From 4a43734dc09b56e418ca5036f54c856555ac2920 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 22 Feb 2011 08:51:09 +0100 Subject: NativeWindow/SWT: Rename SWTMisc -> SWTAccessor; Add to nativewindow.core.jar --- etc/profile.jogl | 30 ++--- make/build-nativewindow.xml | 7 +- make/scripts/tests.sh | 5 +- .../jogamp/nativewindow/swt/SWTAccessor.java | 112 ++++++++++++++++++ .../classes/jogamp/nativewindow/swt/SWTMisc.java | 112 ------------------ .../opengl/test/junit/jogl/swt/TestSWT01GLn.java | 125 ++++++++++++++++++--- 6 files changed, 247 insertions(+), 144 deletions(-) create mode 100644 src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java delete mode 100644 src/nativewindow/classes/jogamp/nativewindow/swt/SWTMisc.java 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-nativewindow.xml b/make/build-nativewindow.xml index 14769d805..1e38a43f0 100644 --- a/make/build-nativewindow.xml +++ b/make/build-nativewindow.xml @@ -72,11 +72,14 @@ + + + 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}"/> + value="javax/media/nativewindow/awt/* jogamp/nativewindow/jawt/** jogamp/nativewindow/**/awt/**"/> diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index 816c691a4..f264b7755 100644 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -32,6 +32,7 @@ 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 $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 @@ -104,7 +105,7 @@ function testawt() { #testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting02NEWT #testawt com.jogamp.opengl.test.junit.newt.TestScreenMode00NEWT #testnoawt com.jogamp.opengl.test.junit.newt.TestScreenMode01NEWT -testnoawt com.jogamp.opengl.test.junit.newt.TestScreenMode02NEWT +#testnoawt com.jogamp.opengl.test.junit.newt.TestScreenMode02NEWT #testawt com.jogamp.opengl.test.junit.newt.TestGLWindows01NEWT -time 1000000 #testawt -Djava.awt.headless=true com.jogamp.opengl.test.junit.newt.TestGLWindows01NEWT #testawt com.jogamp.opengl.test.junit.newt.TestGLWindows02NEWTAnimated @@ -125,7 +126,7 @@ testnoawt com.jogamp.opengl.test.junit.newt.TestScreenMode02NEWT #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 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/swt/SWTMisc.java b/src/nativewindow/classes/jogamp/nativewindow/swt/SWTMisc.java deleted file mode 100644 index 915444cf6..000000000 --- a/src/nativewindow/classes/jogamp/nativewindow/swt/SWTMisc.java +++ /dev/null @@ -1,112 +0,0 @@ -/** - * 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 SWTMisc { - 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/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