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