aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--make/build-nativewindow.xml10
-rw-r--r--make/config/jogl/cgl-macosx.cfg6
-rw-r--r--make/stub_includes/macosx/AppKit/NSOpenGL.h3
-rw-r--r--make/stub_includes/macosx/AppKit/NSOpenGLLayer.h1
-rw-r--r--make/stub_includes/macosx/AppKit/NSOpenGLView.h1
-rw-r--r--make/stub_includes/macosx/OpenGL/CGLDevice.h2
-rw-r--r--make/stub_includes/macosx/OpenGL/OpenGL.h31
-rw-r--r--make/stub_includes/macosx/QuartzCore/CALayer.h1
-rw-r--r--make/stub_includes/opengl/macosx-window-system.h67
-rw-r--r--src/jogl/native/macosx/MacOSXCustomCGLCode.c5
-rw-r--r--src/jogl/native/macosx/MacOSXWindowSystemInterface.m363
-rw-r--r--src/nativewindow/native/macosx/OSXmisc.m65
-rw-r--r--src/newt/native/NewtMacWindow.h3
-rw-r--r--src/newt/native/NewtMacWindow.m30
14 files changed, 397 insertions, 191 deletions
diff --git a/make/build-nativewindow.xml b/make/build-nativewindow.xml
index 4bbe667b8..b50871a24 100644
--- a/make/build-nativewindow.xml
+++ b/make/build-nativewindow.xml
@@ -354,6 +354,10 @@
<compilerarg value="-I/usr/X11R6/include" />
</compiler>
+ <compiler id="compiler.cfg.macosx.nativewindow" extends="compiler.cfg.macosx">
+ <compilerarg value="-I${java.osx.frameworks.dir}/JavaNativeFoundation.framework/Headers" />
+ </compiler>
+
<!-- linker configuration -->
<linker id="linker.cfg.freebsd.nativewindow.x11" extends="linker.cfg.freebsd">
@@ -444,6 +448,10 @@
<linker id="linker.cfg.macosx.nativewindow" extends="linker.cfg.macosx">
<linkerarg value="-framework" />
<linkerarg value="Cocoa" />
+ <linkerarg value="-framework" />
+ <linkerarg value="JavaNativeFoundation" />
+ <linkerarg value="-F" />
+ <linkerarg value="${java.osx.frameworks.dir}" />
</linker>
<linker id="linker.cfg.hpux.nativewindow" extends="linker.cfg.hpux">
@@ -547,7 +555,7 @@
<target name="c.configure.x11" if="isX11" />
<target name="c.configure.macosx" if="isOSX">
- <property name="compiler.cfg.id" value="compiler.cfg.macosx" />
+ <property name="compiler.cfg.id" value="compiler.cfg.macosx.nativewindow" />
<property name="linker.cfg.id.oswin" value="linker.cfg.macosx.nativewindow" />
</target>
diff --git a/make/config/jogl/cgl-macosx.cfg b/make/config/jogl/cgl-macosx.cfg
index 06bc94626..6be8abe76 100644
--- a/make/config/jogl/cgl-macosx.cfg
+++ b/make/config/jogl/cgl-macosx.cfg
@@ -20,6 +20,12 @@ Opaque long CGLShareGroupObj
Opaque long CGLPBufferObj
Opaque long CGLPixelFormatObj
+Opaque long NSOpenGLPixelFormat *
+Opaque long NSOpenGLContext *
+Opaque long NSView *
+Opaque long NSOpenGLPixelBuffer *
+Opaque long NSOpenGLLayer *
+
CustomCCode #include </usr/include/machine/types.h>
CustomCCode #include "macosx-window-system.h"
diff --git a/make/stub_includes/macosx/AppKit/NSOpenGL.h b/make/stub_includes/macosx/AppKit/NSOpenGL.h
new file mode 100644
index 000000000..1b7656dc1
--- /dev/null
+++ b/make/stub_includes/macosx/AppKit/NSOpenGL.h
@@ -0,0 +1,3 @@
+typedef struct _NSOpenGLPixelFormat NSOpenGLPixelFormat;
+typedef struct _NSOpenGLContext NSOpenGLContext;
+typedef struct _NSOpenGLPixelBuffer NSOpenGLPixelBuffer;
diff --git a/make/stub_includes/macosx/AppKit/NSOpenGLLayer.h b/make/stub_includes/macosx/AppKit/NSOpenGLLayer.h
new file mode 100644
index 000000000..2e5e81a68
--- /dev/null
+++ b/make/stub_includes/macosx/AppKit/NSOpenGLLayer.h
@@ -0,0 +1 @@
+typedef struct _NSOpenGLLayer NSOpenGLLayer;
diff --git a/make/stub_includes/macosx/AppKit/NSOpenGLView.h b/make/stub_includes/macosx/AppKit/NSOpenGLView.h
new file mode 100644
index 000000000..6492287df
--- /dev/null
+++ b/make/stub_includes/macosx/AppKit/NSOpenGLView.h
@@ -0,0 +1 @@
+typedef struct _NSOpenGLView NSOpenGLView;
diff --git a/make/stub_includes/macosx/OpenGL/CGLDevice.h b/make/stub_includes/macosx/OpenGL/CGLDevice.h
new file mode 100644
index 000000000..1d4170975
--- /dev/null
+++ b/make/stub_includes/macosx/OpenGL/CGLDevice.h
@@ -0,0 +1,2 @@
+typedef struct _cglShareGroupObj* CGLShareGroupObj;
+
diff --git a/make/stub_includes/macosx/OpenGL/OpenGL.h b/make/stub_includes/macosx/OpenGL/OpenGL.h
index 1a3ddf203..33cfa46b6 100644
--- a/make/stub_includes/macosx/OpenGL/OpenGL.h
+++ b/make/stub_includes/macosx/OpenGL/OpenGL.h
@@ -2,10 +2,13 @@
OpenGL.h to expose portions of the low-level CGL API to Java */
/* Typedefs to get things working */
-typedef struct _cglObj* CGLContextObj;
-typedef struct _cglObj* CGLShareGroupObj;
-typedef struct _cglObj* CGLPBufferObj;
-typedef struct _cglObj* CGLPixelFormatObj;
+typedef struct _cglContextObj* CGLContextObj;
+typedef struct _cglPBufferObj* CGLPBufferObj;
+typedef struct _cglPixelFormatObj* CGLPixelFormatObj;
+
+typedef int GLint; /* 4-byte signed */
+typedef unsigned int GLenum;
+typedef int GLsizei; /* 4-byte signed */
/*
** Attribute names for CGLChoosePixelFormat and CGLDescribePixelFormat.
@@ -105,7 +108,7 @@ typedef enum _CGLContextParameter {
/* Pixel format manipulation */
CGLError CGLChoosePixelFormat(const CGLPixelFormatAttribute *attribs,
CGLPixelFormatObj *pix,
- long *npix);
+ GLint *npix);
CGLError CGLDestroyPixelFormat(CGLPixelFormatObj pix);
CGLPixelFormatObj CGLGetPixelFormat ( CGLContextObj ctx );
@@ -123,16 +126,16 @@ CGLError CGLCopyContext ( CGLContextObj src, CGLContextObj dst, int mask );
CGLShareGroupObj CGLGetShareGroup(CGLContextObj ctx);
-/* PBuffer manipulation */
-CGLError CGLCreatePBuffer(long width,
- long height,
- unsigned long target,
- unsigned long internalFormat,
- long max_level,
+/* PBuffer manipulation (deprecated in 10.7) */
+CGLError CGLCreatePBuffer(GLsizei width,
+ GLsizei height,
+ GLenum target,
+ GLenum internalFormat,
+ GLint max_level,
CGLPBufferObj* pbuffer);
CGLError CGLDestroyPBuffer(CGLPBufferObj pbuffer);
CGLError CGLSetPBuffer(CGLContextObj ctx,
CGLPBufferObj pbuffer,
- unsigned long face,
- long level,
- long screen);
+ GLenum face,
+ GLint level,
+ GLint screen);
diff --git a/make/stub_includes/macosx/QuartzCore/CALayer.h b/make/stub_includes/macosx/QuartzCore/CALayer.h
new file mode 100644
index 000000000..a5a6579a6
--- /dev/null
+++ b/make/stub_includes/macosx/QuartzCore/CALayer.h
@@ -0,0 +1 @@
+typedef struct _CALayer CALayer;
diff --git a/make/stub_includes/opengl/macosx-window-system.h b/make/stub_includes/opengl/macosx-window-system.h
index 65d8e41f7..fe0c0b1bc 100644
--- a/make/stub_includes/opengl/macosx-window-system.h
+++ b/make/stub_includes/opengl/macosx-window-system.h
@@ -7,55 +7,60 @@
compilation then the build fails.
*/
+#include <AppKit/NSView.h>
+#include <AppKit/NSOpenGL.h>
+#include <AppKit/NSOpenGLLayer.h>
+// #include <AppKit/NSOpenGLView.h>
+#include <OpenGL/CGLDevice.h>
+#include <OpenGL/OpenGL.h>
+
typedef int Bool;
// CGL ..
-void CGLQueryPixelFormat(void* pixelFormat, int* iattrs, int niattrs, int* ivalues);
+void CGLQueryPixelFormat(CGLPixelFormatObj fmt, int* iattrs, int niattrs, int* ivalues);
// NS ..
-void* createPixelFormat(int* iattrs, int niattrs, int* ivalues);
-void queryPixelFormat(void* pixelFormat, int* iattrs, int niattrs, int* ivalues);
-void deletePixelFormat(void* pixelFormat);
+NSOpenGLPixelFormat* createPixelFormat(int* iattrs, int niattrs, int* ivalues);
+void queryPixelFormat(NSOpenGLPixelFormat* fmt, int* iattrs, int niattrs, int* ivalues);
+void deletePixelFormat(NSOpenGLPixelFormat* fmt);
// NS ..
-void *getCurrentContext(void);
-void *getNSView(void* nsContext);
+NSOpenGLContext* getCurrentContext(void);
+CGLContextObj getCGLContext(NSOpenGLContext* ctx);
+NSView* getNSView(NSOpenGLContext* ctx);
-void* createContext(void* shareContext,
- void* nsView,
- void* pixelFormat,
+NSOpenGLContext* createContext(NSOpenGLContext* shareContext,
+ NSView* nsView,
+ Bool isBackingLayerView,
+ NSOpenGLPixelFormat* pixelFormat,
Bool opaque,
int* viewNotReady);
-void *getCGLContext(void* nsContext);
-Bool makeCurrentContext(void* nsContext);
-Bool clearCurrentContext(void *nsContext);
-Bool deleteContext(void* nsContext, Bool releaseOnMainThread);
-Bool flushBuffer(void* nsContext);
-void setContextOpacity(void* nsContext, int opacity);
-void updateContext(void* nsContext);
-void copyContext(void* destContext, void* srcContext, int mask);
-
-void* updateContextRegister(void* nsContext, void* nsView);
+Bool makeCurrentContext(NSOpenGLContext* ctx);
+Bool clearCurrentContext(NSOpenGLContext *ctx);
+Bool deleteContext(NSOpenGLContext* ctx, Bool releaseOnMainThread);
+Bool flushBuffer(NSOpenGLContext* ctx);
+void setContextOpacity(NSOpenGLContext* ctx, int opacity);
+void updateContext(NSOpenGLContext* ctx);
+void copyContext(NSOpenGLContext* dest, NSOpenGLContext* src, int mask);
+
+void* updateContextRegister(NSOpenGLContext* ctx, NSView* view);
Bool updateContextNeedsUpdate(void* updater);
void updateContextUnregister(void* updater);
-void* createPBuffer(int renderTarget, int internalFormat, int width, int height);
-Bool destroyPBuffer(void* pBuffer);
-void setContextPBuffer(void* nsContext, void* pBuffer);
-void setContextTextureImageToPBuffer(void* nsContext, void* pBuffer, int colorBuffer);
+NSOpenGLPixelBuffer* createPBuffer(int renderTarget, int internalFormat, int width, int height);
+Bool destroyPBuffer(NSOpenGLPixelBuffer* pBuffer);
+void setContextPBuffer(NSOpenGLContext* ctx, NSOpenGLPixelBuffer* pBuffer);
+void setContextTextureImageToPBuffer(NSOpenGLContext* ctx, NSOpenGLPixelBuffer* pBuffer, int colorBuffer);
+
+NSOpenGLLayer* createNSOpenGLLayer(NSOpenGLContext* ctx, NSOpenGLPixelFormat* fmt, NSView* view, Bool opaque);
+void setNSOpenGLLayerNeedsDisplay(NSOpenGLLayer* glLayer);
+void releaseNSOpenGLLayer(NSOpenGLLayer *glLayer);
void* getProcAddress(const char *procName);
-void setSwapInterval(void* nsContext, int interval);
+void setSwapInterval(NSOpenGLContext* ctx, int interval);
/* Gamma-related functionality */
Bool setGammaRamp(int tableSize, float* redRamp, float* greenRamp, float* blueRamp);
void resetGammaRamp();
-/****************************************************************************************/
-/* Java2D/JOGL bridge support; need to be able to create pbuffers and
- contexts using the CGL APIs to be able to share textures, etc. with
- contexts created by Java2D/JOGL bridge, which are CGLContextObjs */
-
-/* Pick up copies of CGL signatures from Mac OS X stub_includes/window-system-build directory */
-#include <OpenGL/OpenGL.h>
diff --git a/src/jogl/native/macosx/MacOSXCustomCGLCode.c b/src/jogl/native/macosx/MacOSXCustomCGLCode.c
index c29be889d..f8b7a800f 100644
--- a/src/jogl/native/macosx/MacOSXCustomCGLCode.c
+++ b/src/jogl/native/macosx/MacOSXCustomCGLCode.c
@@ -5,8 +5,7 @@
#include </usr/include/machine/types.h>
#include "macosx-window-system.h"
-void CGLQueryPixelFormat(void* pixelFormat, int* iattrs, int niattrs, int* ivalues) {
- CGLPixelFormatObj pix = (CGLPixelFormatObj) pixelFormat;
+void CGLQueryPixelFormat(CGLPixelFormatObj fmt, int* iattrs, int niattrs, int* ivalues) {
// FIXME: think about how specifying this might affect the API
int virtualScreen = 0;
@@ -14,7 +13,7 @@ void CGLQueryPixelFormat(void* pixelFormat, int* iattrs, int niattrs, int* ivalu
GLint value;
for (i = 0; i < niattrs && iattrs[i]>0; i++) {
CGLPixelFormatAttribute attr = (CGLPixelFormatAttribute) iattrs[i];
- if ( kCGLNoError == CGLDescribePixelFormat(pix, virtualScreen, attr, &value) ) {
+ if ( kCGLNoError == CGLDescribePixelFormat(fmt, virtualScreen, attr, &value) ) {
ivalues[i] = value;
} else {
ivalues[i] = 0;
diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m
index 751fba9c0..7c10545f3 100644
--- a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m
+++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m
@@ -19,6 +19,15 @@
#import <OpenGL/CGLTypes.h>
#import <jni.h>
+#define VERBOSE_ON 1
+
+#ifdef VERBOSE_ON
+ // #define DBG_PRINT(...) NSLog(@ ## __VA_ARGS__)
+ #define DBG_PRINT(...) fprintf(stderr, __VA_ARGS__); fflush(stderr)
+#else
+ #define DBG_PRINT(...)
+#endif
+
#ifndef CGL_VERSION_1_3
#warning this SDK doesn't support OpenGL profile
#endif
@@ -377,7 +386,7 @@ long validateParameter(NSOpenGLPixelFormatAttribute attribute, long value)
return value;
}
-void* createPixelFormat(int* iattrs, int niattrs, int* ivalues) {
+NSOpenGLPixelFormat* createPixelFormat(int* iattrs, int niattrs, int* ivalues) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
getRendererInfo();
@@ -451,9 +460,8 @@ void* createPixelFormat(int* iattrs, int niattrs, int* ivalues) {
return fmt;
}
-void queryPixelFormat(void* pixelFormat, int* iattrs, int niattrs, int* ivalues) {
+void queryPixelFormat(NSOpenGLPixelFormat* fmt, int* iattrs, int niattrs, int* ivalues) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- NSOpenGLPixelFormat* fmt = (NSOpenGLPixelFormat*) pixelFormat;
GLint tmp;
// FIXME: think about how specifying this might affect the API
GLint virtualScreen = 0;
@@ -468,16 +476,43 @@ void queryPixelFormat(void* pixelFormat, int* iattrs, int niattrs, int* ivalues)
[pool release];
}
-void deletePixelFormat(void* pixelFormat) {
+void deletePixelFormat(NSOpenGLPixelFormat* fmt) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- NSOpenGLPixelFormat* fmt = (NSOpenGLPixelFormat*) pixelFormat;
[fmt release];
[pool release];
}
-void* createContext(void* shareContext,
- void* view,
- void* pixelFormat,
+NSOpenGLContext* getCurrentContext() {
+ NSOpenGLContext *ctx = NULL;
+
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ ctx = [NSOpenGLContext currentContext];
+ [pool release];
+ return ctx;
+}
+
+CGLContextObj getCGLContext(NSOpenGLContext* ctx) {
+ void * cglContext = NULL;
+
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ cglContext = [ctx CGLContextObj];
+ [pool release];
+ return cglContext;
+}
+
+NSView* getNSView(NSOpenGLContext* ctx) {
+ NSView* view = NULL;
+
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ view = [ctx view];
+ [pool release];
+ return view;
+}
+
+NSOpenGLContext* createContext(NSOpenGLContext* share,
+ NSView* view,
+ Bool isBackingLayerView,
+ NSOpenGLPixelFormat* fmt,
Bool opaque,
int* viewNotReady)
{
@@ -485,27 +520,22 @@ void* createContext(void* shareContext,
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- NSView *nsView = NULL;
- NSObject *nsObj = (NSObject*) view;
-
- if( nsObj != NULL && [nsObj isKindOfClass:[NSView class]] ) {
- nsView = (NSView*)nsObj;
- }
-
- if (nsView != NULL)
- {
+ if (view != NULL) {
Bool viewReady = true;
- if ([nsView lockFocusIfCanDraw] == NO)
- {
- viewReady = false;
+ if(!isBackingLayerView) {
+ if ([view lockFocusIfCanDraw] == NO) {
+ DBG_PRINT("createContext [view lockFocusIfCanDraw] failed\n");
+ viewReady = false;
+ }
}
- else
- {
- NSRect frame = [nsView frame];
- if ((frame.size.width == 0) || (frame.size.height == 0))
- {
- [nsView unlockFocus];
+ if(viewReady) {
+ NSRect frame = [view frame];
+ if ((frame.size.width == 0) || (frame.size.height == 0)) {
+ if(!isBackingLayerView) {
+ [view unlockFocus];
+ }
+ DBG_PRINT("createContext view.frame size %dx%d\n", (int)frame.size.width, (int)frame.size.height);
viewReady = false;
}
}
@@ -523,126 +553,80 @@ void* createContext(void* shareContext,
}
}
- NSOpenGLContext* nsContext = [[NSOpenGLContext alloc]
- initWithFormat: (NSOpenGLPixelFormat*) pixelFormat
- shareContext: (NSOpenGLContext*) shareContext];
+ NSOpenGLContext* ctx = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:share];
- if (nsContext != nil) {
- if (nsView != nil) {
- if(!opaque) {
- GLint zeroOpacity = 0;
- [nsContext setValues:&zeroOpacity forParameter:NSOpenGLCPSurfaceOpacity];
- }
- [nsContext setView:nsView];
- [nsView unlockFocus];
- }
+ if (ctx != nil) {
+ if (view != nil) {
+ if(!opaque) {
+ GLint zeroOpacity = 0;
+ [ctx setValues:&zeroOpacity forParameter:NSOpenGLCPSurfaceOpacity];
+ }
+ [ctx setView:view];
+ if(!isBackingLayerView) {
+ [view unlockFocus];
}
+ }
+ }
[pool release];
- return nsContext;
-}
-
-void * getCurrentContext() {
- NSOpenGLContext *nsContext = NULL;
-
- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- nsContext = [NSOpenGLContext currentContext];
- [pool release];
- return nsContext;;
+ return ctx;
}
-void * getCGLContext(void* nsJContext) {
- NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext;
- void * cglContext = NULL;
-
+Bool makeCurrentContext(NSOpenGLContext* ctx) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- cglContext = [nsContext CGLContextObj];
- [pool release];
- return cglContext;
-}
-
-void * getNSView(void* nsJContext) {
- NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext;
- void * view = NULL;
-
- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- view = [nsContext view];
- [pool release];
- return view;
-}
-
-Bool makeCurrentContext(void* nsJContext) {
- NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext;
-
- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- [nsContext makeCurrentContext];
+ [ctx makeCurrentContext];
[pool release];
return true;
}
-Bool clearCurrentContext(void* nsJContext) {
- NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext;
-
+Bool clearCurrentContext(NSOpenGLContext* ctx) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSOpenGLContext *currentNSContext = [NSOpenGLContext currentContext];
- if( currentNSContext != nsContext ) {
- [nsContext makeCurrentContext];
+ if( currentNSContext != ctx ) {
+ [ctx makeCurrentContext];
}
[NSOpenGLContext clearCurrentContext];
[pool release];
return true;
}
-Bool deleteContext(void* nsJContext, Bool releaseOnMainThread) {
- NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext;
-
+Bool deleteContext(NSOpenGLContext* ctx, Bool releaseOnMainThread) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- [nsContext clearDrawable];
+ [ctx clearDrawable];
if(releaseOnMainThread && NO == [NSThread isMainThread]) {
- [nsContext performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:YES];
+ [ctx performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:YES];
} else {
// would hangs for ~10s for 1 of a shared context set or offscreen context, set releaseOnMainThread=true !
- [nsContext release];
+ [ctx release];
}
[pool release];
return true;
}
-Bool flushBuffer(void* nsJContext) {
- NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext;
-
+Bool flushBuffer(NSOpenGLContext* ctx) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- [nsContext flushBuffer];
+ [ctx flushBuffer];
[pool release];
return true;
}
-void setContextOpacity(void* nsJContext, int opacity) {
- NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext;
-
- [nsContext setValues:&opacity forParameter:NSOpenGLCPSurfaceOpacity];
+void setContextOpacity(NSOpenGLContext* ctx, int opacity) {
+ [ctx setValues:&opacity forParameter:NSOpenGLCPSurfaceOpacity];
}
-void updateContext(void* nsJContext) {
- NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext;
-
+void updateContext(NSOpenGLContext* ctx) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- [nsContext update];
+ [ctx update];
[pool release];
}
-void copyContext(void* destContext, void* srcContext, int mask) {
- NSOpenGLContext *src = (NSOpenGLContext*) srcContext;
- NSOpenGLContext *dst = (NSOpenGLContext*) destContext;
- [dst copyAttributesFromContext: src withMask: mask];
+void copyContext(NSOpenGLContext* dest, NSOpenGLContext* src, int mask) {
+ [dest copyAttributesFromContext: src withMask: mask];
}
-void* updateContextRegister(void* nsJContext, void* nsJView) {
- NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext;
- NSView *nsView = (NSView*)nsJView;
-
+void* updateContextRegister(NSOpenGLContext* ctx, NSView* view) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- ContextUpdater *contextUpdater = [[ContextUpdater alloc] initWithContext: nsContext view: nsView];
+ ContextUpdater *contextUpdater = [[ContextUpdater alloc] initWithContext: ctx view: view];
[pool release];
return contextUpdater;
}
@@ -666,7 +650,7 @@ void updateContextUnregister(void* updater) {
[pool release];
}
-void* createPBuffer(int renderTarget, int internalFormat, int width, int height) {
+NSOpenGLPixelBuffer* createPBuffer(int renderTarget, int internalFormat, int width, int height) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSOpenGLPixelBuffer* pBuffer = [[NSOpenGLPixelBuffer alloc]
initWithTextureTarget:renderTarget
@@ -678,38 +662,172 @@ void* createPBuffer(int renderTarget, int internalFormat, int width, int height)
return pBuffer;
}
-Bool destroyPBuffer(void* buffer) {
- NSOpenGLPixelBuffer *pBuffer = (NSOpenGLPixelBuffer*)buffer;
-
+Bool destroyPBuffer(NSOpenGLPixelBuffer* pBuffer) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
[pBuffer release];
[pool release];
-
return true;
}
-void setContextPBuffer(void* nsJContext, void* buffer) {
- NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext;
- NSOpenGLPixelBuffer *pBuffer = (NSOpenGLPixelBuffer*)buffer;
-
+void setContextPBuffer(NSOpenGLContext* ctx, NSOpenGLPixelBuffer* pBuffer) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- [nsContext setPixelBuffer: pBuffer
+ [ctx setPixelBuffer: pBuffer
cubeMapFace: 0
mipMapLevel: 0
- currentVirtualScreen: [nsContext currentVirtualScreen]];
+ currentVirtualScreen: [ctx currentVirtualScreen]];
[pool release];
}
-void setContextTextureImageToPBuffer(void* nsJContext, void* buffer, int colorBuffer) {
- NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext;
- NSOpenGLPixelBuffer *pBuffer = (NSOpenGLPixelBuffer*)buffer;
-
+void setContextTextureImageToPBuffer(NSOpenGLContext* ctx, NSOpenGLPixelBuffer* pBuffer, int colorBuffer) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- [nsContext setTextureImageToPixelBuffer: pBuffer
+ [ctx setTextureImageToPixelBuffer: pBuffer
colorBuffer: (unsigned long) colorBuffer];
[pool release];
}
+@interface MyNSOpenGLLayer: NSOpenGLLayer
+{
+@protected
+ NSOpenGLContext* ctx;
+ NSView* nsView;
+ NSOpenGLPixelFormat* fmt;
+@public
+ volatile BOOL shallDraw;
+}
+
+- (id) initWithContext: (NSOpenGLContext*) ctx
+ pixelFormat: (NSOpenGLPixelFormat*) pfmt
+ view: (NSView*) v
+ opaque: (Bool) opaque;
+
+@end
+
+@implementation MyNSOpenGLLayer
+
+- (id) initWithContext: (NSOpenGLContext*) _ctx
+ pixelFormat: (NSOpenGLPixelFormat*) pfmt
+ view: (NSView*) view
+ opaque: (Bool) opaque
+{
+ self = [super init];
+ self->ctx = _ctx;
+ if(NULL != ctx) {
+ [ctx retain];
+ }
+ fmt = pfmt;
+ if(NULL != fmt) {
+ [fmt retain];
+ }
+ if(NULL != view) {
+ [view retain];
+ [self setView: view];
+ [view setWantsLayer: YES];
+ }
+ [self setAsynchronous: NO];
+ [self setNeedsDisplayOnBoundsChange: NO];
+ [self setOpaque: opaque ? YES : NO];
+ self->shallDraw=NO;
+ DBG_PRINT("MyNSOpenGLLayer::init %p, ctx %p, pfmt %p, view %p, opaque %d\n", self, ctx, fmt, nsView, opaque);
+ return self;
+}
+
+- (void)dealloc
+{
+ if(NULL != ctx) {
+ [ctx release];
+ }
+ if(NULL != fmt) {
+ [fmt release];
+ }
+ if(NULL != nsView) {
+ [nsView release];
+ }
+ DBG_PRINT("MyNSOpenGLLayer::dealloc %p\n", self);
+ [super dealloc];
+}
+
+- (void) setOpenGLContext: (NSOpenGLContext*) _ctx
+{
+ DBG_PRINT("MyNSOpenGLLayer::setOpenGLContext: %p %p -> %p (ignored)\n", self, ctx, _ctx);
+}
+
+- (NSOpenGLContext *) openGLContext
+{
+ return ctx;
+}
+
+- (void) setOpenGLPixelFormat: (NSOpenGLPixelFormat*) pfmt
+{
+ DBG_PRINT("MyNSOpenGLLayer::setOpenGLPixelFormat %p %p\n", self, pfmt);
+}
+
+- (NSOpenGLPixelFormat *) openGLPixelFormat
+{
+ return fmt;
+}
+
+- (void) setView: (NSView*) v
+{
+ DBG_PRINT("MyNSOpenGLLayer::setView %p %p\n", self, v);
+ nsView = v;
+ [super setView: nsView]; // propagate
+}
+
+- (NSView *) view
+{
+ return nsView;
+}
+
+- (NSOpenGLPixelFormat *)openGLPixelFormatForDisplayMask:(uint32_t)mask
+{
+ DBG_PRINT("MyNSOpenGLLayer::openGLPixelFormatForDisplayMask %p %d\n", self, mask);
+ return fmt;
+}
+
+- (NSOpenGLContext *)openGLContextForPixelFormat:(NSOpenGLPixelFormat *)pixelFormat
+{
+ DBG_PRINT("MyNSOpenGLLayer::openGLContextForPixelFormat %p %p\n", self, pixelFormat);
+ return ctx;
+}
+
+- (BOOL)canDrawInOpenGLContext:(NSOpenGLContext *)context pixelFormat:(NSOpenGLPixelFormat *)pixelFormat
+ forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp
+{
+ DBG_PRINT("MyNSOpenGLLayer::canDrawInOpenGLContext %p: %d\n", self, self->shallDraw);
+ return self->shallDraw;
+}
+
+- (void)drawInOpenGLContext:(NSOpenGLContext *)context pixelFormat:(NSOpenGLPixelFormat *)pixelFormat
+ forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp
+{
+ self->shallDraw = NO;
+ DBG_PRINT("MyNSOpenGLLayer::drawInOpenGLContext %p, ctx %p, pfmt %p\n", self, context, pixelFormat);
+ [super drawInOpenGLContext: context pixelFormat: pixelFormat forLayerTime: timeInterval displayTime: timeStamp];
+}
+
+@end
+
+NSOpenGLLayer* createNSOpenGLLayer(NSOpenGLContext* ctx, NSOpenGLPixelFormat* fmt, NSView* view, Bool opaque) {
+ return [[MyNSOpenGLLayer alloc] initWithContext:ctx pixelFormat: fmt view: view opaque: opaque];
+}
+
+void setNSOpenGLLayerNeedsDisplay(NSOpenGLLayer* glLayer) {
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ MyNSOpenGLLayer* l = (MyNSOpenGLLayer*) glLayer;
+ l->shallDraw = YES;
+ // [l setNeedsDisplay];
+ [l performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:YES];
+ DBG_PRINT("MyNSOpenGLLayer::setNSOpenGLLayerNeedsDisplay %p\n", l);
+ [pool release];
+}
+
+void releaseNSOpenGLLayer(NSOpenGLLayer* glLayer) {
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ MyNSOpenGLLayer* l = (MyNSOpenGLLayer*) glLayer;
+ [l release];
+ [pool release];
+}
+
#include <mach-o/dyld.h>
Bool imagesInitialized = false;
static char libGLStr[] = "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib";
@@ -746,10 +864,9 @@ void* getProcAddress(const char *procname) {
return NULL;
}
-void setSwapInterval(void* nsJContext, int interval) {
- NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext;
+void setSwapInterval(NSOpenGLContext* ctx, int interval) {
GLint swapInterval = interval;
- [nsContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
+ [ctx setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
}
Bool setGammaRamp(int tableSize, float* redRamp, float* greenRamp, float* blueRamp) {
diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m
index e19d5ecf7..221eec393 100644
--- a/src/nativewindow/native/macosx/OSXmisc.m
+++ b/src/nativewindow/native/macosx/OSXmisc.m
@@ -36,6 +36,9 @@
#include "NativewindowCommon.h"
#include "jogamp_nativewindow_macosx_OSXUtil.h"
+#include <jawt_md.h>
+#import <JavaNativeFoundation.h>
+
static const char * const ClazzNameRunnable = "java/lang/Runnable";
static jmethodID runnableRunID = NULL;
@@ -81,7 +84,7 @@ Java_jogamp_nativewindow_macosx_OSXUtil_initIDs0(JNIEnv *env, jclass _unused) {
/*
* Class: Java_jogamp_nativewindow_macosx_OSXUtil
- * Method: getLocationOnScreenImpl0
+ * Method: getLocationOnScreen0
* Signature: (JII)Ljavax/media/nativewindow/util/Point;
*/
JNIEXPORT jobject JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetLocationOnScreen0
@@ -97,7 +100,7 @@ JNIEXPORT jobject JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetLocationOnS
int dest_x=-1;
int dest_y=-1;
- NSObject *nsObj = (NSObject*) ((intptr_t) winOrView);
+ NSObject *nsObj = (NSObject*) (intptr_t) winOrView;
NSWindow* win = NULL;
NSView* view = NULL;
@@ -135,6 +138,61 @@ JNIEXPORT jobject JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetLocationOnS
return res;
}
+/*
+ * Class: Java_jogamp_nativewindow_macosx_OSXUtil
+ * Method: CreateNSView0
+ * Signature: (IIIIZ)J
+ */
+JNIEXPORT jlong JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_CreateNSView0
+ (JNIEnv *env, jclass unused, jint x, jint y, jint width, jint height)
+{
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ NSRect rect = NSMakeRect(x, y, width, height);
+ NSView * view = [[NSView alloc] initWithFrame: rect] ;
+ [view setCanDrawConcurrently: YES];
+ [pool release];
+
+ return (jlong) (intptr_t) view;
+}
+
+/*
+ * Class: Java_jogamp_nativewindow_macosx_OSXUtil
+ * Method: DestroyNSView0
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_DestroyNSView0
+ (JNIEnv *env, jclass unused, jlong nsView)
+{
+ NSView* view = (NSView*) (intptr_t) nsView;
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ [view release];
+ [pool release];
+}
+
+/*
+ * Class: Java_jogamp_nativewindow_macosx_OSXUtil
+ * Method: attachJAWTSurfaceLayer
+ * Signature: (JJ)Z
+ */
+JNIEXPORT jboolean JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_AttachJAWTSurfaceLayer0
+ (JNIEnv *env, jclass unused, jobject jawtDrawingSurfaceInfoBuffer, jlong caLayer)
+{
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ JAWT_DrawingSurfaceInfo* dsi = (JAWT_DrawingSurfaceInfo*) (*env)->GetDirectBufferAddress(env, jawtDrawingSurfaceInfoBuffer);
+ if (NULL == dsi) {
+ NativewindowCommon_throwNewRuntimeException(env, "Argument \"jawtDrawingSurfaceInfoBuffer\" was not a direct buffer");
+ return JNI_FALSE;
+ }
+ CALayer* layer = (CALayer*) (intptr_t) caLayer;
+ [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+ id <JAWT_SurfaceLayers> surfaceLayers = (id <JAWT_SurfaceLayers>)dsi->platformInfo;
+ // FIXME: JAU: surfaceLayers.layer = [layer autorelease];
+ surfaceLayers.layer = layer;
+ }];
+ [pool release];
+ return JNI_TRUE;
+}
+
@interface MainRunnable : NSObject
{
@@ -212,10 +270,11 @@ JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_RunOnMainThread0
/*
* Class: Java_jogamp_nativewindow_macosx_OSXUtil
* Method: RunOnMainThread0
- * Signature: (ZLjava/lang/Runnable;)V
+ * Signature: (V)V
*/
JNIEXPORT jboolean JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_IsMainThread0
(JNIEnv *env, jclass unused)
{
return ( [NSThread isMainThread] == YES ) ? JNI_TRUE : JNI_FALSE ;
}
+
diff --git a/src/newt/native/NewtMacWindow.h b/src/newt/native/NewtMacWindow.h
index cb256e71f..7d6236059 100644
--- a/src/newt/native/NewtMacWindow.h
+++ b/src/newt/native/NewtMacWindow.h
@@ -40,7 +40,8 @@
// #define VERBOSE_ON 1
#ifdef VERBOSE_ON
- #define DBG_PRINT(...) fprintf(stderr, __VA_ARGS__); fflush(stderr)
+ // #define DBG_PRINT(...) NSLog(@ ## __VA_ARGS__)
+ #define DBG_PRINT(...) fprintf(stderr, __VA_ARGS__); fflush(stderr)
#else
#define DBG_PRINT(...)
#endif
diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m
index 1f74742ec..70c4c2ecf 100644
--- a/src/newt/native/NewtMacWindow.m
+++ b/src/newt/native/NewtMacWindow.m
@@ -252,7 +252,7 @@ static jmethodID windowRepaintID = NULL;
int shallBeDetached = 0;
JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, jvmVersion, &shallBeDetached);
if(NULL==env) {
- NSLog(@"viewDidHide: null JNIEnv");
+ DBG_PRINT("viewDidHide: null JNIEnv");
return;
}
@@ -272,7 +272,7 @@ static jmethodID windowRepaintID = NULL;
int shallBeDetached = 0;
JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, jvmVersion, &shallBeDetached);
if(NULL==env) {
- NSLog(@"viewDidHide: null JNIEnv");
+ DBG_PRINT("viewDidHide: null JNIEnv");
return;
}
@@ -290,7 +290,7 @@ static jmethodID windowRepaintID = NULL;
int shallBeDetached = 0;
JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, jvmVersion, &shallBeDetached);
if(NULL==env) {
- NSLog(@"viewDidHide: null JNIEnv");
+ DBG_PRINT("viewDidHide: null JNIEnv");
return;
}
@@ -512,14 +512,14 @@ static jint mods2JavaMods(NSUInteger mods)
NewtView* view = (NewtView *) nsview;
jobject javaWindowObject = [view getJavaWindowObject];
if (javaWindowObject == NULL) {
- NSLog(@"sendKeyEvent: null javaWindowObject");
+ DBG_PRINT("sendKeyEvent: null javaWindowObject");
return;
}
int shallBeDetached = 0;
JavaVM *jvmHandle = [view getJVMHandle];
JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], &shallBeDetached);
if(NULL==env) {
- NSLog(@"sendKeyEvent: null JNIEnv");
+ DBG_PRINT("sendKeyEvent: null JNIEnv");
return;
}
@@ -567,14 +567,14 @@ static jint mods2JavaMods(NSUInteger mods)
NewtView* view = (NewtView *) nsview;
jobject javaWindowObject = [view getJavaWindowObject];
if (javaWindowObject == NULL) {
- NSLog(@"sendMouseEvent: null javaWindowObject");
+ DBG_PRINT("sendMouseEvent: null javaWindowObject");
return;
}
int shallBeDetached = 0;
JavaVM *jvmHandle = [view getJVMHandle];
JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], &shallBeDetached);
if(NULL==env) {
- NSLog(@"sendMouseEvent: null JNIEnv");
+ DBG_PRINT("sendMouseEvent: null JNIEnv");
return;
}
jint javaMods = mods2JavaMods([event modifierFlags]);
@@ -770,14 +770,14 @@ static jint mods2JavaMods(NSUInteger mods)
NewtView* view = (NewtView *) nsview;
jobject javaWindowObject = [view getJavaWindowObject];
if (javaWindowObject == NULL) {
- NSLog(@"windowDidResize: null javaWindowObject");
+ DBG_PRINT("windowDidResize: null javaWindowObject");
return;
}
int shallBeDetached = 0;
JavaVM *jvmHandle = [view getJVMHandle];
JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], &shallBeDetached);
if(NULL==env) {
- NSLog(@"windowDidResize: null JNIEnv");
+ DBG_PRINT("windowDidResize: null JNIEnv");
return;
}
@@ -805,14 +805,14 @@ static jint mods2JavaMods(NSUInteger mods)
NewtView* view = (NewtView *) nsview;
jobject javaWindowObject = [view getJavaWindowObject];
if (javaWindowObject == NULL) {
- NSLog(@"windowDidMove: null javaWindowObject");
+ DBG_PRINT("windowDidMove: null javaWindowObject");
return;
}
int shallBeDetached = 0;
JavaVM *jvmHandle = [view getJVMHandle];
JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], &shallBeDetached);
if(NULL==env) {
- NSLog(@"windowDidMove: null JNIEnv");
+ DBG_PRINT("windowDidMove: null JNIEnv");
return;
}
@@ -841,14 +841,14 @@ static jint mods2JavaMods(NSUInteger mods)
jobject javaWindowObject = [view getJavaWindowObject];
DBG_PRINT( "*************** windowWillClose.0: 0x%p\n", (void *)(intptr_t)javaWindowObject);
if (javaWindowObject == NULL) {
- NSLog(@"windowWillClose: null javaWindowObject");
+ DBG_PRINT("windowWillClose: null javaWindowObject");
return;
}
int shallBeDetached = 0;
JavaVM *jvmHandle = [view getJVMHandle];
JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], &shallBeDetached);
if(NULL==env) {
- NSLog(@"windowWillClose: null JNIEnv");
+ DBG_PRINT("windowWillClose: null JNIEnv");
return;
}
@@ -916,14 +916,14 @@ static jint mods2JavaMods(NSUInteger mods)
NewtView* view = (NewtView *) nsview;
jobject javaWindowObject = [view getJavaWindowObject];
if (javaWindowObject == NULL) {
- NSLog(@"focusChanged: null javaWindowObject");
+ DBG_PRINT("focusChanged: null javaWindowObject");
return;
}
int shallBeDetached = 0;
JavaVM *jvmHandle = [view getJVMHandle];
JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, [view getJVMVersion], &shallBeDetached);
if(NULL==env) {
- NSLog(@"focusChanged: null JNIEnv");
+ DBG_PRINT("focusChanged: null JNIEnv");
return;
}