26 std::optional<xcb_visualid_t> requestedVisualId,
27 std::optional<uint8_t> requestedDepth =
std::nullopt)
29 xcb_depth_iterator_t depthIterator = xcb_screen_allowed_depths_iterator(screen);
31 while (depthIterator.rem) {
32 xcb_depth_t *depth = depthIterator.data;
33 xcb_visualtype_iterator_t visualTypeIterator = xcb_depth_visuals_iterator(depth);
35 while (visualTypeIterator.rem) {
36 xcb_visualtype_t *visualType = visualTypeIterator.data;
37 if (requestedVisualId && visualType->visual_id != *requestedVisualId) {
38 xcb_visualtype_next(&visualTypeIterator);
42 if (requestedDepth && depth->depth != *requestedDepth) {
43 xcb_visualtype_next(&visualTypeIterator);
47 return VisualInfo{ *visualType, depth->depth };
50 xcb_depth_next(&depthIterator);
74 m_connection = connection;
76 const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
78#if QT_CONFIG(xcb_xlib)
79 if (extensions && strstr(extensions,
"EGL_EXT_platform_x11")) {
80 QEGLStreamConvenience streamFuncs;
81 m_egl_display = streamFuncs.get_platform_display(EGL_PLATFORM_X11_KHR,
82 m_connection->xlib_display(),
84 m_using_platform_display =
true;
89 m_egl_display = eglGetDisplay(
reinterpret_cast<EGLNativeDisplayType>(m_connection->xlib_display()));
92 if (extensions && (strstr(extensions,
"EGL_EXT_platform_xcb") || strstr(extensions,
"EGL_MESA_platform_xcb"))) {
93 QEGLStreamConvenience streamFuncs;
94 m_egl_display = streamFuncs.get_platform_display(EGL_PLATFORM_XCB_KHR,
95 reinterpret_cast<
void *>(connection->xcb_connection()),
97 m_using_platform_display =
true;
102 bool success = eglInitialize(m_egl_display, &major, &minor);
103#if QT_CONFIG(egl_x11)
105 m_egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
106 qCDebug(lcQpaGl) <<
"Xcb EGL gl-integration retrying with display" << m_egl_display;
107 success = eglInitialize(m_egl_display, &major, &minor);
111 m_native_interface_handler.reset(
new QXcbEglNativeInterfaceHandler(connection->nativeInterface()));
114 qCDebug(lcQpaGl) <<
"Xcb EGL gl-integration successfully initialized";
116 qCWarning(lcQpaGl) <<
"Xcb EGL gl-integration initialize failed";
148 xcb_visualid_t visualId = 0;
151 EGLint configRedSize = 0;
152 eglGetConfigAttrib(eglDisplay(), config, EGL_RED_SIZE, &configRedSize);
154 EGLint configGreenSize = 0;
155 eglGetConfigAttrib(eglDisplay(), config, EGL_GREEN_SIZE, &configGreenSize);
157 EGLint configBlueSize = 0;
158 eglGetConfigAttrib(eglDisplay(), config, EGL_BLUE_SIZE, &configBlueSize);
160 EGLint configAlphaSize = 0;
161 eglGetConfigAttrib(eglDisplay(), config, EGL_ALPHA_SIZE, &configAlphaSize);
163 eglGetConfigAttrib(eglDisplay(), config, EGL_CONFIG_ID, &eglValue);
164 int configId = eglValue;
167 eglGetConfigAttrib(eglDisplay(), config, EGL_NATIVE_VISUAL_ID, &eglValue);
171 std::optional<
VisualInfo> chosenVisualInfo = getVisualInfo(screen, visualId);
172 if (chosenVisualInfo) {
175 if (q_hasEglExtension(eglDisplay(),
"EGL_NV_post_convert_rounding"))
178 const char *vendor = eglQueryString(eglDisplay(), EGL_VENDOR);
179 if (vendor && strstr(vendor,
"Vivante"))
182 int visualRedSize = qPopulationCount(chosenVisualInfo->visualType.red_mask);
183 int visualGreenSize = qPopulationCount(chosenVisualInfo->visualType.green_mask);
184 int visualBlueSize = qPopulationCount(chosenVisualInfo->visualType.blue_mask);
185 int visualAlphaSize = chosenVisualInfo->depth - visualRedSize - visualBlueSize - visualGreenSize;
187 const bool visualMatchesConfig = visualRedSize >= configRedSize
188 && visualGreenSize >= configGreenSize
189 && visualBlueSize >= configBlueSize
190 && visualAlphaSize >= configAlphaSize;
194 if (!visualMatchesConfig) {
197 "EGL suggested using X Visual ID %d (%d %d %d %d depth %d) for EGL config %d"
198 "(%d %d %d %d), but this is incompatible",
199 visualId, visualRedSize, visualGreenSize, visualBlueSize, visualAlphaSize, chosenVisualInfo->depth,
200 configId, configRedSize, configGreenSize, configBlueSize, configAlphaSize);
203 qCDebug(lcQpaGl,
"EGL suggested using X Visual ID %d for EGL config %d, but that isn't a valid ID",
209 qCDebug(lcQpaGl,
"EGL did not suggest a VisualID (EGL_NATIVE_VISUAL_ID was zero) for EGLConfig %d", configId);
212 qCDebug(lcQpaGl, configAlphaSize > 0
213 ?
"Using ARGB Visual ID %d provided by EGL for config %d"
214 :
"Using Opaque Visual ID %d provided by EGL for config %d", visualId, configId);
220 uint8_t depth = configRedSize + configGreenSize + configBlueSize + configAlphaSize;
221 std::optional<
VisualInfo> matchingVisual = getVisualInfo(screen, std::nullopt, depth);
222 if (!matchingVisual) {
224 depth = configRedSize + configGreenSize + configBlueSize;
225 matchingVisual = getVisualInfo(screen, std::nullopt, depth);
229 visualId = matchingVisual->visualType.visual_id;
233 qCDebug(lcQpaGl,
"Using Visual ID %d provided by getVisualInfo for EGL config %d", visualId, configId);
237 qWarning(
"Unable to find an X11 visual which matches EGL config %d", configId);