aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/native/macosx/MacOSXWindowSystemInterface.m
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/native/macosx/MacOSXWindowSystemInterface.m')
-rw-r--r--src/jogl/native/macosx/MacOSXWindowSystemInterface.m167
1 files changed, 91 insertions, 76 deletions
diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m
index 8ac9f4700..d4d3ddad9 100644
--- a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m
+++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m
@@ -446,7 +446,7 @@ NSOpenGLPixelFormat* createPixelFormat(int* iattrs, int niattrs, int* ivalues) {
NSOpenGLPixelFormat* fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
// if(fmt == nil) { fallback to a [NSOpenGLView defaultPixelFormat] crashed (SIGSEGV) on 10.6.7/NV }
- DBG_PRINT("createPixelFormat.X: pfmt %p\n", fmt);
+ DBG_PRINT("\ncreatePixelFormat.X: pfmt %p\n", fmt);
[pool release];
return fmt;
@@ -501,9 +501,31 @@ NSView* getNSView(NSOpenGLContext* ctx) {
return view;
}
+static Bool lockViewIfReady(NSView *view) {
+ Bool viewReady = false;
+
+ if (view != nil) {
+ if ([view lockFocusIfCanDraw] == NO) {
+ DBG_PRINT("lockViewIfReady.1 [view lockFocusIfCanDraw] failed\n");
+ } else {
+ NSRect frame = [view frame];
+ if ((frame.size.width == 0) || (frame.size.height == 0)) {
+ [view unlockFocus];
+ DBG_PRINT("lockViewIfReady.2 view.frame size %dx%d\n", (int)frame.size.width, (int)frame.size.height);
+ } else {
+ DBG_PRINT("lockViewIfReady.X ready and locked\n");
+ viewReady = true;
+ }
+ }
+ } else {
+ DBG_PRINT("lockViewIfReady.3 nil view\n");
+ }
+ return viewReady;
+}
+
NSOpenGLContext* createContext(NSOpenGLContext* share,
NSView* view,
- Bool isBackingLayerView,
+ Bool incompleteView,
NSOpenGLPixelFormat* fmt,
Bool opaque,
int* viewNotReady)
@@ -512,56 +534,32 @@ NSOpenGLContext* createContext(NSOpenGLContext* share,
getRendererInfo();
- DBG_PRINT("createContext.0: share %p, view %p, isBackingLayer %d, pixfmt %p, opaque %d\n",
- share, view, (int)isBackingLayerView, fmt, opaque);
-
- if (view != NULL) {
- Bool viewReady = true;
+ DBG_PRINT("createContext.0: share %p, view %p, incompleteView %d, pixfmt %p, opaque %d\n",
+ share, view, (int)incompleteView, fmt, opaque);
- if(!isBackingLayerView) {
- if ([view lockFocusIfCanDraw] == NO) {
- DBG_PRINT("createContext.1 [view lockFocusIfCanDraw] failed\n");
- viewReady = false;
- }
- }
- if(viewReady) {
- NSRect frame = [view frame];
- if ((frame.size.width == 0) || (frame.size.height == 0)) {
- if(!isBackingLayerView) {
- [view unlockFocus];
- }
- DBG_PRINT("createContext.2 view.frame size %dx%d\n", (int)frame.size.width, (int)frame.size.height);
- viewReady = false;
- }
- }
+ Bool viewReadyAndLocked = incompleteView ? false : lockViewIfReady(view);
- if (!viewReady)
- {
- if (viewNotReady != NULL)
- {
- *viewNotReady = 1;
- }
+ if (nil != viewNotReady) {
+ *viewNotReady = 1;
+ }
- // the view is not ready yet
- DBG_PRINT("createContext.X: view not ready yet\n");
- [pool release];
- return NULL;
- }
+ if (nil != view && !incompleteView && !viewReadyAndLocked) {
+ DBG_PRINT("createContext.X: Assumed complete view not ready yet\n");
+ [pool release];
+ return NULL;
}
-
+
NSOpenGLContext* ctx = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:share];
- if (ctx != nil) {
- if (view != nil) {
+ if ( nil != ctx && nil != view ) {
if(!opaque) {
GLint zeroOpacity = 0;
[ctx setValues:&zeroOpacity forParameter:NSOpenGLCPSurfaceOpacity];
}
- [ctx setView:view];
- if(!isBackingLayerView) {
+ if( viewReadyAndLocked ) {
+ [ctx setView:view];
[view unlockFocus];
}
- }
}
DBG_PRINT("createContext.X: ctx: %p\n", ctx);
@@ -569,6 +567,32 @@ NSOpenGLContext* createContext(NSOpenGLContext* share,
return ctx;
}
+void setContextView(NSOpenGLContext* ctx, NSView* view) {
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ if ( nil != ctx ) {
+ if ( nil != view ) {
+ Bool viewReadyAndLocked = lockViewIfReady(view);
+ DBG_PRINT("setContextView.0: ctx %p, view %p: setView: %d\n", ctx, view, viewReadyAndLocked);
+ if( viewReadyAndLocked ) {
+ [ctx setView:view];
+ [view unlockFocus];
+ }
+ }
+ DBG_PRINT("setContextView.X\n");
+ }
+ [pool release];
+}
+
+void clearDrawable(NSOpenGLContext* ctx) {
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ if ( nil != ctx ) {
+ DBG_PRINT("clearDrawable.0: %p\n", ctx);
+ [ctx clearDrawable];
+ DBG_PRINT("clearDrawable.X\n");
+ }
+ [pool release];
+}
+
Bool makeCurrentContext(NSOpenGLContext* ctx) {
#if 0
// we issue the CGL Lock from Java upfront!
@@ -628,7 +652,12 @@ void setContextOpacity(NSOpenGLContext* ctx, int opacity) {
void updateContext(NSOpenGLContext* ctx) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- [ctx update];
+ NSView *nsView = [ctx view];
+ if(NULL != nsView) {
+ DBG_PRINT("updateContext.0: ctx %p, ctx.view %p\n", ctx, nsView);
+ [ctx update];
+ DBG_PRINT("updateContext.X\n");
+ }
[pool release];
}
@@ -638,7 +667,10 @@ void copyContext(NSOpenGLContext* dest, NSOpenGLContext* src, int mask) {
void* updateContextRegister(NSOpenGLContext* ctx, NSView* view) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+
+ DBG_PRINT("updateContextRegister.0: ctx %p, view %p\n", ctx, view);
ContextUpdater *contextUpdater = [[ContextUpdater alloc] initWithContext: ctx view: view];
+ DBG_PRINT("updateContextRegister.X: ctxupd %p\n", contextUpdater);
[pool release];
return contextUpdater;
}
@@ -658,44 +690,62 @@ void updateContextUnregister(void* updater) {
ContextUpdater *contextUpdater = (ContextUpdater *)updater;
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ DBG_PRINT("updateContextUnregister.0: ctxupd %p\n", contextUpdater);
[contextUpdater release];
+ DBG_PRINT("updateContextUnregister.X\n");
[pool release];
}
NSOpenGLPixelBuffer* createPBuffer(int renderTarget, int internalFormat, int width, int height) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ DBG_PRINT("createPBuffer.0: renderTarget 0x%x, ifmt 0x%x, %dx%d: \n", renderTarget, internalFormat, width, height);
NSOpenGLPixelBuffer* pBuffer = [[NSOpenGLPixelBuffer alloc]
initWithTextureTarget:renderTarget
textureInternalFormat:internalFormat
textureMaxMipMapLevel:0
pixelsWide:width
pixelsHigh:height];
+ DBG_PRINT("createPBuffer.X: res %p\n", pBuffer);
[pool release];
return pBuffer;
}
Bool destroyPBuffer(NSOpenGLPixelBuffer* pBuffer) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ DBG_PRINT("destroyPBuffer.0: pbuffer %p\n", pBuffer);
[pBuffer release];
+ DBG_PRINT("destroyPBuffer.X\n");
[pool release];
return true;
}
void setContextPBuffer(NSOpenGLContext* ctx, NSOpenGLPixelBuffer* pBuffer) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ DBG_PRINT("setContextPBuffer.0: ctx %p, pbuffer %p\n", ctx, pBuffer);
[ctx setPixelBuffer: pBuffer
cubeMapFace: 0
mipMapLevel: 0
currentVirtualScreen: [ctx currentVirtualScreen]];
+ DBG_PRINT("setContextPBuffer.X\n");
[pool release];
}
void setContextTextureImageToPBuffer(NSOpenGLContext* ctx, NSOpenGLPixelBuffer* pBuffer, GLenum colorBuffer) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ DBG_PRINT("setContextTextureImageToPBuffer.0: ctx %p, pbuffer %p, colorBuffer 0x%x\n", ctx, pBuffer, (int)colorBuffer);
[ctx setTextureImageToPixelBuffer: pBuffer colorBuffer: colorBuffer];
+ DBG_PRINT("setContextTextureImageToPBuffer.X\n");
[pool release];
}
+Bool isNSOpenGLPixelBuffer(uint64_t object) {
+ NSObject *nsObj = (NSObject*) (intptr_t) object;
+ DBG_PRINT("isNSOpenGLPixelBuffer.0: obj %p\n", object);
+ Bool res = [nsObj isKindOfClass:[NSOpenGLPixelBuffer class]];
+ DBG_PRINT("isNSOpenGLPixelBuffer.X: res %d\n", (int)res);
+ return res;
+}
+
#include <mach-o/dyld.h>
Bool imagesInitialized = false;
static char libGLStr[] = "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib";
@@ -746,38 +796,3 @@ void resetGammaRamp() {
CGDisplayRestoreColorSyncSettings();
}
-/***
- * The following static functions are copied out of NEWT's OSX impl. <src/newt/native/MacWindow.m>
- * May need to push code to NativeWindow, to remove duplication.
- */
-static NSScreen * NewtScreen_getNSScreenByIndex(int screen_idx) {
- NSArray *screens = [NSScreen screens];
- if(screen_idx<0) screen_idx=0;
- if(screen_idx>=[screens count]) screen_idx=0;
- return (NSScreen *) [screens objectAtIndex: screen_idx];
-}
-static CGDirectDisplayID NewtScreen_getCGDirectDisplayIDByNSScreen(NSScreen *screen) {
- // Mind: typedef uint32_t CGDirectDisplayID; - however, we assume it's 64bit on 64bit ?!
- NSDictionary * dict = [screen deviceDescription];
- NSNumber * val = (NSNumber *) [dict objectForKey: @"NSScreenNumber"];
- // [NSNumber integerValue] returns NSInteger which is 32 or 64 bit native size
- return (CGDirectDisplayID) [val integerValue];
-}
-static long GetDictionaryLong(CFDictionaryRef theDict, const void* key)
-{
- long value = 0;
- CFNumberRef numRef;
- numRef = (CFNumberRef)CFDictionaryGetValue(theDict, key);
- if (numRef != NULL)
- CFNumberGetValue(numRef, kCFNumberLongType, &value);
- return value;
-}
-#define CGDDGetModeRefreshRate(mode) GetDictionaryLong((mode), kCGDisplayRefreshRate)
-
-int getScreenRefreshRate(int scrn_idx) {
- NSScreen *screen = NewtScreen_getNSScreenByIndex(scrn_idx);
- CGDirectDisplayID display = NewtScreen_getCGDirectDisplayIDByNSScreen(screen);
- CFDictionaryRef mode = CGDisplayCurrentMode(display);
- return CGDDGetModeRefreshRate(mode);
-}
-