diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-06-08 20:00:36 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-07-02 10:27:50 +0200 |
commit | 6ff79478a44fce12ca18832a56db4a370a9ff417 (patch) | |
tree | 2bcd7ab7bac46fe28e0828e0a704649bbc025e8f /src/platformsupport | |
parent | 037dce81fc27ec241edb6829f6df41927b80666e (diff) |
Introduce platform API abstraction for QOpenGLContext
The API is available by including qopenglcontext.h as usual,
but scoped in the QPlatformInterface namespace. The namespace
exposes platform specific type-safe interfaces that provide:
a) Factory functions for adopting native contexts, e.g.
QCocoaGLContext::fromNative(nsContext, shareContext);
b) Access to underlying native handles, e.g.
openGLContext->platformInterface<QCocoaGLContext>->nativeContext()
c) Platform specific functionality, e.g.
static QWGLContext::openGLModuleHandle()
openGLContext->platformInterface<QEGLContext>->doSomething();
The platform interfaces live close to the classes they extend,
removing the need for complex indirection and plumbing, and
avoids kitchen-sink modules and APIs such as the extras modules,
QPlatformFunctions, or QPlatformNativeInterface.
In the case of QOpenGLContext these platform APIs are backed
by the platform plugin, so dynamic_cast is used to ensure the
platform plugin supports the requested interface, but this is
and implementation detail. The interface APIs are agnostic
to where the implementation lives, while still being available
to the user as part of the APIs they extend/augment.
The documentation will be restored when the dust settles.
Task-number: QTBUG-80233
Change-Id: Iac612403383991c4b24064332542a6e4bcbb3293
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/platformsupport')
4 files changed, 44 insertions, 43 deletions
diff --git a/src/platformsupport/eglconvenience/CMakeLists.txt b/src/platformsupport/eglconvenience/CMakeLists.txt index 1858dc7e90..4b709161fd 100644 --- a/src/platformsupport/eglconvenience/CMakeLists.txt +++ b/src/platformsupport/eglconvenience/CMakeLists.txt @@ -48,6 +48,6 @@ qt_extend_target(EglSupport CONDITION NOT QT_FEATURE_egl_x11 ) qt_extend_target(EglSupport CONDITION QT_FEATURE_dlopen - PUBLIC_LIBRARIES + LIBRARIES ${CMAKE_DL_LIBS} ) diff --git a/src/platformsupport/eglconvenience/eglconvenience.pro b/src/platformsupport/eglconvenience/eglconvenience.pro index df21f14697..e9ee52b53b 100644 --- a/src/platformsupport/eglconvenience/eglconvenience.pro +++ b/src/platformsupport/eglconvenience/eglconvenience.pro @@ -38,6 +38,6 @@ qtConfig(egl_x11) { } CONFIG += egl -qtConfig(dlopen): QMAKE_USE += libdl +qtConfig(dlopen): QMAKE_USE_PRIVATE += libdl load(qt_module) diff --git a/src/platformsupport/eglconvenience/qeglplatformcontext.cpp b/src/platformsupport/eglconvenience/qeglplatformcontext.cpp index d38a850065..c82473ebbb 100644 --- a/src/platformsupport/eglconvenience/qeglplatformcontext.cpp +++ b/src/platformsupport/eglconvenience/qeglplatformcontext.cpp @@ -42,7 +42,6 @@ #include "qeglpbuffer_p.h" #include <qpa/qplatformwindow.h> #include <QOpenGLContext> -#include <QtPlatformHeaders/QEGLNativeContext> #include <QDebug> #if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED) @@ -115,25 +114,13 @@ QT_BEGIN_NAMESPACE #endif QEGLPlatformContext::QEGLPlatformContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display, - EGLConfig *config, const QVariant &nativeHandle, Flags flags) + EGLConfig *config, Flags flags) : m_eglDisplay(display) - , m_swapInterval(-1) - , m_swapIntervalEnvChecked(false) - , m_swapIntervalFromEnv(-1) , m_flags(flags) + , m_ownsContext(true) { - if (nativeHandle.isNull()) { - m_eglConfig = config ? *config : q_configFromGLFormat(display, format); - m_ownsContext = true; - init(format, share); - } else { - m_ownsContext = false; - adopt(nativeHandle, share); - } -} + m_eglConfig = config ? *config : q_configFromGLFormat(display, format); -void QEGLPlatformContext::init(const QSurfaceFormat &format, QPlatformOpenGLContext *share) -{ m_format = q_glFormatFromConfig(m_eglDisplay, m_eglConfig, format); // m_format now has the renderableType() resolved (it cannot be Default anymore) // but does not yet contain version, profile, options. @@ -212,24 +199,11 @@ void QEGLPlatformContext::init(const QSurfaceFormat &format, QPlatformOpenGLCont // Cannot just call updateFormatFromGL() since it relies on virtuals. Defer it to initialize(). } -void QEGLPlatformContext::adopt(const QVariant &nativeHandle, QPlatformOpenGLContext *share) +void QEGLPlatformContext::adopt(EGLContext context, EGLDisplay display, QPlatformOpenGLContext *share) { - if (!nativeHandle.canConvert<QEGLNativeContext>()) { - qWarning("QEGLPlatformContext: Requires a QEGLNativeContext"); - return; - } - QEGLNativeContext handle = qvariant_cast<QEGLNativeContext>(nativeHandle); - EGLContext context = handle.context(); - if (!context) { - qWarning("QEGLPlatformContext: No EGLContext given"); - return; - } + Q_ASSERT(!m_ownsContext); - // A context belonging to a given EGLDisplay cannot be used with another one. - if (handle.display() != m_eglDisplay) { - qWarning("QEGLPlatformContext: Cannot adopt context from different display"); - return; - } + m_eglDisplay = display; // Figure out the EGLConfig. EGLint value = 0; diff --git a/src/platformsupport/eglconvenience/qeglplatformcontext_p.h b/src/platformsupport/eglconvenience/qeglplatformcontext_p.h index f0388cd29c..610588568e 100644 --- a/src/platformsupport/eglconvenience/qeglplatformcontext_p.h +++ b/src/platformsupport/eglconvenience/qeglplatformcontext_p.h @@ -56,10 +56,12 @@ #include <qpa/qplatformopenglcontext.h> #include <QtCore/QVariant> #include <QtEglSupport/private/qt_egl_p.h> +#include <QtGui/private/qopenglcontext_p.h> QT_BEGIN_NAMESPACE -class QEGLPlatformContext : public QPlatformOpenGLContext +class QEGLPlatformContext : public QPlatformOpenGLContext, + public QPlatformInterface::QEGLContext { public: enum Flag { @@ -68,8 +70,31 @@ public: Q_DECLARE_FLAGS(Flags, Flag) QEGLPlatformContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display, - EGLConfig *config = nullptr, const QVariant &nativeHandle = QVariant(), - Flags flags = { }); + EGLConfig *config = nullptr, Flags flags = { }); + + template <typename T> + static QOpenGLContext *createFrom(EGLContext context, EGLDisplay contextDisplay, + EGLDisplay platformDisplay, QOpenGLContext *shareContext) + { + if (!context) + return nullptr; + + // A context belonging to a given EGLDisplay cannot be used with another one + if (contextDisplay != platformDisplay) { + qWarning("QEGLPlatformContext: Cannot adopt context from different display"); + return nullptr; + } + + QPlatformOpenGLContext *shareHandle = shareContext ? shareContext->handle() : nullptr; + + auto *resultingContext = new QOpenGLContext; + auto *contextPrivate = QOpenGLContextPrivate::get(resultingContext); + auto *platformContext = new T; + platformContext->adopt(context, contextDisplay, shareHandle); + contextPrivate->adopt(platformContext); + return resultingContext; + } + ~QEGLPlatformContext(); void initialize() override; @@ -82,19 +107,21 @@ public: bool isSharing() const override { return m_shareContext != EGL_NO_CONTEXT; } bool isValid() const override { return m_eglContext != EGL_NO_CONTEXT; } + EGLContext nativeContext() const override { return eglContext(); } + EGLContext eglContext() const; EGLDisplay eglDisplay() const; EGLConfig eglConfig() const; protected: + QEGLPlatformContext() {} // For adoption virtual EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface) = 0; virtual EGLSurface createTemporaryOffscreenSurface(); virtual void destroyTemporaryOffscreenSurface(EGLSurface surface); virtual void runGLChecks(); private: - void init(const QSurfaceFormat &format, QPlatformOpenGLContext *share); - void adopt(const QVariant &nativeHandle, QPlatformOpenGLContext *share); + void adopt(EGLContext context, EGLDisplay display, QPlatformOpenGLContext *shareContext); void updateFormatFromGL(); EGLContext m_eglContext; @@ -103,11 +130,11 @@ private: EGLConfig m_eglConfig; QSurfaceFormat m_format; EGLenum m_api; - int m_swapInterval; - bool m_swapIntervalEnvChecked; - int m_swapIntervalFromEnv; + int m_swapInterval = -1; + bool m_swapIntervalEnvChecked = false; + int m_swapIntervalFromEnv = -1; Flags m_flags; - bool m_ownsContext; + bool m_ownsContext = false; QVector<EGLint> m_contextAttrs; }; |