From 24fcece997ba911b0270033a357bbd83258d4f1a Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 16 Mar 2009 14:38:27 +0000 Subject: JOGL refactoring: Refactored JOGL into 3 independent components. 1 NWI - Native windowing interface Abstracts the the general NativeWindow interface and it's factory, incl the basic JAWT and Xlib toolkit. The latter was motivated to clean up the JOGL workspace, and to allow other to reuse this part. The generic core is nwi.core.jar, the AWT add-on is nwi.awt.jar. 2 JOGL - The OpenGL mapping Further cleanup of the SPEC. All non OpenGL toolkits are relocated to NWI and NEWT. There is still openmax and the windows audio layer .. Another cleanup of the fixed function pipeline emulation. Moved utilities and implementations where they belong .. Removed GLUnsupportedException. Misc .. changes 3 NEWT - The new windowing toolkit The generic NEWT, newt.core.jar. The JOGL and AWT modules are seperate, newt.ogl.jar newt.awt.jar. Their build can be switched off. The modules source and builds resides in their own directory. Because of their nature, they share the stub_includes, etc. Each module has it's own ant build script - build-nwi.xml - build-jogl.xml - build-newt.xml They can be build at once using build.xml as ususal, which just invokes the seperate build tasks. if rootrel.build=build, then the build location is jogl/build-nwi jogl/build-jogl jogl/build-newt and the sources are under jogl/src/nwi jogl/src/jogl jogl/src/newt Tested: jogl-demos, d4; Linux, MacOsX; Nvidia git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1868 232f8b59-042b-4e1e-8c03-345bb8c30851 --- make/config/nwi/jawt-CustomJavaCode.java | 27 +++++++ .../jawt-DrawingSurfaceInfo-CustomJavaCode.java | 38 ++++++++++ make/config/nwi/jawt-macosx.cfg | 30 ++++++++ make/config/nwi/jawt-win32.cfg | 30 ++++++++ make/config/nwi/jawt-x11.cfg | 30 ++++++++ make/config/nwi/x11-CustomCCode.c | 82 ++++++++++++++++++++++ make/config/nwi/x11-lib.cfg | 43 ++++++++++++ 7 files changed, 280 insertions(+) create mode 100755 make/config/nwi/jawt-CustomJavaCode.java create mode 100755 make/config/nwi/jawt-DrawingSurfaceInfo-CustomJavaCode.java create mode 100644 make/config/nwi/jawt-macosx.cfg create mode 100644 make/config/nwi/jawt-win32.cfg create mode 100644 make/config/nwi/jawt-x11.cfg create mode 100755 make/config/nwi/x11-CustomCCode.c create mode 100644 make/config/nwi/x11-lib.cfg (limited to 'make/config/nwi') diff --git a/make/config/nwi/jawt-CustomJavaCode.java b/make/config/nwi/jawt-CustomJavaCode.java new file mode 100755 index 000000000..f1ef91075 --- /dev/null +++ b/make/config/nwi/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/nwi/jawt-DrawingSurfaceInfo-CustomJavaCode.java b/make/config/nwi/jawt-DrawingSurfaceInfo-CustomJavaCode.java new file mode 100755 index 000000000..1cc13e7d8 --- /dev/null +++ b/make/config/nwi/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.nwi.impl.jawt.windows.JAWT_Win32DrawingSurfaceInfo"); + } else if (osName.startsWith("mac os x")) { + factoryClass = Class.forName("com.sun.nwi.impl.jawt.macosx.JAWT_MacOSXDrawingSurfaceInfo"); + } else { + // Assume Linux, Solaris, etc. Should probably test for these explicitly. + factoryClass = Class.forName("com.sun.nwi.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/nwi/jawt-macosx.cfg b/make/config/nwi/jawt-macosx.cfg new file mode 100644 index 000000000..57cceb6a1 --- /dev/null +++ b/make/config/nwi/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.nwi.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 +CustomCCode #include +CustomCCode #include + +import java.security.* +import com.sun.nwi.impl.jawt.* +StructPackage JAWT_MacOSXDrawingSurfaceInfo com.sun.nwi.impl.jawt.macosx +EmitStruct JAWT_MacOSXDrawingSurfaceInfo +Implements JAWT_MacOSXDrawingSurfaceInfo JAWT_PlatformInfo + +IncludeAs CustomJavaCode JAWT_DrawingSurfaceInfo jawt-DrawingSurfaceInfo-CustomJavaCode.java diff --git a/make/config/nwi/jawt-win32.cfg b/make/config/nwi/jawt-win32.cfg new file mode 100644 index 000000000..74aef8f75 --- /dev/null +++ b/make/config/nwi/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.nwi.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 +Include ../intptr.cfg + +import java.security.* +import com.sun.nwi.impl.jawt.* +StructPackage JAWT_Win32DrawingSurfaceInfo com.sun.nwi.impl.jawt.windows +EmitStruct JAWT_Win32DrawingSurfaceInfo +Implements JAWT_Win32DrawingSurfaceInfo JAWT_PlatformInfo + +IncludeAs CustomJavaCode JAWT_DrawingSurfaceInfo jawt-DrawingSurfaceInfo-CustomJavaCode.java diff --git a/make/config/nwi/jawt-x11.cfg b/make/config/nwi/jawt-x11.cfg new file mode 100644 index 000000000..fdcf16bdb --- /dev/null +++ b/make/config/nwi/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.nwi.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 +CustomCCode #include + +import java.security.* +import com.sun.nwi.impl.jawt.* +StructPackage JAWT_X11DrawingSurfaceInfo com.sun.nwi.impl.jawt.x11 +EmitStruct JAWT_X11DrawingSurfaceInfo +Implements JAWT_X11DrawingSurfaceInfo JAWT_PlatformInfo + +IncludeAs CustomJavaCode JAWT_DrawingSurfaceInfo jawt-DrawingSurfaceInfo-CustomJavaCode.java diff --git a/make/config/nwi/x11-CustomCCode.c b/make/config/nwi/x11-CustomCCode.c new file mode 100755 index 000000000..793327c72 --- /dev/null +++ b/make/config/nwi/x11-CustomCCode.c @@ -0,0 +1,82 @@ +#include +#include +#include +#include +/* Linux headers don't work properly */ +#define __USE_GNU +#include +#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 +#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_nwi_impl_x11_X11Lib_DefaultScreen(JNIEnv *env, jclass _unused, jlong display) { + return DefaultScreen((Display*) (intptr_t) display); +} +JNIEXPORT jlong JNICALL +Java_com_sun_nwi_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_nwi_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_nwi_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); + diff --git a/make/config/nwi/x11-lib.cfg b/make/config/nwi/x11-lib.cfg new file mode 100644 index 000000000..1448e7783 --- /dev/null +++ b/make/config/nwi/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.nwi.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 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 RootWindow(long display, int screen); + +# Get returned array's capacity from XGetVisualInfo to be correct +TemporaryCVariableDeclaration XGetVisualInfo int count; +TemporaryCVariableAssignment XGetVisualInfo count = _ptr3[0]; +ReturnValueCapacity XGetVisualInfo count * sizeof(XVisualInfo) + +# 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]; } +ReturnedArrayLength XGetVisualInfo getFirstElement({3}) + -- cgit v1.2.3