57 VisualID visualId = 0;
60 EGLint configRedSize = 0;
61 eglGetConfigAttrib(eglDisplay, config, EGL_RED_SIZE, &configRedSize);
63 EGLint configGreenSize = 0;
64 eglGetConfigAttrib(eglDisplay, config, EGL_GREEN_SIZE, &configGreenSize);
66 EGLint configBlueSize = 0;
67 eglGetConfigAttrib(eglDisplay, config, EGL_BLUE_SIZE, &configBlueSize);
69 EGLint configAlphaSize = 0;
70 eglGetConfigAttrib(eglDisplay, config, EGL_ALPHA_SIZE, &configAlphaSize);
72 eglGetConfigAttrib(eglDisplay, config, EGL_CONFIG_ID, &eglValue);
73 int configId = eglValue;
76 eglGetConfigAttrib(eglDisplay, config, EGL_NATIVE_VISUAL_ID, &eglValue);
77 visualId = (VisualID)eglValue;
80 XVisualInfo visualInfoTemplate;
81 memset(&visualInfoTemplate, 0,
sizeof(XVisualInfo));
82 visualInfoTemplate.visualid = visualId;
84 XVisualInfo *chosenVisualInfo;
85 int matchingCount = 0;
86 chosenVisualInfo = XGetVisualInfo(display, VisualIDMask, &visualInfoTemplate, &matchingCount);
87 if (chosenVisualInfo) {
91 XFree(chosenVisualInfo);
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;
100 bool visualMatchesConfig =
false;
101 if ( visualRedSize == configRedSize &&
102 visualGreenSize == configGreenSize &&
103 visualBlueSize == configBlueSize )
107 if (visualAlphaSize >= 0)
108 visualMatchesConfig = visualAlphaSize == configAlphaSize;
110 visualMatchesConfig =
true;
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);
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);
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);
130 XFree(chosenVisualInfo);
132 #ifdef QT_DEBUG_X11_VISUAL_SELECTION 134 qDebug(
"EGL did not suggest a VisualID (EGL_NATIVE_VISUAL_ID was zero) for EGLConfig %d", configId);
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);
142 qDebug(
"Using Opaque Visual ID %d provided by EGL for config %d", (
int)visualId, configId);
150 XVisualInfo visualInfoTemplate;
151 memset(&visualInfoTemplate, 0,
sizeof(XVisualInfo));
152 XVisualInfo *matchingVisuals;
153 int matchingCount = 0;
155 visualInfoTemplate.depth = configRedSize + configGreenSize + configBlueSize + configAlphaSize;
156 matchingVisuals = XGetVisualInfo(display,
160 if (!matchingVisuals) {
162 visualInfoTemplate.depth = configRedSize + configGreenSize + configBlueSize;
163 matchingVisuals = XGetVisualInfo(display,
169 if (matchingVisuals) {
170 visualId = matchingVisuals[0].visualid;
171 XFree(matchingVisuals);
176 #ifdef QT_DEBUG_X11_VISUAL_SELECTION 177 qDebug(
"Using Visual ID %d provided by XGetVisualInfo for EGL config %d", (
int)visualId, configId);
182 qWarning(
"Unable to find an X11 visual which matches EGL config %d", configId);
static int countBits(unsigned long mask)
Q_CORE_EXPORT void qDebug(const char *,...)
Q_GUI_EXPORT EGLDisplay display()
static VisualID getCompatibleVisualId(Display *display, EGLDisplay eglDisplay, EGLConfig config)
Q_CORE_EXPORT void qWarning(const char *,...)
bool q_hasEglExtension(EGLDisplay display, const char *extensionName)