Add cglContextForContext to QCocoaNativeInterface.
authorZeno Albisser <zeno@webkit.org>
Fri, 12 Oct 2012 14:33:40 +0000 (16:33 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 15 Oct 2012 19:51:41 +0000 (21:51 +0200)
This change enables receiving the native CGLContextObj that is used
by a QOpenGLContext. This clearly is non-public api that is only meant to
be used as a last resort for cases where it is really necessary to
get hold of a native context object.

Change-Id: Id00efc88a73d7df04a68c022f19d9d1c4f6d386b
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
src/plugins/platforms/cocoa/qcocoanativeinterface.h
src/plugins/platforms/cocoa/qcocoanativeinterface.mm

index 6f99dc4..e4b52b9 100644 (file)
@@ -56,8 +56,11 @@ class QCocoaNativeInterface : public QPlatformNativeInterface
 public:
     QCocoaNativeInterface();
 
+    void *nativeResourceForContext(const QByteArray &resourceString, QOpenGLContext *context);
     void *nativeResourceForWindow(const QByteArray &resourceString, QWindow *window);
 
+    static void *cglContextForContext(QOpenGLContext *context);
+
 public Q_SLOTS:
     void onAppFocusWindowChanged(QWindow *window);
 
index e504008..7f37b97 100644 (file)
@@ -65,6 +65,17 @@ QCocoaNativeInterface::QCocoaNativeInterface()
 {
 }
 
+void *QCocoaNativeInterface::nativeResourceForContext(const QByteArray &resourceString, QOpenGLContext *context)
+{
+    if (!context)
+        return 0;
+
+    if (resourceString.toLower() == "cglcontextobj")
+        return cglContextForContext(context);
+
+    return 0;
+}
+
 void *QCocoaNativeInterface::nativeResourceForWindow(const QByteArray &resourceString, QWindow *window)
 {
     if (!window->handle()) {
@@ -109,4 +120,17 @@ void QCocoaNativeInterface::onAppFocusWindowChanged(QWindow *window)
     QCocoaMenuBar::updateMenuBarImmediately();
 }
 
+void *QCocoaNativeInterface::cglContextForContext(QOpenGLContext* context)
+{
+    if (context) {
+        QCocoaGLContext *cocoaGLContext = static_cast<QCocoaGLContext *>(context->handle());
+        if (cocoaGLContext) {
+            NSOpenGLContext *nsOpenGLContext = cocoaGLContext->nsOpenGLContext();
+            if (nsOpenGLContext)
+                return [nsOpenGLContext CGLContextObj];
+        }
+    }
+    return 0;
+}
+
 QT_END_NAMESPACE