diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-10-29 16:23:10 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-10-30 16:32:57 +0000 |
commit | ecd11e498f18a18a79a062c39c0917439479ae4d (patch) | |
tree | 87b0b918aaf6c05385e1035dcd2fc1dd519bd181 /src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp | |
parent | d017baac8993757c035d5ba2829e88e946c169cc (diff) |
Offscreen QPA: implement a native interface
Many code paths simply expect to have a native interface
available, and won't check if a plugin is returning nullptr
for it. This leads to crashes or local workarounds
(e.g. 3197932e6fb03fb9c0ff669af858cb94e3836d79). Instead,
have offscreen implement a dummy native interface.
This requires shuffling some code for the X11 integration.
Pick-to: 5.15
Change-Id: I2bdceee379e4ded9b085ebbb4d03d1e074f60726
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp')
-rw-r--r-- | src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp b/src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp index bb4d8aeaa1..a11da2d543 100644 --- a/src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp +++ b/src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp @@ -76,6 +76,8 @@ private: QOffscreenX11Connection *m_connection; }; +QOffscreenX11Integration::~QOffscreenX11Integration() = default; + bool QOffscreenX11Integration::hasCapability(QPlatformIntegration::Capability cap) const { switch (cap) { @@ -88,21 +90,27 @@ bool QOffscreenX11Integration::hasCapability(QPlatformIntegration::Capability ca QPlatformOpenGLContext *QOffscreenX11Integration::createPlatformOpenGLContext(QOpenGLContext *context) const { - if (!m_connection) - m_connection.reset(new QOffscreenX11Connection); + auto &connection = nativeInterface()->m_connection; + + if (!connection) + connection.reset(new QOffscreenX11Connection); - if (!m_connection->display()) + if (!connection->display()) return nullptr; - return new QOffscreenX11GLXContext(m_connection->x11Info(), context); + return new QOffscreenX11GLXContext(connection->x11Info(), context); } -QPlatformNativeInterface *QOffscreenX11Integration::nativeInterface() const +QOffscreenX11PlatformNativeInterface *QOffscreenX11Integration::nativeInterface() const { - return const_cast<QOffscreenX11Integration *>(this); + if (!m_nativeInterface) + m_nativeInterface.reset(new QOffscreenX11PlatformNativeInterface); + return static_cast<QOffscreenX11PlatformNativeInterface *>(m_nativeInterface.data()); } -void *QOffscreenX11Integration::nativeResourceForScreen(const QByteArray &resource, QScreen *screen) +QOffscreenX11PlatformNativeInterface::~QOffscreenX11PlatformNativeInterface() = default; + +void *QOffscreenX11PlatformNativeInterface::nativeResourceForScreen(const QByteArray &resource, QScreen *screen) { Q_UNUSED(screen); if (resource.toLower() == QByteArrayLiteral("display") ) { @@ -114,7 +122,7 @@ void *QOffscreenX11Integration::nativeResourceForScreen(const QByteArray &resour } #ifndef QT_NO_OPENGL -void *QOffscreenX11Integration::nativeResourceForContext(const QByteArray &resource, QOpenGLContext *context) { +void *QOffscreenX11PlatformNativeInterface::nativeResourceForContext(const QByteArray &resource, QOpenGLContext *context) { if (resource.toLower() == QByteArrayLiteral("glxconfig") ) { if (context) { QOffscreenX11GLXContext *glxPlatformContext = static_cast<QOffscreenX11GLXContext *>(context->handle()); |