From 72785ac35aa7c95bc675f3d773c6a7764b5b0ddc Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 20 Jul 2012 15:44:00 +0200 Subject: Fix OSX regression of commit 20bf031db719f7baa4c6e74734fc999061e08fe2 - handling w/ non NSView handles (pbuffer) --- .../jogamp/opengl/macosx/cgl/MacOSXCGLContext.java | 17 ++++++++++++++++- .../jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java | 4 ++++ .../opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java | 6 ++++++ src/jogl/native/macosx/MacOSXWindowSystemInterface.m | 2 +- .../classes/jogamp/nativewindow/macosx/OSXUtil.java | 5 +++++ src/nativewindow/native/macosx/OSXmisc.m | 6 ++++++ 6 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java index 4bf2a3c9d..cb79e1560 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java @@ -54,6 +54,7 @@ import javax.media.opengl.GLContext; import javax.media.opengl.GLException; import javax.media.opengl.GLProfile; +import jogamp.nativewindow.macosx.OSXUtil; import jogamp.opengl.GLContextImpl; import jogamp.opengl.GLDrawableImpl; import jogamp.opengl.GLGraphicsConfigurationUtil; @@ -430,6 +431,19 @@ public abstract class MacOSXCGLContext extends GLContextImpl @Override public long create(long share, int ctp, int major, int minor) { long ctx = 0; + final long nsViewHandle; + if(drawable instanceof MacOSXCGLDrawable) { + // we allow null here! (special pbuffer case) + nsViewHandle = ((MacOSXCGLDrawable)MacOSXCGLContext.this.drawable).getNSViewHandle(); + } else { + // we only allow a valid NSView here + final long aHandle = drawable.getHandle(); + if( OSXUtil.isNSView(aHandle) ) { + nsViewHandle = aHandle; + } else { + throw new RuntimeException("Anonymous drawable instance's handle not of type NSView: "+drawable.getClass().getName()+", "+drawable); + } + } final NativeSurface surface = drawable.getNativeSurface(); final MacOSXCGLGraphicsConfiguration config = (MacOSXCGLGraphicsConfiguration) surface.getGraphicsConfiguration(); final OffscreenLayerSurface backingLayerHost = NativeWindowFactory.getOffscreenLayerSurface(surface, true); @@ -456,6 +470,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl System.err.println("NS create chosenCaps: "+chosenCaps); System.err.println("NS create pixelFormat: "+toHexString(pixelFormat)); System.err.println("NS create drawable native-handle: "+toHexString(drawable.getHandle())); + System.err.println("NS create drawable NSView-handle: "+toHexString(nsViewHandle)); System.err.println("NS create screen refresh-rate: "+sRefreshRate+" hz, "+screenVSyncTimeout+" micros"); // Thread.dumpStack(); } @@ -463,7 +478,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl int[] viewNotReady = new int[1]; // Try to allocate a context with this ctx = CGL.createContext(share, - drawable.getHandle(), allowIncompleteView, + nsViewHandle, allowIncompleteView, pixelFormat, chosenCaps.isBackgroundOpaque(), viewNotReady, 0); diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java index 841edb2b0..af767f0c3 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java @@ -105,6 +105,10 @@ public abstract class MacOSXCGLDrawable extends GLDrawableImpl { @Override protected void setRealizedImpl() { } + + protected long getNSViewHandle() { + return GLBackendType.NSOPENGL == openGLMode ? getHandle() : 0; + } protected void registerContext(MacOSXCGLContext ctx) { // NOTE: we need to keep track of the created contexts in order to diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java index b144c020d..8f2f386af 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java @@ -94,6 +94,12 @@ public class MacOSXPbufferCGLDrawable extends MacOSXCGLDrawable { registerContext(ctx); return ctx; } + + @Override + protected long getNSViewHandle() { + // pbuffer handle is NSOpenGLPixelBuffer + return 0; + } @Override public long getHandle() { diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m index d3f703142..f774f8f4a 100644 --- a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m +++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m @@ -515,7 +515,7 @@ NSOpenGLContext* createContext(NSOpenGLContext* share, DBG_PRINT("createContext.0: share %p, view %p, allowIncompleteView %d, pixfmt %p, opaque %d\n", share, view, (int)allowIncompleteView, fmt, opaque); - if (view != NULL) { + if (view != nil) { Bool viewReady = true; if(!allowIncompleteView) { diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java index 99fc9244e..4767dff18 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java @@ -59,6 +59,10 @@ public class OSXUtil { return false; } + public static boolean isNSView(long object) { + return isNSView0(object); + } + public static Point GetLocationOnScreen(long windowOrView, int src_x, int src_y) { return (Point) GetLocationOnScreen0(windowOrView, src_x, src_y); } @@ -129,6 +133,7 @@ public class OSXUtil { } */ private static native boolean initIDs0(); + private static native boolean isNSView0(long object); private static native Object GetLocationOnScreen0(long windowOrView, int src_x, int src_y); private static native long CreateNSWindow0(int x, int y, int width, int height); private static native void DestroyNSWindow0(long nsWindow); diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m index ebfefe345..37fa4c88f 100644 --- a/src/nativewindow/native/macosx/OSXmisc.m +++ b/src/nativewindow/native/macosx/OSXmisc.m @@ -92,6 +92,12 @@ Java_jogamp_nativewindow_macosx_OSXUtil_initIDs0(JNIEnv *env, jclass _unused) { return JNI_TRUE; } +JNIEXPORT jboolean JNICALL +Java_jogamp_nativewindow_macosx_OSXUtil_isNSView0(JNIEnv *env, jclass _unused, jlong object) { + NSObject *nsObj = (NSObject*) (intptr_t) object; + return [nsObj isMemberOfClass:[NSView class]]; +} + /* * Class: Java_jogamp_nativewindow_macosx_OSXUtil * Method: getLocationOnScreen0 -- cgit v1.2.3