Qt 4.8
Classes | Macros | Typedefs | Functions | Variables
qgl_x11.cpp File Reference
#include "qgl.h"
#include "qgl_p.h"
#include "qmap.h"
#include "qapplication.h"
#include "qcolormap.h"
#include "qdesktopwidget.h"
#include "qpixmap.h"
#include "qhash.h"
#include "qlibrary.h"
#include "qdebug.h"
#include <private/qfontengine_ft_p.h>
#include <private/qt_x11_p.h>
#include <private/qpixmap_x11_p.h>
#include <private/qimagepixmapcleanuphooks_p.h>
#include <private/qunicodetables_p.h>
#include <GL/glx.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
#include <dlfcn.h>
#include "qgl_x11.moc"

Go to the source code of this file.

Classes

struct  QCMapEntry
 
struct  QGLCMapCleanupHandler
 
class  QGLOverlayWidget
 
class  QGLTemporaryContextPrivate
 
struct  QTransColor
 

Macros

#define GLX_BIND_TO_MIPMAP_TEXTURE_EXT   0x20D2
 
#define GLX_BIND_TO_TEXTURE_RGB_EXT   0x20D0
 
#define GLX_BIND_TO_TEXTURE_RGBA_EXT   0x20D1
 
#define GLX_BIND_TO_TEXTURE_TARGETS_EXT   0x20D3
 
#define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB   0x00000002
 
#define GLX_CONTEXT_CORE_PROFILE_BIT_ARB   0x00000001
 
#define GLX_CONTEXT_DEBUG_BIT_ARB   0x00000001
 
#define GLX_CONTEXT_FLAGS_ARB   0x2094
 
#define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB   0x00000002
 
#define GLX_CONTEXT_MAJOR_VERSION_ARB   0x2091
 
#define GLX_CONTEXT_MINOR_VERSION_ARB   0x2092
 
#define GLX_CONTEXT_PROFILE_MASK_ARB   0x9126
 
#define GLX_EXT_texture_from_pixmap   1
 
#define GLX_FRONT_LEFT_EXT   0x20DE
 
#define GLX_MIPMAP_TEXTURE_EXT   0x20D7
 
#define GLX_SAMPLE_BUFFERS_ARB   100000
 
#define GLX_SAMPLES_ARB   100001
 
#define GLX_TEXTURE_2D_BIT_EXT   0x00000002
 
#define GLX_TEXTURE_2D_EXT   0x20DC
 
#define GLX_TEXTURE_FORMAT_EXT   0x20D5
 
#define GLX_TEXTURE_FORMAT_NONE_EXT   0x20D8
 
#define GLX_TEXTURE_FORMAT_RGB_EXT   0x20D9
 
#define GLX_TEXTURE_FORMAT_RGBA_EXT   0x20DA
 
#define GLX_TEXTURE_RECTANGLE_BIT_EXT   0x00000004
 
#define GLX_TEXTURE_RECTANGLE_EXT   0x20DD
 
#define GLX_TEXTURE_TARGET_EXT   0x20D6
 
#define GLX_Y_INVERTED_EXT   0x20D4
 
#define INT32   dummy_INT32
 
#define INT8   dummy_INT8
 

Typedefs

typedef QHash< int, QCMapEntry * > CMapEntryHash
 
typedef QHash< int, QMap< int, QRgb > > GLCMapHash
 

Functions

static bool buildSpec (int *spec, const QGLFormat &f, QPaintDevice *paintDevice, int bufDepth, bool onlyFBConfig=false)
 
static void cleanup_cmaps ()
 
static void find_trans_colors ()
 
static bool qCanAllocColors (QWidget *w)
 
static void qgl_use_font (QFontEngineFT *engine, int first, int count, int listBase)
 This is basically a substitute for glxUseXFont() which can only handle XLFD fonts. More...
 
void * qglx_getProcAddress (const char *procName)
 
static void qStoreColors (QWidget *tlw, Colormap cmap, const QGLColormap &cols)
 
Colormap qt_gl_choose_cmap (Display *dpy, XVisualInfo *vi)
 
static uint qt_transparent_pixel (VisualID id, int screen)
 
Drawable qt_x11Handle (const QPaintDevice *pd)
 Returns the X11 Drawable of the paint device. More...
 
const QX11Infoqt_x11Info (const QPaintDevice *pd)
 

Variables

static bool first_time = true
 
static bool mesa_gl = false
 
static QVector< QTransColortrans_colors
 
static int trans_colors_init = false
 

Macro Definition Documentation

◆ GLX_BIND_TO_MIPMAP_TEXTURE_EXT

#define GLX_BIND_TO_MIPMAP_TEXTURE_EXT   0x20D2

Definition at line 105 of file qgl_x11.cpp.

◆ GLX_BIND_TO_TEXTURE_RGB_EXT

#define GLX_BIND_TO_TEXTURE_RGB_EXT   0x20D0

Definition at line 103 of file qgl_x11.cpp.

Referenced by QGLContextPrivate::bindTextureFromNativePixmap().

◆ GLX_BIND_TO_TEXTURE_RGBA_EXT

#define GLX_BIND_TO_TEXTURE_RGBA_EXT   0x20D1

Definition at line 104 of file qgl_x11.cpp.

Referenced by QGLContextPrivate::bindTextureFromNativePixmap().

◆ GLX_BIND_TO_TEXTURE_TARGETS_EXT

#define GLX_BIND_TO_TEXTURE_TARGETS_EXT   0x20D3

Definition at line 106 of file qgl_x11.cpp.

Referenced by QGLContextPrivate::bindTextureFromNativePixmap().

◆ GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB

#define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB   0x00000002

Definition at line 129 of file qgl_x11.cpp.

Referenced by buildSpec().

◆ GLX_CONTEXT_CORE_PROFILE_BIT_ARB

#define GLX_CONTEXT_CORE_PROFILE_BIT_ARB   0x00000001

Definition at line 128 of file qgl_x11.cpp.

Referenced by buildSpec().

◆ GLX_CONTEXT_DEBUG_BIT_ARB

#define GLX_CONTEXT_DEBUG_BIT_ARB   0x00000001

Definition at line 120 of file qgl_x11.cpp.

◆ GLX_CONTEXT_FLAGS_ARB

#define GLX_CONTEXT_FLAGS_ARB   0x2094

Definition at line 124 of file qgl_x11.cpp.

◆ GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB

#define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB   0x00000002

Definition at line 121 of file qgl_x11.cpp.

◆ GLX_CONTEXT_MAJOR_VERSION_ARB

#define GLX_CONTEXT_MAJOR_VERSION_ARB   0x2091

Definition at line 122 of file qgl_x11.cpp.

Referenced by buildSpec().

◆ GLX_CONTEXT_MINOR_VERSION_ARB

#define GLX_CONTEXT_MINOR_VERSION_ARB   0x2092

Definition at line 123 of file qgl_x11.cpp.

Referenced by buildSpec().

◆ GLX_CONTEXT_PROFILE_MASK_ARB

#define GLX_CONTEXT_PROFILE_MASK_ARB   0x9126

Definition at line 130 of file qgl_x11.cpp.

Referenced by buildSpec().

◆ GLX_EXT_texture_from_pixmap

#define GLX_EXT_texture_from_pixmap   1

Definition at line 65 of file qgl_x11.cpp.

◆ GLX_FRONT_LEFT_EXT

#define GLX_FRONT_LEFT_EXT   0x20DE

◆ GLX_MIPMAP_TEXTURE_EXT

#define GLX_MIPMAP_TEXTURE_EXT   0x20D7

Definition at line 110 of file qgl_x11.cpp.

Referenced by QGLContextPrivate::bindTextureFromNativePixmap().

◆ GLX_SAMPLE_BUFFERS_ARB

#define GLX_SAMPLE_BUFFERS_ARB   100000

◆ GLX_SAMPLES_ARB

#define GLX_SAMPLES_ARB   100001

◆ GLX_TEXTURE_2D_BIT_EXT

#define GLX_TEXTURE_2D_BIT_EXT   0x00000002

Definition at line 101 of file qgl_x11.cpp.

Referenced by QGLContextPrivate::bindTextureFromNativePixmap().

◆ GLX_TEXTURE_2D_EXT

#define GLX_TEXTURE_2D_EXT   0x20DC

Definition at line 114 of file qgl_x11.cpp.

Referenced by QGLContextPrivate::bindTextureFromNativePixmap().

◆ GLX_TEXTURE_FORMAT_EXT

#define GLX_TEXTURE_FORMAT_EXT   0x20D5

Definition at line 108 of file qgl_x11.cpp.

Referenced by QGLContextPrivate::bindTextureFromNativePixmap().

◆ GLX_TEXTURE_FORMAT_NONE_EXT

#define GLX_TEXTURE_FORMAT_NONE_EXT   0x20D8

Definition at line 111 of file qgl_x11.cpp.

◆ GLX_TEXTURE_FORMAT_RGB_EXT

#define GLX_TEXTURE_FORMAT_RGB_EXT   0x20D9

Definition at line 112 of file qgl_x11.cpp.

Referenced by QGLContextPrivate::bindTextureFromNativePixmap().

◆ GLX_TEXTURE_FORMAT_RGBA_EXT

#define GLX_TEXTURE_FORMAT_RGBA_EXT   0x20DA

Definition at line 113 of file qgl_x11.cpp.

Referenced by QGLContextPrivate::bindTextureFromNativePixmap().

◆ GLX_TEXTURE_RECTANGLE_BIT_EXT

#define GLX_TEXTURE_RECTANGLE_BIT_EXT   0x00000004

Definition at line 102 of file qgl_x11.cpp.

◆ GLX_TEXTURE_RECTANGLE_EXT

#define GLX_TEXTURE_RECTANGLE_EXT   0x20DD

Definition at line 115 of file qgl_x11.cpp.

◆ GLX_TEXTURE_TARGET_EXT

#define GLX_TEXTURE_TARGET_EXT   0x20D6

Definition at line 109 of file qgl_x11.cpp.

Referenced by QGLContextPrivate::bindTextureFromNativePixmap().

◆ GLX_Y_INVERTED_EXT

#define GLX_Y_INVERTED_EXT   0x20D4

Definition at line 107 of file qgl_x11.cpp.

Referenced by QGLContextPrivate::bindTextureFromNativePixmap().

◆ INT32

#define INT32   dummy_INT32

Definition at line 68 of file qgl_x11.cpp.

◆ INT8

#define INT8   dummy_INT8

Definition at line 67 of file qgl_x11.cpp.

Typedef Documentation

◆ CMapEntryHash

typedef QHash<int, QCMapEntry *> CMapEntryHash

Definition at line 162 of file qgl_x11.cpp.

◆ GLCMapHash

typedef QHash<int, QMap<int, QRgb> > GLCMapHash

Definition at line 163 of file qgl_x11.cpp.

Function Documentation

◆ buildSpec()

static bool buildSpec ( int *  spec,
const QGLFormat f,
QPaintDevice paintDevice,
int  bufDepth,
bool  onlyFBConfig = false 
)
static

Definition at line 421 of file qgl_x11.cpp.

Referenced by QGLContext::tryVisual().

423 {
424  int i = 0;
425  spec[i++] = GLX_LEVEL;
426  spec[i++] = f.plane();
427  const QX11Info *xinfo = qt_x11Info(paintDevice);
428  bool useFBConfig = onlyFBConfig;
429 
430 #if defined(GLX_VERSION_1_3) && !defined(QT_NO_XRENDER) && !defined(Q_OS_HPUX)
431  /*
432  HPUX defines GLX_VERSION_1_3 but does not implement the corresponding functions.
433  Specifically glXChooseFBConfig and glXGetVisualFromFBConfig are not implemented.
434  */
435  QWidget* widget = 0;
436  if (paintDevice->devType() == QInternal::Widget)
437  widget = static_cast<QWidget*>(paintDevice);
438 
439  // Only use glXChooseFBConfig for widgets if we're trying to get an ARGB visual
440  if (widget && widget->testAttribute(Qt::WA_TranslucentBackground) && X11->use_xrender)
441  useFBConfig = true;
442 #endif
443 
444 #if defined(GLX_VERSION_1_1) && defined(GLX_EXT_visual_info)
445  static bool useTranspExt = false;
446  static bool useTranspExtChecked = false;
447  if (f.plane() && !useTranspExtChecked && paintDevice) {
448  QGLExtensionMatcher extensions(glXQueryExtensionsString(xinfo->display(), xinfo->screen()));
449  useTranspExt = extensions.match("GLX_EXT_visual_info");
450  //# (A bit simplistic; that could theoretically be a substring)
451  if (useTranspExt) {
452  QByteArray cstr(glXGetClientString(xinfo->display(), GLX_VENDOR));
453  useTranspExt = !cstr.contains("Xi Graphics"); // bug workaround
454  if (useTranspExt) {
455  // bug workaround - some systems (eg. FireGL) refuses to return an overlay
456  // visual if the GLX_TRANSPARENT_TYPE_EXT attribute is specified, even if
457  // the implementation supports transparent overlays
458  int tmpSpec[] = { GLX_LEVEL, f.plane(), GLX_TRANSPARENT_TYPE_EXT,
459  f.rgba() ? GLX_TRANSPARENT_RGB_EXT : GLX_TRANSPARENT_INDEX_EXT,
460  XNone };
461  XVisualInfo * vinf = glXChooseVisual(xinfo->display(), xinfo->screen(), tmpSpec);
462  if (!vinf) {
463  useTranspExt = false;
464  }
465  }
466  }
467 
468  useTranspExtChecked = true;
469  }
470  if (f.plane() && useTranspExt && !useFBConfig) {
471  // Required to avoid non-transparent overlay visual(!) on some systems
472  spec[i++] = GLX_TRANSPARENT_TYPE_EXT;
473  spec[i++] = f.rgba() ? GLX_TRANSPARENT_RGB_EXT : GLX_TRANSPARENT_INDEX_EXT;
474  }
475 #endif
476 
477 #if defined(GLX_VERSION_1_3) && !defined(Q_OS_HPUX)
478  // GLX_RENDER_TYPE is only in glx >=1.3
479  if (useFBConfig) {
480  spec[i++] = GLX_RENDER_TYPE;
481  spec[i++] = f.rgba() ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
482  }
483 #endif
484 
485  if (f.doubleBuffer())
486  spec[i++] = GLX_DOUBLEBUFFER;
487  if (useFBConfig)
488  spec[i++] = True;
489  if (f.depth()) {
490  spec[i++] = GLX_DEPTH_SIZE;
491  spec[i++] = f.depthBufferSize() == -1 ? 1 : f.depthBufferSize();
492  }
493  if (f.stereo()) {
494  spec[i++] = GLX_STEREO;
495  if (useFBConfig)
496  spec[i++] = True;
497  }
498  if (f.stencil()) {
499  spec[i++] = GLX_STENCIL_SIZE;
500  spec[i++] = f.stencilBufferSize() == -1 ? 1 : f.stencilBufferSize();
501  }
502  if (f.rgba()) {
503  if (!useFBConfig)
504  spec[i++] = GLX_RGBA;
505  spec[i++] = GLX_RED_SIZE;
506  spec[i++] = f.redBufferSize() == -1 ? 1 : f.redBufferSize();
507  spec[i++] = GLX_GREEN_SIZE;
508  spec[i++] = f.greenBufferSize() == -1 ? 1 : f.greenBufferSize();
509  spec[i++] = GLX_BLUE_SIZE;
510  spec[i++] = f.blueBufferSize() == -1 ? 1 : f.blueBufferSize();
511  if (f.alpha()) {
512  spec[i++] = GLX_ALPHA_SIZE;
513  spec[i++] = f.alphaBufferSize() == -1 ? 1 : f.alphaBufferSize();
514  }
515  if (f.accum()) {
516  spec[i++] = GLX_ACCUM_RED_SIZE;
517  spec[i++] = f.accumBufferSize() == -1 ? 1 : f.accumBufferSize();
518  spec[i++] = GLX_ACCUM_GREEN_SIZE;
519  spec[i++] = f.accumBufferSize() == -1 ? 1 : f.accumBufferSize();
520  spec[i++] = GLX_ACCUM_BLUE_SIZE;
521  spec[i++] = f.accumBufferSize() == -1 ? 1 : f.accumBufferSize();
522  if (f.alpha()) {
523  spec[i++] = GLX_ACCUM_ALPHA_SIZE;
524  spec[i++] = f.accumBufferSize() == -1 ? 1 : f.accumBufferSize();
525  }
526  }
527  } else {
528  spec[i++] = GLX_BUFFER_SIZE;
529  spec[i++] = bufDepth;
530  }
531 
532  if (f.sampleBuffers()) {
533  spec[i++] = GLX_SAMPLE_BUFFERS_ARB;
534  spec[i++] = 1;
535  spec[i++] = GLX_SAMPLES_ARB;
536  spec[i++] = f.samples() == -1 ? 4 : f.samples();
537  }
538 
539 #if defined(GLX_VERSION_1_3) && !defined(Q_OS_HPUX)
540  if (useFBConfig) {
541  spec[i++] = GLX_DRAWABLE_TYPE;
542  switch(paintDevice->devType()) {
543  case QInternal::Pixmap:
544  spec[i++] = GLX_PIXMAP_BIT;
545  break;
546  case QInternal::Pbuffer:
547  spec[i++] = GLX_PBUFFER_BIT;
548  break;
549  default:
550  qWarning("QGLContext: Unknown paint device type %d", paintDevice->devType());
551  // Fall-through & assume it's a window
552  case QInternal::Widget:
553  spec[i++] = GLX_WINDOW_BIT;
554  break;
555  };
556  }
557 #endif
558 
559  spec[i] = XNone;
560  return useFBConfig;
561 }
bool rgba() const
Returns true if RGBA color mode is set.
Definition: qgl.h:623
QPointer< QWidget > widget
int greenBufferSize() const
Returns the green buffer size.
Definition: qgl.cpp:1070
#define GLX_RGBA_BIT
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int redBufferSize() const
Returns the red buffer size.
Definition: qgl.cpp:1035
#define X11
Definition: qt_x11_p.h:724
Q_GUI_EXPORT QString extensions()
Definition: qegl.cpp:785
virtual int devType() const
Definition: qpaintdevice.h:167
#define GLX_SAMPLE_BUFFERS_ARB
Definition: qgl_x11.cpp:96
bool sampleBuffers() const
Returns true if multisample buffer support is enabled; otherwise returns false.
Definition: qgl.h:658
#define GLX_PBUFFER_BIT
int plane() const
Returns the plane of this format.
Definition: qgl.cpp:924
int alphaBufferSize() const
Returns the alpha buffer size.
Definition: qgl.cpp:1132
const Q_GUI_EXPORT QX11Info * qt_x11Info(const QPaintDevice *pd)
Returns the QX11Info structure for the pd paint device.
#define GLX_DRAWABLE_TYPE
bool depth() const
Returns true if the depth buffer is enabled; otherwise returns false.
Definition: qgl.h:618
int accumBufferSize() const
Returns the accumulation buffer size.
Definition: qgl.cpp:1159
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
#define GLX_RENDER_TYPE
int depthBufferSize() const
Returns the depth buffer size.
Definition: qgl.cpp:1000
bool stencil() const
Returns true if the stencil buffer is enabled; otherwise returns false.
Definition: qgl.h:638
Q_CORE_EXPORT void qWarning(const char *,...)
bool accum() const
Returns true if the accumulation buffer is enabled; otherwise returns false.
Definition: qgl.h:633
#define GLX_SAMPLES_ARB
Definition: qgl_x11.cpp:97
The QX11Info class provides information about the X display configuration.
Definition: qx11info_x11.h:63
bool alpha() const
Returns true if the alpha buffer in the framebuffer is enabled; otherwise returns false...
Definition: qgl.h:628
int blueBufferSize() const
Returns the blue buffer size.
Definition: qgl.cpp:1105
bool doubleBuffer() const
Returns true if double buffering is enabled; otherwise returns false.
Definition: qgl.h:613
int stencilBufferSize() const
Returns the stencil buffer size.
Definition: qgl.cpp:1185
bool stereo() const
Returns true if stereo buffering is enabled; otherwise returns false.
Definition: qgl.h:643
int samples() const
Returns the number of samples per pixel when multisampling is enabled.
Definition: qgl.cpp:824
static Display * display()
Returns the default display for the application.
int screen() const
Returns the number of the screen currently in use.

◆ cleanup_cmaps()

static void cleanup_cmaps ( )
static

Definition at line 183 of file qgl_x11.cpp.

Referenced by qt_gl_choose_cmap().

184 {
185  CMapEntryHash *hash = cmap_handler()->cmap_hash;
187  while (it != hash->constEnd()) {
188  delete it.value();
189  ++it;
190  }
191 
192  hash->clear();
193  cmap_handler()->qglcmap_hash->clear();
194 }
static uint hash(const uchar *p, int n)
Definition: qhash.cpp:68
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
void clear()
Removes all items from the hash.
Definition: qhash.h:574
#define it(className, varName)
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
const T & value() const
Returns the current item&#39;s value.
Definition: qhash.h:420
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469

◆ find_trans_colors()

static void find_trans_colors ( )
static

Definition at line 288 of file qgl_x11.cpp.

Referenced by qglx_getProcAddress().

289 {
290  struct OverlayProp {
291  long visual;
292  long type;
293  long value;
294  long layer;
295  };
296 
297  trans_colors_init = true;
298 
299  Display* appDisplay = X11->display;
300 
301  int scr;
302  int lastsize = 0;
303  for (scr = 0; scr < ScreenCount(appDisplay); scr++) {
304  QWidget* rootWin = QApplication::desktop()->screen(scr);
305  if (!rootWin)
306  return; // Should not happen
307  Atom overlayVisualsAtom = XInternAtom(appDisplay,
308  "SERVER_OVERLAY_VISUALS", True);
309  if (overlayVisualsAtom == XNone)
310  return; // Server has no overlays
311 
312  Atom actualType;
313  int actualFormat;
314  ulong nItems;
315  ulong bytesAfter;
316  unsigned char *retval = 0;
317  int res = XGetWindowProperty(appDisplay, rootWin->winId(),
318  overlayVisualsAtom, 0, 10000, False,
319  overlayVisualsAtom, &actualType,
320  &actualFormat, &nItems, &bytesAfter,
321  &retval);
322 
323  if (res != Success || actualType != overlayVisualsAtom
324  || actualFormat != 32 || nItems < 4 || !retval)
325  return; // Error reading property
326 
327  OverlayProp *overlayProps = (OverlayProp *)retval;
328 
329  int numProps = nItems / 4;
330  trans_colors.resize(lastsize + numProps);
331  int j = lastsize;
332  for (int i = 0; i < numProps; i++) {
333  if (overlayProps[i].type == 1) {
334  trans_colors[j].vis = (VisualID)overlayProps[i].visual;
335  trans_colors[j].screen = scr;
336  trans_colors[j].color = (int)overlayProps[i].value;
337  j++;
338  }
339  }
340  XFree(overlayProps);
341  lastsize = j;
342  trans_colors.resize(lastsize);
343  }
344 }
int type
Definition: qmetatype.cpp:239
static QVector< QTransColor > trans_colors
Definition: qgl_x11.cpp:285
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define X11
Definition: qt_x11_p.h:724
static int trans_colors_init
Definition: qgl_x11.cpp:286
unsigned long ulong
Definition: qglobal.h:997
QWidget * screen(int screen=-1)
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
struct _XDisplay Display
Definition: qwindowdefs.h:115
WId winId() const
Returns the window system identifier of the widget.
Definition: qwidget.cpp:2557

◆ qCanAllocColors()

static bool qCanAllocColors ( QWidget w)
static

Definition at line 1629 of file qgl_x11.cpp.

1630 {
1631  bool validVisual = false;
1632  int numVisuals;
1633  long mask;
1634  XVisualInfo templ;
1635  XVisualInfo * visuals;
1636  VisualID id = XVisualIDFromVisual((Visual *) w->window()->x11Info().visual());
1637 
1638  mask = VisualScreenMask;
1639  templ.screen = w->x11Info().screen();
1640  visuals = XGetVisualInfo(X11->display, mask, &templ, &numVisuals);
1641 
1642  for (int i = 0; i < numVisuals; i++) {
1643  if (visuals[i].visualid == id) {
1644  switch (visuals[i].c_class) {
1645  case TrueColor:
1646  case StaticColor:
1647  case StaticGray:
1648  case XGrayScale:
1649  validVisual = false;
1650  break;
1651  case DirectColor:
1652  case PseudoColor:
1653  validVisual = true;
1654  break;
1655  }
1656  break;
1657  }
1658  }
1659  XFree(visuals);
1660 
1661  if (!validVisual)
1662  return false;
1663  return true;
1664 }
const QX11Info & x11Info() const
Returns information about the configuration of the X display used to display the widget.
#define X11
Definition: qt_x11_p.h:724
void * visual() const
Returns the current visual.
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
int screen() const
Returns the number of the screen currently in use.

◆ qgl_use_font()

static void qgl_use_font ( QFontEngineFT engine,
int  first,
int  count,
int  listBase 
)
static

This is basically a substitute for glxUseXFont() which can only handle XLFD fonts.

Warning
This function is not part of the public interface. This version relies on freetype to render the glyphs, but it works with all fonts that fontconfig provides - both antialiased and aliased bitmap and outline fonts.

Definition at line 1073 of file qgl_x11.cpp.

1074 {
1075  GLfloat color[4];
1076  glGetFloatv(GL_CURRENT_COLOR, color);
1077 
1078  // save the pixel unpack state
1079  GLint gl_swapbytes, gl_lsbfirst, gl_rowlength, gl_skiprows, gl_skippixels, gl_alignment;
1080  glGetIntegerv (GL_UNPACK_SWAP_BYTES, &gl_swapbytes);
1081  glGetIntegerv (GL_UNPACK_LSB_FIRST, &gl_lsbfirst);
1082  glGetIntegerv (GL_UNPACK_ROW_LENGTH, &gl_rowlength);
1083  glGetIntegerv (GL_UNPACK_SKIP_ROWS, &gl_skiprows);
1084  glGetIntegerv (GL_UNPACK_SKIP_PIXELS, &gl_skippixels);
1085  glGetIntegerv (GL_UNPACK_ALIGNMENT, &gl_alignment);
1086 
1087  glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
1088  glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
1089  glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
1090  glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
1091  glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
1092  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1093 
1094  const bool antialiased = engine->drawAntialiased();
1095  FT_Face face = engine->lockFace();
1096 
1097  // start generating font glyphs
1098  for (int i = first; i < count; ++i) {
1099  int list = listBase + i;
1100  GLfloat x0, y0, dx, dy;
1101 
1102  FT_Error err;
1103 
1104  err = FT_Load_Glyph(face, FT_Get_Char_Index(face, i), FT_LOAD_DEFAULT);
1105  if (err) {
1106  qDebug("failed loading glyph %d from font", i);
1107  Q_ASSERT(!err);
1108  }
1109  err = FT_Render_Glyph(face->glyph, (antialiased ? FT_RENDER_MODE_NORMAL
1110  : FT_RENDER_MODE_MONO));
1111  if (err) {
1112  qDebug("failed rendering glyph %d from font", i);
1113  Q_ASSERT(!err);
1114  }
1115 
1116  FT_Bitmap bm = face->glyph->bitmap;
1117  x0 = face->glyph->metrics.horiBearingX >> 6;
1118  y0 = (face->glyph->metrics.height - face->glyph->metrics.horiBearingY) >> 6;
1119  dx = face->glyph->metrics.horiAdvance >> 6;
1120  dy = 0;
1121  int sz = bm.pitch * bm.rows;
1122  uint *aa_glyph = 0;
1123  uchar *ua_glyph = 0;
1124 
1125  if (antialiased)
1126  aa_glyph = new uint[sz];
1127  else
1128  ua_glyph = new uchar[sz];
1129 
1130  // convert to GL format
1131  for (int y = 0; y < bm.rows; ++y) {
1132  for (int x = 0; x < bm.pitch; ++x) {
1133  int c1 = y*bm.pitch + x;
1134  int c2 = (bm.rows - y - 1) > 0 ? (bm.rows-y-1)*bm.pitch + x : x;
1135  if (antialiased) {
1136  aa_glyph[c1] = (int(color[0]*255) << 24)
1137  | (int(color[1]*255) << 16)
1138  | (int(color[2]*255) << 8) | bm.buffer[c2];
1139  } else {
1140  ua_glyph[c1] = bm.buffer[c2];
1141  }
1142  }
1143  }
1144 
1145  glNewList(list, GL_COMPILE);
1146  if (antialiased) {
1147  // calling glBitmap() is just a trick to move the current
1148  // raster pos, since glGet*() won't work in display lists
1149  glBitmap(0, 0, 0, 0, x0, -y0, 0);
1150  glDrawPixels(bm.pitch, bm.rows, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, aa_glyph);
1151  glBitmap(0, 0, 0, 0, dx-x0, y0, 0);
1152  } else {
1153  glBitmap(bm.pitch*8, bm.rows, -x0, y0, dx, dy, ua_glyph);
1154  }
1155  glEndList();
1156  antialiased ? delete[] aa_glyph : delete[] ua_glyph;
1157  }
1158 
1159  engine->unlockFace();
1160 
1161  // restore pixel unpack settings
1162  glPixelStorei(GL_UNPACK_SWAP_BYTES, gl_swapbytes);
1163  glPixelStorei(GL_UNPACK_LSB_FIRST, gl_lsbfirst);
1164  glPixelStorei(GL_UNPACK_ROW_LENGTH, gl_rowlength);
1165  glPixelStorei(GL_UNPACK_SKIP_ROWS, gl_skiprows);
1166  glPixelStorei(GL_UNPACK_SKIP_PIXELS, gl_skippixels);
1167  glPixelStorei(GL_UNPACK_ALIGNMENT, gl_alignment);
1168 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Q_CORE_EXPORT void qDebug(const char *,...)
#define GL_FALSE
unsigned char uchar
Definition: qglobal.h:994
struct FT_FaceRec_ * FT_Face
Definition: qfont.h:50
void unlockFace() const
unsigned int uint
Definition: qglobal.h:996
#define GL_UNPACK_ALIGNMENT
FT_Face lockFace(Scaling scale=Scaled) const
typedef GLint
Definition: glfunctions.h:67
#define GL_RGBA
bool drawAntialiased() const

◆ qglx_getProcAddress()

void* qglx_getProcAddress ( const char *  procName)

Definition at line 350 of file qgl_x11.cpp.

Referenced by buildSpec(), qt_resolve_pbuffer_extensions(), and QGLContext::tryVisual().

351 {
352  // On systems where the GL driver is pluggable (like Mesa), we have to use
353  // the glXGetProcAddressARB extension to resolve other function pointers as
354  // the symbols wont be in the GL library, but rather in a plugin loaded by
355  // the GL library.
356  typedef void* (*qt_glXGetProcAddressARB)(const char *);
357  static qt_glXGetProcAddressARB glXGetProcAddressARB = 0;
358  static bool triedResolvingGlxGetProcAddress = false;
359  if (!triedResolvingGlxGetProcAddress) {
360  triedResolvingGlxGetProcAddress = true;
361  QGLExtensionMatcher extensions(glXGetClientString(QX11Info::display(), GLX_EXTENSIONS));
362  if (extensions.match("GLX_ARB_get_proc_address")) {
363 #if defined(Q_OS_LINUX) || defined(Q_OS_BSD4)
364  void *handle = dlopen(NULL, RTLD_LAZY);
365  if (handle) {
366  glXGetProcAddressARB = (qt_glXGetProcAddressARB) dlsym(handle, "glXGetProcAddressARB");
367  dlclose(handle);
368  }
369  if (!glXGetProcAddressARB)
370 #endif
371  {
372 #if !defined(QT_NO_LIBRARY)
373  extern const QString qt_gl_library_name();
375  lib.setLoadHints(QLibrary::ImprovedSearchHeuristics);
376  glXGetProcAddressARB = (qt_glXGetProcAddressARB) lib.resolve("glXGetProcAddressARB");
377 #endif
378  }
379  }
380  }
381 
382  void *procAddress = 0;
383  if (glXGetProcAddressARB)
384  procAddress = glXGetProcAddressARB(procName);
385 
386  // If glXGetProcAddress didn't work, try looking the symbol up in the GL library
387 #if defined(Q_OS_LINUX) || defined(Q_OS_BSD4)
388  if (!procAddress) {
389  void *handle = dlopen(NULL, RTLD_LAZY);
390  if (handle) {
391  procAddress = dlsym(handle, procName);
392  dlclose(handle);
393  }
394  }
395 #endif
396 #if !defined(QT_NO_LIBRARY)
397  if (!procAddress) {
398  extern const QString qt_gl_library_name();
400  lib.setLoadHints(QLibrary::ImprovedSearchHeuristics);
401  procAddress = lib.resolve(procName);
402  }
403 #endif
404 
405  return procAddress;
406 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_GUI_EXPORT QString extensions()
Definition: qegl.cpp:785
Q_OPENGL_EXPORT const QString qt_gl_library_name()
Definition: qgl.cpp:5827
static Display * display()
Returns the default display for the application.
The QLibrary class loads shared libraries at runtime.
Definition: qlibrary.h:62

◆ qStoreColors()

static void qStoreColors ( QWidget tlw,
Colormap  cmap,
const QGLColormap cols 
)
static

Definition at line 1608 of file qgl_x11.cpp.

Referenced by qCanAllocColors().

1610 {
1611  Q_UNUSED(tlw);
1612  XColor c;
1613  QRgb color;
1614 
1615  for (int i = 0; i < cols.size(); i++) {
1616  color = cols.entryRgb(i);
1617  c.pixel = i;
1618  c.red = (ushort)((qRed(color) / 255.0) * 65535.0 + 0.5);
1619  c.green = (ushort)((qGreen(color) / 255.0) * 65535.0 + 0.5);
1620  c.blue = (ushort)((qBlue(color) / 255.0) * 65535.0 + 0.5);
1621  c.flags = DoRed | DoGreen | DoBlue;
1622  XStoreColor(X11->display, cmap, &c);
1623  }
1624 }
unsigned int QRgb
Definition: qrgb.h:53
unsigned char c[8]
Definition: qnumeric_p.h:62
int size() const
Returns the number of colorcells in the colormap.
static QColor cmap[256]
Definition: qgl_mac.mm:760
#define X11
Definition: qt_x11_p.h:724
int qRed(QRgb rgb)
Returns the red component of the ARGB quadruplet rgb.
Definition: qrgb.h:57
QRgb entryRgb(int idx) const
Returns the QRgb value in the colorcell with index idx.
unsigned short ushort
Definition: qglobal.h:995
int qGreen(QRgb rgb)
Returns the green component of the ARGB quadruplet rgb.
Definition: qrgb.h:60
int qBlue(QRgb rgb)
Returns the blue component of the ARGB quadruplet rgb.
Definition: qrgb.h:63
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ qt_gl_choose_cmap()

Colormap qt_gl_choose_cmap ( Display dpy,
XVisualInfo *  vi 
)

Definition at line 196 of file qgl_x11.cpp.

Referenced by buildSpec(), and QGLOverlayWidget::paintGL().

197 {
198  if (first_time) {
199  const char *v = glXQueryServerString(dpy, vi->screen, GLX_VERSION);
200  if (v)
201  mesa_gl = (strstr(v, "Mesa") != 0);
202  first_time = false;
203  }
204 
205  CMapEntryHash *hash = cmap_handler()->cmap_hash;
206  CMapEntryHash::ConstIterator it = hash->constFind((long) vi->visualid + (vi->screen * 256));
207  if (it != hash->constEnd())
208  return it.value()->cmap; // found colormap for visual
209 
210  if (vi->visualid ==
211  XVisualIDFromVisual((Visual *) QX11Info::appVisual(vi->screen))) {
212  // qDebug("Using x11AppColormap");
213  return QX11Info::appColormap(vi->screen);
214  }
215 
216  QCMapEntry *x = new QCMapEntry();
217 
218  XStandardColormap *c;
219  int n, i;
220 
221  // qDebug("Choosing cmap for vID %0x", vi->visualid);
222 
223  if (mesa_gl) { // we're using MesaGL
224  Atom hp_cmaps = XInternAtom(dpy, "_HP_RGB_SMOOTH_MAP_LIST", true);
225  if (hp_cmaps && vi->visual->c_class == TrueColor && vi->depth == 8) {
226  if (XGetRGBColormaps(dpy,RootWindow(dpy,vi->screen),&c,&n,
227  hp_cmaps)) {
228  i = 0;
229  while (i < n && x->cmap == 0) {
230  if (c[i].visualid == vi->visual->visualid) {
231  x->cmap = c[i].colormap;
232  x->scmap = c[i];
233  //qDebug("Using HP_RGB scmap");
234 
235  }
236  i++;
237  }
238  XFree((char *)c);
239  }
240  }
241  }
242  if (!x->cmap) {
243  if (XGetRGBColormaps(dpy,RootWindow(dpy,vi->screen),&c,&n,
244  XA_RGB_DEFAULT_MAP)) {
245  for (int i = 0; i < n && x->cmap == 0; ++i) {
246  if (!c[i].red_max ||
247  !c[i].green_max ||
248  !c[i].blue_max ||
249  !c[i].red_mult ||
250  !c[i].green_mult ||
251  !c[i].blue_mult)
252  continue; // invalid stdcmap
253  if (c[i].visualid == vi->visualid) {
254  x->cmap = c[i].colormap;
255  x->scmap = c[i];
256  //qDebug("Using RGB_DEFAULT scmap");
257  }
258  }
259  XFree((char *)c);
260  }
261  }
262  if (!x->cmap) { // no shared cmap found
263  x->cmap = XCreateColormap(dpy, RootWindow(dpy,vi->screen), vi->visual,
264  AllocNone);
265  x->alloc = true;
266  // qDebug("Allocating cmap");
267  }
268 
269  // colormap hash should be cleanup only when the QApplication dtor is called
270  if (hash->isEmpty())
272 
273  // associate cmap with visualid
274  hash->insert((long) vi->visualid + (vi->screen * 256), x);
275  return x->cmap;
276 }
static uint hash(const uchar *p, int n)
Definition: qhash.cpp:68
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
unsigned char c[8]
Definition: qnumeric_p.h:62
bool alloc
Definition: qgl_x11.cpp:146
#define it(className, varName)
static QColor cmap[256]
Definition: qgl_mac.mm:760
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
static void cleanup_cmaps()
Definition: qgl_x11.cpp:183
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
Definition: qhash.h:297
const T & value() const
Returns the current item&#39;s value.
Definition: qhash.h:420
const_iterator constFind(const Key &key) const
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:859
static Qt::HANDLE appColormap(int screen=-1)
Returns a handle for the application&#39;s color map on the given screen.
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
static bool first_time
Definition: qgl_x11.cpp:165
Colormap cmap
Definition: qgl_x11.cpp:145
static void * appVisual(int screen=-1)
Returns the current visual used by the application on the given screen.
XStandardColormap scmap
Definition: qgl_x11.cpp:147
static bool mesa_gl
Definition: qgl_x11.cpp:164
void qAddPostRoutine(QtCleanUpFunction ptr)
Adds a global routine that will be called from the QApplication destructor.

◆ qt_transparent_pixel()

static uint qt_transparent_pixel ( VisualID  id,
int  screen 
)
static

Definition at line 991 of file qgl_x11.cpp.

992 {
993  for (int i = 0; i < trans_colors.size(); i++) {
994  if (trans_colors[i].vis == id && trans_colors[i].screen == screen)
995  return trans_colors[i].color;
996  }
997  return 0;
998 }
static QVector< QTransColor > trans_colors
Definition: qgl_x11.cpp:285

◆ qt_x11Handle()

Drawable qt_x11Handle ( const QPaintDevice pd)

Returns the X11 Drawable of the paint device.

Warning
This function is not part of the public interface.

0 is returned if it can't be obtained.

Definition at line 61 of file qpaintdevice_x11.cpp.

Referenced by buildSpec().

62 {
63  if (!pd) return 0;
64  if (pd->devType() == QInternal::Widget)
65  return static_cast<const QWidget *>(pd)->handle();
66  else if (pd->devType() == QInternal::Pixmap)
67  return static_cast<const QPixmap *>(pd)->handle();
68  return 0;
69 }
virtual int devType() const
Definition: qpaintdevice.h:167

◆ qt_x11Info()

const QX11Info* qt_x11Info ( const QPaintDevice pd)
related

Referenced by buildSpec(), and QGLContext::tryVisual().

Variable Documentation

◆ first_time

bool first_time = true
static

Definition at line 165 of file qgl_x11.cpp.

Referenced by qt_gl_choose_cmap().

◆ mesa_gl

bool mesa_gl = false
static

Definition at line 164 of file qgl_x11.cpp.

Referenced by qt_gl_choose_cmap().

◆ trans_colors

QVector<QTransColor> trans_colors
static

Definition at line 285 of file qgl_x11.cpp.

◆ trans_colors_init

int trans_colors_init = false
static

Definition at line 286 of file qgl_x11.cpp.

Referenced by find_trans_colors(), and qglx_getProcAddress().