aboutsummaryrefslogtreecommitdiffstats
path: root/make/config/nativewindow
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2009-06-15 22:57:38 +0000
committerKenneth Russel <[email protected]>2009-06-15 22:57:38 +0000
commita959c53b7ac91e489bf0959391e892790b9ff248 (patch)
tree4664742a4f9f6daa694364292e376ad2e6ee97d1 /make/config/nativewindow
parent506b634b780dcd23aa61015c2ceba3e687196abf (diff)
Copied JOGL_2_SANDBOX r1957 on to trunk; JOGL_2_SANDBOX branch is now closed
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@1959 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'make/config/nativewindow')
-rwxr-xr-xmake/config/nativewindow/jawt-CustomJavaCode.java27
-rwxr-xr-xmake/config/nativewindow/jawt-DrawingSurfaceInfo-CustomJavaCode.java38
-rw-r--r--make/config/nativewindow/jawt-macosx.cfg30
-rw-r--r--make/config/nativewindow/jawt-win32.cfg30
-rw-r--r--make/config/nativewindow/jawt-x11.cfg30
-rwxr-xr-xmake/config/nativewindow/x11-CustomCCode.c165
-rw-r--r--make/config/nativewindow/x11-CustomJavaCode.java26
-rw-r--r--make/config/nativewindow/x11-lib.cfg43
8 files changed, 389 insertions, 0 deletions
diff --git a/make/config/nativewindow/jawt-CustomJavaCode.java b/make/config/nativewindow/jawt-CustomJavaCode.java
new file mode 100755
index 000000000..f1ef91075
--- /dev/null
+++ b/make/config/nativewindow/jawt-CustomJavaCode.java
@@ -0,0 +1,27 @@
+private static volatile JAWT jawt;
+
+/** Helper routine for all users to call to access the JAWT. */
+public static JAWT getJAWT() {
+ if (jawt == null) {
+ synchronized (JAWT.class) {
+ if (jawt == null) {
+ JAWTNativeLibLoader.loadAWTImpl();
+ // Workaround for 4845371.
+ // Make sure the first reference to the JNI GetDirectBufferAddress is done
+ // from a privileged context so the VM's internal class lookups will succeed.
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ JAWT j = JAWT.create();
+ j.version(JAWTFactory.JAWT_VERSION_1_4);
+ if (!JAWTFactory.JAWT_GetAWT(j)) {
+ throw new RuntimeException("Unable to initialize JAWT");
+ }
+ jawt = j;
+ return null;
+ }
+ });
+ }
+ }
+ }
+ return jawt;
+}
diff --git a/make/config/nativewindow/jawt-DrawingSurfaceInfo-CustomJavaCode.java b/make/config/nativewindow/jawt-DrawingSurfaceInfo-CustomJavaCode.java
new file mode 100755
index 000000000..dab377ad4
--- /dev/null
+++ b/make/config/nativewindow/jawt-DrawingSurfaceInfo-CustomJavaCode.java
@@ -0,0 +1,38 @@
+public JAWT_PlatformInfo platformInfo() {
+ return newPlatformInfo(platformInfo0(getBuffer()));
+}
+
+private native ByteBuffer platformInfo0(Buffer jthis0);
+
+private static java.lang.reflect.Method platformInfoFactoryMethod;
+
+private static JAWT_PlatformInfo newPlatformInfo(ByteBuffer buf) {
+ if (platformInfoFactoryMethod == null) {
+ String osName = (String) AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return System.getProperty("os.name").toLowerCase();
+ }
+ });
+ try {
+ Class factoryClass;
+ if (osName.startsWith("wind")) {
+ factoryClass = Class.forName("com.sun.nativewindow.impl.jawt.windows.JAWT_Win32DrawingSurfaceInfo");
+ } else if (osName.startsWith("mac os x")) {
+ factoryClass = Class.forName("com.sun.nativewindow.impl.jawt.macosx.JAWT_MacOSXDrawingSurfaceInfo");
+ } else {
+ // Assume Linux, Solaris, etc. Should probably test for these explicitly.
+ factoryClass = Class.forName("com.sun.nativewindow.impl.jawt.x11.JAWT_X11DrawingSurfaceInfo");
+ }
+ platformInfoFactoryMethod = factoryClass.getMethod("create",
+ new Class[] { ByteBuffer.class });
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ try {
+ return (JAWT_PlatformInfo)
+ platformInfoFactoryMethod.invoke(null, new Object[] { buf });
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+}
diff --git a/make/config/nativewindow/jawt-macosx.cfg b/make/config/nativewindow/jawt-macosx.cfg
new file mode 100644
index 000000000..b047ecdff
--- /dev/null
+++ b/make/config/nativewindow/jawt-macosx.cfg
@@ -0,0 +1,30 @@
+# This .cfg file is used to generate the interface to the JAWT, which
+# is used by the MacOSXOnscreenGLContext.
+Style AllStatic
+Package com.sun.nativewindow.impl.jawt
+JavaClass JAWTFactory
+JavaOutputDir gensrc/classes
+NativeOutputDir gensrc/native/MacOSX
+
+HierarchicalNativeOutput false
+
+Opaque boolean jboolean
+Opaque long void *
+Opaque long NSView *
+
+IgnoreField JAWT GetComponent
+IgnoreField JAWT_DrawingSurfaceInfo platformInfo
+
+IncludeAs CustomJavaCode JAWT jawt-CustomJavaCode.java
+
+CustomCCode #include <inttypes.h>
+CustomCCode #include <jawt.h>
+CustomCCode #include </usr/include/machine/types.h>
+
+import java.security.*
+import com.sun.nativewindow.impl.jawt.*
+StructPackage JAWT_MacOSXDrawingSurfaceInfo com.sun.nativewindow.impl.jawt.macosx
+EmitStruct JAWT_MacOSXDrawingSurfaceInfo
+Implements JAWT_MacOSXDrawingSurfaceInfo JAWT_PlatformInfo
+
+IncludeAs CustomJavaCode JAWT_DrawingSurfaceInfo jawt-DrawingSurfaceInfo-CustomJavaCode.java
diff --git a/make/config/nativewindow/jawt-win32.cfg b/make/config/nativewindow/jawt-win32.cfg
new file mode 100644
index 000000000..e7754843e
--- /dev/null
+++ b/make/config/nativewindow/jawt-win32.cfg
@@ -0,0 +1,30 @@
+# This .cfg file is used to generate the interface to the JAWT, which
+# is used by the WindowsOnscreenGLContext.
+Style AllStatic
+Package com.sun.nativewindow.impl.jawt
+JavaClass JAWTFactory
+JavaOutputDir gensrc/classes
+NativeOutputDir gensrc/native/Windows
+
+HierarchicalNativeOutput false
+
+Opaque boolean jboolean
+Opaque long HDC
+
+IgnoreField JAWT GetComponent
+IgnoreField JAWT_DrawingSurfaceInfo platformInfo
+IgnoreField JAWT_Win32DrawingSurfaceInfo null
+IgnoreField JAWT_Win32DrawingSurfaceInfo hpalette
+
+IncludeAs CustomJavaCode JAWT jawt-CustomJavaCode.java
+
+CustomCCode #include <jawt.h>
+Include ../intptr.cfg
+
+import java.security.*
+import com.sun.nativewindow.impl.jawt.*
+StructPackage JAWT_Win32DrawingSurfaceInfo com.sun.nativewindow.impl.jawt.windows
+EmitStruct JAWT_Win32DrawingSurfaceInfo
+Implements JAWT_Win32DrawingSurfaceInfo JAWT_PlatformInfo
+
+IncludeAs CustomJavaCode JAWT_DrawingSurfaceInfo jawt-DrawingSurfaceInfo-CustomJavaCode.java
diff --git a/make/config/nativewindow/jawt-x11.cfg b/make/config/nativewindow/jawt-x11.cfg
new file mode 100644
index 000000000..25df57a1f
--- /dev/null
+++ b/make/config/nativewindow/jawt-x11.cfg
@@ -0,0 +1,30 @@
+# This .cfg file is used to generate the interface to the JAWT, which
+# is used by the X11OnscreenGLContext.
+Style AllStatic
+Package com.sun.nativewindow.impl.jawt
+JavaClass JAWTFactory
+JavaOutputDir gensrc/classes
+NativeOutputDir gensrc/native/X11
+
+HierarchicalNativeOutput false
+
+Opaque boolean jboolean
+Opaque long Drawable
+Opaque long Display *
+
+IgnoreField JAWT GetComponent
+IgnoreField JAWT_DrawingSurfaceInfo platformInfo
+IgnoreField JAWT_X11DrawingSurfaceInfo GetAWTColor
+
+IncludeAs CustomJavaCode JAWT jawt-CustomJavaCode.java
+
+CustomCCode #include <inttypes.h>
+CustomCCode #include <jawt.h>
+
+import java.security.*
+import com.sun.nativewindow.impl.jawt.*
+StructPackage JAWT_X11DrawingSurfaceInfo com.sun.nativewindow.impl.jawt.x11
+EmitStruct JAWT_X11DrawingSurfaceInfo
+Implements JAWT_X11DrawingSurfaceInfo JAWT_PlatformInfo
+
+IncludeAs CustomJavaCode JAWT_DrawingSurfaceInfo jawt-DrawingSurfaceInfo-CustomJavaCode.java
diff --git a/make/config/nativewindow/x11-CustomCCode.c b/make/config/nativewindow/x11-CustomCCode.c
new file mode 100755
index 000000000..e24e0cd1c
--- /dev/null
+++ b/make/config/nativewindow/x11-CustomCCode.c
@@ -0,0 +1,165 @@
+#include <inttypes.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+/* Linux headers don't work properly */
+#define __USE_GNU
+#include <dlfcn.h>
+#undef __USE_GNU
+
+/* Current versions of Solaris don't expose the XF86 extensions,
+ although with the recent transition to Xorg this will probably
+ happen in an upcoming release */
+#if !defined(__sun) && !defined(_HPUX)
+#include <X11/extensions/xf86vmode.h>
+#else
+/* Need to provide stubs for these */
+Bool XF86VidModeGetGammaRampSize(
+ Display *display,
+ int screen,
+ int* size)
+{
+ return False;
+}
+
+Bool XF86VidModeGetGammaRamp(
+ Display *display,
+ int screen,
+ int size,
+ unsigned short *red_array,
+ unsigned short *green_array,
+ unsigned short *blue_array) {
+ return False;
+}
+Bool XF86VidModeSetGammaRamp(
+ Display *display,
+ int screen,
+ int size,
+ unsigned short *red_array,
+ unsigned short *green_array,
+ unsigned short *blue_array) {
+ return False;
+}
+#endif
+
+/* HP-UX doesn't define RTLD_DEFAULT. */
+#if defined(_HPUX) && !defined(RTLD_DEFAULT)
+#define RTLD_DEFAULT NULL
+#endif
+
+/* Need to expose DefaultScreen and RootWindow macros to Java */
+JNIEXPORT jlong JNICALL
+Java_com_sun_nativewindow_impl_x11_X11Lib_DefaultScreen(JNIEnv *env, jclass _unused, jlong display) {
+ return DefaultScreen((Display*) (intptr_t) display);
+}
+
+JNIEXPORT jlong JNICALL
+Java_com_sun_nativewindow_impl_x11_X11Lib_DefaultVisualID(JNIEnv *env, jclass _unused, jlong display, jint screen) {
+ return (jlong) XVisualIDFromVisual( DefaultVisual( (Display*) (intptr_t) display, screen ) );
+}
+
+JNIEXPORT jlong JNICALL
+Java_com_sun_nativewindow_impl_x11_X11Lib_RootWindow(JNIEnv *env, jclass _unused, jlong display, jint screen) {
+ return RootWindow((Display*) (intptr_t) display, screen);
+}
+
+JNIEXPORT jlong JNICALL
+Java_com_sun_nativewindow_impl_x11_X11Lib_dlopen(JNIEnv *env, jclass _unused, jstring name) {
+ const jbyte* chars;
+ void* res;
+ chars = (*env)->GetStringUTFChars(env, name, NULL);
+ res = dlopen(chars, RTLD_LAZY | RTLD_GLOBAL);
+ (*env)->ReleaseStringUTFChars(env, name, chars);
+ return (jlong) ((intptr_t) res);
+}
+
+JNIEXPORT jlong JNICALL
+Java_com_sun_nativewindow_impl_x11_X11Lib_dlsym(JNIEnv *env, jclass _unused, jstring name) {
+ const jbyte* chars;
+ void* res;
+ chars = (*env)->GetStringUTFChars(env, name, NULL);
+ res = dlsym(RTLD_DEFAULT, chars);
+ (*env)->ReleaseStringUTFChars(env, name, chars);
+ return (jlong) ((intptr_t) res);
+}
+
+/* Need to pull this in as we don't have a stub header for it */
+extern Bool XineramaEnabled(Display* display);
+
+static const char * clazzNameInternalBufferUtil = "com/sun/nativewindow/impl/InternalBufferUtil";
+static const char * clazzNameInternalBufferUtilStaticCstrName = "copyByteBuffer";
+static const char * clazzNameInternalBufferUtilStaticCstrSignature = "(Ljava/nio/ByteBuffer;)Ljava/nio/ByteBuffer;";
+static const char * clazzNameByteBuffer = "java/nio/ByteBuffer";
+static jclass clazzInternalBufferUtil = NULL;
+static jmethodID cstrInternalBufferUtil = NULL;
+static jclass clazzByteBuffer = NULL;
+
+static void _initClazzAccess(JNIEnv *env) {
+ if(NULL!=cstrInternalBufferUtil) return ;
+
+ jclass c = (*env)->FindClass(env, clazzNameInternalBufferUtil);
+ if(NULL==c) {
+ fprintf(stderr, "FatalError: Java_com_sun_nativewindow_impl_x11_X11Lib: can't find %s\n", clazzNameInternalBufferUtil);
+ (*env)->FatalError(env, clazzNameInternalBufferUtil);
+ }
+ clazzInternalBufferUtil = (jclass)(*env)->NewGlobalRef(env, c);
+ if(NULL==clazzInternalBufferUtil) {
+ fprintf(stderr, "FatalError: Java_com_sun_nativewindow_impl_x11_X11Lib: can't use %s\n", clazzNameInternalBufferUtil);
+ (*env)->FatalError(env, clazzNameInternalBufferUtil);
+ }
+ c = (*env)->FindClass(env, clazzNameByteBuffer);
+ if(NULL==c) {
+ fprintf(stderr, "FatalError: Java_com_sun_nativewindow_impl_x11_X11Lib: can't find %s\n", clazzNameByteBuffer);
+ (*env)->FatalError(env, clazzNameByteBuffer);
+ }
+ clazzByteBuffer = (jclass)(*env)->NewGlobalRef(env, c);
+ if(NULL==c) {
+ fprintf(stderr, "FatalError: Java_com_sun_nativewindow_impl_x11_X11Lib: can't use %s\n", clazzNameByteBuffer);
+ (*env)->FatalError(env, clazzNameByteBuffer);
+ }
+
+ cstrInternalBufferUtil = (*env)->GetStaticMethodID(env, clazzInternalBufferUtil,
+ clazzNameInternalBufferUtilStaticCstrName, clazzNameInternalBufferUtilStaticCstrSignature);
+ if(NULL==cstrInternalBufferUtil) {
+ fprintf(stderr, "FatalError: Java_com_sun_nativewindow_impl_x11_X11Lib:: can't create %s.%s %s\n",
+ clazzNameInternalBufferUtil,
+ clazzNameInternalBufferUtilStaticCstrName, clazzNameInternalBufferUtilStaticCstrSignature);
+ (*env)->FatalError(env, clazzNameInternalBufferUtilStaticCstrName);
+ }
+}
+
+/* Java->C glue code:
+ * Java package: com.sun.nativewindow.impl.x11.X11Lib
+ * Java method: XVisualInfo XGetVisualInfo(long arg0, long arg1, XVisualInfo arg2, java.nio.IntBuffer arg3)
+ * C function: XVisualInfo * XGetVisualInfo(Display * , long, XVisualInfo * , int * );
+ */
+JNIEXPORT jobject JNICALL
+Java_com_sun_nativewindow_impl_x11_X11Lib_XGetVisualInfoCopied1__JJLjava_nio_ByteBuffer_2Ljava_lang_Object_2I(JNIEnv *env, jclass _unused, jlong arg0, jlong arg1, jobject arg2, jobject arg3, jint arg3_byte_offset) {
+ XVisualInfo * _ptr2 = NULL;
+ int * _ptr3 = NULL;
+ XVisualInfo * _res;
+ int count;
+ if (arg2 != NULL) {
+ _ptr2 = (XVisualInfo *) (((char*) (*env)->GetDirectBufferAddress(env, arg2)) + 0);
+ }
+ if (arg3 != NULL) {
+ _ptr3 = (int *) (((char*) (*env)->GetPrimitiveArrayCritical(env, arg3, NULL)) + arg3_byte_offset);
+ }
+ _res = XGetVisualInfo((Display *) (intptr_t) arg0, (long) arg1, (XVisualInfo *) _ptr2, (int *) _ptr3);
+ count = _ptr3[0];
+ if (arg3 != NULL) {
+ (*env)->ReleasePrimitiveArrayCritical(env, arg3, _ptr3, 0);
+ }
+ if (_res == NULL) return NULL;
+
+ _initClazzAccess(env);
+
+ jobject jbyteSource = (*env)->NewDirectByteBuffer(env, _res, count * sizeof(XVisualInfo));
+ jobject jbyteCopy = (*env)->CallStaticObjectMethod(env,
+ clazzInternalBufferUtil, cstrInternalBufferUtil, jbyteSource);
+
+ // FIXME: remove reference/gc jbyteSource ??
+ XFree(_res);
+
+ return jbyteCopy;
+}
+
diff --git a/make/config/nativewindow/x11-CustomJavaCode.java b/make/config/nativewindow/x11-CustomJavaCode.java
new file mode 100644
index 000000000..b1ee3a6c3
--- /dev/null
+++ b/make/config/nativewindow/x11-CustomJavaCode.java
@@ -0,0 +1,26 @@
+
+ /** Interface to C language function: <br> <code> XVisualInfo * XGetVisualInfo(Display * , long, XVisualInfo * , int * ); </code> */
+ public static XVisualInfo[] XGetVisualInfoCopied(long arg0, long arg1, XVisualInfo arg2, int[] arg3, int arg3_offset)
+ {
+ if(arg3 != null && arg3.length <= arg3_offset)
+ throw new RuntimeException("array offset argument \"arg3_offset\" (" + arg3_offset + ") equals or exceeds array length (" + arg3.length + ")");
+ java.nio.ByteBuffer _res;
+ _res = XGetVisualInfoCopied1(arg0, arg1, ((arg2 == null) ? null : arg2.getBuffer()), arg3, BufferFactory.SIZEOF_INT * arg3_offset);
+
+ if (_res == null) return null;
+ BufferFactory.nativeOrder(_res);
+ XVisualInfo[] _retarray = new XVisualInfo[getFirstElement(arg3, arg3_offset)];
+ for (int _count = 0; _count < getFirstElement(arg3, arg3_offset); _count++) {
+ _res.position(_count * XVisualInfo.size());
+ _res.limit ((1 + _count) * XVisualInfo.size());
+ java.nio.ByteBuffer _tmp = _res.slice();
+ _res.position(0);
+ _res.limit(_res.capacity());
+ _retarray[_count] = XVisualInfo.create(_tmp);
+ }
+ return _retarray;
+ }
+
+ /** Entry point to C language function: <code> XVisualInfo * XGetVisualInfo(Display * , long, XVisualInfo * , int * ); </code> */
+ private static native java.nio.ByteBuffer XGetVisualInfoCopied1(long arg0, long arg1, java.nio.ByteBuffer arg2, Object arg3, int arg3_byte_offset);
+
diff --git a/make/config/nativewindow/x11-lib.cfg b/make/config/nativewindow/x11-lib.cfg
new file mode 100644
index 000000000..321444725
--- /dev/null
+++ b/make/config/nativewindow/x11-lib.cfg
@@ -0,0 +1,43 @@
+# This .cfg file is used to generate the interface to the GLX routines
+# used internally by the X11GLContext implementation.
+Package com.sun.nativewindow.impl.x11
+JavaClass X11Lib
+Style allstatic
+
+HierarchicalNativeOutput false
+
+JavaOutputDir gensrc/classes
+NativeOutputDir gensrc/native/X11
+
+# Imports needed by all glue code
+Import java.nio.*
+Import java.util.*
+
+# XID needs to be treated as a long for 32/64 bit compatibility
+Opaque long XID
+
+Opaque long Display *
+Opaque boolean Bool
+Opaque long GLXFBConfig
+
+CustomJavaCode X11Lib public static native long dlopen(String name);
+CustomJavaCode X11Lib public static native long dlsym(String name);
+
+IncludeAs CustomJavaCode X11Lib x11-CustomJavaCode.java
+IncludeAs CustomCCode x11-CustomCCode.c
+
+ArgumentIsString XOpenDisplay 0
+
+# Need to expose DefaultScreen and RootWindow macros to Java
+CustomJavaCode X11Lib public static native int DefaultScreen(long display);
+CustomJavaCode X11Lib public static native long DefaultVisualID(long display, int screen);
+CustomJavaCode X11Lib public static native long RootWindow(long display, int screen);
+
+# We have Custom code for the following
+Ignore XGetVisualInfo
+
+# Helper routine to make the ReturnedArrayLength expression below work correctly
+CustomJavaCode X11Lib private static int getFirstElement(IntBuffer buf) { return buf.get(buf.position()); }
+CustomJavaCode X11Lib private static int getFirstElement(int[] arr, int offset) { return arr[offset]; }
+
+CustomJavaCode XVisualInfo public static XVisualInfo create(XVisualInfo s) { XVisualInfo d = XVisualInfo.create(); d.getBuffer().put(s.getBuffer()); d.getBuffer().rewind(); s.getBuffer().rewind(); return d; }