xcb: Initialize OpenGL integration only when required

In some cases OpenGL integration may be unnecessary, e.g.
an application may set Qt::AA_ForceRasterWidgets attribute
and don't use OpenGL in any other way. In addition OpenGL
initialization can take noticeable time on some configurations.
So do it on demand only.

Change-Id: If88953f8d5c826bc96fd49eb397b5e1ad693546d
Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
This commit is contained in:
Alexander Volkov 2018-09-18 14:26:22 +03:00 committed by Shawn Rutledge
parent e4a5483eae
commit 60cecc86f8
4 changed files with 46 additions and 34 deletions

View File

@ -654,34 +654,6 @@ QXcbConnection::QXcbConnection(xcb_connection_t *c, int primaryScreenNumber,
if (!m_startupId.isNull())
qunsetenv("DESKTOP_STARTUP_ID");
QStringList glIntegrationNames;
glIntegrationNames << QStringLiteral("xcb_glx") << QStringLiteral("xcb_egl");
QString glIntegrationName = QString::fromLocal8Bit(qgetenv("QT_XCB_GL_INTEGRATION"));
if (!glIntegrationName.isEmpty()) {
qCDebug(lcQpaGl) << "QT_XCB_GL_INTEGRATION is set to" << glIntegrationName;
if (glIntegrationName != QLatin1String("none")) {
glIntegrationNames.removeAll(glIntegrationName);
glIntegrationNames.prepend(glIntegrationName);
} else {
glIntegrationNames.clear();
}
}
if (!glIntegrationNames.isEmpty()) {
qCDebug(lcQpaGl) << "Choosing xcb gl-integration based on following priority\n" << glIntegrationNames;
for (int i = 0; i < glIntegrationNames.size() && !m_glIntegration; i++) {
m_glIntegration = QXcbGlIntegrationFactory::create(glIntegrationNames.at(i));
if (m_glIntegration && !m_glIntegration->initialize(this)) {
qCDebug(lcQpaGl) << "Failed to initialize xcb gl-integration" << glIntegrationNames.at(i);
delete m_glIntegration;
m_glIntegration = nullptr;
}
}
if (!m_glIntegration)
qCDebug(lcQpaGl) << "Failed to create xcb gl-integration";
}
sync();
}
@ -2304,6 +2276,42 @@ Qt::KeyboardModifiers QXcbConnection::queryKeyboardModifiers() const
return keyboard()->translateModifiers(stateMask);
}
QXcbGlIntegration *QXcbConnection::glIntegration() const
{
if (m_glIntegrationInitialized)
return m_glIntegration;
QStringList glIntegrationNames;
glIntegrationNames << QStringLiteral("xcb_glx") << QStringLiteral("xcb_egl");
QString glIntegrationName = QString::fromLocal8Bit(qgetenv("QT_XCB_GL_INTEGRATION"));
if (!glIntegrationName.isEmpty()) {
qCDebug(lcQpaGl) << "QT_XCB_GL_INTEGRATION is set to" << glIntegrationName;
if (glIntegrationName != QLatin1String("none")) {
glIntegrationNames.removeAll(glIntegrationName);
glIntegrationNames.prepend(glIntegrationName);
} else {
glIntegrationNames.clear();
}
}
if (!glIntegrationNames.isEmpty()) {
qCDebug(lcQpaGl) << "Choosing xcb gl-integration based on following priority\n" << glIntegrationNames;
for (int i = 0; i < glIntegrationNames.size() && !m_glIntegration; i++) {
m_glIntegration = QXcbGlIntegrationFactory::create(glIntegrationNames.at(i));
if (m_glIntegration && !m_glIntegration->initialize(const_cast<QXcbConnection *>(this))) {
qCDebug(lcQpaGl) << "Failed to initialize xcb gl-integration" << glIntegrationNames.at(i);
delete m_glIntegration;
m_glIntegration = nullptr;
}
}
if (!m_glIntegration)
qCDebug(lcQpaGl) << "Failed to create xcb gl-integration";
}
m_glIntegrationInitialized = true;
return m_glIntegration;
}
bool QXcbConnection::event(QEvent *e)
{
if (e->type() == QEvent::User + 1) {

View File

@ -546,7 +546,7 @@ public:
bool canGrab() const { return m_canGrabServer; }
QXcbGlIntegration *glIntegration() const { return m_glIntegration; }
QXcbGlIntegration *glIntegration() const;
protected:
bool event(QEvent *e) override;
@ -727,7 +727,8 @@ private:
xcb_window_t m_clientLeader = 0;
QByteArray m_startupId;
QXcbSystemTrayTracker *m_systemTrayTracker = nullptr;
QXcbGlIntegration *m_glIntegration = nullptr;
mutable QXcbGlIntegration *m_glIntegration = nullptr;
mutable bool m_glIntegrationInitialized = false;
bool m_xiGrab = false;
QVector<int> m_xiMasterPointerIds;

View File

@ -231,11 +231,11 @@ QPlatformPixmap *QXcbIntegration::createPlatformPixmap(QPlatformPixmap::PixelTyp
QPlatformWindow *QXcbIntegration::createPlatformWindow(QWindow *window) const
{
QXcbScreen *screen = static_cast<QXcbScreen *>(window->screen()->handle());
QXcbGlIntegration *glIntegration = screen->connection()->glIntegration();
QXcbGlIntegration *glIntegration = nullptr;
const bool isTrayIconWindow = window->objectName() == QLatin1String("QSystemTrayIconSysWindow");
if (window->type() != Qt::Desktop && !isTrayIconWindow) {
if (window->supportsOpenGL()) {
glIntegration = defaultConnection()->glIntegration();
if (glIntegration) {
QXcbWindow *xcbWindow = glIntegration->createWindow(window);
xcbWindow->create();

View File

@ -397,9 +397,12 @@ void QXcbWindow::create()
| XCB_CW_SAVE_UNDER
| XCB_CW_EVENT_MASK;
static const bool haveOpenGL = QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL);
static auto haveOpenGL = []() {
static const bool result = QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL);
return result;
};
if ((window()->supportsOpenGL() && haveOpenGL) || m_format.hasAlpha()) {
if ((window()->supportsOpenGL() && haveOpenGL()) || m_format.hasAlpha()) {
m_cmap = xcb_generate_id(xcb_connection());
xcb_create_colormap(xcb_connection(),
XCB_COLORMAP_ALLOC_NONE,