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.cpp | |
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.cpp')
-rw-r--r-- | src/platformsupport/eglconvenience/qeglplatformcontext.cpp | 38 |
1 files changed, 6 insertions, 32 deletions
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; |