diff options
41 files changed, 765 insertions, 347 deletions
diff --git a/jnlp-files/nativewindow.jnlp b/jnlp-files/nativewindow.jnlp index 67cb61279..8af99a57c 100644 --- a/jnlp-files/nativewindow.jnlp +++ b/jnlp-files/nativewindow.jnlp @@ -19,48 +19,51 @@ </resources> <resources os="Windows" arch="x86"> + <jar href="nativewindow.os.windows.jar" main="true" /> <nativelib href = "nativewindow-natives-windows-i586.jar" /> </resources> <resources os="Windows" arch="amd64"> + <jar href="nativewindow.os.windows.jar" main="true" /> <nativelib href = "nativewindow-natives-windows-amd64.jar" /> </resources> <resources os="Windows" arch="x86_64"> + <jar href="nativewindow.os.windows.jar" main="true" /> <nativelib href = "nativewindow-natives-windows-amd64.jar" /> </resources> <resources os="SunOS" arch="sparc"> - <jar href="nativewindow.x11.jar" main="true" /> + <jar href="nativewindow.os.x11.jar" main="true" /> <nativelib href = "nativewindow-natives-solaris-sparc.jar" /> </resources> <resources os="SunOS" arch="sparcv9"> - <jar href="nativewindow.x11.jar" main="true" /> + <jar href="nativewindow.os.x11.jar" main="true" /> <nativelib href = "nativewindow-natives-solaris-sparcv9.jar" /> </resources> <resources os="SunOS" arch="x86"> - <jar href="nativewindow.x11.jar" main="true" /> + <jar href="nativewindow.os.x11.jar" main="true" /> <nativelib href = "nativewindow-natives-solaris-i586.jar" /> </resources> <resources os="SunOS" arch="amd64"> - <jar href="nativewindow.x11.jar" main="true" /> + <jar href="nativewindow.os.x11.jar" main="true" /> <nativelib href = "nativewindow-natives-solaris-amd64.jar" /> </resources> <resources os="SunOS" arch="x86_64"> - <jar href="nativewindow.x11.jar" main="true" /> + <jar href="nativewindow.os.x11.jar" main="true" /> <nativelib href = "nativewindow-natives-solaris-amd64.jar" /> </resources> <resources os="Linux" arch="i386"> - <jar href="nativewindow.x11.jar" main="true" /> + <jar href="nativewindow.os.x11.jar" main="true" /> <nativelib href = "nativewindow-natives-linux-i586.jar" /> </resources> <resources os="Linux" arch="x86"> - <jar href="nativewindow.x11.jar" main="true" /> + <jar href="nativewindow.os.x11.jar" main="true" /> <nativelib href = "nativewindow-natives-linux-i586.jar" /> </resources> <resources os="Linux" arch="amd64"> - <jar href="nativewindow.x11.jar" main="true" /> + <jar href="nativewindow.os.x11.jar" main="true" /> <nativelib href = "nativewindow-natives-linux-amd64.jar" /> </resources> <resources os="Linux" arch="x86_64"> - <jar href="nativewindow.x11.jar" main="true" /> + <jar href="nativewindow.os.x11.jar" main="true" /> <nativelib href = "nativewindow-natives-linux-amd64.jar" /> </resources> <resources os="Mac OS X" arch="i386"> diff --git a/make/build-common.xml b/make/build-common.xml index 468e5933c..e6a066197 100644 --- a/make/build-common.xml +++ b/make/build-common.xml @@ -274,6 +274,7 @@ <property name="nativewindow.core.jar" value="${build.nativewindow}/nativewindow.core.jar" /> <property name="nativewindow.awt.jar" value="${build.nativewindow}/nativewindow.awt.jar" /> <property name="nativewindow.os.x11.jar" value="${build.nativewindow}/nativewindow.os.x11.jar" /> + <property name="nativewindow.os.windows.jar" value="${build.nativewindow}/nativewindow.os.windows.jar" /> <property name="jogl.core.jar" value="${build.jogl}/jogl.core.jar" /> <property name="jogl.cg.jar" value="${build.jogl}/jogl.cg.jar" /> @@ -312,8 +313,9 @@ <property name="newt.intelgdl.jar" value="${build.newt}/newt.intelgdl.jar" /> <!-- Atomic CDC JARS --> - <property name="nativewindow.core.cdc.jar" value="${build.nativewindow}/nativewindow.core.cdc.jar" /> - <property name="nativewindow.os.x11.cdc.jar" value="${build.nativewindow}/nativewindow.os.x11.cdc.jar" /> + <property name="nativewindow.core.cdc.jar" value="${build.nativewindow}/nativewindow.core.cdc.jar" /> + <property name="nativewindow.os.x11.cdc.jar" value="${build.nativewindow}/nativewindow.os.x11.cdc.jar" /> + <property name="nativewindow.os.windows.cdc.jar" value="${build.nativewindow}/nativewindow.os.windows.cdc.jar" /> <property name="jogl.core.cdc.jar" value="${build.jogl}/jogl.core.cdc.jar" /> <property name="jogl.gles1.cdc.jar" value="${build.jogl}/jogl.gles1.cdc.jar" /> diff --git a/make/build-jogl.xml b/make/build-jogl.xml index 850393202..ddfbc25f7 100644 --- a/make/build-jogl.xml +++ b/make/build-jogl.xml @@ -724,7 +724,6 @@ <antcall target="java.generate.gl.platforms" inheritRefs="true"> <param name="window.os.system" value="win32"/> - <param name="window.os0.cfg" value="${config.jogl}/gdi-win32.cfg" /> <param name="window.os1.cfg" value="${config.jogl}/wgl-win32.cfg" /> <param name="glext.platform.cfg" value="${config.jogl}/wglext.cfg" /> <param name="glext.platform.header" value="${stub.includes}/win32/wglext.c" /> diff --git a/make/build-nativewindow.xml b/make/build-nativewindow.xml index 46a3f58f4..432646841 100644 --- a/make/build-nativewindow.xml +++ b/make/build-nativewindow.xml @@ -81,6 +81,9 @@ <property name="java.part.x11" value="com/jogamp/nativewindow/impl/x11/** javax/media/nativewindow/x11/*" /> + <property name="java.part.windows" + value="com/jogamp/nativewindow/impl/windows/** javax/media/nativewindow/windows/*" /> + <!-- condition excludes --> <condition property="java.excludes.awt" @@ -231,7 +234,7 @@ </gluegen> <copy todir="${src.generated.java-cdc}"> <fileset dir="${src.generated.java}" - includes="com/jogamp/nativewindow/impl/x11/**" /> + includes="com/jogamp/nativewindow/impl/x11/** com/jogamp/nativewindow/impl/windows/**" /> </copy> </target> @@ -286,6 +289,7 @@ <echo message="Generating platform-specifics: Win32" /> <antcall target="java.generate.platforms" inheritRefs="true"> <param name="window.os.system" value="win32"/> + <param name="windowlib.os.cfg" value="${config.nativewindow}/win32-lib.cfg" /> <param name="jawt.cfg" value="${config.nativewindow}/jawt-win32.cfg" /> <param name="jawt.platform.header" value="${stub.includes}/jni/win32/jawt_md.h" /> </antcall> @@ -406,7 +410,7 @@ <linker id="linker.cfg.win32.msvc.nativewindow" extends="linker.cfg.win32.msvc"> <syslibset libs="gdi32, user32, kernel32" /> </linker> - + <linker id="linker.cfg.macosx.nativewindow" extends="linker.cfg.macosx"> <linkerarg value="-framework" /> <linkerarg value="Cocoa" /> @@ -561,6 +565,11 @@ <include name="${rootrel.src.c}/x11/XineramaHelper.c" if="isX11"/> </patternset> + <patternset id="c.src.files.windows"> + <include name="${rootrel.generated.c}/Windows/GDI*.c" if="isWindows"/> + <include name="${rootrel.src.c}/windows/GDImisc.c" if="isWindows"/> + </patternset> + <echo message="Compiling @{output.lib.name}" /> <cc outtype="shared" @@ -641,11 +650,20 @@ linker.cfg.id="${linker.cfg.id.oswin}"/> </target> - <target name="c.build.nativewindow.windowlib" depends="c.build.nativewindow.windowlib.x11"/> + <target name="c.build.nativewindow.windowlib.windows" if="isWindows"> + <javah destdir="${src.generated.c}/Windows" classpath="${classes}" class="com.jogamp.nativewindow.impl.windows.GDI" /> + + <c.build c.compiler.src.files="c.src.files.windows" + output.lib.name="nativewindow_win32" + compiler.cfg.id="${compiler.cfg.id}" + linker.cfg.id="${linker.cfg.id.oswin}"/> + </target> + <target name="c.build.nativewindow.windowlib" depends="c.build.nativewindow.windowlib.x11, c.build.nativewindow.windowlib.windows"/> <target name="c.manifest" if="isVC8Family"> <!-- exec mt, the Microsoft Manifest Tool, to include DLL manifests in order to resolve the location of msvcr80.dll --> <msvc.manifest objdir="${obj.nativewindow}" dllname="nativewindow_awt" /> + <msvc.manifest objdir="${obj.nativewindow}" dllname="nativewindow_win32" /> </target> <target name="c.build.nativewindow" depends="c.configure,c.build.nativewindow.windowlib,c.build.nativewindow.awt"> @@ -712,6 +730,19 @@ </jar> </target> + <target name="build-jars-windows" depends="setup-manifestfile"> + <jar manifest="tempversion" destfile="${nativewindow.os.windows.jar}" filesonly="true"> + <fileset dir="${classes}" + includes="${java.part.windows}" /> + </jar> + </target> + <target name="build-jars-windows-cdc" depends="setup-manifestfile-cdc"> + <jar manifest="tempversion-cdc" destfile="${nativewindow.os.windows.cdc.jar}" filesonly="true"> + <fileset dir="${classes-cdc}" + includes="${java.part.windows}" /> + </jar> + </target> + <target name="build-jars-all" depends="setup-manifestfile" unless="setup.noAWT"> <jar manifest="tempversion" destfile="${nativewindow.all.jar}" filesonly="true"> <fileset dir="${classes}" @@ -732,11 +763,11 @@ </jar> </target> - <target name="build-jars-javase" depends="setup-manifestfile,build-jars-awt,build-jars-x11,build-jars-all,build-jars-all-noawt"> + <target name="build-jars-javase" depends="setup-manifestfile,build-jars-awt,build-jars-x11,build-jars-windows,build-jars-all,build-jars-all-noawt"> <jar manifest="tempversion" destfile="${nativewindow.core.jar}" filesonly="true"> <fileset dir="${classes}" includes="${java.part.core}" - excludes="${java.part.awt} ${java.part.x11}"/> + excludes="${java.part.awt} ${java.part.x11} ${java.part.windows}"/> </jar> <jar manifest="tempversion" destfile="${build.nativewindow}/nativewindow-natives-${os.and.arch}.jar" filesonly="true"> <fileset dir="${obj.nativewindow}"> @@ -746,11 +777,11 @@ <delete file="tempversion"/> </target> - <target name="build-jars-cdc" depends="setup-manifestfile-cdc,build-jars-x11-cdc,build-jars-all-cdc"> + <target name="build-jars-cdc" depends="setup-manifestfile-cdc,build-jars-x11-cdc,build-jars-windows-cdc,build-jars-all-cdc"> <jar manifest="tempversion-cdc" destfile="${nativewindow.core.cdc.jar}" filesonly="true"> <fileset dir="${classes-cdc}" includes="${java.part.core}" - excludes="${java.part.awt} ${java.part.x11}"/> + excludes="${java.part.awt} ${java.part.x11} ${java.part.windows}"/> </jar> <jar manifest="tempversion-cdc" destfile="${build.nativewindow}/nativewindow-natives-${os.and.arch}-cdc.jar" filesonly="true"> <fileset dir="${obj.nativewindow}"> diff --git a/make/config/jogl/gdi-CustomCCode.c b/make/config/jogl/gdi-CustomCCode.c deleted file mode 100644 index 0fe9ee628..000000000 --- a/make/config/jogl/gdi-CustomCCode.c +++ /dev/null @@ -1,48 +0,0 @@ -#include <stdio.h> - -#define JOGL_DUMMY_WINDOW_NAME "__jogl_dummy_window" - -LRESULT CALLBACK DummyWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { - return DefWindowProc(hWnd,uMsg,wParam,lParam); -} - -ATOM oglClass = 0; - -HWND CreateDummyWindow( int x, int y, int width, int height ) { - HINSTANCE hInstance; - DWORD dwExStyle; - DWORD dwStyle; - HWND hWnd; - - hInstance = GetModuleHandle(NULL); - if( !oglClass ) { - WNDCLASS wc; - ZeroMemory( &wc, sizeof( wc ) ); - wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; - wc.lpfnWndProc = (WNDPROC) DummyWndProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = hInstance; - wc.hIcon = NULL; - wc.hCursor = NULL; - wc.hbrBackground = NULL; - wc.lpszMenuName = NULL; - wc.lpszClassName = JOGL_DUMMY_WINDOW_NAME; - if( !(oglClass = RegisterClass( &wc )) ) { - printf( "RegisterClass Failed: %d\n", GetLastError() ); - return( 0 ); - } - } - - dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; - dwStyle = WS_OVERLAPPEDWINDOW; - if( !(hWnd=CreateWindowEx( dwExStyle, - JOGL_DUMMY_WINDOW_NAME, - JOGL_DUMMY_WINDOW_NAME, - dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, - x, y, width, height, - NULL, NULL, hInstance, NULL ) ) ) { - return( 0 ); - } - return( hWnd ); -} diff --git a/make/config/jogl/gdi-win32.cfg b/make/config/jogl/gdi-win32.cfg deleted file mode 100644 index 7d831c7b9..000000000 --- a/make/config/jogl/gdi-win32.cfg +++ /dev/null @@ -1,26 +0,0 @@ -# This .cfg file is used to generate the interface to the wgl routines -# used internally by the WindowsGLContext implementation. -JavaOutputDir gensrc/classes -NativeOutputDir gensrc/native/jogl/Windows - -Package com.jogamp.opengl.impl.windows.wgl -JavaClass GDI -Style AllStatic -Include gl-common.cfg -Include gl-common-extensions.cfg -Include gl-desktop.cfg - -GLHeader wingdi.h - -AllowNonGLExtensions true - -CustomCCode #define WIN32_LEAN_AND_MEAN -CustomCCode #include <windows.h> -CustomCCode #undef WIN32_LEAN_AND_MEAN - -CustomCCode #include <wingdi.h> -CustomCCode #include <stddef.h> - -Include ../intptr.cfg - -IncludeAs CustomCCode gdi-CustomCCode.c diff --git a/make/config/nativewindow/win32-CustomJavaCode.java b/make/config/nativewindow/win32-CustomJavaCode.java new file mode 100644 index 000000000..cd5b00b79 --- /dev/null +++ b/make/config/nativewindow/win32-CustomJavaCode.java @@ -0,0 +1,24 @@ + + private static final long hInstance; + + static { + NWJNILibLoader.loadNativeWindow("win32"); + hInstance = initIDs0(); + if( 0 == hInstance ) { + throw new NativeWindowException("GDI: Could not initialized native stub"); + } + } + + public static synchronized void initSingleton() { + } + private static native long initIDs0(); + + public static long getModuleHandle() { + return hInstance; + } + + public static Point GetRelativeLocation(long src_win, long dest_win, int src_x, int src_y) { + return (Point) GetRelativeLocation0(src_win, dest_win, src_x, src_y); + } + private static native Object GetRelativeLocation0(long src_win, long dest_win, int src_x, int src_y); + diff --git a/make/config/nativewindow/win32-lib.cfg b/make/config/nativewindow/win32-lib.cfg new file mode 100644 index 000000000..b7535b5e1 --- /dev/null +++ b/make/config/nativewindow/win32-lib.cfg @@ -0,0 +1,37 @@ +# This .cfg file is used to generate the interface to the wgl routines +# used internally by the WindowsGLContext implementation. +JavaOutputDir gensrc/classes +NativeOutputDir gensrc/native/Windows + +Package com.jogamp.nativewindow.impl.windows +JavaClass GDI +Style AllStatic + +Opaque boolean BOOL +Opaque long HINSTANCE +Opaque long HANDLE +Opaque long HBITMAP +Opaque long HDC +Opaque long HGDIOBJ +Opaque long HGLRC +Opaque long HPBUFFERARB +Opaque long HPBUFFEREXT +Opaque boolean BOOL +Opaque long PROC +Opaque long void ** + +Import javax.media.nativewindow.util.Point +Import javax.media.nativewindow.NativeWindowException +Import com.jogamp.nativewindow.impl.NWJNILibLoader + +CustomCCode #define WIN32_LEAN_AND_MEAN +CustomCCode #include <windows.h> +CustomCCode #undef WIN32_LEAN_AND_MEAN + +CustomCCode #include <wingdi.h> +CustomCCode #include <stddef.h> + +Include ../intptr.cfg + +IncludeAs CustomJavaCode GDI win32-CustomJavaCode.java + diff --git a/make/config/nativewindow/x11-CustomJavaCode.java b/make/config/nativewindow/x11-CustomJavaCode.java index 5afa86737..0570901d5 100644 --- a/make/config/nativewindow/x11-CustomJavaCode.java +++ b/make/config/nativewindow/x11-CustomJavaCode.java @@ -29,6 +29,11 @@ public static native long CreateDummyWindow(long display, int screen_index, long visualID); public static native void DestroyDummyWindow(long display, long window); + public static Point GetRelativeLocation(long display, int screen_index, long src_win, long dest_win, int src_x, int src_y) { + return (Point) GetRelativeLocation0(display, screen_index, src_win, dest_win, src_x, src_y); + } + private static native Object GetRelativeLocation0(long display, int screen_index, long src_win, long dest_win, int src_x, int src_y); + public static native int XCloseDisplay(long display); public static native void XUnlockDisplay(long display); public static native void XLockDisplay(long display); diff --git a/make/config/nativewindow/x11-lib.cfg b/make/config/nativewindow/x11-lib.cfg index e554259b8..fb481ac51 100644 --- a/make/config/nativewindow/x11-lib.cfg +++ b/make/config/nativewindow/x11-lib.cfg @@ -12,6 +12,7 @@ NativeOutputDir gensrc/native/X11 # Imports needed by all glue code Import java.nio.* Import java.util.* +Import javax.media.nativewindow.util.Point # XID needs to be treated as a long for 32/64 bit compatibility Opaque long XID @@ -21,7 +22,6 @@ Opaque boolean Bool Opaque long GLXFBConfig IncludeAs CustomJavaCode X11Lib x11-CustomJavaCode.java -# Now resides in x11/Xmisc.c: IncludeAs CustomCCode x11-CustomCCode.c ArgumentIsString XOpenDisplay 0 ReturnsString XDisplayString diff --git a/make/scripts/tests.bat b/make/scripts/tests.bat index 8fee63e8c..cfb801d79 100644 --- a/make/scripts/tests.bat +++ b/make/scripts/tests.bat @@ -1,5 +1,5 @@ -scripts\java-win64-dbg.bat com.jogamp.newt.opengl.GLWindow -scripts\java-win64-dbg.bat com.jogamp.test.junit.jogl.acore.TestGLProfile01NEWT +REM scripts\java-win64-dbg.bat com.jogamp.newt.opengl.GLWindow +REM scripts\java-win64-dbg.bat com.jogamp.test.junit.jogl.acore.TestGLProfile01NEWT REM scripts\java-win64-dbg.bat com.jogamp.test.junit.jogl.demos.gl2.gears.newt.TestGearsNEWT -time 30000 REM scripts\java-win64-dbg.bat com.jogamp.test.junit.jogl.newt.TestSwingAWTRobotUsageBeforeJOGLInitBug411 @@ -24,3 +24,4 @@ REM scripts\java-win64-dbg.bat com.jogamp.test.junit.newt.TestScreenMode02NEWT REM scripts\java-win64-dbg.bat com.jogamp.test.junit.newt.TestDisplayLifecycle01NEWT REM scripts\java-win64-dbg.bat com.jogamp.test.junit.newt.parenting.TestParenting01NEWT REM scripts\java-win64-dbg.bat com.jogamp.test.junit.newt.parenting.TestParenting02NEWT +scripts\java-win64-dbg.bat com.jogamp.test.junit.newt.TestCloseNewtAWT diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index d61435d67..1def82be5 100644 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -36,7 +36,7 @@ function jrun() { #D_ARGS="-Dnewt.debug.Screen -Dnewt.debug.EDT -Djogamp.debug.Lock" #D_ARGS="-Dnewt.debug.EDT" #D_ARGS="-Djogl.debug=all -Dnativewindow.debug=all -Dnewt.debug=all" - D_ARGS="-Dnewt.debug=all" + #D_ARGS="-Dnewt.debug=all" X_ARGS="-Dsun.java2d.noddraw=true -Dsun.java2d.opengl=false" java $awtarg $X_ARGS $D_ARGS $* 2>&1 | tee -a java-run.log } @@ -61,7 +61,7 @@ function testawt() { #testawt com.jogamp.test.junit.jogl.demos.gl2.gears.newt.TestGearsNEWT #testawt com.jogamp.test.junit.newt.TestDisplayLifecycle01NEWT #testawt com.jogamp.test.junit.newt.TestDisplayLifecycle02NEWT -testawt com.jogamp.test.junit.newt.parenting.TestParenting01NEWT +#testawt com.jogamp.test.junit.newt.parenting.TestParenting01NEWT #testawt com.jogamp.test.junit.newt.parenting.TestParenting02NEWT #testawt com.jogamp.test.junit.newt.TestScreenMode00NEWT #testnoawt com.jogamp.test.junit.newt.TestScreenMode01NEWT @@ -97,6 +97,7 @@ testawt com.jogamp.test.junit.newt.parenting.TestParenting01NEWT #testawt com.jogamp.test.junit.newt.parenting.TestParenting03AWT #testawt com.jogamp.test.junit.newt.parenting.TestParenting03AWT -time 100000 #testawt com.jogamp.test.junit.newt.parenting.TestParenting03bAWT -time 100000 +testawt com.jogamp.test.junit.newt.TestCloseNewtAWT #testawt $* diff --git a/make/stub_includes/win32/window-system0.c b/make/stub_includes/win32/window-lib.c index c5c5d37b9..c5c5d37b9 100644 --- a/make/stub_includes/win32/window-system0.c +++ b/make/stub_includes/win32/window-lib.c diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java index 9a86f7d08..3f7028d56 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java @@ -40,9 +40,14 @@ package com.jogamp.opengl.impl.windows.wgl; -import javax.media.opengl.*; -import com.jogamp.opengl.impl.*; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLProfile; + import com.jogamp.nativewindow.impl.ProxySurface; +import com.jogamp.nativewindow.impl.windows.GDI; +import com.jogamp.nativewindow.impl.windows.PIXELFORMATDESCRIPTOR; public class WindowsDummyWGLDrawable extends WindowsWGLDrawable { private long hwnd, hdc; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java index 5ac937be8..f50b1a716 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java @@ -40,10 +40,19 @@ package com.jogamp.opengl.impl.windows.wgl; -import javax.media.opengl.*; -import javax.media.nativewindow.*; -import com.jogamp.opengl.impl.*; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.DefaultGraphicsScreen; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; + import com.jogamp.nativewindow.impl.ProxySurface; +import com.jogamp.nativewindow.impl.windows.GDI; +import com.jogamp.opengl.impl.GLContextShareSet; + public class WindowsExternalWGLContext extends WindowsWGLContext { private boolean firstMakeCurrent = true; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java index ec0bd7c7a..8f41db365 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java @@ -40,10 +40,17 @@ package com.jogamp.opengl.impl.windows.wgl; -import javax.media.nativewindow.*; -import javax.media.opengl.*; -import com.jogamp.opengl.impl.*; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.DefaultGraphicsScreen; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; + import com.jogamp.nativewindow.impl.ProxySurface; +import com.jogamp.nativewindow.impl.windows.GDI; public class WindowsExternalWGLDrawable extends WindowsWGLDrawable { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java index f58d2f4bc..8bb781a45 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java @@ -40,9 +40,16 @@ package com.jogamp.opengl.impl.windows.wgl; -import javax.media.opengl.*; -import javax.media.nativewindow.*; -import com.jogamp.opengl.impl.*; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.SurfaceChangeable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLException; + +import com.jogamp.nativewindow.impl.windows.BITMAPINFO; +import com.jogamp.nativewindow.impl.windows.BITMAPINFOHEADER; +import com.jogamp.nativewindow.impl.windows.GDI; public class WindowsOffscreenWGLDrawable extends WindowsWGLDrawable { private long origbitmap; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java index 0198f334c..a5631aded 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java @@ -40,12 +40,20 @@ package com.jogamp.opengl.impl.windows.wgl; -import javax.media.opengl.*; -import javax.media.nativewindow.*; -import com.jogamp.opengl.impl.*; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.SurfaceChangeable; +import javax.media.opengl.GL; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLException; +import javax.media.opengl.GLPbuffer; +import javax.media.opengl.GLProfile; + +import com.jogamp.nativewindow.impl.windows.GDI; +import com.jogamp.nativewindow.impl.windows.PIXELFORMATDESCRIPTOR; public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { - private long cachedParentHdc; private WGLExt cachedWGLExt; // cached WGLExt instance from parent GLCanvas, // needed to destroy pbuffer private long buffer; // pbuffer handle @@ -270,8 +278,7 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { // Set up instance variables buffer = tmpBuffer; ((SurfaceChangeable)ns).setSurfaceHandle(tmpHdc); - cachedWGLExt = wglExt; - cachedParentHdc = parentHdc; + cachedWGLExt = wglExt; // Re-query chosen pixel format { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java index 7be597dcc..529fda2c9 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java @@ -40,13 +40,23 @@ package com.jogamp.opengl.impl.windows.wgl; -import java.nio.*; -import java.util.*; -import javax.media.opengl.*; -import javax.media.nativewindow.*; -import com.jogamp.opengl.impl.*; +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.Map; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLException; + import com.jogamp.gluegen.runtime.ProcAddressTable; import com.jogamp.gluegen.runtime.opengl.GLProcAddressResolver; +import com.jogamp.nativewindow.impl.windows.GDI; +import com.jogamp.opengl.impl.GLContextImpl; +import com.jogamp.opengl.impl.GLContextShareSet; +import com.jogamp.opengl.impl.GLDrawableImpl; + public class WindowsWGLContext extends GLContextImpl { private static final Map/*<String, String>*/ functionNameMap; @@ -86,7 +96,7 @@ public class WindowsWGLContext extends GLContextImpl { wglGetExtensionsStringEXTAvailable=false; wglMakeContextCurrentInitialized=false; wglMakeContextCurrentAvailable=false; - // no inner state wglExt=null; + // no inner state _wglExt=null; wglExtProcAddressTable=null; } @@ -102,7 +112,7 @@ public class WindowsWGLContext extends GLContextImpl { } public boolean wglMakeContextCurrent(long hDrawDC, long hReadDC, long ctx) { - WGLExt wglExt = getWGLExt(); + WGLExt _wglExt = getWGLExt(); if (!wglMakeContextCurrentInitialized) { wglMakeContextCurrentAvailable = isFunctionAvailable("wglMakeContextCurrent"); wglMakeContextCurrentInitialized = true; @@ -111,7 +121,7 @@ public class WindowsWGLContext extends GLContextImpl { } } if(wglMakeContextCurrentAvailable) { - return wglExt.wglMakeContextCurrent(hDrawDC, hReadDC, ctx); + return _wglExt.wglMakeContextCurrent(hDrawDC, hReadDC, ctx); } return WGL.wglMakeCurrent(hDrawDC, ctx); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawable.java index 984708f52..bbbd93435 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawable.java @@ -40,23 +40,23 @@ package com.jogamp.opengl.impl.windows.wgl; -import javax.media.nativewindow.*; -import javax.media.opengl.*; -import com.jogamp.opengl.impl.*; -import java.security.*; +import java.security.AccessController; +import javax.media.nativewindow.NativeSurface; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLException; + +import com.jogamp.nativewindow.impl.windows.GDI; +import com.jogamp.opengl.impl.Debug; +import com.jogamp.opengl.impl.GLDrawableImpl; +import com.jogamp.opengl.impl.GLDynamicLookupHelper; + public abstract class WindowsWGLDrawable extends GLDrawableImpl { - private static final int MAX_SET_PIXEL_FORMAT_FAIL_COUNT = 5; private static final boolean PROFILING = Debug.isPropertyDefined("jogl.debug.GLDrawable.profiling", true, AccessController.getContext()); private static final int PROFILING_TICKS = 200; - private int profilingLockSurfaceTicks; - private long profilingLockSurfaceTime; - private int profilingUnlockSurfaceTicks; - private long profilingUnlockSurfaceTime; private int profilingSwapBuffersTicks; private long profilingSwapBuffersTime; - public WindowsWGLDrawable(GLDrawableFactory factory, NativeSurface comp, boolean realized) { super(factory, comp, realized); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java index 64dd0eb46..462079913 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java @@ -40,19 +40,39 @@ package com.jogamp.opengl.impl.windows.wgl; -import java.nio.*; -import java.util.*; -import javax.media.nativewindow.*; -import javax.media.opengl.*; +import java.nio.Buffer; +import java.nio.ShortBuffer; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; + +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.DefaultGraphicsScreen; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.nativewindow.windows.WindowsGraphicsDevice; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesChooser; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawable; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; + import com.jogamp.common.JogampRuntimeException; -import com.jogamp.common.util.*; -import com.jogamp.opengl.impl.*; +import com.jogamp.common.util.ReflectionUtil; import com.jogamp.nativewindow.impl.ProxySurface; -import javax.media.nativewindow.windows.WindowsGraphicsDevice; +import com.jogamp.nativewindow.impl.windows.GDI; +import com.jogamp.opengl.impl.Debug; +import com.jogamp.opengl.impl.DesktopGLDynamicLookupHelper; +import com.jogamp.opengl.impl.GLDrawableFactoryImpl; +import com.jogamp.opengl.impl.GLDrawableImpl; +import com.jogamp.opengl.impl.GLDynamicLookupHelper; public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { - private static final boolean VERBOSE = Debug.verbose(); - private static final DesktopGLDynamicLookupHelper windowsWGLDynamicLookupHelper; static { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfiguration.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfiguration.java index 619034da4..6c006577e 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfiguration.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfiguration.java @@ -33,9 +33,22 @@ package com.jogamp.opengl.impl.windows.wgl; -import javax.media.nativewindow.*; -import javax.media.opengl.*; -import com.jogamp.opengl.impl.*; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.DefaultGraphicsConfiguration; +import javax.media.nativewindow.NativeSurface; +import javax.media.opengl.DefaultGLCapabilitiesChooser; +import javax.media.opengl.GL; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesChooser; +import javax.media.opengl.GLDrawable; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLException; +import javax.media.opengl.GLPbuffer; +import javax.media.opengl.GLProfile; + +import com.jogamp.nativewindow.impl.windows.GDI; +import com.jogamp.nativewindow.impl.windows.PIXELFORMATDESCRIPTOR; +import com.jogamp.opengl.impl.GLContextImpl; public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguration implements Cloneable { // Keep this under the same debug flag as the drawable factory for convenience diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java index 372630446..1d8f14d94 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java @@ -33,12 +33,24 @@ package com.jogamp.opengl.impl.windows.wgl; -import javax.media.nativewindow.*; -import javax.media.nativewindow.windows.*; -import com.jogamp.nativewindow.impl.*; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.Capabilities; +import javax.media.nativewindow.CapabilitiesChooser; +import javax.media.nativewindow.DefaultGraphicsScreen; +import javax.media.nativewindow.GraphicsConfigurationFactory; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesChooser; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; -import javax.media.opengl.*; -import com.jogamp.opengl.impl.*; +import com.jogamp.nativewindow.impl.windows.GDI; +import com.jogamp.nativewindow.impl.windows.PIXELFORMATDESCRIPTOR; /** Subclass of GraphicsConfigurationFactory used when non-AWT tookits are used on Windows platforms. Toolkits will likely need to delegate diff --git a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java index f6dce1c9c..ab23e18f8 100644 --- a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java +++ b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java @@ -97,10 +97,21 @@ public abstract class GLDrawableFactory { protected static ArrayList/*<GLDrawableFactoryImpl>*/ glDrawableFactories = new ArrayList(); + // Shutdown hook mechanism for the factory + private static boolean factoryShutdownHookRegistered = false; + private static Thread factoryShutdownHook = null; + /** * Instantiate singleton factories if available, EGLES1, EGLES2 and the OS native ones. */ static { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + registerFactoryShutdownHook(); + return null; + } + }); + nativeOSType = NativeWindowFactory.getNativeWindowType(true); GLDrawableFactory tmp = null; @@ -151,15 +162,38 @@ public abstract class GLDrawableFactory { eglFactory = tmp; } - private AbstractGraphicsDevice defaultSharedDevice = null; + private static synchronized void registerFactoryShutdownHook() { + if (factoryShutdownHookRegistered) { + return; + } + factoryShutdownHook = new Thread(new Runnable() { + public void run() { + GLDrawableFactory.shutdownImpl(); + } + }); + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + Runtime.getRuntime().addShutdownHook(factoryShutdownHook); + return null; + } + }); + factoryShutdownHookRegistered = true; + } - protected GLDrawableFactory() { - synchronized(glDrawableFactories) { - glDrawableFactories.add(this); + private static synchronized void unregisterFactoryShutdownHook() { + if (!factoryShutdownHookRegistered) { + return; } + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + Runtime.getRuntime().removeShutdownHook(factoryShutdownHook); + return null; + } + }); + factoryShutdownHookRegistered = false; } - protected static void shutdown() { + private static void shutdownImpl() { synchronized(glDrawableFactories) { for(int i=0; i<glDrawableFactories.size(); i++) { GLDrawableFactory factory = (GLDrawableFactory) glDrawableFactories.get(i); @@ -169,6 +203,24 @@ public abstract class GLDrawableFactory { } } + protected static void shutdown() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + unregisterFactoryShutdownHook(); + return null; + } + }); + shutdownImpl(); + } + + private AbstractGraphicsDevice defaultSharedDevice = null; + + protected GLDrawableFactory() { + synchronized(glDrawableFactories) { + glDrawableFactories.add(this); + } + } + protected abstract void shutdownInstance(); /** diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java index 878c4024e..02252ac33 100644 --- a/src/jogl/classes/javax/media/opengl/GLProfile.java +++ b/src/jogl/classes/javax/media/opengl/GLProfile.java @@ -103,7 +103,6 @@ public class GLProfile { // since this skips checking further access AccessController.doPrivileged(new PrivilegedAction() { public Object run() { - registerFactoryShutdownHook(); initProfilesForDefaultDevices(firstUIActionOnProcess); return null; } @@ -122,8 +121,9 @@ public class GLProfile { /** * Manual shutdown method, may be called after your last JOGL use * within the running JVM.<br> - * This method is called via the JVM shutdown hook.<br> * It releases all temporary created resources, ie issues {@link javax.media.opengl.GLDrawableFactory#shutdown()}.<br> + * The shutdown implementation is called via the JVM shutdown hook, if not manually invoked here.<br> + * Invoke <code>shutdown()</code> manually is recommended, due to the unreliable JVM state within the shutdown hook.<br> */ public static synchronized void shutdown() { if(initialized) { @@ -1065,10 +1065,6 @@ public class GLProfile { static boolean initialized = false; - // Shutdown hook mechanism for the factory - private static boolean factoryShutdownHookRegistered = false; - private static Thread factoryShutdownHook = null; - /** * Tries the profiles implementation and native libraries. * Throws an GLException if no profile could be found at all. @@ -1299,24 +1295,6 @@ public class GLProfile { return defaultEGLDevice; } - private static synchronized void registerFactoryShutdownHook() { - if (factoryShutdownHookRegistered) { - return; - } - factoryShutdownHook = new Thread(new Runnable() { - public void run() { - GLDrawableFactory.shutdown(); - } - }); - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - Runtime.getRuntime().addShutdownHook(factoryShutdownHook); - return null; - } - }); - factoryShutdownHookRegistered = true; - } - private static void validateInitialization() { if(!initialized) { synchronized(GLProfile.class) { diff --git a/src/junit/com/jogamp/test/junit/newt/TestCloseNewtAWT.java b/src/junit/com/jogamp/test/junit/newt/TestCloseNewtAWT.java new file mode 100644 index 000000000..4aa028308 --- /dev/null +++ b/src/junit/com/jogamp/test/junit/newt/TestCloseNewtAWT.java @@ -0,0 +1,118 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.test.junit.newt; + +import org.junit.Test; + +import javax.swing.JFrame; +import javax.swing.SwingUtilities; +import java.awt.EventQueue; +import java.lang.reflect.InvocationTargetException; + +import javax.media.nativewindow.util.Point; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; +import com.jogamp.newt.Window; +import com.jogamp.newt.awt.NewtCanvasAWT; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.test.junit.util.UITestCase; + +public class TestCloseNewtAWT extends UITestCase { + + GLWindow newtWindow = null; + NewtCanvasAWT newtCanvas = null; + JFrame frame = null; + + class MyCanvas extends NewtCanvasAWT { + public MyCanvas(Window window) { + super(window); + } + + public void addNotify() { + System.err.println("MyCanvas START add: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock())); + super.addNotify(); + System.err.println("MyCanvas END add: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock())); + } + + public void removeNotify() { + System.err.println("MyCanvas START remove: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock())); + + // trigger critical situation around the AWT TreeLock + newtWindow.runOnEDTIfAvail(true, new Runnable() { + public void run() { + // NEWT EDT while AWT is locked + System.err.println("MyCanvas On NEWT-EDT From AWT-EDT: "+Thread.currentThread()+ + ", holds AWTTreeLock: "+Thread.holdsLock(MyCanvas.this.getTreeLock())); + + // Critical: Within NEWT EDT, while AWT is locked + Point p = MyCanvas.this.getNativeWindow().getLocationOnScreen(null); + System.err.println("MyCanvas On NEWT-EDT: position: "+p); + } + }); + System.err.println("MyCanvas passed critical: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock())); + + super.removeNotify(); + + System.err.println("MyCanvas END remove: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock())); + } + } + + @Test + public void testCloseNewtAWT() throws InterruptedException, InvocationTargetException { + newtWindow = GLWindow.create(new GLCapabilities(GLProfile.getDefault())); + newtCanvas = new MyCanvas(newtWindow); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + frame = new JFrame("NEWT Close Test"); + frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + frame.getContentPane().add(newtCanvas); + frame.pack(); + frame.setSize(800, 600); + frame.setVisible(true); + } + }); + Thread.sleep(1000); + + // programatically close window + EventQueue.invokeAndWait(new Runnable() { + public void run() { + frame.dispose(); + } + }); + + GLProfile.shutdown(); + } + + public static void main(String[] args) { + String tstname = TestCloseNewtAWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cSwingAWT.java b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cSwingAWT.java index ec54a0f9e..fb2c74455 100644 --- a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cSwingAWT.java +++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cSwingAWT.java @@ -29,29 +29,19 @@ package com.jogamp.test.junit.newt.parenting; import java.lang.reflect.*; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; import org.junit.Assert; -import org.junit.Before; import org.junit.BeforeClass; -import org.junit.After; -import org.junit.AfterClass; import org.junit.Test; import java.awt.Button; import java.awt.BorderLayout; -import java.awt.Canvas; import java.awt.Container; -import java.awt.Frame; -import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; import javax.media.opengl.*; -import javax.media.nativewindow.*; import com.jogamp.opengl.util.Animator; import com.jogamp.newt.*; @@ -63,7 +53,6 @@ import java.io.IOException; import com.jogamp.test.junit.util.*; import com.jogamp.test.junit.jogl.demos.es1.RedSquare; -import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears; public class TestParenting01cSwingAWT extends UITestCase { static int width, height; diff --git a/src/junit/com/jogamp/test/junit/util/UITestCase.java b/src/junit/com/jogamp/test/junit/util/UITestCase.java index e169405b0..8baa716b7 100644 --- a/src/junit/com/jogamp/test/junit/util/UITestCase.java +++ b/src/junit/com/jogamp/test/junit/util/UITestCase.java @@ -33,7 +33,6 @@ import org.junit.BeforeClass; import org.junit.After; import org.junit.AfterClass; -import java.lang.reflect.InvocationTargetException; public abstract class UITestCase { diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWJNILibLoader.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWJNILibLoader.java index b1cd71386..3b2a728e5 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWJNILibLoader.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWJNILibLoader.java @@ -29,13 +29,8 @@ package com.jogamp.nativewindow.impl; -// FIXME: refactor Java SE dependencies -//import java.awt.Toolkit; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.security.AccessController; import java.security.PrivilegedAction; -import java.util.HashSet; import com.jogamp.common.jvm.JNILibLoaderBase; public class NWJNILibLoader extends JNILibLoaderBase { diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java index 8ef2ba227..de6360212 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java @@ -41,7 +41,10 @@ import com.jogamp.common.util.locks.RecursiveLock; import java.awt.Component; import java.awt.Window; -import javax.media.nativewindow.*; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeWindow; +import javax.media.nativewindow.NativeWindowException; import javax.media.nativewindow.util.Point; import javax.media.nativewindow.util.Rectangle; @@ -64,12 +67,11 @@ public abstract class JAWTWindow implements NativeWindow { init((Component)comp); } - protected void init(Component windowObject) throws NativeWindowException { + private final void init(Component windowObject) throws NativeWindowException { invalidate(); this.component = windowObject; validateNative(); } - protected abstract void validateNative() throws NativeWindowException; protected synchronized void invalidate() { @@ -78,7 +80,7 @@ public abstract class JAWTWindow implements NativeWindow { bounds = new Rectangle(); } - protected void updateBounds(JAWT_Rectangle jawtBounds) { + protected final void updateBounds(JAWT_Rectangle jawtBounds) { bounds.setX(jawtBounds.getX()); bounds.setY(jawtBounds.getY()); bounds.setWidth(jawtBounds.getWidth()); @@ -86,9 +88,9 @@ public abstract class JAWTWindow implements NativeWindow { } /** @return the JAWT_DrawingSurfaceInfo's (JAWT_Rectangle) bounds, updated with lock */ - public Rectangle getBounds() { return bounds; } + public final Rectangle getBounds() { return bounds; } - public Component getAWTComponent() { + public final Component getAWTComponent() { return component; } @@ -96,7 +98,7 @@ public abstract class JAWTWindow implements NativeWindow { // SurfaceUpdateListener // - public void surfaceUpdated(Object updater, NativeSurface ns, long when) { + public final void surfaceUpdated(Object updater, NativeSurface ns, long when) { // nop } @@ -158,36 +160,36 @@ public abstract class JAWTWindow implements NativeWindow { return recurLock.getOwner(); } - public boolean surfaceSwap() { + public final boolean surfaceSwap() { return false; } - public void surfaceUpdated(Object updater, NativeWindow window, long when) { } + public final void surfaceUpdated(Object updater, NativeWindow window, long when) { } - public long getSurfaceHandle() { + public final long getSurfaceHandle() { return drawable; } - public AbstractGraphicsConfiguration getGraphicsConfiguration() { + public final AbstractGraphicsConfiguration getGraphicsConfiguration() { return config; } - public long getDisplayHandle() { + public final long getDisplayHandle() { return config.getScreen().getDevice().getHandle(); } - public int getScreenIndex() { + public final int getScreenIndex() { return config.getScreen().getIndex(); } - public void setSize(int width, int height) { + public final void setSize(int width, int height) { component.setSize(width, height); } - public int getWidth() { + public final int getWidth() { return component.getWidth(); } - public int getHeight() { + public final int getHeight() { return component.getHeight(); } @@ -204,7 +206,7 @@ public abstract class JAWTWindow implements NativeWindow { invalidate(); } - public NativeWindow getParent() { + public final NativeWindow getParent() { return null; } @@ -212,23 +214,45 @@ public abstract class JAWTWindow implements NativeWindow { return drawable; } - public int getX() { + public final int getX() { return component.getX(); } - public int getY() { + public final int getY() { return component.getY(); } - public Point getLocationOnScreen(Point point) { + public Point getLocationOnScreen(Point storage) { + if( 0 != getWindowHandle() ) { + Point d; + // windowLock.lock(); + try { + d = getLocationOnScreenImpl(0, 0); + } finally { + // windowLock.unlock(); + } + if(null!=d) { + if(null!=storage) { + storage.translate(d.getX(),d.getY()); + return storage; + } + return d; + } + // fall through intended .. + } + + if(!Thread.holdsLock(component.getTreeLock())) { + return null; // avoid deadlock .. + } java.awt.Point awtLOS = component.getLocationOnScreen(); int dx = (int) ( awtLOS.getX() + .5 ) ; int dy = (int) ( awtLOS.getY() + .5 ) ; - if(null!=point) { - return point.translate(dx, dy); + if(null!=storage) { + return storage.translate(dx, dy); } return new Point(dx, dy); } + protected abstract Point getLocationOnScreenImpl(int x, int y); public String toString() { StringBuffer sb = new StringBuffer(); diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java index bcaa66847..f511c7082 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java @@ -47,6 +47,7 @@ import java.awt.GraphicsEnvironment; import javax.media.nativewindow.*; import java.security.*; +import javax.media.nativewindow.util.Point; public class MacOSXJAWTWindow extends JAWTWindow { @@ -125,6 +126,10 @@ public class MacOSXJAWTWindow extends JAWTWindow { macosxdsi = null; } + protected Point getLocationOnScreenImpl(int x, int y) { + return null; // FIXME + } + // Variables for lockSurface/unlockSurface private JAWT_DrawingSurface ds; private boolean dsLocked; diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java index d19a11f66..14d6eebcd 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java @@ -40,10 +40,17 @@ package com.jogamp.nativewindow.impl.jawt.windows; -import com.jogamp.nativewindow.impl.*; -import com.jogamp.nativewindow.impl.jawt.*; +import com.jogamp.nativewindow.impl.jawt.JAWT; +import com.jogamp.nativewindow.impl.jawt.JAWTFactory; +import com.jogamp.nativewindow.impl.jawt.JAWTWindow; +import com.jogamp.nativewindow.impl.jawt.JAWT_DrawingSurface; +import com.jogamp.nativewindow.impl.jawt.JAWT_DrawingSurfaceInfo; +import com.jogamp.nativewindow.impl.windows.GDI; -import javax.media.nativewindow.*; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.NativeWindow; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.util.Point; public class WindowsJAWTWindow extends JAWTWindow { @@ -152,6 +159,10 @@ public class WindowsJAWTWindow extends JAWTWindow { return windowHandle; } + protected Point getLocationOnScreenImpl(int x, int y) { + return GDI.GetRelativeLocation( getWindowHandle(), 0 /*root win*/, x, y); + } + // Variables for lockSurface/unlockSurface private JAWT_DrawingSurface ds; private boolean dsLocked; diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11JAWTWindow.java index a5d36b6dd..1324bd199 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11JAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11JAWTWindow.java @@ -37,12 +37,20 @@ package com.jogamp.nativewindow.impl.jawt.x11; -import javax.media.nativewindow.*; -import javax.media.nativewindow.awt.*; - -import com.jogamp.nativewindow.impl.x11.*; -import com.jogamp.nativewindow.impl.jawt.*; - +import com.jogamp.nativewindow.impl.jawt.JAWT; +import com.jogamp.nativewindow.impl.jawt.JAWTFactory; +import com.jogamp.nativewindow.impl.jawt.JAWTWindow; +import com.jogamp.nativewindow.impl.jawt.JAWT_DrawingSurface; +import com.jogamp.nativewindow.impl.jawt.JAWT_DrawingSurfaceInfo; +import com.jogamp.nativewindow.impl.x11.X11Util; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.NativeWindow; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.nativewindow.awt.AWTGraphicsDevice; +import javax.media.nativewindow.util.Point; public class X11JAWTWindow extends JAWTWindow { @@ -134,6 +142,10 @@ public class X11JAWTWindow extends JAWTWindow { x11dsi = null; } + protected Point getLocationOnScreenImpl(int x, int y) { + return X11Util.GetRelativeLocation( getDisplayHandle(), getScreenIndex(), getWindowHandle(), 0 /*root win*/, x, y); + } + // Variables for lockSurface/unlockSurface private JAWT_DrawingSurface ds; private boolean dsLocked; diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java index f7f4828ca..bd76908a1 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java @@ -44,6 +44,7 @@ import java.nio.ShortBuffer; import java.security.AccessController; import java.util.ArrayList; import java.util.List; +import javax.media.nativewindow.util.Point; /** * Contains a thread safe X11 utility to retrieve display connections. @@ -517,6 +518,15 @@ public class X11Util { } } + public static Point GetRelativeLocation(long display, int screen_index, long src_win, long dest_win, int src_x, int src_y) { + lockDefaultToolkit(display); + try { + return X11Lib.GetRelativeLocation(display, screen_index, src_win, dest_win, src_x, src_y); + } finally { + unlockDefaultToolkit(display); + } + } + public static XVisualInfo[] XGetVisualInfo(long display, long arg1, XVisualInfo arg2, int[] arg3, int arg3_offset) { lockDefaultToolkit(display); try { diff --git a/src/nativewindow/native/windows/GDImisc.c b/src/nativewindow/native/windows/GDImisc.c new file mode 100644 index 000000000..3c1001115 --- /dev/null +++ b/src/nativewindow/native/windows/GDImisc.c @@ -0,0 +1,152 @@ +#include <jni.h> +#include <stdlib.h> +#include <assert.h> + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#undef WIN32_LEAN_AND_MEAN + +#include <wingdi.h> +#include <stddef.h> + +#ifdef _WIN32 + #ifdef _MSC_VER + /* This typedef is apparently needed for Microsoft compilers before VC8, + and on Windows CE */ + #if (_MSC_VER < 1400) || defined(UNDER_CE) + #ifdef _WIN64 + typedef long long intptr_t; + #else + typedef int intptr_t; + #endif + #endif + #else + #include <inttypes.h> + #endif +#else + #include <inttypes.h> +#endif + +#include <stdio.h> + +#include "com_jogamp_nativewindow_impl_windows_GDI.h" + +// #define VERBOSE_ON 1 + +#ifdef VERBOSE_ON + #define DBG_PRINT(args...) fprintf(stderr, args); +#else + #define DBG_PRINT(args...) +#endif + +static void _FatalError(JNIEnv *env, const char* msg, ...) +{ + char buffer[512]; + va_list ap; + + va_start(ap, msg); + vsnprintf(buffer, sizeof(buffer), msg, ap); + va_end(ap); + + fprintf(stderr, "%s\n", buffer); + (*env)->FatalError(env, buffer); +} + +static const char * const ClazzNamePoint = "javax/media/nativewindow/util/Point"; +static const char * const ClazzAnyCstrName = "<init>"; +static const char * const ClazzNamePointCstrSignature = "(II)V"; + +static jclass pointClz = NULL; +static jmethodID pointCstr = NULL; + +#define NATIVEWINDOW_DUMMY_WINDOW_NAME "__nativewindow_dummy_window" +static ATOM nativewindowClass = 0; + +LRESULT CALLBACK DummyWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { + return DefWindowProc(hWnd,uMsg,wParam,lParam); +} + +HWND CreateDummyWindow(HINSTANCE hInstance, int x, int y, int width, int height ) { + DWORD dwExStyle; + DWORD dwStyle; + HWND hWnd; + + dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; + dwStyle = WS_OVERLAPPEDWINDOW; + if( !(hWnd=CreateWindowEx( dwExStyle, + NATIVEWINDOW_DUMMY_WINDOW_NAME, + NATIVEWINDOW_DUMMY_WINDOW_NAME, + dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, + x, y, width, height, + NULL, NULL, hInstance, NULL ) ) ) { + return( 0 ); + } + return( hWnd ); +} + +/* + * Class: com_jogamp_nativewindow_impl_windows_GDI + * Method: initIDs0 + * Signature: ()Z + */ +JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_windows_GDI_initIDs0 + (JNIEnv *env, jclass clazz) +{ + if(NULL==pointClz) { + jclass c = (*env)->FindClass(env, ClazzNamePoint); + if(NULL==c) { + _FatalError(env, "FatalError com_jogamp_nativewindow_impl_windows_GDI: can't find %s", ClazzNamePoint); + } + pointClz = (jclass)(*env)->NewGlobalRef(env, c); + (*env)->DeleteLocalRef(env, c); + if(NULL==pointClz) { + _FatalError(env, "FatalError com_jogamp_nativewindow_impl_windows_GDI: can't use %s", ClazzNamePoint); + } + pointCstr = (*env)->GetMethodID(env, pointClz, ClazzAnyCstrName, ClazzNamePointCstrSignature); + if(NULL==pointCstr) { + _FatalError(env, "FatalError com_jogamp_nativewindow_impl_windows_GDI: can't fetch %s.%s %s", + ClazzNamePoint, ClazzAnyCstrName, ClazzNamePointCstrSignature); + } + } + HINSTANCE hInstance = GetModuleHandle(NULL); + if( !nativewindowClass ) { + WNDCLASS wc; + ZeroMemory( &wc, sizeof( wc ) ); + wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; + wc.lpfnWndProc = (WNDPROC) DummyWndProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = hInstance; + wc.hIcon = NULL; + wc.hCursor = NULL; + wc.hbrBackground = NULL; + wc.lpszMenuName = NULL; + wc.lpszClassName = NATIVEWINDOW_DUMMY_WINDOW_NAME; + if( !(nativewindowClass = RegisterClass( &wc )) ) { + _FatalError(env, "FatalError com_jogamp_nativewindow_impl_windows_GDI: RegisterClass Failed: %d", GetLastError() ); + } + } + return (jlong) hInstance; +} + +/* + * Class: com_jogamp_nativewindow_impl_windows_GDI + * Method: GetRelativeLocation0 + * Signature: (JJII)Ljavax/media/nativewindow/util/Point; + */ +JNIEXPORT jobject JNICALL Java_com_jogamp_nativewindow_impl_windows_GDI_GetRelativeLocation0 + (JNIEnv *env, jclass unused, jlong jsrc_win, jlong jdest_win, jint src_x, jint src_y) +{ + HWND src_win = (HWND) (intptr_t) jsrc_win; + HWND dest_win = (HWND) (intptr_t) jdest_win; + POINT dest = { src_x, src_y } ; + int res; + + res = MapWindowPoints(src_win, dest_win, &dest, 1); + + DBG_PRINT("*** WindowsWindow: getRelativeLocation0: %p %d/%d -> %p %d/%d - ok: %d\n", + (void*)src_win, src_x, src_y, (void*)dest_win, (int)dest.x, (int)dest.y, res); + + return (*env)->NewObject(env, pointClz, pointCstr, (jint)dest.x, (jint)dest.y); +} + diff --git a/src/nativewindow/native/x11/Xmisc.c b/src/nativewindow/native/x11/Xmisc.c index 0e91ae831..91292fd37 100644 --- a/src/nativewindow/native/x11/Xmisc.c +++ b/src/nativewindow/native/x11/Xmisc.c @@ -85,14 +85,9 @@ Bool XF86VidModeSetGammaRamp( // #define VERBOSE_ON 1 #ifdef VERBOSE_ON - // Workaround for ancient compiler on Solaris/SPARC #define DBG_PRINT(args...) fprintf(stderr, args); - #else - - // Workaround for ancient compiler on Solaris/SPARC #define DBG_PRINT(args...) - #endif /* Need to pull this in as we don't have a stub header for it */ @@ -116,10 +111,15 @@ static const char * const ClazzNameBuffersStaticCstrName = "copyByteBuffer"; static const char * const ClazzNameBuffersStaticCstrSignature = "(Ljava/nio/ByteBuffer;)Ljava/nio/ByteBuffer;"; static const char * const ClazzNameByteBuffer = "java/nio/ByteBuffer"; static const char * const ClazzNameRuntimeException = "java/lang/RuntimeException"; +static const char * const ClazzNamePoint = "javax/media/nativewindow/util/Point"; +static const char * const ClazzAnyCstrName = "<init>"; +static const char * const ClazzNamePointCstrSignature = "(II)V"; static jclass clazzBuffers = NULL; static jmethodID cstrBuffers = NULL; static jclass clazzByteBuffer = NULL; static jclass clazzRuntimeException=NULL; +static jclass pointClz = NULL; +static jmethodID pointCstr = NULL; static void _initClazzAccess(JNIEnv *env) { jclass c; @@ -128,39 +128,54 @@ static void _initClazzAccess(JNIEnv *env) { c = (*env)->FindClass(env, ClazzNameRuntimeException); if(NULL==c) { - _FatalError(env, "Nativewindow X11Lib: can't find %s", ClazzNameRuntimeException); + _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameRuntimeException); } clazzRuntimeException = (jclass)(*env)->NewGlobalRef(env, c); (*env)->DeleteLocalRef(env, c); if(NULL==clazzRuntimeException) { - _FatalError(env, "FatalError: NEWT X11Window: can't use %s", ClazzNameRuntimeException); + _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameRuntimeException); } c = (*env)->FindClass(env, ClazzNameBuffers); if(NULL==c) { - _FatalError(env, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameBuffers); + _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameBuffers); } clazzBuffers = (jclass)(*env)->NewGlobalRef(env, c); (*env)->DeleteLocalRef(env, c); if(NULL==clazzBuffers) { - _FatalError(env, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameBuffers); + _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameBuffers); } c = (*env)->FindClass(env, ClazzNameByteBuffer); if(NULL==c) { - _FatalError(env, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameByteBuffer); + _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameByteBuffer); } clazzByteBuffer = (jclass)(*env)->NewGlobalRef(env, c); (*env)->DeleteLocalRef(env, c); if(NULL==c) { - _FatalError(env, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameByteBuffer); + _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameByteBuffer); } cstrBuffers = (*env)->GetStaticMethodID(env, clazzBuffers, ClazzNameBuffersStaticCstrName, ClazzNameBuffersStaticCstrSignature); if(NULL==cstrBuffers) { - _FatalError(env, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib:: can't create %s.%s %s", + _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't create %s.%s %s", ClazzNameBuffers, ClazzNameBuffersStaticCstrName, ClazzNameBuffersStaticCstrSignature); } + + c = (*env)->FindClass(env, ClazzNamePoint); + if(NULL==c) { + _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNamePoint); + } + pointClz = (jclass)(*env)->NewGlobalRef(env, c); + (*env)->DeleteLocalRef(env, c); + if(NULL==pointClz) { + _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNamePoint); + } + pointCstr = (*env)->GetMethodID(env, pointClz, ClazzAnyCstrName, ClazzNamePointCstrSignature); + if(NULL==pointCstr) { + _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't fetch %s.%s %s", + ClazzNamePoint, ClazzAnyCstrName, ClazzNamePointCstrSignature); + } } static void _throwNewRuntimeException(Display * unlockDisplay, JNIEnv *env, const char* msg, ...) @@ -386,7 +401,7 @@ Java_com_jogamp_nativewindow_impl_x11_X11Lib_XCloseDisplay__J(JNIEnv *env, jclas * Signature: (JIJ)J */ JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_CreateDummyWindow - (JNIEnv *env, jobject obj, jlong display, jint screen_index, jlong visualID) + (JNIEnv *env, jclass unused, jlong display, jint screen_index, jlong visualID) { Display * dpy = (Display *)(intptr_t)display; int scrn_idx = (int)screen_index; @@ -495,7 +510,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_CreateDummy * Signature: (JJ)V */ JNIEXPORT void JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_DestroyDummyWindow - (JNIEnv *env, jobject obj, jlong display, jlong window) + (JNIEnv *env, jclass unused, jlong display, jlong window) { Display * dpy = (Display *)(intptr_t)display; Window w = (Window) window; @@ -512,3 +527,36 @@ JNIEXPORT void JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_DestroyDummy x11ErrorHandlerEnable(dpy, 0, env); } +/* + * Class: com_jogamp_nativewindow_impl_x11_X11Lib + * Method: GetRelativeLocation + * Signature: (JIJJII)Ljavax/media/nativewindow/util/Point; + */ +JNIEXPORT jobject JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_GetRelativeLocation0 + (JNIEnv *env, jclass unused, jlong jdisplay, jint screen_index, jlong jsrc_win, jlong jdest_win, jint src_x, jint src_y) +{ + Display * dpy = (Display *) (intptr_t) jdisplay; + Screen * scrn = ScreenOfDisplay(dpy, (int)screen_index); + Window root = XRootWindowOfScreen(scrn); + Window src_win = (Window)jsrc_win; + Window dest_win = (Window)jdest_win; + int dest_x=-1; + int dest_y=-1; + Window child; + Bool res; + + if( 0 == jdest_win ) { dest_win = root; } + if( 0 == jsrc_win ) { src_win = root; } + + x11ErrorHandlerEnable(dpy, 1, env); + + res = XTranslateCoordinates(dpy, src_win, dest_win, src_x, src_y, &dest_x, &dest_y, &child); + + x11ErrorHandlerEnable(dpy, 0, env); + + DBG_PRINT( "X11: GetRelativeLocation0: %p %d/%d -> %p %d/%d - ok: %d\n", + (void*)src_win, src_x, src_y, (void*)dest_win, dest_x, dest_y, (int)res); + + return (*env)->NewObject(env, pointClz, pointCstr, (jint)dest_x, (jint)dest_y); +} + diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java index daa09b034..2c3ffc3cc 100644 --- a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java +++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java @@ -34,6 +34,7 @@ package com.jogamp.newt.impl.windows; +import com.jogamp.nativewindow.impl.windows.GDI; import javax.media.nativewindow.*; import com.jogamp.newt.impl.WindowImpl; import javax.media.nativewindow.util.Insets; @@ -168,7 +169,7 @@ public class WindowsWindow extends WindowImpl { } protected Point getLocationOnScreenImpl(int x, int y) { - return (Point) getRelativeLocation0( getWindowHandle(), 0 /*root win*/, x, y); + return GDI.GetRelativeLocation( getWindowHandle(), 0 /*root win*/, x, y); } //---------------------------------------------------------------------- @@ -190,7 +191,6 @@ public class WindowsWindow extends WindowImpl { boolean parentChange, int fullScreenChange, int decorationChange); private static native void setTitle0(long windowHandle, String title); private native void requestFocus0(long windowHandle, boolean force); - private native Object getRelativeLocation0(long src_win, long dest_win, int src_x, int src_y); private void insetsChanged(int left, int top, int right, int bottom) { if (left != -1 && top != -1 && right != -1 && bottom != -1) { diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java index 06c7dfa99..91143923d 100644 --- a/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java +++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java @@ -33,6 +33,7 @@ package com.jogamp.newt.impl.x11; +import com.jogamp.nativewindow.impl.x11.X11Util; import com.jogamp.newt.impl.WindowImpl; import javax.media.nativewindow.*; import javax.media.nativewindow.x11.*; @@ -114,7 +115,7 @@ public class X11Window extends WindowImpl { } protected Point getLocationOnScreenImpl(int x, int y) { - return (Point) getRelativeLocation0( getDisplayHandle(), getScreenIndex(), getWindowHandle(), 0 /*root win*/, x, y); + return X11Util.GetRelativeLocation( getDisplayHandle(), getScreenIndex(), getWindowHandle(), 0 /*root win*/, x, y); } //---------------------------------------------------------------------- diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index 54fcfe85e..967836cf6 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -60,7 +60,7 @@ import javax.media.nativewindow.util.Insets; * via {@link #invoke(boolean, javax.media.opengl.GLRunnable)} to the OpenGL command stream.<br> * <p> */ -public class GLWindow implements GLAutoDrawable, Window { +public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { private WindowImpl window; /** @@ -687,6 +687,13 @@ public class GLWindow implements GLAutoDrawable, Window { } //---------------------------------------------------------------------- + // NEWTEventConsumer + // + public boolean consumeEvent(NEWTEvent event) { + return window.consumeEvent(event); + } + + //---------------------------------------------------------------------- // Window completion // public final void windowRepaint(int x, int y, int width, int height) { diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c index 46d710eda..b282ec9b2 100644 --- a/src/newt/native/WindowsWindow.c +++ b/src/newt/native/WindowsWindow.c @@ -118,13 +118,6 @@ #define STD_PRINT(...) fprintf(stderr, __VA_ARGS__); fflush(stderr) -static const char * const ClazzNamePoint = "javax/media/nativewindow/util/Point"; -static const char * const ClazzAnyCstrName = "<init>"; -static const char * const ClazzNamePointCstrSignature = "(II)V"; - -static jclass pointClz = NULL; -static jmethodID pointCstr = NULL; - static jmethodID insetsChangedID = NULL; static jmethodID sizeChangedID = NULL; static jmethodID positionChangedID = NULL; @@ -1333,23 +1326,6 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_initI { NewtCommon_init(env); - if(NULL==pointClz) { - jclass c = (*env)->FindClass(env, ClazzNamePoint); - if(NULL==c) { - NewtCommon_FatalError(env, "NEWT WindowsWindows: can't find %s", ClazzNamePoint); - } - pointClz = (jclass)(*env)->NewGlobalRef(env, c); - (*env)->DeleteLocalRef(env, c); - if(NULL==pointClz) { - NewtCommon_FatalError(env, "NEWT WindowsWindows: can't use %s", ClazzNamePoint); - } - pointCstr = (*env)->GetMethodID(env, pointClz, ClazzAnyCstrName, ClazzNamePointCstrSignature); - if(NULL==pointCstr) { - NewtCommon_FatalError(env, "NEWT WindowsWindows: can't fetch %s.%s %s", - ClazzNamePoint, ClazzAnyCstrName, ClazzNamePointCstrSignature); - } - } - insetsChangedID = (*env)->GetMethodID(env, clazz, "insetsChanged", "(IIII)V"); sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(IIZ)V"); positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(II)V"); @@ -1708,24 +1684,4 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_requestFo NewtWindows_requestFocus ( env, obj, (HWND) (intptr_t) window, force) ; } -/* - * Class: com_jogamp_newt_impl_windows_WindowsWindows - * Method: getRelativeLocation0 - * Signature: (JJII)Ljavax/media/nativewindow/util/Point; - */ -JNIEXPORT jobject JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_getRelativeLocation0 - (JNIEnv *env, jobject obj, jlong jsrc_win, jlong jdest_win, jint src_x, jint src_y) -{ - HWND src_win = (HWND) (intptr_t) jsrc_win; - HWND dest_win = (HWND) (intptr_t) jdest_win; - POINT dest = { src_x, src_y } ; - int res; - - res = MapWindowPoints(src_win, dest_win, &dest, 1); - - DBG_PRINT("*** WindowsWindow: getRelativeLocation0: %p %d/%d -> %p %d/%d - ok: %d\n", - (void*)src_win, src_x, src_y, (void*)dest_win, (int)dest.x, (int)dest.y, res); - - return (*env)->NewObject(env, pointClz, pointCstr, (jint)dest.x, (jint)dest.y); -} diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index becfa7596..7a19cf202 100644 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -140,15 +140,8 @@ static jint X11KeySym2NewtVKey(KeySym keySym) { static const char * const ClazzNameNewtWindow = "com/jogamp/newt/Window"; -static const char * const ClazzNamePoint = "javax/media/nativewindow/util/Point"; -static const char * const ClazzAnyCstrName = "<init>"; -static const char * const ClazzNamePointCstrSignature = "(II)V"; - static jclass newtWindowClz=NULL; -static jclass pointClz = NULL; -static jmethodID pointCstr = NULL; - static jmethodID sizeChangedID = NULL; static jmethodID positionChangedID = NULL; static jmethodID focusChangedID = NULL; @@ -233,22 +226,6 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_x11_X11Display_initIDs0 } } - if(NULL==pointClz) { - c = (*env)->FindClass(env, ClazzNamePoint); - if(NULL==c) { - NewtCommon_FatalError(env, "NEWT X11Windows: can't find %s", ClazzNamePoint); - } - pointClz = (jclass)(*env)->NewGlobalRef(env, c); - (*env)->DeleteLocalRef(env, c); - if(NULL==pointClz) { - NewtCommon_FatalError(env, "NEWT X11Windows: can't use %s", ClazzNamePoint); - } - pointCstr = (*env)->GetMethodID(env, pointClz, ClazzAnyCstrName, ClazzNamePointCstrSignature); - if(NULL==pointCstr) { - NewtCommon_FatalError(env, "NEWT X11Windows: can't fetch %s.%s %s", - ClazzNamePoint, ClazzAnyCstrName, ClazzNamePointCstrSignature); - } - } return JNI_TRUE; } @@ -1596,38 +1573,3 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_setTitle0 #endif } - - -/* - * Class: com_jogamp_newt_impl_x11_X11Window - * Method: getRelativeLocation0 - * Signature: (JIJJII)Ljavax/media/nativewindow/util/Point; - */ -JNIEXPORT jobject JNICALL Java_com_jogamp_newt_impl_x11_X11Window_getRelativeLocation0 - (JNIEnv *env, jobject obj, jlong jdisplay, jint screen_index, jlong jsrc_win, jlong jdest_win, jint src_x, jint src_y) -{ - Display * dpy = (Display *) (intptr_t) jdisplay; - Screen * scrn = ScreenOfDisplay(dpy, (int)screen_index); - Window root = XRootWindowOfScreen(scrn); - Window src_win = (Window)jsrc_win; - Window dest_win = (Window)jdest_win; - int dest_x=-1; - int dest_y=-1; - Window child; - Bool res; - - if( 0 == jdest_win ) { dest_win = root; } - if( 0 == jsrc_win ) { src_win = root; } - - displayDispatchErrorHandlerEnable(1, env); - - res = XTranslateCoordinates(dpy, src_win, dest_win, src_x, src_y, &dest_x, &dest_y, &child); - - displayDispatchErrorHandlerEnable(0, env); - - DBG_PRINT( "X11: getRelativeLocation0: %p %d/%d -> %p %d/%d - ok: %d\n", - (void*)src_win, src_x, src_y, (void*)dest_win, dest_x, dest_y, (int)res); - - return (*env)->NewObject(env, pointClz, pointCstr, (jint)dest_x, (jint)dest_y); -} - |