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/plugins/platforms/cocoa/qcocoaglcontext.mm | |
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/plugins/platforms/cocoa/qcocoaglcontext.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoaglcontext.mm | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm index c049ca60f2..c2fcb6cdbc 100644 --- a/src/plugins/platforms/cocoa/qcocoaglcontext.mm +++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm @@ -45,7 +45,6 @@ #include "qcocoascreen.h" #include <qdebug.h> -#include <QtPlatformHeaders/qcocoanativecontext.h> #include <dlfcn.h> static inline QByteArray getGlString(GLenum param) @@ -65,30 +64,23 @@ QCocoaGLContext::QCocoaGLContext(QOpenGLContext *context) { } -void QCocoaGLContext::initialize() +QCocoaGLContext::QCocoaGLContext(NSOpenGLContext *nativeContext) + : QPlatformOpenGLContext() { - QVariant nativeHandle = context()->nativeHandle(); - if (!nativeHandle.isNull()) { - if (!nativeHandle.canConvert<QCocoaNativeContext>()) { - qCWarning(lcQpaOpenGLContext, "QOpenGLContext native handle must be a QCocoaNativeContext"); - return; - } - m_context = nativeHandle.value<QCocoaNativeContext>().context(); - if (!m_context) { - qCWarning(lcQpaOpenGLContext, "QCocoaNativeContext's NSOpenGLContext cannot be null"); - return; - } - - [m_context retain]; - - // Note: We have no way of knowing whether the NSOpenGLContext was created with the - // share context as reported by the QOpenGLContext, but we just have to trust that - // it was. It's okey, as the only thing we're using it for is to report isShared(). - if (QPlatformOpenGLContext *shareContext = context()->shareHandle()) - m_shareContext = static_cast<QCocoaGLContext *>(shareContext)->nativeContext(); + m_context = [nativeContext retain]; +} - updateSurfaceFormat(); - return; +void QCocoaGLContext::initialize() +{ + if (m_context) { + // Note: We have no way of knowing whether the NSOpenGLContext was created with the + // share context as reported by the QOpenGLContext, but we just have to trust that + // it was. It's okey, as the only thing we're using it for is to report isShared(). + if (QPlatformOpenGLContext *shareContext = context()->shareHandle()) + m_shareContext = static_cast<QCocoaGLContext *>(shareContext)->nativeContext(); + + updateSurfaceFormat(); + return; } // ----------- Default case, we own the NSOpenGLContext ----------- @@ -139,9 +131,6 @@ void QCocoaGLContext::initialize() return; } - // The native handle should reflect the underlying context, even if we created it - context()->setNativeHandle(QVariant::fromValue<QCocoaNativeContext>(m_context)); - // --------------------- Set NSOpenGLContext properties --------------------- const GLint interval = m_format.swapInterval() >= 0 ? m_format.swapInterval() : 1; |