From 881078d7b5331d62fa52021eae24c115fab87861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 1 Aug 2018 12:43:16 +0200 Subject: [PATCH] macOS: Disambiguate use of native handles in QCocoaGLContext We only need the QVariant native handle when creating the context, so there's no need for a getter, and we then rename the NSOpenGLContext getter to match e.g. QCocoaScreen::nativeScreen(). Change-Id: I041e0eff39af9c8836d8ecd560ea07e92dc63e03 Reviewed-by: Gabriel de Dietrich --- src/plugins/platforms/cocoa/qcocoaglcontext.h | 3 +-- src/plugins/platforms/cocoa/qcocoaglcontext.mm | 11 +++-------- src/plugins/platforms/cocoa/qcocoaintegration.mm | 4 +++- src/plugins/platforms/cocoa/qcocoanativeinterface.mm | 8 +++----- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.h b/src/plugins/platforms/cocoa/qcocoaglcontext.h index 74f3442c1d..1bfe906942 100644 --- a/src/plugins/platforms/cocoa/qcocoaglcontext.h +++ b/src/plugins/platforms/cocoa/qcocoaglcontext.h @@ -67,8 +67,7 @@ public: void windowWasHidden(); - NSOpenGLContext *nsOpenGLContext() const; - QVariant nativeHandle() const; + NSOpenGLContext *nativeContext() const; QFunctionPointer getProcAddress(const char *procName) override; diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm index febe255dfc..306a143f98 100644 --- a/src/plugins/platforms/cocoa/qcocoaglcontext.mm +++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm @@ -78,7 +78,7 @@ QCocoaGLContext::QCocoaGLContext(const QSurfaceFormat &format, QPlatformOpenGLCo } m_context = context; [m_context retain]; - m_shareContext = share ? static_cast(share)->nsOpenGLContext() : nil; + m_shareContext = share ? static_cast(share)->nativeContext() : nil; updateSurfaceFormat(); return; } @@ -89,7 +89,7 @@ QCocoaGLContext::QCocoaGLContext(const QSurfaceFormat &format, QPlatformOpenGLCo if (m_format.renderableType() != QSurfaceFormat::OpenGL) return; - m_shareContext = share ? static_cast(share)->nsOpenGLContext() : nil; + m_shareContext = share ? static_cast(share)->nativeContext() : nil; if (m_shareContext) { // Allow sharing between 3.2 Core and 4.1 Core profile versions in @@ -468,16 +468,11 @@ bool QCocoaGLContext::isSharing() const return m_shareContext != nil; } -NSOpenGLContext *QCocoaGLContext::nsOpenGLContext() const +NSOpenGLContext *QCocoaGLContext::nativeContext() const { return m_context; } -QVariant QCocoaGLContext::nativeHandle() const -{ - return QVariant::fromValue(QCocoaNativeContext(m_context)); -} - QFunctionPointer QCocoaGLContext::getProcAddress(const char *procName) { return (QFunctionPointer)dlsym(RTLD_DEFAULT, procName); diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index 8ad76eb05e..d13d08d843 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -59,6 +59,8 @@ #include #include +#include + #include #ifdef QT_WIDGETS_LIB @@ -361,7 +363,7 @@ QPlatformOpenGLContext *QCocoaIntegration::createPlatformOpenGLContext(QOpenGLCo QCocoaGLContext *glContext = new QCocoaGLContext(context->format(), context->shareHandle(), context->nativeHandle()); - context->setNativeHandle(glContext->nativeHandle()); + context->setNativeHandle(QVariant::fromValue(glContext->nativeContext())); return glContext; } #endif diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm index 3c5f4e68db..228df50d86 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm @@ -104,7 +104,7 @@ void *QCocoaNativeInterface::nativeResourceForWindow(const QByteArray &resourceS return static_cast(window->handle())->m_view; #ifndef QT_NO_OPENGL } else if (resourceString == "nsopenglcontext") { - return static_cast(window->handle())->currentContext()->nsOpenGLContext(); + return static_cast(window->handle())->currentContext()->nativeContext(); #endif } else if (resourceString == "nswindow") { return static_cast(window->handle())->nativeWindow(); @@ -228,10 +228,8 @@ void *QCocoaNativeInterface::cglContextForContext(QOpenGLContext* context) void *QCocoaNativeInterface::nsOpenGLContextForContext(QOpenGLContext* context) { if (context) { - QCocoaGLContext *cocoaGLContext = static_cast(context->handle()); - if (cocoaGLContext) { - return cocoaGLContext->nsOpenGLContext(); - } + if (QCocoaGLContext *cocoaGLContext = static_cast(context->handle())) + return cocoaGLContext->nativeContext(); } return nullptr; }