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/eglconvenience/qeglplatformcontext_p.h | |
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/eglconvenience/qeglplatformcontext_p.h')
-rw-r--r-- | src/platformsupport/eglconvenience/qeglplatformcontext_p.h | 45 |
1 files changed, 36 insertions, 9 deletions
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; }; |