| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qxcbglxwindow.h" |
| 5 | |
| 6 | #include "qxcbscreen.h" |
| 7 | #include <QtGui/private/qglxconvenience_p.h> |
| 8 | #include <QDebug> |
| 9 | |
| 10 | QT_BEGIN_NAMESPACE |
| 11 | |
| 12 | QXcbGlxWindow::QXcbGlxWindow(QWindow *window) |
| 13 | : QXcbWindow(window) |
| 14 | { |
| 15 | } |
| 16 | |
| 17 | QXcbGlxWindow::~QXcbGlxWindow() |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | const xcb_visualtype_t *QXcbGlxWindow::createVisual() |
| 22 | { |
| 23 | QXcbScreen *scr = xcbScreen(); |
| 24 | if (!scr) |
| 25 | return QXcbWindow::createVisual(); |
| 26 | |
| 27 | qCDebug(lcQpaGl) << "Requested format before FBConfig/Visual selection:"<< m_format; |
| 28 | |
| 29 | Display *dpy = static_cast<Display *>(scr->connection()->xlib_display()); |
| 30 | const char *glxExts = glXQueryExtensionsString(dpy, screen: scr->screenNumber()); |
| 31 | int flags = 0; |
| 32 | if (glxExts) { |
| 33 | qCDebug(lcQpaGl, "Available GLX extensions: %s", glxExts); |
| 34 | if (strstr(haystack: glxExts, needle: "GLX_EXT_framebuffer_sRGB") || strstr(haystack: glxExts, needle: "GLX_ARB_framebuffer_sRGB")) |
| 35 | flags |= QGLX_SUPPORTS_SRGB; |
| 36 | } |
| 37 | |
| 38 | const auto formatBackup = m_format; |
| 39 | XVisualInfo *visualInfo = qglx_findVisualInfo(display: dpy, screen: scr->screenNumber(), format: &m_format, GLX_WINDOW_BIT, flags); |
| 40 | if (!visualInfo) { |
| 41 | qCDebug(lcQpaGl) << "No XVisualInfo for format"<< m_format; |
| 42 | // restore initial format before requesting it again |
| 43 | m_format = formatBackup; |
| 44 | return QXcbWindow::createVisual(); |
| 45 | } |
| 46 | const xcb_visualtype_t *xcb_visualtype = scr->visualForId(visualid: visualInfo->visualid); |
| 47 | XFree(visualInfo); |
| 48 | |
| 49 | qCDebug(lcQpaGl) << "Got format:"<< m_format; |
| 50 | |
| 51 | return xcb_visualtype; |
| 52 | } |
| 53 | |
| 54 | QT_END_NAMESPACE |
| 55 |
