Qt 4.8
Static Public Functions | List of all members
QXlibEglIntegration Class Reference

#include <qxlibeglintegration.h>

Static Public Functions

static VisualID getCompatibleVisualId (Display *display, EGLDisplay eglDisplay, EGLConfig config)
 

Detailed Description

Definition at line 47 of file qxlibeglintegration.h.

Functions

◆ getCompatibleVisualId()

VisualID QXlibEglIntegration::getCompatibleVisualId ( Display display,
EGLDisplay  eglDisplay,
EGLConfig  config 
)
static

Definition at line 55 of file qxlibeglintegration.cpp.

Referenced by QWaylandXCompositeEGLContext::geometryChanged(), QXcbWindow::QXcbWindow(), and QXlibWindow::QXlibWindow().

56 {
57  VisualID visualId = 0;
58  EGLint eglValue = 0;
59 
60  EGLint configRedSize = 0;
61  eglGetConfigAttrib(eglDisplay, config, EGL_RED_SIZE, &configRedSize);
62 
63  EGLint configGreenSize = 0;
64  eglGetConfigAttrib(eglDisplay, config, EGL_GREEN_SIZE, &configGreenSize);
65 
66  EGLint configBlueSize = 0;
67  eglGetConfigAttrib(eglDisplay, config, EGL_BLUE_SIZE, &configBlueSize);
68 
69  EGLint configAlphaSize = 0;
70  eglGetConfigAttrib(eglDisplay, config, EGL_ALPHA_SIZE, &configAlphaSize);
71 
72  eglGetConfigAttrib(eglDisplay, config, EGL_CONFIG_ID, &eglValue);
73  int configId = eglValue;
74 
75  // See if EGL provided a valid VisualID:
76  eglGetConfigAttrib(eglDisplay, config, EGL_NATIVE_VISUAL_ID, &eglValue);
77  visualId = (VisualID)eglValue;
78  if (visualId) {
79  // EGL has suggested a visual id, so get the rest of the visual info for that id:
80  XVisualInfo visualInfoTemplate;
81  memset(&visualInfoTemplate, 0, sizeof(XVisualInfo));
82  visualInfoTemplate.visualid = visualId;
83 
84  XVisualInfo *chosenVisualInfo;
85  int matchingCount = 0;
86  chosenVisualInfo = XGetVisualInfo(display, VisualIDMask, &visualInfoTemplate, &matchingCount);
87  if (chosenVisualInfo) {
88  // Skip size checks if implementation supports non-matching visual
89  // and config (http://bugreports.qt-project.org/browse/QTBUG-9444).
90  if (q_hasEglExtension(eglDisplay,"EGL_NV_post_convert_rounding")) {
91  XFree(chosenVisualInfo);
92  return visualId;
93  }
94 
95  int visualRedSize = countBits(chosenVisualInfo->red_mask);
96  int visualGreenSize = countBits(chosenVisualInfo->green_mask);
97  int visualBlueSize = countBits(chosenVisualInfo->blue_mask);
98  int visualAlphaSize = -1; // Need XRender to tell us the alpha channel size
99 
100  bool visualMatchesConfig = false;
101  if ( visualRedSize == configRedSize &&
102  visualGreenSize == configGreenSize &&
103  visualBlueSize == configBlueSize )
104  {
105  // We need XRender to check the alpha channel size of the visual. If we don't have
106  // the alpha size, we don't check it against the EGL config's alpha size.
107  if (visualAlphaSize >= 0)
108  visualMatchesConfig = visualAlphaSize == configAlphaSize;
109  else
110  visualMatchesConfig = true;
111  }
112 
113  if (!visualMatchesConfig) {
114  if (visualAlphaSize >= 0) {
115  qWarning("Warning: EGL suggested using X Visual ID %d (ARGB%d%d%d%d) for EGL config %d (ARGB%d%d%d%d), but this is incompatable",
116  (int)visualId, visualAlphaSize, visualRedSize, visualGreenSize, visualBlueSize,
117  configId, configAlphaSize, configRedSize, configGreenSize, configBlueSize);
118  } else {
119  qWarning("Warning: EGL suggested using X Visual ID %d (RGB%d%d%d) for EGL config %d (RGB%d%d%d), but this is incompatable",
120  (int)visualId, visualRedSize, visualGreenSize, visualBlueSize,
121  configId, configRedSize, configGreenSize, configBlueSize);
122  }
123  visualId = 0;
124  }
125  } else {
126  qWarning("Warning: EGL suggested using X Visual ID %d for EGL config %d, but that isn't a valid ID",
127  (int)visualId, configId);
128  visualId = 0;
129  }
130  XFree(chosenVisualInfo);
131  }
132 #ifdef QT_DEBUG_X11_VISUAL_SELECTION
133  else
134  qDebug("EGL did not suggest a VisualID (EGL_NATIVE_VISUAL_ID was zero) for EGLConfig %d", configId);
135 #endif
136 
137  if (visualId) {
138 #ifdef QT_DEBUG_X11_VISUAL_SELECTION
139  if (configAlphaSize > 0)
140  qDebug("Using ARGB Visual ID %d provided by EGL for config %d", (int)visualId, configId);
141  else
142  qDebug("Using Opaque Visual ID %d provided by EGL for config %d", (int)visualId, configId);
143 #endif
144  return visualId;
145  }
146 
147  // Finally, try to
148  // use XGetVisualInfo and only use the bit depths to match on:
149  if (!visualId) {
150  XVisualInfo visualInfoTemplate;
151  memset(&visualInfoTemplate, 0, sizeof(XVisualInfo));
152  XVisualInfo *matchingVisuals;
153  int matchingCount = 0;
154 
155  visualInfoTemplate.depth = configRedSize + configGreenSize + configBlueSize + configAlphaSize;
156  matchingVisuals = XGetVisualInfo(display,
157  VisualDepthMask,
158  &visualInfoTemplate,
159  &matchingCount);
160  if (!matchingVisuals) {
161  // Try again without taking the alpha channel into account:
162  visualInfoTemplate.depth = configRedSize + configGreenSize + configBlueSize;
163  matchingVisuals = XGetVisualInfo(display,
164  VisualDepthMask,
165  &visualInfoTemplate,
166  &matchingCount);
167  }
168 
169  if (matchingVisuals) {
170  visualId = matchingVisuals[0].visualid;
171  XFree(matchingVisuals);
172  }
173  }
174 
175  if (visualId) {
176 #ifdef QT_DEBUG_X11_VISUAL_SELECTION
177  qDebug("Using Visual ID %d provided by XGetVisualInfo for EGL config %d", (int)visualId, configId);
178 #endif
179  return visualId;
180  }
181 
182  qWarning("Unable to find an X11 visual which matches EGL config %d", configId);
183  return (VisualID)0;
184 }
static int countBits(unsigned long mask)
Q_CORE_EXPORT void qDebug(const char *,...)
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
Q_CORE_EXPORT void qWarning(const char *,...)
bool q_hasEglExtension(EGLDisplay display, const char *extensionName)

The documentation for this class was generated from the following files: