diff options
65 files changed, 1077 insertions, 703 deletions
diff --git a/etc/profile.jogl b/etc/profile.jogl index ecf4fe35d..dec12969c 100755 --- a/etc/profile.jogl +++ b/etc/profile.jogl @@ -148,22 +148,24 @@ if [ "$KERNEL" = "linux" ] ; then elif [ "$KERNEL" = "darwin" ] ; then SWT_SUB="cocoa" fi -SWT_CLASSPATH_0=$JOGL_BUILD_DIR/../make/lib/swt/$SWT_SUB-$KERNEL-$ARCH/swt-debug.jar -SWT_CLASSPATH_1=$HOME/.java/swt.jar -if [ ! -e "$SWT_CLASSPATH_0" ] ; then - echo Info: NO JOGL SWT $SWT_CLASSPATH_0 - if [ ! -e "$SWT_CLASSPATH_1" ] ; then - echo Info: NO Users SWT $SWT_CLASSPATH_1 +if [ -z "$SWT_CLASSPATH" ] ; then + SWT_CLASSPATH_0=$JOGL_BUILD_DIR/../make/lib/swt/$SWT_SUB-$KERNEL-$ARCH/swt-debug.jar + SWT_CLASSPATH_1=$HOME/.java/swt.jar + if [ ! -e "$SWT_CLASSPATH_0" ] ; then + echo Info: NO JOGL SWT $SWT_CLASSPATH_0 + if [ ! -e "$SWT_CLASSPATH_1" ] ; then + echo Info: NO Users SWT $SWT_CLASSPATH_1 + else + export SWT_CLASSPATH=$SWT_CLASSPATH_1 + echo Info: Using Users SWT $SWT_CLASSPATH + fi else - export SWT_CLASSPATH=$SWT_CLASSPATH_1 - echo Info: Using Users SWT $SWT_CLASSPATH + export SWT_CLASSPATH=$SWT_CLASSPATH_0 + echo Info: Using JOGL SWT $SWT_CLASSPATH + fi + if [ ! -z "$SWT_CLASSPATH" ] ; then + export SWT_CLASSPATH fi -else - export SWT_CLASSPATH=$SWT_CLASSPATH_0 - echo Info: Using JOGL SWT $SWT_CLASSPATH -fi -if [ ! -z "$SWT_CLASSPATH" ] ; then - export SWT_CLASSPATH fi if [ -z "$JOGL_CLASSPATH" ] ; then diff --git a/make/build-common.xml b/make/build-common.xml index 29faaef20..eb1162186 100644 --- a/make/build-common.xml +++ b/make/build-common.xml @@ -15,6 +15,8 @@ <!-- Pull in GlueGen cpptasks build file --> <property name="gluegen.root" value="../../gluegen" /> <import file="${gluegen.root}/make/gluegen-cpptasks.xml" /> + <import file="${gluegen.root}/make/jogamp-archivetasks.xml" /> + <import file="${gluegen.root}/make/jogamp-env.xml" /> <property name="ant-contrib.jar" value="${gluegen.root}/make/lib/ant-contrib-1.0b3.jar" /> @@ -30,7 +32,7 @@ <!-- - Base initialization of properties and detection of operating system. --> - <target name="common.init" depends="gluegen.cpptasks.detect.os" unless="common.init.done"> + <target name="common.init" depends="jogamp.env.init, gluegen.cpptasks.detect.os" unless="common.init.done"> <property name="common.init.done" value="true" /> <!-- Set the project root directory to be up one directory. --> @@ -205,24 +207,40 @@ <property name="jogl.all-noawt.jar" value="${build.jogl}/jogl.all-noawt.jar" /> <property name="newt.all-noawt.jar" value="${build.newt}/newt.all-noawt.jar" /> + <path id="swt_gluegen.classpath"> + <pathelement location="${gluegen-rt.jar}" /> + <pathelement location="${swt.jar}" /> + </path> + <path id="nativewindow_gluegen.classpath"> <pathelement location="${gluegen-rt.jar}" /> + <pathelement location="${swt.jar}" /> <pathelement location="${nativewindow.all.jar}" /> </path> <path id="nativewindow_gluegen_jogl.classpath"> <pathelement location="${gluegen-rt.jar}" /> + <pathelement location="${swt.jar}" /> <pathelement location="${nativewindow.all.jar}" /> <pathelement location="${jogl.all.jar}" /> </path> <path id="jogl_newt_all.classpath"> <pathelement location="${gluegen-rt.jar}" /> + <pathelement location="${swt.jar}" /> <pathelement location="${nativewindow.all.jar}" /> <pathelement location="${jogl.all.jar}" /> <pathelement location="${newt.all.jar}" /> </path> + <path id="jogl_newt_all-noawt.classpath"> + <pathelement location="${gluegen-rt.jar}" /> + <pathelement location="${swt.jar}" /> + <pathelement location="${nativewindow.all-noawt.jar}" /> + <pathelement location="${jogl.all-noawt.jar}" /> + <pathelement location="${newt.all-noawt.jar}" /> + </path> + <path id="junit_jogl_newt.compile.classpath"> <pathelement location="${junit.jar}" /> <pathelement location="${ant.jar}" /> @@ -251,11 +269,11 @@ <pathelement location="${ant.jar}" /> <pathelement location="${ant-junit.jar}" /> <pathelement location="${gluegen-rt.jar}" /> + <pathelement location="${swt.jar}" /> <pathelement location="${nativewindow.all.jar}" /> <pathelement location="${jogl.all.jar}" /> <pathelement location="${newt.event.jar}" /> <pathelement location="${jogl.test.jar}" /> - <pathelement location="${swt.jar}" /> </path> <path id="junit_jogl_newt.run.classpath"> @@ -285,13 +303,6 @@ value="${junit.jar}${path.separator}${ant.jar}${path.separator}${ant-junit.jar}${path.separator}${gluegen-rt.jar}${path.separator}${nativewindow.all.jar}${path.separator}${jogl.all.jar}${path.separator}${newt.all.jar}${path.separator}${jogl.test.jar}"/> - <path id="jogl_newt_all-noawt.classpath"> - <pathelement location="${gluegen-rt.jar}" /> - <pathelement location="${nativewindow.all-noawt.jar}" /> - <pathelement location="${jogl.all-noawt.jar}" /> - <pathelement location="${newt.all-noawt.jar}" /> - </path> - <!-- Atomic JavaSE JARS --> <property name="nativewindow.core.jar" value="${build.nativewindow}/nativewindow.core.jar" /> diff --git a/make/build-nativewindow.xml b/make/build-nativewindow.xml index 9c54021ef..475904b06 100644 --- a/make/build-nativewindow.xml +++ b/make/build-nativewindow.xml @@ -77,11 +77,14 @@ <!-- partitioning --> + <property name="java.part.swt" + value="jogamp/nativewindow/swt/**"/> + <property name="java.part.core" - value="javax/media/nativewindow/*, javax/media/nativewindow/util/*, javax/media/nativewindow/egl/*, javax/media/nativewindow/macosx/*, javax/media/nativewindow/windows/*, com/jogamp/nativewindow/*, jogamp/nativewindow/*, jogamp/nativewindow/jvm/*"/> + value="javax/media/nativewindow/* javax/media/nativewindow/util/* javax/media/nativewindow/egl/* javax/media/nativewindow/macosx/* javax/media/nativewindow/windows/* com/jogamp/nativewindow/* jogamp/nativewindow/* jogamp/nativewindow/jvm/* ${java.part.swt}"/> <property name="java.part.awt" - value="javax/media/nativewindow/awt/*, jogamp/nativewindow/jawt/**, jogamp/nativewindow/**/awt/**"/> + value="javax/media/nativewindow/awt/* jogamp/nativewindow/jawt/** jogamp/nativewindow/**/awt/**"/> <property name="java.part.x11" value="jogamp/nativewindow/x11/** javax/media/nativewindow/x11/*" /> @@ -310,11 +313,11 @@ <javac destdir="${classes}" excludes="${java.excludes.all}" source="${target.sourcelevel}" - classpath="${gluegen-rt.jar}" fork="yes" includeAntRuntime="false" memoryMaximumSize="${javac.memorymax}" debug="${javacdebug}" debuglevel="${javacdebuglevel}"> + <classpath refid="swt_gluegen.classpath"/> <src path="${src.java}" /> <src path="${src.generated.java}" /> </javac> diff --git a/make/build-test.xml b/make/build-test.xml index 2d1813668..ac60d09eb 100644 --- a/make/build-test.xml +++ b/make/build-test.xml @@ -26,7 +26,7 @@ <property name="java.dir.junit" value="${java.dir.test}/junit"/> <property name="java.dir.bugs" value="${java.dir.test}/bugs"/> - <property name="test.archive.name" value="${archive.name}-test-results"/> + <property name="test.archive.name" value="${archive.name}-test-results-${build.node.name}"/> <condition property="jvmarg.newt.headless" value="-XstartOnFirstThread -Djava.awt.headless=true"><isset property="isOSX"/></condition> <condition property="jvmarg.newt.headless" value="-Djava.awt.headless=true"><not><isset property="isOSX"/></not></condition> @@ -55,7 +55,7 @@ <!-- Clean the results --> <delete quiet="true"> <fileset dir="${results.test}" includes="**"/> - <fileset file="${build}/${test.archive.name}.zip"/> + <fileset file="${build}/${test.archive.name}.7z"/> </delete> <mkdir dir="${results.test}" /> @@ -382,9 +382,9 @@ <!-- updates / create the test results zip file --> <target name="test-zip-archive" depends="declare.common"> - <zip destfile="${build}/${test.archive.name}.zip" update="true"> - <zipfileset dir="${results.test}" prefix="${archive.name}/test-results"/> - </zip> + <archive.7z destfile="${build}/${test.archive.name}.7z" + basedir="${results.test}" + includes="**" /> </target> <!-- ================================================================== --> diff --git a/make/build.xml b/make/build.xml index 40b001afd..c9dfca0b4 100644 --- a/make/build.xml +++ b/make/build.xml @@ -39,8 +39,9 @@ <target name="javadoc.spec" description="Build Specifications JOGL and Nativewindow" depends="javadoc.init, javadoc.nw.spec, javadoc.jogl.spec" /> + <!-- excluded javadoc.dev due to time consumption --> <target name="javadoc.all" description="Build all NativeWindow, JOGL and NEWT docs" - depends="javadoc.init, javadoc.nw.spec, javadoc.jogl.spec, javadoc.public, javadoc.dev"/> + depends="javadoc.init, javadoc.nw.spec, javadoc.jogl.spec, javadoc.public"/> <target name="clean" depends="init"> <ant antfile="${nativewindow.build.xml}" dir="${nativewindow.make}" target="clean" inheritRefs="true" inheritAll="true"/> @@ -117,7 +118,7 @@ - This must be called after all of the build targets complete. --> - <target name="developer-zip-archive" depends="init" unless="build.noarchives"> + <target name="developer-zip-archive" depends="init" if="build.archiveon"> <delete includeEmptyDirs="true" quiet="true" dir="${archive}" failonerror="false" /> <mkdir dir="${archive}" /> <copy file="${build}/artifact.properties" todir="${archive}" /> @@ -150,8 +151,7 @@ <copy todir="${archive}/etc"> <fileset dir="${project.root}/etc" includes="*" /> </copy> - <delete quiet="true" file="${build}/${archive.name}.zip"/> - <zip destfile="${build}/${archive.name}.zip" + <archive.7z destfile="${build}/${archive.name}.7z" basedir="${build}" includes="${archive.name}/**" /> <!-- Clean up after ourselves --> @@ -235,7 +235,7 @@ <property name="javadoc.windowtitle" value="JOGL, NativeWindow and NEWT APIs" /> <property name="javadoc.packagenames" value="${javadoc.nw.spec.packagenames}, ${javadoc.spec.packagenames}, com.jogamp.opengl, com.jogamp.opengl.util.*, com.jogamp.nativewindow, com.jogamp.newt, com.jogamp.newt.util.*, com.jogamp.newt.event.*, com.jogamp.newt.opengl" /> - <property name="javadoc.dev.packagenames" value="${javadoc.packagenames}, com.jogamp.opengl.*, com.jogamp.nativewindow.*, com.jogamp.newt.*, com.jogamp.gluegen.opengl.*, com.jogamp.gluegen.runtime.opengl.*" /> + <property name="javadoc.dev.packagenames" value="${javadoc.packagenames}, com.jogamp.opengl.*, com.jogamp.nativewindow.*, com.jogamp.newt.*, com.jogamp.gluegen.opengl.*, com.jogamp.gluegen.runtime.opengl.*, jogamp.nativewindow.*, jogamp.opengl.*, jogamp.newt.*" /> <property name="java.excludes.javadoc.packagenames" value="jogamp.opengl.gl2.fixme.*,com.jogamp.audio.windows.waveout.TestSpatialization"/> <property name="javadoc.bottom" value="Copyright 2010 JogAmp Community." /> @@ -327,7 +327,7 @@ </target> <target name="javadoc.zip" depends="javadoc.init"> - <zip destfile="${build}/javadoc.zip" + <archive.7z destfile="${build}/javadoc.7z" basedir="${javadoc.root.path}" includes="jogl/**" /> </target> diff --git a/make/scripts/cmpOld2New.sh b/make/scripts/cmpOld2New.sh index 4394fe7b5..4394fe7b5 100644..100755 --- a/make/scripts/cmpOld2New.sh +++ b/make/scripts/cmpOld2New.sh diff --git a/make/scripts/count-lock.sh b/make/scripts/count-lock.sh index 806235f5c..806235f5c 100644..100755 --- a/make/scripts/count-lock.sh +++ b/make/scripts/count-lock.sh diff --git a/make/scripts/cpp-gluegen-test.sh b/make/scripts/cpp-gluegen-test.sh index 2baa57729..2baa57729 100644..100755 --- a/make/scripts/cpp-gluegen-test.sh +++ b/make/scripts/cpp-gluegen-test.sh diff --git a/make/scripts/java-win32-dbg.bat b/make/scripts/java-win32-dbg.bat index ef117db82..2b15410ff 100755 --- a/make/scripts/java-win32-dbg.bat +++ b/make/scripts/java-win32-dbg.bat @@ -1,7 +1,7 @@ set BLD_SUB=build-win32
-set J2RE_HOME=c:\jre1.6.0_23_x32
-set JAVA_HOME=c:\jdk1.6.0_23_x32
+set J2RE_HOME=c:\jre1.6.0_24_x32
+set JAVA_HOME=c:\jdk1.6.0_24_x32
set ANT_PATH=C:\apache-ant-1.8.2
set PATH=%JAVA_HOME%\bin;%ANT_PATH%\bin;c:\mingw\bin;%PATH%
diff --git a/make/scripts/java-win32.bat b/make/scripts/java-win32.bat index a7697d75c..368501cb4 100755 --- a/make/scripts/java-win32.bat +++ b/make/scripts/java-win32.bat @@ -1,7 +1,7 @@ set BLD_SUB=build-win32
-set J2RE_HOME=c:\jre1.6.0_23_x32
-set JAVA_HOME=c:\jdk1.6.0_23_x32
+set J2RE_HOME=c:\jre1.6.0_24_x32
+set JAVA_HOME=c:\jdk1.6.0_24_x32
set ANT_PATH=C:\apache-ant-1.8.2
set PATH=%JAVA_HOME%\bin;%ANT_PATH%\bin;c:\mingw\bin;%PATH%
diff --git a/make/scripts/java-win64-dbg.bat b/make/scripts/java-win64-dbg.bat index 3aeee346e..34a2fdc4c 100755 --- a/make/scripts/java-win64-dbg.bat +++ b/make/scripts/java-win64-dbg.bat @@ -1,7 +1,7 @@ set BLD_SUB=build-win64
-set J2RE_HOME=c:\jre1.6.0_23_x64
-set JAVA_HOME=c:\jdk1.6.0_23_x64
+set J2RE_HOME=c:\jre1.6.0_24_x64
+set JAVA_HOME=c:\jdk1.6.0_24_x64
set ANT_PATH=C:\apache-ant-1.8.2
set PATH=%JAVA_HOME%\bin;%ANT_PATH%\bin;c:\mingw\bin;%PATH%
diff --git a/make/scripts/java-win64.bat b/make/scripts/java-win64.bat index e931bb38e..320db5725 100755 --- a/make/scripts/java-win64.bat +++ b/make/scripts/java-win64.bat @@ -1,7 +1,7 @@ set BLD_SUB=build-win64
-set J2RE_HOME=c:\jre1.6.0_23_x64
-set JAVA_HOME=c:\jdk1.6.0_23_x64
+set J2RE_HOME=c:\jre1.6.0_24_x64
+set JAVA_HOME=c:\jdk1.6.0_24_x64
set ANT_PATH=C:\apache-ant-1.8.2
set PATH=%JAVA_HOME%\bin;%ANT_PATH%\bin;c:\mingw\bin;%PATH%
diff --git a/make/scripts/make-runtime-properties.sh b/make/scripts/make-runtime-properties.sh index a6075dd85..a6075dd85 100644..100755 --- a/make/scripts/make-runtime-properties.sh +++ b/make/scripts/make-runtime-properties.sh diff --git a/make/scripts/make.jogl.all.linux-x86.sh b/make/scripts/make.jogl.all.linux-x86.sh index 76b46a03b..03dedb99c 100755 --- a/make/scripts/make.jogl.all.linux-x86.sh +++ b/make/scripts/make.jogl.all.linux-x86.sh @@ -31,7 +31,6 @@ fi # -Djogl.cg=1 # -Dc.compiler.debug=true # -DuseOpenMAX=true \ -# -Dbuild.noarchives=true # -Dgluegen.cpptasks.detected.os=true \ # -DisUnix=true \ # -DisLinux=true \ @@ -53,9 +52,7 @@ echo LIBGL_DEBUG: $LIBGL_DEBUG 2>&1 | tee -a $LOGF ant \ $CUSTOMLIBDIR \ - -Dbuild.noarchives=true \ -Dgluegen-cpptasks.file=`pwd`/../../gluegen/make/lib/gluegen-cpptasks-linux-32bit.xml \ - -Dbuild.noarchives=true \ -Djogl.cg=1 \ -Drootrel.build=build-x86 \ -Dos.arch=x86 \ diff --git a/make/scripts/make.jogl.all.linux-x86_64.sh b/make/scripts/make.jogl.all.linux-x86_64.sh index 2b63ef0ab..577caeb14 100755 --- a/make/scripts/make.jogl.all.linux-x86_64.sh +++ b/make/scripts/make.jogl.all.linux-x86_64.sh @@ -29,14 +29,12 @@ fi # -Djogl.cg=1 # -Dc.compiler.debug=true \ -# -Dbuild.noarchives=true \ # -Dgluegen.cpptasks.detected.os=true \ # -DisUnix=true \ # -DisLinux=true \ # -DisLinuxAMD64=true \ # -DisX11=true \ -# -Dbuild.noarchives=true \ #LD_LIBRARY_PATH=/opt-linux-x86_64/mesa-7.8.1/lib64 #export LD_LIBRARY_PATH @@ -50,7 +48,6 @@ echo LIBXCB_ALLOW_SLOPPY_LOCK: $LIBXCB_ALLOW_SLOPPY_LOCK 2>&1 | tee -a $LOGF echo LIBGL_DRIVERS_PATH: $LIBGL_DRIVERS_PATH 2>&1 | tee -a $LOGF echo LIBGL_DEBUG: $LIBGL_DEBUG 2>&1 | tee -a $LOGF -# -Dbuild.noarchives=true \ # -Dc.compiler.debug=true \ # -Djavacdebug="true" \ # -Djavacdebuglevel="source,lines,vars" \ @@ -58,7 +55,6 @@ echo LIBGL_DEBUG: $LIBGL_DEBUG 2>&1 | tee -a $LOGF ant \ $CUSTOMLIBDIR \ -Djavacdebuglevel="source,lines,vars" \ - -Dbuild.noarchives=true \ -Djogl.cg=1 \ -Drootrel.build=build-x86_64 \ -DuseKD=true \ diff --git a/make/scripts/make.jogl.all.macosx.sh b/make/scripts/make.jogl.all.macosx.sh index a85f9344f..967790b6e 100755 --- a/make/scripts/make.jogl.all.macosx.sh +++ b/make/scripts/make.jogl.all.macosx.sh @@ -1,15 +1,13 @@ #! /bin/sh -if [ -e /devtools/etc/profile.ant ] ; then - . /devtools/etc/profile.ant +if [ -e /opt-share/etc/profile.ant ] ; then + . /opt-share/etc/profile.ant fi # -Dc.compiler.debug=true -# -Dbuild.noarchives=true ant \ - -Dbuild.noarchives=true \ -Djogl.cg=1 \ -Drootrel.build=build-macosx \ $* 2>&1 | tee make.jogl.all.macosx.log diff --git a/make/scripts/make.jogl.all.win32.bat b/make/scripts/make.jogl.all.win32.bat index 6b66ff1c8..f73a332d3 100755 --- a/make/scripts/make.jogl.all.win32.bat +++ b/make/scripts/make.jogl.all.win32.bat @@ -1,7 +1,7 @@ set THISDIR="C:\JOGL"
-set J2RE_HOME=c:\jre1.6.0_23_x32
-set JAVA_HOME=c:\jdk1.6.0_23_x32
+set J2RE_HOME=c:\jre1.6.0_24_x32
+set JAVA_HOME=c:\jdk1.6.0_24_x32
set ANT_PATH=C:\apache-ant-1.8.2
set PATH=%JAVA_HOME%\bin;%ANT_PATH%\bin;c:\mingw\bin;%PATH%
@@ -12,6 +12,5 @@ REM -Dc.compiler.debug=true REM -DuseOpenMAX=true
REM -DuseKD=true
REM -Djogl.cg=1
-REM -Dbuild.noarchives=true
-ant -Dbuild.noarchives=true -Drootrel.build=build-win32 -Djogl.cg=1 %1 %2 %3 %4 %5 %6 %7 %8 %9 > make.jogl.all.win32.log 2>&1
+ant -Drootrel.build=build-win32 -Djogl.cg=1 %1 %2 %3 %4 %5 %6 %7 %8 %9 > make.jogl.all.win32.log 2>&1
diff --git a/make/scripts/make.jogl.all.win64.bat b/make/scripts/make.jogl.all.win64.bat index 8dbcd01e7..76e459ae7 100755 --- a/make/scripts/make.jogl.all.win64.bat +++ b/make/scripts/make.jogl.all.win64.bat @@ -1,7 +1,7 @@ set THISDIR="C:\JOGL"
-set J2RE_HOME=c:\jre1.6.0_23_x64
-set JAVA_HOME=c:\jdk1.6.0_23_x64
+set J2RE_HOME=c:\jre1.6.0_24_x64
+set JAVA_HOME=c:\jdk1.6.0_24_x64
set ANT_PATH=C:\apache-ant-1.8.2
set PATH=%JAVA_HOME%\bin;%ANT_PATH%\bin;c:\mingw64\bin;c:\mingw\bin;%PATH%
@@ -12,6 +12,5 @@ REM -Dc.compiler.debug=true REM -DuseOpenMAX=true
REM -DuseKD=true
REM -Djogl.cg=1
-REM -Dbuild.noarchives=true
-ant -Dc.compiler.debug=true -Dbuild.noarchives=true -Drootrel.build=build-win64 -Djogl.cg=1 %1 %2 %3 %4 %5 %6 %7 %8 %9 > make.jogl.all.win64.log 2>&1
+ant -Dc.compiler.debug=true -Drootrel.build=build-win64 -Djogl.cg=1 %1 %2 %3 %4 %5 %6 %7 %8 %9 > make.jogl.all.win64.log 2>&1
diff --git a/make/scripts/make.jogl.cdcfp.linux-x86.sh b/make/scripts/make.jogl.cdcfp.linux-x86.sh index ad80f194d..b26926804 100755 --- a/make/scripts/make.jogl.cdcfp.linux-x86.sh +++ b/make/scripts/make.jogl.cdcfp.linux-x86.sh @@ -10,13 +10,11 @@ fi # -Djavacdebuglevel="none" \ # # -Djava.generate.skip=true \ -# -Dbuild.noarchives=true BUILD_SUBDIR=build-cdcfp-x86 ant -v \ -Dgluegen-cpptasks.file=`pwd`/../../gluegen/make/lib/gluegen-cpptasks-linux-32bit.xml \ - -Dbuild.noarchives=true \ -Drootrel.build=$BUILD_SUBDIR \ -Dsetup.cdcfp=true \ -Dgluegen.cpptasks.detected.os=true \ diff --git a/make/scripts/make.jogl.cdcfp.macosx.sh b/make/scripts/make.jogl.cdcfp.macosx.sh index d36f0bb7e..6875a4d2c 100755 --- a/make/scripts/make.jogl.cdcfp.macosx.sh +++ b/make/scripts/make.jogl.cdcfp.macosx.sh @@ -1,17 +1,15 @@ #! /bin/sh -if [ -e /devtools/etc/profile.ant ] ; then - . /devtools/etc/profile.ant +if [ -e /opt-share/etc/profile.ant ] ; then + . /opt-share/etc/profile.ant fi # -Dc.compiler.debug=true -# -Dbuild.noarchives=true BUILD_SUBDIR=build-cdcfp-macosx ant \ - -Dbuild.noarchives=true \ -Dsetup.cdcfp=true \ -Drootrel.build=$BUILD_SUBDIR \ $* 2>&1 | tee make.jogl.cdcfp.macosx.log diff --git a/make/scripts/make.jogl.doc.all.x86_64.sh b/make/scripts/make.jogl.doc.all.x86_64.sh index 3711171af..5e111d50b 100755 --- a/make/scripts/make.jogl.doc.all.x86_64.sh +++ b/make/scripts/make.jogl.doc.all.x86_64.sh @@ -6,6 +6,5 @@ fi ant -v \ - -Dbuild.noarchives=true \ -Drootrel.build=build-x86_64 \ javadoc.spec javadoc javadoc.dev $* 2>&1 | tee make.jogl.doc.all.x86_64.log diff --git a/make/scripts/make.jogl.doc.x86_64.sh b/make/scripts/make.jogl.doc.x86_64.sh index daf09ec33..677de394c 100755 --- a/make/scripts/make.jogl.doc.x86_64.sh +++ b/make/scripts/make.jogl.doc.x86_64.sh @@ -6,6 +6,5 @@ fi ant -v \ - -Dbuild.noarchives=true \ -Drootrel.build=build-x86_64 \ javadoc $* 2>&1 | tee make.jogl.doc.x86_64.log diff --git a/make/scripts/setenv-jogl.sh b/make/scripts/setenv-jogl.sh index 964bbc5f8..586b667e3 100755 --- a/make/scripts/setenv-jogl.sh +++ b/make/scripts/setenv-jogl.sh @@ -10,8 +10,8 @@ if [ -z "$1" ] ; then exit fi -if [ -e /devtools/etc/profile.ant ] ; then - . /devtools/etc/profile.ant +if [ -e /opt-share/etc/profile.ant ] ; then + . /opt-share/etc/profile.ant fi JOGL_BUILDDIR=$1 diff --git a/make/scripts/setvc9-jogl.bat b/make/scripts/setvc9-jogl.bat index 6ff16053e..26cdf8ff4 100755 --- a/make/scripts/setvc9-jogl.bat +++ b/make/scripts/setvc9-jogl.bat @@ -1,7 +1,7 @@ -set PATH=C:\cygwin\devtools\share\apache-ant-1.8.2\bin;%PATH%
-set ANT_PATH=C:\cygwin\devtools\share\apache-ant-1.8.2
+set PATH=C:\apache-ant-1.8.2\bin;%PATH%
+set ANT_PATH=C:\apache-ant-1.8.2
c:
cd C:\SUN\JOGL2\jogl\make
diff --git a/make/scripts/tests-javaws-x64.bat b/make/scripts/tests-javaws-x64.bat index 0bc8272fe..c25ccf335 100644..100755 --- a/make/scripts/tests-javaws-x64.bat +++ b/make/scripts/tests-javaws-x64.bat @@ -1,4 +1,4 @@ -set JRE_PATH=C:\jre1.6.0_23_x64\bin +set JRE_PATH=C:\jre1.6.0_24_x64\bin set LOG_PATH=%USERPROFILE%\AppData\LocalLow\Sun\Java\Deployment\log %JRE_PATH%\javaws -uninstall diff --git a/make/scripts/tests-javaws.sh b/make/scripts/tests-javaws.sh index a1b1b1e2e..a1b1b1e2e 100644..100755 --- a/make/scripts/tests-javaws.sh +++ b/make/scripts/tests-javaws.sh diff --git a/make/scripts/tests-x32.bat b/make/scripts/tests-x32.bat index 9b44dc178..84d7f2d9b 100644..100755 --- a/make/scripts/tests-x32.bat +++ b/make/scripts/tests-x32.bat @@ -33,5 +33,5 @@ REM scripts\java-win32.bat com.jogamp.opengl.test.junit.newt.TestCloseNewtAWT REM scripts\java-win32-dbg.bat com.jogamp.opengl.test.junit.jogl.caps.TestMultisampleAWT -time 10000 REM scripts\java-win32-dbg.bat com.jogamp.opengl.test.junit.jogl.caps.TestMultisampleNEWT -time 10000 -scripts\java-win32-dbg.bat com.jogamp.opengl.test.junit.jogl.swt.TestSWT01GLn $* +scripts\java-win32-dbg.bat com.jogamp.opengl.test.junit.jogl.swt.TestSWT01GLn %1 %2 %3 %4 REM scripts\java-win32-dbg.bat com.jogamp.opengl.test.junit.jogl.swt.TestSWTAWT01GLn $* diff --git a/make/scripts/tests-x64.bat b/make/scripts/tests-x64.bat index 246826fd6..43cc8ccbb 100644..100755 --- a/make/scripts/tests-x64.bat +++ b/make/scripts/tests-x64.bat @@ -47,7 +47,7 @@ REM scripts\java-win64.bat com.jogamp.opengl.test.junit.newt.TestWindowClosingPr REM scripts\java-win64.bat com.jogamp.opengl.test.junit.newt.TestWindowClosingProtocol02NEWT $* REM scripts\java-win64.bat com.jogamp.opengl.test.junit.newt.TestWindowClosingProtocol03NewtAWT $* -scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.swt.TestSWT01GLn $* +scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.swt.TestSWT01GLn %1 %2 %3 %4 REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.swt.TestSWTAWT01GLn $* REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.offscreen.TestOffscreen02BitmapNEWT -time 5000 diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index 9a5e6fb20..682158eea 100644..100755 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -1,6 +1,23 @@ #! /bin/bash -bdir=../build-x86_64 +if [ -z "$1" -o -z "$2" ] ; then + echo Usage $0 java-exe build-dir + exit 0 +fi + +javaexe=$1 +shift +bdir=$1 +shift + +if [ ! -x $javaexe ] ; then + echo java-exe $javaexe is not an executable + exit 1 +fi +if [ ! -d $bdir ] ; then + echo build-dir $bdir is not a directory + exit 1 +fi rm -f java-run.log @@ -8,13 +25,14 @@ spath=`dirname $0` . $spath/setenv-jogl.sh $bdir JOGL_ALL -which java 2>&1 | tee -a java-run.log -java -version 2>&1 | tee -a java-run.log +which $javaexe 2>&1 | tee -a java-run.log +$javaexe -version 2>&1 | tee -a java-run.log echo LIBXCB_ALLOW_SLOPPY_LOCK: $LIBXCB_ALLOW_SLOPPY_LOCK 2>&1 | tee -a java-run.log echo LIBGL_DRIVERS_PATH: $LIBGL_DRIVERS_PATH 2>&1 | tee -a java-run.log echo LIBGL_DEBUG: $LIBGL_DEBUG 2>&1 | tee -a java-run.log echo SWT_CLASSPATH: $SWT_CLASSPATH 2>&1 | tee -a java-run.log -echo java $X_ARGS $D_ARGS $* 2>&1 | tee -a java-run.log +echo $javaexe $X_ARGS $D_ARGS $* 2>&1 | tee -a java-run.log +echo CLASSPATH $CLASSPATH 2>&1 | tee -a java-run.log function jrun() { awtarg=$1 @@ -50,7 +68,7 @@ function jrun() { echo echo "Test Start: $*" echo - java $awtarg $X_ARGS $D_ARGS $* + $javaexe $awtarg $X_ARGS $D_ARGS $* echo echo "Test End: $*" echo @@ -108,15 +126,15 @@ function testawt() { #testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.TestGearsGLJPanelAWT $* #testawt com.jogamp.opengl.test.junit.jogl.texture.TestTexture01AWT #testawt com.jogamp.opengl.test.junit.jogl.caps.TestMultisampleAWT -#testawt com.jogamp.opengl.test.junit.jogl.swt.TestSWT01GLn +#testawt com.jogamp.opengl.test.junit.jogl.swt.TestSWT01GLn $* #testawt com.jogamp.opengl.test.junit.jogl.awt.TestBug461OffscreenSupersamplingSwingAWT -testawt com.jogamp.opengl.test.junit.jogl.texture.TestGrayTextureFromFileAWTBug417 +#testawt com.jogamp.opengl.test.junit.jogl.texture.TestGrayTextureFromFileAWTBug417 # # newt.awt (testawt) # #testawt com.jogamp.opengl.test.junit.jogl.newt.TestSwingAWTRobotUsageBeforeJOGLInitBug411 -#testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.newt.TestGearsNewtAWTWrapper +testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.newt.TestGearsNewtAWTWrapper #testawt com.jogamp.opengl.test.junit.newt.TestEventSourceNotAWTBug #testawt com.jogamp.opengl.test.junit.newt.TestFocus01SwingAWTRobot #testawt com.jogamp.opengl.test.junit.newt.TestFocus02SwingAWTRobot diff --git a/make/stub_includes/win32/windows.h b/make/stub_includes/win32/windows.h index ddee94c06..c30f99ebd 100644 --- a/make/stub_includes/win32/windows.h +++ b/make/stub_includes/win32/windows.h @@ -52,3 +52,6 @@ typedef struct tagRECT { LONG bottom; } RECT; +typedef RECT* PRECT; +typedef RECT* LPRECT; + diff --git a/make/stub_includes/win32/wingdi.h b/make/stub_includes/win32/wingdi.h index b169621f5..23ac428ca 100644 --- a/make/stub_includes/win32/wingdi.h +++ b/make/stub_includes/win32/wingdi.h @@ -191,6 +191,8 @@ WINGDIAPI HGDIOBJ WINAPI SelectObject(HDC, HGDIOBJ); WINUSERAPI BOOL WINAPI ShowWindow(HWND hWnd, int nCmdShow); WINUSERAPI HDC WINAPI GetDC(HWND); WINUSERAPI int WINAPI ReleaseDC(HWND hWnd, HDC hDC); +WINUSERAPI HWND WINAPI WindowFromDC(HDC hDC); // avail in >= Win2k +WINUSERAPI BOOL WINAPI GetClientRect(HWND hwnd, LPRECT lpRect); WINUSERAPI BOOL WINAPI DestroyWindow(HWND hWnd); WINUSERAPI DWORD WINAPI GetObjectType(HGDIOBJ h); diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java index b6f5dabd3..f81e5a70e 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java @@ -43,7 +43,7 @@ import javax.media.opengl.*; import com.jogamp.common.JogampRuntimeException; import com.jogamp.common.util.*; import jogamp.opengl.*; -import jogamp.nativewindow.ProxySurface; +import jogamp.nativewindow.WrappedSurface; import java.util.HashMap; import java.util.List; @@ -220,7 +220,7 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { } protected NativeSurface createOffscreenSurfaceImpl(AbstractGraphicsDevice device, GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, int width, int height) { - ProxySurface ns = new ProxySurface(EGLGraphicsConfigurationFactory.createOffscreenGraphicsConfiguration(device, capsChosen, capsRequested, chooser)); + WrappedSurface ns = new WrappedSurface(EGLGraphicsConfigurationFactory.createOffscreenGraphicsConfiguration(device, capsChosen, capsRequested, chooser)); ns.setSize(width, height); return ns; } diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java b/src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java index 78c23f710..dd06dc148 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java @@ -40,7 +40,6 @@ import jogamp.opengl.*; import javax.media.nativewindow.*; public class EGLExternalContext extends EGLContext { - private boolean firstMakeCurrent = true; private GLContext lastContext; public EGLExternalContext(AbstractGraphicsScreen screen) { @@ -68,9 +67,6 @@ public class EGLExternalContext extends EGLContext { } protected void makeCurrentImpl(boolean newCreated) throws GLException { - if (firstMakeCurrent) { - firstMakeCurrent = false; - } } protected void releaseImpl() throws GLException { diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java index 19f3ce640..8e27c217b 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java @@ -51,7 +51,7 @@ import javax.media.opengl.*; import com.jogamp.common.JogampRuntimeException; import com.jogamp.common.util.*; import jogamp.opengl.*; -import jogamp.nativewindow.ProxySurface; +import jogamp.nativewindow.WrappedSurface; public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { private static final DesktopGLDynamicLookupHelper macOSXCGLDynamicLookupHelper; @@ -167,7 +167,7 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { protected NativeSurface createOffscreenSurfaceImpl(AbstractGraphicsDevice device,GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, int width, int height) { AbstractGraphicsScreen screen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_MACOSX); - ProxySurface ns = new ProxySurface(MacOSXCGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capsChosen, capsRequested, chooser, screen, true)); + WrappedSurface ns = new WrappedSurface(MacOSXCGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capsChosen, capsRequested, chooser, screen, true)); ns.setSize(width, height); return ns; } diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXExternalCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXExternalCGLContext.java index e0ee8ea73..af055913d 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXExternalCGLContext.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXExternalCGLContext.java @@ -44,10 +44,9 @@ import javax.media.opengl.*; import jogamp.opengl.*; import javax.media.nativewindow.*; -import jogamp.nativewindow.ProxySurface; +import jogamp.nativewindow.WrappedSurface; public class MacOSXExternalCGLContext extends MacOSXCGLContext { - private boolean firstMakeCurrent = true; private GLContext lastContext; private MacOSXExternalCGLContext(Drawable drawable, boolean isNSContext, long handle) { @@ -100,7 +99,7 @@ public class MacOSXExternalCGLContext extends MacOSXCGLContext { AbstractGraphicsScreen aScreen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_MACOSX); MacOSXCGLGraphicsConfiguration cfg = new MacOSXCGLGraphicsConfiguration(aScreen, caps, caps, pixelFormat); - ProxySurface ns = new ProxySurface(cfg); + WrappedSurface ns = new WrappedSurface(cfg); ns.setSurfaceHandle(currentDrawable); return new MacOSXExternalCGLContext(new Drawable(factory, ns), isNSContext, contextHandle); } @@ -127,9 +126,6 @@ public class MacOSXExternalCGLContext extends MacOSXCGLContext { } protected void makeCurrentImpl(boolean newCreated) throws GLException { - if (firstMakeCurrent) { - firstMakeCurrent = false; - } } protected void releaseImpl() throws GLException { diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsDummyWGLDrawable.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsDummyWGLDrawable.java index 27d7b342e..3d0cce725 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsDummyWGLDrawable.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsDummyWGLDrawable.java @@ -45,29 +45,21 @@ import javax.media.opengl.GLDrawableFactory; import javax.media.opengl.GLProfile; import javax.media.nativewindow.AbstractGraphicsScreen; -import jogamp.nativewindow.ProxySurface; import jogamp.nativewindow.windows.GDI; -import javax.media.nativewindow.AbstractGraphicsDevice; import javax.media.nativewindow.NativeSurface; import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLCapabilitiesImmutable; import javax.media.opengl.GLException; +import jogamp.nativewindow.windows.GDISurface; public class WindowsDummyWGLDrawable extends WindowsWGLDrawable { - private static final int f_dim = 64; - private long hwnd, hdc; + private long hwnd; + private boolean handleHwndLifecycle; - protected WindowsDummyWGLDrawable(GLDrawableFactory factory, GLCapabilitiesImmutable caps, AbstractGraphicsScreen absScreen) { - super(factory, new ProxySurface(WindowsWGLGraphicsConfigurationFactory.createDefaultGraphicsConfiguration(caps, absScreen)), true); - hwnd = GDI.CreateDummyWindow(0, 0, f_dim, f_dim); - if(0 == hwnd) { - throw new GLException("Error hwnd 0, werr: "+GDI.GetLastError()); - } - // manual debug only - GDI.ShowWindow(hwnd, GDI.SW_SHOW); - ProxySurface ns = (ProxySurface) getNativeSurface(); - ns.setSize(f_dim, f_dim); + private WindowsDummyWGLDrawable(GLDrawableFactory factory, GDISurface ns, boolean handleHwndLifecycle) { + super(factory, ns, true); + this.handleHwndLifecycle = handleHwndLifecycle; - if(NativeSurface.LOCK_SURFACE_NOT_READY >= lockSurface()) { + if(NativeSurface.LOCK_SURFACE_NOT_READY >= ns.lockSurface()) { throw new GLException("WindowsDummyWGLDrawable: surface not ready (lockSurface)"); } try { @@ -84,70 +76,16 @@ public class WindowsDummyWGLDrawable extends WindowsWGLDrawable { } } - public static WindowsDummyWGLDrawable create(GLDrawableFactory factory, GLProfile glp, AbstractGraphicsScreen absScreen) { - GLCapabilities caps = new GLCapabilities(glp); - caps.setDepthBits(16); - caps.setDoubleBuffered(true); - caps.setOnscreen (true); - return new WindowsDummyWGLDrawable(factory, caps, absScreen); - } - - public int lockSurface() throws GLException { - int res = NativeSurface.LOCK_SURFACE_NOT_READY; - ProxySurface ns = (ProxySurface) getNativeSurface(); - AbstractGraphicsDevice adevice = ns.getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice(); - adevice.lock(); - try { - res = ns.lockSurface(); - if(NativeSurface.LOCK_SUCCESS == res) { - if(0 == hdc) { - hdc = GDI.GetDC(hwnd); - ns.setSurfaceHandle(hdc); - if(0 == hdc) { - res = NativeSurface.LOCK_SURFACE_NOT_READY; - ns.unlockSurface(); - throw new GLException("Error hdc 0, werr: "+GDI.GetLastError()); - // finally will unlock adevice - } - } - } else { - Throwable t = new Throwable("Error lock failed - res "+res+", hwnd "+toHexString(hwnd)+", hdc "+toHexString(hdc)); - t.printStackTrace(); - } - } finally { - if( NativeSurface.LOCK_SURFACE_NOT_READY == res ) { - adevice.unlock(); - } + public static WindowsDummyWGLDrawable create(GLDrawableFactory factory, GLProfile glp, AbstractGraphicsScreen absScreen, + long windowHandle, int width, int height, boolean handleWindowLifecycle) { + if(0 == windowHandle) { + throw new GLException("Error windowHandle 0, werr: "+GDI.GetLastError()); } - return res; - } - - public void unlockSurface() { - ProxySurface ns = (ProxySurface) getNativeSurface(); - ns.validateSurfaceLocked(); - AbstractGraphicsDevice adevice = ns.getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice(); - - try { - if ( 0 != hdc && 0 != hwnd && ns.getSurfaceRecursionCount() == 0) { - GDI.ReleaseDC(hwnd, hdc); - hdc=0; - ns.setSurfaceHandle(hdc); - } - surface.unlockSurface(); - } finally { - adevice.unlock(); - } - } - - public void setSize(int width, int height) { - } - - public int getWidth() { - return 1; - } - - public int getHeight() { - return 1; + GLCapabilities caps = new GLCapabilities(glp); + WindowsWGLGraphicsConfiguration cfg = WindowsWGLGraphicsConfigurationFactory.createDefaultGraphicsConfiguration(caps, absScreen); + GDISurface ns = new GDISurface(cfg, windowHandle); + ns.setSize(width, height); + return new WindowsDummyWGLDrawable(factory, ns, handleWindowLifecycle); } public GLContext createContext(GLContext shareWith) { @@ -156,13 +94,7 @@ public class WindowsDummyWGLDrawable extends WindowsWGLDrawable { } protected void destroyImpl() { - if (hdc != 0) { - GDI.ReleaseDC(hwnd, hdc); - hdc = 0; - ProxySurface ns = (ProxySurface) getNativeSurface(); - ns.setSurfaceHandle(hdc); - } - if (hwnd != 0) { + if (handleHwndLifecycle && hwnd != 0) { GDI.ShowWindow(hwnd, GDI.SW_HIDE); GDI.DestroyDummyWindow(hwnd); hwnd = 0; diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLContext.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLContext.java index 845460c58..0e2575bd9 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLContext.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLContext.java @@ -44,18 +44,18 @@ import javax.media.nativewindow.AbstractGraphicsScreen; import javax.media.nativewindow.DefaultGraphicsScreen; import javax.media.nativewindow.NativeSurface; import javax.media.nativewindow.NativeWindowFactory; +import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLContext; import javax.media.opengl.GLDrawableFactory; import javax.media.opengl.GLException; import javax.media.opengl.GLProfile; -import jogamp.nativewindow.ProxySurface; +import jogamp.nativewindow.WrappedSurface; import jogamp.nativewindow.windows.GDI; import jogamp.opengl.GLContextShareSet; public class WindowsExternalWGLContext extends WindowsWGLContext { - private boolean firstMakeCurrent = true; private GLContext lastContext; private WindowsExternalWGLContext(Drawable drawable, long ctx, WindowsWGLGraphicsConfiguration cfg) { @@ -70,40 +70,38 @@ public class WindowsExternalWGLContext extends WindowsWGLContext { } protected static WindowsExternalWGLContext create(GLDrawableFactory factory, GLProfile glp) { - /** - * Added thorough debug code, since we currently have problems with this code with use case: - * - WinXP [32bit] - * - GDI (Software GL) - * - SWT - * However, it works on other combinations, eg Win7 [64bit], GDI, SWT, etc .. - */ if(DEBUG) { System.err.println("WindowsExternalWGLContext 0: werr: " + GDI.GetLastError()); } - long ctx = WGL.wglGetCurrentContext(); + final long ctx = WGL.wglGetCurrentContext(); if (0 == ctx) { throw new GLException("Error: attempted to make an external GLContext without a context current, werr " + GDI.GetLastError()); } - long hdc = WGL.wglGetCurrentDC(); + final long hdc = WGL.wglGetCurrentDC(); if (0 == hdc) { throw new GLException("Error: attempted to make an external GLDrawable without a drawable current, werr " + GDI.GetLastError()); } - int hdcType = GDI.GetObjectType(hdc); - if( GDI.OBJ_DC != hdcType ) { - // FIXME: Turns out in above use case (WinXP-32bit, GDI, SWT) the returned DC (not 0) is invalid! - throw new GLException("Error: current WGL DC ("+toHexString(hdc)+") is not a DC but: "+hdcType+", werr " + GDI.GetLastError()); - } - - int pfdID = GDI.GetPixelFormat(hdc); + AbstractGraphicsScreen aScreen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_WINDOWS); + WindowsWGLGraphicsConfiguration cfg; + final int pfdID = GDI.GetPixelFormat(hdc); if (0 == pfdID) { - throw new GLException("Error: attempted to make an external GLContext without a valid pixelformat, werr " + GDI.GetLastError()); + // This could have happened if the HDC was released right after the GL ctx made current (SWT), + // WinXP-32bit will not be able to use this HDC afterwards. + // Workaround: Use a fake default configuration + final int werr = GDI.GetLastError(); + cfg = WindowsWGLGraphicsConfigurationFactory.createDefaultGraphicsConfiguration(new GLCapabilities(GLProfile.getDefault()), aScreen); + if(DEBUG) { + System.err.println("WindowsExternalWGLContext invalid hdc/pfd werr "+werr+", using default cfg: " + cfg); + } + } else { + cfg = WindowsWGLGraphicsConfiguration.createFromCurrent(factory, hdc, pfdID, glp, aScreen, true); + if(DEBUG) { + System.err.println("WindowsExternalWGLContext valid hdc/pfd, retrieved cfg: " + cfg); + } } - - AbstractGraphicsScreen aScreen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_WINDOWS); - WindowsWGLGraphicsConfiguration cfg = WindowsWGLGraphicsConfiguration.createFromCurrent(factory, hdc, pfdID, glp, aScreen, true); - return new WindowsExternalWGLContext(new Drawable(factory, new ProxySurface(cfg, hdc)), ctx, cfg); + return new WindowsExternalWGLContext(new Drawable(factory, new WrappedSurface(cfg, hdc)), ctx, cfg); } public int makeCurrent() throws GLException { @@ -124,9 +122,6 @@ public class WindowsExternalWGLContext extends WindowsWGLContext { } protected void makeCurrentImpl(boolean newCreated) throws GLException { - if (firstMakeCurrent) { - firstMakeCurrent = false; - } } protected void releaseImpl() throws GLException { diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLDrawable.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLDrawable.java index 742a42709..7666ae350 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLDrawable.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLDrawable.java @@ -49,7 +49,7 @@ import javax.media.opengl.GLDrawableFactory; import javax.media.opengl.GLException; import javax.media.opengl.GLProfile; -import jogamp.nativewindow.ProxySurface; +import jogamp.nativewindow.WrappedSurface; import jogamp.nativewindow.windows.GDI; public class WindowsExternalWGLDrawable extends WindowsWGLDrawable { @@ -70,7 +70,7 @@ public class WindowsExternalWGLDrawable extends WindowsWGLDrawable { AbstractGraphicsScreen aScreen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_WINDOWS); WindowsWGLGraphicsConfiguration cfg = WindowsWGLGraphicsConfiguration.createFromCurrent(factory, hdc, pfdID, glp, aScreen, true); - return new WindowsExternalWGLDrawable(factory, new ProxySurface(cfg, hdc)); + return new WindowsExternalWGLDrawable(factory, new WrappedSurface(cfg, hdc)); } diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java index 2c078dd98..5afbb9218 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java @@ -51,6 +51,7 @@ import javax.media.nativewindow.AbstractGraphicsDevice; import javax.media.nativewindow.AbstractGraphicsScreen; import javax.media.nativewindow.DefaultGraphicsScreen; import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.ProxySurface; import javax.media.nativewindow.NativeWindowFactory; import javax.media.nativewindow.windows.WindowsGraphicsDevice; import javax.media.nativewindow.AbstractGraphicsConfiguration; @@ -64,11 +65,11 @@ import javax.media.opengl.GLProfile; import com.jogamp.common.JogampRuntimeException; import com.jogamp.common.nio.PointerBuffer; import com.jogamp.common.util.ReflectionUtil; -import jogamp.nativewindow.ProxySurface; +import jogamp.nativewindow.WrappedSurface; import jogamp.nativewindow.windows.GDI; +import jogamp.nativewindow.windows.GDISurface; import jogamp.nativewindow.windows.RegisteredClassFactory; import jogamp.opengl.DesktopGLDynamicLookupHelper; -import jogamp.opengl.GLContextImpl; import jogamp.opengl.GLDrawableFactoryImpl; import jogamp.opengl.GLDrawableImpl; import jogamp.opengl.GLDynamicLookupHelper; @@ -228,7 +229,9 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { if (null == glp) { throw new GLException("Couldn't get default GLProfile for device: "+sharedDevice); } - WindowsDummyWGLDrawable sharedDrawable = WindowsDummyWGLDrawable.create(WindowsWGLDrawableFactory.this, glp, absScreen); + final int f_dim = 64; + long hwnd = GDI.CreateDummyWindow(0, 0, f_dim, f_dim); + WindowsDummyWGLDrawable sharedDrawable = WindowsDummyWGLDrawable.create(WindowsWGLDrawableFactory.this, glp, absScreen, hwnd, f_dim, f_dim, true); if (null == sharedDrawable) { throw new GLException("Couldn't create shared drawable for screen: "+absScreen+", "+glp); } @@ -434,9 +437,9 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { return false; } - protected final NativeSurface createOffscreenSurfaceImpl(AbstractGraphicsDevice device,GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, int width, int height) { + protected final NativeSurface createOffscreenSurfaceImpl(AbstractGraphicsDevice device, GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, int width, int height) { AbstractGraphicsScreen screen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_WINDOWS); - ProxySurface ns = new ProxySurface(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( + WrappedSurface ns = new WrappedSurface(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( capsChosen, capsRequested, chooser, screen) ); ns.setSize(width, height); return ns; diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11DummyGLXDrawable.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11DummyGLXDrawable.java index 202bba9e7..68bdb4ab8 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11DummyGLXDrawable.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11DummyGLXDrawable.java @@ -45,11 +45,11 @@ public class X11DummyGLXDrawable extends X11OnscreenGLXDrawable { */ public X11DummyGLXDrawable(X11GraphicsScreen screen, GLDrawableFactory factory, GLCapabilitiesImmutable caps) { super(factory, - new ProxySurface(X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( + new WrappedSurface(X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( caps, caps, null, screen))); this.realized = true; - ProxySurface ns = (ProxySurface) getNativeSurface(); + WrappedSurface ns = (WrappedSurface) getNativeSurface(); X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)ns.getGraphicsConfiguration().getNativeGraphicsConfiguration(); X11GraphicsDevice device = (X11GraphicsDevice) screen.getDevice(); diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXContext.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXContext.java index 769d5f1da..c488fe5cf 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXContext.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXContext.java @@ -44,10 +44,9 @@ import javax.media.nativewindow.*; import javax.media.nativewindow.x11.*; import javax.media.opengl.*; import jogamp.opengl.*; -import jogamp.nativewindow.ProxySurface; +import jogamp.nativewindow.WrappedSurface; public class X11ExternalGLXContext extends X11GLXContext { - private boolean firstMakeCurrent = true; private GLContext lastContext; private X11ExternalGLXContext(Drawable drawable, long ctx) { @@ -78,7 +77,7 @@ public class X11ExternalGLXContext extends X11GLXContext { GLX.glXQueryContext(display, ctx, GLX.GLX_FBCONFIG_ID, val, 0); X11GLXGraphicsConfiguration cfg = X11GLXGraphicsConfiguration.create(glp, x11Screen, val[0]); - ProxySurface ns = new ProxySurface(cfg); + WrappedSurface ns = new WrappedSurface(cfg); ns.setSurfaceHandle(drawable); return new X11ExternalGLXContext(new Drawable(factory, ns), ctx); } @@ -105,9 +104,6 @@ public class X11ExternalGLXContext extends X11GLXContext { } protected void makeCurrentImpl(boolean newCreated) throws GLException { - if (firstMakeCurrent) { - firstMakeCurrent = false; - } } protected void releaseImpl() throws GLException { diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXDrawable.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXDrawable.java index 014992b88..eb286cdf0 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXDrawable.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXDrawable.java @@ -42,7 +42,7 @@ package jogamp.opengl.x11.glx; import javax.media.nativewindow.*; import javax.media.nativewindow.x11.*; import javax.media.opengl.*; -import jogamp.nativewindow.ProxySurface; +import jogamp.nativewindow.WrappedSurface; public class X11ExternalGLXDrawable extends X11GLXDrawable { @@ -83,7 +83,7 @@ public class X11ExternalGLXDrawable extends X11GLXDrawable { System.err.println("X11ExternalGLXDrawable: WARNING: forcing GLX_RGBA_TYPE for newly created contexts (current 0x"+Integer.toHexString(val[0])+")"); } } - ProxySurface ns = new ProxySurface(cfg); + WrappedSurface ns = new WrappedSurface(cfg); ns.setSurfaceHandle(drawable); ns.setSize(w, h); return new X11ExternalGLXDrawable(factory, ns); diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java index 44ade1513..755c078b9 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java @@ -49,7 +49,7 @@ import javax.media.opengl.*; import jogamp.opengl.*; import com.jogamp.common.JogampRuntimeException; import com.jogamp.common.util.*; -import jogamp.nativewindow.ProxySurface; +import jogamp.nativewindow.WrappedSurface; import jogamp.nativewindow.x11.*; public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { @@ -399,7 +399,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return null; } - ProxySurface ns = new ProxySurface( + WrappedSurface ns = new WrappedSurface( X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capsChosen, capsRequested, chooser, screen) ); if(ns != null) { ns.setSize(width, height); diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java index 55f1f034b..ee7dd280e 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java @@ -96,13 +96,12 @@ public class X11AWTGLXGraphicsConfigurationFactory extends GLGraphicsConfigurati System.err.println(Thread.currentThread().getName() + " - X11AWTGLXGraphicsConfigurationFactory: using AWT X11 display 0x"+Long.toHexString(displayHandle)); } /** - * May cause an exception on NVidia X11 Display destruction, - * when destruction happen immediately after construction, around 10ms. - * However, the own Display handle is required for AMD gpus. + * Using the AWT display handle works fine with NVidia and AMD drivers today 2011-02-22, + * hence no need for our own display instance anymore. + String name = X11Util.XDisplayString(displayHandle); + displayHandle = X11Util.createDisplay(name); + owner = true; */ - String name = X11Util.XDisplayString(displayHandle); - displayHandle = X11Util.createDisplay(name); - owner = true; } ((AWTGraphicsDevice)awtScreen.getDevice()).setSubType(NativeWindowFactory.TYPE_X11, displayHandle); X11GraphicsDevice x11Device = new X11GraphicsDevice(displayHandle, AbstractGraphicsDevice.DEFAULT_UNIT); diff --git a/src/nativewindow/classes/javax/media/nativewindow/ProxySurface.java b/src/nativewindow/classes/javax/media/nativewindow/ProxySurface.java new file mode 100644 index 000000000..038580ce0 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/ProxySurface.java @@ -0,0 +1,150 @@ +/** + * 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 javax.media.nativewindow; + +import com.jogamp.common.util.locks.RecursiveLock; + +public abstract class ProxySurface implements NativeSurface { + protected RecursiveLock surfaceLock = new RecursiveLock(); + protected AbstractGraphicsConfiguration config; + protected long displayHandle; + protected int height; + protected int scrnIndex; + protected int width; + + public ProxySurface(AbstractGraphicsConfiguration cfg) { + invalidate(); + config = cfg; + displayHandle=cfg.getScreen().getDevice().getHandle(); + } + + void invalidate() { + displayHandle = 0; + invalidateImpl(); + } + protected abstract void invalidateImpl(); + + public final long getDisplayHandle() { + return displayHandle; + } + + public final AbstractGraphicsConfiguration getGraphicsConfiguration() { + return config; + } + + public final int getScreenIndex() { + return config.getScreen().getIndex(); + } + + public abstract long getSurfaceHandle(); + + public final int getWidth() { + return width; + } + + public final int getHeight() { + return height; + } + + public void setSize(int width, int height) { + this.width = width; + this.height = height; + } + + public boolean surfaceSwap() { + return false; + } + + public void surfaceUpdated(Object updater, NativeSurface ns, long when) { + } + + public int lockSurface() throws NativeWindowException { + surfaceLock.lock(); + int res = surfaceLock.getRecursionCount() == 0 ? LOCK_SURFACE_NOT_READY : LOCK_SUCCESS; + + if ( LOCK_SURFACE_NOT_READY == res ) { + try { + final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); + adevice.lock(); + try { + res = lockSurfaceImpl(); + } finally { + if (LOCK_SURFACE_NOT_READY >= res) { + adevice.unlock(); + } + } + } finally { + if (LOCK_SURFACE_NOT_READY >= res) { + surfaceLock.unlock(); + } + } + } + return res; + } + + public final void unlockSurface() { + surfaceLock.validateLocked(); + + if (surfaceLock.getRecursionCount() == 0) { + final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); + try { + unlockSurfaceImpl(); + } finally { + adevice.unlock(); + } + } + surfaceLock.unlock(); + } + + protected abstract int lockSurfaceImpl(); + + protected abstract void unlockSurfaceImpl() ; + + public final void validateSurfaceLocked() { + surfaceLock.validateLocked(); + } + + public final boolean isSurfaceLocked() { + return surfaceLock.isLocked(); + } + + public final boolean isSurfaceLockedByOtherThread() { + return surfaceLock.isLockedByOtherThread(); + } + + public final Thread getSurfaceLockOwner() { + return surfaceLock.getOwner(); + } + + public final int getSurfaceRecursionCount() { + return surfaceLock.getRecursionCount(); + } + + public abstract String toString(); +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/ProxySurface.java b/src/nativewindow/classes/jogamp/nativewindow/ProxySurface.java deleted file mode 100644 index 6dfbb2a91..000000000 --- a/src/nativewindow/classes/jogamp/nativewindow/ProxySurface.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 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: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution 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. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - */ - -package jogamp.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.SurfaceChangeable; - -import com.jogamp.common.util.locks.RecursiveLock; - -public class ProxySurface implements NativeSurface, SurfaceChangeable { - private RecursiveLock recurLock = new RecursiveLock(); - protected AbstractGraphicsConfiguration config; - protected long displayHandle; - protected long surfaceHandle; - protected int scrnIndex; - protected int width, height; - - public ProxySurface(AbstractGraphicsConfiguration cfg) { - this(cfg, 0); - } - - public ProxySurface(AbstractGraphicsConfiguration cfg, long handle) { - invalidate(); - config = cfg; - displayHandle=cfg.getScreen().getDevice().getHandle(); - surfaceHandle=handle; - scrnIndex=cfg.getScreen().getIndex(); - } - - protected void init(Object windowObject) throws NativeWindowException { - } - - protected void initNative() throws NativeWindowException { - } - - public NativeWindow getParent() { - return null; - } - - public void destroy() { - invalidate(); - } - - public synchronized void invalidate() { - displayHandle=0; - scrnIndex=-1; - surfaceHandle=0; - } - - public final int lockSurface() throws NativeWindowException { - recurLock.lock(); - - if(recurLock.getRecursionCount() == 0) { - config.getScreen().getDevice().lock(); - } - return LOCK_SUCCESS; - } - - public final void unlockSurface() { - recurLock.validateLocked(); - - if(recurLock.getRecursionCount()==0) { - config.getScreen().getDevice().unlock(); - } - recurLock.unlock(); - } - - public final void validateSurfaceLocked() { - recurLock.validateLocked(); - } - - public final int getSurfaceRecursionCount() { - return recurLock.getRecursionCount(); - } - - public final boolean isSurfaceLockedByOtherThread() { - return recurLock.isLockedByOtherThread(); - } - - public final boolean isSurfaceLocked() { - return recurLock.isLocked(); - } - - public final Thread getSurfaceLockOwner() { - return recurLock.getOwner(); - } - - public boolean surfaceSwap() { - return false; - } - - public long getSurfaceHandle() { - return surfaceHandle; - } - - public int getWidth() { - return width; - } - - public int getHeight() { - return height; - } - - public AbstractGraphicsConfiguration getGraphicsConfiguration() { - return config; - } - - public void surfaceUpdated(Object updater, NativeSurface ns, long when) { } - - public long getDisplayHandle() { - return displayHandle; - } - public int getScreenIndex() { - return scrnIndex; - } - - public void setSurfaceHandle(long surfaceHandle) { - this.surfaceHandle=surfaceHandle; - } - - public void setSize(int width, int height) { - this.width=width; - this.height=height; - } - - public String toString() { - return "ProxySurface[config "+config+ - ", displayHandle 0x"+Long.toHexString(getDisplayHandle())+ - ", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle())+ - ", size "+getWidth()+"x"+getHeight()+"]"; - } - -} diff --git a/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java b/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java new file mode 100644 index 000000000..4c2b1c875 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java @@ -0,0 +1,70 @@ +/** + * 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 jogamp.nativewindow; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.ProxySurface; +import javax.media.nativewindow.SurfaceChangeable; + + +public class WrappedSurface extends ProxySurface implements SurfaceChangeable { + protected long surfaceHandle; + + public WrappedSurface(AbstractGraphicsConfiguration cfg) { + this(cfg, 0); + } + + public WrappedSurface(AbstractGraphicsConfiguration cfg, long handle) { + super(cfg); + surfaceHandle=handle; + } + + protected final void invalidateImpl() { + surfaceHandle = 0; + } + + public long getSurfaceHandle() { + return surfaceHandle; + } + + public void setSurfaceHandle(long surfaceHandle) { + this.surfaceHandle=surfaceHandle; + } + + protected int lockSurfaceImpl() { + return LOCK_SUCCESS; + } + + protected void unlockSurfaceImpl() { + } + + public String toString() { + return "WrappedSurface[config " + config + ", displayHandle 0x" + Long.toHexString(getDisplayHandle()) + ", surfaceHandle 0x" + Long.toHexString(getSurfaceHandle()) + ", size " + getWidth() + "x" + getHeight() + "]"; + } +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java index 944c08604..781882f08 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java @@ -42,6 +42,7 @@ import com.jogamp.common.util.locks.RecursiveLock; import java.awt.Component; import java.awt.Window; import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsDevice; import javax.media.nativewindow.NativeSurface; import javax.media.nativewindow.NativeWindow; import javax.media.nativewindow.NativeWindowException; @@ -106,58 +107,60 @@ public abstract class JAWTWindow implements NativeWindow { // NativeSurface // - private RecursiveLock recurLock = new RecursiveLock(); + private RecursiveLock surfaceLock = new RecursiveLock(); protected abstract int lockSurfaceImpl() throws NativeWindowException; public final int lockSurface() throws NativeWindowException { - int res = LOCK_SURFACE_NOT_READY; + surfaceLock.lock(); + int res = surfaceLock.getRecursionCount() == 0 ? LOCK_SURFACE_NOT_READY : LOCK_SUCCESS; - recurLock.lock(); - - if(recurLock.getRecursionCount() == 0) { - config.getScreen().getDevice().lock(); + if ( LOCK_SURFACE_NOT_READY == res ) { try { - res = lockSurfaceImpl(); + final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); + adevice.lock(); + try { + res = lockSurfaceImpl(); + } finally { + if (LOCK_SURFACE_NOT_READY >= res) { + adevice.unlock(); + } + } } finally { - // Unlock in case surface couldn't be locked - if(LOCK_SURFACE_NOT_READY >= res ) { - config.getScreen().getDevice().unlock(); - recurLock.unlock(); + if (LOCK_SURFACE_NOT_READY >= res) { + surfaceLock.unlock(); } } - } else { - res = LOCK_SUCCESS; } - return res; } protected abstract void unlockSurfaceImpl() throws NativeWindowException; public final void unlockSurface() { - recurLock.validateLocked(); + surfaceLock.validateLocked(); - if(recurLock.getRecursionCount()==0) { + if (surfaceLock.getRecursionCount() == 0) { + final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); try { unlockSurfaceImpl(); } finally { - config.getScreen().getDevice().unlock(); + adevice.unlock(); } } - recurLock.unlock(); + surfaceLock.unlock(); } public final boolean isSurfaceLockedByOtherThread() { - return recurLock.isLockedByOtherThread(); + return surfaceLock.isLockedByOtherThread(); } public final boolean isSurfaceLocked() { - return recurLock.isLocked(); + return surfaceLock.isLocked(); } public final Thread getSurfaceLockOwner() { - return recurLock.getOwner(); + return surfaceLock.getOwner(); } public final boolean surfaceSwap() { diff --git a/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java b/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java new file mode 100644 index 000000000..7f8bccd56 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java @@ -0,0 +1,112 @@ +/** + * 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 jogamp.nativewindow.swt; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import org.eclipse.swt.graphics.GCData; +import org.eclipse.swt.widgets.Control; + +import javax.media.nativewindow.NativeWindowException; +import com.jogamp.common.util.ReflectionUtil; + +public class SWTAccessor { + static final Method swt_control_internal_new_GC; + static final Method swt_control_internal_dispose_GC; + static final boolean swt_uses_long_handles; + static final Field swt_control_handle; + + static final String str_internal_new_GC = "internal_new_GC"; + static final String str_internal_dispose_GC = "internal_dispose_GC"; + static final String str_handle = "handle"; + + static { + Method m=null; + try { + m = ReflectionUtil.getMethod(Control.class, str_internal_new_GC, new Class[] { GCData.class }); + } catch (Exception ex) { + throw new NativeWindowException(ex); + } + swt_control_internal_new_GC = m; + + boolean swt_uses_long_tmp = false; + try { + m = Control.class.getDeclaredMethod(str_internal_dispose_GC, new Class[] { int.class, GCData.class }); + swt_uses_long_tmp = false; + } catch (NoSuchMethodException ex1) { + try { + m = Control.class.getDeclaredMethod(str_internal_dispose_GC, new Class[] { long.class, GCData.class }); + swt_uses_long_tmp = true; + } catch (NoSuchMethodException ex2) { + throw new NativeWindowException("Neither 'int' nor 'long' variant of '"+str_internal_dispose_GC+"' exist", ex2); + } + } + swt_uses_long_handles = swt_uses_long_tmp; + swt_control_internal_dispose_GC = m; + + Field f = null; + try { + f = Control.class.getField(str_handle); + } catch (Exception ex) { + throw new NativeWindowException(ex); + } + swt_control_handle = f; + } + + public static boolean isUsingLongHandles() { + return swt_uses_long_handles; + } + + public static long getHandle(Control swtControl) { + long h = 0; + try { + h = swt_control_handle.getLong(swtControl); + } catch (Exception ex) { + throw new NativeWindowException(ex); + } + return h; + } + + public static long newGC(Control swtControl, GCData gcData) { + Object o = ReflectionUtil.callMethod(swtControl, swt_control_internal_new_GC, new Object[] { gcData }); + if(o instanceof Number) { + return ((Number)o).longValue(); + } else { + throw new InternalError("SWT internal_new_GC did not return int or long but "+o.getClass()); + } + } + + public static void disposeGC(Control swtControl, long gc, GCData gcData) { + if(swt_uses_long_handles) { + ReflectionUtil.callMethod(swtControl, swt_control_internal_dispose_GC, new Object[] { new Long(gc), gcData }); + } else { + ReflectionUtil.callMethod(swtControl, swt_control_internal_dispose_GC, new Object[] { new Integer((int)gc), gcData }); + } + } +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/windows/GDISurface.java b/src/nativewindow/classes/jogamp/nativewindow/windows/GDISurface.java new file mode 100644 index 000000000..68cf8af45 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/windows/GDISurface.java @@ -0,0 +1,87 @@ +/** + * 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 jogamp.nativewindow.windows; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.NativeWindowException; + +import javax.media.nativewindow.ProxySurface; + +/** + * GDI Surface implementation which wraps an existing window handle + * allowing the use of HDC via lockSurface()/unlockSurface() protocol. + * The latter will get and release the HDC. + * The size via getWidth()/getHeight() is invalid. + */ +public class GDISurface extends ProxySurface { + protected long windowHandle; + protected long surfaceHandle; + + public GDISurface(AbstractGraphicsConfiguration cfg, long windowHandle) { + super(cfg); + if(0 == windowHandle) { + throw new NativeWindowException("Error hwnd 0, werr: "+GDI.GetLastError()); + } + this.windowHandle=windowHandle; + } + + protected final void invalidateImpl() { + windowHandle=0; + surfaceHandle=0; + } + + protected int lockSurfaceImpl() { + if (0 != surfaceHandle) { + throw new InternalError("surface not released"); + } + surfaceHandle = GDI.GetDC(windowHandle); + return (0 != surfaceHandle) ? LOCK_SUCCESS : LOCK_SURFACE_NOT_READY; + } + + protected void unlockSurfaceImpl() { + if (0 == surfaceHandle) { + throw new InternalError("surface not acquired"); + } + GDI.ReleaseDC(windowHandle, surfaceHandle); + surfaceHandle=0; + } + + public long getSurfaceHandle() { + return surfaceHandle; + } + + public String toString() { + return "GDISurface[config "+config+ + ", displayHandle 0x"+Long.toHexString(getDisplayHandle())+ + ", windowHandle 0x"+Long.toHexString(windowHandle)+ + ", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle())+ + ", size "+getWidth()+"x"+getHeight()+"]"; + } + +} diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index f3fab7bce..fee188768 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -76,14 +76,14 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { ((WindowImpl)this.window).setHandleDestroyNotify(false); window.addWindowListener(new WindowAdapter() { public void windowRepaint(WindowUpdateEvent e) { - if( !GLWindow.this.window.isSurfaceLockedByOtherThread() && !GLWindow.this.helper.isExternalAnimatorAnimating() ) { + if( !GLWindow.this.window.isWindowLockedByOtherThread() && !GLWindow.this.helper.isExternalAnimatorAnimating() ) { display(); } } public void windowResized(WindowEvent e) { sendReshape = true; - if( !GLWindow.this.window.isSurfaceLockedByOtherThread() && !GLWindow.this.helper.isExternalAnimatorAnimating() ) { + if( !GLWindow.this.window.isWindowLockedByOtherThread() && !GLWindow.this.helper.isExternalAnimatorAnimating() ) { display(); } } @@ -99,8 +99,8 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { if(isPaused) { ctrl.resume(); } - } else if (GLWindow.this.window.isSurfaceLockedByOtherThread()) { - // Surface is locked by another thread + } else if (GLWindow.this.window.isWindowLockedByOtherThread()) { + // Window is locked by another thread // Flag that destroy should be performed on the next // attempt to display. sendDestroy = true; diff --git a/src/newt/classes/com/jogamp/newt/util/MainThread.java b/src/newt/classes/com/jogamp/newt/util/MainThread.java index 607645052..9f66fefe6 100644 --- a/src/newt/classes/com/jogamp/newt/util/MainThread.java +++ b/src/newt/classes/com/jogamp/newt/util/MainThread.java @@ -37,16 +37,25 @@ package com.jogamp.newt.util; -import java.util.*; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; -import java.security.*; - -import javax.media.nativewindow.*; - -import com.jogamp.common.util.*; -import com.jogamp.newt.*; -import jogamp.newt.*; +import java.security.AccessControlContext; +import java.security.AccessController; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; + +import javax.media.nativewindow.NativeWindowFactory; + +import com.jogamp.common.util.ReflectionUtil; +import com.jogamp.common.util.RunnableTask; +import com.jogamp.newt.Display; +import jogamp.newt.Debug; +import jogamp.newt.NEWTJNILibLoader; +import jogamp.newt.awt.AWTEDTUtil; /** * NEWT Utility class MainThread<P> @@ -103,16 +112,11 @@ public class MainThread implements EDTUtil { private static Map/*<Display, Runnable>*/ pumpMessageDisplayMap = new HashMap(); private static boolean useMainThread = false; - private static Class cAWTEventQueue=null; - private static Method mAWTInvokeAndWait=null; - private static Method mAWTInvokeLater=null; - private static Method mAWTIsDispatchThread=null; static class MainAction extends Thread { private String mainClassName; private String[] mainClassArgs; - private Class mainClass; private Method mainClassMain; public MainAction(String mainClassName, String[] mainClassArgs) { @@ -237,33 +241,28 @@ public class MainThread implements EDTUtil { } } - private void initAWTReflection() { - if(null == cAWTEventQueue) { - ClassLoader cl = MainThread.class.getClassLoader(); - cAWTEventQueue = ReflectionUtil.getClass("java.awt.EventQueue", true, cl); - mAWTInvokeAndWait = ReflectionUtil.getMethod(cAWTEventQueue, "invokeAndWait", new Class[] { java.lang.Runnable.class }, cl); - mAWTInvokeLater = ReflectionUtil.getMethod(cAWTEventQueue, "invokeLater", new Class[] { java.lang.Runnable.class }, cl); - mAWTIsDispatchThread = ReflectionUtil.getMethod(cAWTEventQueue, "isDispatchThread", new Class[] { }, cl); + final public void reset() { + if(NativeWindowFactory.isAWTAvailable()) { + AWTEDTUtil.getSingleton().reset(); } - } - - public void reset() { // nop } - public void start() { + final public void start() { + if(NativeWindowFactory.isAWTAvailable()) { + AWTEDTUtil.getSingleton().start(); + } // nop } - public boolean isCurrentThreadEDT() { + final public boolean isCurrentThreadEDT() { if(NativeWindowFactory.isAWTAvailable()) { - initAWTReflection(); - return ((Boolean) ReflectionUtil.callMethod(null, mAWTIsDispatchThread, null) ).booleanValue(); + return AWTEDTUtil.getSingleton().isCurrentThreadEDT(); } return isRunning() && mainThread == Thread.currentThread() ; } - public boolean isRunning() { + final public boolean isRunning() { if( useMainThread ) { synchronized(taskWorkerLock) { return isRunning; @@ -284,11 +283,11 @@ public class MainThread implements EDTUtil { } } - public void invokeStop(Runnable r) { + final public void invokeStop(Runnable r) { invokeImpl(true, r, true); } - public void invoke(boolean wait, Runnable r) { + final public void invoke(boolean wait, Runnable r) { invokeImpl(wait, r, false); } @@ -298,22 +297,7 @@ public class MainThread implements EDTUtil { } if(NativeWindowFactory.isAWTAvailable()) { - initAWTReflection(); - - // handover to AWT MainThread .. - try { - if ( ((Boolean) ReflectionUtil.callMethod(null, mAWTIsDispatchThread, null) ).booleanValue() ) { - r.run(); - return; - } - if(wait) { - ReflectionUtil.callMethod(null, mAWTInvokeAndWait, new Object[] { r }); - } else { - ReflectionUtil.callMethod(null, mAWTInvokeLater, new Object[] { r }); - } - } catch (Exception e) { - throw new NativeWindowException(e); - } + AWTEDTUtil.getSingleton().invokeImpl(wait, r, stop); return; } @@ -355,10 +339,16 @@ public class MainThread implements EDTUtil { } } - public void waitUntilIdle() { + final public void waitUntilIdle() { + if(NativeWindowFactory.isAWTAvailable()) { + AWTEDTUtil.getSingleton().waitUntilIdle(); + } } - public void waitUntilStopped() { + final public void waitUntilStopped() { + if(NativeWindowFactory.isAWTAvailable()) { + AWTEDTUtil.getSingleton().waitUntilStopped(); + } } private void waitUntilRunning() { diff --git a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java index 925828175..016906581 100644 --- a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java +++ b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java @@ -37,10 +37,10 @@ package jogamp.newt; +import java.util.ArrayList; +import javax.media.nativewindow.NativeWindowException; import com.jogamp.common.util.RunnableTask; import com.jogamp.newt.util.EDTUtil; -import java.util.*; -import javax.media.nativewindow.NativeWindowException; public class DefaultEDTUtil implements EDTUtil { public static final boolean DEBUG = Debug.debug("EDT"); @@ -191,7 +191,7 @@ public class DefaultEDTUtil implements EDTUtil { } } - public void waitUntilIdle() { + final public void waitUntilIdle() { if(edt.isRunning() && edt != Thread.currentThread()) { synchronized(edt.tasks) { while(edt.isRunning() && edt.tasks.size()>0) { @@ -206,7 +206,7 @@ public class DefaultEDTUtil implements EDTUtil { } } - public void waitUntilStopped() { + final public void waitUntilStopped() { if(edt.isRunning() && edt != Thread.currentThread() ) { synchronized(edtLock) { if(edt.isRunning() && edt != Thread.currentThread() ) { @@ -231,11 +231,11 @@ public class DefaultEDTUtil implements EDTUtil { super(tg, name); } - public final boolean isRunning() { + final public boolean isRunning() { return isRunning; } - public void start() throws IllegalThreadStateException { + final public void start() throws IllegalThreadStateException { isRunning = true; super.start(); } @@ -244,7 +244,7 @@ public class DefaultEDTUtil implements EDTUtil { * Utilizing locking only on tasks and its execution, * not for event dispatching. */ - public void run() { + final public void run() { if(DEBUG) { System.err.println(getName()+": EDT run() START "+ getName()); } diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index 79679b7b3..815fd705e 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -73,7 +73,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer { public static final boolean DEBUG_TEST_REPARENT_INCOMPATIBLE = Debug.isPropertyDefined("newt.test.Window.reparent.incompatible", true); - private RecursiveLock windowLock = new RecursiveLock(); + private RecursiveLock windowLock = new RecursiveLock(); // Window instance wide lock + private RecursiveLock surfaceLock = new RecursiveLock(); // Surface only lock private long windowHandle; private ScreenImpl screen; private boolean screenReferenceAdded = false; @@ -463,52 +464,73 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer // public final int lockSurface() { - int res = LOCK_SURFACE_NOT_READY; windowLock.lock(); + surfaceLock.lock(); + int res = surfaceLock.getRecursionCount() == 0 ? LOCK_SURFACE_NOT_READY : LOCK_SUCCESS; - if(isNativeValid()) { - AbstractGraphicsDevice adevice = screen.getDisplay().getGraphicsDevice(); - adevice.lock(); + if ( LOCK_SURFACE_NOT_READY == res ) { try { - res = lockSurfaceImpl(); + if( isNativeValid() ) { + final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); + adevice.lock(); + try { + res = lockSurfaceImpl(); + } finally { + if (LOCK_SURFACE_NOT_READY >= res) { + adevice.unlock(); + } + } + } } finally { - if( LOCK_SURFACE_NOT_READY == res ) { - adevice.unlock(); + if (LOCK_SURFACE_NOT_READY >= res) { + surfaceLock.unlock(); + windowLock.unlock(); } } } - if( LOCK_SURFACE_NOT_READY == res ) { - windowLock.unlock(); - } - return res; } public final void unlockSurface() { - // may throw RuntimeException if not locked + surfaceLock.validateLocked(); windowLock.validateLocked(); - AbstractGraphicsDevice adevice = screen.getDisplay().getGraphicsDevice(); - try { - unlockSurfaceImpl(); - } finally { - adevice.unlock(); + if (surfaceLock.getRecursionCount() == 0) { + final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); + try { + unlockSurfaceImpl(); + } finally { + adevice.unlock(); + } } + surfaceLock.unlock(); windowLock.unlock(); } - public final boolean isSurfaceLockedByOtherThread() { + public final boolean isWindowLockedByOtherThread() { return windowLock.isLockedByOtherThread(); } - public final boolean isSurfaceLocked() { + public final boolean isWindowLocked() { return windowLock.isLocked(); } - public final Thread getSurfaceLockOwner() { + public final Thread getWindowLockOwner() { return windowLock.getOwner(); } + public final boolean isSurfaceLockedByOtherThread() { + return surfaceLock.isLockedByOtherThread(); + } + + public final boolean isSurfaceLocked() { + return surfaceLock.isLocked(); + } + + public final Thread getSurfaceLockOwner() { + return surfaceLock.getOwner(); + } + public long getSurfaceHandle() { return windowHandle; // default: return window handle } @@ -1367,7 +1389,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer "\n, ParentWindow "+parentWindow+ "\n, ParentWindowHandle "+toHexString(parentWindowHandle)+ "\n, WindowHandle "+toHexString(getWindowHandle())+ - "\n, SurfaceHandle "+toHexString(getSurfaceHandle())+ " (lockedExt "+isSurfaceLockedByOtherThread()+")"+ + "\n, SurfaceHandle "+toHexString(getSurfaceHandle())+ " (lockedExt window "+isWindowLockedByOtherThread()+", surface "+isSurfaceLockedByOtherThread()+")"+ "\n, Pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+ "\n, Visible "+isVisible()+ "\n, Undecorated "+undecorated+ @@ -1645,8 +1667,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer switch(e.getEventType()) { // special repaint treatment case WindowEvent.EVENT_WINDOW_REPAINT: - // queue repaint event in case surface is locked, ie in operation - if( isSurfaceLocked() ) { + // queue repaint event in case window is locked, ie in operation + if( isWindowLocked() ) { // make sure only one repaint event is queued if(!repaintQueued) { repaintQueued=true; @@ -1664,8 +1686,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer // common treatment case WindowEvent.EVENT_WINDOW_RESIZED: - // queue event in case surface is locked, ie in operation - if( isSurfaceLocked() ) { + // queue event in case window is locked, ie in operation + if( isWindowLocked() ) { if(DEBUG_IMPLEMENTATION) { System.err.println("Window.consumeEvent: queued "+e); // Exception ee = new Exception("Window.windowRepaint: "+e); @@ -2160,10 +2182,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } } - protected int getWindowLockRecursionCount() { - return windowLock.getRecursionCount(); - } - // // Reflection helper .. // diff --git a/src/newt/classes/jogamp/newt/awt/AWTCanvas.java b/src/newt/classes/jogamp/newt/awt/AWTCanvas.java index 5606ceb01..01e813449 100644 --- a/src/newt/classes/jogamp/newt/awt/AWTCanvas.java +++ b/src/newt/classes/jogamp/newt/awt/AWTCanvas.java @@ -33,18 +33,24 @@ package jogamp.newt.awt; -import com.jogamp.newt.Window; - import java.awt.Canvas; import java.awt.GraphicsDevice; import java.awt.GraphicsConfiguration; - -import javax.media.nativewindow.*; -import javax.media.nativewindow.awt.*; import java.lang.reflect.Method; import java.security.AccessController; import java.security.PrivilegedAction; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.CapabilitiesChooser; +import javax.media.nativewindow.CapabilitiesImmutable; +import javax.media.nativewindow.GraphicsConfigurationFactory; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.awt.AWTGraphicsConfiguration; +import javax.media.nativewindow.awt.AWTGraphicsDevice; +import javax.media.nativewindow.awt.AWTGraphicsScreen; +import com.jogamp.newt.Window; + public class AWTCanvas extends Canvas { private GraphicsDevice device; private GraphicsConfiguration chosen; @@ -76,29 +82,37 @@ public class AWTCanvas extends Canvas { } public void addNotify() { - super.addNotify(); - - disableBackgroundErase(); - GraphicsConfiguration gc = super.getGraphicsConfiguration(); - if(null!=gc) { - device = gc.getDevice(); - } - - /* - * Save the chosen capabilities for use in getGraphicsConfiguration(). + /** + * 'super.addNotify()' determines the GraphicsConfiguration, + * while calling this class's overriden 'getGraphicsConfiguration()' method + * after which it creates the native peer. + * Hence we have to set the 'awtConfig' before since it's GraphicsConfiguration + * is being used in getGraphicsConfiguration(). + * This code order also allows recreation, ie re-adding the GLCanvas. */ awtConfig = chooseGraphicsConfiguration(capabilities, capabilities, chooser, device); if(Window.DEBUG_IMPLEMENTATION) { Exception e = new Exception("Info: Created Config: "+awtConfig); e.printStackTrace(); } - if(null!=awtConfig) { - // update .. - chosen = awtConfig.getGraphicsConfiguration(); - } if(null==awtConfig) { - throw new NativeWindowException("Error: AWTGraphicsConfiguration is null"); + throw new NativeWindowException("Error: NULL AWTGraphicsConfiguration"); + } + chosen = awtConfig.getGraphicsConfiguration(); + + // before native peer is valid: X11 + disableBackgroundErase(); + + // issues getGraphicsConfiguration() and creates the native peer + super.addNotify(); + + // after native peer is valid: Windows + disableBackgroundErase(); + + GraphicsConfiguration gc = super.getGraphicsConfiguration(); + if(null!=gc) { + device = gc.getDevice(); } } @@ -276,13 +290,22 @@ public class AWTCanvas extends Canvas { } catch (Exception e) { } disableBackgroundEraseInitialized = true; + if(Window.DEBUG_IMPLEMENTATION) { + System.err.println("AWTCanvas: TK disableBackgroundErase method found: "+ + (null!=disableBackgroundEraseMethod)); + } } if (disableBackgroundEraseMethod != null) { + Throwable t=null; try { disableBackgroundEraseMethod.invoke(getToolkit(), new Object[] { this }); } catch (Exception e) { // FIXME: workaround for 6504460 (incorrect backport of 6333613 in 5.0u10) // throw new GLException(e); + t = e; + } + if(Window.DEBUG_IMPLEMENTATION) { + System.err.println("AWTCanvas: TK disableBackgroundErase error: "+t); } } } diff --git a/src/newt/classes/jogamp/newt/awt/AWTDisplay.java b/src/newt/classes/jogamp/newt/awt/AWTDisplay.java index f8a756f60..4c864c111 100644 --- a/src/newt/classes/jogamp/newt/awt/AWTDisplay.java +++ b/src/newt/classes/jogamp/newt/awt/AWTDisplay.java @@ -33,13 +33,10 @@ package jogamp.newt.awt; -import java.awt.event.*; -import com.jogamp.newt.Display; -import com.jogamp.newt.Window; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.awt.AWTGraphicsDevice; +import com.jogamp.newt.NewtFactory; import jogamp.newt.DisplayImpl; -import javax.media.nativewindow.*; -import javax.media.nativewindow.awt.*; -import java.util.*; public class AWTDisplay extends DisplayImpl { public AWTDisplay() { @@ -55,9 +52,16 @@ public class AWTDisplay extends DisplayImpl { protected void closeNativeImpl() { } - protected boolean shallRunOnEDT() { - return false; + @Override + protected void createEDTUtil() { + if(NewtFactory.useEDT()) { + edtUtil = AWTEDTUtil.getSingleton(); + if(DEBUG) { + System.err.println("AWTDisplay.createNative("+getFQName()+") Create EDTUtil: "+edtUtil.getClass().getName()); + } + } } + protected void dispatchMessagesNative() { /* nop */ } } diff --git a/src/newt/classes/jogamp/newt/awt/AWTEDTUtil.java b/src/newt/classes/jogamp/newt/awt/AWTEDTUtil.java new file mode 100644 index 000000000..914a73f4d --- /dev/null +++ b/src/newt/classes/jogamp/newt/awt/AWTEDTUtil.java @@ -0,0 +1,108 @@ +/** + * 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 jogamp.newt.awt; + +import java.awt.EventQueue; +import javax.media.nativewindow.NativeWindowException; +import com.jogamp.newt.util.EDTUtil; +import jogamp.newt.Debug; + +public class AWTEDTUtil implements EDTUtil { + public static final boolean DEBUG = Debug.debug("EDT"); + + private static AWTEDTUtil singletonMainThread = new AWTEDTUtil(); // one singleton MainThread + + public static final AWTEDTUtil getSingleton() { + return singletonMainThread; + } + + AWTEDTUtil() { + // package private access .. + } + + final public void reset() { + // nop + } + + final public void start() { + // nop + } + + final public boolean isCurrentThreadEDT() { + return EventQueue.isDispatchThread(); + } + + final public boolean isRunning() { + return true; // AWT is always running + } + + final public void invokeStop(Runnable r) { + invokeImpl(true, r, true); + } + + final public void invoke(boolean wait, Runnable r) { + invokeImpl(wait, r, false); + } + + /** + * Public access to provide simple dispatching from other EDTUtil implementations + * @param wait true if invokeLater + * @param r the Runnable action + * @param stop true if EDT shall stop (ignored with AWT) + */ + final public void invokeImpl(boolean wait, Runnable r, boolean stop) { + if(r == null) { + return; + } + + // handover to AWT MainThread .. + try { + if ( isCurrentThreadEDT() ) { + r.run(); + return; + } + if(wait) { + EventQueue.invokeAndWait(r); + } else { + EventQueue.invokeLater(r); + } + } catch (Exception e) { + throw new NativeWindowException(e); + } + } + + final public void waitUntilIdle() { + } + + final public void waitUntilStopped() { + } + +} + + diff --git a/src/newt/classes/jogamp/newt/awt/AWTScreen.java b/src/newt/classes/jogamp/newt/awt/AWTScreen.java index 83d7be57c..d05933321 100644 --- a/src/newt/classes/jogamp/newt/awt/AWTScreen.java +++ b/src/newt/classes/jogamp/newt/awt/AWTScreen.java @@ -33,11 +33,11 @@ package jogamp.newt.awt; -import com.jogamp.newt.*; -import jogamp.newt.ScreenImpl; import java.awt.DisplayMode; -import javax.media.nativewindow.*; -import javax.media.nativewindow.awt.*; + +import jogamp.newt.ScreenImpl; +import javax.media.nativewindow.awt.AWTGraphicsDevice; +import javax.media.nativewindow.awt.AWTGraphicsScreen; public class AWTScreen extends ScreenImpl { public AWTScreen() { @@ -46,10 +46,10 @@ public class AWTScreen extends ScreenImpl { protected void createNativeImpl() { aScreen = new AWTGraphicsScreen((AWTGraphicsDevice)display.getGraphicsDevice()); - DisplayMode mode = ((AWTGraphicsDevice)getDisplay().getGraphicsDevice()).getGraphicsDevice().getDisplayMode(); - int w = mode.getWidth(); - int h = mode.getHeight(); - setScreenSize(w, h); + final DisplayMode mode = ((AWTGraphicsDevice)getDisplay().getGraphicsDevice()).getGraphicsDevice().getDisplayMode(); + if(null != mode) { + setScreenSize(mode.getWidth(), mode.getHeight()); + } } protected void setAWTGraphicsScreen(AWTGraphicsScreen s) { diff --git a/src/newt/classes/jogamp/newt/awt/AWTWindow.java b/src/newt/classes/jogamp/newt/awt/AWTWindow.java index 908b6f2cb..0a6a557f7 100644 --- a/src/newt/classes/jogamp/newt/awt/AWTWindow.java +++ b/src/newt/classes/jogamp/newt/awt/AWTWindow.java @@ -34,19 +34,19 @@ package jogamp.newt.awt; -import com.jogamp.newt.event.awt.*; -import com.jogamp.newt.util.EDTUtil; - import java.awt.BorderLayout; import java.awt.Container; import java.awt.DisplayMode; -import java.awt.EventQueue; import java.awt.Frame; -import jogamp.newt.WindowImpl; import java.awt.Insets; -import javax.media.nativewindow.*; -import javax.media.nativewindow.awt.*; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.awt.AWTGraphicsDevice; +import javax.media.nativewindow.awt.AWTGraphicsScreen; import javax.media.nativewindow.util.Point; +import jogamp.newt.WindowImpl; +import com.jogamp.newt.event.awt.AWTKeyAdapter; +import com.jogamp.newt.event.awt.AWTMouseAdapter; +import com.jogamp.newt.event.awt.AWTWindowAdapter; /** An implementation of the Newt Window class built using the AWT. This is provided for convenience of porting to platforms @@ -77,89 +77,67 @@ public class AWTWindow extends WindowImpl { private AWTCanvas canvas; protected void requestFocusImpl(boolean reparented) { - runOnEDT(true, new Runnable() { - public void run() { - container.requestFocus(); - } - }); + container.requestFocus(); } protected void setTitleImpl(final String title) { - runOnEDT(true, new Runnable() { - public void run() { - if (frame != null) { - frame.setTitle(title); - } - } - }); + if (frame != null) { + frame.setTitle(title); + } } protected void createNativeImpl() { - if(0!=getParentWindowHandle()) { throw new RuntimeException("Window parenting not supported in AWT, use AWTWindow(Frame) cstr for wrapping instead"); } - final AWTWindow awtWindow = this; + if(null==container) { + frame = new Frame(); + container = frame; + owningFrame=true; + } else { + owningFrame=false; + width = container.getWidth(); + height = container.getHeight(); + x = container.getX(); + y = container.getY(); + } + if(null!=frame) { + frame.setTitle(getTitle()); + } + container.setLayout(new BorderLayout()); + canvas = new AWTCanvas(capsRequested, AWTWindow.this.capabilitiesChooser); - runOnEDT(true, new Runnable() { - public void run() { - if(null==container) { - frame = new Frame(); - container = frame; - owningFrame=true; - } else { - owningFrame=false; - width = container.getWidth(); - height = container.getHeight(); - x = container.getX(); - y = container.getY(); - } - if(null!=frame) { - frame.setTitle(getTitle()); - } - container.setLayout(new BorderLayout()); - canvas = new AWTCanvas(capsRequested, AWTWindow.this.capabilitiesChooser); + addWindowListener(new LocalWindowListener()); - addWindowListener(new LocalWindowListener()); + new AWTMouseAdapter(this).addTo(canvas); // fwd all AWT Mouse events to here + new AWTKeyAdapter(this).addTo(canvas); // fwd all AWT Key events to here - new AWTMouseAdapter(awtWindow).addTo(canvas); // fwd all AWT Mouse events to here - new AWTKeyAdapter(awtWindow).addTo(canvas); // fwd all AWT Key events to here + // canvas.addComponentListener(listener); + container.add(canvas, BorderLayout.CENTER); + container.setSize(width, height); + container.setLocation(x, y); + new AWTWindowAdapter(this).addTo(container); // fwd all AWT Window events to here - // canvas.addComponentListener(listener); - container.add(canvas, BorderLayout.CENTER); - container.setSize(width, height); - container.setLocation(x, y); - new AWTWindowAdapter(awtWindow).addTo(container); // fwd all AWT Window events to here + if(null!=frame) { + frame.setUndecorated(undecorated||fullscreen); + } - if(null!=frame) { - frame.setUndecorated(undecorated||fullscreen); - } - } - }); setWindowHandle(1); // just a marker .. } protected void closeNativeImpl() { setWindowHandle(0); // just a marker .. if(null!=container) { - runOnEDT(true, new Runnable() { - public void run() { - container.setVisible(false); - container.remove(canvas); - container.setEnabled(false); - canvas.setEnabled(false); - } - }); + container.setVisible(false); + container.remove(canvas); + container.setEnabled(false); + canvas.setEnabled(false); } if(owningFrame && null!=frame) { - runOnEDT(true, new Runnable() { - public void run() { - frame.dispose(); - owningFrame=false; - frame = null; - } - }); + frame.dispose(); + owningFrame=false; + frame = null; } } @@ -176,11 +154,7 @@ public class AWTWindow extends WindowImpl { } protected void setVisibleImpl(final boolean visible, int x, int y, int width, int height) { - runOnEDT(true, new Runnable() { - public void run() { - container.setVisible(visible); - } - }); + container.setVisible(visible); reconfigureWindowImpl(x, y, width, height, false, 0, 0); config = canvas.getAWTGraphicsConfiguration(); @@ -206,42 +180,33 @@ public class AWTWindow extends WindowImpl { public javax.media.nativewindow.util.Insets getInsets() { final int insets[] = new int[] { 0, 0, 0, 0 }; - runOnEDT(true, new Runnable() { - public void run() { - Insets contInsets = container.getInsets(); - insets[0] = contInsets.top; - insets[1] = contInsets.left; - insets[2] = contInsets.bottom; - insets[3] = contInsets.right; - } - }); + Insets contInsets = container.getInsets(); + insets[0] = contInsets.top; + insets[1] = contInsets.left; + insets[2] = contInsets.bottom; + insets[3] = contInsets.right; return new javax.media.nativewindow.util.Insets(insets[0],insets[1],insets[2],insets[3]); } protected boolean reconfigureWindowImpl(final int x, final int y, final int width, final int height, final boolean parentChange, final int fullScreenChange, final int decorationChange) { - /** An AWT event on setSize() would bring us in a deadlock situation, hence invokeLater() */ - runOnEDT(false, new Runnable() { - public void run() { - if(decorationChange!=0 && null!=frame) { - if(!container.isDisplayable()) { - frame.setUndecorated(isUndecorated()); - } else { - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("AWTWindow can't undecorate already created frame"); - } - } - } - int _x=(x>=0)?x:AWTWindow.this.x; - int _y=(x>=0)?y:AWTWindow.this.y; - int _w=(width>0)?width:AWTWindow.this.width; - int _h=(height>0)?height:AWTWindow.this.height; - - container.setLocation(_x, _y); - Insets insets = container.getInsets(); - container.setSize(_w + insets.left + insets.right, - _h + insets.top + insets.bottom); + if(decorationChange!=0 && null!=frame) { + if(!container.isDisplayable()) { + frame.setUndecorated(isUndecorated()); + } else { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("AWTWindow can't undecorate already created frame"); } - }); + } + } + int _x=(x>=0)?x:AWTWindow.this.x; + int _y=(x>=0)?y:AWTWindow.this.y; + int _w=(width>0)?width:AWTWindow.this.width; + int _h=(height>0)?height:AWTWindow.this.height; + + container.setLocation(_x, _y); + Insets insets = container.getInsets(); + container.setSize(_w + insets.left + insets.right, + _h + insets.top + insets.bottom); return true; } @@ -255,23 +220,6 @@ public class AWTWindow extends WindowImpl { return canvas; } - private void runOnEDT(boolean wait, Runnable r) { - EDTUtil edtUtil = getScreen().getDisplay().getEDTUtil(); - if ( ( null != edtUtil && edtUtil.isCurrentThreadEDT() ) || EventQueue.isDispatchThread() ) { - r.run(); - } else { - try { - if(wait) { - EventQueue.invokeAndWait(r); - } else { - EventQueue.invokeLater(r); - } - } catch (Exception e) { - throw new NativeWindowException(e); - } - } - } - class LocalWindowListener extends com.jogamp.newt.event.WindowAdapter { public void windowMoved(com.jogamp.newt.event.WindowEvent e) { if(null!=container) { diff --git a/src/newt/classes/jogamp/newt/windows/WindowsWindow.java b/src/newt/classes/jogamp/newt/windows/WindowsWindow.java index d820be529..05d169c5e 100644 --- a/src/newt/classes/jogamp/newt/windows/WindowsWindow.java +++ b/src/newt/classes/jogamp/newt/windows/WindowsWindow.java @@ -56,18 +56,20 @@ public class WindowsWindow extends WindowImpl { } protected int lockSurfaceImpl() { - if( 0 != getWindowHandle() && 0 == hdc ) { - hdc = GDI.GetDC(getWindowHandle()); - hmon = MonitorFromWindow0(getWindowHandle()); + if (0 != hdc) { + throw new InternalError("surface not released"); } + hdc = GDI.GetDC(getWindowHandle()); + hmon = MonitorFromWindow0(getWindowHandle()); return ( 0 != hdc ) ? LOCK_SUCCESS : LOCK_SURFACE_NOT_READY; } protected void unlockSurfaceImpl() { - if ( 0 != hdc && 0 != getWindowHandle() && getWindowLockRecursionCount() == 0) { - GDI.ReleaseDC(getWindowHandle(), hdc); - hdc=0; + if (0 == hdc) { + throw new InternalError("surface not acquired"); } + GDI.ReleaseDC(getWindowHandle(), hdc); + hdc=0; } public final long getSurfaceHandle() { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java index 6d9801d48..9e0bebc9c 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java @@ -101,8 +101,9 @@ public class TestSharedContextListAWT extends UITestCase { frame.pack(); frame.setSize(width, height); frame.setLocation(x, y); - frame.validate(); + frame.invalidate(); frame.setVisible(true); + frame.validate(); } }); Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas, true)); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/newt/TestGearsNewtAWTWrapper.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/newt/TestGearsNewtAWTWrapper.java index 939a85631..f05c20c4c 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/newt/TestGearsNewtAWTWrapper.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/newt/TestGearsNewtAWTWrapper.java @@ -40,10 +40,8 @@ import com.jogamp.newt.event.*; import com.jogamp.newt.opengl.*; import org.junit.Assert; -import org.junit.Before; import org.junit.BeforeClass; import org.junit.AfterClass; -import org.junit.After; import org.junit.Test; public class TestGearsNewtAWTWrapper extends UITestCase { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT01GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT01GLn.java index 94231a88d..96204d148 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT01GLn.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT01GLn.java @@ -54,6 +54,14 @@ import org.junit.After; import org.junit.Test;
import com.jogamp.opengl.test.junit.util.UITestCase;
+import javax.media.nativewindow.NativeSurface;
+import javax.media.nativewindow.ProxySurface;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLDrawable;
+import jogamp.nativewindow.swt.SWTAccessor;
+import jogamp.opengl.windows.wgl.WindowsWGLDrawableFactory;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Canvas;
/**
* Tests that a basic SWT app can open without crashing under different GL profiles. Uses the SWT GL canvas.
@@ -61,12 +69,14 @@ import com.jogamp.opengl.test.junit.util.UITestCase; */
public class TestSWT01GLn extends UITestCase {
- static final int duration = 250;
+ static int duration = 250;
+
+ static final int iwidth = 640;
+ static final int iheight = 480;
Display display = null;
Shell shell = null;
Composite composite = null;
- GLCanvas glcanvas = null;
@BeforeClass
public static void startup() {
@@ -91,9 +101,7 @@ public class TestSWT01GLn extends UITestCase { Assert.assertNotNull( display );
Assert.assertNotNull( shell );
Assert.assertNotNull( composite );
- Assert.assertNotNull( glcanvas );
try {
- glcanvas.dispose();
composite.dispose();
shell.dispose();
display.dispose();
@@ -105,15 +113,14 @@ public class TestSWT01GLn extends UITestCase { display = null;
shell = null;
composite = null;
- glcanvas = null;
}
- protected void runTestGL( GLProfile glprofile ) throws InterruptedException {
+ protected void runTestAGL( GLProfile glprofile ) throws InterruptedException {
GLData gldata = new GLData();
gldata.doubleBuffer = true;
// need SWT.NO_BACKGROUND to prevent SWT from clearing the window
// at the wrong times (we use glClear for this instead)
- glcanvas = new GLCanvas( composite, SWT.NO_BACKGROUND, gldata );
+ final GLCanvas glcanvas = new GLCanvas( composite, SWT.NO_BACKGROUND, gldata );
Assert.assertNotNull( glcanvas );
glcanvas.setCurrent();
final GLContext glcontext = GLDrawableFactory.getFactory( glprofile ).createExternalGLContext();
@@ -127,7 +134,8 @@ public class TestSWT01GLn extends UITestCase { glcontext.makeCurrent();
GL2 gl = glcontext.getGL().getGL2();
OneTriangle.setup( gl, rectangle );
- glcontext.release();
+ glcontext.release();
+ System.err.println("resize");
}
});
@@ -140,7 +148,8 @@ public class TestSWT01GLn extends UITestCase { GL2 gl = glcontext.getGL().getGL2();
OneTriangle.render( gl, rectangle );
glcanvas.swapBuffers();
- glcontext.release();
+ glcontext.release();
+ System.err.println("paint");
}
});
@@ -157,28 +166,116 @@ public class TestSWT01GLn extends UITestCase { Thread.sleep(10);
}
}
- }
- catch( Throwable throwable ) {
+ } catch( Throwable throwable ) {
throwable.printStackTrace();
Assume.assumeNoException( throwable );
}
+ glcanvas.dispose();
}
+ /**
+ protected void runTestBGL( GLProfile glprofile ) throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glprofile);
+ WindowsWGLDrawableFactory factory = (WindowsWGLDrawableFactory) GLDrawableFactory.getFactory(glprofile);
+
+ GLData gldata = new GLData();
+ gldata.doubleBuffer = true;
+ // need SWT.NO_BACKGROUND to prevent SWT from clearing the window
+ // at the wrong times (we use glClear for this instead)
+ final Canvas canvas = new Canvas(composite, SWT.NO_BACKGROUND);
+ Assert.assertNotNull( canvas );
+ canvas.setSize(iwidth, iheight);
+ long windowHandle = SWTAccessor.getHandle(canvas);
+ Point sz = canvas.getSize();
+ ProxySurface surface = factory.createProxySurfaceImpl(caps, caps, null, windowHandle, sz.x, sz.y);
+ final GLDrawable glDrawable = factory.createGLDrawable(surface);
+
+ glDrawable.setRealized(true);
+ final GLContext glContext = glDrawable.createContext(null);
+
+ // fix the viewport when the user resizes the window
+ canvas.addListener( SWT.Resize, new Listener() {
+ public void handleEvent( Event event ) {
+ Rectangle rectangle = canvas.getClientArea();
+ glContext.makeCurrent();
+ GL2 gl = glContext.getGL().getGL2();
+ OneTriangle.setup( gl, rectangle );
+ glContext.release();
+ System.err.println("resize");
+ }
+ });
+
+ // draw the triangle when the OS tells us that any part of the window needs drawing
+ canvas.addPaintListener( new PaintListener() {
+ public void paintControl( PaintEvent paintevent ) {
+ Rectangle rectangle = canvas.getClientArea();
+ glContext.makeCurrent();
+ GL2 gl = glContext.getGL().getGL2();
+ OneTriangle.render( gl, rectangle );
+ glDrawable.swapBuffers();
+ glContext.release();
+ System.err.println("paint");
+ }
+ });
+
+ shell.setText( getClass().getName() );
+ shell.setSize( iwidth, iheight );
+ shell.open();
+
+ long lStartTime = System.currentTimeMillis();
+ long lEndTime = lStartTime + duration;
+ try {
+ while( (System.currentTimeMillis() < lEndTime) && !canvas.isDisposed() ) {
+ if( !display.readAndDispatch() ) {
+ // blocks on linux .. display.sleep();
+ Thread.sleep(10);
+ }
+ }
+ } catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ glContext.destroy();
+ glDrawable.setRealized(false);
+ canvas.dispose();
+ } */
+
@Test
- public void test01GLDefault() throws InterruptedException {
+ public void testA01GLDefault() throws InterruptedException {
GLProfile glprofile = GLProfile.getDefault();
System.out.println( "GLProfile Default: " + glprofile );
- runTestGL( glprofile );
+ runTestAGL( glprofile );
}
+ /* @Test
+ public void testB01GLDefault() throws InterruptedException {
+ GLProfile glprofile = GLProfile.getDefault();
+ System.out.println( "GLProfile Default: " + glprofile );
+ runTestBGL( glprofile );
+ } */
+
@Test
public void test02GL2() throws InterruptedException {
GLProfile glprofile = GLProfile.get(GLProfile.GL2);
System.out.println( "GLProfile GL2: " + glprofile );
- runTestGL( glprofile );
+ runTestAGL( glprofile );
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
}
public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ duration = atoi(args[++i]);
+ }
+ }
+ System.out.println("durationPerTest: "+duration);
org.junit.runner.JUnitCore.main(TestSWT01GLn.class.getName());
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java index 846013b1d..7de63e6a6 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java @@ -30,22 +30,17 @@ package com.jogamp.opengl.test.junit.newt; import java.io.IOException; import javax.media.nativewindow.NativeWindowFactory; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLProfile; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import com.jogamp.newt.Display; import com.jogamp.newt.NewtFactory; import com.jogamp.newt.Screen; import com.jogamp.newt.Window; import com.jogamp.newt.ScreenMode; -import com.jogamp.newt.opengl.GLWindow; import com.jogamp.newt.util.MonitorMode; import com.jogamp.newt.util.ScreenModeUtil; -import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears; import com.jogamp.opengl.test.junit.util.UITestCase; import java.util.Iterator; import java.util.List; diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java index 35522f681..40c1e0528 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java +++ b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java @@ -45,7 +45,7 @@ import javax.swing.JFrame; public class AWTRobotUtil { - public static int TIME_OUT = 1000; // 1s + public static int TIME_OUT = 2000; // 2s public static int ROBOT_DELAY = 50; // ms public static int POLL_DIVIDER = 20; // TO/20 |