diff options
author | Laszlo Agocs <laszlo.agocs@digia.com> | 2014-04-06 15:53:55 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@digia.com> | 2014-06-25 12:39:07 +0200 |
commit | 27dc07fa050b5f216516debcd11802530a0c2d79 (patch) | |
tree | 30fd4a5663c84274d39e967eb6302ef44c2958f7 /src/plugins | |
parent | b69d537d7ffe385d374388a0754dd03ba25684c8 (diff) |
Support adapting an existing NSOpenGLContext in cocoa
Change-Id: I61b4055020c82dd5ac40850fe7def91d26ffb6fe
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoaglcontext.h | 4 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoaglcontext.mm | 30 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoaintegration.mm | 6 |
3 files changed, 37 insertions, 3 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.h b/src/plugins/platforms/cocoa/qcocoaglcontext.h index 30f1cdc278..2aa22ea759 100644 --- a/src/plugins/platforms/cocoa/qcocoaglcontext.h +++ b/src/plugins/platforms/cocoa/qcocoaglcontext.h @@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE class QCocoaGLContext : public QPlatformOpenGLContext { public: - QCocoaGLContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share); + QCocoaGLContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, const QVariant &nativeHandle); ~QCocoaGLContext(); QSurfaceFormat format() const; @@ -77,6 +77,8 @@ public: void windowWasHidden(); + QVariant nativeHandle() const; + private: void setActiveWindow(QWindow *window); void updateSurfaceFormat(); diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm index 3f61bd81ee..7b70fbb4bb 100644 --- a/src/plugins/platforms/cocoa/qcocoaglcontext.mm +++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm @@ -46,6 +46,7 @@ #include <qdebug.h> #include <QtCore/private/qcore_mac_p.h> #include <QtPlatformSupport/private/cglconvenience_p.h> +#include <QtPlatformHeaders/qcocoanativecontext.h> #import <Cocoa/Cocoa.h> @@ -117,11 +118,33 @@ static void updateFormatFromContext(QSurfaceFormat *format) format->setProfile(QSurfaceFormat::CompatibilityProfile); } -QCocoaGLContext::QCocoaGLContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share) +QCocoaGLContext::QCocoaGLContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, + const QVariant &nativeHandle) : m_context(nil), m_shareContext(nil), m_format(format) { + if (!nativeHandle.isNull()) { + if (!nativeHandle.canConvert<QCocoaNativeContext>()) { + qWarning("QCocoaGLContext: Requires a QCocoaNativeContext"); + return; + } + QCocoaNativeContext handle = nativeHandle.value<QCocoaNativeContext>(); + NSOpenGLContext *context = handle.context(); + if (!context) { + qWarning("QCocoaGLContext: No NSOpenGLContext given"); + return; + } + m_context = context; + [m_context retain]; + m_shareContext = share ? static_cast<QCocoaGLContext *>(share)->nsOpenGLContext() : nil; + // OpenGL surfaces can be ordered either above(default) or below the NSWindow. + const GLint order = qt_mac_resolveOption(1, "QT_MAC_OPENGL_SURFACE_ORDER"); + [m_context setValues:&order forParameter:NSOpenGLCPSurfaceOrder]; + updateSurfaceFormat(); + return; + } + // we only support OpenGL contexts under Cocoa if (m_format.renderableType() == QSurfaceFormat::DefaultRenderableType) m_format.setRenderableType(QSurfaceFormat::OpenGL); @@ -168,6 +191,11 @@ QCocoaGLContext::~QCocoaGLContext() [m_context release]; } +QVariant QCocoaGLContext::nativeHandle() const +{ + return QVariant::fromValue<QCocoaNativeContext>(QCocoaNativeContext(m_context)); +} + // Match up with createNSOpenGLPixelFormat! QSurfaceFormat QCocoaGLContext::format() const { diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index 8723b20615..b22bc71e30 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -422,7 +422,11 @@ QPlatformWindow *QCocoaIntegration::createPlatformWindow(QWindow *window) const QPlatformOpenGLContext *QCocoaIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const { - return new QCocoaGLContext(context->format(), context->shareHandle()); + QCocoaGLContext *glContext = new QCocoaGLContext(context->format(), + context->shareHandle(), + context->nativeHandle()); + context->setNativeHandle(glContext->nativeHandle()); + return glContext; } QPlatformBackingStore *QCocoaIntegration::createPlatformBackingStore(QWindow *window) const |