diff --git a/src/plugins/platforms/offscreen/qoffscreencommon.cpp b/src/plugins/platforms/offscreen/qoffscreencommon.cpp index 3d02721869..33b98cfa1b 100644 --- a/src/plugins/platforms/offscreen/qoffscreencommon.cpp +++ b/src/plugins/platforms/offscreen/qoffscreencommon.cpp @@ -232,4 +232,6 @@ void QOffscreenBackingStore::clearHash() QHash QOffscreenBackingStore::m_backingStoreForWinIdHash; +QOffscreenPlatformNativeInterface::~QOffscreenPlatformNativeInterface() = default; + QT_END_NAMESPACE diff --git a/src/plugins/platforms/offscreen/qoffscreencommon.h b/src/plugins/platforms/offscreen/qoffscreencommon.h index abb641fbbc..7f92c5b4d9 100644 --- a/src/plugins/platforms/offscreen/qoffscreencommon.h +++ b/src/plugins/platforms/offscreen/qoffscreencommon.h @@ -45,6 +45,7 @@ #include #endif #include +#include #include #include @@ -116,6 +117,12 @@ private: static QHash m_backingStoreForWinIdHash; }; +class QOffscreenPlatformNativeInterface : public QPlatformNativeInterface +{ +public: + ~QOffscreenPlatformNativeInterface(); +}; + QT_END_NAMESPACE #endif diff --git a/src/plugins/platforms/offscreen/qoffscreenintegration.cpp b/src/plugins/platforms/offscreen/qoffscreenintegration.cpp index c9f97ce46a..cc45776397 100644 --- a/src/plugins/platforms/offscreen/qoffscreenintegration.cpp +++ b/src/plugins/platforms/offscreen/qoffscreenintegration.cpp @@ -244,6 +244,13 @@ QAbstractEventDispatcher *QOffscreenIntegration::createEventDispatcher() const #endif } +QPlatformNativeInterface *QOffscreenIntegration::nativeInterface() const +{ + if (!m_nativeInterface) + m_nativeInterface.reset(new QOffscreenPlatformNativeInterface); + return m_nativeInterface.get(); +} + static QString themeName() { return QStringLiteral("offscreen"); } QStringList QOffscreenIntegration::themeNames() const diff --git a/src/plugins/platforms/offscreen/qoffscreenintegration.h b/src/plugins/platforms/offscreen/qoffscreenintegration.h index be47313913..38d145eee3 100644 --- a/src/plugins/platforms/offscreen/qoffscreenintegration.h +++ b/src/plugins/platforms/offscreen/qoffscreenintegration.h @@ -71,19 +71,22 @@ public: QPlatformFontDatabase *fontDatabase() const override; QAbstractEventDispatcher *createEventDispatcher() const override; + QPlatformNativeInterface *nativeInterface() const override; + QStringList themeNames() const override; QPlatformTheme *createPlatformTheme(const QString &name) const override; static QOffscreenIntegration *createOffscreenIntegration(const QStringList& paramList); QList screens() const; -private: +protected: QScopedPointer m_fontDatabase; #if QT_CONFIG(draganddrop) QScopedPointer m_drag; #endif QScopedPointer m_inputContext; QScopedPointer m_services; + mutable QScopedPointer m_nativeInterface; QList m_screens; bool m_windowFrameMarginsEnabled = true; }; 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 (!m_connection->display()) + if (!connection) + connection.reset(new QOffscreenX11Connection); + + 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(this); + if (!m_nativeInterface) + m_nativeInterface.reset(new QOffscreenX11PlatformNativeInterface); + return static_cast(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(context->handle()); diff --git a/src/plugins/platforms/offscreen/qoffscreenintegration_x11.h b/src/plugins/platforms/offscreen/qoffscreenintegration_x11.h index 01a75510fb..ed4b83c0a4 100644 --- a/src/plugins/platforms/offscreen/qoffscreenintegration_x11.h +++ b/src/plugins/platforms/offscreen/qoffscreenintegration_x11.h @@ -41,6 +41,7 @@ #define QOFFSCREENINTEGRATION_X11_H #include "qoffscreenintegration.h" +#include "qoffscreencommon.h" #include #include @@ -52,22 +53,27 @@ QT_BEGIN_NAMESPACE class QOffscreenX11Connection; class QOffscreenX11Info; -class QOffscreenX11Integration : public QOffscreenIntegration, public QPlatformNativeInterface +class QOffscreenX11PlatformNativeInterface : public QOffscreenPlatformNativeInterface { public: - bool hasCapability(QPlatformIntegration::Capability cap) const override; + ~QOffscreenX11PlatformNativeInterface(); - QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const override; - QPlatformNativeInterface *nativeInterface()const override; - - // QPlatformNativeInterface void *nativeResourceForScreen(const QByteArray &resource, QScreen *screen) override; #ifndef QT_NO_OPENGL void *nativeResourceForContext(const QByteArray &resource, QOpenGLContext *context) override; #endif -private: - mutable QScopedPointer m_connection; + QScopedPointer m_connection; +}; + +class QOffscreenX11Integration : public QOffscreenIntegration +{ +public: + ~QOffscreenX11Integration(); + bool hasCapability(QPlatformIntegration::Capability cap) const override; + + QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const override; + QOffscreenX11PlatformNativeInterface *nativeInterface() const override; }; class QOffscreenX11Connection {