8#include <QtGui/QOffscreenSurface>
9#include <QtGui/private/qeglconvenience_p.h>
10#include <QtGui/private/qeglstreamconvenience_p.h>
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);
50 xcb_depth_next(&depthIterator);
60 , m_egl_display(EGL_NO_DISPLAY)
62 qCDebug(lcQpaGl) <<
"Xcb EGL gl-integration created";
67 if (m_egl_display != EGL_NO_DISPLAY)
68 eglTerminate(m_egl_display);
75 const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
77#if QT_CONFIG(xcb_xlib)
78 if (extensions && strstr(extensions,
"EGL_EXT_platform_x11")) {
81 m_connection->xlib_display(),
87 m_egl_display = eglGetDisplay(
reinterpret_cast<EGLNativeDisplayType
>(m_connection->xlib_display()));
90 if (extensions && (strstr(extensions,
"EGL_EXT_platform_xcb") || strstr(extensions,
"EGL_MESA_platform_xcb"))) {
93 reinterpret_cast<void *
>(
connection->xcb_connection()),
99 bool success = eglInitialize(m_egl_display, &major, &minor);
100#if QT_CONFIG(egl_x11)
102 m_egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
103 qCDebug(lcQpaGl) <<
"Xcb EGL gl-integration retrying with display" << m_egl_display;
104 success = eglInitialize(m_egl_display, &major, &minor);
111 qCDebug(lcQpaGl) <<
"Xcb EGL gl-integration successfully initialized";
113 qCWarning(lcQpaGl) <<
"Xcb EGL gl-integration initialize failed";
129 return platformContext;
145 xcb_visualid_t visualId = 0;
148 EGLint configRedSize = 0;
151 EGLint configGreenSize = 0;
154 EGLint configBlueSize = 0;
157 EGLint configAlphaSize = 0;
161 int configId = eglValue;
168 std::optional<VisualInfo> chosenVisualInfo = getVisualInfo(
screen, visualId);
169 if (chosenVisualInfo) {
175 const char *vendor = eglQueryString(
eglDisplay(), EGL_VENDOR);
176 if (vendor && strstr(vendor,
"Vivante"))
179 int visualRedSize =
qPopulationCount(chosenVisualInfo->visualType.red_mask);
180 int visualGreenSize =
qPopulationCount(chosenVisualInfo->visualType.green_mask);
181 int visualBlueSize =
qPopulationCount(chosenVisualInfo->visualType.blue_mask);
182 int visualAlphaSize = chosenVisualInfo->depth - visualRedSize - visualBlueSize - visualGreenSize;
184 const bool visualMatchesConfig = visualRedSize >= configRedSize
185 && visualGreenSize >= configGreenSize
186 && visualBlueSize >= configBlueSize
187 && visualAlphaSize >= configAlphaSize;
191 if (!visualMatchesConfig) {
194 "EGL suggested using X Visual ID %d (%d %d %d %d depth %d) for EGL config %d"
195 "(%d %d %d %d), but this is incompatible",
196 visualId, visualRedSize, visualGreenSize, visualBlueSize, visualAlphaSize, chosenVisualInfo->depth,
197 configId, configRedSize, configGreenSize, configBlueSize, configAlphaSize);
200 qCDebug(lcQpaGl,
"EGL suggested using X Visual ID %d for EGL config %d, but that isn't a valid ID",
206 qCDebug(lcQpaGl,
"EGL did not suggest a VisualID (EGL_NATIVE_VISUAL_ID was zero) for EGLConfig %d", configId);
209 qCDebug(lcQpaGl, configAlphaSize > 0
210 ?
"Using ARGB Visual ID %d provided by EGL for config %d"
211 :
"Using Opaque Visual ID %d provided by EGL for config %d", visualId, configId);
217 uint8_t
depth = configRedSize + configGreenSize + configBlueSize + configAlphaSize;
218 std::optional<VisualInfo> matchingVisual = getVisualInfo(
screen, std::nullopt,
depth);
219 if (!matchingVisual) {
221 depth = configRedSize + configGreenSize + configBlueSize;
222 matchingVisual = getVisualInfo(
screen, std::nullopt,
depth);
226 visualId = matchingVisual->visualType.visual_id;
230 qCDebug(lcQpaGl,
"Using Visual ID %d provided by getVisualInfo for EGL config %d", visualId, configId);
234 qWarning(
"Unable to find an X11 visual which matches EGL config %d", configId);
A pbuffer-based implementation of QPlatformOffscreenSurface for EGL.
PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display
QScreen * screen() const
Returns the screen to which the offscreen surface is connected.
QSurfaceFormat requestedFormat() const
Returns the requested surfaceformat of this offscreen surface.
The QPlatformOpenGLContext class provides an abstraction for native GL contexts.
void reset(T *other=nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval< T * >())))
Deletes the existing object it is pointing to (if any), and sets its pointer to other.
QPlatformScreen * handle() const
Get the platform screen handle.
QOpenGLContext * createOpenGLContext(EGLContext context, EGLDisplay display, QOpenGLContext *shareContext) const override
QPlatformOffscreenSurface * createPlatformOffscreenSurface(QOffscreenSurface *surface) const override
QXcbWindow * createWindow(QWindow *window) const override
bool initialize(QXcbConnection *connection) override
xcb_visualid_t getCompatibleVisualId(xcb_screen_t *screen, EGLConfig config) const
EGLDisplay eglDisplay() const
QPlatformOpenGLContext * createPlatformOpenGLContext(QOpenGLContext *context) const override
struct wl_display * display
Combined button and popup list for selecting options.
std::optional< VisualInfo > getVisualInfo(xcb_screen_t *screen, std::optional< xcb_visualid_t > requestedVisualId, std::optional< uint8_t > requestedDepth=std::nullopt)
Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR uint qPopulationCount(quint32 v) noexcept
DBusConnection * connection
bool q_hasEglExtension(EGLDisplay display, const char *extensionName)
typedef EGLDisplay(EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYEXTPROC)(EGLenum platform
#define EGL_PLATFORM_XCB_KHR
#define EGL_PLATFORM_X11_KHR
#define qCWarning(category,...)
#define qCDebug(category,...)
GLint GLenum GLsizei GLsizei GLsizei depth
xcb_visualtype_t visualType