From f3bc93b003c05684e48d75eee9107c16a9dc7283 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Sat, 27 Mar 2010 23:31:01 +0100 Subject: refactoring part 4 (remaining files): renamed com.sun.opengl -> com.jogamp.opengl. --- .../classes/com/sun/nativewindow/impl/InternalBufferUtil.java | 2 +- src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nativewindow/classes') diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/InternalBufferUtil.java b/src/nativewindow/classes/com/sun/nativewindow/impl/InternalBufferUtil.java index 0425014df..7cf2e3ff5 100644 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/InternalBufferUtil.java +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/InternalBufferUtil.java @@ -37,7 +37,7 @@ import java.lang.reflect.*; import java.nio.*; /** Internal copy of selected routines from BufferUtil to avoid - outward dependencies on com.sun.opengl.util package. */ + outward dependencies on com.jogamp.opengl.util package. */ public class InternalBufferUtil { public static final int SIZEOF_BYTE = 1; public static final int SIZEOF_SHORT = 2; diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java index aac01e990..6a8f8cdb2 100644 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java @@ -65,7 +65,7 @@ public class JAWTUtil { Method m=null; if(!headlessMode) { try { - jC = Class.forName("com.sun.opengl.impl.awt.Java2D"); + jC = Class.forName("com.jogamp.opengl.impl.awt.Java2D"); m = jC.getMethod("isQueueFlusherThread", null); ok = true; } catch (Exception e) {} -- cgit v1.2.3 From be452bbfbb101292350cc6a483471a0e98ac937b Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Sun, 28 Mar 2010 20:25:31 +0200 Subject: final large refactoring to move to com.jogamp.*. --- doc/wiki/FAQ.xml | 6 +- doxygen/doxygen-all-dev.cfg | 2 +- doxygen/doxygen-all-pub.cfg | 2 +- make/build-jogl.xml | 24 +- make/build-nativewindow.xml | 24 +- make/build-newt.xml | 40 +- make/build-staticglgen.xml | 2 +- make/build.xml | 6 +- make/config/jogl/glu-common.cfg | 2 +- make/config/jogl/glx-x11.cfg | 2 +- make/config/jogl/glxext.cfg | 2 +- .../jawt-DrawingSurfaceInfo-CustomJavaCode.java | 6 +- make/config/nativewindow/jawt-macosx.cfg | 6 +- make/config/nativewindow/jawt-win32.cfg | 6 +- make/config/nativewindow/jawt-x11.cfg | 6 +- make/config/nativewindow/x11-CustomCCode.c | 26 +- make/config/nativewindow/x11-lib.cfg | 2 +- .../jogamp/javafx/audio/windows/waveout/Audio.java | 66 ++ .../jogamp/javafx/audio/windows/waveout/Mixer.java | 362 ++++++++ .../javafx/audio/windows/waveout/SoundBuffer.java | 124 +++ .../audio/windows/waveout/TestSpatialization.java | 89 ++ .../jogamp/javafx/audio/windows/waveout/Track.java | 206 +++++ .../jogamp/javafx/audio/windows/waveout/Vec3f.java | 212 +++++ .../com/jogamp/opengl/impl/GLContextImpl.java | 2 +- .../jogamp/opengl/impl/GLDrawableFactoryImpl.java | 2 +- .../com/jogamp/opengl/impl/NativeLibLoader.java | 2 +- .../com/jogamp/opengl/impl/ThreadingImpl.java | 2 +- .../com/jogamp/opengl/impl/awt/AWTUtil.java | 2 +- .../com/jogamp/opengl/impl/egl/EGLDrawable.java | 2 +- .../jogamp/opengl/impl/egl/EGLDrawableFactory.java | 2 +- .../opengl/impl/egl/EGLDynamicLookupHelper.java | 2 +- .../opengl/impl/egl/EGLES1DynamicLookupHelper.java | 2 +- .../opengl/impl/egl/EGLES2DynamicLookupHelper.java | 2 +- .../impl/egl/EGLGraphicsConfigurationFactory.java | 2 +- .../opengl/impl/egl/EGLOnscreenDrawable.java | 2 +- .../impl/macosx/cgl/MacOSXCGLDrawableFactory.java | 2 +- .../cgl/MacOSXCGLGraphicsConfigurationFactory.java | 2 +- .../impl/macosx/cgl/MacOSXExternalCGLContext.java | 2 +- .../MacOSXAWTCGLGraphicsConfigurationFactory.java | 4 +- .../impl/windows/wgl/WindowsDummyWGLDrawable.java | 2 +- .../windows/wgl/WindowsExternalWGLContext.java | 2 +- .../windows/wgl/WindowsExternalWGLDrawable.java | 2 +- .../windows/wgl/WindowsOffscreenWGLDrawable.java | 2 +- .../windows/wgl/WindowsWGLDrawableFactory.java | 4 +- .../WindowsWGLGraphicsConfigurationFactory.java | 2 +- .../WindowsAWTWGLGraphicsConfigurationFactory.java | 4 +- .../com/jogamp/opengl/impl/x11/glx/GLXUtil.java | 2 +- .../opengl/impl/x11/glx/X11ExternalGLXContext.java | 4 +- .../impl/x11/glx/X11ExternalGLXDrawable.java | 4 +- .../jogamp/opengl/impl/x11/glx/X11GLXContext.java | 2 +- .../jogamp/opengl/impl/x11/glx/X11GLXDrawable.java | 2 +- .../opengl/impl/x11/glx/X11GLXDrawableFactory.java | 6 +- .../impl/x11/glx/X11GLXGraphicsConfiguration.java | 2 +- .../glx/X11GLXGraphicsConfigurationFactory.java | 4 +- .../impl/x11/glx/X11OffscreenGLXDrawable.java | 2 +- .../opengl/impl/x11/glx/X11PbufferGLXDrawable.java | 2 +- .../awt/X11AWTGLXGraphicsConfigurationFactory.java | 6 +- .../com/jogamp/opengl/util/ImmModeSink.java | 2 +- .../com/jogamp/openmax/OMXEventListener.java | 14 + .../classes/com/jogamp/openmax/OMXInstance.java | 509 +++++++++++ .../sun/javafx/audio/windows/waveout/Audio.java | 66 -- .../sun/javafx/audio/windows/waveout/Mixer.java | 362 -------- .../javafx/audio/windows/waveout/SoundBuffer.java | 124 --- .../audio/windows/waveout/TestSpatialization.java | 88 -- .../sun/javafx/audio/windows/waveout/Track.java | 206 ----- .../sun/javafx/audio/windows/waveout/Vec3f.java | 212 ----- .../classes/com/sun/openmax/OMXEventListener.java | 14 - src/jogl/classes/com/sun/openmax/OMXInstance.java | 509 ----------- .../javax/media/opengl/GLDrawableFactory.java | 2 +- src/jogl/classes/javax/media/opengl/GLProfile.java | 4 +- src/jogl/native/audio/Mixer.cpp | 26 +- .../native/openmax/com_sun_openmax_OMXInstance.c | 30 +- .../com/jogamp/nativewindow/impl/Debug.java | 140 ++++ .../impl/GraphicsConfigurationFactoryImpl.java | 43 + .../nativewindow/impl/InternalBufferUtil.java | 124 +++ .../impl/LockingNativeWindowFactory.java | 75 ++ .../com/jogamp/nativewindow/impl/NWReflection.java | 181 ++++ .../nativewindow/impl/NativeLibLoaderBase.java | 202 +++++ .../nativewindow/impl/NativeWindowFactoryImpl.java | 114 +++ .../com/jogamp/nativewindow/impl/NullWindow.java | 148 ++++ .../impl/jawt/JAWTNativeLibLoader.java | 78 ++ .../jogamp/nativewindow/impl/jawt/JAWTUtil.java | 145 ++++ .../jogamp/nativewindow/impl/jawt/JAWTWindow.java | 186 +++++ .../nativewindow/impl/jawt/JAWT_PlatformInfo.java | 47 ++ .../impl/jawt/macosx/MacOSXJAWTWindow.java | 152 ++++ .../impl/jawt/windows/WindowsJAWTWindow.java | 170 ++++ .../nativewindow/impl/jawt/x11/X11JAWTWindow.java | 136 +++ .../impl/jawt/x11/X11SunJDKReflection.java | 132 +++ .../com/jogamp/nativewindow/impl/jvm/JVMUtil.java | 72 ++ .../impl/x11/X11GraphicsConfigurationFactory.java | 118 +++ .../com/jogamp/nativewindow/impl/x11/X11Util.java | 166 ++++ .../impl/x11/awt/X11AWTNativeWindowFactory.java | 87 ++ .../classes/com/sun/nativewindow/impl/Debug.java | 140 ---- .../impl/GraphicsConfigurationFactoryImpl.java | 43 - .../sun/nativewindow/impl/InternalBufferUtil.java | 124 --- .../impl/LockingNativeWindowFactory.java | 75 -- .../com/sun/nativewindow/impl/NWReflection.java | 181 ---- .../sun/nativewindow/impl/NativeLibLoaderBase.java | 202 ----- .../nativewindow/impl/NativeWindowFactoryImpl.java | 114 --- .../com/sun/nativewindow/impl/NullWindow.java | 148 ---- .../impl/jawt/JAWTNativeLibLoader.java | 78 -- .../com/sun/nativewindow/impl/jawt/JAWTUtil.java | 145 ---- .../com/sun/nativewindow/impl/jawt/JAWTWindow.java | 186 ----- .../nativewindow/impl/jawt/JAWT_PlatformInfo.java | 47 -- .../impl/jawt/macosx/MacOSXJAWTWindow.java | 152 ---- .../impl/jawt/windows/WindowsJAWTWindow.java | 170 ---- .../nativewindow/impl/jawt/x11/X11JAWTWindow.java | 136 --- .../impl/jawt/x11/X11SunJDKReflection.java | 132 --- .../com/sun/nativewindow/impl/jvm/JVMUtil.java | 72 -- .../impl/x11/X11GraphicsConfigurationFactory.java | 118 --- .../com/sun/nativewindow/impl/x11/X11Util.java | 166 ---- .../impl/x11/awt/X11AWTNativeWindowFactory.java | 87 -- .../nativewindow/GraphicsConfigurationFactory.java | 4 +- .../media/nativewindow/NativeWindowFactory.java | 8 +- .../nativewindow/awt/AWTGraphicsConfiguration.java | 2 +- .../media/nativewindow/awt/AWTGraphicsDevice.java | 2 +- .../media/nativewindow/awt/AWTGraphicsScreen.java | 2 +- .../classes/javax/media/nativewindow/package.html | 2 +- .../nativewindow/x11/X11GraphicsConfiguration.java | 2 +- .../media/nativewindow/x11/X11GraphicsScreen.java | 4 +- src/nativewindow/native/JAWT_DrawingSurfaceInfo.c | 2 +- src/nativewindow/native/JVM_Tool.c | 2 +- .../classes/com/jogamp/javafx/newt/Display.java | 276 ++++++ src/newt/classes/com/jogamp/javafx/newt/Event.java | 86 ++ .../com/jogamp/javafx/newt/EventListener.java | 44 + .../classes/com/jogamp/javafx/newt/InputEvent.java | 97 +++ .../classes/com/jogamp/javafx/newt/Insets.java | 105 +++ .../classes/com/jogamp/javafx/newt/KeyEvent.java | 738 ++++++++++++++++ .../com/jogamp/javafx/newt/KeyListener.java | 42 + .../classes/com/jogamp/javafx/newt/MouseEvent.java | 110 +++ .../com/jogamp/javafx/newt/MouseListener.java | 47 ++ .../com/jogamp/javafx/newt/NewtFactory.java | 181 ++++ .../com/jogamp/javafx/newt/OffscreenWindow.java | 108 +++ .../classes/com/jogamp/javafx/newt/PaintEvent.java | 74 ++ .../com/jogamp/javafx/newt/PaintListener.java | 42 + .../classes/com/jogamp/javafx/newt/Screen.java | 147 ++++ .../classes/com/jogamp/javafx/newt/Window.java | 929 +++++++++++++++++++++ .../com/jogamp/javafx/newt/WindowEvent.java | 67 ++ .../com/jogamp/javafx/newt/WindowListener.java | 42 + .../com/jogamp/javafx/newt/awt/AWTCanvas.java | 264 ++++++ .../com/jogamp/javafx/newt/awt/AWTDisplay.java | 168 ++++ .../com/jogamp/javafx/newt/awt/AWTScreen.java | 65 ++ .../com/jogamp/javafx/newt/awt/AWTWindow.java | 429 ++++++++++ .../classes/com/jogamp/javafx/newt/impl/Debug.java | 140 ++++ .../jogamp/javafx/newt/impl/NativeLibLoader.java | 62 ++ .../com/jogamp/javafx/newt/intel/gdl/Display.java | 104 +++ .../com/jogamp/javafx/newt/intel/gdl/Screen.java | 68 ++ .../com/jogamp/javafx/newt/intel/gdl/Window.java | 179 ++++ .../com/jogamp/javafx/newt/macosx/MacDisplay.java | 82 ++ .../com/jogamp/javafx/newt/macosx/MacScreen.java | 56 ++ .../com/jogamp/javafx/newt/macosx/MacWindow.java | 600 +++++++++++++ .../com/jogamp/javafx/newt/opengl/GLWindow.java | 628 ++++++++++++++ .../javafx/newt/opengl/broadcom/egl/Display.java | 81 ++ .../javafx/newt/opengl/broadcom/egl/Screen.java | 63 ++ .../javafx/newt/opengl/broadcom/egl/Window.java | 156 ++++ .../jogamp/javafx/newt/opengl/kd/KDDisplay.java | 84 ++ .../com/jogamp/javafx/newt/opengl/kd/KDScreen.java | 57 ++ .../com/jogamp/javafx/newt/opengl/kd/KDWindow.java | 153 ++++ .../javafx/newt/util/EventDispatchThread.java | 240 ++++++ .../com/jogamp/javafx/newt/util/MainThread.java | 307 +++++++ .../jogamp/javafx/newt/windows/WindowsDisplay.java | 105 +++ .../jogamp/javafx/newt/windows/WindowsScreen.java | 58 ++ .../jogamp/javafx/newt/windows/WindowsWindow.java | 289 +++++++ .../com/jogamp/javafx/newt/x11/X11Display.java | 120 +++ .../com/jogamp/javafx/newt/x11/X11Screen.java | 71 ++ .../com/jogamp/javafx/newt/x11/X11Window.java | 203 +++++ src/newt/classes/com/sun/javafx/newt/Display.java | 276 ------ src/newt/classes/com/sun/javafx/newt/Event.java | 86 -- .../classes/com/sun/javafx/newt/EventListener.java | 44 - .../classes/com/sun/javafx/newt/InputEvent.java | 97 --- src/newt/classes/com/sun/javafx/newt/Insets.java | 105 --- src/newt/classes/com/sun/javafx/newt/KeyEvent.java | 738 ---------------- .../classes/com/sun/javafx/newt/KeyListener.java | 42 - .../classes/com/sun/javafx/newt/MouseEvent.java | 110 --- .../classes/com/sun/javafx/newt/MouseListener.java | 47 -- .../classes/com/sun/javafx/newt/NewtFactory.java | 181 ---- .../com/sun/javafx/newt/OffscreenWindow.java | 108 --- .../classes/com/sun/javafx/newt/PaintEvent.java | 74 -- .../classes/com/sun/javafx/newt/PaintListener.java | 42 - src/newt/classes/com/sun/javafx/newt/Screen.java | 147 ---- src/newt/classes/com/sun/javafx/newt/Window.java | 929 --------------------- .../classes/com/sun/javafx/newt/WindowEvent.java | 67 -- .../com/sun/javafx/newt/WindowListener.java | 42 - .../classes/com/sun/javafx/newt/awt/AWTCanvas.java | 264 ------ .../com/sun/javafx/newt/awt/AWTDisplay.java | 168 ---- .../classes/com/sun/javafx/newt/awt/AWTScreen.java | 65 -- .../classes/com/sun/javafx/newt/awt/AWTWindow.java | 429 ---------- .../classes/com/sun/javafx/newt/impl/Debug.java | 140 ---- .../com/sun/javafx/newt/impl/NativeLibLoader.java | 62 -- .../com/sun/javafx/newt/intel/gdl/Display.java | 104 --- .../com/sun/javafx/newt/intel/gdl/Screen.java | 68 -- .../com/sun/javafx/newt/intel/gdl/Window.java | 179 ---- .../com/sun/javafx/newt/macosx/MacDisplay.java | 82 -- .../com/sun/javafx/newt/macosx/MacScreen.java | 56 -- .../com/sun/javafx/newt/macosx/MacWindow.java | 600 ------------- .../com/sun/javafx/newt/opengl/GLWindow.java | 628 -------------- .../javafx/newt/opengl/broadcom/egl/Display.java | 81 -- .../javafx/newt/opengl/broadcom/egl/Screen.java | 63 -- .../javafx/newt/opengl/broadcom/egl/Window.java | 156 ---- .../com/sun/javafx/newt/opengl/kd/KDDisplay.java | 84 -- .../com/sun/javafx/newt/opengl/kd/KDScreen.java | 57 -- .../com/sun/javafx/newt/opengl/kd/KDWindow.java | 153 ---- .../sun/javafx/newt/util/EventDispatchThread.java | 240 ------ .../com/sun/javafx/newt/util/MainThread.java | 307 ------- .../sun/javafx/newt/windows/WindowsDisplay.java | 105 --- .../com/sun/javafx/newt/windows/WindowsScreen.java | 58 -- .../com/sun/javafx/newt/windows/WindowsWindow.java | 289 ------- .../com/sun/javafx/newt/x11/X11Display.java | 120 --- .../classes/com/sun/javafx/newt/x11/X11Screen.java | 71 -- .../classes/com/sun/javafx/newt/x11/X11Window.java | 203 ----- src/newt/native/BroadcomEGL.c | 16 +- src/newt/native/IntelGDL.c | 24 +- src/newt/native/KDWindow.c | 20 +- src/newt/native/WindowsWindow.c | 74 +- src/newt/native/X11Window.c | 56 +- 215 files changed, 12333 insertions(+), 12332 deletions(-) create mode 100755 src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Audio.java create mode 100755 src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Mixer.java create mode 100755 src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/SoundBuffer.java create mode 100755 src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/TestSpatialization.java create mode 100755 src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Track.java create mode 100755 src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Vec3f.java create mode 100644 src/jogl/classes/com/jogamp/openmax/OMXEventListener.java create mode 100644 src/jogl/classes/com/jogamp/openmax/OMXInstance.java delete mode 100755 src/jogl/classes/com/sun/javafx/audio/windows/waveout/Audio.java delete mode 100755 src/jogl/classes/com/sun/javafx/audio/windows/waveout/Mixer.java delete mode 100755 src/jogl/classes/com/sun/javafx/audio/windows/waveout/SoundBuffer.java delete mode 100755 src/jogl/classes/com/sun/javafx/audio/windows/waveout/TestSpatialization.java delete mode 100755 src/jogl/classes/com/sun/javafx/audio/windows/waveout/Track.java delete mode 100755 src/jogl/classes/com/sun/javafx/audio/windows/waveout/Vec3f.java delete mode 100644 src/jogl/classes/com/sun/openmax/OMXEventListener.java delete mode 100644 src/jogl/classes/com/sun/openmax/OMXInstance.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/Debug.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/GraphicsConfigurationFactoryImpl.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/InternalBufferUtil.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/LockingNativeWindowFactory.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/NWReflection.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeLibLoaderBase.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeWindowFactoryImpl.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/NullWindow.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTNativeLibLoader.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTUtil.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWT_PlatformInfo.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11JAWTWindow.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11SunJDKReflection.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/jvm/JVMUtil.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java delete mode 100644 src/nativewindow/classes/com/sun/nativewindow/impl/Debug.java delete mode 100644 src/nativewindow/classes/com/sun/nativewindow/impl/GraphicsConfigurationFactoryImpl.java delete mode 100644 src/nativewindow/classes/com/sun/nativewindow/impl/InternalBufferUtil.java delete mode 100644 src/nativewindow/classes/com/sun/nativewindow/impl/LockingNativeWindowFactory.java delete mode 100644 src/nativewindow/classes/com/sun/nativewindow/impl/NWReflection.java delete mode 100644 src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java delete mode 100644 src/nativewindow/classes/com/sun/nativewindow/impl/NativeWindowFactoryImpl.java delete mode 100644 src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java delete mode 100644 src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTNativeLibLoader.java delete mode 100644 src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java delete mode 100644 src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java delete mode 100644 src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWT_PlatformInfo.java delete mode 100644 src/nativewindow/classes/com/sun/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java delete mode 100644 src/nativewindow/classes/com/sun/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java delete mode 100644 src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11JAWTWindow.java delete mode 100644 src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11SunJDKReflection.java delete mode 100644 src/nativewindow/classes/com/sun/nativewindow/impl/jvm/JVMUtil.java delete mode 100644 src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java delete mode 100644 src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java delete mode 100644 src/nativewindow/classes/com/sun/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java create mode 100755 src/newt/classes/com/jogamp/javafx/newt/Display.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/Event.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/EventListener.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/InputEvent.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/Insets.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/KeyEvent.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/KeyListener.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/MouseEvent.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/MouseListener.java create mode 100755 src/newt/classes/com/jogamp/javafx/newt/NewtFactory.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/OffscreenWindow.java create mode 100755 src/newt/classes/com/jogamp/javafx/newt/PaintEvent.java create mode 100755 src/newt/classes/com/jogamp/javafx/newt/PaintListener.java create mode 100755 src/newt/classes/com/jogamp/javafx/newt/Screen.java create mode 100755 src/newt/classes/com/jogamp/javafx/newt/Window.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/WindowEvent.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/WindowListener.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/awt/AWTCanvas.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/awt/AWTDisplay.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/awt/AWTScreen.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/awt/AWTWindow.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/impl/Debug.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/impl/NativeLibLoader.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Display.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Screen.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Window.java create mode 100755 src/newt/classes/com/jogamp/javafx/newt/macosx/MacDisplay.java create mode 100755 src/newt/classes/com/jogamp/javafx/newt/macosx/MacScreen.java create mode 100755 src/newt/classes/com/jogamp/javafx/newt/macosx/MacWindow.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/opengl/GLWindow.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Display.java create mode 100755 src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Screen.java create mode 100755 src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Window.java create mode 100755 src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDDisplay.java create mode 100755 src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDScreen.java create mode 100755 src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDWindow.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/util/EventDispatchThread.java create mode 100644 src/newt/classes/com/jogamp/javafx/newt/util/MainThread.java create mode 100755 src/newt/classes/com/jogamp/javafx/newt/windows/WindowsDisplay.java create mode 100755 src/newt/classes/com/jogamp/javafx/newt/windows/WindowsScreen.java create mode 100755 src/newt/classes/com/jogamp/javafx/newt/windows/WindowsWindow.java create mode 100755 src/newt/classes/com/jogamp/javafx/newt/x11/X11Display.java create mode 100755 src/newt/classes/com/jogamp/javafx/newt/x11/X11Screen.java create mode 100755 src/newt/classes/com/jogamp/javafx/newt/x11/X11Window.java delete mode 100755 src/newt/classes/com/sun/javafx/newt/Display.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/Event.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/EventListener.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/InputEvent.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/Insets.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/KeyEvent.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/KeyListener.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/MouseEvent.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/MouseListener.java delete mode 100755 src/newt/classes/com/sun/javafx/newt/NewtFactory.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/OffscreenWindow.java delete mode 100755 src/newt/classes/com/sun/javafx/newt/PaintEvent.java delete mode 100755 src/newt/classes/com/sun/javafx/newt/PaintListener.java delete mode 100755 src/newt/classes/com/sun/javafx/newt/Screen.java delete mode 100755 src/newt/classes/com/sun/javafx/newt/Window.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/WindowEvent.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/WindowListener.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/awt/AWTCanvas.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/awt/AWTDisplay.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/awt/AWTScreen.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/impl/Debug.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/impl/NativeLibLoader.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/intel/gdl/Display.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/intel/gdl/Screen.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/intel/gdl/Window.java delete mode 100755 src/newt/classes/com/sun/javafx/newt/macosx/MacDisplay.java delete mode 100755 src/newt/classes/com/sun/javafx/newt/macosx/MacScreen.java delete mode 100755 src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/opengl/broadcom/egl/Display.java delete mode 100755 src/newt/classes/com/sun/javafx/newt/opengl/broadcom/egl/Screen.java delete mode 100755 src/newt/classes/com/sun/javafx/newt/opengl/broadcom/egl/Window.java delete mode 100755 src/newt/classes/com/sun/javafx/newt/opengl/kd/KDDisplay.java delete mode 100755 src/newt/classes/com/sun/javafx/newt/opengl/kd/KDScreen.java delete mode 100755 src/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/util/EventDispatchThread.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/util/MainThread.java delete mode 100755 src/newt/classes/com/sun/javafx/newt/windows/WindowsDisplay.java delete mode 100755 src/newt/classes/com/sun/javafx/newt/windows/WindowsScreen.java delete mode 100755 src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java delete mode 100755 src/newt/classes/com/sun/javafx/newt/x11/X11Display.java delete mode 100755 src/newt/classes/com/sun/javafx/newt/x11/X11Screen.java delete mode 100755 src/newt/classes/com/sun/javafx/newt/x11/X11Window.java (limited to 'src/nativewindow/classes') diff --git a/doc/wiki/FAQ.xml b/doc/wiki/FAQ.xml index 7ee1f639b..9c14bc7ce 100644 --- a/doc/wiki/FAQ.xml +++ b/doc/wiki/FAQ.xml @@ -289,13 +289,13 @@ Below you see the invocation of the ES2 RedSquare jogl-demos utilizing multiple * Single thread (Unix, Win32)
java -Djava.awt.headless=true demos.es2.RedSquare -GL2
* Single thread (MacOSX)
java -XstartOnFirstThread -Djava.awt.headless=true demos.es2.RedSquare -GL2
* Multiple threads & windows (Unix, Win32)
java -Djava.awt.headless=true demos.es2.RedSquare -GL2 -GL2 -GL2 -GL2
-* Multiple threads & windows (MacOSX)
java -XstartOnFirstThread -Djava.awt.headless=true com.sun.javafx.newt.util.MainThread demos.es2.RedSquare -GL2 -GL2 -GL2 -GL2
+* Multiple threads & windows (MacOSX)
java -XstartOnFirstThread -Djava.awt.headless=true com.jogamp.javafx.newt.util.MainThread demos.es2.RedSquare -GL2 -GL2 -GL2 -GL2
-The serialization of the main Java class through ''com.sun.javafx.newt.util.MainThread'' +The serialization of the main Java class through ''com.jogamp.javafx.newt.util.MainThread'' may be used for all platforms, since it only takes effect on ''MacOSX''. This allows you an almost platform independent invocation of your multithreaded Java applications. -On ''MacOSX'', ''com.sun.javafx.newt.util.MainThread'' will occupy the main thread and +On ''MacOSX'', ''com.jogamp.javafx.newt.util.MainThread'' will occupy the main thread and serializes all native window related tasks through it. This mechanism is thread safe utilizes reentrant locking. diff --git a/doxygen/doxygen-all-dev.cfg b/doxygen/doxygen-all-dev.cfg index 2425ff403..d047e7182 100644 --- a/doxygen/doxygen-all-dev.cfg +++ b/doxygen/doxygen-all-dev.cfg @@ -465,7 +465,7 @@ INPUT = ../src/newt/classes INPUT += ../build/jogl/gensrc/classes INPUT += ../build/nativewindow/gensrc/classes INPUT += ../build/newt/gensrc/classes -INPUT += ../../gluegen/src/java/com/sun/gluegen/runtime +INPUT += ../../gluegen/src/java/com/jogamp/gluegen/runtime # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp diff --git a/doxygen/doxygen-all-pub.cfg b/doxygen/doxygen-all-pub.cfg index 3cac3e651..a7f4711df 100644 --- a/doxygen/doxygen-all-pub.cfg +++ b/doxygen/doxygen-all-pub.cfg @@ -462,7 +462,7 @@ WARN_LOGFILE = INPUT = ../src/jogl/classes/javax INPUT += ../build-x86_64/jogl/gensrc/classes/javax INPUT += ../src/jogl/classes/com/jogamp/opengl/util -INPUT += ../src/newt/classes/com/sun/javafx/newt +INPUT += ../src/newt/classes/com/jogamp/javafx/newt # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp diff --git a/make/build-jogl.xml b/make/build-jogl.xml index 80b106467..c3bc96bd8 100644 --- a/make/build-jogl.xml +++ b/make/build-jogl.xml @@ -114,7 +114,7 @@ value="com/jogamp/opengl/impl/glu/gl2/** com/jogamp/opengl/impl/glu/nurbs/** com/jogamp/opengl/impl/glu/registry/** javax/media/opengl/glu/gl2/**"/> + value="com/jogamp/openmax/**"/> @@ -191,10 +191,10 @@ + value="com.jogamp.opengl.impl.gl2.fixme.*,com.jogamp.javafx.audio.windows.waveout.TestSpatialization"/> + value="com/jogamp/opengl/impl/gl2/fixme/** com/jogamp/javafx/audio/windows/waveout/TestSpatialization.java" /> @@ -1465,7 +1465,7 @@ - + @@ -1484,7 +1484,7 @@ - + @@ -1497,7 +1497,7 @@ - + @@ -1507,7 +1507,7 @@ - + @@ -1584,13 +1584,13 @@ - + - + @@ -1822,11 +1822,11 @@ - + - + @@ -1835,7 +1835,7 @@ + value="javax/media/nativewindow/*, javax/media/nativewindow/egl/*, javax/media/nativewindow/macosx/*, javax/media/nativewindow/windows/*, com/jogamp/nativewindow/impl/*, com/jogamp/nativewindow/impl/jvm/*"/> + value="javax/media/nativewindow/awt/*, com/jogamp/nativewindow/impl/jawt/**, com/jogamp/nativewindow/impl/**/awt/**"/> + value="com/jogamp/nativewindow/impl/x11/** javax/media/nativewindow/x11/*" /> @@ -257,7 +257,7 @@ - + @@ -320,13 +320,13 @@ + targetfile="${src.generated.java}/com/jogamp/nativewindow/impl/x11/X11Lib.java"> + targetfile="${src.generated.java}/com/jogamp/nativewindow/impl/jawt/JAWT.java"> @@ -353,7 +353,7 @@ + includes="com/jogamp/nativewindow/impl/x11/**" /> @@ -373,7 +373,7 @@ + includes="com/jogamp/nativewindow/impl/jawt/**" /> @@ -851,8 +851,8 @@ - - + + @@ -861,8 +861,8 @@ - - + + diff --git a/make/build-newt.xml b/make/build-newt.xml index df5783319..0bbcf2ccd 100644 --- a/make/build-newt.xml +++ b/make/build-newt.xml @@ -108,25 +108,25 @@ + value="com/jogamp/javafx/newt/*, com/jogamp/javafx/newt/util/*, com/jogamp/javafx/newt/impl/*, com/jogamp/javafx/newt/intel/gdl/*"/> + value="com/jogamp/javafx/newt/x11/*"/> + value="com/jogamp/javafx/newt/windows/*"/> + value="com/jogamp/javafx/newt/macosx/*"/> + value="com/jogamp/javafx/newt/opengl/*, com/jogamp/javafx/newt/opengl/kd/*"/> + value="com/jogamp/javafx/newt/opengl/broadcom/egl/*"/> + value="com/jogamp/javafx/newt/awt/*"/> @@ -279,11 +279,11 @@ - + - + @@ -596,23 +596,23 @@ - + - - - + + + - + - - - + + + @@ -759,14 +759,14 @@ + includes="com/jogamp/javafx/newt/**" /> @@ -774,7 +774,7 @@ diff --git a/make/build-staticglgen.xml b/make/build-staticglgen.xml index 9ef1147a3..2683b305a 100644 --- a/make/build-staticglgen.xml +++ b/make/build-staticglgen.xml @@ -17,7 +17,7 @@ --> - + diff --git a/make/build.xml b/make/build.xml index cd3ee2ab9..e73235cac 100644 --- a/make/build.xml +++ b/make/build.xml @@ -43,12 +43,12 @@ - + - + - + diff --git a/make/config/jogl/glu-common.cfg b/make/config/jogl/glu-common.cfg index 28a075954..8fd053da1 100644 --- a/make/config/jogl/glu-common.cfg +++ b/make/config/jogl/glu-common.cfg @@ -15,7 +15,7 @@ Import javax.media.opengl.glu.* Import com.jogamp.opengl.impl.* Import com.jogamp.opengl.impl.glu.* Import com.jogamp.opengl.impl.glu.tessellator.GLUtessellatorImpl -Import com.sun.nativewindow.impl.NWReflection +Import com.jogamp.nativewindow.impl.NWReflection # Raise GLException instead of RuntimeException in glue code RuntimeExceptionType GLException diff --git a/make/config/jogl/glx-x11.cfg b/make/config/jogl/glx-x11.cfg index 8814f5e2f..bbe805a04 100644 --- a/make/config/jogl/glx-x11.cfg +++ b/make/config/jogl/glx-x11.cfg @@ -19,7 +19,7 @@ GetProcAddressTableExpr glxProcAddressTable # This must be present for bootstrapping SkipProcAddressGen glXGetProcAddressARB -Import com.sun.nativewindow.impl.x11.* +Import com.jogamp.nativewindow.impl.x11.* CustomJavaCode GLX private static GLXProcAddressTable glxProcAddressTable = new GLXProcAddressTable(); diff --git a/make/config/jogl/glxext.cfg b/make/config/jogl/glxext.cfg index f07d5cc1b..1dfc8fccd 100755 --- a/make/config/jogl/glxext.cfg +++ b/make/config/jogl/glxext.cfg @@ -20,7 +20,7 @@ EmitProcAddressTable true ProcAddressTableClassName GLXExtProcAddressTable GetProcAddressTableExpr _context.getGLXExtProcAddressTable() -Import com.sun.nativewindow.impl.x11.* +Import com.jogamp.nativewindow.impl.x11.* # Ignore everything that doesn't start with glX or GLX IgnoreNot ^(glX|GLX).+ diff --git a/make/config/nativewindow/jawt-DrawingSurfaceInfo-CustomJavaCode.java b/make/config/nativewindow/jawt-DrawingSurfaceInfo-CustomJavaCode.java index dab377ad4..aad0ab261 100755 --- a/make/config/nativewindow/jawt-DrawingSurfaceInfo-CustomJavaCode.java +++ b/make/config/nativewindow/jawt-DrawingSurfaceInfo-CustomJavaCode.java @@ -16,12 +16,12 @@ private static JAWT_PlatformInfo newPlatformInfo(ByteBuffer buf) { try { Class factoryClass; if (osName.startsWith("wind")) { - factoryClass = Class.forName("com.sun.nativewindow.impl.jawt.windows.JAWT_Win32DrawingSurfaceInfo"); + factoryClass = Class.forName("com.jogamp.nativewindow.impl.jawt.windows.JAWT_Win32DrawingSurfaceInfo"); } else if (osName.startsWith("mac os x")) { - factoryClass = Class.forName("com.sun.nativewindow.impl.jawt.macosx.JAWT_MacOSXDrawingSurfaceInfo"); + factoryClass = Class.forName("com.jogamp.nativewindow.impl.jawt.macosx.JAWT_MacOSXDrawingSurfaceInfo"); } else { // Assume Linux, Solaris, etc. Should probably test for these explicitly. - factoryClass = Class.forName("com.sun.nativewindow.impl.jawt.x11.JAWT_X11DrawingSurfaceInfo"); + factoryClass = Class.forName("com.jogamp.nativewindow.impl.jawt.x11.JAWT_X11DrawingSurfaceInfo"); } platformInfoFactoryMethod = factoryClass.getMethod("create", new Class[] { ByteBuffer.class }); diff --git a/make/config/nativewindow/jawt-macosx.cfg b/make/config/nativewindow/jawt-macosx.cfg index b047ecdff..dea1a27b7 100644 --- a/make/config/nativewindow/jawt-macosx.cfg +++ b/make/config/nativewindow/jawt-macosx.cfg @@ -1,7 +1,7 @@ # This .cfg file is used to generate the interface to the JAWT, which # is used by the MacOSXOnscreenGLContext. Style AllStatic -Package com.sun.nativewindow.impl.jawt +Package com.jogamp.nativewindow.impl.jawt JavaClass JAWTFactory JavaOutputDir gensrc/classes NativeOutputDir gensrc/native/MacOSX @@ -22,8 +22,8 @@ CustomCCode #include CustomCCode #include import java.security.* -import com.sun.nativewindow.impl.jawt.* -StructPackage JAWT_MacOSXDrawingSurfaceInfo com.sun.nativewindow.impl.jawt.macosx +import com.jogamp.nativewindow.impl.jawt.* +StructPackage JAWT_MacOSXDrawingSurfaceInfo com.jogamp.nativewindow.impl.jawt.macosx EmitStruct JAWT_MacOSXDrawingSurfaceInfo Implements JAWT_MacOSXDrawingSurfaceInfo JAWT_PlatformInfo diff --git a/make/config/nativewindow/jawt-win32.cfg b/make/config/nativewindow/jawt-win32.cfg index e7754843e..af0c7ce29 100644 --- a/make/config/nativewindow/jawt-win32.cfg +++ b/make/config/nativewindow/jawt-win32.cfg @@ -1,7 +1,7 @@ # This .cfg file is used to generate the interface to the JAWT, which # is used by the WindowsOnscreenGLContext. Style AllStatic -Package com.sun.nativewindow.impl.jawt +Package com.jogamp.nativewindow.impl.jawt JavaClass JAWTFactory JavaOutputDir gensrc/classes NativeOutputDir gensrc/native/Windows @@ -22,8 +22,8 @@ CustomCCode #include Include ../intptr.cfg import java.security.* -import com.sun.nativewindow.impl.jawt.* -StructPackage JAWT_Win32DrawingSurfaceInfo com.sun.nativewindow.impl.jawt.windows +import com.jogamp.nativewindow.impl.jawt.* +StructPackage JAWT_Win32DrawingSurfaceInfo com.jogamp.nativewindow.impl.jawt.windows EmitStruct JAWT_Win32DrawingSurfaceInfo Implements JAWT_Win32DrawingSurfaceInfo JAWT_PlatformInfo diff --git a/make/config/nativewindow/jawt-x11.cfg b/make/config/nativewindow/jawt-x11.cfg index 25df57a1f..ccfe009dd 100644 --- a/make/config/nativewindow/jawt-x11.cfg +++ b/make/config/nativewindow/jawt-x11.cfg @@ -1,7 +1,7 @@ # This .cfg file is used to generate the interface to the JAWT, which # is used by the X11OnscreenGLContext. Style AllStatic -Package com.sun.nativewindow.impl.jawt +Package com.jogamp.nativewindow.impl.jawt JavaClass JAWTFactory JavaOutputDir gensrc/classes NativeOutputDir gensrc/native/X11 @@ -22,8 +22,8 @@ CustomCCode #include CustomCCode #include import java.security.* -import com.sun.nativewindow.impl.jawt.* -StructPackage JAWT_X11DrawingSurfaceInfo com.sun.nativewindow.impl.jawt.x11 +import com.jogamp.nativewindow.impl.jawt.* +StructPackage JAWT_X11DrawingSurfaceInfo com.jogamp.nativewindow.impl.jawt.x11 EmitStruct JAWT_X11DrawingSurfaceInfo Implements JAWT_X11DrawingSurfaceInfo JAWT_PlatformInfo diff --git a/make/config/nativewindow/x11-CustomCCode.c b/make/config/nativewindow/x11-CustomCCode.c index c1f66fee1..8eded9aa2 100755 --- a/make/config/nativewindow/x11-CustomCCode.c +++ b/make/config/nativewindow/x11-CustomCCode.c @@ -48,22 +48,22 @@ Bool XF86VidModeSetGammaRamp( /* Need to expose DefaultScreen and RootWindow macros to Java */ JNIEXPORT jlong JNICALL -Java_com_sun_nativewindow_impl_x11_X11Lib_DefaultScreen(JNIEnv *env, jclass _unused, jlong display) { +Java_com_jogamp_nativewindow_impl_x11_X11Lib_DefaultScreen(JNIEnv *env, jclass _unused, jlong display) { return DefaultScreen((Display*) (intptr_t) display); } JNIEXPORT jlong JNICALL -Java_com_sun_nativewindow_impl_x11_X11Lib_DefaultVisualID(JNIEnv *env, jclass _unused, jlong display, jint screen) { +Java_com_jogamp_nativewindow_impl_x11_X11Lib_DefaultVisualID(JNIEnv *env, jclass _unused, jlong display, jint screen) { return (jlong) XVisualIDFromVisual( DefaultVisual( (Display*) (intptr_t) display, screen ) ); } JNIEXPORT jlong JNICALL -Java_com_sun_nativewindow_impl_x11_X11Lib_RootWindow(JNIEnv *env, jclass _unused, jlong display, jint screen) { +Java_com_jogamp_nativewindow_impl_x11_X11Lib_RootWindow(JNIEnv *env, jclass _unused, jlong display, jint screen) { return RootWindow((Display*) (intptr_t) display, screen); } JNIEXPORT jlong JNICALL -Java_com_sun_nativewindow_impl_x11_X11Lib_dlopen(JNIEnv *env, jclass _unused, jstring name) { +Java_com_jogamp_nativewindow_impl_x11_X11Lib_dlopen(JNIEnv *env, jclass _unused, jstring name) { const jbyte* chars; void* res; chars = (*env)->GetStringUTFChars(env, name, NULL); @@ -73,7 +73,7 @@ Java_com_sun_nativewindow_impl_x11_X11Lib_dlopen(JNIEnv *env, jclass _unused, js } JNIEXPORT jlong JNICALL -Java_com_sun_nativewindow_impl_x11_X11Lib_dlsym(JNIEnv *env, jclass _unused, jstring name) { +Java_com_jogamp_nativewindow_impl_x11_X11Lib_dlsym(JNIEnv *env, jclass _unused, jstring name) { const jbyte* chars; void* res; chars = (*env)->GetStringUTFChars(env, name, NULL); @@ -85,7 +85,7 @@ Java_com_sun_nativewindow_impl_x11_X11Lib_dlsym(JNIEnv *env, jclass _unused, jst /* Need to pull this in as we don't have a stub header for it */ extern Bool XineramaEnabled(Display* display); -static const char * clazzNameInternalBufferUtil = "com/sun/nativewindow/impl/InternalBufferUtil"; +static const char * clazzNameInternalBufferUtil = "com/jogamp/nativewindow/impl/InternalBufferUtil"; static const char * clazzNameInternalBufferUtilStaticCstrName = "copyByteBuffer"; static const char * clazzNameInternalBufferUtilStaticCstrSignature = "(Ljava/nio/ByteBuffer;)Ljava/nio/ByteBuffer;"; static const char * clazzNameByteBuffer = "java/nio/ByteBuffer"; @@ -100,29 +100,29 @@ static void _initClazzAccess(JNIEnv *env) { c = (*env)->FindClass(env, clazzNameInternalBufferUtil); if(NULL==c) { - fprintf(stderr, "FatalError: Java_com_sun_nativewindow_impl_x11_X11Lib: can't find %s\n", clazzNameInternalBufferUtil); + fprintf(stderr, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s\n", clazzNameInternalBufferUtil); (*env)->FatalError(env, clazzNameInternalBufferUtil); } clazzInternalBufferUtil = (jclass)(*env)->NewGlobalRef(env, c); if(NULL==clazzInternalBufferUtil) { - fprintf(stderr, "FatalError: Java_com_sun_nativewindow_impl_x11_X11Lib: can't use %s\n", clazzNameInternalBufferUtil); + fprintf(stderr, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s\n", clazzNameInternalBufferUtil); (*env)->FatalError(env, clazzNameInternalBufferUtil); } c = (*env)->FindClass(env, clazzNameByteBuffer); if(NULL==c) { - fprintf(stderr, "FatalError: Java_com_sun_nativewindow_impl_x11_X11Lib: can't find %s\n", clazzNameByteBuffer); + fprintf(stderr, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s\n", clazzNameByteBuffer); (*env)->FatalError(env, clazzNameByteBuffer); } clazzByteBuffer = (jclass)(*env)->NewGlobalRef(env, c); if(NULL==c) { - fprintf(stderr, "FatalError: Java_com_sun_nativewindow_impl_x11_X11Lib: can't use %s\n", clazzNameByteBuffer); + fprintf(stderr, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s\n", clazzNameByteBuffer); (*env)->FatalError(env, clazzNameByteBuffer); } cstrInternalBufferUtil = (*env)->GetStaticMethodID(env, clazzInternalBufferUtil, clazzNameInternalBufferUtilStaticCstrName, clazzNameInternalBufferUtilStaticCstrSignature); if(NULL==cstrInternalBufferUtil) { - fprintf(stderr, "FatalError: Java_com_sun_nativewindow_impl_x11_X11Lib:: can't create %s.%s %s\n", + fprintf(stderr, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib:: can't create %s.%s %s\n", clazzNameInternalBufferUtil, clazzNameInternalBufferUtilStaticCstrName, clazzNameInternalBufferUtilStaticCstrSignature); (*env)->FatalError(env, clazzNameInternalBufferUtilStaticCstrName); @@ -130,12 +130,12 @@ static void _initClazzAccess(JNIEnv *env) { } /* Java->C glue code: - * Java package: com.sun.nativewindow.impl.x11.X11Lib + * Java package: com.jogamp.nativewindow.impl.x11.X11Lib * Java method: XVisualInfo XGetVisualInfo(long arg0, long arg1, XVisualInfo arg2, java.nio.IntBuffer arg3) * C function: XVisualInfo * XGetVisualInfo(Display * , long, XVisualInfo * , int * ); */ JNIEXPORT jobject JNICALL -Java_com_sun_nativewindow_impl_x11_X11Lib_XGetVisualInfoCopied1__JJLjava_nio_ByteBuffer_2Ljava_lang_Object_2I(JNIEnv *env, jclass _unused, jlong arg0, jlong arg1, jobject arg2, jobject arg3, jint arg3_byte_offset) { +Java_com_jogamp_nativewindow_impl_x11_X11Lib_XGetVisualInfoCopied1__JJLjava_nio_ByteBuffer_2Ljava_lang_Object_2I(JNIEnv *env, jclass _unused, jlong arg0, jlong arg1, jobject arg2, jobject arg3, jint arg3_byte_offset) { XVisualInfo * _ptr2 = NULL; int * _ptr3 = NULL; XVisualInfo * _res; diff --git a/make/config/nativewindow/x11-lib.cfg b/make/config/nativewindow/x11-lib.cfg index 321444725..7a64307da 100644 --- a/make/config/nativewindow/x11-lib.cfg +++ b/make/config/nativewindow/x11-lib.cfg @@ -1,6 +1,6 @@ # This .cfg file is used to generate the interface to the GLX routines # used internally by the X11GLContext implementation. -Package com.sun.nativewindow.impl.x11 +Package com.jogamp.nativewindow.impl.x11 JavaClass X11Lib Style allstatic diff --git a/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Audio.java b/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Audio.java new file mode 100755 index 000000000..fe77c7c48 --- /dev/null +++ b/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Audio.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + */ + +package com.jogamp.javafx.audio.windows.waveout; + +import java.io.*; + +public class Audio { + private static Audio instance = null; + private Mixer mixer; + + public synchronized static Audio getInstance() { + if (instance == null) { + instance = new Audio(); + } + return instance; + } + + private Audio() { + mixer = Mixer.getMixer(); + } + + public Mixer getMixer() { + return mixer; + } + + public Track newTrack(File file) throws IOException + { + Track res = new Track(file); + mixer.add(res); + return res; + } + + public void shutdown() { + mixer.shutdown(); + } +} diff --git a/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Mixer.java b/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Mixer.java new file mode 100755 index 000000000..59877052f --- /dev/null +++ b/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Mixer.java @@ -0,0 +1,362 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + */ + +package com.jogamp.javafx.audio.windows.waveout; + +import java.io.*; +import java.nio.*; +import java.util.*; + +// Needed only for NIO workarounds on CVM +import java.lang.reflect.*; + +public class Mixer { + // This class is a singleton + private static Mixer mixer; + + private volatile boolean shutdown; + private volatile Object shutdownLock = new Object(); + private volatile boolean shutdownDone; + + // Windows Event object + private long event; + + private volatile ArrayList/**/ tracks = new ArrayList(); + + private Vec3f leftSpeakerPosition = new Vec3f(-1, 0, 0); + private Vec3f rightSpeakerPosition = new Vec3f( 1, 0, 0); + + private float falloffFactor = 1.0f; + + static { + mixer = new Mixer(); + } + + private Mixer() { + event = CreateEvent(); + new FillerThread().start(); + MixerThread m = new MixerThread(); + m.setPriority(Thread.MAX_PRIORITY - 1); + m.start(); + } + + public static Mixer getMixer() { + return mixer; + } + + synchronized void add(Track track) { + ArrayList/**/ newTracks = (ArrayList) tracks.clone(); + newTracks.add(track); + tracks = newTracks; + } + + synchronized void remove(Track track) { + ArrayList/**/ newTracks = (ArrayList) tracks.clone(); + newTracks.remove(track); + tracks = newTracks; + } + + // NOTE: due to a bug on the APX device, we only have mono sounds, + // so we currently only pay attention to the position of the left + // speaker + public void setLeftSpeakerPosition(float x, float y, float z) { + leftSpeakerPosition.set(x, y, z); + } + + // NOTE: due to a bug on the APX device, we only have mono sounds, + // so we currently only pay attention to the position of the left + // speaker + public void setRightSpeakerPosition(float x, float y, float z) { + rightSpeakerPosition.set(x, y, z); + } + + /** This defines a scale factor of sorts -- the higher the number, + the larger an area the sound will affect. Default value is + 1.0f. Valid values are [1.0f, ...]. The formula for the gain + for each channel is +
+     falloffFactor
+  -------------------
+  falloffFactor + r^2
+
+*/ + public void setFalloffFactor(float factor) { + falloffFactor = factor; + } + + public void shutdown() { + synchronized(shutdownLock) { + shutdown = true; + SetEvent(event); + try { + shutdownLock.wait(); + } catch (InterruptedException e) { + } + } + } + + class FillerThread extends Thread { + FillerThread() { + super("Mixer Thread"); + } + + public void run() { + while (!shutdown) { + List/**/ curTracks = tracks; + + for (Iterator iter = curTracks.iterator(); iter.hasNext(); ) { + Track track = (Track) iter.next(); + try { + track.fill(); + } catch (IOException e) { + e.printStackTrace(); + remove(track); + } + } + + try { + // Run ten times per second + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + + class MixerThread extends Thread { + // Temporary mixing buffer + // Interleaved left and right channels + float[] mixingBuffer; + private Vec3f temp = new Vec3f(); + + MixerThread() { + super("Mixer Thread"); + if (!initializeWaveOut(event)) { + throw new InternalError("Error initializing waveout device"); + } + } + + public void run() { + while (!shutdown) { + // Get the next buffer + long mixerBuffer = getNextMixerBuffer(); + if (mixerBuffer != 0) { + ByteBuffer buf = getMixerBufferData(mixerBuffer); + + if (buf == null) { + // This is happening on CVM because + // JNI_NewDirectByteBuffer isn't implemented + // by default and isn't compatible with the + // JSR-239 NIO implementation (apparently) + buf = newDirectByteBuffer(getMixerBufferDataAddress(mixerBuffer), + getMixerBufferDataCapacity(mixerBuffer)); + } + + if (buf == null) { + throw new InternalError("Couldn't wrap the native address with a direct byte buffer"); + } + + // System.out.println("Mixing buffer"); + + // If we don't have enough samples in our mixing buffer, expand it + // FIXME: knowledge of native output rendering format + if ((mixingBuffer == null) || (mixingBuffer.length < (buf.capacity() / 2 /* bytes / sample */))) { + mixingBuffer = new float[buf.capacity() / 2]; + } else { + // Zap it + for (int i = 0; i < mixingBuffer.length; i++) { + mixingBuffer[i] = 0.0f; + } + } + + // This assertion should be in place if we have stereo + if ((mixingBuffer.length % 2) != 0) { + String msg = "FATAL ERROR: odd number of samples in the mixing buffer"; + System.out.println(msg); + throw new InternalError(msg); + } + + // Run down all of the registered tracks mixing them in + List/**/ curTracks = tracks; + + for (Iterator iter = curTracks.iterator(); iter.hasNext(); ) { + Track track = (Track) iter.next(); + // Consider only playing tracks + if (track.isPlaying()) { + // First recompute its gain + Vec3f pos = track.getPosition(); + float leftGain = gain(pos, leftSpeakerPosition); + float rightGain = gain(pos, rightSpeakerPosition); + // Now mix it in + int i = 0; + while (i < mixingBuffer.length) { + if (track.hasNextSample()) { + float sample = track.nextSample(); + mixingBuffer[i++] = sample * leftGain; + mixingBuffer[i++] = sample * rightGain; + } else { + // This allows tracks to stall without being abruptly cancelled + if (track.done()) { + remove(track); + } + break; + } + } + } + } + + // Now that we have our data, send it down to the card + int outPos = 0; + for (int i = 0; i < mixingBuffer.length; i++) { + short val = (short) mixingBuffer[i]; + buf.put(outPos++, (byte) val); + buf.put(outPos++, (byte) (val >> 8)); + } + if (!prepareMixerBuffer(mixerBuffer)) { + throw new RuntimeException("Error preparing mixer buffer"); + } + if (!writeMixerBuffer(mixerBuffer)) { + throw new RuntimeException("Error writing mixer buffer to device"); + } + } else { + // System.out.println("No mixer buffer available"); + + // Wait for a buffer to become available + if (!WaitForSingleObject(event)) { + throw new RuntimeException("Error while waiting for event object"); + } + + /* + try { + Thread.sleep(10); + } catch (InterruptedException e) { + } + */ + } + } + + // Need to shut down + shutdownWaveOut(); + synchronized(shutdownLock) { + shutdownLock.notifyAll(); + } + } + + // This defines the 3D spatialization gain function. + // The function is defined as: + // falloffFactor + // ------------------- + // falloffFactor + r^2 + private float gain(Vec3f pos, Vec3f speakerPos) { + temp.sub(pos, speakerPos); + float dotp = temp.dot(temp); + return (falloffFactor / (falloffFactor + dotp)); + } + } + + // Initializes waveout device + private static native boolean initializeWaveOut(long eventObject); + // Shuts down waveout device + private static native void shutdownWaveOut(); + + // Gets the next (opaque) buffer of data to fill from the native + // code, or 0 if none was available yet (it should not happen that + // none is available the way the code is written). + private static native long getNextMixerBuffer(); + // Gets the next ByteBuffer to fill out of the mixer buffer. It + // requires interleaved left and right channel samples, 16 signed + // bits per sample, little endian. Implicit 44.1 kHz sample rate. + private static native ByteBuffer getMixerBufferData(long mixerBuffer); + // We need these to work around the lack of + // JNI_NewDirectByteBuffer in CVM + the JSR 239 NIO classes + private static native long getMixerBufferDataAddress(long mixerBuffer); + private static native int getMixerBufferDataCapacity(long mixerBuffer); + // Prepares this mixer buffer for writing to the device. + private static native boolean prepareMixerBuffer(long mixerBuffer); + // Writes this mixer buffer to the device. + private static native boolean writeMixerBuffer(long mixerBuffer); + + // Helpers to prevent mixer thread from busy waiting + private static native long CreateEvent(); + private static native boolean WaitForSingleObject(long event); + private static native void SetEvent(long event); + private static native void CloseHandle(long handle); + + // We need a reflective hack to wrap a direct ByteBuffer around + // the native memory because JNI_NewDirectByteBuffer doesn't work + // in CVM + JSR-239 NIO + private static Class directByteBufferClass; + private static Constructor directByteBufferConstructor; + private static Map createdBuffers = new HashMap(); // Map Long, ByteBuffer + + private static ByteBuffer newDirectByteBuffer(long address, long capacity) { + Long key = new Long(address); + ByteBuffer buf = (ByteBuffer) createdBuffers.get(key); + if (buf == null) { + buf = newDirectByteBufferImpl(address, capacity); + if (buf != null) { + createdBuffers.put(key, buf); + } + } + return buf; + } + private static ByteBuffer newDirectByteBufferImpl(long address, long capacity) { + if (directByteBufferClass == null) { + try { + directByteBufferClass = Class.forName("java.nio.DirectByteBuffer"); + byte[] tmp = new byte[0]; + directByteBufferConstructor = + directByteBufferClass.getDeclaredConstructor(new Class[] { Integer.TYPE, + tmp.getClass(), + Integer.TYPE }); + directByteBufferConstructor.setAccessible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + + if (directByteBufferConstructor != null) { + try { + return (ByteBuffer) + directByteBufferConstructor.newInstance(new Object[] { + new Integer((int) capacity), + null, + new Integer((int) address) + }); + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } +} diff --git a/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/SoundBuffer.java b/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/SoundBuffer.java new file mode 100755 index 000000000..6b75450eb --- /dev/null +++ b/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/SoundBuffer.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + */ + +package com.jogamp.javafx.audio.windows.waveout; + +import java.io.*; + +class SoundBuffer { + private byte[] data; + private boolean needsByteSwap; + private int numBytes; + private int bytesPerSample; + private int numSamples; + private boolean playing; + private boolean empty; + + // Note: needsByteSwap argument makes assumptions about the format + SoundBuffer(int size, int bytesPerSample, boolean needsByteSwap) { + this.bytesPerSample = bytesPerSample; + this.needsByteSwap = needsByteSwap; + data = new byte[size * bytesPerSample]; + empty = true; + } + + boolean playing() { + return playing; + } + + void playing(boolean playing) { + this.playing = playing; + } + + boolean empty() { + return empty; + } + + void empty(boolean empty) { + this.empty = empty; + } + + void fill(InputStream input) throws IOException { + synchronized(this) { + if (playing) { + throw new IllegalStateException("Can not fill a buffer that is playing"); + } + } + + empty(true); + int num = input.read(data); + if (num > 0) { + numBytes = num; + numSamples = numBytes / bytesPerSample; + empty(false); + if ((numBytes % bytesPerSample) != 0) { + System.out.println("WARNING: needed integral multiple of " + bytesPerSample + + " bytes, but read " + numBytes + " bytes"); + } + } else { + numBytes = 0; + } + } + + int numSamples() { + return numSamples; + } + + // This is called by the mixer and must be extremely fast + // FIXME: may want to reconsider use of floating point at this point + // FIXME: assumes all sounds are of the same format to avoid normalization + float getSample(int sample) { + int startByte = sample * bytesPerSample; + // FIXME: assumes no more than 4 bytes per sample + int res = 0; + if (needsByteSwap) { + for (int i = startByte + bytesPerSample - 1; i >= startByte; i--) { + res <<= 8; + res |= (data[i] & 0xff); + } + } else { + int endByte = startByte + bytesPerSample - 1; + for (int i = startByte; i <= endByte; i++) { + res <<= 8; + res |= (data[i] & 0xff); + } + } + // Sign extend + if (bytesPerSample == 2) { + res = (short) res; + } else if (bytesPerSample == 1) { + res = (byte) res; + } + + return (float) res; + } +} diff --git a/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/TestSpatialization.java b/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/TestSpatialization.java new file mode 100755 index 000000000..38e3bb808 --- /dev/null +++ b/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/TestSpatialization.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + */ + +package com.jogamp.javafx.audio.windows.waveout; + +import java.io.*; +import javax.media.nativewindow.NativeWindow; +import javax.media.opengl.GLDrawableFactory; + +public class TestSpatialization { + public static void main(String[] args) { + if (args.length != 1) { + System.out.println("Usage: TestSpatialization [file name]"); + System.exit(1); + } + + try { + // FIXME: this is a hack to get the native library loaded + try { + GLDrawableFactory.getFactory(NativeWindow.class); + } catch (Exception e) {} + // Initialize the audio subsystem + Audio audio = Audio.getInstance(); + // Create a track + Track track = audio.newTrack(new File(args[0])); + track.setPosition(1, 0, 0); + // Run for ten seconds + long startTime = System.currentTimeMillis(); + long duration = 10000; + long curTime = 0; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + } + System.out.println("Playing..."); + track.setLooping(true); + track.play(); + while ((curTime = System.currentTimeMillis()) < startTime + duration) { + // Make one revolution every two seconds + float rads = (float) (((2 * Math.PI) * (((float) (curTime - startTime)) / 1000.0f)) / 2); + track.setPosition((float) Math.cos(rads), 0, (float) Math.sin(rads)); + // Would like to make it go in a circle, but since + // stereo doesn't work now, make it move along a line + // track.setPosition(-1.0f, 0, 2.0f * (float) Math.sin(rads)); + // Sleep a little between updates + try { + Thread.sleep(10); + } catch (InterruptedException e) { + } + } + System.out.println("Shutting down audio subsystem"); + audio.shutdown(); + System.out.println("Exiting."); + System.exit(0); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } +} diff --git a/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Track.java b/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Track.java new file mode 100755 index 000000000..40c39e755 --- /dev/null +++ b/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Track.java @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + */ + +package com.jogamp.javafx.audio.windows.waveout; + +import java.io.*; +import java.nio.*; + +public class Track { + // Default number of samples per buffer + private static final int BUFFER_SIZE = 32768; + // Number of bytes per sample (FIXME: dependence on audio format) + static final int BYTES_PER_SAMPLE = 2; + // Whether we need byte swapping (FIXME: dependence on audio format) + static final boolean NEEDS_BYTE_SWAP = true; + + // This is the buffer this track is currently playing from + private SoundBuffer activeBuffer; + // This is the sample position in the active buffer + private int samplePosition; + // This is the total number of samples in the file + private int totalSamples; + // This is the total number of samples we have read + private int samplesRead; + // This is the buffer that the background filler thread may be filling + private SoundBuffer fillingBuffer; + // If we're playing the file, this is its input stream + private InputStream input; + // Keep around the file name + private File file; + // Whether we're playing this sound + private boolean playing; + // Whether we're looping this sound + private boolean looping; + // The position of this sound; defaults to being at the origin + private volatile Vec3f position = new Vec3f(); + + Track(File file) throws IOException { + if (!file.getName().endsWith(".rawsound")) { + throw new IOException("Unsupported file format (currently supports only raw sounds)"); + } + + this.file = file; + openInput(); + + // Allocate the buffers + activeBuffer = new SoundBuffer(BUFFER_SIZE, BYTES_PER_SAMPLE, NEEDS_BYTE_SWAP); + fillingBuffer = new SoundBuffer(BUFFER_SIZE, BYTES_PER_SAMPLE, NEEDS_BYTE_SWAP); + + // Fill the first buffer immediately + fill(); + swapBuffers(); + } + + private void openInput() throws IOException { + input = new BufferedInputStream(new FileInputStream(file)); + totalSamples = (int) file.length() / BYTES_PER_SAMPLE; + } + + public File getFile() { + return file; + } + + public synchronized void play() { + if (input == null) { + try { + openInput(); + // Fill it immediately + fill(); + } catch (IOException e) { + e.printStackTrace(); + return; + } + } + + playing = true; + } + + public synchronized boolean isPlaying() { + return playing; + } + + public synchronized void setLooping(boolean looping) { + this.looping = looping; + } + + public synchronized boolean isLooping() { + return looping; + } + + public void setPosition(float x, float y, float z) { + position = new Vec3f(x, y, z); + } + + synchronized void fill() throws IOException { + if (input == null) { + return; + } + SoundBuffer curBuffer = fillingBuffer; + if (!curBuffer.empty()) { + return; + } + curBuffer.fill(input); + if (curBuffer.empty()) { + // End of file + InputStream tmp = null; + synchronized(this) { + tmp = input; + input = null; + } + tmp.close(); + + // If looping, re-open + if (isLooping()) { + openInput(); + // and fill + fill(); + } + } + } + + // These are only for use by the Mixer + private float leftGain; + private float rightGain; + + void setLeftGain(float leftGain) { + this.leftGain = leftGain; + } + + float getLeftGain() { + return leftGain; + } + + void setRightGain(float rightGain) { + this.rightGain = rightGain; + } + + float getRightGain() { + return rightGain; + } + + Vec3f getPosition() { + return position; + } + + // This is called by the mixer and must be extremely fast + // Note this assumes mono sounds (FIXME) + boolean hasNextSample() { + return (!activeBuffer.empty() && samplePosition < activeBuffer.numSamples()); + } + + // This is called by the mixer and must be extremely fast + float nextSample() { + float res = activeBuffer.getSample(samplePosition++); + ++samplesRead; + if (!hasNextSample()) { + swapBuffers(); + samplePosition = 0; + if (done()) { + playing = false; + } + } + return res; + } + + synchronized void swapBuffers() { + SoundBuffer tmp = activeBuffer; + activeBuffer = fillingBuffer; + fillingBuffer = tmp; + fillingBuffer.empty(true); + } + + // This provides a more robust termination condition + boolean done() { + return (samplesRead == totalSamples) && !looping; + } +} diff --git a/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Vec3f.java b/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Vec3f.java new file mode 100755 index 000000000..5b480a513 --- /dev/null +++ b/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Vec3f.java @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + */ + +package com.jogamp.javafx.audio.windows.waveout; + +/** 3-element single-precision vector */ + +class Vec3f { + public static final Vec3f X_AXIS = new Vec3f( 1, 0, 0); + public static final Vec3f Y_AXIS = new Vec3f( 0, 1, 0); + public static final Vec3f Z_AXIS = new Vec3f( 0, 0, 1); + public static final Vec3f NEG_X_AXIS = new Vec3f(-1, 0, 0); + public static final Vec3f NEG_Y_AXIS = new Vec3f( 0, -1, 0); + public static final Vec3f NEG_Z_AXIS = new Vec3f( 0, 0, -1); + + private float x; + private float y; + private float z; + + public Vec3f() {} + + public Vec3f(Vec3f arg) { + set(arg); + } + + public Vec3f(float x, float y, float z) { + set(x, y, z); + } + + public Vec3f copy() { + return new Vec3f(this); + } + + public void set(Vec3f arg) { + set(arg.x, arg.y, arg.z); + } + + public void set(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + } + + /** Sets the ith component, 0 <= i < 3 */ + public void set(int i, float val) { + switch (i) { + case 0: x = val; break; + case 1: y = val; break; + case 2: z = val; break; + default: throw new IndexOutOfBoundsException(); + } + } + + /** Gets the ith component, 0 <= i < 3 */ + public float get(int i) { + switch (i) { + case 0: return x; + case 1: return y; + case 2: return z; + default: throw new IndexOutOfBoundsException(); + } + } + + public float x() { return x; } + public float y() { return y; } + public float z() { return z; } + + public void setX(float x) { this.x = x; } + public void setY(float y) { this.y = y; } + public void setZ(float z) { this.z = z; } + + public float dot(Vec3f arg) { + return x * arg.x + y * arg.y + z * arg.z; + } + + public float length() { + return (float) Math.sqrt(lengthSquared()); + } + + public float lengthSquared() { + return this.dot(this); + } + + public void normalize() { + float len = length(); + if (len == 0.0f) return; + scale(1.0f / len); + } + + /** Returns this * val; creates new vector */ + public Vec3f times(float val) { + Vec3f tmp = new Vec3f(this); + tmp.scale(val); + return tmp; + } + + /** this = this * val */ + public void scale(float val) { + x *= val; + y *= val; + z *= val; + } + + /** Returns this + arg; creates new vector */ + public Vec3f plus(Vec3f arg) { + Vec3f tmp = new Vec3f(); + tmp.add(this, arg); + return tmp; + } + + /** this = this + b */ + public void add(Vec3f b) { + add(this, b); + } + + /** this = a + b */ + public void add(Vec3f a, Vec3f b) { + x = a.x + b.x; + y = a.y + b.y; + z = a.z + b.z; + } + + /** Returns this + s * arg; creates new vector */ + public Vec3f addScaled(float s, Vec3f arg) { + Vec3f tmp = new Vec3f(); + tmp.addScaled(this, s, arg); + return tmp; + } + + /** this = a + s * b */ + public void addScaled(Vec3f a, float s, Vec3f b) { + x = a.x + s * b.x; + y = a.y + s * b.y; + z = a.z + s * b.z; + } + + /** Returns this - arg; creates new vector */ + public Vec3f minus(Vec3f arg) { + Vec3f tmp = new Vec3f(); + tmp.sub(this, arg); + return tmp; + } + + /** this = this - b */ + public void sub(Vec3f b) { + sub(this, b); + } + + /** this = a - b */ + public void sub(Vec3f a, Vec3f b) { + x = a.x - b.x; + y = a.y - b.y; + z = a.z - b.z; + } + + /** Returns this cross arg; creates new vector */ + public Vec3f cross(Vec3f arg) { + Vec3f tmp = new Vec3f(); + tmp.cross(this, arg); + return tmp; + } + + /** this = a cross b. NOTE: "this" must be a different vector than + both a and b. */ + public void cross(Vec3f a, Vec3f b) { + x = a.y * b.z - a.z * b.y; + y = a.z * b.x - a.x * b.z; + z = a.x * b.y - a.y * b.x; + } + + /** Sets each component of this vector to the product of the + component with the corresponding component of the argument + vector. */ + public void componentMul(Vec3f arg) { + x *= arg.x; + y *= arg.y; + z *= arg.z; + } + + public String toString() { + return "(" + x + ", " + y + ", " + z + ")"; + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java index 32a32e322..49045910a 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java @@ -43,7 +43,7 @@ import java.nio.*; import java.lang.reflect.*; import javax.media.opengl.*; -import com.sun.nativewindow.impl.NWReflection; +import com.jogamp.nativewindow.impl.NWReflection; import com.jogamp.gluegen.runtime.*; import com.jogamp.gluegen.runtime.opengl.*; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java index 20d0c8072..eaf29df77 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java @@ -43,7 +43,7 @@ import java.nio.*; import javax.media.nativewindow.*; import javax.media.opengl.*; import com.jogamp.gluegen.runtime.*; -import com.sun.nativewindow.impl.NWReflection; +import com.jogamp.nativewindow.impl.NWReflection; import java.lang.reflect.*; /** Extends GLDrawableFactory with a few methods for handling diff --git a/src/jogl/classes/com/jogamp/opengl/impl/NativeLibLoader.java b/src/jogl/classes/com/jogamp/opengl/impl/NativeLibLoader.java index aa71a37da..0e5885349 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/NativeLibLoader.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/NativeLibLoader.java @@ -46,7 +46,7 @@ import java.lang.reflect.Method; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.HashSet; -import com.sun.nativewindow.impl.NativeLibLoaderBase; +import com.jogamp.nativewindow.impl.NativeLibLoaderBase; public class NativeLibLoader extends NativeLibLoaderBase { public static void loadNEWT() { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/ThreadingImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/ThreadingImpl.java index 2576c8ae8..b32ed51b6 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/ThreadingImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/ThreadingImpl.java @@ -38,7 +38,7 @@ import java.security.AccessController; import java.security.PrivilegedAction; import javax.media.nativewindow.NativeWindowFactory; -import com.sun.nativewindow.impl.NWReflection; +import com.jogamp.nativewindow.impl.NWReflection; import javax.media.opengl.GLException; /** Implementation of the {@link javax.media.opengl.Threading} class. */ diff --git a/src/jogl/classes/com/jogamp/opengl/impl/awt/AWTUtil.java b/src/jogl/classes/com/jogamp/opengl/impl/awt/AWTUtil.java index 306f6cee7..e5570a8ee 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/awt/AWTUtil.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/awt/AWTUtil.java @@ -36,7 +36,7 @@ package com.jogamp.opengl.impl.awt; -import com.sun.nativewindow.impl.jawt.*; +import com.jogamp.nativewindow.impl.jawt.*; import com.jogamp.opengl.impl.*; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawable.java index e48c78301..f3695ed16 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawable.java @@ -36,7 +36,7 @@ package com.jogamp.opengl.impl.egl; import com.jogamp.opengl.impl.GLDrawableImpl; -import com.sun.nativewindow.impl.NWReflection; +import com.jogamp.nativewindow.impl.NWReflection; import com.jogamp.gluegen.runtime.DynamicLookupHelper; import javax.media.nativewindow.*; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java index f6c8b800e..d50f671a3 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java @@ -39,7 +39,7 @@ import java.util.*; import javax.media.nativewindow.*; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; -import com.sun.nativewindow.impl.*; +import com.jogamp.nativewindow.impl.*; import com.jogamp.gluegen.runtime.NativeLibrary; public class EGLDrawableFactory extends GLDrawableFactoryImpl { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDynamicLookupHelper.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDynamicLookupHelper.java index beffb513f..4918acbb3 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDynamicLookupHelper.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDynamicLookupHelper.java @@ -39,7 +39,7 @@ import java.util.*; import javax.media.nativewindow.*; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; -import com.sun.nativewindow.impl.*; +import com.jogamp.nativewindow.impl.*; import com.jogamp.gluegen.runtime.NativeLibrary; import com.jogamp.gluegen.runtime.DynamicLookupHelper; import java.security.*; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLES1DynamicLookupHelper.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLES1DynamicLookupHelper.java index 0dc9535ce..5c4da5098 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLES1DynamicLookupHelper.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLES1DynamicLookupHelper.java @@ -39,7 +39,7 @@ import java.util.*; import javax.media.nativewindow.*; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; -import com.sun.nativewindow.impl.*; +import com.jogamp.nativewindow.impl.*; import com.jogamp.gluegen.runtime.NativeLibrary; /** diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLES2DynamicLookupHelper.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLES2DynamicLookupHelper.java index 595ded538..0b499c204 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLES2DynamicLookupHelper.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLES2DynamicLookupHelper.java @@ -39,7 +39,7 @@ import java.util.*; import javax.media.nativewindow.*; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; -import com.sun.nativewindow.impl.*; +import com.jogamp.nativewindow.impl.*; import com.jogamp.gluegen.runtime.NativeLibrary; /** diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfigurationFactory.java index 6546ecab7..0a9edd239 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfigurationFactory.java @@ -35,7 +35,7 @@ package com.jogamp.opengl.impl.egl; import java.io.PrintStream; import javax.media.nativewindow.*; import javax.media.nativewindow.egl.*; -import com.sun.nativewindow.impl.*; +import com.jogamp.nativewindow.impl.*; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLOnscreenDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLOnscreenDrawable.java index d37a36fb0..2f5bbf359 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLOnscreenDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLOnscreenDrawable.java @@ -43,7 +43,7 @@ import javax.media.opengl.*; import javax.media.nativewindow.*; import javax.media.nativewindow.egl.*; import com.jogamp.opengl.impl.*; -import com.sun.nativewindow.impl.NullWindow; +import com.jogamp.nativewindow.impl.NullWindow; public class EGLOnscreenDrawable extends EGLDrawable { protected EGLOnscreenDrawable(EGLDrawableFactory factory, NativeWindow component) throws GLException { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java index c08599964..a3ae6f936 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java @@ -45,7 +45,7 @@ import java.util.*; import javax.media.nativewindow.*; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; -import com.sun.nativewindow.impl.*; +import com.jogamp.nativewindow.impl.*; import com.jogamp.gluegen.runtime.DynamicLookupHelper; public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl implements DynamicLookupHelper { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLGraphicsConfigurationFactory.java index ab53e49e9..ada5fb1a7 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLGraphicsConfigurationFactory.java @@ -34,7 +34,7 @@ package com.jogamp.opengl.impl.macosx.cgl; import javax.media.nativewindow.*; import javax.media.nativewindow.macosx.*; -import com.sun.nativewindow.impl.*; +import com.jogamp.nativewindow.impl.*; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java index 239eedd43..dde77cde6 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java @@ -43,7 +43,7 @@ import javax.media.opengl.*; import com.jogamp.opengl.impl.*; import javax.media.nativewindow.*; -import com.sun.nativewindow.impl.NullWindow; +import com.jogamp.nativewindow.impl.NullWindow; public class MacOSXExternalCGLContext extends MacOSXCGLContext { private boolean firstMakeCurrent = true; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXAWTCGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXAWTCGLGraphicsConfigurationFactory.java index 97d5e8d68..0d59da32e 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXAWTCGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXAWTCGLGraphicsConfigurationFactory.java @@ -43,8 +43,8 @@ import javax.media.opengl.awt.*; import com.jogamp.opengl.impl.*; import com.jogamp.opengl.impl.macosx.cgl.*; -import com.sun.nativewindow.impl.jawt.*; -import com.sun.nativewindow.impl.jawt.macosx.*; +import com.jogamp.nativewindow.impl.jawt.*; +import com.jogamp.nativewindow.impl.jawt.macosx.*; public class MacOSXAWTCGLGraphicsConfigurationFactory extends GraphicsConfigurationFactory { protected static final boolean DEBUG = com.jogamp.opengl.impl.Debug.debug("GraphicsConfiguration"); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java index 89a25fe9a..49e646844 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java @@ -41,7 +41,7 @@ package com.jogamp.opengl.impl.windows.wgl; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; -import com.sun.nativewindow.impl.NullWindow; +import com.jogamp.nativewindow.impl.NullWindow; public class WindowsDummyWGLDrawable extends WindowsWGLDrawable { private long hwnd, hdc; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java index 25691ab91..da8b70eb8 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java @@ -42,7 +42,7 @@ package com.jogamp.opengl.impl.windows.wgl; import javax.media.opengl.*; import javax.media.nativewindow.*; import com.jogamp.opengl.impl.*; -import com.sun.nativewindow.impl.NullWindow; +import com.jogamp.nativewindow.impl.NullWindow; public class WindowsExternalWGLContext extends WindowsWGLContext { private boolean firstMakeCurrent = true; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java index f5b89842d..74db45932 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java @@ -42,7 +42,7 @@ package com.jogamp.opengl.impl.windows.wgl; import javax.media.nativewindow.*; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; -import com.sun.nativewindow.impl.NullWindow; +import com.jogamp.nativewindow.impl.NullWindow; public class WindowsExternalWGLDrawable extends WindowsWGLDrawable { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java index 88bfb3b1c..e0c70bd8c 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java @@ -42,7 +42,7 @@ package com.jogamp.opengl.impl.windows.wgl; import javax.media.opengl.*; import javax.media.nativewindow.*; import com.jogamp.opengl.impl.*; -import com.sun.nativewindow.impl.NullWindow; +import com.jogamp.nativewindow.impl.NullWindow; public class WindowsOffscreenWGLDrawable extends WindowsWGLDrawable { private long origbitmap; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java index 38b9bac51..6827c755e 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java @@ -44,9 +44,9 @@ import java.util.*; import javax.media.nativewindow.*; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; -import com.sun.nativewindow.impl.NWReflection; +import com.jogamp.nativewindow.impl.NWReflection; import com.jogamp.gluegen.runtime.DynamicLookupHelper; -import com.sun.nativewindow.impl.NullWindow; +import com.jogamp.nativewindow.impl.NullWindow; public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements DynamicLookupHelper { private static final boolean VERBOSE = Debug.verbose(); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java index 06590a913..b82535bfe 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java @@ -34,7 +34,7 @@ package com.jogamp.opengl.impl.windows.wgl; import javax.media.nativewindow.*; import javax.media.nativewindow.windows.*; -import com.sun.nativewindow.impl.*; +import com.jogamp.nativewindow.impl.*; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/awt/WindowsAWTWGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/awt/WindowsAWTWGLGraphicsConfigurationFactory.java index 4458fb1ac..02cfd14c3 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/awt/WindowsAWTWGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/awt/WindowsAWTWGLGraphicsConfigurationFactory.java @@ -43,8 +43,8 @@ import javax.media.opengl.awt.*; import com.jogamp.opengl.impl.*; import com.jogamp.opengl.impl.windows.wgl.*; -import com.sun.nativewindow.impl.jawt.*; -import com.sun.nativewindow.impl.jawt.windows.*; +import com.jogamp.nativewindow.impl.jawt.*; +import com.jogamp.nativewindow.impl.jawt.windows.*; public class WindowsAWTWGLGraphicsConfigurationFactory extends GraphicsConfigurationFactory { protected static final boolean DEBUG = com.jogamp.opengl.impl.Debug.debug("GraphicsConfiguration"); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/GLXUtil.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/GLXUtil.java index cbd98014a..99c54332f 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/GLXUtil.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/GLXUtil.java @@ -36,7 +36,7 @@ import javax.media.opengl.*; import com.jogamp.opengl.impl.*; import javax.media.nativewindow.NativeWindowFactory; -import com.sun.nativewindow.impl.x11.*; +import com.jogamp.nativewindow.impl.x11.*; public class GLXUtil { public static boolean isMultisampleAvailable(long display) { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java index b94dac1da..783e3278a 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java @@ -43,8 +43,8 @@ import javax.media.nativewindow.*; import javax.media.nativewindow.x11.*; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; -import com.sun.nativewindow.impl.NullWindow; -import com.sun.nativewindow.impl.x11.*; +import com.jogamp.nativewindow.impl.NullWindow; +import com.jogamp.nativewindow.impl.x11.*; public class X11ExternalGLXContext extends X11GLXContext { private boolean firstMakeCurrent = true; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXDrawable.java index 261b1b370..44aea0fa7 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXDrawable.java @@ -43,8 +43,8 @@ import javax.media.nativewindow.*; import javax.media.nativewindow.x11.*; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; -import com.sun.nativewindow.impl.NullWindow; -import com.sun.nativewindow.impl.x11.*; +import com.jogamp.nativewindow.impl.NullWindow; +import com.jogamp.nativewindow.impl.x11.*; import com.jogamp.gluegen.runtime.PointerBuffer; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java index 629bcb0b9..ce846c0a4 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java @@ -46,7 +46,7 @@ import javax.media.nativewindow.*; import javax.media.nativewindow.x11.*; import com.jogamp.opengl.impl.*; import com.jogamp.opengl.impl.x11.glx.*; -import com.sun.nativewindow.impl.x11.*; +import com.jogamp.nativewindow.impl.x11.*; import com.jogamp.gluegen.runtime.ProcAddressTable; public abstract class X11GLXContext extends GLContextImpl { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawable.java index fe030af00..ee807c32a 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawable.java @@ -42,7 +42,7 @@ package com.jogamp.opengl.impl.x11.glx; import javax.media.nativewindow.*; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; -import com.sun.nativewindow.impl.x11.*; +import com.jogamp.nativewindow.impl.x11.*; import com.jogamp.gluegen.runtime.DynamicLookupHelper; public abstract class X11GLXDrawable extends GLDrawableImpl { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java index 089a516ee..cb25e6723 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java @@ -46,9 +46,9 @@ import com.jogamp.gluegen.runtime.*; import com.jogamp.gluegen.runtime.opengl.*; import com.jogamp.opengl.impl.*; import com.jogamp.opengl.impl.x11.glx.*; -import com.sun.nativewindow.impl.NullWindow; -import com.sun.nativewindow.impl.NWReflection; -import com.sun.nativewindow.impl.x11.*; +import com.jogamp.nativewindow.impl.NullWindow; +import com.jogamp.nativewindow.impl.NWReflection; +import com.jogamp.nativewindow.impl.x11.*; public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements DynamicLookupHelper { public X11GLXDrawableFactory() { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfiguration.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfiguration.java index 498605594..f127ec2d0 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfiguration.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfiguration.java @@ -39,7 +39,7 @@ import javax.media.opengl.*; import com.jogamp.opengl.impl.*; import com.jogamp.gluegen.runtime.NativeLibrary; import com.jogamp.gluegen.runtime.PointerBuffer; -import com.sun.nativewindow.impl.x11.*; +import com.jogamp.nativewindow.impl.x11.*; public class X11GLXGraphicsConfiguration extends X11GraphicsConfiguration implements Cloneable { protected static final boolean DEBUG = Debug.debug("GraphicsConfiguration"); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java index 1ddac9013..eca5fede5 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java @@ -34,8 +34,8 @@ package com.jogamp.opengl.impl.x11.glx; import javax.media.nativewindow.*; import javax.media.nativewindow.x11.*; -import com.sun.nativewindow.impl.NativeWindowFactoryImpl; -import com.sun.nativewindow.impl.x11.*; +import com.jogamp.nativewindow.impl.NativeWindowFactoryImpl; +import com.jogamp.nativewindow.impl.x11.*; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java index 7d866a200..ea855d28d 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java @@ -42,7 +42,7 @@ package com.jogamp.opengl.impl.x11.glx; import javax.media.nativewindow.*; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; -import com.sun.nativewindow.impl.x11.*; +import com.jogamp.nativewindow.impl.x11.*; public class X11OffscreenGLXDrawable extends X11GLXDrawable { private long pixmap; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11PbufferGLXDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11PbufferGLXDrawable.java index 3e012225e..50b32b9ec 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11PbufferGLXDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11PbufferGLXDrawable.java @@ -43,7 +43,7 @@ import javax.media.opengl.*; import javax.media.nativewindow.*; import com.jogamp.opengl.impl.*; import com.jogamp.opengl.impl.x11.glx.*; -import com.sun.nativewindow.impl.x11.*; +import com.jogamp.nativewindow.impl.x11.*; public class X11PbufferGLXDrawable extends X11GLXDrawable { protected X11PbufferGLXDrawable(GLDrawableFactory factory, NativeWindow target) { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java index 3b2c8f541..63b350bd3 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java @@ -42,9 +42,9 @@ import javax.media.opengl.*; import javax.media.opengl.awt.*; import com.jogamp.opengl.impl.*; -import com.sun.nativewindow.impl.jawt.*; -import com.sun.nativewindow.impl.jawt.x11.*; -import com.sun.nativewindow.impl.x11.*; +import com.jogamp.nativewindow.impl.jawt.*; +import com.jogamp.nativewindow.impl.jawt.x11.*; +import com.jogamp.nativewindow.impl.x11.*; import com.jogamp.opengl.impl.x11.*; import com.jogamp.opengl.impl.x11.glx.*; diff --git a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java index 98249184d..7c71c4309 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java +++ b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java @@ -3,7 +3,7 @@ package com.jogamp.opengl.util; import javax.media.opengl.*; import javax.media.opengl.fixedfunc.*; -import com.sun.nativewindow.impl.NWReflection; +import com.jogamp.nativewindow.impl.NWReflection; import java.nio.*; import java.util.Iterator; import java.util.ArrayList; diff --git a/src/jogl/classes/com/jogamp/openmax/OMXEventListener.java b/src/jogl/classes/com/jogamp/openmax/OMXEventListener.java new file mode 100644 index 000000000..08cfeccde --- /dev/null +++ b/src/jogl/classes/com/jogamp/openmax/OMXEventListener.java @@ -0,0 +1,14 @@ + +package com.jogamp.openmax; + +public interface OMXEventListener { + + static final int EVENT_CHANGE_SIZE = 1<<0; + static final int EVENT_CHANGE_FPS = 1<<1; + static final int EVENT_CHANGE_BPS = 1<<2; + static final int EVENT_CHANGE_LENGTH = 1<<3; + + public void changedAttributes(OMXInstance omx, int event_mask); + +} + diff --git a/src/jogl/classes/com/jogamp/openmax/OMXInstance.java b/src/jogl/classes/com/jogamp/openmax/OMXInstance.java new file mode 100644 index 000000000..9f5b850ba --- /dev/null +++ b/src/jogl/classes/com/jogamp/openmax/OMXInstance.java @@ -0,0 +1,509 @@ + +package com.jogamp.openmax; + +import javax.media.opengl.*; +import javax.media.opengl.glu.GLU; +import com.jogamp.opengl.util.texture.*; + +import com.jogamp.opengl.impl.egl.EGL; +import com.jogamp.opengl.impl.egl.EGLContext; +import com.jogamp.opengl.impl.egl.EGLDrawable; +import com.jogamp.opengl.impl.egl.EGLExt; + +import java.net.URL; +import java.nio.ByteBuffer; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.*; + +public class OMXInstance { + private long moviePtr = 0; + + protected String path = null; + protected URL url = null; + + // *** Texture impl + protected Texture texture = null; // holds the last fetched texture + + protected float playSpeed = 1.0f; + + /** + * The following data is set by the setStream function, + * and may be set by the native OMX implementation, + * in case the stream attributes changes (see attributesUpdated) + */ + protected int width = 0; + protected int height = 0; + protected int fps = 0; // frames per seconds + protected long bps = 0; // bits per seconds + protected long totalFrames = 0; // duration in frames + protected String acodec = null; + protected String vcodec = null; + + /** + * Old stream values, before the last attributesUpdated) + */ + protected int o_width = 0; + protected int o_height = 0; + protected int o_fps = 0; // frames per seconds + protected long o_bps = 0; // bits per seconds + protected long o_totalFrames = 0; // duration in frames + + static class EGLImageTexture { + public EGLImageTexture(com.jogamp.opengl.util.texture.Texture t, long i, long s) { + texture = t; image = i; sync = s; + } + public String toString() { + return "EGLImageTexture[" + texture + ", image " + image + ", sync "+sync+"]"; + } + protected com.jogamp.opengl.util.texture.Texture texture; + protected long image; + protected long sync; + } + private EGLImageTexture[] eglImgTexs=null; + private HashMap eglImgTexsMap = new HashMap(); + protected int textureNum; + + private EGLExt eglExt = null; + private long eglSurface = 0; + private long eglDisplay = 0; + private long eglContext = 0; + private int sWidth=0, sHeight=0; + + private GL initGLData(GL gl) { + if(null==gl) { + throw new RuntimeException("No current GL"); + } + EGLContext eglCtx = (EGLContext) gl.getContext(); + if(null==eglCtx) { + throw new RuntimeException("No current EGL context"); + } + EGLDrawable eglDrawable = (EGLDrawable) eglCtx.getGLDrawable(); + if(null==eglDrawable) { + throw new RuntimeException("No valid drawable"); + } + eglContext = eglCtx.getContext(); + eglDisplay = eglDrawable.getDisplay(); + eglSurface = eglDrawable.getSurface(); + eglExt = eglCtx.getEGLExt(); + if(null==eglExt) { + throw new RuntimeException("No valid EGLExt"); + } + + int iTmp[] = new int[1]; + EGL.eglQuerySurface(eglDisplay, eglSurface, EGL.EGL_WIDTH, iTmp, 0); + sWidth=iTmp[0]; + EGL.eglQuerySurface(eglDisplay, eglSurface, EGL.EGL_HEIGHT, iTmp, 0); + sHeight=iTmp[0]; + System.out.println("surface size: "+width+"x"+height); + System.out.println(eglDrawable); + System.out.println(eglCtx); + System.out.println("EGL Extensions : "+EGL.eglQueryString(eglDisplay, EGL.EGL_EXTENSIONS)); + System.out.println("EGL CLIENT APIs: "+EGL.eglQueryString(eglDisplay, EGL.EGL_CLIENT_APIS)); + return gl; + } + + public OMXInstance() { + moviePtr = _createInstance(); + if(0==moviePtr) { + throw new GLException("Couldn't create OMXInstance"); + } + } + native long _createInstance(); + + public synchronized void setStream(int textureNum, URL u) { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + this.textureNum=textureNum; + url = u; + if (url == null) { + System.out.println("setURL (null)"); + stop(); + return; + } + path=null; + if (url.getProtocol() == null || "file".equals(url.getProtocol())) { + // CV only accepts absolute paths + try { + File file = new File(url.getPath()); + if (!file.exists()) { + throw new RuntimeException(new FileNotFoundException(file.toString())); + } + path = file.getCanonicalPath(); + System.out.println("setURL: path "+path); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + path = replaceAll(path, "\\", "/").trim(); + if(null==path) { + throw new RuntimeException("Couldn't parse stream URL: "+url); + } + System.out.println("setURL: clean path "+path); + + System.out.println("setURL: p1 "+this); + _setStream(moviePtr, textureNum, path); + System.out.println("setURL: p2 "+this); + } + native void _setStream(long moviePtr, int textureNum, String path); + + public synchronized void setStreamAllEGLImageTexture2D(GL gl) { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + if(null==vcodec) { + return; + } + gl = initGLData(gl); + + if(null!=eglImgTexs) { + removeAllEGLImageTexture2D(gl); + } else { + eglImgTexs = new EGLImageTexture[textureNum]; + } + + int[] tmp = new int[1]; + int tex, e; + + errorCheckGL(gl, "i.1"); + gl.glEnable(gl.GL_TEXTURE_2D); + errorCheckGL(gl, "i.2"); + + for(int i=0; itex ) { + throw new RuntimeException("TextureName creation failed: "+e); + } + gl.glBindTexture(gl.GL_TEXTURE_2D, tex); + + // create space for buffer with a texture + gl.glTexImage2D( + gl.GL_TEXTURE_2D, // target + 0, // level + gl.GL_RGBA, // internal format + width, // width + height, // height + 0, // border + gl.GL_RGBA, // format + gl.GL_UNSIGNED_BYTE, // type + null); // pixels -- will be provided later + gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST); + gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST); + + long image=0, sync=0; + + // create EGLImage from texture + tmp[0] = EGL.EGL_NONE; + image = eglExt.eglCreateImageKHR( + eglDisplay, + eglContext, + eglExt.EGL_GL_TEXTURE_2D_KHR, + tex, + tmp, 0); + if (0==image) { + throw new RuntimeException("EGLImage creation failed: "+EGL.eglGetError()+", dpy "+eglDisplay+", ctx "+eglContext+", tex "+tex); + } + + // Create sync object so that we can be sure that gl has finished + // rendering the EGLImage texture before we tell OpenMAX to fill + // it with a new frame. + tmp[0] = EGL.EGL_NONE; + sync = eglExt.eglCreateFenceSyncKHR( + eglDisplay, + eglExt.EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR, tmp, 0); + + _setStreamEGLImageTexture2D(moviePtr, i, tex, image, sync); + + eglImgTexs[i] = new EGLImageTexture( + com.jogamp.opengl.util.texture.TextureIO.newTexture(tex, + javax.media.opengl.GL2.GL_TEXTURE_2D, + width, + height, + width, + height, + true), + image, sync); + eglImgTexsMap.put(new Integer(tex), eglImgTexs[i]); + } + gl.glDisable(gl.GL_TEXTURE_2D); + } + native void _setStreamEGLImageTexture2D(long moviePtr, int i, int tex, long image, long sync); + + public synchronized void activateStream() { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + _activateStream(moviePtr); + } + native void _activateStream(long moviePtr); + + public synchronized void detachVideoRenderer() { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + _detachVideoRenderer(moviePtr); + } + native void _detachVideoRenderer(long moviePtr); // stop before + + public synchronized void attachVideoRenderer() { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + _attachVideoRenderer(moviePtr); + } + native void _attachVideoRenderer(long moviePtr); // detach before + + public synchronized void setPlaySpeed(float rate) { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + _setPlaySpeed(moviePtr, rate); + playSpeed = rate; + } + public synchronized float getPlaySpeed() { + return playSpeed; + } + native void _setPlaySpeed(long moviePtr, float rate); + + /** @return time position after issuing the command */ + public synchronized float play() { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + return _play(moviePtr); + } + native float _play(long moviePtr); + + /** @return time position after issuing the command */ + public synchronized float pause() { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + return _pause(moviePtr); + } + native float _pause(long moviePtr); + + /** @return time position after issuing the command */ + public synchronized float stop() { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + return _stop(moviePtr); + } + native float _stop(long moviePtr); + + /** @return time position after issuing the command */ + public synchronized float seek(float pos) { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + return _seek(moviePtr, pos); + } + native float _seek(long moviePtr, float position); + + public synchronized Texture getLastTextureID() { + return texture; + } + public synchronized Texture getNextTextureID() { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + texture=null; + EGLImageTexture eglImgTex = (EGLImageTexture) eglImgTexsMap.get(new Integer(_getNextTextureID(moviePtr))); + if(null!=eglImgTex) { + texture = eglImgTex.texture; + } + return texture; + } + native int _getNextTextureID(long moviePtr); + + public synchronized float getCurrentPosition() { + if(0==moviePtr) { + throw new GLException("OMX native instance null"); + } + return _getCurrentPosition(moviePtr); + } + native float _getCurrentPosition(long moviePtr); + + public synchronized void destroy(GL gl) { + removeAllEGLImageTexture2D(gl); + if (moviePtr != 0) { + long ptr = moviePtr; + moviePtr = 0; + _destroyInstance(ptr); + + eglExt=null; + eglSurface=0; + eglDisplay=0; + eglContext=0; + } + } + protected synchronized void finalize() { + if (moviePtr != 0) { + destroy(null); + } + } + native void _destroyInstance(long moviePtr); + + public synchronized boolean isValid() { + return (moviePtr != 0); + } + public synchronized String getPath() { + return path; + } + public synchronized URL getURL() { + return url; + } + public synchronized String getVideoCodec() { + return vcodec; + } + public synchronized String getAudioCodec() { + return acodec; + } + public synchronized long getTotalFrames() { + return totalFrames; + } + public synchronized long getBitrate() { + return bps; + } + public synchronized int getFramerate() { + return fps; + } + public synchronized int getWidth() { + return width; + } + public synchronized int getHeight() { + return height; + } + public synchronized String toString() { + return "OMXInstance [ stream [ video [ "+vcodec+", "+width+"x"+height+", "+fps+"fps, "+bps+"bsp, "+totalFrames+"f ] ] ]"; + } + + /** + * Java callback method issued by the native OMX backend + */ + private void saveAttributes() { + o_width = width; + o_height = height; + o_fps = fps; + o_bps = bps; + o_totalFrames = totalFrames; + } + + private void attributesUpdated() { + int event_mask = 0; + if( o_width != width || o_height != height ) { + event_mask |= OMXEventListener.EVENT_CHANGE_SIZE; + } + if( o_fps != fps ) { + event_mask |= OMXEventListener.EVENT_CHANGE_FPS; + } + if( o_bps != bps ) { + event_mask |= OMXEventListener.EVENT_CHANGE_BPS; + } + if( o_totalFrames != totalFrames ) { + event_mask |= OMXEventListener.EVENT_CHANGE_LENGTH; + } + if(0==event_mask) { + return; + } + + ArrayList listeners = null; + synchronized(this) { + listeners = eventListeners; + } + for(Iterator i = listeners.iterator(); i.hasNext(); ) { + OMXEventListener l = (OMXEventListener) i.next(); + l.changedAttributes(this, event_mask); + } + } + + private String replaceAll(String orig, String search, String repl) { + String dest=null; + // In case replaceAll / java.util.regex.* is not supported (-> CVM) + int i=0,j; + dest = new String(); + while((j=orig.indexOf(search, i))>=0) { + dest=dest.concat(orig.substring(i, j)); + dest=dest.concat(repl); + i=j+1; + } + return dest.concat(orig.substring(i, orig.length())); + } + + private void removeAllEGLImageTexture2D(GL gl) { + if (moviePtr != 0) { + if(null==eglExt) { + throw new RuntimeException("No valid EGLExt"); + } + + texture = null; + for(int i=0; i*/ tracks = new ArrayList(); - - private Vec3f leftSpeakerPosition = new Vec3f(-1, 0, 0); - private Vec3f rightSpeakerPosition = new Vec3f( 1, 0, 0); - - private float falloffFactor = 1.0f; - - static { - mixer = new Mixer(); - } - - private Mixer() { - event = CreateEvent(); - new FillerThread().start(); - MixerThread m = new MixerThread(); - m.setPriority(Thread.MAX_PRIORITY - 1); - m.start(); - } - - public static Mixer getMixer() { - return mixer; - } - - synchronized void add(Track track) { - ArrayList/**/ newTracks = (ArrayList) tracks.clone(); - newTracks.add(track); - tracks = newTracks; - } - - synchronized void remove(Track track) { - ArrayList/**/ newTracks = (ArrayList) tracks.clone(); - newTracks.remove(track); - tracks = newTracks; - } - - // NOTE: due to a bug on the APX device, we only have mono sounds, - // so we currently only pay attention to the position of the left - // speaker - public void setLeftSpeakerPosition(float x, float y, float z) { - leftSpeakerPosition.set(x, y, z); - } - - // NOTE: due to a bug on the APX device, we only have mono sounds, - // so we currently only pay attention to the position of the left - // speaker - public void setRightSpeakerPosition(float x, float y, float z) { - rightSpeakerPosition.set(x, y, z); - } - - /** This defines a scale factor of sorts -- the higher the number, - the larger an area the sound will affect. Default value is - 1.0f. Valid values are [1.0f, ...]. The formula for the gain - for each channel is -
-     falloffFactor
-  -------------------
-  falloffFactor + r^2
-
-*/ - public void setFalloffFactor(float factor) { - falloffFactor = factor; - } - - public void shutdown() { - synchronized(shutdownLock) { - shutdown = true; - SetEvent(event); - try { - shutdownLock.wait(); - } catch (InterruptedException e) { - } - } - } - - class FillerThread extends Thread { - FillerThread() { - super("Mixer Thread"); - } - - public void run() { - while (!shutdown) { - List/**/ curTracks = tracks; - - for (Iterator iter = curTracks.iterator(); iter.hasNext(); ) { - Track track = (Track) iter.next(); - try { - track.fill(); - } catch (IOException e) { - e.printStackTrace(); - remove(track); - } - } - - try { - // Run ten times per second - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - } - - class MixerThread extends Thread { - // Temporary mixing buffer - // Interleaved left and right channels - float[] mixingBuffer; - private Vec3f temp = new Vec3f(); - - MixerThread() { - super("Mixer Thread"); - if (!initializeWaveOut(event)) { - throw new InternalError("Error initializing waveout device"); - } - } - - public void run() { - while (!shutdown) { - // Get the next buffer - long mixerBuffer = getNextMixerBuffer(); - if (mixerBuffer != 0) { - ByteBuffer buf = getMixerBufferData(mixerBuffer); - - if (buf == null) { - // This is happening on CVM because - // JNI_NewDirectByteBuffer isn't implemented - // by default and isn't compatible with the - // JSR-239 NIO implementation (apparently) - buf = newDirectByteBuffer(getMixerBufferDataAddress(mixerBuffer), - getMixerBufferDataCapacity(mixerBuffer)); - } - - if (buf == null) { - throw new InternalError("Couldn't wrap the native address with a direct byte buffer"); - } - - // System.out.println("Mixing buffer"); - - // If we don't have enough samples in our mixing buffer, expand it - // FIXME: knowledge of native output rendering format - if ((mixingBuffer == null) || (mixingBuffer.length < (buf.capacity() / 2 /* bytes / sample */))) { - mixingBuffer = new float[buf.capacity() / 2]; - } else { - // Zap it - for (int i = 0; i < mixingBuffer.length; i++) { - mixingBuffer[i] = 0.0f; - } - } - - // This assertion should be in place if we have stereo - if ((mixingBuffer.length % 2) != 0) { - String msg = "FATAL ERROR: odd number of samples in the mixing buffer"; - System.out.println(msg); - throw new InternalError(msg); - } - - // Run down all of the registered tracks mixing them in - List/**/ curTracks = tracks; - - for (Iterator iter = curTracks.iterator(); iter.hasNext(); ) { - Track track = (Track) iter.next(); - // Consider only playing tracks - if (track.isPlaying()) { - // First recompute its gain - Vec3f pos = track.getPosition(); - float leftGain = gain(pos, leftSpeakerPosition); - float rightGain = gain(pos, rightSpeakerPosition); - // Now mix it in - int i = 0; - while (i < mixingBuffer.length) { - if (track.hasNextSample()) { - float sample = track.nextSample(); - mixingBuffer[i++] = sample * leftGain; - mixingBuffer[i++] = sample * rightGain; - } else { - // This allows tracks to stall without being abruptly cancelled - if (track.done()) { - remove(track); - } - break; - } - } - } - } - - // Now that we have our data, send it down to the card - int outPos = 0; - for (int i = 0; i < mixingBuffer.length; i++) { - short val = (short) mixingBuffer[i]; - buf.put(outPos++, (byte) val); - buf.put(outPos++, (byte) (val >> 8)); - } - if (!prepareMixerBuffer(mixerBuffer)) { - throw new RuntimeException("Error preparing mixer buffer"); - } - if (!writeMixerBuffer(mixerBuffer)) { - throw new RuntimeException("Error writing mixer buffer to device"); - } - } else { - // System.out.println("No mixer buffer available"); - - // Wait for a buffer to become available - if (!WaitForSingleObject(event)) { - throw new RuntimeException("Error while waiting for event object"); - } - - /* - try { - Thread.sleep(10); - } catch (InterruptedException e) { - } - */ - } - } - - // Need to shut down - shutdownWaveOut(); - synchronized(shutdownLock) { - shutdownLock.notifyAll(); - } - } - - // This defines the 3D spatialization gain function. - // The function is defined as: - // falloffFactor - // ------------------- - // falloffFactor + r^2 - private float gain(Vec3f pos, Vec3f speakerPos) { - temp.sub(pos, speakerPos); - float dotp = temp.dot(temp); - return (falloffFactor / (falloffFactor + dotp)); - } - } - - // Initializes waveout device - private static native boolean initializeWaveOut(long eventObject); - // Shuts down waveout device - private static native void shutdownWaveOut(); - - // Gets the next (opaque) buffer of data to fill from the native - // code, or 0 if none was available yet (it should not happen that - // none is available the way the code is written). - private static native long getNextMixerBuffer(); - // Gets the next ByteBuffer to fill out of the mixer buffer. It - // requires interleaved left and right channel samples, 16 signed - // bits per sample, little endian. Implicit 44.1 kHz sample rate. - private static native ByteBuffer getMixerBufferData(long mixerBuffer); - // We need these to work around the lack of - // JNI_NewDirectByteBuffer in CVM + the JSR 239 NIO classes - private static native long getMixerBufferDataAddress(long mixerBuffer); - private static native int getMixerBufferDataCapacity(long mixerBuffer); - // Prepares this mixer buffer for writing to the device. - private static native boolean prepareMixerBuffer(long mixerBuffer); - // Writes this mixer buffer to the device. - private static native boolean writeMixerBuffer(long mixerBuffer); - - // Helpers to prevent mixer thread from busy waiting - private static native long CreateEvent(); - private static native boolean WaitForSingleObject(long event); - private static native void SetEvent(long event); - private static native void CloseHandle(long handle); - - // We need a reflective hack to wrap a direct ByteBuffer around - // the native memory because JNI_NewDirectByteBuffer doesn't work - // in CVM + JSR-239 NIO - private static Class directByteBufferClass; - private static Constructor directByteBufferConstructor; - private static Map createdBuffers = new HashMap(); // Map Long, ByteBuffer - - private static ByteBuffer newDirectByteBuffer(long address, long capacity) { - Long key = new Long(address); - ByteBuffer buf = (ByteBuffer) createdBuffers.get(key); - if (buf == null) { - buf = newDirectByteBufferImpl(address, capacity); - if (buf != null) { - createdBuffers.put(key, buf); - } - } - return buf; - } - private static ByteBuffer newDirectByteBufferImpl(long address, long capacity) { - if (directByteBufferClass == null) { - try { - directByteBufferClass = Class.forName("java.nio.DirectByteBuffer"); - byte[] tmp = new byte[0]; - directByteBufferConstructor = - directByteBufferClass.getDeclaredConstructor(new Class[] { Integer.TYPE, - tmp.getClass(), - Integer.TYPE }); - directByteBufferConstructor.setAccessible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - - if (directByteBufferConstructor != null) { - try { - return (ByteBuffer) - directByteBufferConstructor.newInstance(new Object[] { - new Integer((int) capacity), - null, - new Integer((int) address) - }); - } catch (Exception e) { - e.printStackTrace(); - } - } - return null; - } -} diff --git a/src/jogl/classes/com/sun/javafx/audio/windows/waveout/SoundBuffer.java b/src/jogl/classes/com/sun/javafx/audio/windows/waveout/SoundBuffer.java deleted file mode 100755 index b0404673e..000000000 --- a/src/jogl/classes/com/sun/javafx/audio/windows/waveout/SoundBuffer.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - */ - -package com.sun.javafx.audio.windows.waveout; - -import java.io.*; - -class SoundBuffer { - private byte[] data; - private boolean needsByteSwap; - private int numBytes; - private int bytesPerSample; - private int numSamples; - private boolean playing; - private boolean empty; - - // Note: needsByteSwap argument makes assumptions about the format - SoundBuffer(int size, int bytesPerSample, boolean needsByteSwap) { - this.bytesPerSample = bytesPerSample; - this.needsByteSwap = needsByteSwap; - data = new byte[size * bytesPerSample]; - empty = true; - } - - boolean playing() { - return playing; - } - - void playing(boolean playing) { - this.playing = playing; - } - - boolean empty() { - return empty; - } - - void empty(boolean empty) { - this.empty = empty; - } - - void fill(InputStream input) throws IOException { - synchronized(this) { - if (playing) { - throw new IllegalStateException("Can not fill a buffer that is playing"); - } - } - - empty(true); - int num = input.read(data); - if (num > 0) { - numBytes = num; - numSamples = numBytes / bytesPerSample; - empty(false); - if ((numBytes % bytesPerSample) != 0) { - System.out.println("WARNING: needed integral multiple of " + bytesPerSample + - " bytes, but read " + numBytes + " bytes"); - } - } else { - numBytes = 0; - } - } - - int numSamples() { - return numSamples; - } - - // This is called by the mixer and must be extremely fast - // FIXME: may want to reconsider use of floating point at this point - // FIXME: assumes all sounds are of the same format to avoid normalization - float getSample(int sample) { - int startByte = sample * bytesPerSample; - // FIXME: assumes no more than 4 bytes per sample - int res = 0; - if (needsByteSwap) { - for (int i = startByte + bytesPerSample - 1; i >= startByte; i--) { - res <<= 8; - res |= (data[i] & 0xff); - } - } else { - int endByte = startByte + bytesPerSample - 1; - for (int i = startByte; i <= endByte; i++) { - res <<= 8; - res |= (data[i] & 0xff); - } - } - // Sign extend - if (bytesPerSample == 2) { - res = (short) res; - } else if (bytesPerSample == 1) { - res = (byte) res; - } - - return (float) res; - } -} diff --git a/src/jogl/classes/com/sun/javafx/audio/windows/waveout/TestSpatialization.java b/src/jogl/classes/com/sun/javafx/audio/windows/waveout/TestSpatialization.java deleted file mode 100755 index 4bf967a02..000000000 --- a/src/jogl/classes/com/sun/javafx/audio/windows/waveout/TestSpatialization.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - */ - -package com.sun.javafx.audio.windows.waveout; - -import java.io.*; -import javax.media.opengl.GLDrawableFactory; - -public class TestSpatialization { - public static void main(String[] args) { - if (args.length != 1) { - System.out.println("Usage: TestSpatialization [file name]"); - System.exit(1); - } - - try { - // FIXME: this is a hack to get the native library loaded - try { - GLDrawableFactory.getFactory(NativeWindow.class); - } catch (Exception e) {} - // Initialize the audio subsystem - Audio audio = Audio.getInstance(); - // Create a track - Track track = audio.newTrack(new File(args[0])); - track.setPosition(1, 0, 0); - // Run for ten seconds - long startTime = System.currentTimeMillis(); - long duration = 10000; - long curTime = 0; - try { - Thread.sleep(500); - } catch (InterruptedException e) { - } - System.out.println("Playing..."); - track.setLooping(true); - track.play(); - while ((curTime = System.currentTimeMillis()) < startTime + duration) { - // Make one revolution every two seconds - float rads = (float) (((2 * Math.PI) * (((float) (curTime - startTime)) / 1000.0f)) / 2); - track.setPosition((float) Math.cos(rads), 0, (float) Math.sin(rads)); - // Would like to make it go in a circle, but since - // stereo doesn't work now, make it move along a line - // track.setPosition(-1.0f, 0, 2.0f * (float) Math.sin(rads)); - // Sleep a little between updates - try { - Thread.sleep(10); - } catch (InterruptedException e) { - } - } - System.out.println("Shutting down audio subsystem"); - audio.shutdown(); - System.out.println("Exiting."); - System.exit(0); - } catch (Exception e) { - e.printStackTrace(); - System.exit(1); - } - } -} diff --git a/src/jogl/classes/com/sun/javafx/audio/windows/waveout/Track.java b/src/jogl/classes/com/sun/javafx/audio/windows/waveout/Track.java deleted file mode 100755 index 190396112..000000000 --- a/src/jogl/classes/com/sun/javafx/audio/windows/waveout/Track.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - */ - -package com.sun.javafx.audio.windows.waveout; - -import java.io.*; -import java.nio.*; - -public class Track { - // Default number of samples per buffer - private static final int BUFFER_SIZE = 32768; - // Number of bytes per sample (FIXME: dependence on audio format) - static final int BYTES_PER_SAMPLE = 2; - // Whether we need byte swapping (FIXME: dependence on audio format) - static final boolean NEEDS_BYTE_SWAP = true; - - // This is the buffer this track is currently playing from - private SoundBuffer activeBuffer; - // This is the sample position in the active buffer - private int samplePosition; - // This is the total number of samples in the file - private int totalSamples; - // This is the total number of samples we have read - private int samplesRead; - // This is the buffer that the background filler thread may be filling - private SoundBuffer fillingBuffer; - // If we're playing the file, this is its input stream - private InputStream input; - // Keep around the file name - private File file; - // Whether we're playing this sound - private boolean playing; - // Whether we're looping this sound - private boolean looping; - // The position of this sound; defaults to being at the origin - private volatile Vec3f position = new Vec3f(); - - Track(File file) throws IOException { - if (!file.getName().endsWith(".rawsound")) { - throw new IOException("Unsupported file format (currently supports only raw sounds)"); - } - - this.file = file; - openInput(); - - // Allocate the buffers - activeBuffer = new SoundBuffer(BUFFER_SIZE, BYTES_PER_SAMPLE, NEEDS_BYTE_SWAP); - fillingBuffer = new SoundBuffer(BUFFER_SIZE, BYTES_PER_SAMPLE, NEEDS_BYTE_SWAP); - - // Fill the first buffer immediately - fill(); - swapBuffers(); - } - - private void openInput() throws IOException { - input = new BufferedInputStream(new FileInputStream(file)); - totalSamples = (int) file.length() / BYTES_PER_SAMPLE; - } - - public File getFile() { - return file; - } - - public synchronized void play() { - if (input == null) { - try { - openInput(); - // Fill it immediately - fill(); - } catch (IOException e) { - e.printStackTrace(); - return; - } - } - - playing = true; - } - - public synchronized boolean isPlaying() { - return playing; - } - - public synchronized void setLooping(boolean looping) { - this.looping = looping; - } - - public synchronized boolean isLooping() { - return looping; - } - - public void setPosition(float x, float y, float z) { - position = new Vec3f(x, y, z); - } - - synchronized void fill() throws IOException { - if (input == null) { - return; - } - SoundBuffer curBuffer = fillingBuffer; - if (!curBuffer.empty()) { - return; - } - curBuffer.fill(input); - if (curBuffer.empty()) { - // End of file - InputStream tmp = null; - synchronized(this) { - tmp = input; - input = null; - } - tmp.close(); - - // If looping, re-open - if (isLooping()) { - openInput(); - // and fill - fill(); - } - } - } - - // These are only for use by the Mixer - private float leftGain; - private float rightGain; - - void setLeftGain(float leftGain) { - this.leftGain = leftGain; - } - - float getLeftGain() { - return leftGain; - } - - void setRightGain(float rightGain) { - this.rightGain = rightGain; - } - - float getRightGain() { - return rightGain; - } - - Vec3f getPosition() { - return position; - } - - // This is called by the mixer and must be extremely fast - // Note this assumes mono sounds (FIXME) - boolean hasNextSample() { - return (!activeBuffer.empty() && samplePosition < activeBuffer.numSamples()); - } - - // This is called by the mixer and must be extremely fast - float nextSample() { - float res = activeBuffer.getSample(samplePosition++); - ++samplesRead; - if (!hasNextSample()) { - swapBuffers(); - samplePosition = 0; - if (done()) { - playing = false; - } - } - return res; - } - - synchronized void swapBuffers() { - SoundBuffer tmp = activeBuffer; - activeBuffer = fillingBuffer; - fillingBuffer = tmp; - fillingBuffer.empty(true); - } - - // This provides a more robust termination condition - boolean done() { - return (samplesRead == totalSamples) && !looping; - } -} diff --git a/src/jogl/classes/com/sun/javafx/audio/windows/waveout/Vec3f.java b/src/jogl/classes/com/sun/javafx/audio/windows/waveout/Vec3f.java deleted file mode 100755 index 9a3038e35..000000000 --- a/src/jogl/classes/com/sun/javafx/audio/windows/waveout/Vec3f.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - */ - -package com.sun.javafx.audio.windows.waveout; - -/** 3-element single-precision vector */ - -class Vec3f { - public static final Vec3f X_AXIS = new Vec3f( 1, 0, 0); - public static final Vec3f Y_AXIS = new Vec3f( 0, 1, 0); - public static final Vec3f Z_AXIS = new Vec3f( 0, 0, 1); - public static final Vec3f NEG_X_AXIS = new Vec3f(-1, 0, 0); - public static final Vec3f NEG_Y_AXIS = new Vec3f( 0, -1, 0); - public static final Vec3f NEG_Z_AXIS = new Vec3f( 0, 0, -1); - - private float x; - private float y; - private float z; - - public Vec3f() {} - - public Vec3f(Vec3f arg) { - set(arg); - } - - public Vec3f(float x, float y, float z) { - set(x, y, z); - } - - public Vec3f copy() { - return new Vec3f(this); - } - - public void set(Vec3f arg) { - set(arg.x, arg.y, arg.z); - } - - public void set(float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - } - - /** Sets the ith component, 0 <= i < 3 */ - public void set(int i, float val) { - switch (i) { - case 0: x = val; break; - case 1: y = val; break; - case 2: z = val; break; - default: throw new IndexOutOfBoundsException(); - } - } - - /** Gets the ith component, 0 <= i < 3 */ - public float get(int i) { - switch (i) { - case 0: return x; - case 1: return y; - case 2: return z; - default: throw new IndexOutOfBoundsException(); - } - } - - public float x() { return x; } - public float y() { return y; } - public float z() { return z; } - - public void setX(float x) { this.x = x; } - public void setY(float y) { this.y = y; } - public void setZ(float z) { this.z = z; } - - public float dot(Vec3f arg) { - return x * arg.x + y * arg.y + z * arg.z; - } - - public float length() { - return (float) Math.sqrt(lengthSquared()); - } - - public float lengthSquared() { - return this.dot(this); - } - - public void normalize() { - float len = length(); - if (len == 0.0f) return; - scale(1.0f / len); - } - - /** Returns this * val; creates new vector */ - public Vec3f times(float val) { - Vec3f tmp = new Vec3f(this); - tmp.scale(val); - return tmp; - } - - /** this = this * val */ - public void scale(float val) { - x *= val; - y *= val; - z *= val; - } - - /** Returns this + arg; creates new vector */ - public Vec3f plus(Vec3f arg) { - Vec3f tmp = new Vec3f(); - tmp.add(this, arg); - return tmp; - } - - /** this = this + b */ - public void add(Vec3f b) { - add(this, b); - } - - /** this = a + b */ - public void add(Vec3f a, Vec3f b) { - x = a.x + b.x; - y = a.y + b.y; - z = a.z + b.z; - } - - /** Returns this + s * arg; creates new vector */ - public Vec3f addScaled(float s, Vec3f arg) { - Vec3f tmp = new Vec3f(); - tmp.addScaled(this, s, arg); - return tmp; - } - - /** this = a + s * b */ - public void addScaled(Vec3f a, float s, Vec3f b) { - x = a.x + s * b.x; - y = a.y + s * b.y; - z = a.z + s * b.z; - } - - /** Returns this - arg; creates new vector */ - public Vec3f minus(Vec3f arg) { - Vec3f tmp = new Vec3f(); - tmp.sub(this, arg); - return tmp; - } - - /** this = this - b */ - public void sub(Vec3f b) { - sub(this, b); - } - - /** this = a - b */ - public void sub(Vec3f a, Vec3f b) { - x = a.x - b.x; - y = a.y - b.y; - z = a.z - b.z; - } - - /** Returns this cross arg; creates new vector */ - public Vec3f cross(Vec3f arg) { - Vec3f tmp = new Vec3f(); - tmp.cross(this, arg); - return tmp; - } - - /** this = a cross b. NOTE: "this" must be a different vector than - both a and b. */ - public void cross(Vec3f a, Vec3f b) { - x = a.y * b.z - a.z * b.y; - y = a.z * b.x - a.x * b.z; - z = a.x * b.y - a.y * b.x; - } - - /** Sets each component of this vector to the product of the - component with the corresponding component of the argument - vector. */ - public void componentMul(Vec3f arg) { - x *= arg.x; - y *= arg.y; - z *= arg.z; - } - - public String toString() { - return "(" + x + ", " + y + ", " + z + ")"; - } -} diff --git a/src/jogl/classes/com/sun/openmax/OMXEventListener.java b/src/jogl/classes/com/sun/openmax/OMXEventListener.java deleted file mode 100644 index ebbf7129f..000000000 --- a/src/jogl/classes/com/sun/openmax/OMXEventListener.java +++ /dev/null @@ -1,14 +0,0 @@ - -package com.sun.openmax; - -public interface OMXEventListener { - - static final int EVENT_CHANGE_SIZE = 1<<0; - static final int EVENT_CHANGE_FPS = 1<<1; - static final int EVENT_CHANGE_BPS = 1<<2; - static final int EVENT_CHANGE_LENGTH = 1<<3; - - public void changedAttributes(OMXInstance omx, int event_mask); - -} - diff --git a/src/jogl/classes/com/sun/openmax/OMXInstance.java b/src/jogl/classes/com/sun/openmax/OMXInstance.java deleted file mode 100644 index 84bd87809..000000000 --- a/src/jogl/classes/com/sun/openmax/OMXInstance.java +++ /dev/null @@ -1,509 +0,0 @@ - -package com.sun.openmax; - -import javax.media.opengl.*; -import javax.media.opengl.glu.GLU; -import com.jogamp.opengl.util.texture.*; - -import com.jogamp.opengl.impl.egl.EGL; -import com.jogamp.opengl.impl.egl.EGLContext; -import com.jogamp.opengl.impl.egl.EGLDrawable; -import com.jogamp.opengl.impl.egl.EGLExt; - -import java.net.URL; -import java.nio.ByteBuffer; -import java.io.File; -import java.io.FileNotFoundException; -import java.util.*; - -public class OMXInstance { - private long moviePtr = 0; - - protected String path = null; - protected URL url = null; - - // *** Texture impl - protected Texture texture = null; // holds the last fetched texture - - protected float playSpeed = 1.0f; - - /** - * The following data is set by the setStream function, - * and may be set by the native OMX implementation, - * in case the stream attributes changes (see attributesUpdated) - */ - protected int width = 0; - protected int height = 0; - protected int fps = 0; // frames per seconds - protected long bps = 0; // bits per seconds - protected long totalFrames = 0; // duration in frames - protected String acodec = null; - protected String vcodec = null; - - /** - * Old stream values, before the last attributesUpdated) - */ - protected int o_width = 0; - protected int o_height = 0; - protected int o_fps = 0; // frames per seconds - protected long o_bps = 0; // bits per seconds - protected long o_totalFrames = 0; // duration in frames - - static class EGLImageTexture { - public EGLImageTexture(com.jogamp.opengl.util.texture.Texture t, long i, long s) { - texture = t; image = i; sync = s; - } - public String toString() { - return "EGLImageTexture[" + texture + ", image " + image + ", sync "+sync+"]"; - } - protected com.jogamp.opengl.util.texture.Texture texture; - protected long image; - protected long sync; - } - private EGLImageTexture[] eglImgTexs=null; - private HashMap eglImgTexsMap = new HashMap(); - protected int textureNum; - - private EGLExt eglExt = null; - private long eglSurface = 0; - private long eglDisplay = 0; - private long eglContext = 0; - private int sWidth=0, sHeight=0; - - private GL initGLData(GL gl) { - if(null==gl) { - throw new RuntimeException("No current GL"); - } - EGLContext eglCtx = (EGLContext) gl.getContext(); - if(null==eglCtx) { - throw new RuntimeException("No current EGL context"); - } - EGLDrawable eglDrawable = (EGLDrawable) eglCtx.getGLDrawable(); - if(null==eglDrawable) { - throw new RuntimeException("No valid drawable"); - } - eglContext = eglCtx.getContext(); - eglDisplay = eglDrawable.getDisplay(); - eglSurface = eglDrawable.getSurface(); - eglExt = eglCtx.getEGLExt(); - if(null==eglExt) { - throw new RuntimeException("No valid EGLExt"); - } - - int iTmp[] = new int[1]; - EGL.eglQuerySurface(eglDisplay, eglSurface, EGL.EGL_WIDTH, iTmp, 0); - sWidth=iTmp[0]; - EGL.eglQuerySurface(eglDisplay, eglSurface, EGL.EGL_HEIGHT, iTmp, 0); - sHeight=iTmp[0]; - System.out.println("surface size: "+width+"x"+height); - System.out.println(eglDrawable); - System.out.println(eglCtx); - System.out.println("EGL Extensions : "+EGL.eglQueryString(eglDisplay, EGL.EGL_EXTENSIONS)); - System.out.println("EGL CLIENT APIs: "+EGL.eglQueryString(eglDisplay, EGL.EGL_CLIENT_APIS)); - return gl; - } - - public OMXInstance() { - moviePtr = _createInstance(); - if(0==moviePtr) { - throw new GLException("Couldn't create OMXInstance"); - } - } - native long _createInstance(); - - public synchronized void setStream(int textureNum, URL u) { - if(0==moviePtr) { - throw new GLException("OMX native instance null"); - } - this.textureNum=textureNum; - url = u; - if (url == null) { - System.out.println("setURL (null)"); - stop(); - return; - } - path=null; - if (url.getProtocol() == null || "file".equals(url.getProtocol())) { - // CV only accepts absolute paths - try { - File file = new File(url.getPath()); - if (!file.exists()) { - throw new RuntimeException(new FileNotFoundException(file.toString())); - } - path = file.getCanonicalPath(); - System.out.println("setURL: path "+path); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - } - path = replaceAll(path, "\\", "/").trim(); - if(null==path) { - throw new RuntimeException("Couldn't parse stream URL: "+url); - } - System.out.println("setURL: clean path "+path); - - System.out.println("setURL: p1 "+this); - _setStream(moviePtr, textureNum, path); - System.out.println("setURL: p2 "+this); - } - native void _setStream(long moviePtr, int textureNum, String path); - - public synchronized void setStreamAllEGLImageTexture2D(GL gl) { - if(0==moviePtr) { - throw new GLException("OMX native instance null"); - } - if(null==vcodec) { - return; - } - gl = initGLData(gl); - - if(null!=eglImgTexs) { - removeAllEGLImageTexture2D(gl); - } else { - eglImgTexs = new EGLImageTexture[textureNum]; - } - - int[] tmp = new int[1]; - int tex, e; - - errorCheckGL(gl, "i.1"); - gl.glEnable(gl.GL_TEXTURE_2D); - errorCheckGL(gl, "i.2"); - - for(int i=0; itex ) { - throw new RuntimeException("TextureName creation failed: "+e); - } - gl.glBindTexture(gl.GL_TEXTURE_2D, tex); - - // create space for buffer with a texture - gl.glTexImage2D( - gl.GL_TEXTURE_2D, // target - 0, // level - gl.GL_RGBA, // internal format - width, // width - height, // height - 0, // border - gl.GL_RGBA, // format - gl.GL_UNSIGNED_BYTE, // type - null); // pixels -- will be provided later - gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST); - gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST); - - long image=0, sync=0; - - // create EGLImage from texture - tmp[0] = EGL.EGL_NONE; - image = eglExt.eglCreateImageKHR( - eglDisplay, - eglContext, - eglExt.EGL_GL_TEXTURE_2D_KHR, - tex, - tmp, 0); - if (0==image) { - throw new RuntimeException("EGLImage creation failed: "+EGL.eglGetError()+", dpy "+eglDisplay+", ctx "+eglContext+", tex "+tex); - } - - // Create sync object so that we can be sure that gl has finished - // rendering the EGLImage texture before we tell OpenMAX to fill - // it with a new frame. - tmp[0] = EGL.EGL_NONE; - sync = eglExt.eglCreateFenceSyncKHR( - eglDisplay, - eglExt.EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR, tmp, 0); - - _setStreamEGLImageTexture2D(moviePtr, i, tex, image, sync); - - eglImgTexs[i] = new EGLImageTexture( - com.jogamp.opengl.util.texture.TextureIO.newTexture(tex, - javax.media.opengl.GL2.GL_TEXTURE_2D, - width, - height, - width, - height, - true), - image, sync); - eglImgTexsMap.put(new Integer(tex), eglImgTexs[i]); - } - gl.glDisable(gl.GL_TEXTURE_2D); - } - native void _setStreamEGLImageTexture2D(long moviePtr, int i, int tex, long image, long sync); - - public synchronized void activateStream() { - if(0==moviePtr) { - throw new GLException("OMX native instance null"); - } - _activateStream(moviePtr); - } - native void _activateStream(long moviePtr); - - public synchronized void detachVideoRenderer() { - if(0==moviePtr) { - throw new GLException("OMX native instance null"); - } - _detachVideoRenderer(moviePtr); - } - native void _detachVideoRenderer(long moviePtr); // stop before - - public synchronized void attachVideoRenderer() { - if(0==moviePtr) { - throw new GLException("OMX native instance null"); - } - _attachVideoRenderer(moviePtr); - } - native void _attachVideoRenderer(long moviePtr); // detach before - - public synchronized void setPlaySpeed(float rate) { - if(0==moviePtr) { - throw new GLException("OMX native instance null"); - } - _setPlaySpeed(moviePtr, rate); - playSpeed = rate; - } - public synchronized float getPlaySpeed() { - return playSpeed; - } - native void _setPlaySpeed(long moviePtr, float rate); - - /** @return time position after issuing the command */ - public synchronized float play() { - if(0==moviePtr) { - throw new GLException("OMX native instance null"); - } - return _play(moviePtr); - } - native float _play(long moviePtr); - - /** @return time position after issuing the command */ - public synchronized float pause() { - if(0==moviePtr) { - throw new GLException("OMX native instance null"); - } - return _pause(moviePtr); - } - native float _pause(long moviePtr); - - /** @return time position after issuing the command */ - public synchronized float stop() { - if(0==moviePtr) { - throw new GLException("OMX native instance null"); - } - return _stop(moviePtr); - } - native float _stop(long moviePtr); - - /** @return time position after issuing the command */ - public synchronized float seek(float pos) { - if(0==moviePtr) { - throw new GLException("OMX native instance null"); - } - return _seek(moviePtr, pos); - } - native float _seek(long moviePtr, float position); - - public synchronized Texture getLastTextureID() { - return texture; - } - public synchronized Texture getNextTextureID() { - if(0==moviePtr) { - throw new GLException("OMX native instance null"); - } - texture=null; - EGLImageTexture eglImgTex = (EGLImageTexture) eglImgTexsMap.get(new Integer(_getNextTextureID(moviePtr))); - if(null!=eglImgTex) { - texture = eglImgTex.texture; - } - return texture; - } - native int _getNextTextureID(long moviePtr); - - public synchronized float getCurrentPosition() { - if(0==moviePtr) { - throw new GLException("OMX native instance null"); - } - return _getCurrentPosition(moviePtr); - } - native float _getCurrentPosition(long moviePtr); - - public synchronized void destroy(GL gl) { - removeAllEGLImageTexture2D(gl); - if (moviePtr != 0) { - long ptr = moviePtr; - moviePtr = 0; - _destroyInstance(ptr); - - eglExt=null; - eglSurface=0; - eglDisplay=0; - eglContext=0; - } - } - protected synchronized void finalize() { - if (moviePtr != 0) { - destroy(null); - } - } - native void _destroyInstance(long moviePtr); - - public synchronized boolean isValid() { - return (moviePtr != 0); - } - public synchronized String getPath() { - return path; - } - public synchronized URL getURL() { - return url; - } - public synchronized String getVideoCodec() { - return vcodec; - } - public synchronized String getAudioCodec() { - return acodec; - } - public synchronized long getTotalFrames() { - return totalFrames; - } - public synchronized long getBitrate() { - return bps; - } - public synchronized int getFramerate() { - return fps; - } - public synchronized int getWidth() { - return width; - } - public synchronized int getHeight() { - return height; - } - public synchronized String toString() { - return "OMXInstance [ stream [ video [ "+vcodec+", "+width+"x"+height+", "+fps+"fps, "+bps+"bsp, "+totalFrames+"f ] ] ]"; - } - - /** - * Java callback method issued by the native OMX backend - */ - private void saveAttributes() { - o_width = width; - o_height = height; - o_fps = fps; - o_bps = bps; - o_totalFrames = totalFrames; - } - - private void attributesUpdated() { - int event_mask = 0; - if( o_width != width || o_height != height ) { - event_mask |= OMXEventListener.EVENT_CHANGE_SIZE; - } - if( o_fps != fps ) { - event_mask |= OMXEventListener.EVENT_CHANGE_FPS; - } - if( o_bps != bps ) { - event_mask |= OMXEventListener.EVENT_CHANGE_BPS; - } - if( o_totalFrames != totalFrames ) { - event_mask |= OMXEventListener.EVENT_CHANGE_LENGTH; - } - if(0==event_mask) { - return; - } - - ArrayList listeners = null; - synchronized(this) { - listeners = eventListeners; - } - for(Iterator i = listeners.iterator(); i.hasNext(); ) { - OMXEventListener l = (OMXEventListener) i.next(); - l.changedAttributes(this, event_mask); - } - } - - private String replaceAll(String orig, String search, String repl) { - String dest=null; - // In case replaceAll / java.util.regex.* is not supported (-> CVM) - int i=0,j; - dest = new String(); - while((j=orig.indexOf(search, i))>=0) { - dest=dest.concat(orig.substring(i, j)); - dest=dest.concat(repl); - i=j+1; - } - return dest.concat(orig.substring(i, orig.length())); - } - - private void removeAllEGLImageTexture2D(GL gl) { - if (moviePtr != 0) { - if(null==eglExt) { - throw new RuntimeException("No valid EGLExt"); - } - - texture = null; - for(int i=0; i Provides a virtual machine- and operating system-independent mechanism for creating {@link GLDrawable}s.

diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java index 6719a76a2..755fae73d 100644 --- a/src/jogl/classes/javax/media/opengl/GLProfile.java +++ b/src/jogl/classes/javax/media/opengl/GLProfile.java @@ -39,8 +39,8 @@ package javax.media.opengl; import com.jogamp.opengl.impl.DRIHack; import com.jogamp.opengl.impl.Debug; import com.jogamp.opengl.impl.NativeLibLoader; -import com.sun.nativewindow.impl.NWReflection; -import com.sun.nativewindow.impl.jvm.JVMUtil; +import com.jogamp.nativewindow.impl.NWReflection; +import com.jogamp.nativewindow.impl.jvm.JVMUtil; import java.util.HashMap; import java.security.AccessControlContext; import java.security.AccessController; diff --git a/src/jogl/native/audio/Mixer.cpp b/src/jogl/native/audio/Mixer.cpp index 8843c00ec..821a03246 100755 --- a/src/jogl/native/audio/Mixer.cpp +++ b/src/jogl/native/audio/Mixer.cpp @@ -2,7 +2,7 @@ #include #include #include -#include "com_sun_javafx_audio_windows_waveout_Mixer.h" +#include "com_jogamp_javafx_audio_windows_waveout_Mixer.h" static HANDLE event = NULL; static HWAVEOUT output = NULL; @@ -57,7 +57,7 @@ void CALLBACK playbackCallback(HWAVEOUT output, } } -JNIEXPORT jboolean JNICALL Java_com_sun_javafx_audio_windows_waveout_Mixer_initializeWaveOut +JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_initializeWaveOut (JNIEnv *env, jclass unused, jlong eventObject) { event = (HANDLE) eventObject; @@ -98,7 +98,7 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_audio_windows_waveout_Mixer_initi return JNI_TRUE; } -JNIEXPORT void JNICALL Java_com_sun_javafx_audio_windows_waveout_Mixer_shutdownWaveOut +JNIEXPORT void JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_shutdownWaveOut (JNIEnv *env, jclass unused) { // writeString("Pausing\n"); @@ -109,7 +109,7 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_audio_windows_waveout_Mixer_shutdownW waveOutClose(output); } -JNIEXPORT jlong JNICALL Java_com_sun_javafx_audio_windows_waveout_Mixer_getNextMixerBuffer +JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_getNextMixerBuffer (JNIEnv *env, jclass unused) { WAVEHDR* hdr = NULL; @@ -123,28 +123,28 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_audio_windows_waveout_Mixer_getNextM return (jlong) hdr; } -JNIEXPORT jobject JNICALL Java_com_sun_javafx_audio_windows_waveout_Mixer_getMixerBufferData +JNIEXPORT jobject JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_getMixerBufferData (JNIEnv *env, jclass unused, jlong mixerBuffer) { WAVEHDR* hdr = (WAVEHDR*) mixerBuffer; return env->NewDirectByteBuffer(hdr->lpData, hdr->dwBufferLength); } -JNIEXPORT jlong JNICALL Java_com_sun_javafx_audio_windows_waveout_Mixer_getMixerBufferDataAddress +JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_getMixerBufferDataAddress (JNIEnv *env, jclass unused, jlong mixerBuffer) { WAVEHDR* hdr = (WAVEHDR*) mixerBuffer; return (jlong) hdr->lpData; } -JNIEXPORT jint JNICALL Java_com_sun_javafx_audio_windows_waveout_Mixer_getMixerBufferDataCapacity +JNIEXPORT jint JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_getMixerBufferDataCapacity (JNIEnv *env, jclass unused, jlong mixerBuffer) { WAVEHDR* hdr = (WAVEHDR*) mixerBuffer; return (jint) hdr->dwBufferLength; } -JNIEXPORT jboolean JNICALL Java_com_sun_javafx_audio_windows_waveout_Mixer_prepareMixerBuffer +JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_prepareMixerBuffer (JNIEnv *env, jclass unused, jlong mixerBuffer) { MMRESULT res = waveOutPrepareHeader(output, @@ -156,7 +156,7 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_audio_windows_waveout_Mixer_prepa return JNI_FALSE; } -JNIEXPORT jboolean JNICALL Java_com_sun_javafx_audio_windows_waveout_Mixer_writeMixerBuffer +JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_writeMixerBuffer (JNIEnv *env, jclass unused, jlong mixerBuffer) { MMRESULT res = waveOutWrite(output, @@ -170,13 +170,13 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_audio_windows_waveout_Mixer_write return JNI_FALSE; } -JNIEXPORT jlong JNICALL Java_com_sun_javafx_audio_windows_waveout_Mixer_CreateEvent +JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_CreateEvent (JNIEnv *env, jclass unused) { return (jlong) CreateEvent(NULL, FALSE, TRUE, NULL); } -JNIEXPORT jboolean JNICALL Java_com_sun_javafx_audio_windows_waveout_Mixer_WaitForSingleObject +JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_WaitForSingleObject (JNIEnv *env, jclass unused, jlong eventObject) { DWORD res = WaitForSingleObject((HANDLE) eventObject, INFINITE); @@ -186,13 +186,13 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_audio_windows_waveout_Mixer_WaitF return JNI_FALSE; } -JNIEXPORT void JNICALL Java_com_sun_javafx_audio_windows_waveout_Mixer_SetEvent +JNIEXPORT void JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_SetEvent (JNIEnv *env, jclass unused, jlong eventObject) { SetEvent((HANDLE) eventObject); } -JNIEXPORT void JNICALL Java_com_sun_javafx_audio_windows_waveout_Mixer_CloseHandle +JNIEXPORT void JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_CloseHandle (JNIEnv *env, jclass unused, jlong eventObject) { CloseHandle((HANDLE) eventObject); diff --git a/src/jogl/native/openmax/com_sun_openmax_OMXInstance.c b/src/jogl/native/openmax/com_sun_openmax_OMXInstance.c index c763b0dd6..1ca973097 100644 --- a/src/jogl/native/openmax/com_sun_openmax_OMXInstance.c +++ b/src/jogl/native/openmax/com_sun_openmax_OMXInstance.c @@ -13,7 +13,7 @@ // http://developer.apple.com/qa/qa2001/qa1149.html // http://developer.apple.com/qa/qa2001/qa1262.html -#include "com_sun_openmax_OMXInstance.h" +#include "com_jogamp_openmax_OMXInstance.h" #include "omx_tool.h" #include @@ -105,7 +105,7 @@ void OMXInstance_UpdateJavaAttributes(OMXToolBasicAV_t *pOMXAV, KDboolean issueJ } } -JNIEXPORT jlong JNICALL Java_com_sun_openmax_OMXInstance__1createInstance +JNIEXPORT jlong JNICALL Java_com_jogamp_openmax_OMXInstance__1createInstance (JNIEnv *env, jobject instance) { OMXToolBasicAV_t * pOMXAV; @@ -132,7 +132,7 @@ JNIEXPORT jlong JNICALL Java_com_sun_openmax_OMXInstance__1createInstance return (jlong) (intptr_t) (void *)pOMXAV; } -JNIEXPORT void JNICALL Java_com_sun_openmax_OMXInstance__1setStream +JNIEXPORT void JNICALL Java_com_jogamp_openmax_OMXInstance__1setStream (JNIEnv *env, jobject instance, jlong ptr, jint vBufferNum, jstring jpath) { jboolean iscopy; @@ -150,7 +150,7 @@ JNIEXPORT void JNICALL Java_com_sun_openmax_OMXInstance__1setStream fprintf(stdout, "setStream 3 ..\n"); fflush(stdout); // JAU } -JNIEXPORT void JNICALL Java_com_sun_openmax_OMXInstance__1setStreamEGLImageTexture2D +JNIEXPORT void JNICALL Java_com_jogamp_openmax_OMXInstance__1setStreamEGLImageTexture2D (JNIEnv *env, jobject instance, jlong ptr, jint i, jint tex, jlong image, jlong sync) { OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); @@ -161,7 +161,7 @@ JNIEXPORT void JNICALL Java_com_sun_openmax_OMXInstance__1setStreamEGLImageTextu } } -JNIEXPORT void JNICALL Java_com_sun_openmax_OMXInstance__1activateStream +JNIEXPORT void JNICALL Java_com_jogamp_openmax_OMXInstance__1activateStream (JNIEnv *env, jobject instance, jlong ptr) { OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); @@ -171,28 +171,28 @@ JNIEXPORT void JNICALL Java_com_sun_openmax_OMXInstance__1activateStream } } -JNIEXPORT void JNICALL Java_com_sun_openmax_OMXInstance__1attachVideoRenderer +JNIEXPORT void JNICALL Java_com_jogamp_openmax_OMXInstance__1attachVideoRenderer (JNIEnv *env, jobject instance, jlong ptr) { OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); OMXToolBasicAV_AttachVideoRenderer(pOMXAV); } -JNIEXPORT void JNICALL Java_com_sun_openmax_OMXInstance__1detachVideoRenderer +JNIEXPORT void JNICALL Java_com_jogamp_openmax_OMXInstance__1detachVideoRenderer (JNIEnv *env, jobject instance, jlong ptr) { OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); OMXToolBasicAV_DetachVideoRenderer(pOMXAV); } -JNIEXPORT void JNICALL Java_com_sun_openmax_OMXInstance__1setPlaySpeed +JNIEXPORT void JNICALL Java_com_jogamp_openmax_OMXInstance__1setPlaySpeed (JNIEnv *env, jobject instance, jlong ptr, jfloat scale) { OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); OMXToolBasicAV_SetPlaySpeed(pOMXAV, scale); } -JNIEXPORT jfloat JNICALL Java_com_sun_openmax_OMXInstance__1play +JNIEXPORT jfloat JNICALL Java_com_jogamp_openmax_OMXInstance__1play (JNIEnv *env, jobject instance, jlong ptr) { OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); @@ -200,7 +200,7 @@ JNIEXPORT jfloat JNICALL Java_com_sun_openmax_OMXInstance__1play return OMXToolBasicAV_GetCurrentPosition(pOMXAV); } -JNIEXPORT jfloat JNICALL Java_com_sun_openmax_OMXInstance__1pause +JNIEXPORT jfloat JNICALL Java_com_jogamp_openmax_OMXInstance__1pause (JNIEnv *env, jobject instance, jlong ptr) { OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); @@ -208,7 +208,7 @@ JNIEXPORT jfloat JNICALL Java_com_sun_openmax_OMXInstance__1pause return OMXToolBasicAV_GetCurrentPosition(pOMXAV); } -JNIEXPORT jfloat JNICALL Java_com_sun_openmax_OMXInstance__1stop +JNIEXPORT jfloat JNICALL Java_com_jogamp_openmax_OMXInstance__1stop (JNIEnv *env, jobject instance, jlong ptr) { OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); @@ -216,7 +216,7 @@ JNIEXPORT jfloat JNICALL Java_com_sun_openmax_OMXInstance__1stop return OMXToolBasicAV_GetCurrentPosition(pOMXAV); } -JNIEXPORT jfloat JNICALL Java_com_sun_openmax_OMXInstance__1seek +JNIEXPORT jfloat JNICALL Java_com_jogamp_openmax_OMXInstance__1seek (JNIEnv *env, jobject instance, jlong ptr, jfloat pos) { OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); @@ -224,7 +224,7 @@ JNIEXPORT jfloat JNICALL Java_com_sun_openmax_OMXInstance__1seek return OMXToolBasicAV_GetCurrentPosition(pOMXAV); } -JNIEXPORT jint JNICALL Java_com_sun_openmax_OMXInstance__1getNextTextureID +JNIEXPORT jint JNICALL Java_com_jogamp_openmax_OMXInstance__1getNextTextureID (JNIEnv *env, jobject instance, jlong ptr) { jint textureID = 0xffffffff; @@ -235,7 +235,7 @@ JNIEXPORT jint JNICALL Java_com_sun_openmax_OMXInstance__1getNextTextureID return textureID; } -JNIEXPORT jfloat JNICALL Java_com_sun_openmax_OMXInstance__1getCurrentPosition +JNIEXPORT jfloat JNICALL Java_com_jogamp_openmax_OMXInstance__1getCurrentPosition (JNIEnv *env, jobject instance, jlong ptr) { OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); @@ -243,7 +243,7 @@ JNIEXPORT jfloat JNICALL Java_com_sun_openmax_OMXInstance__1getCurrentPosition } -JNIEXPORT void JNICALL Java_com_sun_openmax_OMXInstance__1destroyInstance +JNIEXPORT void JNICALL Java_com_jogamp_openmax_OMXInstance__1destroyInstance (JNIEnv *env, jobject instance, jlong ptr) { OMXToolBasicAV_t *pOMXAV = (OMXToolBasicAV_t *)((void *)((intptr_t)ptr)); diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/Debug.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/Debug.java new file mode 100644 index 000000000..edb682392 --- /dev/null +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/Debug.java @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2003-2005 Sun Microsystems, Inc. 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. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.nativewindow.impl; + +import java.security.*; + +/** Helper routines for logging and debugging. */ + +public class Debug { + // Some common properties + private static boolean verbose; + private static boolean debugAll; + private static AccessControlContext localACC; + + static { + localACC=AccessController.getContext(); + verbose = isPropertyDefined("nativewindow.verbose", true); + debugAll = isPropertyDefined("nativewindow.debug", true); + if (verbose) { + Package p = Package.getPackage("javax.media.nativewindow"); + System.err.println("NativeWindow specification version " + p.getSpecificationVersion()); + System.err.println("NativeWindow implementation version " + p.getImplementationVersion()); + System.err.println("NativeWindow implementation vendor " + p.getImplementationVendor()); + } + } + + static int getIntProperty(final String property, final boolean jnlpAlias) { + return getIntProperty(property, jnlpAlias, localACC); + } + + public static int getIntProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + int i=0; + try { + Integer iv = Integer.valueOf(Debug.getProperty(property, jnlpAlias, acc)); + i = iv.intValue(); + } catch (NumberFormatException nfe) {} + return i; + } + + static boolean getBooleanProperty(final String property, final boolean jnlpAlias) { + return getBooleanProperty(property, jnlpAlias, localACC); + } + + public static boolean getBooleanProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + Boolean b = Boolean.valueOf(Debug.getProperty(property, jnlpAlias, acc)); + return b.booleanValue(); + } + + static boolean isPropertyDefined(final String property, final boolean jnlpAlias) { + return isPropertyDefined(property, jnlpAlias, localACC); + } + + public static boolean isPropertyDefined(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + return (Debug.getProperty(property, jnlpAlias, acc) != null) ? true : false; + } + + static String getProperty(final String property, final boolean jnlpAlias) { + return getProperty(property, jnlpAlias, localACC); + } + + public static String getProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + String s=null; + if(null!=acc && acc.equals(localACC)) { + s = (String) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String val=null; + try { + val = System.getProperty(property); + } catch (Exception e) {} + if(null==val && jnlpAlias && !property.startsWith(jnlp_prefix)) { + try { + val = System.getProperty(jnlp_prefix + property); + } catch (Exception e) {} + } + return val; + } + }); + } else { + try { + s = System.getProperty(property); + } catch (Exception e) {} + if(null==s && jnlpAlias && !property.startsWith(jnlp_prefix)) { + try { + s = System.getProperty(jnlp_prefix + property); + } catch (Exception e) {} + } + } + return s; + } + public static final String jnlp_prefix = "jnlp." ; + + public static boolean verbose() { + return verbose; + } + + public static boolean debugAll() { + return debugAll; + } + + public static boolean debug(String subcomponent) { + return debugAll() || isPropertyDefined("nativewindow.debug." + subcomponent, true); + } +} diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/GraphicsConfigurationFactoryImpl.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/GraphicsConfigurationFactoryImpl.java new file mode 100644 index 000000000..22f2d544f --- /dev/null +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/GraphicsConfigurationFactoryImpl.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. 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. + */ + +package com.jogamp.nativewindow.impl; + +import javax.media.nativewindow.*; + +public class GraphicsConfigurationFactoryImpl extends GraphicsConfigurationFactory { + public AbstractGraphicsConfiguration chooseGraphicsConfiguration(Capabilities capabilities, + CapabilitiesChooser chooser, + AbstractGraphicsScreen screen) { + return new DefaultGraphicsConfiguration(screen, capabilities, capabilities); + } +} diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/InternalBufferUtil.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/InternalBufferUtil.java new file mode 100644 index 000000000..f590e9b8b --- /dev/null +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/InternalBufferUtil.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.nativewindow.impl; + +import java.lang.reflect.*; +import java.nio.*; + +/** Internal copy of selected routines from BufferUtil to avoid + outward dependencies on com.jogamp.opengl.util package. */ +public class InternalBufferUtil { + public static final int SIZEOF_BYTE = 1; + public static final int SIZEOF_SHORT = 2; + public static final int SIZEOF_INT = 4; + public static final int SIZEOF_FLOAT = 4; + + //---------------------------------------------------------------------- + // Allocation routines + // + + /** Allocates a new direct ByteBuffer with the specified number of + elements. The returned buffer will have its byte order set to + the host platform's native byte order. */ + public static ByteBuffer newByteBuffer(int numElements) { + ByteBuffer bb = ByteBuffer.allocateDirect(numElements); + nativeOrder(bb); + return bb; + } + + /** Allocates a new direct IntBuffer with the specified number of + elements. The returned buffer will have its byte order set to + the host platform's native byte order. */ + public static IntBuffer newIntBuffer(int numElements) { + ByteBuffer bb = newByteBuffer(numElements * SIZEOF_INT); + return bb.asIntBuffer(); + } + + //---------------------------------------------------------------------- + // Copy routines (type-to-type) + // + + /** Copies the remaining elements (as defined by + limit() - position()) in the passed ByteBuffer into + a newly-allocated direct ByteBuffer. The returned buffer will + have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static ByteBuffer copyByteBuffer(ByteBuffer orig) { + ByteBuffer dest = newByteBuffer(orig.remaining()); + dest.put(orig); + dest.rewind(); + return dest; + } + + //---------------------------------------------------------------------- + // Conversion routines + // + + public static ByteBuffer nativeOrder(ByteBuffer buf) { + if (!isCDCFP) { + try { + if (byteOrderClass == null) { + byteOrderClass = Class.forName("java.nio.ByteOrder"); + orderMethod = ByteBuffer.class.getMethod("order", new Class[] { byteOrderClass }); + Method nativeOrderMethod = byteOrderClass.getMethod("nativeOrder", null); + nativeOrderObject = nativeOrderMethod.invoke(null, null); + } + } catch (Throwable t) { + // Must be running on CDC / FP + isCDCFP = true; + } + + if (!isCDCFP) { + try { + orderMethod.invoke(buf, new Object[] { nativeOrderObject }); + } catch (Throwable t) { + } + } + } + return buf; + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + // NOTE that this work must be done reflectively at the present time + // because this code must compile and run correctly on both CDC/FP and J2SE + private static boolean isCDCFP; + private static Class byteOrderClass; + private static Object nativeOrderObject; + private static Method orderMethod; +} diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/LockingNativeWindowFactory.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/LockingNativeWindowFactory.java new file mode 100644 index 000000000..fd2478ab2 --- /dev/null +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/LockingNativeWindowFactory.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. 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. + */ + +package com.jogamp.nativewindow.impl; + +import javax.media.nativewindow.*; + +public class LockingNativeWindowFactory extends NativeWindowFactoryImpl { + // Provides a generic basic and recursive locking mechanism for your discretion. + private ToolkitLock toolkitLock = new ToolkitLock() { + private Thread owner; + private int recursionCount; + + public synchronized void lock() { + Thread cur = Thread.currentThread(); + if (owner == cur) { + ++recursionCount; + return; + } + while (owner != null) { + try { + wait(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + owner = cur; + } + + public synchronized void unlock() { + if (owner != Thread.currentThread()) { + throw new RuntimeException("Not owner"); + } + if (recursionCount > 0) { + --recursionCount; + return; + } + owner = null; + notifyAll(); + } + }; + + public ToolkitLock getToolkitLock() { + return toolkitLock; + } +} diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWReflection.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWReflection.java new file mode 100644 index 000000000..22bdedac9 --- /dev/null +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWReflection.java @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. 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 com.jogamp.nativewindow.impl; + +import java.lang.reflect.*; +import javax.media.nativewindow.*; + +public final class NWReflection { + public static final boolean DEBUG = Debug.debug("NWReflection"); + + public static final boolean isClassAvailable(String clazzName) { + try { + Class clazz = Class.forName(clazzName, false, NWReflection.class.getClassLoader()); + return null!=clazz; + } catch (Throwable e) { } + return false; + } + + public static final Class getClass(String clazzName, boolean initialize) { + try { + return Class.forName(clazzName, initialize, NWReflection.class.getClassLoader()); + } catch (Throwable e) { } + return null; + } + + public static final Constructor getConstructor(String clazzName, Class[] cstrArgTypes) { + Class factoryClass = null; + Constructor factory = null; + + try { + factoryClass = getClass(clazzName, true); + if (factoryClass == null) { + throw new NativeWindowException(clazzName + " not available"); + } + return getConstructor(factoryClass, cstrArgTypes); + } catch (Throwable e) { + if (DEBUG) { + e.printStackTrace(); + } + throw new NativeWindowException(e); + } + } + + public static final Constructor getConstructor(Class clazz, Class[] cstrArgTypes) { + Constructor factory = null; + + try { + try { + factory = clazz.getDeclaredConstructor( cstrArgTypes ); + } catch(NoSuchMethodException nsme) { + throw new NativeWindowException("Constructor: '" + clazz + "("+cstrArgTypes+")' not found"); + } + return factory; + } catch (Throwable e) { + if (DEBUG) { + e.printStackTrace(); + } + throw new NativeWindowException(e); + } + } + + public static final Constructor getConstructor(String clazzName) { + return getConstructor(clazzName, new Class[0]); + } + + public static final Object createInstance(Class clazz, Class[] cstrArgTypes, Object[] cstrArgs) { + Constructor factory = null; + + try { + factory = getConstructor(clazz, cstrArgTypes); + return factory.newInstance( cstrArgs ) ; + } catch (Exception e) { + throw new NativeWindowException(e); + } + } + + public static final Object createInstance(Class clazz, Object[] cstrArgs) { + Class[] cstrArgTypes = new Class[cstrArgs.length]; + for(int i=0; i=0; i--) { + Class face = clazzes[i]; + if(face.getName().equals(faceName)) { + return true; + } + } + clazz = clazz.getSuperclass(); + } while (clazz!=null); + return false; + } + + public static boolean isAWTComponent(Object target) { + return instanceOf(target, "java.awt.Component"); + } + + public static boolean isAWTComponent(Class clazz) { + return instanceOf(clazz, "java.awt.Component"); + } + +} + diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeLibLoaderBase.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeLibLoaderBase.java new file mode 100644 index 000000000..0670234d4 --- /dev/null +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeLibLoaderBase.java @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. 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. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.nativewindow.impl; + +// FIXME: refactor Java SE dependencies +//import java.awt.Toolkit; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.HashSet; + +public class NativeLibLoaderBase { + public static final boolean DEBUG = Debug.debug("NativeLibLoader"); + + public interface LoaderAction { + /** + * Loads the library specified by libname. Optionally preloads the libraries specified by + * preload. The implementation should ignore, if the preload-libraries have already been + * loaded. + * @param libname the library to load + * @param preload the libraries to load before loading the main library if not null + * @param preloadIgnoreError true, if errors during loading the preload-libraries should be ignored + */ + void loadLibrary(String libname, String[] preload, + boolean preloadIgnoreError); + } + + private static class DefaultAction implements LoaderAction { + public void loadLibrary(String libname, String[] preload, + boolean preloadIgnoreError) { + if (null!=preload) { + for (int i=0; i + 4395095 JNI access to java.nio DirectBuffer constructor/accessor + 6852404 Race condition in JNI Direct Buffer access and creation routines + + * + * Make sure to initialize this class as soon as possible, + * before doing any multithreading work. + * + */ +public class JVMUtil { + private static final boolean DEBUG = Debug.debug("JVMUtil"); + + static { + NativeLibLoaderBase.loadNativeWindow("jvm"); + + ByteBuffer buffer = InternalBufferUtil.newByteBuffer(64); + if( ! initialize(buffer) ) { + throw new RuntimeException("Failed to initialize the JVMUtil "+Thread.currentThread().getName()); + } + if(DEBUG) { + Exception e = new Exception("JVMUtil.initSingleton() .. initialized "+Thread.currentThread().getName()); + e.printStackTrace(); + } + } + + public static void initSingleton() { + } + + private JVMUtil() {} + + private static native boolean initialize(java.nio.ByteBuffer buffer); +} + diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java new file mode 100644 index 000000000..4ffda2fae --- /dev/null +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + */ + +package com.jogamp.nativewindow.impl.x11; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; +import com.jogamp.nativewindow.impl.x11.XVisualInfo; +import com.jogamp.nativewindow.impl.x11.X11Lib; + +public class X11GraphicsConfigurationFactory extends GraphicsConfigurationFactory { + public AbstractGraphicsConfiguration + chooseGraphicsConfiguration(Capabilities capabilities, + CapabilitiesChooser chooser, + AbstractGraphicsScreen screen) + throws IllegalArgumentException, NativeWindowException { + + if(null==screen || !(screen instanceof X11GraphicsScreen)) { + throw new NativeWindowException("Only valid X11GraphicsScreen are allowed"); + } + return new X11GraphicsConfiguration((X11GraphicsScreen)screen, capabilities, capabilities, getXVisualInfo(screen, capabilities)); + } + + public static XVisualInfo getXVisualInfo(AbstractGraphicsScreen screen, long visualID) + { + XVisualInfo xvi_temp = XVisualInfo.create(); + xvi_temp.setVisualid(visualID); + xvi_temp.setScreen(screen.getIndex()); + int num[] = { -1 }; + long display = screen.getDevice().getHandle(); + + try { + X11Lib.XLockDisplay(display); + XVisualInfo[] xvis = X11Lib.XGetVisualInfoCopied(display, X11Lib.VisualIDMask|X11Lib.VisualScreenMask, xvi_temp, num, 0); + + if(xvis==null || num[0]<1) { + return null; + } + + return XVisualInfo.create(xvis[0]); + } finally { + X11Lib.XUnlockDisplay(display); + } + + } + + public static XVisualInfo getXVisualInfo(AbstractGraphicsScreen screen, Capabilities capabilities) + { + XVisualInfo xv = getXVisualInfoImpl(screen, capabilities, 4 /* TrueColor */); + if(null!=xv) return xv; + return getXVisualInfoImpl(screen, capabilities, 5 /* DirectColor */); + } + + private static XVisualInfo getXVisualInfoImpl(AbstractGraphicsScreen screen, Capabilities capabilities, int c_class) + { + XVisualInfo ret = null; + int[] num = { -1 }; + + XVisualInfo vinfo_template = XVisualInfo.create(); + vinfo_template.setScreen(screen.getIndex()); + vinfo_template.setC_class(c_class); + long display = screen.getDevice().getHandle(); + + try { + X11Lib.XLockDisplay(display); + XVisualInfo[] vinfos = X11Lib.XGetVisualInfoCopied(display, X11Lib.VisualScreenMask, vinfo_template, num, 0); + XVisualInfo best=null; + int rdepth = capabilities.getRedBits() + capabilities.getGreenBits() + capabilities.getBlueBits() + capabilities.getAlphaBits(); + for (int i = 0; vinfos!=null && i < num[0]; i++) { + if ( best == null || + best.getDepth() < vinfos[i].getDepth() ) + { + best = vinfos[i]; + if(rdepth <= best.getDepth()) + break; + } + } + if ( null!=best && ( rdepth <= best.getDepth() || 24 == best.getDepth()) ) { + ret = XVisualInfo.create(best); + } + best = null; + + return ret; + } finally { + X11Lib.XUnlockDisplay(display); + } + } +} + diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java new file mode 100644 index 000000000..9fc986180 --- /dev/null +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + */ + +package com.jogamp.nativewindow.impl.x11; + +import java.util.HashMap; +import java.util.Map; + +import javax.media.nativewindow.*; + +import com.jogamp.nativewindow.impl.*; + +/** + * Contains a thread safe X11 utility to retrieve thread local display connection,
+ * as well as the static global discplay connection.
+ * + * The TLS variant is thread safe per se, but be aware of the memory leak risk + * where an application heavily utilizing this class on temporary new threads.
+ */ +public class X11Util { + private static final boolean DEBUG = Debug.debug("X11Util"); + + static { + NativeLibLoaderBase.loadNativeWindow("x11"); + } + + private X11Util() {} + + private static ThreadLocal currentDisplayMap = new ThreadLocal(); + + public static class NamedDisplay implements Cloneable { + private String name; + private long handle; + + protected NamedDisplay(String name, long handle) { + this.name=name; + this.handle=handle; + } + + public String getName() { return name; } + public long getHandle() { return handle; } + + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + } + + /** Returns a clone of the thread local display map, you may {@link Object#wait()} on it */ + public static Map getCurrentDisplayMap() { + return (Map) ((HashMap)getCurrentDisplayMapImpl()).clone(); + } + + /** Returns this thread current default display. If it doesn not exist, it is being created */ + public static long getThreadLocalDefaultDisplay() { + return getThreadLocalDisplay(null); + } + + /** Returns this thread named display. If it doesn not exist, it is being created */ + public static long getThreadLocalDisplay(String name) { + NamedDisplay namedDpy = getCurrentDisplay(name); + if(null==namedDpy) { + long dpy = X11Lib.XOpenDisplay(name); + if(0==dpy) { + throw new NativeWindowException("X11Util.Display: Unable to create a display("+name+") connection in Thread "+Thread.currentThread().getName()); + } + namedDpy = new NamedDisplay(name, dpy); + setCurrentDisplay( namedDpy ); + if(DEBUG) { + Exception e = new Exception("X11Util.Display: Created new TLS display("+name+") connection 0x"+Long.toHexString(dpy)+" in thread "+Thread.currentThread().getName()); + e.printStackTrace(); + } + } + return namedDpy.getHandle(); + } + + /** Closes this thread named display. It returns the handle of the closed display or 0, if it does not exist. */ + public static long closeThreadLocalDisplay(String name) { + NamedDisplay namedDpy = removeCurrentDisplay(name); + if(null==namedDpy) { + if(DEBUG) { + Exception e = new Exception("X11Util.Display: Display("+name+") with given handle is not mapped to TLS in thread "+Thread.currentThread().getName()); + e.printStackTrace(); + } + return 0; + } + long dpy = namedDpy.getHandle(); + X11Lib.XCloseDisplay(dpy); + if(DEBUG) { + Exception e = new Exception("X11Util.Display: Closed TLS Display("+name+") with handle 0x"+Long.toHexString(dpy)+" in thread "+Thread.currentThread().getName()); + e.printStackTrace(); + } + return dpy; + } + + private static Map getCurrentDisplayMapImpl() { + Map displayMap = (Map) currentDisplayMap.get(); + if(null==displayMap) { + displayMap = new HashMap(); + currentDisplayMap.set( displayMap ); + } + return displayMap; + } + + /** maps the given display to the thread local display map + * and notifies all threads synchronized to this display map. */ + private static NamedDisplay setCurrentDisplay(NamedDisplay newDisplay) { + Map displayMap = getCurrentDisplayMapImpl(); + NamedDisplay oldDisplay = null; + synchronized(displayMap) { + String name = (null==newDisplay.getName())?"nil":newDisplay.getName(); + oldDisplay = (NamedDisplay) displayMap.put(name, newDisplay); + displayMap.notifyAll(); + } + return oldDisplay; + } + + /** removes the mapping of the given name from the thread local display map + * and notifies all threads synchronized to this display map. */ + private static NamedDisplay removeCurrentDisplay(String name) { + Map displayMap = getCurrentDisplayMapImpl(); + NamedDisplay oldDisplay = null; + synchronized(displayMap) { + if(null==name) name="nil"; + oldDisplay = (NamedDisplay) displayMap.remove(name); + displayMap.notifyAll(); + } + return oldDisplay; + } + + /** Returns the thread local display mapped to the given name */ + private static NamedDisplay getCurrentDisplay(String name) { + if(null==name) name="nil"; + Map displayMap = getCurrentDisplayMapImpl(); + return (NamedDisplay) displayMap.get(name); + } + +} diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java new file mode 100644 index 000000000..616220e14 --- /dev/null +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2008-2009 Sun Microsystems, Inc. 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. + */ + +package com.jogamp.nativewindow.impl.x11.awt; + +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import javax.media.nativewindow.*; + +import com.jogamp.nativewindow.impl.*; +import com.jogamp.nativewindow.impl.jawt.*; +import com.jogamp.nativewindow.impl.jawt.x11.*; +import com.jogamp.nativewindow.impl.x11.*; + +public class X11AWTNativeWindowFactory extends NativeWindowFactoryImpl { + + // When running the AWT on X11 platforms, we use the AWT native + // interface (JAWT) to lock and unlock the toolkit + private ToolkitLock toolkitLock = new ToolkitLock() { + private Thread owner; + private int recursionCount; + + public synchronized void lock() { + Thread cur = Thread.currentThread(); + if (owner == cur) { + ++recursionCount; + return; + } + while (owner != null) { + try { + wait(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + owner = cur; + JAWTUtil.lockToolkit(); + } + + public synchronized void unlock() { + if (owner != Thread.currentThread()) { + throw new RuntimeException("Not owner"); + } + if (recursionCount > 0) { + --recursionCount; + return; + } + owner = null; + JAWTUtil.unlockToolkit(); + notifyAll(); + } + }; + + public ToolkitLock getToolkitLock() { + return toolkitLock; + } +} diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/Debug.java b/src/nativewindow/classes/com/sun/nativewindow/impl/Debug.java deleted file mode 100644 index dd967c71a..000000000 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/Debug.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) 2003-2005 Sun Microsystems, Inc. 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. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.sun.nativewindow.impl; - -import java.security.*; - -/** Helper routines for logging and debugging. */ - -public class Debug { - // Some common properties - private static boolean verbose; - private static boolean debugAll; - private static AccessControlContext localACC; - - static { - localACC=AccessController.getContext(); - verbose = isPropertyDefined("nativewindow.verbose", true); - debugAll = isPropertyDefined("nativewindow.debug", true); - if (verbose) { - Package p = Package.getPackage("javax.media.nativewindow"); - System.err.println("NativeWindow specification version " + p.getSpecificationVersion()); - System.err.println("NativeWindow implementation version " + p.getImplementationVersion()); - System.err.println("NativeWindow implementation vendor " + p.getImplementationVendor()); - } - } - - static int getIntProperty(final String property, final boolean jnlpAlias) { - return getIntProperty(property, jnlpAlias, localACC); - } - - public static int getIntProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { - int i=0; - try { - Integer iv = Integer.valueOf(Debug.getProperty(property, jnlpAlias, acc)); - i = iv.intValue(); - } catch (NumberFormatException nfe) {} - return i; - } - - static boolean getBooleanProperty(final String property, final boolean jnlpAlias) { - return getBooleanProperty(property, jnlpAlias, localACC); - } - - public static boolean getBooleanProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { - Boolean b = Boolean.valueOf(Debug.getProperty(property, jnlpAlias, acc)); - return b.booleanValue(); - } - - static boolean isPropertyDefined(final String property, final boolean jnlpAlias) { - return isPropertyDefined(property, jnlpAlias, localACC); - } - - public static boolean isPropertyDefined(final String property, final boolean jnlpAlias, final AccessControlContext acc) { - return (Debug.getProperty(property, jnlpAlias, acc) != null) ? true : false; - } - - static String getProperty(final String property, final boolean jnlpAlias) { - return getProperty(property, jnlpAlias, localACC); - } - - public static String getProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { - String s=null; - if(null!=acc && acc.equals(localACC)) { - s = (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - String val=null; - try { - val = System.getProperty(property); - } catch (Exception e) {} - if(null==val && jnlpAlias && !property.startsWith(jnlp_prefix)) { - try { - val = System.getProperty(jnlp_prefix + property); - } catch (Exception e) {} - } - return val; - } - }); - } else { - try { - s = System.getProperty(property); - } catch (Exception e) {} - if(null==s && jnlpAlias && !property.startsWith(jnlp_prefix)) { - try { - s = System.getProperty(jnlp_prefix + property); - } catch (Exception e) {} - } - } - return s; - } - public static final String jnlp_prefix = "jnlp." ; - - public static boolean verbose() { - return verbose; - } - - public static boolean debugAll() { - return debugAll; - } - - public static boolean debug(String subcomponent) { - return debugAll() || isPropertyDefined("nativewindow.debug." + subcomponent, true); - } -} diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/GraphicsConfigurationFactoryImpl.java b/src/nativewindow/classes/com/sun/nativewindow/impl/GraphicsConfigurationFactoryImpl.java deleted file mode 100644 index 4e8e281a8..000000000 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/GraphicsConfigurationFactoryImpl.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2009 Sun Microsystems, Inc. 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. - */ - -package com.sun.nativewindow.impl; - -import javax.media.nativewindow.*; - -public class GraphicsConfigurationFactoryImpl extends GraphicsConfigurationFactory { - public AbstractGraphicsConfiguration chooseGraphicsConfiguration(Capabilities capabilities, - CapabilitiesChooser chooser, - AbstractGraphicsScreen screen) { - return new DefaultGraphicsConfiguration(screen, capabilities, capabilities); - } -} diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/InternalBufferUtil.java b/src/nativewindow/classes/com/sun/nativewindow/impl/InternalBufferUtil.java deleted file mode 100644 index 7cf2e3ff5..000000000 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/InternalBufferUtil.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2009 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.nativewindow.impl; - -import java.lang.reflect.*; -import java.nio.*; - -/** Internal copy of selected routines from BufferUtil to avoid - outward dependencies on com.jogamp.opengl.util package. */ -public class InternalBufferUtil { - public static final int SIZEOF_BYTE = 1; - public static final int SIZEOF_SHORT = 2; - public static final int SIZEOF_INT = 4; - public static final int SIZEOF_FLOAT = 4; - - //---------------------------------------------------------------------- - // Allocation routines - // - - /** Allocates a new direct ByteBuffer with the specified number of - elements. The returned buffer will have its byte order set to - the host platform's native byte order. */ - public static ByteBuffer newByteBuffer(int numElements) { - ByteBuffer bb = ByteBuffer.allocateDirect(numElements); - nativeOrder(bb); - return bb; - } - - /** Allocates a new direct IntBuffer with the specified number of - elements. The returned buffer will have its byte order set to - the host platform's native byte order. */ - public static IntBuffer newIntBuffer(int numElements) { - ByteBuffer bb = newByteBuffer(numElements * SIZEOF_INT); - return bb.asIntBuffer(); - } - - //---------------------------------------------------------------------- - // Copy routines (type-to-type) - // - - /** Copies the remaining elements (as defined by - limit() - position()) in the passed ByteBuffer into - a newly-allocated direct ByteBuffer. The returned buffer will - have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyByteBuffer(ByteBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining()); - dest.put(orig); - dest.rewind(); - return dest; - } - - //---------------------------------------------------------------------- - // Conversion routines - // - - public static ByteBuffer nativeOrder(ByteBuffer buf) { - if (!isCDCFP) { - try { - if (byteOrderClass == null) { - byteOrderClass = Class.forName("java.nio.ByteOrder"); - orderMethod = ByteBuffer.class.getMethod("order", new Class[] { byteOrderClass }); - Method nativeOrderMethod = byteOrderClass.getMethod("nativeOrder", null); - nativeOrderObject = nativeOrderMethod.invoke(null, null); - } - } catch (Throwable t) { - // Must be running on CDC / FP - isCDCFP = true; - } - - if (!isCDCFP) { - try { - orderMethod.invoke(buf, new Object[] { nativeOrderObject }); - } catch (Throwable t) { - } - } - } - return buf; - } - - //---------------------------------------------------------------------- - // Internals only below this point - // - - // NOTE that this work must be done reflectively at the present time - // because this code must compile and run correctly on both CDC/FP and J2SE - private static boolean isCDCFP; - private static Class byteOrderClass; - private static Object nativeOrderObject; - private static Method orderMethod; -} diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/LockingNativeWindowFactory.java b/src/nativewindow/classes/com/sun/nativewindow/impl/LockingNativeWindowFactory.java deleted file mode 100644 index 880fd8c7d..000000000 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/LockingNativeWindowFactory.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2009 Sun Microsystems, Inc. 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. - */ - -package com.sun.nativewindow.impl; - -import javax.media.nativewindow.*; - -public class LockingNativeWindowFactory extends NativeWindowFactoryImpl { - // Provides a generic basic and recursive locking mechanism for your discretion. - private ToolkitLock toolkitLock = new ToolkitLock() { - private Thread owner; - private int recursionCount; - - public synchronized void lock() { - Thread cur = Thread.currentThread(); - if (owner == cur) { - ++recursionCount; - return; - } - while (owner != null) { - try { - wait(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - owner = cur; - } - - public synchronized void unlock() { - if (owner != Thread.currentThread()) { - throw new RuntimeException("Not owner"); - } - if (recursionCount > 0) { - --recursionCount; - return; - } - owner = null; - notifyAll(); - } - }; - - public ToolkitLock getToolkitLock() { - return toolkitLock; - } -} diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/NWReflection.java b/src/nativewindow/classes/com/sun/nativewindow/impl/NWReflection.java deleted file mode 100644 index d86fbdc55..000000000 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/NWReflection.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. 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 com.sun.nativewindow.impl; - -import java.lang.reflect.*; -import javax.media.nativewindow.*; - -public final class NWReflection { - public static final boolean DEBUG = Debug.debug("NWReflection"); - - public static final boolean isClassAvailable(String clazzName) { - try { - Class clazz = Class.forName(clazzName, false, NWReflection.class.getClassLoader()); - return null!=clazz; - } catch (Throwable e) { } - return false; - } - - public static final Class getClass(String clazzName, boolean initialize) { - try { - return Class.forName(clazzName, initialize, NWReflection.class.getClassLoader()); - } catch (Throwable e) { } - return null; - } - - public static final Constructor getConstructor(String clazzName, Class[] cstrArgTypes) { - Class factoryClass = null; - Constructor factory = null; - - try { - factoryClass = getClass(clazzName, true); - if (factoryClass == null) { - throw new NativeWindowException(clazzName + " not available"); - } - return getConstructor(factoryClass, cstrArgTypes); - } catch (Throwable e) { - if (DEBUG) { - e.printStackTrace(); - } - throw new NativeWindowException(e); - } - } - - public static final Constructor getConstructor(Class clazz, Class[] cstrArgTypes) { - Constructor factory = null; - - try { - try { - factory = clazz.getDeclaredConstructor( cstrArgTypes ); - } catch(NoSuchMethodException nsme) { - throw new NativeWindowException("Constructor: '" + clazz + "("+cstrArgTypes+")' not found"); - } - return factory; - } catch (Throwable e) { - if (DEBUG) { - e.printStackTrace(); - } - throw new NativeWindowException(e); - } - } - - public static final Constructor getConstructor(String clazzName) { - return getConstructor(clazzName, new Class[0]); - } - - public static final Object createInstance(Class clazz, Class[] cstrArgTypes, Object[] cstrArgs) { - Constructor factory = null; - - try { - factory = getConstructor(clazz, cstrArgTypes); - return factory.newInstance( cstrArgs ) ; - } catch (Exception e) { - throw new NativeWindowException(e); - } - } - - public static final Object createInstance(Class clazz, Object[] cstrArgs) { - Class[] cstrArgTypes = new Class[cstrArgs.length]; - for(int i=0; i=0; i--) { - Class face = clazzes[i]; - if(face.getName().equals(faceName)) { - return true; - } - } - clazz = clazz.getSuperclass(); - } while (clazz!=null); - return false; - } - - public static boolean isAWTComponent(Object target) { - return instanceOf(target, "java.awt.Component"); - } - - public static boolean isAWTComponent(Class clazz) { - return instanceOf(clazz, "java.awt.Component"); - } - -} - diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java b/src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java deleted file mode 100644 index 570cf1f9d..000000000 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. 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. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.sun.nativewindow.impl; - -// FIXME: refactor Java SE dependencies -//import java.awt.Toolkit; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.HashSet; - -public class NativeLibLoaderBase { - public static final boolean DEBUG = Debug.debug("NativeLibLoader"); - - public interface LoaderAction { - /** - * Loads the library specified by libname. Optionally preloads the libraries specified by - * preload. The implementation should ignore, if the preload-libraries have already been - * loaded. - * @param libname the library to load - * @param preload the libraries to load before loading the main library if not null - * @param preloadIgnoreError true, if errors during loading the preload-libraries should be ignored - */ - void loadLibrary(String libname, String[] preload, - boolean preloadIgnoreError); - } - - private static class DefaultAction implements LoaderAction { - public void loadLibrary(String libname, String[] preload, - boolean preloadIgnoreError) { - if (null!=preload) { - for (int i=0; i - 4395095 JNI access to java.nio DirectBuffer constructor/accessor - 6852404 Race condition in JNI Direct Buffer access and creation routines - - * - * Make sure to initialize this class as soon as possible, - * before doing any multithreading work. - * - */ -public class JVMUtil { - private static final boolean DEBUG = Debug.debug("JVMUtil"); - - static { - NativeLibLoaderBase.loadNativeWindow("jvm"); - - ByteBuffer buffer = InternalBufferUtil.newByteBuffer(64); - if( ! initialize(buffer) ) { - throw new RuntimeException("Failed to initialize the JVMUtil "+Thread.currentThread().getName()); - } - if(DEBUG) { - Exception e = new Exception("JVMUtil.initSingleton() .. initialized "+Thread.currentThread().getName()); - e.printStackTrace(); - } - } - - public static void initSingleton() { - } - - private JVMUtil() {} - - private static native boolean initialize(java.nio.ByteBuffer buffer); -} - diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java deleted file mode 100644 index 4709e3ef0..000000000 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - */ - -package com.sun.nativewindow.impl.x11; - -import javax.media.nativewindow.*; -import javax.media.nativewindow.x11.*; -import com.sun.nativewindow.impl.x11.XVisualInfo; -import com.sun.nativewindow.impl.x11.X11Lib; - -public class X11GraphicsConfigurationFactory extends GraphicsConfigurationFactory { - public AbstractGraphicsConfiguration - chooseGraphicsConfiguration(Capabilities capabilities, - CapabilitiesChooser chooser, - AbstractGraphicsScreen screen) - throws IllegalArgumentException, NativeWindowException { - - if(null==screen || !(screen instanceof X11GraphicsScreen)) { - throw new NativeWindowException("Only valid X11GraphicsScreen are allowed"); - } - return new X11GraphicsConfiguration((X11GraphicsScreen)screen, capabilities, capabilities, getXVisualInfo(screen, capabilities)); - } - - public static XVisualInfo getXVisualInfo(AbstractGraphicsScreen screen, long visualID) - { - XVisualInfo xvi_temp = XVisualInfo.create(); - xvi_temp.setVisualid(visualID); - xvi_temp.setScreen(screen.getIndex()); - int num[] = { -1 }; - long display = screen.getDevice().getHandle(); - - try { - X11Lib.XLockDisplay(display); - XVisualInfo[] xvis = X11Lib.XGetVisualInfoCopied(display, X11Lib.VisualIDMask|X11Lib.VisualScreenMask, xvi_temp, num, 0); - - if(xvis==null || num[0]<1) { - return null; - } - - return XVisualInfo.create(xvis[0]); - } finally { - X11Lib.XUnlockDisplay(display); - } - - } - - public static XVisualInfo getXVisualInfo(AbstractGraphicsScreen screen, Capabilities capabilities) - { - XVisualInfo xv = getXVisualInfoImpl(screen, capabilities, 4 /* TrueColor */); - if(null!=xv) return xv; - return getXVisualInfoImpl(screen, capabilities, 5 /* DirectColor */); - } - - private static XVisualInfo getXVisualInfoImpl(AbstractGraphicsScreen screen, Capabilities capabilities, int c_class) - { - XVisualInfo ret = null; - int[] num = { -1 }; - - XVisualInfo vinfo_template = XVisualInfo.create(); - vinfo_template.setScreen(screen.getIndex()); - vinfo_template.setC_class(c_class); - long display = screen.getDevice().getHandle(); - - try { - X11Lib.XLockDisplay(display); - XVisualInfo[] vinfos = X11Lib.XGetVisualInfoCopied(display, X11Lib.VisualScreenMask, vinfo_template, num, 0); - XVisualInfo best=null; - int rdepth = capabilities.getRedBits() + capabilities.getGreenBits() + capabilities.getBlueBits() + capabilities.getAlphaBits(); - for (int i = 0; vinfos!=null && i < num[0]; i++) { - if ( best == null || - best.getDepth() < vinfos[i].getDepth() ) - { - best = vinfos[i]; - if(rdepth <= best.getDepth()) - break; - } - } - if ( null!=best && ( rdepth <= best.getDepth() || 24 == best.getDepth()) ) { - ret = XVisualInfo.create(best); - } - best = null; - - return ret; - } finally { - X11Lib.XUnlockDisplay(display); - } - } -} - diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java deleted file mode 100644 index 11343f3e1..000000000 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - */ - -package com.sun.nativewindow.impl.x11; - -import java.util.HashMap; -import java.util.Map; - -import javax.media.nativewindow.*; - -import com.sun.nativewindow.impl.*; - -/** - * Contains a thread safe X11 utility to retrieve thread local display connection,
- * as well as the static global discplay connection.
- * - * The TLS variant is thread safe per se, but be aware of the memory leak risk - * where an application heavily utilizing this class on temporary new threads.
- */ -public class X11Util { - private static final boolean DEBUG = Debug.debug("X11Util"); - - static { - NativeLibLoaderBase.loadNativeWindow("x11"); - } - - private X11Util() {} - - private static ThreadLocal currentDisplayMap = new ThreadLocal(); - - public static class NamedDisplay implements Cloneable { - private String name; - private long handle; - - protected NamedDisplay(String name, long handle) { - this.name=name; - this.handle=handle; - } - - public String getName() { return name; } - public long getHandle() { return handle; } - - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } - } - - /** Returns a clone of the thread local display map, you may {@link Object#wait()} on it */ - public static Map getCurrentDisplayMap() { - return (Map) ((HashMap)getCurrentDisplayMapImpl()).clone(); - } - - /** Returns this thread current default display. If it doesn not exist, it is being created */ - public static long getThreadLocalDefaultDisplay() { - return getThreadLocalDisplay(null); - } - - /** Returns this thread named display. If it doesn not exist, it is being created */ - public static long getThreadLocalDisplay(String name) { - NamedDisplay namedDpy = getCurrentDisplay(name); - if(null==namedDpy) { - long dpy = X11Lib.XOpenDisplay(name); - if(0==dpy) { - throw new NativeWindowException("X11Util.Display: Unable to create a display("+name+") connection in Thread "+Thread.currentThread().getName()); - } - namedDpy = new NamedDisplay(name, dpy); - setCurrentDisplay( namedDpy ); - if(DEBUG) { - Exception e = new Exception("X11Util.Display: Created new TLS display("+name+") connection 0x"+Long.toHexString(dpy)+" in thread "+Thread.currentThread().getName()); - e.printStackTrace(); - } - } - return namedDpy.getHandle(); - } - - /** Closes this thread named display. It returns the handle of the closed display or 0, if it does not exist. */ - public static long closeThreadLocalDisplay(String name) { - NamedDisplay namedDpy = removeCurrentDisplay(name); - if(null==namedDpy) { - if(DEBUG) { - Exception e = new Exception("X11Util.Display: Display("+name+") with given handle is not mapped to TLS in thread "+Thread.currentThread().getName()); - e.printStackTrace(); - } - return 0; - } - long dpy = namedDpy.getHandle(); - X11Lib.XCloseDisplay(dpy); - if(DEBUG) { - Exception e = new Exception("X11Util.Display: Closed TLS Display("+name+") with handle 0x"+Long.toHexString(dpy)+" in thread "+Thread.currentThread().getName()); - e.printStackTrace(); - } - return dpy; - } - - private static Map getCurrentDisplayMapImpl() { - Map displayMap = (Map) currentDisplayMap.get(); - if(null==displayMap) { - displayMap = new HashMap(); - currentDisplayMap.set( displayMap ); - } - return displayMap; - } - - /** maps the given display to the thread local display map - * and notifies all threads synchronized to this display map. */ - private static NamedDisplay setCurrentDisplay(NamedDisplay newDisplay) { - Map displayMap = getCurrentDisplayMapImpl(); - NamedDisplay oldDisplay = null; - synchronized(displayMap) { - String name = (null==newDisplay.getName())?"nil":newDisplay.getName(); - oldDisplay = (NamedDisplay) displayMap.put(name, newDisplay); - displayMap.notifyAll(); - } - return oldDisplay; - } - - /** removes the mapping of the given name from the thread local display map - * and notifies all threads synchronized to this display map. */ - private static NamedDisplay removeCurrentDisplay(String name) { - Map displayMap = getCurrentDisplayMapImpl(); - NamedDisplay oldDisplay = null; - synchronized(displayMap) { - if(null==name) name="nil"; - oldDisplay = (NamedDisplay) displayMap.remove(name); - displayMap.notifyAll(); - } - return oldDisplay; - } - - /** Returns the thread local display mapped to the given name */ - private static NamedDisplay getCurrentDisplay(String name) { - if(null==name) name="nil"; - Map displayMap = getCurrentDisplayMapImpl(); - return (NamedDisplay) displayMap.get(name); - } - -} diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java deleted file mode 100644 index dff733735..000000000 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2008-2009 Sun Microsystems, Inc. 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. - */ - -package com.sun.nativewindow.impl.x11.awt; - -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsDevice; -import java.awt.GraphicsEnvironment; -import javax.media.nativewindow.*; - -import com.sun.nativewindow.impl.*; -import com.sun.nativewindow.impl.jawt.*; -import com.sun.nativewindow.impl.jawt.x11.*; -import com.sun.nativewindow.impl.x11.*; - -public class X11AWTNativeWindowFactory extends NativeWindowFactoryImpl { - - // When running the AWT on X11 platforms, we use the AWT native - // interface (JAWT) to lock and unlock the toolkit - private ToolkitLock toolkitLock = new ToolkitLock() { - private Thread owner; - private int recursionCount; - - public synchronized void lock() { - Thread cur = Thread.currentThread(); - if (owner == cur) { - ++recursionCount; - return; - } - while (owner != null) { - try { - wait(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - owner = cur; - JAWTUtil.lockToolkit(); - } - - public synchronized void unlock() { - if (owner != Thread.currentThread()) { - throw new RuntimeException("Not owner"); - } - if (recursionCount > 0) { - --recursionCount; - return; - } - owner = null; - JAWTUtil.unlockToolkit(); - notifyAll(); - } - }; - - public ToolkitLock getToolkitLock() { - return toolkitLock; - } -} diff --git a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java index 881499bec..a8b67fddc 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java +++ b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java @@ -35,7 +35,7 @@ package javax.media.nativewindow; import java.lang.reflect.*; import java.util.*; -import com.sun.nativewindow.impl.*; +import com.jogamp.nativewindow.impl.*; /** * Provides the mechanism by which the graphics configuration for a @@ -77,7 +77,7 @@ public abstract class GraphicsConfigurationFactory { if (NativeWindowFactory.TYPE_X11.equals(NativeWindowFactory.getNativeWindowType(true))) { try { GraphicsConfigurationFactory factory = (GraphicsConfigurationFactory) - NWReflection.createInstance("com.sun.nativewindow.impl.x11.X11GraphicsConfigurationFactory", new Object[] {}); + NWReflection.createInstance("com.jogamp.nativewindow.impl.x11.X11GraphicsConfigurationFactory", new Object[] {}); registerFactory(javax.media.nativewindow.x11.X11GraphicsDevice.class, factory); } catch (Exception e) { throw new RuntimeException(e); diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java index cd89e2164..5b1bf54bb 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java @@ -36,8 +36,8 @@ import java.lang.reflect.*; import java.security.*; import java.util.*; -import com.sun.nativewindow.impl.*; -import com.sun.nativewindow.impl.jvm.JVMUtil; +import com.jogamp.nativewindow.impl.*; +import com.jogamp.nativewindow.impl.jvm.JVMUtil; /** Provides a pluggable mechanism for arbitrary window toolkits to adapt their components to the {@link NativeWindow} interface, @@ -177,7 +177,7 @@ public abstract class NativeWindowFactory { try { Constructor factoryConstructor = - NWReflection.getConstructor("com.sun.nativewindow.impl.x11.awt.X11AWTNativeWindowFactory", new Class[] {}); + NWReflection.getConstructor("com.jogamp.nativewindow.impl.x11.awt.X11AWTNativeWindowFactory", new Class[] {}); _factory = (NativeWindowFactory) factoryConstructor.newInstance(null); } catch (Exception e) { } } @@ -185,7 +185,7 @@ public abstract class NativeWindowFactory { if (toolkitLockForced && null==_factory) { try { Constructor factoryConstructor = - NWReflection.getConstructor("com.sun.nativewindow.impl.LockingNativeWindowFactory", new Class[] {}); + NWReflection.getConstructor("com.jogamp.nativewindow.impl.LockingNativeWindowFactory", new Class[] {}); _factory = (NativeWindowFactory) factoryConstructor.newInstance(null); } catch (Exception e) { } } diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java index 7373e7b97..9b48f8f6e 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java +++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java @@ -44,7 +44,7 @@ import java.awt.GraphicsConfiguration; import java.awt.Transparency; import java.awt.image.ColorModel; import javax.media.nativewindow.AbstractGraphicsConfiguration; -import com.sun.nativewindow.impl.Debug; +import com.jogamp.nativewindow.impl.Debug; /** A wrapper for an AWT GraphicsConfiguration allowing it to be handled in a toolkit-independent manner. */ diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java index 077cbf8aa..d326b9159 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java +++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java @@ -43,7 +43,7 @@ import javax.media.nativewindow.*; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import javax.media.nativewindow.AbstractGraphicsDevice; -import com.sun.nativewindow.impl.*; +import com.jogamp.nativewindow.impl.*; /** A wrapper for an AWT GraphicsDevice allowing it to be handled in a toolkit-independent manner. */ diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java index 2ad8a99af..6cbf2ee71 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java +++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java @@ -43,7 +43,7 @@ import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import javax.media.nativewindow.*; import javax.media.nativewindow.AbstractGraphicsDevice; -import com.sun.nativewindow.impl.*; +import com.jogamp.nativewindow.impl.*; /** A wrapper for an AWT GraphicsDevice (screen) allowing it to be handled in a toolkit-independent manner. */ diff --git a/src/nativewindow/classes/javax/media/nativewindow/package.html b/src/nativewindow/classes/javax/media/nativewindow/package.html index ce9dbbb7a..d30b4a8df 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/package.html +++ b/src/nativewindow/classes/javax/media/nativewindow/package.html @@ -41,7 +41,7 @@
This protocol does not describe how to create native windows, but how to bind a native window to an implementation of {@link javax.media.nativewindow.NativeWindow NativeWindow}.
- However, an implementation of this protocol (e.g. {@link com.sun.javafx.newt}) may support the creation.
+ However, an implementation of this protocol (e.g. {@link com.jogamp.javafx.newt}) may support the creation.

Dependencies

This binding has dependencies to the following:

diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java index 49d5f2d83..5659dcdcc 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java +++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java @@ -33,7 +33,7 @@ package javax.media.nativewindow.x11; import javax.media.nativewindow.*; -import com.sun.nativewindow.impl.x11.XVisualInfo; +import com.jogamp.nativewindow.impl.x11.XVisualInfo; /** Encapsulates a graphics configuration, or OpenGL pixel format, on X11 platforms. Objects of this type are returned from {@link diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java index 614d26a61..52f48660a 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java +++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java @@ -33,8 +33,8 @@ package javax.media.nativewindow.x11; import javax.media.nativewindow.*; -import com.sun.nativewindow.impl.x11.X11Util; -import com.sun.nativewindow.impl.x11.X11Lib; +import com.jogamp.nativewindow.impl.x11.X11Util; +import com.jogamp.nativewindow.impl.x11.X11Lib; /** Encapsulates a screen index on X11 platforms. Objects of this type are passed to {@link diff --git a/src/nativewindow/native/JAWT_DrawingSurfaceInfo.c b/src/nativewindow/native/JAWT_DrawingSurfaceInfo.c index e4afbdb70..a0422fa8e 100644 --- a/src/nativewindow/native/JAWT_DrawingSurfaceInfo.c +++ b/src/nativewindow/native/JAWT_DrawingSurfaceInfo.c @@ -50,7 +50,7 @@ #endif JNIEXPORT jobject JNICALL -Java_com_sun_nativewindow_impl_jawt_JAWT_1DrawingSurfaceInfo_platformInfo0(JNIEnv* env, jobject unused, jobject jthis0) { +Java_com_jogamp_nativewindow_impl_jawt_JAWT_1DrawingSurfaceInfo_platformInfo0(JNIEnv* env, jobject unused, jobject jthis0) { JAWT_DrawingSurfaceInfo* dsi; dsi = (*env)->GetDirectBufferAddress(env, jthis0); if (dsi == NULL) { diff --git a/src/nativewindow/native/JVM_Tool.c b/src/nativewindow/native/JVM_Tool.c index e04032aa2..ce827129c 100644 --- a/src/nativewindow/native/JVM_Tool.c +++ b/src/nativewindow/native/JVM_Tool.c @@ -40,7 +40,7 @@ #include JNIEXPORT jboolean JNICALL -Java_com_sun_nativewindow_impl_jvm_JVMUtil_initialize(JNIEnv *env, jclass _unused, jobject nioBuffer) { +Java_com_jogamp_nativewindow_impl_jvm_JVMUtil_initialize(JNIEnv *env, jclass _unused, jobject nioBuffer) { int res; void * ptr = NULL; if (nioBuffer != NULL) { diff --git a/src/newt/classes/com/jogamp/javafx/newt/Display.java b/src/newt/classes/com/jogamp/javafx/newt/Display.java new file mode 100755 index 000000000..5c5db0338 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/Display.java @@ -0,0 +1,276 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt; + +import javax.media.nativewindow.*; +import com.jogamp.javafx.newt.impl.Debug; +import com.jogamp.javafx.newt.util.EventDispatchThread; +import java.util.*; + +public abstract class Display { + public static final boolean DEBUG = Debug.debug("Display"); + + private static Class getDisplayClass(String type) + throws ClassNotFoundException + { + Class displayClass = NewtFactory.getCustomClass(type, "Display"); + if(null==displayClass) { + if (NativeWindowFactory.TYPE_EGL.equals(type)) { + displayClass = Class.forName("com.jogamp.javafx.newt.opengl.kd.KDDisplay"); + } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) { + displayClass = Class.forName("com.jogamp.javafx.newt.windows.WindowsDisplay"); + } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { + displayClass = Class.forName("com.jogamp.javafx.newt.macosx.MacDisplay"); + } else if (NativeWindowFactory.TYPE_X11.equals(type)) { + displayClass = Class.forName("com.jogamp.javafx.newt.x11.X11Display"); + } else if (NativeWindowFactory.TYPE_AWT.equals(type)) { + displayClass = Class.forName("com.jogamp.javafx.newt.awt.AWTDisplay"); + } else { + throw new RuntimeException("Unknown display type \"" + type + "\""); + } + } + return displayClass; + } + + // Unique Display for each thread + private static ThreadLocal currentDisplayMap = new ThreadLocal(); + + /** Returns the thread local display map */ + public static Map getCurrentDisplayMap() { + Map displayMap = (Map) currentDisplayMap.get(); + if(null==displayMap) { + displayMap = new HashMap(); + currentDisplayMap.set( displayMap ); + } + return displayMap; + } + + /** maps the given display to the thread local display map + * and notifies all threads synchronized to this display map. */ + protected static Display setCurrentDisplay(Display display) { + Map displayMap = getCurrentDisplayMap(); + Display oldDisplay = null; + synchronized(displayMap) { + String name = display.getName(); + if(null==name) name="nil"; + oldDisplay = (Display) displayMap.put(name, display); + displayMap.notifyAll(); + } + return oldDisplay; + } + + /** removes the mapping of the given name from the thread local display map + * and notifies all threads synchronized to this display map. */ + protected static Display removeCurrentDisplay(String name) { + if(null==name) name="nil"; + Map displayMap = getCurrentDisplayMap(); + Display oldDisplay = null; + synchronized(displayMap) { + oldDisplay = (Display) displayMap.remove(name); + displayMap.notifyAll(); + } + return oldDisplay; + } + + /** Returns the thread local display mapped to the given name */ + public static Display getCurrentDisplay(String name) { + if(null==name) name="nil"; + Map displayMap = getCurrentDisplayMap(); + Display display = (Display) displayMap.get(name); + return display; + } + + public static void dumpDisplayMap(String prefix) { + Map displayMap = getCurrentDisplayMap(); + Set entrySet = displayMap.entrySet(); + Iterator i = entrySet.iterator(); + System.err.println(prefix+" DisplayMap["+entrySet.size()+"] "+Thread.currentThread()); + for(int j=0; i.hasNext(); j++) { + Map.Entry entry = (Map.Entry) i.next(); + System.err.println(" ["+j+"] "+entry.getKey()+" -> "+entry.getValue()); + } + } + + /** Returns the thread local display collection */ + public static Collection getCurrentDisplays() { + return getCurrentDisplayMap().values(); + } + + /** Make sure to reuse a Display with the same name */ + protected static Display create(String type, String name) { + try { + if(DEBUG) { + dumpDisplayMap("Display.create("+name+") BEGIN"); + } + Display display = getCurrentDisplay(name); + if(null==display) { + Class displayClass = getDisplayClass(type); + display = (Display) displayClass.newInstance(); + display.name=name; + display.refCount=1; + + if(NewtFactory.useEDT()) { + Thread current = Thread.currentThread(); + display.eventDispatchThread = new EventDispatchThread(display, current.getThreadGroup(), current.getName()); + display.eventDispatchThread.start(); + final Display f_dpy = display; + display.eventDispatchThread.invokeAndWait(new Runnable() { + public void run() { + f_dpy.createNative(); + } + } ); + } else { + display.createNative(); + } + if(null==display.aDevice) { + throw new RuntimeException("Display.createNative() failed to instanciate an AbstractGraphicsDevice"); + } + setCurrentDisplay(display); + if(DEBUG) { + System.err.println("Display.create("+name+") NEW: "+display+" "+Thread.currentThread()); + } + } else { + synchronized(display) { + display.refCount++; + if(DEBUG) { + System.err.println("Display.create("+name+") REUSE: refCount "+display.refCount+", "+display+" "+Thread.currentThread()); + } + } + } + if(DEBUG) { + dumpDisplayMap("Display.create("+name+") END"); + } + return display; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected static Display wrapHandle(String type, String name, AbstractGraphicsDevice aDevice) { + try { + Class displayClass = getDisplayClass(type); + Display display = (Display) displayClass.newInstance(); + display.name=name; + display.aDevice=aDevice; + return display; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public EventDispatchThread getEDT() { return eventDispatchThread; } + + public synchronized void destroy() { + if(DEBUG) { + dumpDisplayMap("Display.destroy("+name+") BEGIN"); + } + refCount--; + if(0==refCount) { + removeCurrentDisplay(name); + if(DEBUG) { + System.err.println("Display.destroy("+name+") REMOVE: "+this+" "+Thread.currentThread()); + } + if(null!=eventDispatchThread) { + final Display f_dpy = this; + final EventDispatchThread f_edt = eventDispatchThread; + eventDispatchThread.invokeAndWait(new Runnable() { + public void run() { + f_dpy.closeNative(); + f_edt.stop(); + } + } ); + } else { + closeNative(); + } + if(null!=eventDispatchThread) { + eventDispatchThread.waitUntilStopped(); + eventDispatchThread=null; + } + aDevice = null; + } else { + if(DEBUG) { + System.err.println("Display.destroy("+name+") KEEP: refCount "+refCount+", "+this+" "+Thread.currentThread()); + } + } + if(DEBUG) { + dumpDisplayMap("Display.destroy("+name+") END"); + } + } + + protected abstract void createNative(); + protected abstract void closeNative(); + + public String getName() { + return name; + } + + public long getHandle() { + if(null!=aDevice) { + return aDevice.getHandle(); + } + return 0; + } + + public AbstractGraphicsDevice getGraphicsDevice() { + return aDevice; + } + + public void pumpMessages() { + if(null!=eventDispatchThread) { + dispatchMessages(); + } else { + synchronized(this) { + dispatchMessages(); + } + } + } + + public String toString() { + return "NEWT-Display["+name+", refCount "+refCount+", "+aDevice+"]"; + } + + protected abstract void dispatchMessages(); + + /** Default impl. nop - Currently only X11 needs a Display lock */ + protected void lockDisplay() { } + + /** Default impl. nop - Currently only X11 needs a Display lock */ + protected void unlockDisplay() { } + + protected EventDispatchThread eventDispatchThread = null; + protected String name; + protected int refCount; + protected AbstractGraphicsDevice aDevice; +} + diff --git a/src/newt/classes/com/jogamp/javafx/newt/Event.java b/src/newt/classes/com/jogamp/javafx/newt/Event.java new file mode 100644 index 000000000..4274454ab --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/Event.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt; + +public class Event { + private boolean isSystemEvent; + private int eventType; + private Window source; + private long when; + + Event(boolean isSystemEvent, int eventType, Window source, long when) { + this.isSystemEvent = isSystemEvent; + this.eventType = eventType; + this.source = source; + this.when = when; + } + + protected Event(int eventType, Window source, long when) { + this(false, eventType, source, when); + } + + /** Indicates whether this event was produced by the system or + generated by user code. */ + public final boolean isSystemEvent() { + return isSystemEvent; + } + + /** Returns the event type of this event. */ + public final int getEventType() { + return eventType; + } + + /** Returns the source Window which produced this Event. */ + public final Window getSource() { + return source; + } + + /** Returns the timestamp, in milliseconds, of this event. */ + public final long getWhen() { + return when; + } + + public String toString() { + return "Event[sys:"+isSystemEvent()+", source:"+getSource()+", when:"+getWhen()+"]"; + } + + public static String toHexString(int hex) { + return "0x" + Integer.toHexString(hex); + } + + public static String toHexString(long hex) { + return "0x" + Long.toHexString(hex); + } + +} diff --git a/src/newt/classes/com/jogamp/javafx/newt/EventListener.java b/src/newt/classes/com/jogamp/javafx/newt/EventListener.java new file mode 100644 index 000000000..065cc1de3 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/EventListener.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt; + +public interface EventListener +{ + public static final int WINDOW = 1 << 0; + public static final int MOUSE = 1 << 1; + public static final int KEY = 1 << 2; + public static final int SURFACE = 1 << 3; + +} + diff --git a/src/newt/classes/com/jogamp/javafx/newt/InputEvent.java b/src/newt/classes/com/jogamp/javafx/newt/InputEvent.java new file mode 100644 index 000000000..0cfaaa4c0 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/InputEvent.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt; + +public abstract class InputEvent extends Event +{ + public static final int SHIFT_MASK = 1 << 0; + public static final int CTRL_MASK = 1 << 1; + public static final int META_MASK = 1 << 2; + public static final int ALT_MASK = 1 << 3; + public static final int ALT_GRAPH_MASK = 1 << 5; + public static final int BUTTON1_MASK = 1 << 6; + public static final int BUTTON2_MASK = 1 << 7; + public static final int BUTTON3_MASK = 1 << 8; + + protected InputEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers) { + super(sysEvent, eventType, source, when); + this.consumed=false; + this.modifiers=modifiers; + } + + public void consume() { + consumed=true; + } + + public boolean isConsumed() { + return consumed; + } + public int getModifiers() { + return modifiers; + } + public boolean isAltDown() { + return (modifiers&ALT_MASK)!=0; + } + public boolean isAltGraphDown() { + return (modifiers&ALT_GRAPH_MASK)!=0; + } + public boolean isControlDown() { + return (modifiers&CTRL_MASK)!=0; + } + public boolean isMetaDown() { + return (modifiers&META_MASK)!=0; + } + public boolean isShiftDown() { + return (modifiers&SHIFT_MASK)!=0; + } + + public boolean isButton1Down() { + return (modifiers&BUTTON1_MASK)!=0; + } + + public boolean isButton2Down() { + return (modifiers&BUTTON2_MASK)!=0; + } + + public boolean isButton3Down() { + return (modifiers&BUTTON3_MASK)!=0; + } + + public String toString() { + return "InputEvent[modifiers:"+modifiers+"]"; + } + + private boolean consumed; + private int modifiers; +} diff --git a/src/newt/classes/com/jogamp/javafx/newt/Insets.java b/src/newt/classes/com/jogamp/javafx/newt/Insets.java new file mode 100644 index 000000000..5c91847f4 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/Insets.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. 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. + * + */ +package com.jogamp.javafx.newt; + +/** + * Simple class representing insets. + * + * @author tdv + */ +public class Insets implements Cloneable { + public int top; + public int left; + public int bottom; + public int right; + + /** + * Creates and initializes a new Insets object with the + * specified top, left, bottom, and right insets. + * @param top the inset from the top. + * @param left the inset from the left. + * @param bottom the inset from the bottom. + * @param right the inset from the right. + */ + public Insets(int top, int left, int bottom, int right) { + this.top = top; + this.left = left; + this.bottom = bottom; + this.right = right; + } + + /** + * Checks whether two insets objects are equal. Two instances + * of Insets are equal if the four integer values + * of the fields top, left, + * bottom, and right are all equal. + * @return true if the two insets are equal; + * otherwise false. + */ + public boolean equals(Object obj) { + if (obj instanceof Insets) { + Insets insets = (Insets)obj; + return ((top == insets.top) && (left == insets.left) && + (bottom == insets.bottom) && (right == insets.right)); + } + return false; + } + + /** + * Returns the hash code for this Insets. + * + * @return a hash code for this Insets. + */ + public int hashCode() { + int sum1 = left + bottom; + int sum2 = right + top; + int val1 = sum1 * (sum1 + 1)/2 + left; + int val2 = sum2 * (sum2 + 1)/2 + top; + int sum3 = val1 + val2; + return sum3 * (sum3 + 1)/2 + val2; + } + + public String toString() { + return getClass().getName() + "[top=" + top + ",left=" + left + + ",bottom=" + bottom + ",right=" + right + "]"; + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException ex) { + throw new InternalError(); + } + } + +} diff --git a/src/newt/classes/com/jogamp/javafx/newt/KeyEvent.java b/src/newt/classes/com/jogamp/javafx/newt/KeyEvent.java new file mode 100644 index 000000000..8ae92464c --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/KeyEvent.java @@ -0,0 +1,738 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt; + +public class KeyEvent extends InputEvent +{ + KeyEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers, int keyCode, char keyChar) { + super(sysEvent, eventType, source, when, modifiers); + this.keyCode=keyCode; + this.keyChar=keyChar; + } + public KeyEvent(int eventType, Window source, long when, int modifiers, int keyCode, char keyChar) { + this(false, eventType, source, when, modifiers, keyCode, keyChar); + } + + public char getKeyChar() { + return keyChar; + } + public int getKeyCode() { + return keyCode; + } + + public String toString() { + return "KeyEvent["+getEventTypeString(getEventType())+ + ", code "+keyCode+"("+toHexString(keyCode)+"), char <"+keyChar+"> ("+toHexString((int)keyChar)+"), isActionKey "+isActionKey()+", "+super.toString()+"]"; + } + + public static String getEventTypeString(int type) { + switch(type) { + case EVENT_KEY_PRESSED: return "EVENT_KEY_PRESSED"; + case EVENT_KEY_RELEASED: return "EVENT_KEY_RELEASED"; + case EVENT_KEY_TYPED: return "EVENT_KEY_TYPED"; + default: return "unknown (" + type + ")"; + } + } + + public boolean isActionKey() { + switch (keyCode) { + case VK_HOME: + case VK_END: + case VK_PAGE_UP: + case VK_PAGE_DOWN: + case VK_UP: + case VK_DOWN: + case VK_LEFT: + case VK_RIGHT: + + case VK_F1: + case VK_F2: + case VK_F3: + case VK_F4: + case VK_F5: + case VK_F6: + case VK_F7: + case VK_F8: + case VK_F9: + case VK_F10: + case VK_F11: + case VK_F12: + case VK_F13: + case VK_F14: + case VK_F15: + case VK_F16: + case VK_F17: + case VK_F18: + case VK_F19: + case VK_F20: + case VK_F21: + case VK_F22: + case VK_F23: + case VK_F24: + case VK_PRINTSCREEN: + case VK_CAPS_LOCK: + case VK_PAUSE: + case VK_INSERT: + + case VK_HELP: + case VK_WINDOWS: + return true; + } + return false; + } + + private int keyCode; + private char keyChar; + + public static final int EVENT_KEY_PRESSED = 300; + public static final int EVENT_KEY_RELEASED= 301; + public static final int EVENT_KEY_TYPED = 302; + + /* Virtual key codes. */ + + public static final int VK_ENTER = '\n'; + public static final int VK_BACK_SPACE = '\b'; + public static final int VK_TAB = '\t'; + public static final int VK_CANCEL = 0x03; + public static final int VK_CLEAR = 0x0C; + public static final int VK_SHIFT = 0x10; + public static final int VK_CONTROL = 0x11; + public static final int VK_ALT = 0x12; + public static final int VK_PAUSE = 0x13; + public static final int VK_CAPS_LOCK = 0x14; + public static final int VK_ESCAPE = 0x1B; + public static final int VK_SPACE = 0x20; + public static final int VK_PAGE_UP = 0x21; + public static final int VK_PAGE_DOWN = 0x22; + public static final int VK_END = 0x23; + public static final int VK_HOME = 0x24; + + /** + * Constant for the non-numpad left arrow key. + * @see #VK_KP_LEFT + */ + public static final int VK_LEFT = 0x25; + + /** + * Constant for the non-numpad up arrow key. + * @see #VK_KP_UP + */ + public static final int VK_UP = 0x26; + + /** + * Constant for the non-numpad right arrow key. + * @see #VK_KP_RIGHT + */ + public static final int VK_RIGHT = 0x27; + + /** + * Constant for the non-numpad down arrow key. + * @see #VK_KP_DOWN + */ + public static final int VK_DOWN = 0x28; + + /** + * Constant for the comma key, "," + */ + public static final int VK_COMMA = 0x2C; + + /** + * Constant for the minus key, "-" + * @since 1.2 + */ + public static final int VK_MINUS = 0x2D; + + /** + * Constant for the period key, "." + */ + public static final int VK_PERIOD = 0x2E; + + /** + * Constant for the forward slash key, "/" + */ + public static final int VK_SLASH = 0x2F; + + /** VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */ + public static final int VK_0 = 0x30; + public static final int VK_1 = 0x31; + public static final int VK_2 = 0x32; + public static final int VK_3 = 0x33; + public static final int VK_4 = 0x34; + public static final int VK_5 = 0x35; + public static final int VK_6 = 0x36; + public static final int VK_7 = 0x37; + public static final int VK_8 = 0x38; + public static final int VK_9 = 0x39; + + /** + * Constant for the semicolon key, ";" + */ + public static final int VK_SEMICOLON = 0x3B; + + /** + * Constant for the equals key, "=" + */ + public static final int VK_EQUALS = 0x3D; + + /** VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */ + public static final int VK_A = 0x41; + public static final int VK_B = 0x42; + public static final int VK_C = 0x43; + public static final int VK_D = 0x44; + public static final int VK_E = 0x45; + public static final int VK_F = 0x46; + public static final int VK_G = 0x47; + public static final int VK_H = 0x48; + public static final int VK_I = 0x49; + public static final int VK_J = 0x4A; + public static final int VK_K = 0x4B; + public static final int VK_L = 0x4C; + public static final int VK_M = 0x4D; + public static final int VK_N = 0x4E; + public static final int VK_O = 0x4F; + public static final int VK_P = 0x50; + public static final int VK_Q = 0x51; + public static final int VK_R = 0x52; + public static final int VK_S = 0x53; + public static final int VK_T = 0x54; + public static final int VK_U = 0x55; + public static final int VK_V = 0x56; + public static final int VK_W = 0x57; + public static final int VK_X = 0x58; + public static final int VK_Y = 0x59; + public static final int VK_Z = 0x5A; + + /** + * Constant for the open bracket key, "[" + */ + public static final int VK_OPEN_BRACKET = 0x5B; + + /** + * Constant for the back slash key, "\" + */ + public static final int VK_BACK_SLASH = 0x5C; + + /** + * Constant for the close bracket key, "]" + */ + public static final int VK_CLOSE_BRACKET = 0x5D; + + public static final int VK_NUMPAD0 = 0x60; + public static final int VK_NUMPAD1 = 0x61; + public static final int VK_NUMPAD2 = 0x62; + public static final int VK_NUMPAD3 = 0x63; + public static final int VK_NUMPAD4 = 0x64; + public static final int VK_NUMPAD5 = 0x65; + public static final int VK_NUMPAD6 = 0x66; + public static final int VK_NUMPAD7 = 0x67; + public static final int VK_NUMPAD8 = 0x68; + public static final int VK_NUMPAD9 = 0x69; + public static final int VK_MULTIPLY = 0x6A; + public static final int VK_ADD = 0x6B; + + /** + * This constant is obsolete, and is included only for backwards + * compatibility. + * @see #VK_SEPARATOR + */ + public static final int VK_SEPARATER = 0x6C; + + /** + * Constant for the Numpad Separator key. + * @since 1.4 + */ + public static final int VK_SEPARATOR = VK_SEPARATER; + + public static final int VK_SUBTRACT = 0x6D; + public static final int VK_DECIMAL = 0x6E; + public static final int VK_DIVIDE = 0x6F; + public static final int VK_DELETE = 0x7F; /* ASCII DEL */ + public static final int VK_NUM_LOCK = 0x90; + public static final int VK_SCROLL_LOCK = 0x91; + + /** Constant for the F1 function key. */ + public static final int VK_F1 = 0x70; + + /** Constant for the F2 function key. */ + public static final int VK_F2 = 0x71; + + /** Constant for the F3 function key. */ + public static final int VK_F3 = 0x72; + + /** Constant for the F4 function key. */ + public static final int VK_F4 = 0x73; + + /** Constant for the F5 function key. */ + public static final int VK_F5 = 0x74; + + /** Constant for the F6 function key. */ + public static final int VK_F6 = 0x75; + + /** Constant for the F7 function key. */ + public static final int VK_F7 = 0x76; + + /** Constant for the F8 function key. */ + public static final int VK_F8 = 0x77; + + /** Constant for the F9 function key. */ + public static final int VK_F9 = 0x78; + + /** Constant for the F10 function key. */ + public static final int VK_F10 = 0x79; + + /** Constant for the F11 function key. */ + public static final int VK_F11 = 0x7A; + + /** Constant for the F12 function key. */ + public static final int VK_F12 = 0x7B; + + /** + * Constant for the F13 function key. + * @since 1.2 + */ + /* F13 - F24 are used on IBM 3270 keyboard; use random range for constants. */ + public static final int VK_F13 = 0xF000; + + /** + * Constant for the F14 function key. + * @since 1.2 + */ + public static final int VK_F14 = 0xF001; + + /** + * Constant for the F15 function key. + * @since 1.2 + */ + public static final int VK_F15 = 0xF002; + + /** + * Constant for the F16 function key. + * @since 1.2 + */ + public static final int VK_F16 = 0xF003; + + /** + * Constant for the F17 function key. + * @since 1.2 + */ + public static final int VK_F17 = 0xF004; + + /** + * Constant for the F18 function key. + * @since 1.2 + */ + public static final int VK_F18 = 0xF005; + + /** + * Constant for the F19 function key. + * @since 1.2 + */ + public static final int VK_F19 = 0xF006; + + /** + * Constant for the F20 function key. + * @since 1.2 + */ + public static final int VK_F20 = 0xF007; + + /** + * Constant for the F21 function key. + * @since 1.2 + */ + public static final int VK_F21 = 0xF008; + + /** + * Constant for the F22 function key. + * @since 1.2 + */ + public static final int VK_F22 = 0xF009; + + /** + * Constant for the F23 function key. + * @since 1.2 + */ + public static final int VK_F23 = 0xF00A; + + /** + * Constant for the F24 function key. + * @since 1.2 + */ + public static final int VK_F24 = 0xF00B; + + public static final int VK_PRINTSCREEN = 0x9A; + public static final int VK_INSERT = 0x9B; + public static final int VK_HELP = 0x9C; + public static final int VK_META = 0x9D; + + public static final int VK_BACK_QUOTE = 0xC0; + public static final int VK_QUOTE = 0xDE; + + /** + * Constant for the numeric keypad up arrow key. + * @see #VK_UP + * @since 1.2 + */ + public static final int VK_KP_UP = 0xE0; + + /** + * Constant for the numeric keypad down arrow key. + * @see #VK_DOWN + * @since 1.2 + */ + public static final int VK_KP_DOWN = 0xE1; + + /** + * Constant for the numeric keypad left arrow key. + * @see #VK_LEFT + * @since 1.2 + */ + public static final int VK_KP_LEFT = 0xE2; + + /** + * Constant for the numeric keypad right arrow key. + * @see #VK_RIGHT + * @since 1.2 + */ + public static final int VK_KP_RIGHT = 0xE3; + + /* For European keyboards */ + /** @since 1.2 */ + public static final int VK_DEAD_GRAVE = 0x80; + /** @since 1.2 */ + public static final int VK_DEAD_ACUTE = 0x81; + /** @since 1.2 */ + public static final int VK_DEAD_CIRCUMFLEX = 0x82; + /** @since 1.2 */ + public static final int VK_DEAD_TILDE = 0x83; + /** @since 1.2 */ + public static final int VK_DEAD_MACRON = 0x84; + /** @since 1.2 */ + public static final int VK_DEAD_BREVE = 0x85; + /** @since 1.2 */ + public static final int VK_DEAD_ABOVEDOT = 0x86; + /** @since 1.2 */ + public static final int VK_DEAD_DIAERESIS = 0x87; + /** @since 1.2 */ + public static final int VK_DEAD_ABOVERING = 0x88; + /** @since 1.2 */ + public static final int VK_DEAD_DOUBLEACUTE = 0x89; + /** @since 1.2 */ + public static final int VK_DEAD_CARON = 0x8a; + /** @since 1.2 */ + public static final int VK_DEAD_CEDILLA = 0x8b; + /** @since 1.2 */ + public static final int VK_DEAD_OGONEK = 0x8c; + /** @since 1.2 */ + public static final int VK_DEAD_IOTA = 0x8d; + /** @since 1.2 */ + public static final int VK_DEAD_VOICED_SOUND = 0x8e; + /** @since 1.2 */ + public static final int VK_DEAD_SEMIVOICED_SOUND = 0x8f; + + /** @since 1.2 */ + public static final int VK_AMPERSAND = 0x96; + /** @since 1.2 */ + public static final int VK_ASTERISK = 0x97; + /** @since 1.2 */ + public static final int VK_QUOTEDBL = 0x98; + /** @since 1.2 */ + public static final int VK_LESS = 0x99; + + /** @since 1.2 */ + public static final int VK_GREATER = 0xa0; + /** @since 1.2 */ + public static final int VK_BRACELEFT = 0xa1; + /** @since 1.2 */ + public static final int VK_BRACERIGHT = 0xa2; + + /** + * Constant for the "@" key. + * @since 1.2 + */ + public static final int VK_AT = 0x0200; + + /** + * Constant for the ":" key. + * @since 1.2 + */ + public static final int VK_COLON = 0x0201; + + /** + * Constant for the "^" key. + * @since 1.2 + */ + public static final int VK_CIRCUMFLEX = 0x0202; + + /** + * Constant for the "$" key. + * @since 1.2 + */ + public static final int VK_DOLLAR = 0x0203; + + /** + * Constant for the Euro currency sign key. + * @since 1.2 + */ + public static final int VK_EURO_SIGN = 0x0204; + + /** + * Constant for the "!" key. + * @since 1.2 + */ + public static final int VK_EXCLAMATION_MARK = 0x0205; + + /** + * Constant for the inverted exclamation mark key. + * @since 1.2 + */ + public static final int VK_INVERTED_EXCLAMATION_MARK = 0x0206; + + /** + * Constant for the "(" key. + * @since 1.2 + */ + public static final int VK_LEFT_PARENTHESIS = 0x0207; + + /** + * Constant for the "#" key. + * @since 1.2 + */ + public static final int VK_NUMBER_SIGN = 0x0208; + + /** + * Constant for the "+" key. + * @since 1.2 + */ + public static final int VK_PLUS = 0x0209; + + /** + * Constant for the ")" key. + * @since 1.2 + */ + public static final int VK_RIGHT_PARENTHESIS = 0x020A; + + /** + * Constant for the "_" key. + * @since 1.2 + */ + public static final int VK_UNDERSCORE = 0x020B; + + /** + * Constant for the Microsoft Windows "Windows" key. + * It is used for both the left and right version of the key. + * @see #getKeyLocation() + * @since 1.5 + */ + public static final int VK_WINDOWS = 0x020C; + + /** + * Constant for the Microsoft Windows Context Menu key. + * @since 1.5 + */ + public static final int VK_CONTEXT_MENU = 0x020D; + + /* for input method support on Asian Keyboards */ + + /* not clear what this means - listed in Microsoft Windows API */ + public static final int VK_FINAL = 0x0018; + + /** Constant for the Convert function key. */ + /* Japanese PC 106 keyboard, Japanese Solaris keyboard: henkan */ + public static final int VK_CONVERT = 0x001C; + + /** Constant for the Don't Convert function key. */ + /* Japanese PC 106 keyboard: muhenkan */ + public static final int VK_NONCONVERT = 0x001D; + + /** Constant for the Accept or Commit function key. */ + /* Japanese Solaris keyboard: kakutei */ + public static final int VK_ACCEPT = 0x001E; + + /* not clear what this means - listed in Microsoft Windows API */ + public static final int VK_MODECHANGE = 0x001F; + + /* replaced by VK_KANA_LOCK for Microsoft Windows and Solaris; + might still be used on other platforms */ + public static final int VK_KANA = 0x0015; + + /* replaced by VK_INPUT_METHOD_ON_OFF for Microsoft Windows and Solaris; + might still be used for other platforms */ + public static final int VK_KANJI = 0x0019; + + /** + * Constant for the Alphanumeric function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: eisuu */ + public static final int VK_ALPHANUMERIC = 0x00F0; + + /** + * Constant for the Katakana function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: katakana */ + public static final int VK_KATAKANA = 0x00F1; + + /** + * Constant for the Hiragana function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: hiragana */ + public static final int VK_HIRAGANA = 0x00F2; + + /** + * Constant for the Full-Width Characters function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: zenkaku */ + public static final int VK_FULL_WIDTH = 0x00F3; + + /** + * Constant for the Half-Width Characters function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: hankaku */ + public static final int VK_HALF_WIDTH = 0x00F4; + + /** + * Constant for the Roman Characters function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: roumaji */ + public static final int VK_ROMAN_CHARACTERS = 0x00F5; + + /** + * Constant for the All Candidates function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard - VK_CONVERT + ALT: zenkouho */ + public static final int VK_ALL_CANDIDATES = 0x0100; + + /** + * Constant for the Previous Candidate function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard - VK_CONVERT + SHIFT: maekouho */ + public static final int VK_PREVIOUS_CANDIDATE = 0x0101; + + /** + * Constant for the Code Input function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard - VK_ALPHANUMERIC + ALT: kanji bangou */ + public static final int VK_CODE_INPUT = 0x0102; + + /** + * Constant for the Japanese-Katakana function key. + * This key switches to a Japanese input method and selects its Katakana input mode. + * @since 1.2 + */ + /* Japanese Macintosh keyboard - VK_JAPANESE_HIRAGANA + SHIFT */ + public static final int VK_JAPANESE_KATAKANA = 0x0103; + + /** + * Constant for the Japanese-Hiragana function key. + * This key switches to a Japanese input method and selects its Hiragana input mode. + * @since 1.2 + */ + /* Japanese Macintosh keyboard */ + public static final int VK_JAPANESE_HIRAGANA = 0x0104; + + /** + * Constant for the Japanese-Roman function key. + * This key switches to a Japanese input method and selects its Roman-Direct input mode. + * @since 1.2 + */ + /* Japanese Macintosh keyboard */ + public static final int VK_JAPANESE_ROMAN = 0x0105; + + /** + * Constant for the locking Kana function key. + * This key locks the keyboard into a Kana layout. + * @since 1.3 + */ + /* Japanese PC 106 keyboard with special Windows driver - eisuu + Control; Japanese Solaris keyboard: kana */ + public static final int VK_KANA_LOCK = 0x0106; + + /** + * Constant for the input method on/off key. + * @since 1.3 + */ + /* Japanese PC 106 keyboard: kanji. Japanese Solaris keyboard: nihongo */ + public static final int VK_INPUT_METHOD_ON_OFF = 0x0107; + + /* for Sun keyboards */ + /** @since 1.2 */ + public static final int VK_CUT = 0xFFD1; + /** @since 1.2 */ + public static final int VK_COPY = 0xFFCD; + /** @since 1.2 */ + public static final int VK_PASTE = 0xFFCF; + /** @since 1.2 */ + public static final int VK_UNDO = 0xFFCB; + /** @since 1.2 */ + public static final int VK_AGAIN = 0xFFC9; + /** @since 1.2 */ + public static final int VK_FIND = 0xFFD0; + /** @since 1.2 */ + public static final int VK_PROPS = 0xFFCA; + /** @since 1.2 */ + public static final int VK_STOP = 0xFFC8; + + /** + * Constant for the Compose function key. + * @since 1.2 + */ + public static final int VK_COMPOSE = 0xFF20; + + /** + * Constant for the AltGraph function key. + * @since 1.2 + */ + public static final int VK_ALT_GRAPH = 0xFF7E; + + /** + * Constant for the Begin key. + * @since 1.5 + */ + public static final int VK_BEGIN = 0xFF58; + + /** + * This value is used to indicate that the keyCode is unknown. + * KEY_TYPED events do not have a keyCode value; this value + * is used instead. + */ + public static final int VK_UNDEFINED = 0x0; +} + diff --git a/src/newt/classes/com/jogamp/javafx/newt/KeyListener.java b/src/newt/classes/com/jogamp/javafx/newt/KeyListener.java new file mode 100644 index 000000000..7921a0a97 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/KeyListener.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt; + +public interface KeyListener extends EventListener +{ + public void keyPressed(KeyEvent e); + public void keyReleased(KeyEvent e); + public void keyTyped(KeyEvent e) ; +} + diff --git a/src/newt/classes/com/jogamp/javafx/newt/MouseEvent.java b/src/newt/classes/com/jogamp/javafx/newt/MouseEvent.java new file mode 100644 index 000000000..82989e216 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/MouseEvent.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt; + +public class MouseEvent extends InputEvent +{ + public static final int BUTTON1 = 1; + public static final int BUTTON2 = 2; + public static final int BUTTON3 = 3; + public static final int BUTTON4 = 4; + public static final int BUTTON5 = 5; + public static final int BUTTON6 = 6; + public static final int BUTTON_NUMBER = 6; + + protected MouseEvent(boolean sysEvent, int eventType, Window source, long when, + int modifiers, int x, int y, int clickCount, int button, + int rotation) + { + super(sysEvent, eventType, source, when, modifiers); + this.x=x; + this.y=y; + this.clickCount=clickCount; + this.button=button; + this.wheelRotation = rotation; + } + public MouseEvent(int eventType, Window source, long when, int modifiers, + int x, int y, int clickCount, int button, int rotation) { + this(false, eventType, source, when, modifiers, x, y, clickCount, button, + rotation); + } + + public int getButton() { + return button; + } + public int getClickCount() { + return clickCount; + } + public int getX() { + return x; + } + public int getY() { + return y; + } + public int getWheelRotation() { + return wheelRotation; + } + + public String toString() { + return "MouseEvent["+getEventTypeString(getEventType())+ + ", "+x+"/"+y+", button "+button+", count "+clickCount+ + ", wheel rotation "+wheelRotation+ + ", "+super.toString()+"]"; + } + + public static String getEventTypeString(int type) { + switch(type) { + case EVENT_MOUSE_CLICKED: return "EVENT_MOUSE_CLICKED"; + case EVENT_MOUSE_ENTERED: return "EVENT_MOUSE_ENTERED"; + case EVENT_MOUSE_EXITED: return "EVENT_MOUSE_EXITED"; + case EVENT_MOUSE_PRESSED: return "EVENT_MOUSE_PRESSED"; + case EVENT_MOUSE_RELEASED: return "EVENT_MOUSE_RELEASED"; + case EVENT_MOUSE_MOVED: return "EVENT_MOUSE_MOVED"; + case EVENT_MOUSE_DRAGGED: return "EVENT_MOUSE_DRAGGED"; + case EVENT_MOUSE_WHEEL_MOVED: return "EVENT_MOUSE_WHEEL_MOVED"; + default: return "unknown (" + type + ")"; + } + } + + private int x, y, clickCount, button, wheelRotation; + + public static final int EVENT_MOUSE_CLICKED = 200; + public static final int EVENT_MOUSE_ENTERED = 201; + public static final int EVENT_MOUSE_EXITED = 202; + public static final int EVENT_MOUSE_PRESSED = 203; + public static final int EVENT_MOUSE_RELEASED = 204; + public static final int EVENT_MOUSE_MOVED = 205; + public static final int EVENT_MOUSE_DRAGGED = 206; + public static final int EVENT_MOUSE_WHEEL_MOVED = 207; +} diff --git a/src/newt/classes/com/jogamp/javafx/newt/MouseListener.java b/src/newt/classes/com/jogamp/javafx/newt/MouseListener.java new file mode 100644 index 000000000..a0d42f738 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/MouseListener.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt; + +public interface MouseListener extends EventListener +{ + public void mouseClicked(MouseEvent e); + public void mouseEntered(MouseEvent e); + public void mouseExited(MouseEvent e); + public void mousePressed(MouseEvent e); + public void mouseReleased(MouseEvent e); + public void mouseMoved(MouseEvent e); + public void mouseDragged(MouseEvent e); + public void mouseWheelMoved(MouseEvent e); +} + diff --git a/src/newt/classes/com/jogamp/javafx/newt/NewtFactory.java b/src/newt/classes/com/jogamp/javafx/newt/NewtFactory.java new file mode 100755 index 000000000..aae51aaf6 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/NewtFactory.java @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt; + +import javax.media.nativewindow.*; +import java.util.ArrayList; +import java.util.Iterator; +import com.jogamp.nativewindow.impl.jvm.JVMUtil; + +public abstract class NewtFactory { + // Work-around for initialization order problems on Mac OS X + // between native Newt and (apparently) Fmod + static { + JVMUtil.initSingleton(); + Window.init(NativeWindowFactory.getNativeWindowType(true)); + } + + static Class getCustomClass(String packageName, String classBaseName) { + Class clazz = null; + if(packageName!=null || classBaseName!=null) { + String clazzName = packageName + "." + classBaseName ; + try { + clazz = Class.forName(clazzName); + } catch (Throwable t) {} + } + return clazz; + } + + private static boolean useEDT = true; + + /** + * Toggles the usage of an EventDispatchThread while creating a Display.
+ * The default is enabled.
+ * The EventDispatchThread is thread local to the Display instance.
+ */ + public static synchronized void setUseEDT(boolean onoff) { + useEDT = onoff; + } + + /** @see #setUseEDT(boolean) */ + public static boolean useEDT() { return useEDT; } + + /** + * Create a Display entity, incl native creation + */ + public static Display createDisplay(String name) { + return Display.create(NativeWindowFactory.getNativeWindowType(true), name); + } + + /** + * Create a Display entity using the given implementation type, incl native creation + */ + public static Display createDisplay(String type, String name) { + return Display.create(type, name); + } + + /** + * Create a Screen entity, incl native creation + */ + public static Screen createScreen(Display display, int index) { + return Screen.create(NativeWindowFactory.getNativeWindowType(true), display, index); + } + + /** + * Create a Screen entity using the given implementation type, incl native creation + */ + public static Screen createScreen(String type, Display display, int index) { + return Screen.create(type, display, index); + } + + /** + * Create a Window entity, incl native creation + */ + public static Window createWindow(Screen screen, Capabilities caps) { + return Window.create(NativeWindowFactory.getNativeWindowType(true), 0, screen, caps, false); + } + + public static Window createWindow(Screen screen, Capabilities caps, boolean undecorated) { + return Window.create(NativeWindowFactory.getNativeWindowType(true), 0, screen, caps, undecorated); + } + + public static Window createWindow(long parentWindowHandle, Screen screen, Capabilities caps, boolean undecorated) { + return Window.create(NativeWindowFactory.getNativeWindowType(true), parentWindowHandle, screen, caps, undecorated); + } + + /** + * Ability to try a Window type with a construnctor argument, if supported ..

+ * Currently only valid is AWTWindow(Frame frame) , + * to support an external created AWT Frame, ie the browsers embedded frame. + */ + public static Window createWindow(Object[] cstrArguments, Screen screen, Capabilities caps, boolean undecorated) { + return Window.create(NativeWindowFactory.getNativeWindowType(true), cstrArguments, screen, caps, undecorated); + } + + /** + * Create a Window entity using the given implementation type, incl native creation + */ + public static Window createWindow(String type, Screen screen, Capabilities caps) { + return Window.create(type, 0, screen, caps, false); + } + + public static Window createWindow(String type, Screen screen, Capabilities caps, boolean undecorated) { + return Window.create(type, 0, screen, caps, undecorated); + } + + public static Window createWindow(String type, long parentWindowHandle, Screen screen, Capabilities caps, boolean undecorated) { + return Window.create(type, parentWindowHandle, screen, caps, undecorated); + } + + public static Window createWindow(String type, Object[] cstrArguments, Screen screen, Capabilities caps, boolean undecorated) { + return Window.create(type, cstrArguments, screen, caps, undecorated); + } + + /** + * Instantiate a Display entity using the native handle. + */ + public static Display wrapDisplay(String name, AbstractGraphicsDevice device) { + return Display.wrapHandle(NativeWindowFactory.getNativeWindowType(true), name, device); + } + + /** + * Instantiate a Screen entity using the native handle. + */ + public static Screen wrapScreen(Display display, AbstractGraphicsScreen screen) { + return Screen.wrapHandle(NativeWindowFactory.getNativeWindowType(true), display, screen); + } + + /** + * Instantiate a Window entity using the native handle. + */ + public static Window wrapWindow(Screen screen, AbstractGraphicsConfiguration config, + long windowHandle, boolean fullscreen, boolean visible, + int x, int y, int width, int height) { + return Window.wrapHandle(NativeWindowFactory.getNativeWindowType(true), screen, config, + windowHandle, fullscreen, visible, x, y, width, height); + } + + private static final boolean instanceOf(Object obj, String clazzName) { + Class clazz = obj.getClass(); + do { + if(clazz.getName().equals(clazzName)) { + return true; + } + clazz = clazz.getSuperclass(); + } while (clazz!=null); + return false; + } + +} + diff --git a/src/newt/classes/com/jogamp/javafx/newt/OffscreenWindow.java b/src/newt/classes/com/jogamp/javafx/newt/OffscreenWindow.java new file mode 100644 index 000000000..015e9b8d2 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/OffscreenWindow.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt; + +import javax.media.nativewindow.*; + +public class OffscreenWindow extends Window implements SurfaceChangeable { + + long surfaceHandle = 0; + + public OffscreenWindow() { + } + + static long nextWindowHandle = 0x100; // start here - a marker + + protected void createNative(long parentWindowHandle, Capabilities caps) { + if(0!=parentWindowHandle) { + throw new NativeWindowException("OffscreenWindow does not support window parenting"); + } + if(caps.isOnscreen()) { + throw new NativeWindowException("Capabilities is onscreen"); + } + AbstractGraphicsScreen aScreen = screen.getGraphicsScreen(); + config = GraphicsConfigurationFactory.getFactory(aScreen.getDevice()).chooseGraphicsConfiguration(caps, null, aScreen); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + + synchronized(OffscreenWindow.class) { + windowHandle = nextWindowHandle++; + } + } + + protected void closeNative() { + // nop + } + + public void invalidate() { + super.invalidate(); + surfaceHandle = 0; + } + + public synchronized void destroy() { + surfaceHandle = 0; + } + + public void setSurfaceHandle(long handle) { + surfaceHandle = handle ; + } + + public long getSurfaceHandle() { + return surfaceHandle; + } + + public void setVisible(boolean visible) { + if(!visible) { + this.visible = visible; + } + } + + public void setSize(int width, int height) { + if(!visible) { + this.width = width; + this.height = height; + } + } + + public void setPosition(int x, int y) { + // nop + } + + public boolean setFullscreen(boolean fullscreen) { + // nop + return false; + } +} + diff --git a/src/newt/classes/com/jogamp/javafx/newt/PaintEvent.java b/src/newt/classes/com/jogamp/javafx/newt/PaintEvent.java new file mode 100755 index 000000000..8543246a7 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/PaintEvent.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt; + +/** + * + * @author tdv + */ +public class PaintEvent extends Event { + + // bounds of the damage region + private int x, y, width, height; + public PaintEvent(int eventType, Window source, + long when, int x, int y, int w, int h) + { + super(true, eventType, source, when); + this.x = x; + this.y = y; + this.width = w; + this.height = h; + } + + public int getHeight() { + return height; + } + + public int getWidth() { + return width; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public String toString() { + return "ExposeEvent[modifiers: x="+x+" y="+y+" w="+width+" h="+height +"]"; + } + +} diff --git a/src/newt/classes/com/jogamp/javafx/newt/PaintListener.java b/src/newt/classes/com/jogamp/javafx/newt/PaintListener.java new file mode 100755 index 000000000..adfd78f18 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/PaintListener.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt; + +/** + * + * @author tdv + */ +public interface PaintListener { + public void exposed(PaintEvent e); +} diff --git a/src/newt/classes/com/jogamp/javafx/newt/Screen.java b/src/newt/classes/com/jogamp/javafx/newt/Screen.java new file mode 100755 index 000000000..b02a7ef00 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/Screen.java @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt; + +import com.jogamp.javafx.newt.impl.*; + +import javax.media.nativewindow.*; +import java.security.*; + +public abstract class Screen { + + private static Class getScreenClass(String type) + throws ClassNotFoundException + { + Class screenClass = NewtFactory.getCustomClass(type, "Screen"); + if(null==screenClass) { + if (NativeWindowFactory.TYPE_EGL.equals(type)) { + screenClass = Class.forName("com.jogamp.javafx.newt.opengl.kd.KDScreen"); + } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) { + screenClass = Class.forName("com.jogamp.javafx.newt.windows.WindowsScreen"); + } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { + screenClass = Class.forName("com.jogamp.javafx.newt.macosx.MacScreen"); + } else if (NativeWindowFactory.TYPE_X11.equals(type)) { + screenClass = Class.forName("com.jogamp.javafx.newt.x11.X11Screen"); + } else if (NativeWindowFactory.TYPE_AWT.equals(type)) { + screenClass = Class.forName("com.jogamp.javafx.newt.awt.AWTScreen"); + } else { + throw new RuntimeException("Unknown window type \"" + type + "\""); + } + } + return screenClass; + } + + protected static Screen create(String type, Display display, int idx) { + try { + if(usrWidth<0 || usrHeight<0) { + usrWidth = Debug.getIntProperty("newt.ws.swidth", true, localACC); + usrHeight = Debug.getIntProperty("newt.ws.sheight", true, localACC); + System.out.println("User screen size "+usrWidth+"x"+usrHeight); + } + Class screenClass = getScreenClass(type); + Screen screen = (Screen) screenClass.newInstance(); + screen.display = display; + screen.createNative(idx); + if(null==screen.aScreen) { + throw new RuntimeException("Screen.createNative() failed to instanciate an AbstractGraphicsScreen"); + } + return screen; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public synchronized void destroy() { + closeNative(); + display = null; + aScreen = null; + } + + protected static Screen wrapHandle(String type, Display display, AbstractGraphicsScreen aScreen) { + try { + Class screenClass = getScreenClass(type); + Screen screen = (Screen) screenClass.newInstance(); + screen.display = display; + screen.aScreen = aScreen; + return screen; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected abstract void createNative(int index); + protected abstract void closeNative(); + + protected void setScreenSize(int w, int h) { + System.out.println("Detected screen size "+w+"x"+h); + width=w; height=h; + } + + public Display getDisplay() { + return display; + } + + public int getIndex() { + return aScreen.getIndex(); + } + + public AbstractGraphicsScreen getGraphicsScreen() { + return aScreen; + } + + /** + * The actual implementation shall return the detected display value, + * if not we return 800. + * This can be overwritten with the user property 'newt.ws.swidth', + */ + public int getWidth() { + return (usrWidth>0) ? usrWidth : (width>0) ? width : 480; + } + + /** + * The actual implementation shall return the detected display value, + * if not we return 480. + * This can be overwritten with the user property 'newt.ws.sheight', + */ + public int getHeight() { + return (usrHeight>0) ? usrHeight : (height>0) ? height : 480; + } + + protected Display display; + protected AbstractGraphicsScreen aScreen; + protected int width=-1, height=-1; // detected values: set using setScreenSize + protected static int usrWidth=-1, usrHeight=-1; // property values: newt.ws.swidth and newt.ws.sheight + private static AccessControlContext localACC = AccessController.getContext(); +} + diff --git a/src/newt/classes/com/jogamp/javafx/newt/Window.java b/src/newt/classes/com/jogamp/javafx/newt/Window.java new file mode 100755 index 000000000..2d9341e13 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/Window.java @@ -0,0 +1,929 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt; + +import com.jogamp.javafx.newt.impl.Debug; +import com.jogamp.javafx.newt.util.EventDispatchThread; + +import javax.media.nativewindow.*; +import com.jogamp.nativewindow.impl.NWReflection; + +import java.util.ArrayList; +import java.util.Iterator; +import java.lang.reflect.Method; + +public abstract class Window implements NativeWindow +{ + public static final boolean DEBUG_MOUSE_EVENT = Debug.debug("Window.MouseEvent"); + public static final boolean DEBUG_KEY_EVENT = Debug.debug("Window.KeyEvent"); + public static final boolean DEBUG_WINDOW_EVENT = Debug.debug("Window.WindowEvent"); + public static final boolean DEBUG_IMPLEMENTATION = Debug.debug("Window"); + + // Workaround for initialization order problems on Mac OS X + // between native Newt and (apparently) Fmod -- if Fmod is + // initialized first then the connection to the window server + // breaks, leading to errors from deep within the AppKit + static void init(String type) { + if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { + try { + getWindowClass(type); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + private static Class getWindowClass(String type) + throws ClassNotFoundException + { + Class windowClass = NewtFactory.getCustomClass(type, "Window"); + if(null==windowClass) { + if (NativeWindowFactory.TYPE_EGL.equals(type)) { + windowClass = Class.forName("com.jogamp.javafx.newt.opengl.kd.KDWindow"); + } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) { + windowClass = Class.forName("com.jogamp.javafx.newt.windows.WindowsWindow"); + } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { + windowClass = Class.forName("com.jogamp.javafx.newt.macosx.MacWindow"); + } else if (NativeWindowFactory.TYPE_X11.equals(type)) { + windowClass = Class.forName("com.jogamp.javafx.newt.x11.X11Window"); + } else if (NativeWindowFactory.TYPE_AWT.equals(type)) { + windowClass = Class.forName("com.jogamp.javafx.newt.awt.AWTWindow"); + } else { + throw new NativeWindowException("Unknown window type \"" + type + "\""); + } + } + return windowClass; + } + + protected static Window create(String type, final long parentWindowHandle, Screen screen, final Capabilities caps, boolean undecorated) { + try { + Class windowClass; + if(caps.isOnscreen()) { + windowClass = getWindowClass(type); + } else { + windowClass = OffscreenWindow.class; + } + Window window = (Window) windowClass.newInstance(); + window.invalidate(); + window.screen = screen; + window.setUndecorated(undecorated||0!=parentWindowHandle); + EventDispatchThread edt = screen.getDisplay().getEDT(); + if(null!=edt) { + final Window f_win = window; + edt.invokeAndWait(new Runnable() { + public void run() { + f_win.createNative(parentWindowHandle, caps); + } + } ); + } else { + window.createNative(parentWindowHandle, caps); + } + return window; + } catch (Throwable t) { + t.printStackTrace(); + throw new NativeWindowException(t); + } + } + + protected static Window create(String type, Object[] cstrArguments, Screen screen, final Capabilities caps, boolean undecorated) { + try { + Class windowClass = getWindowClass(type); + Class[] cstrArgumentTypes = getCustomConstructorArgumentTypes(windowClass); + if(null==cstrArgumentTypes) { + throw new NativeWindowException("WindowClass "+windowClass+" doesn't support custom arguments in constructor"); + } + int argsChecked = verifyConstructorArgumentTypes(cstrArgumentTypes, cstrArguments); + if ( argsChecked < cstrArguments.length ) { + throw new NativeWindowException("WindowClass "+windowClass+" constructor mismatch at argument #"+argsChecked+"; Constructor: "+getTypeStrList(cstrArgumentTypes)+", arguments: "+getArgsStrList(cstrArguments)); + } + Window window = (Window) NWReflection.createInstance( windowClass, cstrArgumentTypes, cstrArguments ) ; + window.invalidate(); + window.screen = screen; + window.setUndecorated(undecorated); + EventDispatchThread edt = screen.getDisplay().getEDT(); + if(null!=edt) { + final Window f_win = window; + edt.invokeAndWait(new Runnable() { + public void run() { + f_win.createNative(0, caps); + } + } ); + } else { + window.createNative(0, caps); + } + return window; + } catch (Throwable t) { + t.printStackTrace(); + throw new NativeWindowException(t); + } + } + + protected static Window wrapHandle(String type, Screen screen, AbstractGraphicsConfiguration config, + long windowHandle, boolean fullscreen, boolean visible, + int x, int y, int width, int height) + { + try { + Class windowClass = getWindowClass(type); + Window window = (Window) windowClass.newInstance(); + window.invalidate(); + window.screen = screen; + window.config = config; + window.windowHandle = windowHandle; + window.fullscreen=fullscreen; + window.visible=visible; + window.x=x; + window.y=y; + window.width=width; + window.height=height; + return window; + } catch (Throwable t) { + t.printStackTrace(); + throw new NativeWindowException(t); + } + } + + public static String toHexString(int hex) { + return "0x" + Integer.toHexString(hex); + } + + public static String toHexString(long hex) { + return "0x" + Long.toHexString(hex); + } + + protected Screen screen; + + protected AbstractGraphicsConfiguration config; + protected long windowHandle; + protected boolean fullscreen, visible; + protected int width, height, x, y; + protected int eventMask; + + protected String title = "Newt Window"; + protected boolean undecorated = false; + + /** + * Create native windowHandle, ie creates a new native invisible window. + * + * The parentWindowHandle may be null, in which case no window parenting + * is requested. + * + * Shall use the capabilities to determine the graphics configuration + * and shall set the chosen capabilities. + */ + protected abstract void createNative(long parentWindowHandle, Capabilities caps); + + protected abstract void closeNative(); + + public Screen getScreen() { + return screen; + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + + sb.append(getClass().getName()+"[config "+config+ + ", windowHandle "+toHexString(getWindowHandle())+ + ", surfaceHandle "+toHexString(getSurfaceHandle())+ + ", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+ + ", visible "+isVisible()+ + ", undecorated "+undecorated+ + ", fullscreen "+fullscreen+ + ", "+screen+ + ", wrappedWindow "+getWrappedWindow()); + + sb.append(", SurfaceUpdatedListeners num "+surfaceUpdatedListeners.size()+" ["); + for (Iterator iter = surfaceUpdatedListeners.iterator(); iter.hasNext(); ) { + sb.append(iter.next()+", "); + } + sb.append("], WindowListeners num "+windowListeners.size()+" ["); + for (Iterator iter = windowListeners.iterator(); iter.hasNext(); ) { + sb.append(iter.next()+", "); + } + sb.append("], MouseListeners num "+mouseListeners.size()+" ["); + for (Iterator iter = mouseListeners.iterator(); iter.hasNext(); ) { + sb.append(iter.next()+", "); + } + sb.append("], KeyListeners num "+keyListeners.size()+" ["); + for (Iterator iter = keyListeners.iterator(); iter.hasNext(); ) { + sb.append(iter.next()+", "); + } + sb.append("] ]"); + return sb.toString(); + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public void setUndecorated(boolean value) { + undecorated = value; + } + + public boolean isUndecorated() { + return undecorated; + } + + public void requestFocus() { + } + + // + // NativeWindow impl + // + private Thread owner; + private int recursionCount; + protected Exception lockedStack = null; + + /** Recursive and blocking lockSurface() implementation */ + public synchronized int lockSurface() { + // We leave the ToolkitLock lock to the specializtion's discretion, + // ie the implicit JAWTWindow in case of AWTWindow + Thread cur = Thread.currentThread(); + if (owner == cur) { + ++recursionCount; + return LOCK_SUCCESS; + } + while (owner != null) { + try { + wait(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + owner = cur; + lockedStack = new Exception("NEWT Surface previously locked by "+Thread.currentThread()); + screen.getDisplay().lockDisplay(); + return LOCK_SUCCESS; + } + + /** Recursive and unblocking unlockSurface() implementation */ + public synchronized void unlockSurface() throws NativeWindowException { + Thread cur = Thread.currentThread(); + if (owner != cur) { + lockedStack.printStackTrace(); + throw new NativeWindowException(cur+": Not owner, owner is "+owner); + } + if (recursionCount > 0) { + --recursionCount; + return; + } + owner = null; + lockedStack = null; + screen.getDisplay().unlockDisplay(); + notifyAll(); + // We leave the ToolkitLock unlock to the specializtion's discretion, + // ie the implicit JAWTWindow in case of AWTWindow + } + + public synchronized boolean isSurfaceLocked() { + return null!=owner; + } + + public synchronized Thread getSurfaceLockOwner() { + return owner; + } + + public synchronized Exception getLockedStack() { + return lockedStack; + } + + public synchronized void destroy() { + destroy(false); + } + + /** @param deep If true, the linked Screen and Display will be destroyed as well. */ + public synchronized void destroy(boolean deep) { + if(DEBUG_WINDOW_EVENT) { + System.out.println("Window.destroy() start (deep "+deep+" - "+Thread.currentThread()); + } + synchronized(surfaceUpdatedListeners) { + surfaceUpdatedListeners = new ArrayList(); + } + synchronized(windowListeners) { + windowListeners = new ArrayList(); + } + synchronized(mouseListeners) { + mouseListeners = new ArrayList(); + } + synchronized(keyListeners) { + keyListeners = new ArrayList(); + } + Screen scr = screen; + Display dpy = (null!=screen) ? screen.getDisplay() : null; + EventDispatchThread edt = (null!=dpy) ? dpy.getEDT() : null; + if(null!=edt) { + final Window f_win = this; + edt.invokeAndWait(new Runnable() { + public void run() { + f_win.closeNative(); + } + } ); + } else { + closeNative(); + } + invalidate(); + if(deep) { + if(null!=scr) { + scr.destroy(); + } + if(null!=dpy) { + dpy.destroy(); + } + } + if(DEBUG_WINDOW_EVENT) { + System.out.println("Window.destroy() end "+Thread.currentThread()); + } + } + + public void invalidate() { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + Exception e = new Exception("!!! Window Invalidate "+Thread.currentThread()); + e.printStackTrace(); + } + screen = null; + windowHandle = 0; + fullscreen=false; + visible=false; + eventMask = 0; + + // Default position and dimension will be re-set immediately by user + width = 100; + height = 100; + x=0; + y=0; + } + + public boolean surfaceSwap() { + return false; + } + + protected void clearEventMask() { + eventMask=0; + } + + public long getDisplayHandle() { + return screen.getDisplay().getHandle(); + } + + public int getScreenIndex() { + return screen.getIndex(); + } + + public long getWindowHandle() { + return windowHandle; + } + + public long getSurfaceHandle() { + return windowHandle; // default: return window handle + } + + public AbstractGraphicsConfiguration getGraphicsConfiguration() { + return config; + } + + /** + * Returns the width of the client area of this window + * @return width of the client area + */ + public int getWidth() { + return width; + } + + /** + * Returns the height of the client area of this window + * @return height of the client area + */ + public int getHeight() { + return height; + } + + /** + * Returns the insets for this native window (the difference between the + * size of the toplevel window with the decorations and the client area). + * + * @return insets for this platform window + */ + // this probably belongs to NativeWindow interface + public Insets getInsets() { + return new Insets(0,0,0,0); + } + + /** If this Window actually wraps one from another toolkit such as + the AWT, this will return a non-null value. */ + public Object getWrappedWindow() { + return null; + } + + // + // Additional methods + // + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public boolean isVisible() { + return visible; + } + + public boolean isFullscreen() { + return fullscreen; + } + + private boolean autoDrawableMember = false; + + /** If the implementation is capable of detecting a device change + return true and clear the status/reason of the change. */ + public boolean hasDeviceChanged() { + return false; + } + + /** + * If set to true, + * certain action will be performed by the owning + * AutoDrawable, ie the destroy() call within windowDestroyNotify() + */ + public void setAutoDrawableClient(boolean b) { + autoDrawableMember = b; + } + + protected void windowDestroyNotify() { + if(DEBUG_WINDOW_EVENT) { + System.out.println("Window.windowDestroyeNotify start "+Thread.currentThread()); + } + + sendWindowEvent(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY); + + if(!autoDrawableMember) { + destroy(); + } + + if(DEBUG_WINDOW_EVENT) { + System.out.println("Window.windowDestroyeNotify end "+Thread.currentThread()); + } + } + + protected void windowDestroyed() { + if(DEBUG_WINDOW_EVENT) { + System.out.println("Window.windowDestroyed "+Thread.currentThread()); + } + invalidate(); + } + + public abstract void setVisible(boolean visible); + /** + * Sets the size of the client area of the window, excluding decorations + * Total size of the window will be + * {@code width+insets.left+insets.right, height+insets.top+insets.bottom} + * @param width of the client area of the window + * @param height of the client area of the window + */ + public abstract void setSize(int width, int height); + /** + * Sets the location of the top left corner of the window, including + * decorations (so the client area will be placed at + * {@code x+insets.left,y+insets.top}. + * @param x coord of the top left corner + * @param y coord of the top left corner + */ + public abstract void setPosition(int x, int y); + public abstract boolean setFullscreen(boolean fullscreen); + + // + // SurfaceUpdatedListener Support + // + private ArrayList surfaceUpdatedListeners = new ArrayList(); + + public void addSurfaceUpdatedListener(SurfaceUpdatedListener l) { + if(l == null) { + return; + } + synchronized(surfaceUpdatedListeners) { + ArrayList newSurfaceUpdatedListeners = (ArrayList) surfaceUpdatedListeners.clone(); + newSurfaceUpdatedListeners.add(l); + surfaceUpdatedListeners = newSurfaceUpdatedListeners; + } + } + + public void removeSurfaceUpdatedListener(SurfaceUpdatedListener l) { + if (l == null) { + return; + } + synchronized(surfaceUpdatedListeners) { + ArrayList newSurfaceUpdatedListeners = (ArrayList) surfaceUpdatedListeners.clone(); + newSurfaceUpdatedListeners.remove(l); + surfaceUpdatedListeners = newSurfaceUpdatedListeners; + } + } + + public SurfaceUpdatedListener[] getSurfaceUpdatedListener() { + synchronized(surfaceUpdatedListeners) { + return (SurfaceUpdatedListener[]) surfaceUpdatedListeners.toArray(); + } + } + + public void surfaceUpdated(Object updater, NativeWindow window, long when) { + ArrayList listeners = null; + synchronized(surfaceUpdatedListeners) { + listeners = surfaceUpdatedListeners; + } + for(Iterator i = listeners.iterator(); i.hasNext(); ) { + SurfaceUpdatedListener l = (SurfaceUpdatedListener) i.next(); + l.surfaceUpdated(updater, window, when); + } + } + + // + // MouseListener Support + // + + public void addMouseListener(MouseListener l) { + if(l == null) { + return; + } + synchronized(mouseListeners) { + ArrayList newMouseListeners = (ArrayList) mouseListeners.clone(); + newMouseListeners.add(l); + mouseListeners = newMouseListeners; + } + } + + public void removeMouseListener(MouseListener l) { + if (l == null) { + return; + } + synchronized(mouseListeners) { + ArrayList newMouseListeners = (ArrayList) mouseListeners.clone(); + newMouseListeners.remove(l); + mouseListeners = newMouseListeners; + } + } + + public MouseListener[] getMouseListeners() { + synchronized(mouseListeners) { + return (MouseListener[]) mouseListeners.toArray(); + } + } + + private ArrayList mouseListeners = new ArrayList(); + private int mouseButtonPressed = 0; // current pressed mouse button number + private long lastMousePressed = 0; // last time when a mouse button was pressed + private int lastMouseClickCount = 0; // last mouse button click count + public static final int ClickTimeout = 300; + + protected void sendMouseEvent(int eventType, int modifiers, + int x, int y, int button, int rotation) { + if(x<0||y<0||x>=width||y>=height) { + return; // .. invalid .. + } + if(DEBUG_MOUSE_EVENT) { + System.out.println("sendMouseEvent: "+MouseEvent.getEventTypeString(eventType)+ + ", mod "+modifiers+", pos "+x+"/"+y+", button "+button); + } + if(button<0||button>MouseEvent.BUTTON_NUMBER) { + throw new NativeWindowException("Invalid mouse button number" + button); + } + long when = System.currentTimeMillis(); + MouseEvent eClicked = null; + MouseEvent e = null; + + if(MouseEvent.EVENT_MOUSE_PRESSED==eventType) { + if(when-lastMousePressed0) { + e = new MouseEvent(true, MouseEvent.EVENT_MOUSE_DRAGGED, this, when, + modifiers, x, y, 1, mouseButtonPressed, 0); + } else { + e = new MouseEvent(true, eventType, this, when, + modifiers, x, y, 0, button, 0); + } + } else if(MouseEvent.EVENT_MOUSE_WHEEL_MOVED==eventType) { + e = new MouseEvent(true, eventType, this, when, modifiers, x, y, 0, button, rotation); + } else { + e = new MouseEvent(true, eventType, this, when, modifiers, x, y, 0, button, 0); + } + + if(DEBUG_MOUSE_EVENT) { + System.out.println("sendMouseEvent: event: "+e); + if(null!=eClicked) { + System.out.println("sendMouseEvent: event Clicked: "+eClicked); + } + } + + ArrayList listeners = null; + synchronized(mouseListeners) { + listeners = mouseListeners; + } + for(Iterator i = listeners.iterator(); i.hasNext(); ) { + MouseListener l = (MouseListener) i.next(); + switch(e.getEventType()) { + case MouseEvent.EVENT_MOUSE_CLICKED: + l.mouseClicked(e); + break; + case MouseEvent.EVENT_MOUSE_ENTERED: + l.mouseEntered(e); + break; + case MouseEvent.EVENT_MOUSE_EXITED: + l.mouseExited(e); + break; + case MouseEvent.EVENT_MOUSE_PRESSED: + l.mousePressed(e); + break; + case MouseEvent.EVENT_MOUSE_RELEASED: + l.mouseReleased(e); + if(null!=eClicked) { + l.mouseClicked(eClicked); + } + break; + case MouseEvent.EVENT_MOUSE_MOVED: + l.mouseMoved(e); + break; + case MouseEvent.EVENT_MOUSE_DRAGGED: + l.mouseDragged(e); + break; + case MouseEvent.EVENT_MOUSE_WHEEL_MOVED: + l.mouseWheelMoved(e); + break; + default: + throw new NativeWindowException("Unexpected mouse event type " + e.getEventType()); + } + } + } + + // + // KeyListener Support + // + + public void addKeyListener(KeyListener l) { + if(l == null) { + return; + } + synchronized(keyListeners) { + ArrayList newKeyListeners = (ArrayList) keyListeners.clone(); + newKeyListeners.add(l); + keyListeners = newKeyListeners; + } + } + + public void removeKeyListener(KeyListener l) { + if (l == null) { + return; + } + synchronized(keyListeners) { + ArrayList newKeyListeners = (ArrayList) keyListeners.clone(); + newKeyListeners.remove(l); + keyListeners = newKeyListeners; + } + } + + public KeyListener[] getKeyListeners() { + synchronized(keyListeners) { + return (KeyListener[]) keyListeners.toArray(); + } + } + + private ArrayList keyListeners = new ArrayList(); + + protected void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { + KeyEvent e = new KeyEvent(true, eventType, this, System.currentTimeMillis(), + modifiers, keyCode, keyChar); + if(DEBUG_KEY_EVENT) { + System.out.println("sendKeyEvent: "+e); + } + ArrayList listeners = null; + synchronized(keyListeners) { + listeners = keyListeners; + } + for(Iterator i = listeners.iterator(); i.hasNext(); ) { + KeyListener l = (KeyListener) i.next(); + switch(eventType) { + case KeyEvent.EVENT_KEY_PRESSED: + l.keyPressed(e); + break; + case KeyEvent.EVENT_KEY_RELEASED: + l.keyReleased(e); + break; + case KeyEvent.EVENT_KEY_TYPED: + l.keyTyped(e); + break; + default: + throw new NativeWindowException("Unexpected key event type " + e.getEventType()); + } + } + } + + // + // WindowListener Support + // + + private ArrayList windowListeners = new ArrayList(); + + public void addWindowListener(WindowListener l) { + if(l == null) { + return; + } + synchronized(windowListeners) { + ArrayList newWindowListeners = (ArrayList) windowListeners.clone(); + newWindowListeners.add(l); + windowListeners = newWindowListeners; + } + } + + public void removeWindowListener(WindowListener l) { + if (l == null) { + return; + } + synchronized(windowListeners) { + ArrayList newWindowListeners = (ArrayList) windowListeners.clone(); + newWindowListeners.remove(l); + windowListeners = newWindowListeners; + } + } + + public WindowListener[] getWindowListeners() { + synchronized(windowListeners) { + return (WindowListener[]) windowListeners.toArray(); + } + } + + protected void sendWindowEvent(int eventType) { + WindowEvent e = new WindowEvent(true, eventType, this, System.currentTimeMillis()); + if(DEBUG_WINDOW_EVENT) { + System.out.println("sendWindowEvent: "+e); + } + ArrayList listeners = null; + synchronized(windowListeners) { + listeners = windowListeners; + } + for(Iterator i = listeners.iterator(); i.hasNext(); ) { + WindowListener l = (WindowListener) i.next(); + switch(eventType) { + case WindowEvent.EVENT_WINDOW_RESIZED: + l.windowResized(e); + break; + case WindowEvent.EVENT_WINDOW_MOVED: + l.windowMoved(e); + break; + case WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY: + l.windowDestroyNotify(e); + break; + case WindowEvent.EVENT_WINDOW_GAINED_FOCUS: + l.windowGainedFocus(e); + break; + case WindowEvent.EVENT_WINDOW_LOST_FOCUS: + l.windowLostFocus(e); + break; + default: + throw + new NativeWindowException("Unexpected window event type " + + e.getEventType()); + } + } + } + + + // + // WindowListener Support + // + + private ArrayList paintListeners = new ArrayList(); + + public void addPaintListener(PaintListener l) { + if(l == null) { + return; + } + synchronized(paintListeners) { + ArrayList newPaintListeners = (ArrayList) paintListeners.clone(); + newPaintListeners.add(l); + paintListeners = newPaintListeners; + } + } + + public void removePaintListener(PaintListener l) { + if (l == null) { + return; + } + synchronized(paintListeners) { + ArrayList newPaintListeners = (ArrayList) paintListeners.clone(); + newPaintListeners.remove(l); + paintListeners = newPaintListeners; + } + } + + protected void sendPaintEvent(int eventType, int x, int y, int w, int h) { + PaintEvent e = + new PaintEvent(eventType, this, System.currentTimeMillis(), x, y, w, h); + ArrayList listeners = null; + synchronized(paintListeners) { + listeners = paintListeners; + } + for(Iterator i = listeners.iterator(); i.hasNext(); ) { + PaintListener l = (PaintListener) i.next(); + l.exposed(e); + } + } + + // + // Reflection helper .. + // + + private static Class[] getCustomConstructorArgumentTypes(Class windowClass) { + Class[] argTypes = null; + try { + Method m = windowClass.getDeclaredMethod("getCustomConstructorArgumentTypes", new Class[] {}); + argTypes = (Class[]) m.invoke(null, null); + } catch (Throwable t) {} + return argTypes; + } + + private static int verifyConstructorArgumentTypes(Class[] types, Object[] args) { + if(types.length != args.length) { + return -1; + } + for(int i=0; i*/ events = new LinkedList(); + + static class AWTEventWrapper { + AWTWindow window; + int type; + InputEvent e; + + AWTEventWrapper(AWTWindow w, int type, InputEvent e) { + this.window = w; + this.type = type; + this.e = e; + } + + public AWTWindow getWindow() { + return window; + } + + public int getType() { + return type; + } + + public InputEvent getEvent() { + return e; + } + } + + private static int convertModifiers(InputEvent e) { + int newtMods = 0; + int mods = e.getModifiers(); + if ((mods & InputEvent.SHIFT_MASK) != 0) newtMods |= com.jogamp.javafx.newt.InputEvent.SHIFT_MASK; + if ((mods & InputEvent.CTRL_MASK) != 0) newtMods |= com.jogamp.javafx.newt.InputEvent.CTRL_MASK; + if ((mods & InputEvent.META_MASK) != 0) newtMods |= com.jogamp.javafx.newt.InputEvent.META_MASK; + if ((mods & InputEvent.ALT_MASK) != 0) newtMods |= com.jogamp.javafx.newt.InputEvent.ALT_MASK; + if ((mods & InputEvent.ALT_GRAPH_MASK) != 0) newtMods |= com.jogamp.javafx.newt.InputEvent.ALT_GRAPH_MASK; + return newtMods; + } + + private static int convertButton(MouseEvent e) { + switch (e.getButton()) { + case MouseEvent.BUTTON1: return com.jogamp.javafx.newt.MouseEvent.BUTTON1; + case MouseEvent.BUTTON2: return com.jogamp.javafx.newt.MouseEvent.BUTTON2; + case MouseEvent.BUTTON3: return com.jogamp.javafx.newt.MouseEvent.BUTTON3; + } + return 0; + } + +} diff --git a/src/newt/classes/com/jogamp/javafx/newt/awt/AWTScreen.java b/src/newt/classes/com/jogamp/javafx/newt/awt/AWTScreen.java new file mode 100644 index 000000000..00da66078 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/awt/AWTScreen.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.awt; + +import com.jogamp.javafx.newt.*; +import java.awt.DisplayMode; +import javax.media.nativewindow.*; +import javax.media.nativewindow.awt.*; + +public class AWTScreen extends Screen { + public AWTScreen() { + } + + protected void createNative(int index) { + aScreen = new AWTGraphicsScreen((AWTGraphicsDevice)display.getGraphicsDevice()); + + DisplayMode mode = ((AWTGraphicsDevice)getDisplay().getGraphicsDevice()).getGraphicsDevice().getDisplayMode(); + int w = mode.getWidth(); + int h = mode.getHeight(); + setScreenSize(w, h); + } + + protected void setAWTGraphicsScreen(AWTGraphicsScreen s) { + aScreen = s; + } + + // done by AWTWindow .. + protected void setScreenSize(int w, int h) { + super.setScreenSize(w, h); + } + + protected void closeNative() { } + +} diff --git a/src/newt/classes/com/jogamp/javafx/newt/awt/AWTWindow.java b/src/newt/classes/com/jogamp/javafx/newt/awt/AWTWindow.java new file mode 100644 index 000000000..a0c2b6a89 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/awt/AWTWindow.java @@ -0,0 +1,429 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.awt; + +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.Container; +import java.awt.DisplayMode; +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; +import java.awt.event.*; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.*; +import com.jogamp.javafx.newt.Window; +import java.awt.Insets; +import javax.media.nativewindow.*; +import javax.media.nativewindow.awt.*; + +/** An implementation of the Newt Window class built using the + AWT. This is provided for convenience of porting to platforms + supporting Java SE. */ + +public class AWTWindow extends Window { + + public AWTWindow() { + this(null); + } + + public static Class[] getCustomConstructorArgumentTypes() { + return new Class[] { Container.class } ; + } + + public AWTWindow(Container container) { + super(); + title = "AWT NewtWindow"; + this.container = container; + if(container instanceof Frame) { + frame = (Frame) container; + } + } + + private boolean owningFrame; + private Container container = null; + private Frame frame = null; // same instance as container, just for impl. convenience + private AWTCanvas canvas; + // non fullscreen dimensions .. + private int nfs_width, nfs_height, nfs_x, nfs_y; + + public void setTitle(final String title) { + super.setTitle(title); + runOnEDT(true, new Runnable() { + public void run() { + if (frame != null) { + frame.setTitle(title); + } + } + }); + } + + protected void createNative(long parentWindowHandle, final Capabilities caps) { + + if(0!=parentWindowHandle) { + throw new RuntimeException("Window parenting not supported in AWT, use AWTWindow(Frame) cstr for wrapping instead"); + } + + final AWTWindow awtWindow = this; + + 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(caps); + Listener listener = new Listener(awtWindow); + canvas.addMouseListener(listener); + canvas.addMouseMotionListener(listener); + canvas.addKeyListener(listener); + canvas.addComponentListener(listener); + container.add(canvas, BorderLayout.CENTER); + container.setSize(width, height); + container.setLocation(x, y); + container.addComponentListener(new MoveListener(awtWindow)); + if(null!=frame) { + frame.setUndecorated(undecorated||fullscreen); + frame.addWindowListener(new WindowEventListener(awtWindow)); + } + } + }); + } + + protected void closeNative() { + runOnEDT(true, new Runnable() { + public void run() { + if(owningFrame && null!=frame) { + frame.dispose(); + owningFrame=false; + } + frame = null; + } + }); + } + + public boolean hasDeviceChanged() { + boolean res = canvas.hasDeviceChanged(); + if(res) { + config = canvas.getAWTGraphicsConfiguration(); + if (config == null) { + throw new NativeWindowException("Error Device change null GraphicsConfiguration: "+this); + } + updateDeviceData(); + } + return res; + } + + public void setVisible(final boolean visible) { + runOnEDT(true, new Runnable() { + public void run() { + container.setVisible(visible); + } + }); + + config = canvas.getAWTGraphicsConfiguration(); + + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + + updateDeviceData(); + } + + private void updateDeviceData() { + // propagate new info .. + ((AWTScreen)getScreen()).setAWTGraphicsScreen((AWTGraphicsScreen)config.getScreen()); + ((AWTDisplay)getScreen().getDisplay()).setAWTGraphicsDevice((AWTGraphicsDevice)config.getScreen().getDevice()); + + DisplayMode mode = ((AWTGraphicsDevice)config.getScreen().getDevice()).getGraphicsDevice().getDisplayMode(); + int w = mode.getWidth(); + int h = mode.getHeight(); + ((AWTScreen)screen).setScreenSize(w, h); + } + + public void setSize(final int width, final int height) { + this.width = width; + this.height = height; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + /** An AWT event on setSize() would bring us in a deadlock situation, hence invokeLater() */ + runOnEDT(false, new Runnable() { + public void run() { + Insets insets = container.getInsets(); + container.setSize(width + insets.left + insets.right, + height + insets.top + insets.bottom); + } + }); + } + + public com.jogamp.javafx.newt.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; + } + }); + return new com.jogamp.javafx.newt. + Insets(insets[0],insets[1],insets[2],insets[3]); + } + + public void setPosition(final int x, final int y) { + this.x = x; + this.y = y; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + runOnEDT(true, new Runnable() { + public void run() { + container.setLocation(x, y); + } + }); + } + + public boolean setFullscreen(final boolean fullscreen) { + if(this.fullscreen!=fullscreen) { + final int x,y,w,h; + this.fullscreen=fullscreen; + if(fullscreen) { + x = 0; y = 0; + w = screen.getWidth(); + h = screen.getHeight(); + } else { + x = nfs_x; + y = nfs_y; + w = nfs_width; + h = nfs_height; + } + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("AWTWindow fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); + } + /** An AWT event on setSize() would bring us in a deadlock situation, hence invokeLater() */ + runOnEDT(false, new Runnable() { + public void run() { + if(null!=frame) { + if(!container.isDisplayable()) { + frame.setUndecorated(undecorated||fullscreen); + } else { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("AWTWindow can't undecorate already created frame"); + } + } + } + container.setLocation(x, y); + container.setSize(w, h); + } + }); + } + return true; + } + + public Object getWrappedWindow() { + return canvas; + } + + protected void sendWindowEvent(int eventType) { + super.sendWindowEvent(eventType); + } + + protected void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { + super.sendKeyEvent(eventType, modifiers, keyCode, keyChar); + } + + protected void sendMouseEvent(int eventType, int modifiers, + int x, int y, int button, int rotation) { + super.sendMouseEvent(eventType, modifiers, x, y, button, rotation); + } + + private static void runOnEDT(boolean wait, Runnable r) { + if (EventQueue.isDispatchThread()) { + r.run(); + } else { + try { + if(wait) { + EventQueue.invokeAndWait(r); + } else { + EventQueue.invokeLater(r); + } + } catch (Exception e) { + throw new NativeWindowException(e); + } + } + } + + private static final int WINDOW_EVENT = 1; + private static final int KEY_EVENT = 2; + private static final int MOUSE_EVENT = 3; + + class MoveListener implements ComponentListener { + private AWTWindow window; + private AWTDisplay display; + + public MoveListener(AWTWindow w) { + window = w; + display = (AWTDisplay)window.getScreen().getDisplay(); + } + + public void componentResized(ComponentEvent e) { + } + + public void componentMoved(ComponentEvent e) { + if(null!=container) { + x = container.getX(); + y = container.getY(); + } + display.enqueueEvent(window, com.jogamp.javafx.newt.WindowEvent.EVENT_WINDOW_MOVED, null); + } + + public void componentShown(ComponentEvent e) { + } + + public void componentHidden(ComponentEvent e) { + } + + } + + class Listener implements ComponentListener, MouseListener, MouseMotionListener, KeyListener { + private AWTWindow window; + private AWTDisplay display; + + public Listener(AWTWindow w) { + window = w; + display = (AWTDisplay)window.getScreen().getDisplay(); + } + + public void componentResized(ComponentEvent e) { + width = canvas.getWidth(); + height = canvas.getHeight(); + display.enqueueEvent(window, com.jogamp.javafx.newt.WindowEvent.EVENT_WINDOW_RESIZED, null); + } + + public void componentMoved(ComponentEvent e) { + } + + public void componentShown(ComponentEvent e) { + } + + public void componentHidden(ComponentEvent e) { + } + + public void mouseClicked(MouseEvent e) { + // We ignore these as we synthesize them ourselves out of + // mouse pressed and released events + } + + public void mouseEntered(MouseEvent e) { + display.enqueueEvent(window, com.jogamp.javafx.newt.MouseEvent.EVENT_MOUSE_ENTERED, e); + } + + public void mouseExited(MouseEvent e) { + display.enqueueEvent(window, com.jogamp.javafx.newt.MouseEvent.EVENT_MOUSE_EXITED, e); + } + + public void mousePressed(MouseEvent e) { + display.enqueueEvent(window, com.jogamp.javafx.newt.MouseEvent.EVENT_MOUSE_PRESSED, e); + } + + public void mouseReleased(MouseEvent e) { + display.enqueueEvent(window, com.jogamp.javafx.newt.MouseEvent.EVENT_MOUSE_RELEASED, e); + } + + public void mouseMoved(MouseEvent e) { + display.enqueueEvent(window, com.jogamp.javafx.newt.MouseEvent.EVENT_MOUSE_MOVED, e); + } + + public void mouseDragged(MouseEvent e) { + display.enqueueEvent(window, com.jogamp.javafx.newt.MouseEvent.EVENT_MOUSE_DRAGGED, e); + } + + public void keyPressed(KeyEvent e) { + display.enqueueEvent(window, com.jogamp.javafx.newt.KeyEvent.EVENT_KEY_PRESSED, e); + } + + public void keyReleased(KeyEvent e) { + display.enqueueEvent(window, com.jogamp.javafx.newt.KeyEvent.EVENT_KEY_RELEASED, e); + } + + public void keyTyped(KeyEvent e) { + display.enqueueEvent(window, com.jogamp.javafx.newt.KeyEvent.EVENT_KEY_TYPED, e); + } + } + + class WindowEventListener implements WindowListener { + private AWTWindow window; + private AWTDisplay display; + + public WindowEventListener(AWTWindow w) { + window = w; + display = (AWTDisplay)window.getScreen().getDisplay(); + } + + public void windowActivated(WindowEvent e) { + } + public void windowClosed(WindowEvent e) { + } + public void windowClosing(WindowEvent e) { + display.enqueueEvent(window, com.jogamp.javafx.newt.WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY, null); + } + public void windowDeactivated(WindowEvent e) { + } + public void windowDeiconified(WindowEvent e) { + } + public void windowIconified(WindowEvent e) { + } + public void windowOpened(WindowEvent e) { + } + } +} diff --git a/src/newt/classes/com/jogamp/javafx/newt/impl/Debug.java b/src/newt/classes/com/jogamp/javafx/newt/impl/Debug.java new file mode 100644 index 000000000..bbabe72df --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/impl/Debug.java @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2003-2005 Sun Microsystems, Inc. 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. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.javafx.newt.impl; + +import java.security.*; + +/** Helper routines for logging and debugging. */ + +public class Debug { + // Some common properties + private static boolean verbose; + private static boolean debugAll; + private static AccessControlContext localACC; + + static { + localACC=AccessController.getContext(); + verbose = isPropertyDefined("newt.verbose", true); + debugAll = isPropertyDefined("newt.debug", true); + if (verbose) { + Package p = Package.getPackage("com.jogamp.javafx.newt"); + System.err.println("NEWT specification version " + p.getSpecificationVersion()); + System.err.println("NEWT implementation version " + p.getImplementationVersion()); + System.err.println("NEWT implementation vendor " + p.getImplementationVendor()); + } + } + + static int getIntProperty(final String property, final boolean jnlpAlias) { + return getIntProperty(property, jnlpAlias, localACC); + } + + public static int getIntProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + int i=0; + try { + Integer iv = Integer.valueOf(Debug.getProperty(property, jnlpAlias, acc)); + i = iv.intValue(); + } catch (NumberFormatException nfe) {} + return i; + } + + static boolean getBooleanProperty(final String property, final boolean jnlpAlias) { + return getBooleanProperty(property, jnlpAlias, localACC); + } + + public static boolean getBooleanProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + Boolean b = Boolean.valueOf(Debug.getProperty(property, jnlpAlias, acc)); + return b.booleanValue(); + } + + static boolean isPropertyDefined(final String property, final boolean jnlpAlias) { + return isPropertyDefined(property, jnlpAlias, localACC); + } + + public static boolean isPropertyDefined(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + return (Debug.getProperty(property, jnlpAlias, acc) != null) ? true : false; + } + + static String getProperty(final String property, final boolean jnlpAlias) { + return getProperty(property, jnlpAlias, localACC); + } + + public static String getProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + String s=null; + if(null!=acc && acc.equals(localACC)) { + s = (String) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String val=null; + try { + val = System.getProperty(property); + } catch (Exception e) {} + if(null==val && jnlpAlias && !property.startsWith(jnlp_prefix)) { + try { + val = System.getProperty(jnlp_prefix + property); + } catch (Exception e) {} + } + return val; + } + }); + } else { + try { + s = System.getProperty(property); + } catch (Exception e) {} + if(null==s && jnlpAlias && !property.startsWith(jnlp_prefix)) { + try { + s = System.getProperty(jnlp_prefix + property); + } catch (Exception e) {} + } + } + return s; + } + public static final String jnlp_prefix = "jnlp." ; + + public static boolean verbose() { + return verbose; + } + + public static boolean debugAll() { + return debugAll; + } + + public static boolean debug(String subcomponent) { + return debugAll() || isPropertyDefined("newt.debug." + subcomponent, true); + } +} diff --git a/src/newt/classes/com/jogamp/javafx/newt/impl/NativeLibLoader.java b/src/newt/classes/com/jogamp/javafx/newt/impl/NativeLibLoader.java new file mode 100644 index 000000000..9bbfc5921 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/impl/NativeLibLoader.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. 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. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.javafx.newt.impl; + +// FIXME: refactor Java SE dependencies +//import java.awt.Toolkit; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.HashSet; +import com.jogamp.nativewindow.impl.NativeLibLoaderBase; + +public class NativeLibLoader extends NativeLibLoaderBase { + + public static void loadNEWT() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + loadLibrary("newt", null, true); + return null; + } + }); + } + +} diff --git a/src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Display.java b/src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Display.java new file mode 100644 index 000000000..3198c7511 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Display.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.intel.gdl; + +import com.jogamp.javafx.newt.impl.*; +import javax.media.nativewindow.*; + +public class Display extends com.jogamp.javafx.newt.Display { + static int initCounter = 0; + + static { + NativeLibLoader.loadNEWT(); + + if (!Screen.initIDs()) { + throw new NativeWindowException("Failed to initialize GDL Screen jmethodIDs"); + } + if (!Window.initIDs()) { + throw new NativeWindowException("Failed to initialize GDL Window jmethodIDs"); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + + public Display() { + } + + protected void createNative() { + synchronized(Display.class) { + if(0==initCounter) { + displayHandle = CreateDisplay(); + if(0==displayHandle) { + throw new NativeWindowException("Couldn't initialize GDL Display"); + } + } + initCounter++; + } + aDevice = new DefaultGraphicsDevice(NativeWindowFactory.TYPE_DEFAULT, displayHandle); + } + + protected void closeNative() { + if(0==displayHandle) { + throw new NativeWindowException("displayHandle null; initCnt "+initCounter); + } + synchronized(Display.class) { + if(initCounter>0) { + initCounter--; + if(0==initCounter) { + DestroyDisplay(displayHandle); + } + } + } + } + + protected void dispatchMessages() { + if(0!=displayHandle) { + DispatchMessages(displayHandle, focusedWindow); + } + } + + protected void setFocus(Window focus) { + focusedWindow = focus; + } + + private long displayHandle = 0; + private Window focusedWindow = null; + private native long CreateDisplay(); + private native void DestroyDisplay(long displayHandle); + private native void DispatchMessages(long displayHandle, Window focusedWindow); +} + diff --git a/src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Screen.java b/src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Screen.java new file mode 100644 index 000000000..a09b1e790 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Screen.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.intel.gdl; + +import com.jogamp.javafx.newt.impl.*; +import javax.media.nativewindow.*; + +public class Screen extends com.jogamp.javafx.newt.Screen { + + static { + Display.initSingleton(); + } + + public Screen() { + } + + protected void createNative(int index) { + AbstractGraphicsDevice adevice = getDisplay().getGraphicsDevice(); + GetScreenInfo(adevice.getHandle(), index); + aScreen = new DefaultGraphicsScreen(adevice, index); + } + + protected void closeNative() { } + + //---------------------------------------------------------------------- + // Internals only + // + + protected static native boolean initIDs(); + private native void GetScreenInfo(long displayHandle, int screen_idx); + + // called by GetScreenInfo() .. + private void screenCreated(int width, int height) { + setScreenSize(width, height); + } +} + diff --git a/src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Window.java b/src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Window.java new file mode 100644 index 000000000..28ffa1296 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Window.java @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.intel.gdl; + +import javax.media.nativewindow.*; + +public class Window extends com.jogamp.javafx.newt.Window { + static { + Display.initSingleton(); + } + + public Window() { + } + + static long nextWindowHandle = 1; + + protected void createNative(long parentWindowHandle, Capabilities caps) { + if(0!=parentWindowHandle) { + throw new NativeWindowException("GDL Window does not support window parenting"); + } + AbstractGraphicsScreen aScreen = screen.getGraphicsScreen(); + AbstractGraphicsDevice aDevice = screen.getDisplay().getGraphicsDevice(); + + config = GraphicsConfigurationFactory.getFactory(aDevice).chooseGraphicsConfiguration(caps, null, aScreen); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + + synchronized(Window.class) { + windowHandle = nextWindowHandle++; + } + } + + protected void closeNative() { + if(0!=surfaceHandle) { + synchronized(Window.class) { + CloseSurface(getDisplayHandle(), surfaceHandle); + } + surfaceHandle = 0; + ((Display)screen.getDisplay()).setFocus(null); + } + } + + public void setVisible(boolean visible) { + if(this.visible!=visible) { + this.visible=visible; + if(visible && 0==surfaceHandle) { + synchronized(Window.class) { + AbstractGraphicsDevice aDevice = screen.getDisplay().getGraphicsDevice(); + surfaceHandle = CreateSurface(aDevice.getHandle(), screen.getWidth(), screen.getHeight(), x, y, width, height); + } + if (surfaceHandle == 0) { + throw new NativeWindowException("Error creating window"); + } + ((Display)screen.getDisplay()).setFocus(this); + } + } + } + + public void setSize(int width, int height) { + Screen screen = (Screen) getScreen(); + if((x+width)>screen.getWidth()) { + width=screen.getWidth()-x; + } + if((y+height)>screen.getHeight()) { + height=screen.getHeight()-y; + } + this.width = width; + this.height = height; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + if(0!=surfaceHandle) { + SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, width, height); + } + } + + public void setPosition(int x, int y) { + Screen screen = (Screen) getScreen(); + if((x+width)>screen.getWidth()) { + x=screen.getWidth()-width; + } + if((y+height)>screen.getHeight()) { + y=screen.getHeight()-height; + } + this.x = x; + this.y = y; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + if(0!=surfaceHandle) { + SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, width, height); + } + } + + public boolean setFullscreen(boolean fullscreen) { + if(this.fullscreen!=fullscreen) { + int x,y,w,h; + this.fullscreen=fullscreen; + if(fullscreen) { + x = 0; y = 0; + w = screen.getWidth(); + h = screen.getHeight(); + } else { + x = nfs_x; + y = nfs_y; + w = nfs_width; + h = nfs_height; + } + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("IntelGDL Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); + } + if(0!=surfaceHandle) { + SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, w, h); + } + } + return fullscreen; + } + + public void requestFocus() { + ((Display)screen.getDisplay()).setFocus(this); + } + + public long getSurfaceHandle() { + return surfaceHandle; + } + + //---------------------------------------------------------------------- + // Internals only + // + + protected static native boolean initIDs(); + private native long CreateSurface(long displayHandle, int scrn_width, int scrn_height, int x, int y, int width, int height); + private native void CloseSurface(long displayHandle, long surfaceHandle); + private native void SetBounds0(long surfaceHandle, int scrn_width, int scrn_height, int x, int y, int width, int height); + + private void updateBounds(int x, int y, int width, int height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + private long surfaceHandle; + private int nfs_width, nfs_height, nfs_x, nfs_y; +} diff --git a/src/newt/classes/com/jogamp/javafx/newt/macosx/MacDisplay.java b/src/newt/classes/com/jogamp/javafx/newt/macosx/MacDisplay.java new file mode 100755 index 000000000..4d78358d7 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/macosx/MacDisplay.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.macosx; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.macosx.*; +import com.jogamp.javafx.newt.*; +import com.jogamp.javafx.newt.impl.*; +import com.jogamp.javafx.newt.util.MainThread; + +public class MacDisplay extends Display { + static { + NativeLibLoader.loadNEWT(); + + if(!initNSApplication()) { + throw new NativeWindowException("Failed to initialize native Application hook"); + } + if(!MacWindow.initIDs()) { + throw new NativeWindowException("Failed to initialize jmethodIDs"); + } + if(DEBUG) System.out.println("MacDisplay.init App and IDs OK "+Thread.currentThread().getName()); + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + public MacDisplay() { + } + + class DispatchAction implements Runnable { + public void run() { + dispatchMessages0(); + } + } + private DispatchAction dispatchAction = new DispatchAction(); + + public void dispatchMessages() { + MainThread.invoke(false, dispatchAction); + } + + protected void createNative() { + aDevice = new MacOSXGraphicsDevice(); + } + + protected void closeNative() { } + + private static native boolean initNSApplication(); + protected native void dispatchMessages0(); +} + diff --git a/src/newt/classes/com/jogamp/javafx/newt/macosx/MacScreen.java b/src/newt/classes/com/jogamp/javafx/newt/macosx/MacScreen.java new file mode 100755 index 000000000..8d0be80dc --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/macosx/MacScreen.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.macosx; + +import com.jogamp.javafx.newt.*; +import javax.media.nativewindow.*; + +public class MacScreen extends Screen { + static { + MacDisplay.initSingleton(); + } + + public MacScreen() { + } + + protected void createNative(int index) { + aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); + setScreenSize(getWidthImpl(getIndex()), getHeightImpl(getIndex())); + } + + protected void closeNative() { } + + private static native int getWidthImpl(int scrn_idx); + private static native int getHeightImpl(int scrn_idx); +} diff --git a/src/newt/classes/com/jogamp/javafx/newt/macosx/MacWindow.java b/src/newt/classes/com/jogamp/javafx/newt/macosx/MacWindow.java new file mode 100755 index 000000000..f1698bfcd --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/macosx/MacWindow.java @@ -0,0 +1,600 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.macosx; + +import javax.media.nativewindow.*; + +import com.jogamp.javafx.newt.util.MainThread; +import com.jogamp.javafx.newt.*; +import com.jogamp.javafx.newt.impl.*; + +public class MacWindow extends Window { + + // Window styles + private static final int NSBorderlessWindowMask = 0; + private static final int NSTitledWindowMask = 1 << 0; + private static final int NSClosableWindowMask = 1 << 1; + private static final int NSMiniaturizableWindowMask = 1 << 2; + private static final int NSResizableWindowMask = 1 << 3; + + // Window backing store types + private static final int NSBackingStoreRetained = 0; + private static final int NSBackingStoreNonretained = 1; + private static final int NSBackingStoreBuffered = 2; + + // Key constants handled differently on Mac OS X than other platforms + private static final int NSUpArrowFunctionKey = 0xF700; + private static final int NSDownArrowFunctionKey = 0xF701; + private static final int NSLeftArrowFunctionKey = 0xF702; + private static final int NSRightArrowFunctionKey = 0xF703; + private static final int NSF1FunctionKey = 0xF704; + private static final int NSF2FunctionKey = 0xF705; + private static final int NSF3FunctionKey = 0xF706; + private static final int NSF4FunctionKey = 0xF707; + private static final int NSF5FunctionKey = 0xF708; + private static final int NSF6FunctionKey = 0xF709; + private static final int NSF7FunctionKey = 0xF70A; + private static final int NSF8FunctionKey = 0xF70B; + private static final int NSF9FunctionKey = 0xF70C; + private static final int NSF10FunctionKey = 0xF70D; + private static final int NSF11FunctionKey = 0xF70E; + private static final int NSF12FunctionKey = 0xF70F; + private static final int NSF13FunctionKey = 0xF710; + private static final int NSF14FunctionKey = 0xF711; + private static final int NSF15FunctionKey = 0xF712; + private static final int NSF16FunctionKey = 0xF713; + private static final int NSF17FunctionKey = 0xF714; + private static final int NSF18FunctionKey = 0xF715; + private static final int NSF19FunctionKey = 0xF716; + private static final int NSF20FunctionKey = 0xF717; + private static final int NSF21FunctionKey = 0xF718; + private static final int NSF22FunctionKey = 0xF719; + private static final int NSF23FunctionKey = 0xF71A; + private static final int NSF24FunctionKey = 0xF71B; + private static final int NSF25FunctionKey = 0xF71C; + private static final int NSF26FunctionKey = 0xF71D; + private static final int NSF27FunctionKey = 0xF71E; + private static final int NSF28FunctionKey = 0xF71F; + private static final int NSF29FunctionKey = 0xF720; + private static final int NSF30FunctionKey = 0xF721; + private static final int NSF31FunctionKey = 0xF722; + private static final int NSF32FunctionKey = 0xF723; + private static final int NSF33FunctionKey = 0xF724; + private static final int NSF34FunctionKey = 0xF725; + private static final int NSF35FunctionKey = 0xF726; + private static final int NSInsertFunctionKey = 0xF727; + private static final int NSDeleteFunctionKey = 0xF728; + private static final int NSHomeFunctionKey = 0xF729; + private static final int NSBeginFunctionKey = 0xF72A; + private static final int NSEndFunctionKey = 0xF72B; + private static final int NSPageUpFunctionKey = 0xF72C; + private static final int NSPageDownFunctionKey = 0xF72D; + private static final int NSPrintScreenFunctionKey = 0xF72E; + private static final int NSScrollLockFunctionKey = 0xF72F; + private static final int NSPauseFunctionKey = 0xF730; + private static final int NSSysReqFunctionKey = 0xF731; + private static final int NSBreakFunctionKey = 0xF732; + private static final int NSResetFunctionKey = 0xF733; + private static final int NSStopFunctionKey = 0xF734; + private static final int NSMenuFunctionKey = 0xF735; + private static final int NSUserFunctionKey = 0xF736; + private static final int NSSystemFunctionKey = 0xF737; + private static final int NSPrintFunctionKey = 0xF738; + private static final int NSClearLineFunctionKey = 0xF739; + private static final int NSClearDisplayFunctionKey = 0xF73A; + private static final int NSInsertLineFunctionKey = 0xF73B; + private static final int NSDeleteLineFunctionKey = 0xF73C; + private static final int NSInsertCharFunctionKey = 0xF73D; + private static final int NSDeleteCharFunctionKey = 0xF73E; + private static final int NSPrevFunctionKey = 0xF73F; + private static final int NSNextFunctionKey = 0xF740; + private static final int NSSelectFunctionKey = 0xF741; + private static final int NSExecuteFunctionKey = 0xF742; + private static final int NSUndoFunctionKey = 0xF743; + private static final int NSRedoFunctionKey = 0xF744; + private static final int NSFindFunctionKey = 0xF745; + private static final int NSHelpFunctionKey = 0xF746; + private static final int NSModeSwitchFunctionKey = 0xF747; + + private volatile long surfaceHandle; + private long parentWindowHandle; + + // non fullscreen dimensions .. + private int nfs_width, nfs_height, nfs_x, nfs_y; + private final Insets insets = new Insets(0,0,0,0); + + static { + MacDisplay.initSingleton(); + } + + public MacWindow() { + } + + protected void createNative(long parentWindowHandle, Capabilities caps) { + this.parentWindowHandle=parentWindowHandle; + config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + } + + class CloseAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.CloseAction "+Thread.currentThread().getName()); + if (windowHandle != 0) { + close0(windowHandle); + windowHandle = 0; + } + } finally { + nsViewLock.unlock(); + } + } + } + private CloseAction closeAction = new CloseAction(); + + protected void closeNative() { + MainThread.invoke(true, closeAction); + } + + public long getWindowHandle() { + nsViewLock.lock(); + try { + return windowHandle; + } finally { + nsViewLock.unlock(); + } + } + + public long getSurfaceHandle() { + nsViewLock.lock(); + try { + return surfaceHandle; + } finally { + nsViewLock.unlock(); + } + } + + class EnsureWindowCreatedAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + createWindow(parentWindowHandle, false); + } finally { + nsViewLock.unlock(); + } + } + } + private EnsureWindowCreatedAction ensureWindowCreatedAction = + new EnsureWindowCreatedAction(); + + public Insets getInsets() { + // in order to properly calculate insets we need the window to be + // created + MainThread.invoke(true, ensureWindowCreatedAction); + nsViewLock.lock(); + try { + return (Insets) insets.clone(); + } finally { + nsViewLock.unlock(); + } + } + + private ToolkitLock nsViewLock = new ToolkitLock() { + private Thread owner; + private int recursionCount; + + public synchronized void lock() { + Thread cur = Thread.currentThread(); + if (owner == cur) { + ++recursionCount; + return; + } + while (owner != null) { + try { + wait(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + owner = cur; + } + + public synchronized void unlock() { + if (owner != Thread.currentThread()) { + throw new RuntimeException("Not owner"); + } + if (recursionCount > 0) { + --recursionCount; + return; + } + owner = null; + notifyAll(); + } + }; + + public synchronized int lockSurface() throws NativeWindowException { + nsViewLock.lock(); + return super.lockSurface(); + } + + public void unlockSurface() { + super.unlockSurface(); + nsViewLock.unlock(); + } + + class VisibleAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.VisibleAction "+visible+" "+Thread.currentThread().getName()); + if (visible) { + createWindow(parentWindowHandle, false); + if (windowHandle != 0) { + makeKeyAndOrderFront(windowHandle); + } + } else { + if (windowHandle != 0) { + orderOut(windowHandle); + } + } + } finally { + nsViewLock.unlock(); + } + } + } + private VisibleAction visibleAction = new VisibleAction(); + + public void setVisible(boolean visible) { + this.visible = visible; + MainThread.invoke(true, visibleAction); + } + + class TitleAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if (windowHandle != 0) { + setTitle0(windowHandle, title); + } + } finally { + nsViewLock.unlock(); + } + } + } + private TitleAction titleAction = new TitleAction(); + + public void setTitle(String title) { + super.setTitle(title); + MainThread.invoke(true, titleAction); + } + + class FocusAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if (windowHandle != 0) { + makeKey(windowHandle); + } + } finally { + nsViewLock.unlock(); + } + } + } + private FocusAction focusAction = new FocusAction(); + + public void requestFocus() { + super.requestFocus(); + MainThread.invoke(true, focusAction); + } + + class SizeAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if (windowHandle != 0) { + setContentSize(windowHandle, width, height); + } + } finally { + nsViewLock.unlock(); + } + } + } + private SizeAction sizeAction = new SizeAction(); + + public void setSize(int width, int height) { + this.width=width; + this.height=height; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + MainThread.invoke(true, sizeAction); + } + + class PositionAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if (windowHandle != 0) { + setFrameTopLeftPoint(parentWindowHandle, windowHandle, x, y); + } + } finally { + nsViewLock.unlock(); + } + } + } + private PositionAction positionAction = new PositionAction(); + + public void setPosition(int x, int y) { + this.x=x; + this.y=y; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + MainThread.invoke(true, positionAction); + } + + class FullscreenAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("MacWindow fs: "+fullscreen+" "+x+"/"+y+" "+width+"x"+height); + } + createWindow(parentWindowHandle, true); + if (windowHandle != 0) { + makeKeyAndOrderFront(windowHandle); + } + } finally { + nsViewLock.unlock(); + } + } + } + private FullscreenAction fullscreenAction = new FullscreenAction(); + + public boolean setFullscreen(boolean fullscreen) { + if(this.fullscreen!=fullscreen) { + this.fullscreen=fullscreen; + if(fullscreen) { + x = 0; + y = 0; + width = screen.getWidth(); + height = screen.getHeight(); + } else { + x = nfs_x; + y = nfs_y; + width = nfs_width; + height = nfs_height; + } + MainThread.invoke(true, fullscreenAction); + } + return fullscreen; + } + + private void sizeChanged(int newWidth, int newHeight) { + if (DEBUG_IMPLEMENTATION) { + System.out.println(Thread.currentThread().getName()+" Size changed to " + newWidth + ", " + newHeight); + } + width = newWidth; + height = newHeight; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + if (DEBUG_IMPLEMENTATION) { + System.out.println(" Posted WINDOW_RESIZED event"); + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + } + + private void insetsChanged(int left, int top, int right, int bottom) { + if (DEBUG_IMPLEMENTATION) { + System.out.println(Thread.currentThread().getName()+ + " Insets changed to " + left + ", " + top + ", " + right + ", " + bottom); + } + if (left != -1 && top != -1 && right != -1 && bottom != -1) { + insets.left = left; + insets.top = top; + insets.right = right; + insets.bottom = bottom; + } + } + + private void positionChanged(int newX, int newY) { + if (DEBUG_IMPLEMENTATION) { + System.out.println(Thread.currentThread().getName()+" Position changed to " + newX + ", " + newY); + } + x = newX; + y = newY; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + if (DEBUG_IMPLEMENTATION) { + System.out.println(" Posted WINDOW_MOVED event"); + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); + } + + private void focusChanged(boolean focusGained) { + if (focusGained) { + sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); + } else { + sendWindowEvent(WindowEvent.EVENT_WINDOW_LOST_FOCUS); + } + } + + private char convertKeyChar(char keyChar) { + if (keyChar == '\r') { + // Turn these into \n + return '\n'; + } + + if (keyChar >= NSUpArrowFunctionKey && keyChar <= NSModeSwitchFunctionKey) { + switch (keyChar) { + case NSUpArrowFunctionKey: return KeyEvent.VK_UP; + case NSDownArrowFunctionKey: return KeyEvent.VK_DOWN; + case NSLeftArrowFunctionKey: return KeyEvent.VK_LEFT; + case NSRightArrowFunctionKey: return KeyEvent.VK_RIGHT; + case NSF1FunctionKey: return KeyEvent.VK_F1; + case NSF2FunctionKey: return KeyEvent.VK_F2; + case NSF3FunctionKey: return KeyEvent.VK_F3; + case NSF4FunctionKey: return KeyEvent.VK_F4; + case NSF5FunctionKey: return KeyEvent.VK_F5; + case NSF6FunctionKey: return KeyEvent.VK_F6; + case NSF7FunctionKey: return KeyEvent.VK_F7; + case NSF8FunctionKey: return KeyEvent.VK_F8; + case NSF9FunctionKey: return KeyEvent.VK_F9; + case NSF10FunctionKey: return KeyEvent.VK_F10; + case NSF11FunctionKey: return KeyEvent.VK_F11; + case NSF12FunctionKey: return KeyEvent.VK_F12; + case NSF13FunctionKey: return KeyEvent.VK_F13; + case NSF14FunctionKey: return KeyEvent.VK_F14; + case NSF15FunctionKey: return KeyEvent.VK_F15; + case NSF16FunctionKey: return KeyEvent.VK_F16; + case NSF17FunctionKey: return KeyEvent.VK_F17; + case NSF18FunctionKey: return KeyEvent.VK_F18; + case NSF19FunctionKey: return KeyEvent.VK_F19; + case NSF20FunctionKey: return KeyEvent.VK_F20; + case NSF21FunctionKey: return KeyEvent.VK_F21; + case NSF22FunctionKey: return KeyEvent.VK_F22; + case NSF23FunctionKey: return KeyEvent.VK_F23; + case NSF24FunctionKey: return KeyEvent.VK_F24; + case NSInsertFunctionKey: return KeyEvent.VK_INSERT; + case NSDeleteFunctionKey: return KeyEvent.VK_DELETE; + case NSHomeFunctionKey: return KeyEvent.VK_HOME; + case NSBeginFunctionKey: return KeyEvent.VK_BEGIN; + case NSEndFunctionKey: return KeyEvent.VK_END; + case NSPageUpFunctionKey: return KeyEvent.VK_PAGE_UP; + case NSPageDownFunctionKey: return KeyEvent.VK_PAGE_DOWN; + case NSPrintScreenFunctionKey: return KeyEvent.VK_PRINTSCREEN; + case NSScrollLockFunctionKey: return KeyEvent.VK_SCROLL_LOCK; + case NSPauseFunctionKey: return KeyEvent.VK_PAUSE; + // Not handled: + // NSSysReqFunctionKey + // NSBreakFunctionKey + // NSResetFunctionKey + case NSStopFunctionKey: return KeyEvent.VK_STOP; + // Not handled: + // NSMenuFunctionKey + // NSUserFunctionKey + // NSSystemFunctionKey + // NSPrintFunctionKey + // NSClearLineFunctionKey + // NSClearDisplayFunctionKey + // NSInsertLineFunctionKey + // NSDeleteLineFunctionKey + // NSInsertCharFunctionKey + // NSDeleteCharFunctionKey + // NSPrevFunctionKey + // NSNextFunctionKey + // NSSelectFunctionKey + // NSExecuteFunctionKey + // NSUndoFunctionKey + // NSRedoFunctionKey + // NSFindFunctionKey + // NSHelpFunctionKey + // NSModeSwitchFunctionKey + default: break; + } + } + + // NSEvent's charactersIgnoringModifiers doesn't ignore the shift key + if (keyChar >= 'a' && keyChar <= 'z') { + return Character.toUpperCase(keyChar); + } + + return keyChar; + } + + protected void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { + int key = convertKeyChar(keyChar); + if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.sendKeyEvent "+Thread.currentThread().getName()); + // Note that we send the key char for the key code on this + // platform -- we do not get any useful key codes out of the system + super.sendKeyEvent(eventType, modifiers, key, keyChar); + } + + private void createWindow(long parentWindowHandle, boolean recreate) { + if(0!=windowHandle && !recreate) { + return; + } + if(0!=windowHandle) { + // save the view .. close the window + surfaceHandle = changeContentView(parentWindowHandle, windowHandle, 0); + if(recreate && 0==surfaceHandle) { + throw new NativeWindowException("Internal Error - recreate, window but no view"); + } + close0(windowHandle); + windowHandle=0; + } else { + surfaceHandle = 0; + } + windowHandle = createWindow0(parentWindowHandle, + getX(), getY(), getWidth(), getHeight(), fullscreen, + (isUndecorated() ? + NSBorderlessWindowMask : + NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask), + NSBackingStoreBuffered, + getScreen().getIndex(), surfaceHandle); + if (windowHandle == 0) { + throw new NativeWindowException("Could create native window "+Thread.currentThread().getName()+" "+this); + } + surfaceHandle = contentView(windowHandle); + setTitle0(windowHandle, getTitle()); + // don't make the window visible on window creation +// makeKeyAndOrderFront(windowHandle); + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); + } + + protected static native boolean initIDs(); + private native long createWindow0(long parentWindowHandle, int x, int y, int w, int h, + boolean fullscreen, int windowStyle, + int backingStoreType, + int screen_idx, long view); + private native void makeKeyAndOrderFront(long window); + private native void makeKey(long window); + private native void orderOut(long window); + private native void close0(long window); + private native void setTitle0(long window, String title); + private native long contentView(long window); + private native long changeContentView(long parentWindowHandle, long window, long view); + private native void setContentSize(long window, int w, int h); + private native void setFrameTopLeftPoint(long parentWindowHandle, long window, int x, int y); +} diff --git a/src/newt/classes/com/jogamp/javafx/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/javafx/newt/opengl/GLWindow.java new file mode 100644 index 000000000..b299d011e --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/opengl/GLWindow.java @@ -0,0 +1,628 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.opengl; + +import com.jogamp.javafx.newt.*; +import javax.media.nativewindow.*; +import javax.media.opengl.*; +import com.jogamp.opengl.impl.GLDrawableHelper; +import java.util.*; + +/** + * An implementation of {@link Window} which is customized for OpenGL + * use, and which implements the {@link javax.media.opengl.GLAutoDrawable} interface. + *

+ * This implementation does not make the OpenGL context current
+ * before calling the various input EventListener callbacks (MouseListener, KeyListener, + * etc.).
+ * This design decision is made to favor a more performant and simplified + * implementation, as well as the event dispatcher shall be allowed + * not having a notion about OpenGL. + *

+ */ +public class GLWindow extends Window implements GLAutoDrawable { + private static List/*GLWindow*/ glwindows = new ArrayList(); + + private boolean ownerOfWinScrDpy; + private Window window; + private boolean runPumpMessages; + + /** Constructor. Do not call this directly -- use {@link + create()} instead. */ + protected GLWindow(Window window, boolean ownerOfWinScrDpy) { + this.ownerOfWinScrDpy = ownerOfWinScrDpy; + this.window = window; + this.window.setAutoDrawableClient(true); + this.runPumpMessages = ( null == getScreen().getDisplay().getEDT() ) ; + window.addWindowListener(new WindowListener() { + public void windowResized(WindowEvent e) { + sendReshape = true; + } + + public void windowMoved(WindowEvent e) { + } + + public void windowGainedFocus(WindowEvent e) { + } + + public void windowLostFocus(WindowEvent e) { + } + + public void windowDestroyNotify(WindowEvent e) { + sendDestroy = true; + } + }); + + List newglw = (List) ((ArrayList) glwindows).clone(); + newglw.add(this); + glwindows=newglw; + } + + /** Creates a new GLWindow on the local display, screen 0, with a + dummy visual ID, and with the default GLCapabilities. */ + public static GLWindow create() { + return create(null, null, false); + } + + public static GLWindow create(boolean undecorated) { + return create(null, null, undecorated); + } + + /** Creates a new GLWindow referring to the given window. */ + public static GLWindow create(Window window) { + return create(window, null, false); + } + public static GLWindow create(GLCapabilities caps) { + return create(null, caps, false); + } + + /** Creates a new GLWindow on the local display, screen 0, with a + dummy visual ID, and with the given GLCapabilities. */ + public static GLWindow create(GLCapabilities caps, boolean undecorated) { + return create(null, caps, undecorated); + } + + /** Either or: window (prio), or caps and undecorated (2nd choice) */ + private static GLWindow create(Window window, + GLCapabilities caps, + boolean undecorated) { + Display display; + boolean ownerOfWinScrDpy=false; + if (window == null) { + if (caps == null) { + caps = new GLCapabilities(null); // default .. + } + ownerOfWinScrDpy = true; + display = NewtFactory.createDisplay(null); // local display + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + window = NewtFactory.createWindow(screen, caps, undecorated); + } + + return new GLWindow(window, ownerOfWinScrDpy); + } + + /** + * EXPERIMENTAL
+ * Enable or disables running the {@link Display#pumpMessages} in the {@link #display()} call.
+ * The default behavior is to run {@link Display#pumpMessages}.

+ * + * The idea was that in a single threaded environment with one {@link Display} and many {@link Window}'s, + * a performance benefit was expected while disabling the implicit {@link Display#pumpMessages} and + * do it once via {@link GLWindow#runCurrentThreadPumpMessage()}
+ * This could not have been verified. No measurable difference could have been recognized.

+ * + * Best performance has been achieved with one GLWindow per thread.
+ * + * Enabling local pump messages while using the EDT, + * {@link com.jogamp.javafx.newt.NewtFactory#setUseEDT(boolean)}, + * will result in an exception. + * + * @deprecated EXPERIMENTAL, semantic is about to be removed after further verification. + */ + public void setRunPumpMessages(boolean onoff) { + if( onoff && null!=getScreen().getDisplay().getEDT() ) { + throw new GLException("GLWindow.setRunPumpMessages(true) - Can't do with EDT on"); + } + runPumpMessages = onoff; + } + + protected void createNative(long parentWindowHandle, Capabilities caps) { + shouldNotCallThis(); + } + + protected void closeNative() { + shouldNotCallThis(); + } + + protected void dispose(boolean regenerate, boolean sendEvent) { + if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { + Exception e1 = new Exception("GLWindow.dispose("+regenerate+") "+Thread.currentThread()+", 1"); + e1.printStackTrace(); + } + + if(sendEvent) { + sendDisposeEvent(); + } + + if (context != null) { + context.destroy(); + } + if (drawable != null) { + drawable.setRealized(false); + } + + if(regenerate) { + if(null==window) { + throw new GLException("GLWindow.dispose(true): null window"); + } + + // recreate GLDrawable, to reflect the new graphics configurations + NativeWindow nw; + if (window.getWrappedWindow() != null) { + nw = NativeWindowFactory.getNativeWindow(window.getWrappedWindow(), window.getGraphicsConfiguration()); + } else { + nw = window; + } + drawable = factory.createGLDrawable(nw); + drawable.setRealized(true); + context = drawable.createContext(null); + sendReshape = true; // ensure a reshape event is send .. + } + + if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { + System.out.println("GLWindow.dispose("+regenerate+") "+Thread.currentThread()+", fin: "+this); + } + } + + public synchronized void destroy() { + destroy(true); + } + + /** @param sendDisposeEvent should be false in a [time,reliable] critical shutdown */ + public synchronized void destroy(boolean sendDisposeEvent) { + if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { + Exception e1 = new Exception("GLWindow.destroy "+Thread.currentThread()+", 1: "+this); + e1.printStackTrace(); + } + + List newglw = (List) ((ArrayList) glwindows).clone(); + newglw.remove(this); + glwindows=newglw; + + dispose(false, sendDisposeEvent); + + if(null!=window) { + if(ownerOfWinScrDpy) { + window.destroy(true); + } + } + + drawable = null; + context = null; + window = null; + + if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { + System.out.println("GLWindow.destroy "+Thread.currentThread()+", fin: "+this); + } + } + + public boolean getPerfLogEnabled() { return perfLog; } + + public void enablePerfLog(boolean v) { + perfLog = v; + } + + public void setVisible(boolean visible) { + if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { + System.out.println(Thread.currentThread()+" GLWindow.setVisible("+visible+") START ; isVisible "+this.visible+" ; has context "+(null!=context)); + } + this.visible=visible; + window.setVisible(visible); + if (visible && context == null) { + NativeWindow nw; + if (window.getWrappedWindow() != null) { + nw = NativeWindowFactory.getNativeWindow(window.getWrappedWindow(), window.getGraphicsConfiguration()); + } else { + nw = window; + } + GLCapabilities glCaps = (GLCapabilities) nw.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + factory = GLDrawableFactory.getFactory(glCaps.getGLProfile()); + drawable = factory.createGLDrawable(nw); + drawable.setRealized(true); + context = drawable.createContext(null); + sendReshape = true; // ensure a reshape event is send .. + } + if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { + System.out.println(Thread.currentThread()+" GLWindow.setVisible("+visible+") END ; has context "+(null!=context)); + } + } + + public Screen getScreen() { + return window.getScreen(); + } + + public void setTitle(String title) { + window.setTitle(title); + } + + public String getTitle() { + return window.getTitle(); + } + + public void setUndecorated(boolean value) { + window.setUndecorated(value); + } + + public boolean isUndecorated() { + return window.isUndecorated(); + } + + public void setSize(int width, int height) { + window.setSize(width, height); + } + + public void setPosition(int x, int y) { + window.setPosition(x, y); + } + + public Insets getInsets() { + return window.getInsets(); + } + + public boolean setFullscreen(boolean fullscreen) { + return window.setFullscreen(fullscreen); + } + + public boolean isVisible() { + return window.isVisible(); + } + + public int getX() { + return window.getX(); + } + + public int getY() { + return window.getY(); + } + + public int getWidth() { + return window.getWidth(); + } + + public int getHeight() { + return window.getHeight(); + } + + public boolean isFullscreen() { + return window.isFullscreen(); + } + + public void addSurfaceUpdatedListener(SurfaceUpdatedListener l) { + window.addSurfaceUpdatedListener(l); + } + public void removeSurfaceUpdatedListener(SurfaceUpdatedListener l) { + window.removeSurfaceUpdatedListener(l); + } + public SurfaceUpdatedListener[] getSurfaceUpdatedListener() { + return window.getSurfaceUpdatedListener(); + } + public void surfaceUpdated(Object updater, NativeWindow window0, long when) { + window.surfaceUpdated(updater, window, when); + } + + public void addMouseListener(MouseListener l) { + window.addMouseListener(l); + } + + public void removeMouseListener(MouseListener l) { + window.removeMouseListener(l); + } + + public MouseListener[] getMouseListeners() { + return window.getMouseListeners(); + } + + public void addKeyListener(KeyListener l) { + window.addKeyListener(l); + } + + public void removeKeyListener(KeyListener l) { + window.removeKeyListener(l); + } + + public KeyListener[] getKeyListeners() { + return window.getKeyListeners(); + } + + public void addWindowListener(WindowListener l) { + window.addWindowListener(l); + } + + public void removeWindowListener(WindowListener l) { + window.removeWindowListener(l); + } + + public WindowListener[] getWindowListeners() { + return window.getWindowListeners(); + } + + public String toString() { + return "NEWT-GLWindow[ \n\tDrawable: "+drawable+", \n\tWindow: "+window+", \n\tHelper: "+helper+", \n\tFactory: "+factory+"]"; + } + + //---------------------------------------------------------------------- + // OpenGL-related methods and state + // + + private GLDrawableFactory factory; + private GLDrawable drawable; + private GLContext context; + private GLDrawableHelper helper = new GLDrawableHelper(); + // To make reshape events be sent immediately before a display event + private boolean sendReshape=false; + private boolean sendDestroy=false; + private boolean perfLog = false; + + public GLDrawableFactory getFactory() { + return factory; + } + + public void setContext(GLContext newCtx) { + context = newCtx; + } + + public GLContext getContext() { + return context; + } + + public GL getGL() { + if (context == null) { + return null; + } + return context.getGL(); + } + + public GL setGL(GL gl) { + if (context != null) { + context.setGL(gl); + return gl; + } + return null; + } + + public void addGLEventListener(GLEventListener listener) { + helper.addGLEventListener(listener); + } + + public void removeGLEventListener(GLEventListener listener) { + helper.removeGLEventListener(listener); + } + + public void display() { + display(false); + } + + public void display(boolean forceReshape) { + if(window!=null && drawable!=null && context != null) { + if(runPumpMessages) { + window.getScreen().getDisplay().pumpMessages(); + } + if(window.hasDeviceChanged() && GLAutoDrawable.SCREEN_CHANGE_ACTION_ENABLED) { + dispose(true, true); + } + if (sendDestroy) { + destroy(); + sendDestroy=false; + } else { + if(forceReshape) { + sendReshape = true; + } + helper.invokeGL(drawable, context, displayAction, initAction); + } + } + } + + private void sendDisposeEvent() { + if(drawable!=null && context != null) { + helper.invokeGL(drawable, context, disposeAction, null); + } + } + + /** This implementation uses a static value */ + public void setAutoSwapBufferMode(boolean onOrOff) { + helper.setAutoSwapBufferMode(onOrOff); + } + + /** This implementation uses a static value */ + public boolean getAutoSwapBufferMode() { + return helper.getAutoSwapBufferMode(); + } + + public void swapBuffers() { + if(drawable!=null && context != null) { + if (context != GLContext.getCurrent()) { + // Assume we should try to make the context current before swapping the buffers + helper.invokeGL(drawable, context, swapBuffersAction, initAction); + } else { + drawable.swapBuffers(); + } + } + } + + class InitAction implements Runnable { + public void run() { + helper.init(GLWindow.this); + startTime = System.currentTimeMillis(); + curTime = startTime; + if(perfLog) { + lastCheck = startTime; + totalFrames = 0; lastFrames = 0; + } + } + } + private InitAction initAction = new InitAction(); + + class DisposeAction implements Runnable { + public void run() { + helper.dispose(GLWindow.this); + } + } + private DisposeAction disposeAction = new DisposeAction(); + + class DisplayAction implements Runnable { + public void run() { + if (sendReshape) { + int width = getWidth(); + int height = getHeight(); + getGL().glViewport(0, 0, width, height); + helper.reshape(GLWindow.this, 0, 0, width, height); + sendReshape = false; + } + + helper.display(GLWindow.this); + + curTime = System.currentTimeMillis(); + totalFrames++; + + if(perfLog) { + long dt0, dt1; + lastFrames++; + dt0 = curTime-lastCheck; + if ( dt0 > 5000 ) { + dt1 = curTime-startTime; + System.out.println(dt0/1000 +"s: "+ lastFrames + "f, " + (lastFrames*1000)/dt0 + " fps, "+dt0/lastFrames+" ms/f; "+ + "total: "+ dt1/1000+"s, "+(totalFrames*1000)/dt1 + " fps, "+dt1/totalFrames+" ms/f"); + lastCheck=curTime; + lastFrames=0; + } + } + } + } + private DisplayAction displayAction = new DisplayAction(); + + public long getStartTime() { return startTime; } + public long getCurrentTime() { return curTime; } + public long getDuration() { return curTime-startTime; } + public int getTotalFrames() { return totalFrames; } + + private long startTime = 0; + private long curTime = 0; + private long lastCheck = 0; + private int totalFrames = 0, lastFrames = 0; + + class SwapBuffersAction implements Runnable { + public void run() { + drawable.swapBuffers(); + } + } + private SwapBuffersAction swapBuffersAction = new SwapBuffersAction(); + + //---------------------------------------------------------------------- + // GLDrawable methods + // + + public NativeWindow getNativeWindow() { + return null!=drawable ? drawable.getNativeWindow() : null; + } + + public synchronized int lockSurface() throws NativeWindowException { + if(null!=drawable) return drawable.getNativeWindow().lockSurface(); + return NativeWindow.LOCK_SURFACE_NOT_READY; + } + + public synchronized void unlockSurface() { + if(null!=drawable) drawable.getNativeWindow().unlockSurface(); + else throw new NativeWindowException("NEWT-GLWindow not locked"); + } + + public synchronized boolean isSurfaceLocked() { + if(null!=drawable) return drawable.getNativeWindow().isSurfaceLocked(); + return false; + } + + public synchronized Exception getLockedStack() { + if(null!=drawable) return drawable.getNativeWindow().getLockedStack(); + return null; + } + + public boolean surfaceSwap() { + if(null!=drawable) return drawable.getNativeWindow().surfaceSwap(); + return super.surfaceSwap(); + } + + public long getWindowHandle() { + if(null!=drawable) return drawable.getNativeWindow().getWindowHandle(); + return super.getWindowHandle(); + } + + public long getSurfaceHandle() { + if(null!=drawable) return drawable.getNativeWindow().getSurfaceHandle(); + return super.getSurfaceHandle(); + } + + //---------------------------------------------------------------------- + // GLDrawable methods that are not really needed + // + + public GLContext createContext(GLContext shareWith) { + return drawable.createContext(shareWith); + } + + public void setRealized(boolean realized) { + } + + public GLCapabilities getChosenGLCapabilities() { + if (drawable == null) { + throw new GLException("No drawable yet"); + } + + return drawable.getChosenGLCapabilities(); + } + + public GLProfile getGLProfile() { + if (drawable == null) { + throw new GLException("No drawable yet"); + } + + return drawable.getGLProfile(); + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private void shouldNotCallThis() { + throw new NativeWindowException("Should not call this"); + } +} diff --git a/src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Display.java b/src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Display.java new file mode 100644 index 000000000..c0c1ee5fd --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Display.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.opengl.broadcom.egl; + +import com.jogamp.javafx.newt.impl.*; +import com.jogamp.opengl.impl.egl.*; +import javax.media.nativewindow.*; +import javax.media.nativewindow.egl.*; + +public class Display extends com.jogamp.javafx.newt.Display { + + static { + NativeLibLoader.loadNEWT(); + + if (!Window.initIDs()) { + throw new NativeWindowException("Failed to initialize BCEGL Window jmethodIDs"); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + + public Display() { + } + + protected void createNative() { + long handle = CreateDisplay(Screen.fixedWidth, Screen.fixedHeight); + if (handle == EGL.EGL_NO_DISPLAY) { + throw new NativeWindowException("BC EGL CreateDisplay failed"); + } + aDevice = new EGLGraphicsDevice(handle); + } + + protected void closeNative() { + if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) { + DestroyDisplay(aDevice.getHandle()); + } + } + + protected void dispatchMessages() { + // n/a .. DispatchMessages(); + } + + private native long CreateDisplay(int width, int height); + private native void DestroyDisplay(long dpy); + private native void DispatchMessages(); +} + diff --git a/src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Screen.java b/src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Screen.java new file mode 100755 index 000000000..f7abe3836 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Screen.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.opengl.broadcom.egl; + +import com.jogamp.javafx.newt.impl.*; +import javax.media.nativewindow.*; + +public class Screen extends com.jogamp.javafx.newt.Screen { + + static { + Display.initSingleton(); + } + + + public Screen() { + } + + protected void createNative(int index) { + aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); + setScreenSize(fixedWidth, fixedHeight); + } + + protected void closeNative() { } + + //---------------------------------------------------------------------- + // Internals only + // + + static final int fixedWidth = 1920; + static final int fixedHeight = 1080; +} + diff --git a/src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Window.java b/src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Window.java new file mode 100755 index 000000000..bd2d7930e --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Window.java @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.opengl.broadcom.egl; + +import com.jogamp.javafx.newt.impl.*; +import com.jogamp.opengl.impl.egl.*; +import javax.media.nativewindow.*; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; +import javax.media.nativewindow.NativeWindowException; + +public class Window extends com.jogamp.javafx.newt.Window { + static { + Display.initSingleton(); + } + + public Window() { + } + + protected void createNative(long parentWindowHandle, Capabilities caps) { + if(0!=parentWindowHandle) { + throw new RuntimeException("Window parenting not supported (yet)"); + } + // query a good configuration .. even thought we drop this one + // and reuse the EGLUtil choosen one later. + config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + setSizeImpl(getScreen().getWidth(), getScreen().getHeight()); + } + + protected void closeNative() { + if(0!=windowHandleClose) { + CloseWindow(getDisplayHandle(), windowHandleClose); + } + } + + public void setVisible(boolean visible) { + if(this.visible!=visible) { + this.visible=visible; + if ( 0==windowHandle ) { + windowHandle = realizeWindow(true, width, height); + if (0 == windowHandle) { + throw new NativeWindowException("Error native Window Handle is null"); + } + } + clearEventMask(); + } + } + + public void setSize(int width, int height) { + System.err.println("setSize "+width+"x"+height+" n/a in BroadcomEGL"); + } + + void setSizeImpl(int width, int height) { + if(0!=windowHandle) { + // n/a in BroadcomEGL + System.err.println("BCEGL Window.setSizeImpl n/a in BroadcomEGL with realized window"); + } else { + if(DEBUG_IMPLEMENTATION) { + Exception e = new Exception("BCEGL Window.setSizeImpl() "+this.width+"x"+this.height+" -> "+width+"x"+height); + e.printStackTrace(); + } + this.width = width; + this.height = height; + } + } + + public void setPosition(int x, int y) { + // n/a in BroadcomEGL + System.err.println("setPosition n/a in BroadcomEGL"); + } + + public boolean setFullscreen(boolean fullscreen) { + // n/a in BroadcomEGL + System.err.println("setFullscreen n/a in BroadcomEGL"); + return false; + } + + public boolean surfaceSwap() { + if ( 0!=windowHandle ) { + SwapWindow(getDisplayHandle(), windowHandle); + return true; + } + return false; + } + + //---------------------------------------------------------------------- + // Internals only + // + + protected static native boolean initIDs(); + private native long CreateWindow(long eglDisplayHandle, boolean chromaKey, int width, int height); + private native void CloseWindow(long eglDisplayHandle, long eglWindowHandle); + private native void SwapWindow(long eglDisplayHandle, long eglWindowHandle); + + + private long realizeWindow(boolean chromaKey, int width, int height) { + if(DEBUG_IMPLEMENTATION) { + System.out.println("BCEGL Window.realizeWindow() with: chroma "+chromaKey+", "+width+"x"+height+", "+config); + } + long handle = CreateWindow(getDisplayHandle(), chromaKey, width, height); + if (0 == handle) { + throw new NativeWindowException("Error native Window Handle is null"); + } + windowHandleClose = handle; + return handle; + } + + private void windowCreated(int cfgID, int width, int height) { + this.width = width; + this.height = height; + GLCapabilities capsReq = (GLCapabilities) config.getRequestedCapabilities(); + config = EGLGraphicsConfiguration.create(capsReq, screen.getGraphicsScreen(), cfgID); + if (config == null) { + throw new NativeWindowException("Error creating EGLGraphicsConfiguration from id: "+cfgID+", "+this); + } + if(DEBUG_IMPLEMENTATION) { + System.out.println("BCEGL Window.windowCreated(): "+toHexString(cfgID)+", "+width+"x"+height+", "+config); + } + } + + private long windowHandleClose; +} diff --git a/src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDDisplay.java b/src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDDisplay.java new file mode 100755 index 000000000..40a37115d --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDDisplay.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.opengl.kd; + +import com.jogamp.javafx.newt.*; +import com.jogamp.javafx.newt.impl.*; +import com.jogamp.opengl.impl.egl.*; +import javax.media.nativewindow.*; +import javax.media.nativewindow.egl.*; + +public class KDDisplay extends Display { + + static { + NativeLibLoader.loadNEWT(); + + if (!KDWindow.initIDs()) { + throw new NativeWindowException("Failed to initialize KDWindow jmethodIDs"); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + + public KDDisplay() { + } + + protected void createNative() { + // FIXME: map name to EGL_*_DISPLAY + long handle = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY); + if (handle == EGL.EGL_NO_DISPLAY) { + throw new NativeWindowException("eglGetDisplay failed"); + } + if (!EGL.eglInitialize(handle, null, null)) { + throw new NativeWindowException("eglInitialize failed"); + } + aDevice = new EGLGraphicsDevice(handle); + } + + protected void closeNative() { + if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) { + EGL.eglTerminate(aDevice.getHandle()); + } + } + + protected void dispatchMessages() { + DispatchMessages(); + } + + private native void DispatchMessages(); +} + diff --git a/src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDScreen.java b/src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDScreen.java new file mode 100755 index 000000000..4bc7f8257 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDScreen.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.opengl.kd; + +import com.jogamp.javafx.newt.*; +import javax.media.nativewindow.*; + +public class KDScreen extends Screen { + static { + KDDisplay.initSingleton(); + } + + public KDScreen() { + } + + protected void createNative(int index) { + aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); + } + + protected void closeNative() { } + + // elevate access to this package .. + protected void setScreenSize(int w, int h) { + super.setScreenSize(w, h); + } +} diff --git a/src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDWindow.java b/src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDWindow.java new file mode 100755 index 000000000..d5be2207c --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDWindow.java @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.opengl.kd; + +import com.jogamp.javafx.newt.*; +import com.jogamp.javafx.newt.impl.*; +import com.jogamp.opengl.impl.egl.*; +import javax.media.nativewindow.*; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; +import javax.media.nativewindow.NativeWindowException; + +public class KDWindow extends Window { + private static final String WINDOW_CLASS_NAME = "NewtWindow"; + // non fullscreen dimensions .. + private int nfs_width, nfs_height, nfs_x, nfs_y; + + static { + KDDisplay.initSingleton(); + } + + public KDWindow() { + } + + protected void createNative(long parentWindowHandle, Capabilities caps) { + if(0!=parentWindowHandle) { + throw new RuntimeException("Window parenting not supported (yet)"); + } + config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + + GLCapabilities eglCaps = (GLCapabilities)config.getChosenCapabilities(); + int[] eglAttribs = EGLGraphicsConfiguration.GLCapabilities2AttribList(eglCaps); + + windowHandle = 0; + eglWindowHandle = CreateWindow(getDisplayHandle(), eglAttribs); + if (eglWindowHandle == 0) { + throw new NativeWindowException("Error creating egl window: "+config); + } + setVisible0(eglWindowHandle, false); + windowHandleClose = eglWindowHandle; + } + + protected void closeNative() { + if(0!=windowHandleClose) { + CloseWindow(windowHandleClose, windowUserData); + windowUserData=0; + } + } + + public void setVisible(boolean visible) { + if(0!=eglWindowHandle && this.visible!=visible) { + this.visible=visible; + setVisible0(eglWindowHandle, visible); + if ( 0==windowHandle ) { + windowHandle = RealizeWindow(eglWindowHandle); + if (0 == windowHandle) { + throw new NativeWindowException("Error native Window Handle is null"); + } + } + clearEventMask(); + } + } + + public void setSize(int width, int height) { + if(0!=eglWindowHandle) { + setSize0(eglWindowHandle, width, height); + } + } + + public void setPosition(int x, int y) { + // n/a in KD + System.err.println("setPosition n/a in KD"); + } + + public boolean setFullscreen(boolean fullscreen) { + if(0!=eglWindowHandle && this.fullscreen!=fullscreen) { + this.fullscreen=fullscreen; + if(this.fullscreen) { + setFullScreen0(eglWindowHandle, true); + } else { + setFullScreen0(eglWindowHandle, false); + setSize0(eglWindowHandle, nfs_width, nfs_height); + } + } + return true; + } + + //---------------------------------------------------------------------- + // Internals only + // + + protected static native boolean initIDs(); + private native long CreateWindow(long displayHandle, int[] attributes); + private native long RealizeWindow(long eglWindowHandle); + private native int CloseWindow(long eglWindowHandle, long userData); + private native void setVisible0(long eglWindowHandle, boolean visible); + private native void setSize0(long eglWindowHandle, int width, int height); + private native void setFullScreen0(long eglWindowHandle, boolean fullscreen); + + private void windowCreated(long userData) { + windowUserData=userData; + } + + private void sizeChanged(int newWidth, int newHeight) { + width = newWidth; + height = newHeight; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } else { + ((KDScreen)screen).setScreenSize(width, height); + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + } + + private long eglWindowHandle; + private long windowHandleClose; + private long windowUserData; +} diff --git a/src/newt/classes/com/jogamp/javafx/newt/util/EventDispatchThread.java b/src/newt/classes/com/jogamp/javafx/newt/util/EventDispatchThread.java new file mode 100644 index 000000000..db3f97ee6 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/util/EventDispatchThread.java @@ -0,0 +1,240 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. 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 com.jogamp.javafx.newt.util; + +import com.jogamp.javafx.newt.Display; +import com.jogamp.javafx.newt.impl.Debug; +import java.util.*; + +public class EventDispatchThread { + public static final boolean DEBUG = Debug.debug("EDT"); + + private ThreadGroup threadGroup; + private volatile boolean shouldStop = false; + private TaskWorker taskWorker = null; + private Object taskWorkerLock = new Object(); + private ArrayList tasks = new ArrayList(); // one shot tasks + private Display display = null; + private String name; + private long edtPollGranularity = 10; + + public EventDispatchThread(Display display, ThreadGroup tg, String name) { + this.display = display; + this.threadGroup = tg; + this.name=new String("EDT-Display_"+display.getName()+"-"+name); + } + + public String getName() { return name; } + + public ThreadGroup getThreadGroup() { return threadGroup; } + + public void start() { + start(false); + } + + /** + * @param externalStimuli true indicates that another thread stimulates, + * ie. calls this TaskManager's run() loop method. + * Hence no own thread is started in this case. + * + * @return The started Runnable, which handles the run-loop. + * Usefull in combination with externalStimuli=true, + * so an external stimuli can call it. + */ + public Runnable start(boolean externalStimuli) { + synchronized(taskWorkerLock) { + if(null==taskWorker) { + taskWorker = new TaskWorker(threadGroup, name); + } + if(!taskWorker.isRunning()) { + shouldStop = false; + taskWorker.start(externalStimuli); + } + taskWorkerLock.notifyAll(); + } + return taskWorker; + } + + public void stop() { + synchronized(taskWorkerLock) { + if(null!=taskWorker && taskWorker.isRunning()) { + shouldStop = true; + } + taskWorkerLock.notifyAll(); + if(DEBUG) { + System.out.println(Thread.currentThread()+": EDT signal STOP"); + } + } + } + + public boolean isThreadEDT(Thread thread) { + return null!=taskWorker && taskWorker == thread; + } + + public boolean isCurrentThreadEDT() { + return null!=taskWorker && taskWorker == Thread.currentThread(); + } + + public boolean isRunning() { + return null!=taskWorker && taskWorker.isRunning() ; + } + + public void invokeLater(Runnable task) { + if(task == null) { + return; + } + synchronized(taskWorkerLock) { + if(null!=taskWorker && taskWorker.isRunning() && taskWorker != Thread.currentThread() ) { + tasks.add(task); + taskWorkerLock.notifyAll(); + } else { + // if !running or isEDTThread, do it right away + task.run(); + } + } + } + + public void invokeAndWait(Runnable task) { + if(task == null) { + return; + } + invokeLater(task); + waitOnWorker(); + } + + public void waitOnWorker() { + synchronized(taskWorkerLock) { + if(null!=taskWorker && taskWorker.isRunning() && tasks.size()>0 && taskWorker != Thread.currentThread() ) { + try { + taskWorkerLock.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + + public void waitUntilStopped() { + synchronized(taskWorkerLock) { + while(null!=taskWorker && taskWorker.isRunning() && taskWorker != Thread.currentThread() ) { + try { + taskWorkerLock.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + + class TaskWorker extends Thread { + boolean isRunning = false; + boolean externalStimuli = false; + + public TaskWorker(ThreadGroup tg, String name) { + super(tg, name); + } + + public synchronized boolean isRunning() { + return isRunning; + } + + public void start(boolean externalStimuli) throws IllegalThreadStateException { + synchronized(this) { + this.externalStimuli = externalStimuli; + isRunning = true; + } + if(!externalStimuli) { + super.start(); + } + } + + /** + * Utilizing taskWorkerLock only for local resources and task execution, + * not for event dispatching. + */ + public void run() { + if(DEBUG) { + System.out.println(Thread.currentThread()+": EDT run() START"); + } + while(!shouldStop) { + try { + // wait for something todo + while(!shouldStop && tasks.size()==0) { + synchronized(taskWorkerLock) { + if(!shouldStop && tasks.size()==0) { + try { + taskWorkerLock.wait(edtPollGranularity); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + display.pumpMessages(); // event dispatch + } + if(!shouldStop && tasks.size()>0) { + synchronized(taskWorkerLock) { + if(!shouldStop && tasks.size()>0) { + Runnable task = (Runnable) tasks.remove(0); + task.run(); + taskWorkerLock.notifyAll(); + } + } + display.pumpMessages(); // event dispatch + } + } catch (Throwable t) { + // handle errors .. + t.printStackTrace(); + } finally { + // epilog - unlock locked stuff + } + if(externalStimuli) break; // no loop if called by external stimuli + } + synchronized(this) { + isRunning = !shouldStop; + } + if(!isRunning) { + synchronized(taskWorkerLock) { + taskWorkerLock.notifyAll(); + } + } + if(DEBUG) { + System.out.println(Thread.currentThread()+": EDT run() EXIT"); + } + } + } +} + diff --git a/src/newt/classes/com/jogamp/javafx/newt/util/MainThread.java b/src/newt/classes/com/jogamp/javafx/newt/util/MainThread.java new file mode 100644 index 000000000..9bf25098f --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/util/MainThread.java @@ -0,0 +1,307 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. 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 com.jogamp.javafx.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.javafx.newt.*; +import com.jogamp.javafx.newt.impl.*; +import com.jogamp.javafx.newt.macosx.MacDisplay; +import com.jogamp.nativewindow.impl.NWReflection; + +/** + * NEWT Utility class MainThread

+ * + * This class provides a startup singleton main thread, + * from which a new thread with the users main class is launched.
+ * + * Such behavior is necessary for native windowing toolkits, + * where the windowing management must happen on the so called + * main thread e.g. for Mac OS X !
+ * + * Utilizing this class as a launchpad, now you are able to + * use a NEWT multithreaded application with window handling within the different threads, + * even on these restricted platforms.
+ * + * To support your NEWT Window platform, + * you have to pass your main thread actions to {@link #invoke invoke(..)}, + * have a look at the {@link com.jogamp.javafx.newt.macosx.MacWindow MacWindow} implementation.
+ * TODO: Some hardcoded dependencies exist in this implementation, + * where you have to patch this code or factor it out.

+ * + * If your platform is not Mac OS X, but you want to test your code without modifying + * this class, you have to set the system property newt.MainThread.force to true.

+ * + * The code is compatible with all other platform, which support multithreaded windowing handling. + * Since those platforms won't trigger the main thread serialization, the main method + * will be simply executed, in case you haven't set newt.MainThread.force to true.

+ * + * Test case on Mac OS X (or any other platform): +

+    java -XstartOnFirstThread com.jogamp.javafx.newt.util.MainThread demos.es1.RedSquare -GL2 -GL2 -GL2 -GL2
+ 
+ * Which starts 4 threads, each with a window and OpenGL rendering.
+ */ +public class MainThread { + private static AccessControlContext localACC = AccessController.getContext(); + public static final boolean USE_MAIN_THREAD = NativeWindowFactory.TYPE_MACOSX.equals(NativeWindowFactory.getNativeWindowType(false)) || + Debug.getBooleanProperty("newt.MainThread.force", true, localACC); + + protected static final boolean DEBUG = Debug.debug("MainThread"); + + private static boolean isExit=false; + private static volatile boolean isRunning=false; + private static Object taskWorkerLock=new Object(); + private static boolean shouldStop; + private static ArrayList tasks; + private static ArrayList tasksBlock; + private static Thread mainThread; + + static class MainAction extends Thread { + private String mainClassName; + private String[] mainClassArgs; + + private Class mainClass; + private Method mainClassMain; + + public MainAction(String mainClassName, String[] mainClassArgs) { + this.mainClassName=mainClassName; + this.mainClassArgs=mainClassArgs; + } + + public void run() { + if ( USE_MAIN_THREAD ) { + // we have to start first to provide the service .. + MainThread.waitUntilRunning(); + } + + // start user app .. + try { + Class mainClass = NWReflection.getClass(mainClassName, true); + if(null==mainClass) { + throw new RuntimeException(new ClassNotFoundException("MainThread couldn't find main class "+mainClassName)); + } + try { + mainClassMain = mainClass.getDeclaredMethod("main", new Class[] { String[].class }); + mainClassMain.setAccessible(true); + } catch (Throwable t) { + throw new RuntimeException(t); + } + if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" invoke "+mainClassName); + mainClassMain.invoke(null, new Object[] { mainClassArgs } ); + } catch (InvocationTargetException ite) { + ite.getTargetException().printStackTrace(); + } catch (Throwable t) { + t.printStackTrace(); + } + + if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" user app fin"); + + if ( USE_MAIN_THREAD ) { + MainThread.exit(); + if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" MainThread fin - exit"); + System.exit(0); + } + } + } + private static MainAction mainAction; + + /** Your new java application main entry, which pipelines your application */ + public static void main(String[] args) { + if(DEBUG) System.err.println("MainThread.main(): "+Thread.currentThread().getName()+" USE_MAIN_THREAD "+ USE_MAIN_THREAD ); + + if(args.length==0) { + return; + } + + String mainClassName=args[0]; + String[] mainClassArgs=new String[args.length-1]; + if(args.length>1) { + System.arraycopy(args, 1, mainClassArgs, 0, args.length-1); + } + + NativeLibLoader.loadNEWT(); + + shouldStop = false; + tasks = new ArrayList(); + tasksBlock = new ArrayList(); + mainThread = Thread.currentThread(); + + mainAction = new MainAction(mainClassName, mainClassArgs); + + if(NativeWindowFactory.TYPE_MACOSX.equals(NativeWindowFactory.getNativeWindowType(false))) { + MacDisplay.initSingleton(); + } + + if ( USE_MAIN_THREAD ) { + // dispatch user's main thread .. + mainAction.start(); + + // do our main thread task scheduling + run(); + } else { + // run user's main in this thread + mainAction.run(); + } + } + + /** invokes the given Runnable */ + public static void invoke(boolean wait, Runnable r) { + if(r == null) { + return; + } + + // if this main thread is not being used or + // if this is already the main thread .. just execute. + if( !isRunning() || mainThread == Thread.currentThread() ) { + r.run(); + return; + } + + synchronized(taskWorkerLock) { + tasks.add(r); + if(wait) { + tasksBlock.add(r); + } + taskWorkerLock.notifyAll(); + if(wait) { + while(tasksBlock.size()>0) { + try { + taskWorkerLock.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + } + + public static void exit() { + if(DEBUG) System.err.println("MainThread.exit(): "+Thread.currentThread().getName()+" start"); + synchronized(taskWorkerLock) { + if(isRunning) { + shouldStop = true; + } + taskWorkerLock.notifyAll(); + } + if(DEBUG) System.err.println("MainThread.exit(): "+Thread.currentThread().getName()+" end"); + } + + public static boolean isRunning() { + synchronized(taskWorkerLock) { + return isRunning; + } + } + + private static void waitUntilRunning() { + synchronized(taskWorkerLock) { + if(isExit) return; + + while(!isRunning) { + try { + taskWorkerLock.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + + public static void run() { + if(DEBUG) System.err.println("MainThread.run(): "+Thread.currentThread().getName()); + synchronized(taskWorkerLock) { + isRunning = true; + taskWorkerLock.notifyAll(); + } + while(!shouldStop) { + try { + ArrayList localTasks=null; + + // wait for something todo .. + synchronized(taskWorkerLock) { + while(!shouldStop && tasks.size()==0) { + try { + taskWorkerLock.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + // seq. process all tasks until no blocking one exists in the list + for(Iterator i = tasks.iterator(); tasksBlock.size()>0 && i.hasNext(); ) { + Runnable task = (Runnable) i.next(); + task.run(); + i.remove(); + tasksBlock.remove(task); + } + + // take over the tasks .. + if(tasks.size()>0) { + localTasks = tasks; + tasks = new ArrayList(); + } + taskWorkerLock.notifyAll(); + } + + // seq. process all unblocking tasks .. + if(null!=localTasks) { + for(Iterator i = localTasks.iterator(); i.hasNext(); ) { + Runnable task = (Runnable) i.next(); + task.run(); + } + } + } catch (Throwable t) { + // handle errors .. + t.printStackTrace(); + } finally { + // epilog - unlock locked stuff + } + } + if(DEBUG) System.err.println("MainThread.run(): "+Thread.currentThread().getName()+" fin"); + synchronized(taskWorkerLock) { + isRunning = false; + isExit = true; + taskWorkerLock.notifyAll(); + } + } +} + + diff --git a/src/newt/classes/com/jogamp/javafx/newt/windows/WindowsDisplay.java b/src/newt/classes/com/jogamp/javafx/newt/windows/WindowsDisplay.java new file mode 100755 index 000000000..f2e8d21ef --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/windows/WindowsDisplay.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.windows; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.windows.*; +import com.jogamp.javafx.newt.*; +import com.jogamp.javafx.newt.impl.*; + +public class WindowsDisplay extends Display { + + protected static final String WINDOW_CLASS_NAME = "NewtWindowClass"; + private static int windowClassAtom; + private static long hInstance; + + static { + NativeLibLoader.loadNEWT(); + + if (!WindowsWindow.initIDs()) { + throw new NativeWindowException("Failed to initialize WindowsWindow jmethodIDs"); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + + public WindowsDisplay() { + } + + protected void createNative() { + aDevice = new WindowsGraphicsDevice(); + } + + protected void closeNative() { + // Can't do .. only at application shutdown + // UnregisterWindowClass(getWindowClassAtom(), getHInstance()); + } + + protected void dispatchMessages() { + DispatchMessages(); + } + + protected static synchronized int getWindowClassAtom() { + if(0 == windowClassAtom) { + windowClassAtom = RegisterWindowClass(WINDOW_CLASS_NAME, getHInstance()); + if (0 == windowClassAtom) { + throw new NativeWindowException("Error while registering window class"); + } + } + return windowClassAtom; + } + + protected static synchronized long getHInstance() { + if(0 == hInstance) { + hInstance = LoadLibraryW("newt"); + if (0 == hInstance) { + throw new NativeWindowException("Error finding HINSTANCE for \"newt\""); + } + } + return hInstance; + } + + //---------------------------------------------------------------------- + // Internals only + // + private static native long LoadLibraryW(String libraryName); + private static native int RegisterWindowClass(String windowClassName, long hInstance); + private static native void UnregisterWindowClass(int wndClassAtom, long hInstance); + + private static native void DispatchMessages(); +} + diff --git a/src/newt/classes/com/jogamp/javafx/newt/windows/WindowsScreen.java b/src/newt/classes/com/jogamp/javafx/newt/windows/WindowsScreen.java new file mode 100755 index 000000000..ab11f97dd --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/windows/WindowsScreen.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.windows; + +import com.jogamp.javafx.newt.*; +import com.jogamp.javafx.newt.impl.*; +import javax.media.nativewindow.*; + +public class WindowsScreen extends Screen { + static { + WindowsDisplay.initSingleton(); + } + + + public WindowsScreen() { + } + + protected void createNative(int index) { + aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); + setScreenSize(getWidthImpl(getIndex()), getHeightImpl(getIndex())); + } + + protected void closeNative() { } + + private native int getWidthImpl(int scrn_idx); + private native int getHeightImpl(int scrn_idx); +} diff --git a/src/newt/classes/com/jogamp/javafx/newt/windows/WindowsWindow.java b/src/newt/classes/com/jogamp/javafx/newt/windows/WindowsWindow.java new file mode 100755 index 000000000..7c8864190 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/windows/WindowsWindow.java @@ -0,0 +1,289 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.windows; + +import javax.media.nativewindow.*; +import com.jogamp.javafx.newt.*; + +public class WindowsWindow extends Window { + + private long hmon; + private long hdc; + private long windowHandleClose; + private long parentWindowHandle; + // non fullscreen dimensions .. + private int nfs_width, nfs_height, nfs_x, nfs_y; + private final Insets insets = new Insets(0, 0, 0, 0); + + static { + WindowsDisplay.initSingleton(); + } + + public WindowsWindow() { + } + + Thread hdcOwner = null; + + public synchronized int lockSurface() throws NativeWindowException { + int res = super.lockSurface(); + if(LOCK_SUCCESS==res && 0!=windowHandle) { + if(hdc!=0) { + throw new NativeWindowException("NEWT Surface handle set HDC "+toHexString(hdc)+" - "+Thread.currentThread().getName()+" ; "+this); + } + hdc = GetDC(windowHandle); + hmon = MonitorFromWindow(windowHandle); + hdcOwner = Thread.currentThread(); + } + return res; + } + + public synchronized void unlockSurface() { + // prevalidate, before we change data .. + Thread cur = Thread.currentThread(); + if ( getSurfaceLockOwner() != cur ) { + getLockedStack().printStackTrace(); + throw new NativeWindowException(cur+": Not owner, owner is "+getSurfaceLockOwner()); + } + if (0!=hdc && 0!=windowHandle) { + if(hdcOwner != cur) { + throw new NativeWindowException("NEWT Surface handle set HDC "+toHexString(hdc)+" by other thread "+hdcOwner+", this "+cur+" ; "+this); + } + ReleaseDC(windowHandle, hdc); + hdc=0; + hdcOwner=null; + } + super.unlockSurface(); + } + + public long getSurfaceHandle() { + return hdc; + } + + public boolean hasDeviceChanged() { + if(0!=windowHandle) { + long _hmon = MonitorFromWindow(windowHandle); + if (hmon != _hmon) { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + Exception e = new Exception("!!! Window Device Changed "+Thread.currentThread().getName()+ + ", HMON "+toHexString(hmon)+" -> "+toHexString(_hmon)); + e.printStackTrace(); + } + hmon = _hmon; + return true; + } + } + return false; + } + + protected void createNative(long parentWindowHandle, Capabilities caps) { + WindowsScreen screen = (WindowsScreen) getScreen(); + WindowsDisplay display = (WindowsDisplay) screen.getDisplay(); + config = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, screen.getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + windowHandle = CreateWindow(parentWindowHandle, + display.getWindowClassAtom(), display.WINDOW_CLASS_NAME, display.getHInstance(), + 0, undecorated, x, y, width, height); + if (windowHandle == 0) { + throw new NativeWindowException("Error creating window"); + } + this.parentWindowHandle = parentWindowHandle; + windowHandleClose = windowHandle; + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + Exception e = new Exception("!!! Window new window handle "+Thread.currentThread().getName()+ + " (Parent HWND "+toHexString(parentWindowHandle)+ + ") : HWND "+toHexString(windowHandle)+", "+Thread.currentThread()); + e.printStackTrace(); + } + } + + protected void closeNative() { + if (hdc != 0) { + if(windowHandleClose != 0) { + ReleaseDC(windowHandleClose, hdc); + } + hdc = 0; + } + if(windowHandleClose != 0) { + DestroyWindow(windowHandleClose); + windowHandleClose = 0; + } + } + + protected void windowDestroyed() { + windowHandleClose = 0; + super.windowDestroyed(); + } + + public void setVisible(boolean visible) { + if(this.visible!=visible && 0!=windowHandle) { + this.visible=visible; + setVisible0(windowHandle, visible); + } + } + + // @Override + public void setSize(int width, int height) { + if (0!=windowHandle && (width != this.width || this.height != height)) { + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + this.width = width; + this.height = height; + setSize0(parentWindowHandle, windowHandle, x, y, width, height); + } + } + + //@Override + public void setPosition(int x, int y) { + if (0!=windowHandle && (this.x != x || this.y != y)) { + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + this.x = x; + this.y = y; + setPosition(parentWindowHandle, windowHandle, x , y); + } + } + + public boolean setFullscreen(boolean fullscreen) { + if(0!=windowHandle && (this.fullscreen!=fullscreen)) { + int x,y,w,h; + this.fullscreen=fullscreen; + if(fullscreen) { + x = 0; y = 0; + w = screen.getWidth(); + h = screen.getHeight(); + } else { + x = nfs_x; + y = nfs_y; + w = nfs_width; + h = nfs_height; + } + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("WindowsWindow fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); + } + setFullscreen0(parentWindowHandle, windowHandle, x, y, w, h, undecorated, fullscreen); + } + return fullscreen; + } + + // @Override + public void requestFocus() { + super.requestFocus(); + if (windowHandle != 0L) { + requestFocus(windowHandle); + } + } + + // @Override + public void setTitle(String title) { + if (title == null) { + title = ""; + } + if (0!=windowHandle && !title.equals(getTitle())) { + super.setTitle(title); + setTitle(windowHandle, title); + } + } + + public Insets getInsets() { + return (Insets)insets.clone(); + } + + //---------------------------------------------------------------------- + // Internals only + // + protected static native boolean initIDs(); + private native long CreateWindow(long parentWindowHandle, + int wndClassAtom, String wndName, + long hInstance, long visualID, + boolean isUndecorated, + int x, int y, int width, int height); + private native void DestroyWindow(long windowHandle); + private native long GetDC(long windowHandle); + private native void ReleaseDC(long windowHandle, long hdc); + private native long MonitorFromWindow(long windowHandle); + private static native void setVisible0(long windowHandle, boolean visible); + private native void setSize0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height); + private native void setPosition(long parentWindowHandle, long windowHandle, int x, int y); + private native void setFullscreen0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height, boolean isUndecorated, boolean on); + private static native void setTitle(long windowHandle, String title); + private static native void requestFocus(long windowHandle); + + private void insetsChanged(int left, int top, int right, int bottom) { + if (left != -1 && top != -1 && right != -1 && bottom != -1) { + insets.left = left; + insets.top = top; + insets.right = right; + insets.bottom = bottom; + } + } + private void sizeChanged(int newWidth, int newHeight) { + width = newWidth; + height = newHeight; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + } + + private void positionChanged(int newX, int newY) { + x = newX; + y = newY; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); + } + + /** + * + * @param focusOwner if focusGained is true, focusOwner is the previous + * focus owner, if focusGained is false, focusOwner is the new focus owner + * @param focusGained + */ + private void focusChanged(long focusOwner, boolean focusGained) { + if (focusGained) { + sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); + } else { + sendWindowEvent(WindowEvent.EVENT_WINDOW_LOST_FOCUS); + } + } +} diff --git a/src/newt/classes/com/jogamp/javafx/newt/x11/X11Display.java b/src/newt/classes/com/jogamp/javafx/newt/x11/X11Display.java new file mode 100755 index 000000000..96d55c082 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/x11/X11Display.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.x11; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; +import com.jogamp.javafx.newt.*; +import com.jogamp.javafx.newt.impl.*; +import com.jogamp.nativewindow.impl.x11.X11Util; + +public class X11Display extends Display { + static { + NativeLibLoader.loadNEWT(); + + if (!initIDs()) { + throw new NativeWindowException("Failed to initialize X11Display jmethodIDs"); + } + + if (!X11Window.initIDs()) { + throw new NativeWindowException("Failed to initialize X11Window jmethodIDs"); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + + public X11Display() { + } + + protected void createNative() { + long handle= X11Util.getThreadLocalDisplay(name); + if (handle == 0 ) { + throw new RuntimeException("Error creating display: "+name); + } + try { + CompleteDisplay(handle); + } catch(RuntimeException e) { + X11Util.closeThreadLocalDisplay(name); + throw e; + } + aDevice = new X11GraphicsDevice(handle); + } + + protected void closeNative() { + if(0==X11Util.closeThreadLocalDisplay(name)) { + throw new NativeWindowException(this+" was not mapped"); + } + } + + protected void dispatchMessages() { + DispatchMessages(getHandle(), javaObjectAtom, windowDeleteAtom); + } + + protected void lockDisplay() { + super.lockDisplay(); + LockDisplay(getHandle()); + } + + protected void unlockDisplay() { + UnlockDisplay(getHandle()); + super.unlockDisplay(); + } + + protected long getJavaObjectAtom() { return javaObjectAtom; } + protected long getWindowDeleteAtom() { return windowDeleteAtom; } + + //---------------------------------------------------------------------- + // Internals only + // + private static native boolean initIDs(); + + private native void LockDisplay(long handle); + private native void UnlockDisplay(long handle); + + private native void CompleteDisplay(long handle); + + private native void DispatchMessages(long display, long javaObjectAtom, long windowDeleteAtom); + + private void displayCompleted(long javaObjectAtom, long windowDeleteAtom) { + this.javaObjectAtom=javaObjectAtom; + this.windowDeleteAtom=windowDeleteAtom; + } + + private long windowDeleteAtom; + private long javaObjectAtom; +} + diff --git a/src/newt/classes/com/jogamp/javafx/newt/x11/X11Screen.java b/src/newt/classes/com/jogamp/javafx/newt/x11/X11Screen.java new file mode 100755 index 000000000..d90b1868d --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/x11/X11Screen.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.x11; + +import com.jogamp.javafx.newt.*; +import com.jogamp.javafx.newt.impl.*; +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; + +public class X11Screen extends Screen { + + static { + X11Display.initSingleton(); + } + + + public X11Screen() { + } + + protected void createNative(int index) { + long handle = GetScreen(display.getHandle(), index); + if (handle == 0 ) { + throw new RuntimeException("Error creating screen: "+index); + } + aScreen = new X11GraphicsScreen((X11GraphicsDevice)getDisplay().getGraphicsDevice(), index); + setScreenSize(getWidth0(display.getHandle(), index), + getHeight0(display.getHandle(), index)); + } + + protected void closeNative() { } + + //---------------------------------------------------------------------- + // Internals only + // + + private native long GetScreen(long dpy, int scrn_idx); + private native int getWidth0(long display, int scrn_idx); + private native int getHeight0(long display, int scrn_idx); +} + diff --git a/src/newt/classes/com/jogamp/javafx/newt/x11/X11Window.java b/src/newt/classes/com/jogamp/javafx/newt/x11/X11Window.java new file mode 100755 index 000000000..8387160c9 --- /dev/null +++ b/src/newt/classes/com/jogamp/javafx/newt/x11/X11Window.java @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.javafx.newt.x11; + +import com.jogamp.javafx.newt.*; +import com.jogamp.javafx.newt.impl.*; +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; + +public class X11Window extends Window { + private static final String WINDOW_CLASS_NAME = "NewtWindow"; + // non fullscreen dimensions .. + private int nfs_width, nfs_height, nfs_x, nfs_y; + + static { + X11Display.initSingleton(); + } + + public X11Window() { + } + + protected void createNative(long parentWindowHandle, Capabilities caps) { + X11Screen screen = (X11Screen) getScreen(); + X11Display display = (X11Display) screen.getDisplay(); + config = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, screen.getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + X11GraphicsConfiguration x11config = (X11GraphicsConfiguration) config; + long visualID = x11config.getVisualID(); + long w = CreateWindow(parentWindowHandle, + display.getHandle(), screen.getIndex(), visualID, + display.getJavaObjectAtom(), display.getWindowDeleteAtom(), x, y, width, height); + if (w == 0 || w!=windowHandle) { + throw new NativeWindowException("Error creating window: "+w); + } + this.parentWindowHandle = parentWindowHandle; + windowHandleClose = windowHandle; + displayHandleClose = display.getHandle(); + } + + protected void closeNative() { + if(0!=displayHandleClose && 0!=windowHandleClose && null!=getScreen() ) { + X11Display display = (X11Display) getScreen().getDisplay(); + CloseWindow(displayHandleClose, windowHandleClose, display.getJavaObjectAtom()); + windowHandleClose = 0; + displayHandleClose = 0; + } + } + + protected void windowDestroyed() { + windowHandleClose = 0; + displayHandleClose = 0; + super.windowDestroyed(); + } + + public void setVisible(boolean visible) { + if(0!=windowHandle && this.visible!=visible) { + this.visible=visible; + setVisible0(getDisplayHandle(), windowHandle, visible); + clearEventMask(); + } + } + + public void requestFocus() { + super.requestFocus(); + } + + public void setSize(int width, int height) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("X11Window setSize: "+this.x+"/"+this.y+" "+this.width+"x"+this.height+" -> "+width+"x"+height); + // Exception e = new Exception("XXXXXXXXXX"); + // e.printStackTrace(); + } + this.width = width; + this.height = height; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + if(0!=windowHandle) { + setSize0(parentWindowHandle, getDisplayHandle(), getScreenIndex(), windowHandle, x, y, width, height, (undecorated||fullscreen)?-1:1, false); + } + } + + public void setPosition(int x, int y) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("X11Window setPosition: "+this.x+"/"+this.y+" -> "+x+"/"+y); + // Exception e = new Exception("XXXXXXXXXX"); + // e.printStackTrace(); + } + this.x = x; + this.y = y; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + if(0!=windowHandle) { + setPosition0(getDisplayHandle(), windowHandle, x, y); + } + } + + public boolean setFullscreen(boolean fullscreen) { + if(0!=windowHandle && this.fullscreen!=fullscreen) { + int x,y,w,h; + this.fullscreen=fullscreen; + if(fullscreen) { + x = 0; y = 0; + w = screen.getWidth(); + h = screen.getHeight(); + } else { + x = nfs_x; + y = nfs_y; + w = nfs_width; + h = nfs_height; + } + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("X11Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); + } + setSize0(parentWindowHandle, getDisplayHandle(), getScreenIndex(), windowHandle, x, y, w, h, (undecorated||fullscreen)?-1:1, false); + } + return fullscreen; + } + + //---------------------------------------------------------------------- + // Internals only + // + + protected static native boolean initIDs(); + private native long CreateWindow(long parentWindowHandle, long display, int screen_index, + long visualID, long javaObjectAtom, long windowDeleteAtom, int x, int y, int width, int height); + private native void CloseWindow(long display, long windowHandle, long javaObjectAtom); + private native void setVisible0(long display, long windowHandle, boolean visible); + private native void setSize0(long parentWindowHandle, long display, int screen_index, long windowHandle, + int x, int y, int width, int height, int decorationToggle, boolean setVisible); + private native void setPosition0(long display, long windowHandle, int x, int y); + + private void windowChanged(int newX, int newY, int newWidth, int newHeight) { + if(width != newWidth || height != newHeight) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("X11Window windowChanged size: "+this.width+"x"+this.height+" -> "+newWidth+"x"+newHeight); + } + width = newWidth; + height = newHeight; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + } + if( 0==parentWindowHandle && ( x != newX || y != newY ) ) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("X11Window windowChanged position: "+this.x+"/"+this.y+" -> "+newX+"x"+newY); + } + x = newX; + y = newY; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); + } + } + + private void windowCreated(long windowHandle) { + this.windowHandle = windowHandle; + } + + private long windowHandleClose; + private long displayHandleClose; + private long parentWindowHandle; +} diff --git a/src/newt/classes/com/sun/javafx/newt/Display.java b/src/newt/classes/com/sun/javafx/newt/Display.java deleted file mode 100755 index a4b7a4f51..000000000 --- a/src/newt/classes/com/sun/javafx/newt/Display.java +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt; - -import javax.media.nativewindow.*; -import com.sun.javafx.newt.impl.Debug; -import com.sun.javafx.newt.util.EventDispatchThread; -import java.util.*; - -public abstract class Display { - public static final boolean DEBUG = Debug.debug("Display"); - - private static Class getDisplayClass(String type) - throws ClassNotFoundException - { - Class displayClass = NewtFactory.getCustomClass(type, "Display"); - if(null==displayClass) { - if (NativeWindowFactory.TYPE_EGL.equals(type)) { - displayClass = Class.forName("com.sun.javafx.newt.opengl.kd.KDDisplay"); - } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) { - displayClass = Class.forName("com.sun.javafx.newt.windows.WindowsDisplay"); - } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { - displayClass = Class.forName("com.sun.javafx.newt.macosx.MacDisplay"); - } else if (NativeWindowFactory.TYPE_X11.equals(type)) { - displayClass = Class.forName("com.sun.javafx.newt.x11.X11Display"); - } else if (NativeWindowFactory.TYPE_AWT.equals(type)) { - displayClass = Class.forName("com.sun.javafx.newt.awt.AWTDisplay"); - } else { - throw new RuntimeException("Unknown display type \"" + type + "\""); - } - } - return displayClass; - } - - // Unique Display for each thread - private static ThreadLocal currentDisplayMap = new ThreadLocal(); - - /** Returns the thread local display map */ - public static Map getCurrentDisplayMap() { - Map displayMap = (Map) currentDisplayMap.get(); - if(null==displayMap) { - displayMap = new HashMap(); - currentDisplayMap.set( displayMap ); - } - return displayMap; - } - - /** maps the given display to the thread local display map - * and notifies all threads synchronized to this display map. */ - protected static Display setCurrentDisplay(Display display) { - Map displayMap = getCurrentDisplayMap(); - Display oldDisplay = null; - synchronized(displayMap) { - String name = display.getName(); - if(null==name) name="nil"; - oldDisplay = (Display) displayMap.put(name, display); - displayMap.notifyAll(); - } - return oldDisplay; - } - - /** removes the mapping of the given name from the thread local display map - * and notifies all threads synchronized to this display map. */ - protected static Display removeCurrentDisplay(String name) { - if(null==name) name="nil"; - Map displayMap = getCurrentDisplayMap(); - Display oldDisplay = null; - synchronized(displayMap) { - oldDisplay = (Display) displayMap.remove(name); - displayMap.notifyAll(); - } - return oldDisplay; - } - - /** Returns the thread local display mapped to the given name */ - public static Display getCurrentDisplay(String name) { - if(null==name) name="nil"; - Map displayMap = getCurrentDisplayMap(); - Display display = (Display) displayMap.get(name); - return display; - } - - public static void dumpDisplayMap(String prefix) { - Map displayMap = getCurrentDisplayMap(); - Set entrySet = displayMap.entrySet(); - Iterator i = entrySet.iterator(); - System.err.println(prefix+" DisplayMap["+entrySet.size()+"] "+Thread.currentThread()); - for(int j=0; i.hasNext(); j++) { - Map.Entry entry = (Map.Entry) i.next(); - System.err.println(" ["+j+"] "+entry.getKey()+" -> "+entry.getValue()); - } - } - - /** Returns the thread local display collection */ - public static Collection getCurrentDisplays() { - return getCurrentDisplayMap().values(); - } - - /** Make sure to reuse a Display with the same name */ - protected static Display create(String type, String name) { - try { - if(DEBUG) { - dumpDisplayMap("Display.create("+name+") BEGIN"); - } - Display display = getCurrentDisplay(name); - if(null==display) { - Class displayClass = getDisplayClass(type); - display = (Display) displayClass.newInstance(); - display.name=name; - display.refCount=1; - - if(NewtFactory.useEDT()) { - Thread current = Thread.currentThread(); - display.eventDispatchThread = new EventDispatchThread(display, current.getThreadGroup(), current.getName()); - display.eventDispatchThread.start(); - final Display f_dpy = display; - display.eventDispatchThread.invokeAndWait(new Runnable() { - public void run() { - f_dpy.createNative(); - } - } ); - } else { - display.createNative(); - } - if(null==display.aDevice) { - throw new RuntimeException("Display.createNative() failed to instanciate an AbstractGraphicsDevice"); - } - setCurrentDisplay(display); - if(DEBUG) { - System.err.println("Display.create("+name+") NEW: "+display+" "+Thread.currentThread()); - } - } else { - synchronized(display) { - display.refCount++; - if(DEBUG) { - System.err.println("Display.create("+name+") REUSE: refCount "+display.refCount+", "+display+" "+Thread.currentThread()); - } - } - } - if(DEBUG) { - dumpDisplayMap("Display.create("+name+") END"); - } - return display; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - protected static Display wrapHandle(String type, String name, AbstractGraphicsDevice aDevice) { - try { - Class displayClass = getDisplayClass(type); - Display display = (Display) displayClass.newInstance(); - display.name=name; - display.aDevice=aDevice; - return display; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public EventDispatchThread getEDT() { return eventDispatchThread; } - - public synchronized void destroy() { - if(DEBUG) { - dumpDisplayMap("Display.destroy("+name+") BEGIN"); - } - refCount--; - if(0==refCount) { - removeCurrentDisplay(name); - if(DEBUG) { - System.err.println("Display.destroy("+name+") REMOVE: "+this+" "+Thread.currentThread()); - } - if(null!=eventDispatchThread) { - final Display f_dpy = this; - final EventDispatchThread f_edt = eventDispatchThread; - eventDispatchThread.invokeAndWait(new Runnable() { - public void run() { - f_dpy.closeNative(); - f_edt.stop(); - } - } ); - } else { - closeNative(); - } - if(null!=eventDispatchThread) { - eventDispatchThread.waitUntilStopped(); - eventDispatchThread=null; - } - aDevice = null; - } else { - if(DEBUG) { - System.err.println("Display.destroy("+name+") KEEP: refCount "+refCount+", "+this+" "+Thread.currentThread()); - } - } - if(DEBUG) { - dumpDisplayMap("Display.destroy("+name+") END"); - } - } - - protected abstract void createNative(); - protected abstract void closeNative(); - - public String getName() { - return name; - } - - public long getHandle() { - if(null!=aDevice) { - return aDevice.getHandle(); - } - return 0; - } - - public AbstractGraphicsDevice getGraphicsDevice() { - return aDevice; - } - - public void pumpMessages() { - if(null!=eventDispatchThread) { - dispatchMessages(); - } else { - synchronized(this) { - dispatchMessages(); - } - } - } - - public String toString() { - return "NEWT-Display["+name+", refCount "+refCount+", "+aDevice+"]"; - } - - protected abstract void dispatchMessages(); - - /** Default impl. nop - Currently only X11 needs a Display lock */ - protected void lockDisplay() { } - - /** Default impl. nop - Currently only X11 needs a Display lock */ - protected void unlockDisplay() { } - - protected EventDispatchThread eventDispatchThread = null; - protected String name; - protected int refCount; - protected AbstractGraphicsDevice aDevice; -} - diff --git a/src/newt/classes/com/sun/javafx/newt/Event.java b/src/newt/classes/com/sun/javafx/newt/Event.java deleted file mode 100644 index 3c045c52b..000000000 --- a/src/newt/classes/com/sun/javafx/newt/Event.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt; - -public class Event { - private boolean isSystemEvent; - private int eventType; - private Window source; - private long when; - - Event(boolean isSystemEvent, int eventType, Window source, long when) { - this.isSystemEvent = isSystemEvent; - this.eventType = eventType; - this.source = source; - this.when = when; - } - - protected Event(int eventType, Window source, long when) { - this(false, eventType, source, when); - } - - /** Indicates whether this event was produced by the system or - generated by user code. */ - public final boolean isSystemEvent() { - return isSystemEvent; - } - - /** Returns the event type of this event. */ - public final int getEventType() { - return eventType; - } - - /** Returns the source Window which produced this Event. */ - public final Window getSource() { - return source; - } - - /** Returns the timestamp, in milliseconds, of this event. */ - public final long getWhen() { - return when; - } - - public String toString() { - return "Event[sys:"+isSystemEvent()+", source:"+getSource()+", when:"+getWhen()+"]"; - } - - public static String toHexString(int hex) { - return "0x" + Integer.toHexString(hex); - } - - public static String toHexString(long hex) { - return "0x" + Long.toHexString(hex); - } - -} diff --git a/src/newt/classes/com/sun/javafx/newt/EventListener.java b/src/newt/classes/com/sun/javafx/newt/EventListener.java deleted file mode 100644 index a312752fe..000000000 --- a/src/newt/classes/com/sun/javafx/newt/EventListener.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt; - -public interface EventListener -{ - public static final int WINDOW = 1 << 0; - public static final int MOUSE = 1 << 1; - public static final int KEY = 1 << 2; - public static final int SURFACE = 1 << 3; - -} - diff --git a/src/newt/classes/com/sun/javafx/newt/InputEvent.java b/src/newt/classes/com/sun/javafx/newt/InputEvent.java deleted file mode 100644 index b49c72e75..000000000 --- a/src/newt/classes/com/sun/javafx/newt/InputEvent.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt; - -public abstract class InputEvent extends Event -{ - public static final int SHIFT_MASK = 1 << 0; - public static final int CTRL_MASK = 1 << 1; - public static final int META_MASK = 1 << 2; - public static final int ALT_MASK = 1 << 3; - public static final int ALT_GRAPH_MASK = 1 << 5; - public static final int BUTTON1_MASK = 1 << 6; - public static final int BUTTON2_MASK = 1 << 7; - public static final int BUTTON3_MASK = 1 << 8; - - protected InputEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers) { - super(sysEvent, eventType, source, when); - this.consumed=false; - this.modifiers=modifiers; - } - - public void consume() { - consumed=true; - } - - public boolean isConsumed() { - return consumed; - } - public int getModifiers() { - return modifiers; - } - public boolean isAltDown() { - return (modifiers&ALT_MASK)!=0; - } - public boolean isAltGraphDown() { - return (modifiers&ALT_GRAPH_MASK)!=0; - } - public boolean isControlDown() { - return (modifiers&CTRL_MASK)!=0; - } - public boolean isMetaDown() { - return (modifiers&META_MASK)!=0; - } - public boolean isShiftDown() { - return (modifiers&SHIFT_MASK)!=0; - } - - public boolean isButton1Down() { - return (modifiers&BUTTON1_MASK)!=0; - } - - public boolean isButton2Down() { - return (modifiers&BUTTON2_MASK)!=0; - } - - public boolean isButton3Down() { - return (modifiers&BUTTON3_MASK)!=0; - } - - public String toString() { - return "InputEvent[modifiers:"+modifiers+"]"; - } - - private boolean consumed; - private int modifiers; -} diff --git a/src/newt/classes/com/sun/javafx/newt/Insets.java b/src/newt/classes/com/sun/javafx/newt/Insets.java deleted file mode 100644 index 7d379cd92..000000000 --- a/src/newt/classes/com/sun/javafx/newt/Insets.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2009 Sun Microsystems, Inc. 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. - * - */ -package com.sun.javafx.newt; - -/** - * Simple class representing insets. - * - * @author tdv - */ -public class Insets implements Cloneable { - public int top; - public int left; - public int bottom; - public int right; - - /** - * Creates and initializes a new Insets object with the - * specified top, left, bottom, and right insets. - * @param top the inset from the top. - * @param left the inset from the left. - * @param bottom the inset from the bottom. - * @param right the inset from the right. - */ - public Insets(int top, int left, int bottom, int right) { - this.top = top; - this.left = left; - this.bottom = bottom; - this.right = right; - } - - /** - * Checks whether two insets objects are equal. Two instances - * of Insets are equal if the four integer values - * of the fields top, left, - * bottom, and right are all equal. - * @return true if the two insets are equal; - * otherwise false. - */ - public boolean equals(Object obj) { - if (obj instanceof Insets) { - Insets insets = (Insets)obj; - return ((top == insets.top) && (left == insets.left) && - (bottom == insets.bottom) && (right == insets.right)); - } - return false; - } - - /** - * Returns the hash code for this Insets. - * - * @return a hash code for this Insets. - */ - public int hashCode() { - int sum1 = left + bottom; - int sum2 = right + top; - int val1 = sum1 * (sum1 + 1)/2 + left; - int val2 = sum2 * (sum2 + 1)/2 + top; - int sum3 = val1 + val2; - return sum3 * (sum3 + 1)/2 + val2; - } - - public String toString() { - return getClass().getName() + "[top=" + top + ",left=" + left + - ",bottom=" + bottom + ",right=" + right + "]"; - } - - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException ex) { - throw new InternalError(); - } - } - -} diff --git a/src/newt/classes/com/sun/javafx/newt/KeyEvent.java b/src/newt/classes/com/sun/javafx/newt/KeyEvent.java deleted file mode 100644 index c7450da67..000000000 --- a/src/newt/classes/com/sun/javafx/newt/KeyEvent.java +++ /dev/null @@ -1,738 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt; - -public class KeyEvent extends InputEvent -{ - KeyEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers, int keyCode, char keyChar) { - super(sysEvent, eventType, source, when, modifiers); - this.keyCode=keyCode; - this.keyChar=keyChar; - } - public KeyEvent(int eventType, Window source, long when, int modifiers, int keyCode, char keyChar) { - this(false, eventType, source, when, modifiers, keyCode, keyChar); - } - - public char getKeyChar() { - return keyChar; - } - public int getKeyCode() { - return keyCode; - } - - public String toString() { - return "KeyEvent["+getEventTypeString(getEventType())+ - ", code "+keyCode+"("+toHexString(keyCode)+"), char <"+keyChar+"> ("+toHexString((int)keyChar)+"), isActionKey "+isActionKey()+", "+super.toString()+"]"; - } - - public static String getEventTypeString(int type) { - switch(type) { - case EVENT_KEY_PRESSED: return "EVENT_KEY_PRESSED"; - case EVENT_KEY_RELEASED: return "EVENT_KEY_RELEASED"; - case EVENT_KEY_TYPED: return "EVENT_KEY_TYPED"; - default: return "unknown (" + type + ")"; - } - } - - public boolean isActionKey() { - switch (keyCode) { - case VK_HOME: - case VK_END: - case VK_PAGE_UP: - case VK_PAGE_DOWN: - case VK_UP: - case VK_DOWN: - case VK_LEFT: - case VK_RIGHT: - - case VK_F1: - case VK_F2: - case VK_F3: - case VK_F4: - case VK_F5: - case VK_F6: - case VK_F7: - case VK_F8: - case VK_F9: - case VK_F10: - case VK_F11: - case VK_F12: - case VK_F13: - case VK_F14: - case VK_F15: - case VK_F16: - case VK_F17: - case VK_F18: - case VK_F19: - case VK_F20: - case VK_F21: - case VK_F22: - case VK_F23: - case VK_F24: - case VK_PRINTSCREEN: - case VK_CAPS_LOCK: - case VK_PAUSE: - case VK_INSERT: - - case VK_HELP: - case VK_WINDOWS: - return true; - } - return false; - } - - private int keyCode; - private char keyChar; - - public static final int EVENT_KEY_PRESSED = 300; - public static final int EVENT_KEY_RELEASED= 301; - public static final int EVENT_KEY_TYPED = 302; - - /* Virtual key codes. */ - - public static final int VK_ENTER = '\n'; - public static final int VK_BACK_SPACE = '\b'; - public static final int VK_TAB = '\t'; - public static final int VK_CANCEL = 0x03; - public static final int VK_CLEAR = 0x0C; - public static final int VK_SHIFT = 0x10; - public static final int VK_CONTROL = 0x11; - public static final int VK_ALT = 0x12; - public static final int VK_PAUSE = 0x13; - public static final int VK_CAPS_LOCK = 0x14; - public static final int VK_ESCAPE = 0x1B; - public static final int VK_SPACE = 0x20; - public static final int VK_PAGE_UP = 0x21; - public static final int VK_PAGE_DOWN = 0x22; - public static final int VK_END = 0x23; - public static final int VK_HOME = 0x24; - - /** - * Constant for the non-numpad left arrow key. - * @see #VK_KP_LEFT - */ - public static final int VK_LEFT = 0x25; - - /** - * Constant for the non-numpad up arrow key. - * @see #VK_KP_UP - */ - public static final int VK_UP = 0x26; - - /** - * Constant for the non-numpad right arrow key. - * @see #VK_KP_RIGHT - */ - public static final int VK_RIGHT = 0x27; - - /** - * Constant for the non-numpad down arrow key. - * @see #VK_KP_DOWN - */ - public static final int VK_DOWN = 0x28; - - /** - * Constant for the comma key, "," - */ - public static final int VK_COMMA = 0x2C; - - /** - * Constant for the minus key, "-" - * @since 1.2 - */ - public static final int VK_MINUS = 0x2D; - - /** - * Constant for the period key, "." - */ - public static final int VK_PERIOD = 0x2E; - - /** - * Constant for the forward slash key, "/" - */ - public static final int VK_SLASH = 0x2F; - - /** VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */ - public static final int VK_0 = 0x30; - public static final int VK_1 = 0x31; - public static final int VK_2 = 0x32; - public static final int VK_3 = 0x33; - public static final int VK_4 = 0x34; - public static final int VK_5 = 0x35; - public static final int VK_6 = 0x36; - public static final int VK_7 = 0x37; - public static final int VK_8 = 0x38; - public static final int VK_9 = 0x39; - - /** - * Constant for the semicolon key, ";" - */ - public static final int VK_SEMICOLON = 0x3B; - - /** - * Constant for the equals key, "=" - */ - public static final int VK_EQUALS = 0x3D; - - /** VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */ - public static final int VK_A = 0x41; - public static final int VK_B = 0x42; - public static final int VK_C = 0x43; - public static final int VK_D = 0x44; - public static final int VK_E = 0x45; - public static final int VK_F = 0x46; - public static final int VK_G = 0x47; - public static final int VK_H = 0x48; - public static final int VK_I = 0x49; - public static final int VK_J = 0x4A; - public static final int VK_K = 0x4B; - public static final int VK_L = 0x4C; - public static final int VK_M = 0x4D; - public static final int VK_N = 0x4E; - public static final int VK_O = 0x4F; - public static final int VK_P = 0x50; - public static final int VK_Q = 0x51; - public static final int VK_R = 0x52; - public static final int VK_S = 0x53; - public static final int VK_T = 0x54; - public static final int VK_U = 0x55; - public static final int VK_V = 0x56; - public static final int VK_W = 0x57; - public static final int VK_X = 0x58; - public static final int VK_Y = 0x59; - public static final int VK_Z = 0x5A; - - /** - * Constant for the open bracket key, "[" - */ - public static final int VK_OPEN_BRACKET = 0x5B; - - /** - * Constant for the back slash key, "\" - */ - public static final int VK_BACK_SLASH = 0x5C; - - /** - * Constant for the close bracket key, "]" - */ - public static final int VK_CLOSE_BRACKET = 0x5D; - - public static final int VK_NUMPAD0 = 0x60; - public static final int VK_NUMPAD1 = 0x61; - public static final int VK_NUMPAD2 = 0x62; - public static final int VK_NUMPAD3 = 0x63; - public static final int VK_NUMPAD4 = 0x64; - public static final int VK_NUMPAD5 = 0x65; - public static final int VK_NUMPAD6 = 0x66; - public static final int VK_NUMPAD7 = 0x67; - public static final int VK_NUMPAD8 = 0x68; - public static final int VK_NUMPAD9 = 0x69; - public static final int VK_MULTIPLY = 0x6A; - public static final int VK_ADD = 0x6B; - - /** - * This constant is obsolete, and is included only for backwards - * compatibility. - * @see #VK_SEPARATOR - */ - public static final int VK_SEPARATER = 0x6C; - - /** - * Constant for the Numpad Separator key. - * @since 1.4 - */ - public static final int VK_SEPARATOR = VK_SEPARATER; - - public static final int VK_SUBTRACT = 0x6D; - public static final int VK_DECIMAL = 0x6E; - public static final int VK_DIVIDE = 0x6F; - public static final int VK_DELETE = 0x7F; /* ASCII DEL */ - public static final int VK_NUM_LOCK = 0x90; - public static final int VK_SCROLL_LOCK = 0x91; - - /** Constant for the F1 function key. */ - public static final int VK_F1 = 0x70; - - /** Constant for the F2 function key. */ - public static final int VK_F2 = 0x71; - - /** Constant for the F3 function key. */ - public static final int VK_F3 = 0x72; - - /** Constant for the F4 function key. */ - public static final int VK_F4 = 0x73; - - /** Constant for the F5 function key. */ - public static final int VK_F5 = 0x74; - - /** Constant for the F6 function key. */ - public static final int VK_F6 = 0x75; - - /** Constant for the F7 function key. */ - public static final int VK_F7 = 0x76; - - /** Constant for the F8 function key. */ - public static final int VK_F8 = 0x77; - - /** Constant for the F9 function key. */ - public static final int VK_F9 = 0x78; - - /** Constant for the F10 function key. */ - public static final int VK_F10 = 0x79; - - /** Constant for the F11 function key. */ - public static final int VK_F11 = 0x7A; - - /** Constant for the F12 function key. */ - public static final int VK_F12 = 0x7B; - - /** - * Constant for the F13 function key. - * @since 1.2 - */ - /* F13 - F24 are used on IBM 3270 keyboard; use random range for constants. */ - public static final int VK_F13 = 0xF000; - - /** - * Constant for the F14 function key. - * @since 1.2 - */ - public static final int VK_F14 = 0xF001; - - /** - * Constant for the F15 function key. - * @since 1.2 - */ - public static final int VK_F15 = 0xF002; - - /** - * Constant for the F16 function key. - * @since 1.2 - */ - public static final int VK_F16 = 0xF003; - - /** - * Constant for the F17 function key. - * @since 1.2 - */ - public static final int VK_F17 = 0xF004; - - /** - * Constant for the F18 function key. - * @since 1.2 - */ - public static final int VK_F18 = 0xF005; - - /** - * Constant for the F19 function key. - * @since 1.2 - */ - public static final int VK_F19 = 0xF006; - - /** - * Constant for the F20 function key. - * @since 1.2 - */ - public static final int VK_F20 = 0xF007; - - /** - * Constant for the F21 function key. - * @since 1.2 - */ - public static final int VK_F21 = 0xF008; - - /** - * Constant for the F22 function key. - * @since 1.2 - */ - public static final int VK_F22 = 0xF009; - - /** - * Constant for the F23 function key. - * @since 1.2 - */ - public static final int VK_F23 = 0xF00A; - - /** - * Constant for the F24 function key. - * @since 1.2 - */ - public static final int VK_F24 = 0xF00B; - - public static final int VK_PRINTSCREEN = 0x9A; - public static final int VK_INSERT = 0x9B; - public static final int VK_HELP = 0x9C; - public static final int VK_META = 0x9D; - - public static final int VK_BACK_QUOTE = 0xC0; - public static final int VK_QUOTE = 0xDE; - - /** - * Constant for the numeric keypad up arrow key. - * @see #VK_UP - * @since 1.2 - */ - public static final int VK_KP_UP = 0xE0; - - /** - * Constant for the numeric keypad down arrow key. - * @see #VK_DOWN - * @since 1.2 - */ - public static final int VK_KP_DOWN = 0xE1; - - /** - * Constant for the numeric keypad left arrow key. - * @see #VK_LEFT - * @since 1.2 - */ - public static final int VK_KP_LEFT = 0xE2; - - /** - * Constant for the numeric keypad right arrow key. - * @see #VK_RIGHT - * @since 1.2 - */ - public static final int VK_KP_RIGHT = 0xE3; - - /* For European keyboards */ - /** @since 1.2 */ - public static final int VK_DEAD_GRAVE = 0x80; - /** @since 1.2 */ - public static final int VK_DEAD_ACUTE = 0x81; - /** @since 1.2 */ - public static final int VK_DEAD_CIRCUMFLEX = 0x82; - /** @since 1.2 */ - public static final int VK_DEAD_TILDE = 0x83; - /** @since 1.2 */ - public static final int VK_DEAD_MACRON = 0x84; - /** @since 1.2 */ - public static final int VK_DEAD_BREVE = 0x85; - /** @since 1.2 */ - public static final int VK_DEAD_ABOVEDOT = 0x86; - /** @since 1.2 */ - public static final int VK_DEAD_DIAERESIS = 0x87; - /** @since 1.2 */ - public static final int VK_DEAD_ABOVERING = 0x88; - /** @since 1.2 */ - public static final int VK_DEAD_DOUBLEACUTE = 0x89; - /** @since 1.2 */ - public static final int VK_DEAD_CARON = 0x8a; - /** @since 1.2 */ - public static final int VK_DEAD_CEDILLA = 0x8b; - /** @since 1.2 */ - public static final int VK_DEAD_OGONEK = 0x8c; - /** @since 1.2 */ - public static final int VK_DEAD_IOTA = 0x8d; - /** @since 1.2 */ - public static final int VK_DEAD_VOICED_SOUND = 0x8e; - /** @since 1.2 */ - public static final int VK_DEAD_SEMIVOICED_SOUND = 0x8f; - - /** @since 1.2 */ - public static final int VK_AMPERSAND = 0x96; - /** @since 1.2 */ - public static final int VK_ASTERISK = 0x97; - /** @since 1.2 */ - public static final int VK_QUOTEDBL = 0x98; - /** @since 1.2 */ - public static final int VK_LESS = 0x99; - - /** @since 1.2 */ - public static final int VK_GREATER = 0xa0; - /** @since 1.2 */ - public static final int VK_BRACELEFT = 0xa1; - /** @since 1.2 */ - public static final int VK_BRACERIGHT = 0xa2; - - /** - * Constant for the "@" key. - * @since 1.2 - */ - public static final int VK_AT = 0x0200; - - /** - * Constant for the ":" key. - * @since 1.2 - */ - public static final int VK_COLON = 0x0201; - - /** - * Constant for the "^" key. - * @since 1.2 - */ - public static final int VK_CIRCUMFLEX = 0x0202; - - /** - * Constant for the "$" key. - * @since 1.2 - */ - public static final int VK_DOLLAR = 0x0203; - - /** - * Constant for the Euro currency sign key. - * @since 1.2 - */ - public static final int VK_EURO_SIGN = 0x0204; - - /** - * Constant for the "!" key. - * @since 1.2 - */ - public static final int VK_EXCLAMATION_MARK = 0x0205; - - /** - * Constant for the inverted exclamation mark key. - * @since 1.2 - */ - public static final int VK_INVERTED_EXCLAMATION_MARK = 0x0206; - - /** - * Constant for the "(" key. - * @since 1.2 - */ - public static final int VK_LEFT_PARENTHESIS = 0x0207; - - /** - * Constant for the "#" key. - * @since 1.2 - */ - public static final int VK_NUMBER_SIGN = 0x0208; - - /** - * Constant for the "+" key. - * @since 1.2 - */ - public static final int VK_PLUS = 0x0209; - - /** - * Constant for the ")" key. - * @since 1.2 - */ - public static final int VK_RIGHT_PARENTHESIS = 0x020A; - - /** - * Constant for the "_" key. - * @since 1.2 - */ - public static final int VK_UNDERSCORE = 0x020B; - - /** - * Constant for the Microsoft Windows "Windows" key. - * It is used for both the left and right version of the key. - * @see #getKeyLocation() - * @since 1.5 - */ - public static final int VK_WINDOWS = 0x020C; - - /** - * Constant for the Microsoft Windows Context Menu key. - * @since 1.5 - */ - public static final int VK_CONTEXT_MENU = 0x020D; - - /* for input method support on Asian Keyboards */ - - /* not clear what this means - listed in Microsoft Windows API */ - public static final int VK_FINAL = 0x0018; - - /** Constant for the Convert function key. */ - /* Japanese PC 106 keyboard, Japanese Solaris keyboard: henkan */ - public static final int VK_CONVERT = 0x001C; - - /** Constant for the Don't Convert function key. */ - /* Japanese PC 106 keyboard: muhenkan */ - public static final int VK_NONCONVERT = 0x001D; - - /** Constant for the Accept or Commit function key. */ - /* Japanese Solaris keyboard: kakutei */ - public static final int VK_ACCEPT = 0x001E; - - /* not clear what this means - listed in Microsoft Windows API */ - public static final int VK_MODECHANGE = 0x001F; - - /* replaced by VK_KANA_LOCK for Microsoft Windows and Solaris; - might still be used on other platforms */ - public static final int VK_KANA = 0x0015; - - /* replaced by VK_INPUT_METHOD_ON_OFF for Microsoft Windows and Solaris; - might still be used for other platforms */ - public static final int VK_KANJI = 0x0019; - - /** - * Constant for the Alphanumeric function key. - * @since 1.2 - */ - /* Japanese PC 106 keyboard: eisuu */ - public static final int VK_ALPHANUMERIC = 0x00F0; - - /** - * Constant for the Katakana function key. - * @since 1.2 - */ - /* Japanese PC 106 keyboard: katakana */ - public static final int VK_KATAKANA = 0x00F1; - - /** - * Constant for the Hiragana function key. - * @since 1.2 - */ - /* Japanese PC 106 keyboard: hiragana */ - public static final int VK_HIRAGANA = 0x00F2; - - /** - * Constant for the Full-Width Characters function key. - * @since 1.2 - */ - /* Japanese PC 106 keyboard: zenkaku */ - public static final int VK_FULL_WIDTH = 0x00F3; - - /** - * Constant for the Half-Width Characters function key. - * @since 1.2 - */ - /* Japanese PC 106 keyboard: hankaku */ - public static final int VK_HALF_WIDTH = 0x00F4; - - /** - * Constant for the Roman Characters function key. - * @since 1.2 - */ - /* Japanese PC 106 keyboard: roumaji */ - public static final int VK_ROMAN_CHARACTERS = 0x00F5; - - /** - * Constant for the All Candidates function key. - * @since 1.2 - */ - /* Japanese PC 106 keyboard - VK_CONVERT + ALT: zenkouho */ - public static final int VK_ALL_CANDIDATES = 0x0100; - - /** - * Constant for the Previous Candidate function key. - * @since 1.2 - */ - /* Japanese PC 106 keyboard - VK_CONVERT + SHIFT: maekouho */ - public static final int VK_PREVIOUS_CANDIDATE = 0x0101; - - /** - * Constant for the Code Input function key. - * @since 1.2 - */ - /* Japanese PC 106 keyboard - VK_ALPHANUMERIC + ALT: kanji bangou */ - public static final int VK_CODE_INPUT = 0x0102; - - /** - * Constant for the Japanese-Katakana function key. - * This key switches to a Japanese input method and selects its Katakana input mode. - * @since 1.2 - */ - /* Japanese Macintosh keyboard - VK_JAPANESE_HIRAGANA + SHIFT */ - public static final int VK_JAPANESE_KATAKANA = 0x0103; - - /** - * Constant for the Japanese-Hiragana function key. - * This key switches to a Japanese input method and selects its Hiragana input mode. - * @since 1.2 - */ - /* Japanese Macintosh keyboard */ - public static final int VK_JAPANESE_HIRAGANA = 0x0104; - - /** - * Constant for the Japanese-Roman function key. - * This key switches to a Japanese input method and selects its Roman-Direct input mode. - * @since 1.2 - */ - /* Japanese Macintosh keyboard */ - public static final int VK_JAPANESE_ROMAN = 0x0105; - - /** - * Constant for the locking Kana function key. - * This key locks the keyboard into a Kana layout. - * @since 1.3 - */ - /* Japanese PC 106 keyboard with special Windows driver - eisuu + Control; Japanese Solaris keyboard: kana */ - public static final int VK_KANA_LOCK = 0x0106; - - /** - * Constant for the input method on/off key. - * @since 1.3 - */ - /* Japanese PC 106 keyboard: kanji. Japanese Solaris keyboard: nihongo */ - public static final int VK_INPUT_METHOD_ON_OFF = 0x0107; - - /* for Sun keyboards */ - /** @since 1.2 */ - public static final int VK_CUT = 0xFFD1; - /** @since 1.2 */ - public static final int VK_COPY = 0xFFCD; - /** @since 1.2 */ - public static final int VK_PASTE = 0xFFCF; - /** @since 1.2 */ - public static final int VK_UNDO = 0xFFCB; - /** @since 1.2 */ - public static final int VK_AGAIN = 0xFFC9; - /** @since 1.2 */ - public static final int VK_FIND = 0xFFD0; - /** @since 1.2 */ - public static final int VK_PROPS = 0xFFCA; - /** @since 1.2 */ - public static final int VK_STOP = 0xFFC8; - - /** - * Constant for the Compose function key. - * @since 1.2 - */ - public static final int VK_COMPOSE = 0xFF20; - - /** - * Constant for the AltGraph function key. - * @since 1.2 - */ - public static final int VK_ALT_GRAPH = 0xFF7E; - - /** - * Constant for the Begin key. - * @since 1.5 - */ - public static final int VK_BEGIN = 0xFF58; - - /** - * This value is used to indicate that the keyCode is unknown. - * KEY_TYPED events do not have a keyCode value; this value - * is used instead. - */ - public static final int VK_UNDEFINED = 0x0; -} - diff --git a/src/newt/classes/com/sun/javafx/newt/KeyListener.java b/src/newt/classes/com/sun/javafx/newt/KeyListener.java deleted file mode 100644 index 6f022c45a..000000000 --- a/src/newt/classes/com/sun/javafx/newt/KeyListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt; - -public interface KeyListener extends EventListener -{ - public void keyPressed(KeyEvent e); - public void keyReleased(KeyEvent e); - public void keyTyped(KeyEvent e) ; -} - diff --git a/src/newt/classes/com/sun/javafx/newt/MouseEvent.java b/src/newt/classes/com/sun/javafx/newt/MouseEvent.java deleted file mode 100644 index ede193e1c..000000000 --- a/src/newt/classes/com/sun/javafx/newt/MouseEvent.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt; - -public class MouseEvent extends InputEvent -{ - public static final int BUTTON1 = 1; - public static final int BUTTON2 = 2; - public static final int BUTTON3 = 3; - public static final int BUTTON4 = 4; - public static final int BUTTON5 = 5; - public static final int BUTTON6 = 6; - public static final int BUTTON_NUMBER = 6; - - protected MouseEvent(boolean sysEvent, int eventType, Window source, long when, - int modifiers, int x, int y, int clickCount, int button, - int rotation) - { - super(sysEvent, eventType, source, when, modifiers); - this.x=x; - this.y=y; - this.clickCount=clickCount; - this.button=button; - this.wheelRotation = rotation; - } - public MouseEvent(int eventType, Window source, long when, int modifiers, - int x, int y, int clickCount, int button, int rotation) { - this(false, eventType, source, when, modifiers, x, y, clickCount, button, - rotation); - } - - public int getButton() { - return button; - } - public int getClickCount() { - return clickCount; - } - public int getX() { - return x; - } - public int getY() { - return y; - } - public int getWheelRotation() { - return wheelRotation; - } - - public String toString() { - return "MouseEvent["+getEventTypeString(getEventType())+ - ", "+x+"/"+y+", button "+button+", count "+clickCount+ - ", wheel rotation "+wheelRotation+ - ", "+super.toString()+"]"; - } - - public static String getEventTypeString(int type) { - switch(type) { - case EVENT_MOUSE_CLICKED: return "EVENT_MOUSE_CLICKED"; - case EVENT_MOUSE_ENTERED: return "EVENT_MOUSE_ENTERED"; - case EVENT_MOUSE_EXITED: return "EVENT_MOUSE_EXITED"; - case EVENT_MOUSE_PRESSED: return "EVENT_MOUSE_PRESSED"; - case EVENT_MOUSE_RELEASED: return "EVENT_MOUSE_RELEASED"; - case EVENT_MOUSE_MOVED: return "EVENT_MOUSE_MOVED"; - case EVENT_MOUSE_DRAGGED: return "EVENT_MOUSE_DRAGGED"; - case EVENT_MOUSE_WHEEL_MOVED: return "EVENT_MOUSE_WHEEL_MOVED"; - default: return "unknown (" + type + ")"; - } - } - - private int x, y, clickCount, button, wheelRotation; - - public static final int EVENT_MOUSE_CLICKED = 200; - public static final int EVENT_MOUSE_ENTERED = 201; - public static final int EVENT_MOUSE_EXITED = 202; - public static final int EVENT_MOUSE_PRESSED = 203; - public static final int EVENT_MOUSE_RELEASED = 204; - public static final int EVENT_MOUSE_MOVED = 205; - public static final int EVENT_MOUSE_DRAGGED = 206; - public static final int EVENT_MOUSE_WHEEL_MOVED = 207; -} diff --git a/src/newt/classes/com/sun/javafx/newt/MouseListener.java b/src/newt/classes/com/sun/javafx/newt/MouseListener.java deleted file mode 100644 index 3d2031f2a..000000000 --- a/src/newt/classes/com/sun/javafx/newt/MouseListener.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt; - -public interface MouseListener extends EventListener -{ - public void mouseClicked(MouseEvent e); - public void mouseEntered(MouseEvent e); - public void mouseExited(MouseEvent e); - public void mousePressed(MouseEvent e); - public void mouseReleased(MouseEvent e); - public void mouseMoved(MouseEvent e); - public void mouseDragged(MouseEvent e); - public void mouseWheelMoved(MouseEvent e); -} - diff --git a/src/newt/classes/com/sun/javafx/newt/NewtFactory.java b/src/newt/classes/com/sun/javafx/newt/NewtFactory.java deleted file mode 100755 index 6e25b19eb..000000000 --- a/src/newt/classes/com/sun/javafx/newt/NewtFactory.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt; - -import javax.media.nativewindow.*; -import java.util.ArrayList; -import java.util.Iterator; -import com.sun.nativewindow.impl.jvm.JVMUtil; - -public abstract class NewtFactory { - // Work-around for initialization order problems on Mac OS X - // between native Newt and (apparently) Fmod - static { - JVMUtil.initSingleton(); - Window.init(NativeWindowFactory.getNativeWindowType(true)); - } - - static Class getCustomClass(String packageName, String classBaseName) { - Class clazz = null; - if(packageName!=null || classBaseName!=null) { - String clazzName = packageName + "." + classBaseName ; - try { - clazz = Class.forName(clazzName); - } catch (Throwable t) {} - } - return clazz; - } - - private static boolean useEDT = true; - - /** - * Toggles the usage of an EventDispatchThread while creating a Display.
- * The default is enabled.
- * The EventDispatchThread is thread local to the Display instance.
- */ - public static synchronized void setUseEDT(boolean onoff) { - useEDT = onoff; - } - - /** @see #setUseEDT(boolean) */ - public static boolean useEDT() { return useEDT; } - - /** - * Create a Display entity, incl native creation - */ - public static Display createDisplay(String name) { - return Display.create(NativeWindowFactory.getNativeWindowType(true), name); - } - - /** - * Create a Display entity using the given implementation type, incl native creation - */ - public static Display createDisplay(String type, String name) { - return Display.create(type, name); - } - - /** - * Create a Screen entity, incl native creation - */ - public static Screen createScreen(Display display, int index) { - return Screen.create(NativeWindowFactory.getNativeWindowType(true), display, index); - } - - /** - * Create a Screen entity using the given implementation type, incl native creation - */ - public static Screen createScreen(String type, Display display, int index) { - return Screen.create(type, display, index); - } - - /** - * Create a Window entity, incl native creation - */ - public static Window createWindow(Screen screen, Capabilities caps) { - return Window.create(NativeWindowFactory.getNativeWindowType(true), 0, screen, caps, false); - } - - public static Window createWindow(Screen screen, Capabilities caps, boolean undecorated) { - return Window.create(NativeWindowFactory.getNativeWindowType(true), 0, screen, caps, undecorated); - } - - public static Window createWindow(long parentWindowHandle, Screen screen, Capabilities caps, boolean undecorated) { - return Window.create(NativeWindowFactory.getNativeWindowType(true), parentWindowHandle, screen, caps, undecorated); - } - - /** - * Ability to try a Window type with a construnctor argument, if supported ..

- * Currently only valid is AWTWindow(Frame frame) , - * to support an external created AWT Frame, ie the browsers embedded frame. - */ - public static Window createWindow(Object[] cstrArguments, Screen screen, Capabilities caps, boolean undecorated) { - return Window.create(NativeWindowFactory.getNativeWindowType(true), cstrArguments, screen, caps, undecorated); - } - - /** - * Create a Window entity using the given implementation type, incl native creation - */ - public static Window createWindow(String type, Screen screen, Capabilities caps) { - return Window.create(type, 0, screen, caps, false); - } - - public static Window createWindow(String type, Screen screen, Capabilities caps, boolean undecorated) { - return Window.create(type, 0, screen, caps, undecorated); - } - - public static Window createWindow(String type, long parentWindowHandle, Screen screen, Capabilities caps, boolean undecorated) { - return Window.create(type, parentWindowHandle, screen, caps, undecorated); - } - - public static Window createWindow(String type, Object[] cstrArguments, Screen screen, Capabilities caps, boolean undecorated) { - return Window.create(type, cstrArguments, screen, caps, undecorated); - } - - /** - * Instantiate a Display entity using the native handle. - */ - public static Display wrapDisplay(String name, AbstractGraphicsDevice device) { - return Display.wrapHandle(NativeWindowFactory.getNativeWindowType(true), name, device); - } - - /** - * Instantiate a Screen entity using the native handle. - */ - public static Screen wrapScreen(Display display, AbstractGraphicsScreen screen) { - return Screen.wrapHandle(NativeWindowFactory.getNativeWindowType(true), display, screen); - } - - /** - * Instantiate a Window entity using the native handle. - */ - public static Window wrapWindow(Screen screen, AbstractGraphicsConfiguration config, - long windowHandle, boolean fullscreen, boolean visible, - int x, int y, int width, int height) { - return Window.wrapHandle(NativeWindowFactory.getNativeWindowType(true), screen, config, - windowHandle, fullscreen, visible, x, y, width, height); - } - - private static final boolean instanceOf(Object obj, String clazzName) { - Class clazz = obj.getClass(); - do { - if(clazz.getName().equals(clazzName)) { - return true; - } - clazz = clazz.getSuperclass(); - } while (clazz!=null); - return false; - } - -} - diff --git a/src/newt/classes/com/sun/javafx/newt/OffscreenWindow.java b/src/newt/classes/com/sun/javafx/newt/OffscreenWindow.java deleted file mode 100644 index 11ce8e6c7..000000000 --- a/src/newt/classes/com/sun/javafx/newt/OffscreenWindow.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt; - -import javax.media.nativewindow.*; - -public class OffscreenWindow extends Window implements SurfaceChangeable { - - long surfaceHandle = 0; - - public OffscreenWindow() { - } - - static long nextWindowHandle = 0x100; // start here - a marker - - protected void createNative(long parentWindowHandle, Capabilities caps) { - if(0!=parentWindowHandle) { - throw new NativeWindowException("OffscreenWindow does not support window parenting"); - } - if(caps.isOnscreen()) { - throw new NativeWindowException("Capabilities is onscreen"); - } - AbstractGraphicsScreen aScreen = screen.getGraphicsScreen(); - config = GraphicsConfigurationFactory.getFactory(aScreen.getDevice()).chooseGraphicsConfiguration(caps, null, aScreen); - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - - synchronized(OffscreenWindow.class) { - windowHandle = nextWindowHandle++; - } - } - - protected void closeNative() { - // nop - } - - public void invalidate() { - super.invalidate(); - surfaceHandle = 0; - } - - public synchronized void destroy() { - surfaceHandle = 0; - } - - public void setSurfaceHandle(long handle) { - surfaceHandle = handle ; - } - - public long getSurfaceHandle() { - return surfaceHandle; - } - - public void setVisible(boolean visible) { - if(!visible) { - this.visible = visible; - } - } - - public void setSize(int width, int height) { - if(!visible) { - this.width = width; - this.height = height; - } - } - - public void setPosition(int x, int y) { - // nop - } - - public boolean setFullscreen(boolean fullscreen) { - // nop - return false; - } -} - diff --git a/src/newt/classes/com/sun/javafx/newt/PaintEvent.java b/src/newt/classes/com/sun/javafx/newt/PaintEvent.java deleted file mode 100755 index b27b969da..000000000 --- a/src/newt/classes/com/sun/javafx/newt/PaintEvent.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2009 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt; - -/** - * - * @author tdv - */ -public class PaintEvent extends Event { - - // bounds of the damage region - private int x, y, width, height; - public PaintEvent(int eventType, Window source, - long when, int x, int y, int w, int h) - { - super(true, eventType, source, when); - this.x = x; - this.y = y; - this.width = w; - this.height = h; - } - - public int getHeight() { - return height; - } - - public int getWidth() { - return width; - } - - public int getX() { - return x; - } - - public int getY() { - return y; - } - - public String toString() { - return "ExposeEvent[modifiers: x="+x+" y="+y+" w="+width+" h="+height +"]"; - } - -} diff --git a/src/newt/classes/com/sun/javafx/newt/PaintListener.java b/src/newt/classes/com/sun/javafx/newt/PaintListener.java deleted file mode 100755 index fab5fa35c..000000000 --- a/src/newt/classes/com/sun/javafx/newt/PaintListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2009 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt; - -/** - * - * @author tdv - */ -public interface PaintListener { - public void exposed(PaintEvent e); -} diff --git a/src/newt/classes/com/sun/javafx/newt/Screen.java b/src/newt/classes/com/sun/javafx/newt/Screen.java deleted file mode 100755 index 9edd0b719..000000000 --- a/src/newt/classes/com/sun/javafx/newt/Screen.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt; - -import com.sun.javafx.newt.impl.*; - -import javax.media.nativewindow.*; -import java.security.*; - -public abstract class Screen { - - private static Class getScreenClass(String type) - throws ClassNotFoundException - { - Class screenClass = NewtFactory.getCustomClass(type, "Screen"); - if(null==screenClass) { - if (NativeWindowFactory.TYPE_EGL.equals(type)) { - screenClass = Class.forName("com.sun.javafx.newt.opengl.kd.KDScreen"); - } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) { - screenClass = Class.forName("com.sun.javafx.newt.windows.WindowsScreen"); - } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { - screenClass = Class.forName("com.sun.javafx.newt.macosx.MacScreen"); - } else if (NativeWindowFactory.TYPE_X11.equals(type)) { - screenClass = Class.forName("com.sun.javafx.newt.x11.X11Screen"); - } else if (NativeWindowFactory.TYPE_AWT.equals(type)) { - screenClass = Class.forName("com.sun.javafx.newt.awt.AWTScreen"); - } else { - throw new RuntimeException("Unknown window type \"" + type + "\""); - } - } - return screenClass; - } - - protected static Screen create(String type, Display display, int idx) { - try { - if(usrWidth<0 || usrHeight<0) { - usrWidth = Debug.getIntProperty("newt.ws.swidth", true, localACC); - usrHeight = Debug.getIntProperty("newt.ws.sheight", true, localACC); - System.out.println("User screen size "+usrWidth+"x"+usrHeight); - } - Class screenClass = getScreenClass(type); - Screen screen = (Screen) screenClass.newInstance(); - screen.display = display; - screen.createNative(idx); - if(null==screen.aScreen) { - throw new RuntimeException("Screen.createNative() failed to instanciate an AbstractGraphicsScreen"); - } - return screen; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public synchronized void destroy() { - closeNative(); - display = null; - aScreen = null; - } - - protected static Screen wrapHandle(String type, Display display, AbstractGraphicsScreen aScreen) { - try { - Class screenClass = getScreenClass(type); - Screen screen = (Screen) screenClass.newInstance(); - screen.display = display; - screen.aScreen = aScreen; - return screen; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - protected abstract void createNative(int index); - protected abstract void closeNative(); - - protected void setScreenSize(int w, int h) { - System.out.println("Detected screen size "+w+"x"+h); - width=w; height=h; - } - - public Display getDisplay() { - return display; - } - - public int getIndex() { - return aScreen.getIndex(); - } - - public AbstractGraphicsScreen getGraphicsScreen() { - return aScreen; - } - - /** - * The actual implementation shall return the detected display value, - * if not we return 800. - * This can be overwritten with the user property 'newt.ws.swidth', - */ - public int getWidth() { - return (usrWidth>0) ? usrWidth : (width>0) ? width : 480; - } - - /** - * The actual implementation shall return the detected display value, - * if not we return 480. - * This can be overwritten with the user property 'newt.ws.sheight', - */ - public int getHeight() { - return (usrHeight>0) ? usrHeight : (height>0) ? height : 480; - } - - protected Display display; - protected AbstractGraphicsScreen aScreen; - protected int width=-1, height=-1; // detected values: set using setScreenSize - protected static int usrWidth=-1, usrHeight=-1; // property values: newt.ws.swidth and newt.ws.sheight - private static AccessControlContext localACC = AccessController.getContext(); -} - diff --git a/src/newt/classes/com/sun/javafx/newt/Window.java b/src/newt/classes/com/sun/javafx/newt/Window.java deleted file mode 100755 index 58bd251d2..000000000 --- a/src/newt/classes/com/sun/javafx/newt/Window.java +++ /dev/null @@ -1,929 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt; - -import com.sun.javafx.newt.impl.Debug; -import com.sun.javafx.newt.util.EventDispatchThread; - -import javax.media.nativewindow.*; -import com.sun.nativewindow.impl.NWReflection; - -import java.util.ArrayList; -import java.util.Iterator; -import java.lang.reflect.Method; - -public abstract class Window implements NativeWindow -{ - public static final boolean DEBUG_MOUSE_EVENT = Debug.debug("Window.MouseEvent"); - public static final boolean DEBUG_KEY_EVENT = Debug.debug("Window.KeyEvent"); - public static final boolean DEBUG_WINDOW_EVENT = Debug.debug("Window.WindowEvent"); - public static final boolean DEBUG_IMPLEMENTATION = Debug.debug("Window"); - - // Workaround for initialization order problems on Mac OS X - // between native Newt and (apparently) Fmod -- if Fmod is - // initialized first then the connection to the window server - // breaks, leading to errors from deep within the AppKit - static void init(String type) { - if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { - try { - getWindowClass(type); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - private static Class getWindowClass(String type) - throws ClassNotFoundException - { - Class windowClass = NewtFactory.getCustomClass(type, "Window"); - if(null==windowClass) { - if (NativeWindowFactory.TYPE_EGL.equals(type)) { - windowClass = Class.forName("com.sun.javafx.newt.opengl.kd.KDWindow"); - } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) { - windowClass = Class.forName("com.sun.javafx.newt.windows.WindowsWindow"); - } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { - windowClass = Class.forName("com.sun.javafx.newt.macosx.MacWindow"); - } else if (NativeWindowFactory.TYPE_X11.equals(type)) { - windowClass = Class.forName("com.sun.javafx.newt.x11.X11Window"); - } else if (NativeWindowFactory.TYPE_AWT.equals(type)) { - windowClass = Class.forName("com.sun.javafx.newt.awt.AWTWindow"); - } else { - throw new NativeWindowException("Unknown window type \"" + type + "\""); - } - } - return windowClass; - } - - protected static Window create(String type, final long parentWindowHandle, Screen screen, final Capabilities caps, boolean undecorated) { - try { - Class windowClass; - if(caps.isOnscreen()) { - windowClass = getWindowClass(type); - } else { - windowClass = OffscreenWindow.class; - } - Window window = (Window) windowClass.newInstance(); - window.invalidate(); - window.screen = screen; - window.setUndecorated(undecorated||0!=parentWindowHandle); - EventDispatchThread edt = screen.getDisplay().getEDT(); - if(null!=edt) { - final Window f_win = window; - edt.invokeAndWait(new Runnable() { - public void run() { - f_win.createNative(parentWindowHandle, caps); - } - } ); - } else { - window.createNative(parentWindowHandle, caps); - } - return window; - } catch (Throwable t) { - t.printStackTrace(); - throw new NativeWindowException(t); - } - } - - protected static Window create(String type, Object[] cstrArguments, Screen screen, final Capabilities caps, boolean undecorated) { - try { - Class windowClass = getWindowClass(type); - Class[] cstrArgumentTypes = getCustomConstructorArgumentTypes(windowClass); - if(null==cstrArgumentTypes) { - throw new NativeWindowException("WindowClass "+windowClass+" doesn't support custom arguments in constructor"); - } - int argsChecked = verifyConstructorArgumentTypes(cstrArgumentTypes, cstrArguments); - if ( argsChecked < cstrArguments.length ) { - throw new NativeWindowException("WindowClass "+windowClass+" constructor mismatch at argument #"+argsChecked+"; Constructor: "+getTypeStrList(cstrArgumentTypes)+", arguments: "+getArgsStrList(cstrArguments)); - } - Window window = (Window) NWReflection.createInstance( windowClass, cstrArgumentTypes, cstrArguments ) ; - window.invalidate(); - window.screen = screen; - window.setUndecorated(undecorated); - EventDispatchThread edt = screen.getDisplay().getEDT(); - if(null!=edt) { - final Window f_win = window; - edt.invokeAndWait(new Runnable() { - public void run() { - f_win.createNative(0, caps); - } - } ); - } else { - window.createNative(0, caps); - } - return window; - } catch (Throwable t) { - t.printStackTrace(); - throw new NativeWindowException(t); - } - } - - protected static Window wrapHandle(String type, Screen screen, AbstractGraphicsConfiguration config, - long windowHandle, boolean fullscreen, boolean visible, - int x, int y, int width, int height) - { - try { - Class windowClass = getWindowClass(type); - Window window = (Window) windowClass.newInstance(); - window.invalidate(); - window.screen = screen; - window.config = config; - window.windowHandle = windowHandle; - window.fullscreen=fullscreen; - window.visible=visible; - window.x=x; - window.y=y; - window.width=width; - window.height=height; - return window; - } catch (Throwable t) { - t.printStackTrace(); - throw new NativeWindowException(t); - } - } - - public static String toHexString(int hex) { - return "0x" + Integer.toHexString(hex); - } - - public static String toHexString(long hex) { - return "0x" + Long.toHexString(hex); - } - - protected Screen screen; - - protected AbstractGraphicsConfiguration config; - protected long windowHandle; - protected boolean fullscreen, visible; - protected int width, height, x, y; - protected int eventMask; - - protected String title = "Newt Window"; - protected boolean undecorated = false; - - /** - * Create native windowHandle, ie creates a new native invisible window. - * - * The parentWindowHandle may be null, in which case no window parenting - * is requested. - * - * Shall use the capabilities to determine the graphics configuration - * and shall set the chosen capabilities. - */ - protected abstract void createNative(long parentWindowHandle, Capabilities caps); - - protected abstract void closeNative(); - - public Screen getScreen() { - return screen; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - - sb.append(getClass().getName()+"[config "+config+ - ", windowHandle "+toHexString(getWindowHandle())+ - ", surfaceHandle "+toHexString(getSurfaceHandle())+ - ", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+ - ", visible "+isVisible()+ - ", undecorated "+undecorated+ - ", fullscreen "+fullscreen+ - ", "+screen+ - ", wrappedWindow "+getWrappedWindow()); - - sb.append(", SurfaceUpdatedListeners num "+surfaceUpdatedListeners.size()+" ["); - for (Iterator iter = surfaceUpdatedListeners.iterator(); iter.hasNext(); ) { - sb.append(iter.next()+", "); - } - sb.append("], WindowListeners num "+windowListeners.size()+" ["); - for (Iterator iter = windowListeners.iterator(); iter.hasNext(); ) { - sb.append(iter.next()+", "); - } - sb.append("], MouseListeners num "+mouseListeners.size()+" ["); - for (Iterator iter = mouseListeners.iterator(); iter.hasNext(); ) { - sb.append(iter.next()+", "); - } - sb.append("], KeyListeners num "+keyListeners.size()+" ["); - for (Iterator iter = keyListeners.iterator(); iter.hasNext(); ) { - sb.append(iter.next()+", "); - } - sb.append("] ]"); - return sb.toString(); - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public void setUndecorated(boolean value) { - undecorated = value; - } - - public boolean isUndecorated() { - return undecorated; - } - - public void requestFocus() { - } - - // - // NativeWindow impl - // - private Thread owner; - private int recursionCount; - protected Exception lockedStack = null; - - /** Recursive and blocking lockSurface() implementation */ - public synchronized int lockSurface() { - // We leave the ToolkitLock lock to the specializtion's discretion, - // ie the implicit JAWTWindow in case of AWTWindow - Thread cur = Thread.currentThread(); - if (owner == cur) { - ++recursionCount; - return LOCK_SUCCESS; - } - while (owner != null) { - try { - wait(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - owner = cur; - lockedStack = new Exception("NEWT Surface previously locked by "+Thread.currentThread()); - screen.getDisplay().lockDisplay(); - return LOCK_SUCCESS; - } - - /** Recursive and unblocking unlockSurface() implementation */ - public synchronized void unlockSurface() throws NativeWindowException { - Thread cur = Thread.currentThread(); - if (owner != cur) { - lockedStack.printStackTrace(); - throw new NativeWindowException(cur+": Not owner, owner is "+owner); - } - if (recursionCount > 0) { - --recursionCount; - return; - } - owner = null; - lockedStack = null; - screen.getDisplay().unlockDisplay(); - notifyAll(); - // We leave the ToolkitLock unlock to the specializtion's discretion, - // ie the implicit JAWTWindow in case of AWTWindow - } - - public synchronized boolean isSurfaceLocked() { - return null!=owner; - } - - public synchronized Thread getSurfaceLockOwner() { - return owner; - } - - public synchronized Exception getLockedStack() { - return lockedStack; - } - - public synchronized void destroy() { - destroy(false); - } - - /** @param deep If true, the linked Screen and Display will be destroyed as well. */ - public synchronized void destroy(boolean deep) { - if(DEBUG_WINDOW_EVENT) { - System.out.println("Window.destroy() start (deep "+deep+" - "+Thread.currentThread()); - } - synchronized(surfaceUpdatedListeners) { - surfaceUpdatedListeners = new ArrayList(); - } - synchronized(windowListeners) { - windowListeners = new ArrayList(); - } - synchronized(mouseListeners) { - mouseListeners = new ArrayList(); - } - synchronized(keyListeners) { - keyListeners = new ArrayList(); - } - Screen scr = screen; - Display dpy = (null!=screen) ? screen.getDisplay() : null; - EventDispatchThread edt = (null!=dpy) ? dpy.getEDT() : null; - if(null!=edt) { - final Window f_win = this; - edt.invokeAndWait(new Runnable() { - public void run() { - f_win.closeNative(); - } - } ); - } else { - closeNative(); - } - invalidate(); - if(deep) { - if(null!=scr) { - scr.destroy(); - } - if(null!=dpy) { - dpy.destroy(); - } - } - if(DEBUG_WINDOW_EVENT) { - System.out.println("Window.destroy() end "+Thread.currentThread()); - } - } - - public void invalidate() { - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - Exception e = new Exception("!!! Window Invalidate "+Thread.currentThread()); - e.printStackTrace(); - } - screen = null; - windowHandle = 0; - fullscreen=false; - visible=false; - eventMask = 0; - - // Default position and dimension will be re-set immediately by user - width = 100; - height = 100; - x=0; - y=0; - } - - public boolean surfaceSwap() { - return false; - } - - protected void clearEventMask() { - eventMask=0; - } - - public long getDisplayHandle() { - return screen.getDisplay().getHandle(); - } - - public int getScreenIndex() { - return screen.getIndex(); - } - - public long getWindowHandle() { - return windowHandle; - } - - public long getSurfaceHandle() { - return windowHandle; // default: return window handle - } - - public AbstractGraphicsConfiguration getGraphicsConfiguration() { - return config; - } - - /** - * Returns the width of the client area of this window - * @return width of the client area - */ - public int getWidth() { - return width; - } - - /** - * Returns the height of the client area of this window - * @return height of the client area - */ - public int getHeight() { - return height; - } - - /** - * Returns the insets for this native window (the difference between the - * size of the toplevel window with the decorations and the client area). - * - * @return insets for this platform window - */ - // this probably belongs to NativeWindow interface - public Insets getInsets() { - return new Insets(0,0,0,0); - } - - /** If this Window actually wraps one from another toolkit such as - the AWT, this will return a non-null value. */ - public Object getWrappedWindow() { - return null; - } - - // - // Additional methods - // - - public int getX() { - return x; - } - - public int getY() { - return y; - } - - public boolean isVisible() { - return visible; - } - - public boolean isFullscreen() { - return fullscreen; - } - - private boolean autoDrawableMember = false; - - /** If the implementation is capable of detecting a device change - return true and clear the status/reason of the change. */ - public boolean hasDeviceChanged() { - return false; - } - - /** - * If set to true, - * certain action will be performed by the owning - * AutoDrawable, ie the destroy() call within windowDestroyNotify() - */ - public void setAutoDrawableClient(boolean b) { - autoDrawableMember = b; - } - - protected void windowDestroyNotify() { - if(DEBUG_WINDOW_EVENT) { - System.out.println("Window.windowDestroyeNotify start "+Thread.currentThread()); - } - - sendWindowEvent(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY); - - if(!autoDrawableMember) { - destroy(); - } - - if(DEBUG_WINDOW_EVENT) { - System.out.println("Window.windowDestroyeNotify end "+Thread.currentThread()); - } - } - - protected void windowDestroyed() { - if(DEBUG_WINDOW_EVENT) { - System.out.println("Window.windowDestroyed "+Thread.currentThread()); - } - invalidate(); - } - - public abstract void setVisible(boolean visible); - /** - * Sets the size of the client area of the window, excluding decorations - * Total size of the window will be - * {@code width+insets.left+insets.right, height+insets.top+insets.bottom} - * @param width of the client area of the window - * @param height of the client area of the window - */ - public abstract void setSize(int width, int height); - /** - * Sets the location of the top left corner of the window, including - * decorations (so the client area will be placed at - * {@code x+insets.left,y+insets.top}. - * @param x coord of the top left corner - * @param y coord of the top left corner - */ - public abstract void setPosition(int x, int y); - public abstract boolean setFullscreen(boolean fullscreen); - - // - // SurfaceUpdatedListener Support - // - private ArrayList surfaceUpdatedListeners = new ArrayList(); - - public void addSurfaceUpdatedListener(SurfaceUpdatedListener l) { - if(l == null) { - return; - } - synchronized(surfaceUpdatedListeners) { - ArrayList newSurfaceUpdatedListeners = (ArrayList) surfaceUpdatedListeners.clone(); - newSurfaceUpdatedListeners.add(l); - surfaceUpdatedListeners = newSurfaceUpdatedListeners; - } - } - - public void removeSurfaceUpdatedListener(SurfaceUpdatedListener l) { - if (l == null) { - return; - } - synchronized(surfaceUpdatedListeners) { - ArrayList newSurfaceUpdatedListeners = (ArrayList) surfaceUpdatedListeners.clone(); - newSurfaceUpdatedListeners.remove(l); - surfaceUpdatedListeners = newSurfaceUpdatedListeners; - } - } - - public SurfaceUpdatedListener[] getSurfaceUpdatedListener() { - synchronized(surfaceUpdatedListeners) { - return (SurfaceUpdatedListener[]) surfaceUpdatedListeners.toArray(); - } - } - - public void surfaceUpdated(Object updater, NativeWindow window, long when) { - ArrayList listeners = null; - synchronized(surfaceUpdatedListeners) { - listeners = surfaceUpdatedListeners; - } - for(Iterator i = listeners.iterator(); i.hasNext(); ) { - SurfaceUpdatedListener l = (SurfaceUpdatedListener) i.next(); - l.surfaceUpdated(updater, window, when); - } - } - - // - // MouseListener Support - // - - public void addMouseListener(MouseListener l) { - if(l == null) { - return; - } - synchronized(mouseListeners) { - ArrayList newMouseListeners = (ArrayList) mouseListeners.clone(); - newMouseListeners.add(l); - mouseListeners = newMouseListeners; - } - } - - public void removeMouseListener(MouseListener l) { - if (l == null) { - return; - } - synchronized(mouseListeners) { - ArrayList newMouseListeners = (ArrayList) mouseListeners.clone(); - newMouseListeners.remove(l); - mouseListeners = newMouseListeners; - } - } - - public MouseListener[] getMouseListeners() { - synchronized(mouseListeners) { - return (MouseListener[]) mouseListeners.toArray(); - } - } - - private ArrayList mouseListeners = new ArrayList(); - private int mouseButtonPressed = 0; // current pressed mouse button number - private long lastMousePressed = 0; // last time when a mouse button was pressed - private int lastMouseClickCount = 0; // last mouse button click count - public static final int ClickTimeout = 300; - - protected void sendMouseEvent(int eventType, int modifiers, - int x, int y, int button, int rotation) { - if(x<0||y<0||x>=width||y>=height) { - return; // .. invalid .. - } - if(DEBUG_MOUSE_EVENT) { - System.out.println("sendMouseEvent: "+MouseEvent.getEventTypeString(eventType)+ - ", mod "+modifiers+", pos "+x+"/"+y+", button "+button); - } - if(button<0||button>MouseEvent.BUTTON_NUMBER) { - throw new NativeWindowException("Invalid mouse button number" + button); - } - long when = System.currentTimeMillis(); - MouseEvent eClicked = null; - MouseEvent e = null; - - if(MouseEvent.EVENT_MOUSE_PRESSED==eventType) { - if(when-lastMousePressed0) { - e = new MouseEvent(true, MouseEvent.EVENT_MOUSE_DRAGGED, this, when, - modifiers, x, y, 1, mouseButtonPressed, 0); - } else { - e = new MouseEvent(true, eventType, this, when, - modifiers, x, y, 0, button, 0); - } - } else if(MouseEvent.EVENT_MOUSE_WHEEL_MOVED==eventType) { - e = new MouseEvent(true, eventType, this, when, modifiers, x, y, 0, button, rotation); - } else { - e = new MouseEvent(true, eventType, this, when, modifiers, x, y, 0, button, 0); - } - - if(DEBUG_MOUSE_EVENT) { - System.out.println("sendMouseEvent: event: "+e); - if(null!=eClicked) { - System.out.println("sendMouseEvent: event Clicked: "+eClicked); - } - } - - ArrayList listeners = null; - synchronized(mouseListeners) { - listeners = mouseListeners; - } - for(Iterator i = listeners.iterator(); i.hasNext(); ) { - MouseListener l = (MouseListener) i.next(); - switch(e.getEventType()) { - case MouseEvent.EVENT_MOUSE_CLICKED: - l.mouseClicked(e); - break; - case MouseEvent.EVENT_MOUSE_ENTERED: - l.mouseEntered(e); - break; - case MouseEvent.EVENT_MOUSE_EXITED: - l.mouseExited(e); - break; - case MouseEvent.EVENT_MOUSE_PRESSED: - l.mousePressed(e); - break; - case MouseEvent.EVENT_MOUSE_RELEASED: - l.mouseReleased(e); - if(null!=eClicked) { - l.mouseClicked(eClicked); - } - break; - case MouseEvent.EVENT_MOUSE_MOVED: - l.mouseMoved(e); - break; - case MouseEvent.EVENT_MOUSE_DRAGGED: - l.mouseDragged(e); - break; - case MouseEvent.EVENT_MOUSE_WHEEL_MOVED: - l.mouseWheelMoved(e); - break; - default: - throw new NativeWindowException("Unexpected mouse event type " + e.getEventType()); - } - } - } - - // - // KeyListener Support - // - - public void addKeyListener(KeyListener l) { - if(l == null) { - return; - } - synchronized(keyListeners) { - ArrayList newKeyListeners = (ArrayList) keyListeners.clone(); - newKeyListeners.add(l); - keyListeners = newKeyListeners; - } - } - - public void removeKeyListener(KeyListener l) { - if (l == null) { - return; - } - synchronized(keyListeners) { - ArrayList newKeyListeners = (ArrayList) keyListeners.clone(); - newKeyListeners.remove(l); - keyListeners = newKeyListeners; - } - } - - public KeyListener[] getKeyListeners() { - synchronized(keyListeners) { - return (KeyListener[]) keyListeners.toArray(); - } - } - - private ArrayList keyListeners = new ArrayList(); - - protected void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { - KeyEvent e = new KeyEvent(true, eventType, this, System.currentTimeMillis(), - modifiers, keyCode, keyChar); - if(DEBUG_KEY_EVENT) { - System.out.println("sendKeyEvent: "+e); - } - ArrayList listeners = null; - synchronized(keyListeners) { - listeners = keyListeners; - } - for(Iterator i = listeners.iterator(); i.hasNext(); ) { - KeyListener l = (KeyListener) i.next(); - switch(eventType) { - case KeyEvent.EVENT_KEY_PRESSED: - l.keyPressed(e); - break; - case KeyEvent.EVENT_KEY_RELEASED: - l.keyReleased(e); - break; - case KeyEvent.EVENT_KEY_TYPED: - l.keyTyped(e); - break; - default: - throw new NativeWindowException("Unexpected key event type " + e.getEventType()); - } - } - } - - // - // WindowListener Support - // - - private ArrayList windowListeners = new ArrayList(); - - public void addWindowListener(WindowListener l) { - if(l == null) { - return; - } - synchronized(windowListeners) { - ArrayList newWindowListeners = (ArrayList) windowListeners.clone(); - newWindowListeners.add(l); - windowListeners = newWindowListeners; - } - } - - public void removeWindowListener(WindowListener l) { - if (l == null) { - return; - } - synchronized(windowListeners) { - ArrayList newWindowListeners = (ArrayList) windowListeners.clone(); - newWindowListeners.remove(l); - windowListeners = newWindowListeners; - } - } - - public WindowListener[] getWindowListeners() { - synchronized(windowListeners) { - return (WindowListener[]) windowListeners.toArray(); - } - } - - protected void sendWindowEvent(int eventType) { - WindowEvent e = new WindowEvent(true, eventType, this, System.currentTimeMillis()); - if(DEBUG_WINDOW_EVENT) { - System.out.println("sendWindowEvent: "+e); - } - ArrayList listeners = null; - synchronized(windowListeners) { - listeners = windowListeners; - } - for(Iterator i = listeners.iterator(); i.hasNext(); ) { - WindowListener l = (WindowListener) i.next(); - switch(eventType) { - case WindowEvent.EVENT_WINDOW_RESIZED: - l.windowResized(e); - break; - case WindowEvent.EVENT_WINDOW_MOVED: - l.windowMoved(e); - break; - case WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY: - l.windowDestroyNotify(e); - break; - case WindowEvent.EVENT_WINDOW_GAINED_FOCUS: - l.windowGainedFocus(e); - break; - case WindowEvent.EVENT_WINDOW_LOST_FOCUS: - l.windowLostFocus(e); - break; - default: - throw - new NativeWindowException("Unexpected window event type " - + e.getEventType()); - } - } - } - - - // - // WindowListener Support - // - - private ArrayList paintListeners = new ArrayList(); - - public void addPaintListener(PaintListener l) { - if(l == null) { - return; - } - synchronized(paintListeners) { - ArrayList newPaintListeners = (ArrayList) paintListeners.clone(); - newPaintListeners.add(l); - paintListeners = newPaintListeners; - } - } - - public void removePaintListener(PaintListener l) { - if (l == null) { - return; - } - synchronized(paintListeners) { - ArrayList newPaintListeners = (ArrayList) paintListeners.clone(); - newPaintListeners.remove(l); - paintListeners = newPaintListeners; - } - } - - protected void sendPaintEvent(int eventType, int x, int y, int w, int h) { - PaintEvent e = - new PaintEvent(eventType, this, System.currentTimeMillis(), x, y, w, h); - ArrayList listeners = null; - synchronized(paintListeners) { - listeners = paintListeners; - } - for(Iterator i = listeners.iterator(); i.hasNext(); ) { - PaintListener l = (PaintListener) i.next(); - l.exposed(e); - } - } - - // - // Reflection helper .. - // - - private static Class[] getCustomConstructorArgumentTypes(Class windowClass) { - Class[] argTypes = null; - try { - Method m = windowClass.getDeclaredMethod("getCustomConstructorArgumentTypes", new Class[] {}); - argTypes = (Class[]) m.invoke(null, null); - } catch (Throwable t) {} - return argTypes; - } - - private static int verifyConstructorArgumentTypes(Class[] types, Object[] args) { - if(types.length != args.length) { - return -1; - } - for(int i=0; i*/ events = new LinkedList(); - - static class AWTEventWrapper { - AWTWindow window; - int type; - InputEvent e; - - AWTEventWrapper(AWTWindow w, int type, InputEvent e) { - this.window = w; - this.type = type; - this.e = e; - } - - public AWTWindow getWindow() { - return window; - } - - public int getType() { - return type; - } - - public InputEvent getEvent() { - return e; - } - } - - private static int convertModifiers(InputEvent e) { - int newtMods = 0; - int mods = e.getModifiers(); - if ((mods & InputEvent.SHIFT_MASK) != 0) newtMods |= com.sun.javafx.newt.InputEvent.SHIFT_MASK; - if ((mods & InputEvent.CTRL_MASK) != 0) newtMods |= com.sun.javafx.newt.InputEvent.CTRL_MASK; - if ((mods & InputEvent.META_MASK) != 0) newtMods |= com.sun.javafx.newt.InputEvent.META_MASK; - if ((mods & InputEvent.ALT_MASK) != 0) newtMods |= com.sun.javafx.newt.InputEvent.ALT_MASK; - if ((mods & InputEvent.ALT_GRAPH_MASK) != 0) newtMods |= com.sun.javafx.newt.InputEvent.ALT_GRAPH_MASK; - return newtMods; - } - - private static int convertButton(MouseEvent e) { - switch (e.getButton()) { - case MouseEvent.BUTTON1: return com.sun.javafx.newt.MouseEvent.BUTTON1; - case MouseEvent.BUTTON2: return com.sun.javafx.newt.MouseEvent.BUTTON2; - case MouseEvent.BUTTON3: return com.sun.javafx.newt.MouseEvent.BUTTON3; - } - return 0; - } - -} diff --git a/src/newt/classes/com/sun/javafx/newt/awt/AWTScreen.java b/src/newt/classes/com/sun/javafx/newt/awt/AWTScreen.java deleted file mode 100644 index 9bda5893b..000000000 --- a/src/newt/classes/com/sun/javafx/newt/awt/AWTScreen.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.awt; - -import com.sun.javafx.newt.*; -import java.awt.DisplayMode; -import javax.media.nativewindow.*; -import javax.media.nativewindow.awt.*; - -public class AWTScreen extends Screen { - public AWTScreen() { - } - - protected void createNative(int index) { - aScreen = new AWTGraphicsScreen((AWTGraphicsDevice)display.getGraphicsDevice()); - - DisplayMode mode = ((AWTGraphicsDevice)getDisplay().getGraphicsDevice()).getGraphicsDevice().getDisplayMode(); - int w = mode.getWidth(); - int h = mode.getHeight(); - setScreenSize(w, h); - } - - protected void setAWTGraphicsScreen(AWTGraphicsScreen s) { - aScreen = s; - } - - // done by AWTWindow .. - protected void setScreenSize(int w, int h) { - super.setScreenSize(w, h); - } - - protected void closeNative() { } - -} diff --git a/src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java b/src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java deleted file mode 100644 index 9725cf08b..000000000 --- a/src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java +++ /dev/null @@ -1,429 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.awt; - -import java.awt.BorderLayout; -import java.awt.Canvas; -import java.awt.Container; -import java.awt.DisplayMode; -import java.awt.EventQueue; -import java.awt.Frame; -import java.awt.GraphicsDevice; -import java.awt.GraphicsEnvironment; -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; -import java.awt.event.*; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.*; -import com.sun.javafx.newt.Window; -import java.awt.Insets; -import javax.media.nativewindow.*; -import javax.media.nativewindow.awt.*; - -/** An implementation of the Newt Window class built using the - AWT. This is provided for convenience of porting to platforms - supporting Java SE. */ - -public class AWTWindow extends Window { - - public AWTWindow() { - this(null); - } - - public static Class[] getCustomConstructorArgumentTypes() { - return new Class[] { Container.class } ; - } - - public AWTWindow(Container container) { - super(); - title = "AWT NewtWindow"; - this.container = container; - if(container instanceof Frame) { - frame = (Frame) container; - } - } - - private boolean owningFrame; - private Container container = null; - private Frame frame = null; // same instance as container, just for impl. convenience - private AWTCanvas canvas; - // non fullscreen dimensions .. - private int nfs_width, nfs_height, nfs_x, nfs_y; - - public void setTitle(final String title) { - super.setTitle(title); - runOnEDT(true, new Runnable() { - public void run() { - if (frame != null) { - frame.setTitle(title); - } - } - }); - } - - protected void createNative(long parentWindowHandle, final Capabilities caps) { - - if(0!=parentWindowHandle) { - throw new RuntimeException("Window parenting not supported in AWT, use AWTWindow(Frame) cstr for wrapping instead"); - } - - final AWTWindow awtWindow = this; - - 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(caps); - Listener listener = new Listener(awtWindow); - canvas.addMouseListener(listener); - canvas.addMouseMotionListener(listener); - canvas.addKeyListener(listener); - canvas.addComponentListener(listener); - container.add(canvas, BorderLayout.CENTER); - container.setSize(width, height); - container.setLocation(x, y); - container.addComponentListener(new MoveListener(awtWindow)); - if(null!=frame) { - frame.setUndecorated(undecorated||fullscreen); - frame.addWindowListener(new WindowEventListener(awtWindow)); - } - } - }); - } - - protected void closeNative() { - runOnEDT(true, new Runnable() { - public void run() { - if(owningFrame && null!=frame) { - frame.dispose(); - owningFrame=false; - } - frame = null; - } - }); - } - - public boolean hasDeviceChanged() { - boolean res = canvas.hasDeviceChanged(); - if(res) { - config = canvas.getAWTGraphicsConfiguration(); - if (config == null) { - throw new NativeWindowException("Error Device change null GraphicsConfiguration: "+this); - } - updateDeviceData(); - } - return res; - } - - public void setVisible(final boolean visible) { - runOnEDT(true, new Runnable() { - public void run() { - container.setVisible(visible); - } - }); - - config = canvas.getAWTGraphicsConfiguration(); - - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - - updateDeviceData(); - } - - private void updateDeviceData() { - // propagate new info .. - ((AWTScreen)getScreen()).setAWTGraphicsScreen((AWTGraphicsScreen)config.getScreen()); - ((AWTDisplay)getScreen().getDisplay()).setAWTGraphicsDevice((AWTGraphicsDevice)config.getScreen().getDevice()); - - DisplayMode mode = ((AWTGraphicsDevice)config.getScreen().getDevice()).getGraphicsDevice().getDisplayMode(); - int w = mode.getWidth(); - int h = mode.getHeight(); - ((AWTScreen)screen).setScreenSize(w, h); - } - - public void setSize(final int width, final int height) { - this.width = width; - this.height = height; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - /** An AWT event on setSize() would bring us in a deadlock situation, hence invokeLater() */ - runOnEDT(false, new Runnable() { - public void run() { - Insets insets = container.getInsets(); - container.setSize(width + insets.left + insets.right, - height + insets.top + insets.bottom); - } - }); - } - - public com.sun.javafx.newt.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; - } - }); - return new com.sun.javafx.newt. - Insets(insets[0],insets[1],insets[2],insets[3]); - } - - public void setPosition(final int x, final int y) { - this.x = x; - this.y = y; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - runOnEDT(true, new Runnable() { - public void run() { - container.setLocation(x, y); - } - }); - } - - public boolean setFullscreen(final boolean fullscreen) { - if(this.fullscreen!=fullscreen) { - final int x,y,w,h; - this.fullscreen=fullscreen; - if(fullscreen) { - x = 0; y = 0; - w = screen.getWidth(); - h = screen.getHeight(); - } else { - x = nfs_x; - y = nfs_y; - w = nfs_width; - h = nfs_height; - } - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("AWTWindow fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); - } - /** An AWT event on setSize() would bring us in a deadlock situation, hence invokeLater() */ - runOnEDT(false, new Runnable() { - public void run() { - if(null!=frame) { - if(!container.isDisplayable()) { - frame.setUndecorated(undecorated||fullscreen); - } else { - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("AWTWindow can't undecorate already created frame"); - } - } - } - container.setLocation(x, y); - container.setSize(w, h); - } - }); - } - return true; - } - - public Object getWrappedWindow() { - return canvas; - } - - protected void sendWindowEvent(int eventType) { - super.sendWindowEvent(eventType); - } - - protected void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { - super.sendKeyEvent(eventType, modifiers, keyCode, keyChar); - } - - protected void sendMouseEvent(int eventType, int modifiers, - int x, int y, int button, int rotation) { - super.sendMouseEvent(eventType, modifiers, x, y, button, rotation); - } - - private static void runOnEDT(boolean wait, Runnable r) { - if (EventQueue.isDispatchThread()) { - r.run(); - } else { - try { - if(wait) { - EventQueue.invokeAndWait(r); - } else { - EventQueue.invokeLater(r); - } - } catch (Exception e) { - throw new NativeWindowException(e); - } - } - } - - private static final int WINDOW_EVENT = 1; - private static final int KEY_EVENT = 2; - private static final int MOUSE_EVENT = 3; - - class MoveListener implements ComponentListener { - private AWTWindow window; - private AWTDisplay display; - - public MoveListener(AWTWindow w) { - window = w; - display = (AWTDisplay)window.getScreen().getDisplay(); - } - - public void componentResized(ComponentEvent e) { - } - - public void componentMoved(ComponentEvent e) { - if(null!=container) { - x = container.getX(); - y = container.getY(); - } - display.enqueueEvent(window, com.sun.javafx.newt.WindowEvent.EVENT_WINDOW_MOVED, null); - } - - public void componentShown(ComponentEvent e) { - } - - public void componentHidden(ComponentEvent e) { - } - - } - - class Listener implements ComponentListener, MouseListener, MouseMotionListener, KeyListener { - private AWTWindow window; - private AWTDisplay display; - - public Listener(AWTWindow w) { - window = w; - display = (AWTDisplay)window.getScreen().getDisplay(); - } - - public void componentResized(ComponentEvent e) { - width = canvas.getWidth(); - height = canvas.getHeight(); - display.enqueueEvent(window, com.sun.javafx.newt.WindowEvent.EVENT_WINDOW_RESIZED, null); - } - - public void componentMoved(ComponentEvent e) { - } - - public void componentShown(ComponentEvent e) { - } - - public void componentHidden(ComponentEvent e) { - } - - public void mouseClicked(MouseEvent e) { - // We ignore these as we synthesize them ourselves out of - // mouse pressed and released events - } - - public void mouseEntered(MouseEvent e) { - display.enqueueEvent(window, com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_ENTERED, e); - } - - public void mouseExited(MouseEvent e) { - display.enqueueEvent(window, com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_EXITED, e); - } - - public void mousePressed(MouseEvent e) { - display.enqueueEvent(window, com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_PRESSED, e); - } - - public void mouseReleased(MouseEvent e) { - display.enqueueEvent(window, com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_RELEASED, e); - } - - public void mouseMoved(MouseEvent e) { - display.enqueueEvent(window, com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_MOVED, e); - } - - public void mouseDragged(MouseEvent e) { - display.enqueueEvent(window, com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_DRAGGED, e); - } - - public void keyPressed(KeyEvent e) { - display.enqueueEvent(window, com.sun.javafx.newt.KeyEvent.EVENT_KEY_PRESSED, e); - } - - public void keyReleased(KeyEvent e) { - display.enqueueEvent(window, com.sun.javafx.newt.KeyEvent.EVENT_KEY_RELEASED, e); - } - - public void keyTyped(KeyEvent e) { - display.enqueueEvent(window, com.sun.javafx.newt.KeyEvent.EVENT_KEY_TYPED, e); - } - } - - class WindowEventListener implements WindowListener { - private AWTWindow window; - private AWTDisplay display; - - public WindowEventListener(AWTWindow w) { - window = w; - display = (AWTDisplay)window.getScreen().getDisplay(); - } - - public void windowActivated(WindowEvent e) { - } - public void windowClosed(WindowEvent e) { - } - public void windowClosing(WindowEvent e) { - display.enqueueEvent(window, com.sun.javafx.newt.WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY, null); - } - public void windowDeactivated(WindowEvent e) { - } - public void windowDeiconified(WindowEvent e) { - } - public void windowIconified(WindowEvent e) { - } - public void windowOpened(WindowEvent e) { - } - } -} diff --git a/src/newt/classes/com/sun/javafx/newt/impl/Debug.java b/src/newt/classes/com/sun/javafx/newt/impl/Debug.java deleted file mode 100644 index 202d9d5b3..000000000 --- a/src/newt/classes/com/sun/javafx/newt/impl/Debug.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) 2003-2005 Sun Microsystems, Inc. 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. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.sun.javafx.newt.impl; - -import java.security.*; - -/** Helper routines for logging and debugging. */ - -public class Debug { - // Some common properties - private static boolean verbose; - private static boolean debugAll; - private static AccessControlContext localACC; - - static { - localACC=AccessController.getContext(); - verbose = isPropertyDefined("newt.verbose", true); - debugAll = isPropertyDefined("newt.debug", true); - if (verbose) { - Package p = Package.getPackage("com.sun.javafx.newt"); - System.err.println("NEWT specification version " + p.getSpecificationVersion()); - System.err.println("NEWT implementation version " + p.getImplementationVersion()); - System.err.println("NEWT implementation vendor " + p.getImplementationVendor()); - } - } - - static int getIntProperty(final String property, final boolean jnlpAlias) { - return getIntProperty(property, jnlpAlias, localACC); - } - - public static int getIntProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { - int i=0; - try { - Integer iv = Integer.valueOf(Debug.getProperty(property, jnlpAlias, acc)); - i = iv.intValue(); - } catch (NumberFormatException nfe) {} - return i; - } - - static boolean getBooleanProperty(final String property, final boolean jnlpAlias) { - return getBooleanProperty(property, jnlpAlias, localACC); - } - - public static boolean getBooleanProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { - Boolean b = Boolean.valueOf(Debug.getProperty(property, jnlpAlias, acc)); - return b.booleanValue(); - } - - static boolean isPropertyDefined(final String property, final boolean jnlpAlias) { - return isPropertyDefined(property, jnlpAlias, localACC); - } - - public static boolean isPropertyDefined(final String property, final boolean jnlpAlias, final AccessControlContext acc) { - return (Debug.getProperty(property, jnlpAlias, acc) != null) ? true : false; - } - - static String getProperty(final String property, final boolean jnlpAlias) { - return getProperty(property, jnlpAlias, localACC); - } - - public static String getProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { - String s=null; - if(null!=acc && acc.equals(localACC)) { - s = (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - String val=null; - try { - val = System.getProperty(property); - } catch (Exception e) {} - if(null==val && jnlpAlias && !property.startsWith(jnlp_prefix)) { - try { - val = System.getProperty(jnlp_prefix + property); - } catch (Exception e) {} - } - return val; - } - }); - } else { - try { - s = System.getProperty(property); - } catch (Exception e) {} - if(null==s && jnlpAlias && !property.startsWith(jnlp_prefix)) { - try { - s = System.getProperty(jnlp_prefix + property); - } catch (Exception e) {} - } - } - return s; - } - public static final String jnlp_prefix = "jnlp." ; - - public static boolean verbose() { - return verbose; - } - - public static boolean debugAll() { - return debugAll; - } - - public static boolean debug(String subcomponent) { - return debugAll() || isPropertyDefined("newt.debug." + subcomponent, true); - } -} diff --git a/src/newt/classes/com/sun/javafx/newt/impl/NativeLibLoader.java b/src/newt/classes/com/sun/javafx/newt/impl/NativeLibLoader.java deleted file mode 100644 index d96c56f6e..000000000 --- a/src/newt/classes/com/sun/javafx/newt/impl/NativeLibLoader.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. 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. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.sun.javafx.newt.impl; - -// FIXME: refactor Java SE dependencies -//import java.awt.Toolkit; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.HashSet; -import com.sun.nativewindow.impl.NativeLibLoaderBase; - -public class NativeLibLoader extends NativeLibLoaderBase { - - public static void loadNEWT() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - loadLibrary("newt", null, true); - return null; - } - }); - } - -} diff --git a/src/newt/classes/com/sun/javafx/newt/intel/gdl/Display.java b/src/newt/classes/com/sun/javafx/newt/intel/gdl/Display.java deleted file mode 100644 index b1f0ac6d2..000000000 --- a/src/newt/classes/com/sun/javafx/newt/intel/gdl/Display.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.intel.gdl; - -import com.sun.javafx.newt.impl.*; -import javax.media.nativewindow.*; - -public class Display extends com.sun.javafx.newt.Display { - static int initCounter = 0; - - static { - NativeLibLoader.loadNEWT(); - - if (!Screen.initIDs()) { - throw new NativeWindowException("Failed to initialize GDL Screen jmethodIDs"); - } - if (!Window.initIDs()) { - throw new NativeWindowException("Failed to initialize GDL Window jmethodIDs"); - } - } - - public static void initSingleton() { - // just exist to ensure static init has been run - } - - - public Display() { - } - - protected void createNative() { - synchronized(Display.class) { - if(0==initCounter) { - displayHandle = CreateDisplay(); - if(0==displayHandle) { - throw new NativeWindowException("Couldn't initialize GDL Display"); - } - } - initCounter++; - } - aDevice = new DefaultGraphicsDevice(NativeWindowFactory.TYPE_DEFAULT, displayHandle); - } - - protected void closeNative() { - if(0==displayHandle) { - throw new NativeWindowException("displayHandle null; initCnt "+initCounter); - } - synchronized(Display.class) { - if(initCounter>0) { - initCounter--; - if(0==initCounter) { - DestroyDisplay(displayHandle); - } - } - } - } - - protected void dispatchMessages() { - if(0!=displayHandle) { - DispatchMessages(displayHandle, focusedWindow); - } - } - - protected void setFocus(Window focus) { - focusedWindow = focus; - } - - private long displayHandle = 0; - private Window focusedWindow = null; - private native long CreateDisplay(); - private native void DestroyDisplay(long displayHandle); - private native void DispatchMessages(long displayHandle, Window focusedWindow); -} - diff --git a/src/newt/classes/com/sun/javafx/newt/intel/gdl/Screen.java b/src/newt/classes/com/sun/javafx/newt/intel/gdl/Screen.java deleted file mode 100644 index 83d9074e2..000000000 --- a/src/newt/classes/com/sun/javafx/newt/intel/gdl/Screen.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.intel.gdl; - -import com.sun.javafx.newt.impl.*; -import javax.media.nativewindow.*; - -public class Screen extends com.sun.javafx.newt.Screen { - - static { - Display.initSingleton(); - } - - public Screen() { - } - - protected void createNative(int index) { - AbstractGraphicsDevice adevice = getDisplay().getGraphicsDevice(); - GetScreenInfo(adevice.getHandle(), index); - aScreen = new DefaultGraphicsScreen(adevice, index); - } - - protected void closeNative() { } - - //---------------------------------------------------------------------- - // Internals only - // - - protected static native boolean initIDs(); - private native void GetScreenInfo(long displayHandle, int screen_idx); - - // called by GetScreenInfo() .. - private void screenCreated(int width, int height) { - setScreenSize(width, height); - } -} - diff --git a/src/newt/classes/com/sun/javafx/newt/intel/gdl/Window.java b/src/newt/classes/com/sun/javafx/newt/intel/gdl/Window.java deleted file mode 100644 index 0332f442a..000000000 --- a/src/newt/classes/com/sun/javafx/newt/intel/gdl/Window.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.intel.gdl; - -import javax.media.nativewindow.*; - -public class Window extends com.sun.javafx.newt.Window { - static { - Display.initSingleton(); - } - - public Window() { - } - - static long nextWindowHandle = 1; - - protected void createNative(long parentWindowHandle, Capabilities caps) { - if(0!=parentWindowHandle) { - throw new NativeWindowException("GDL Window does not support window parenting"); - } - AbstractGraphicsScreen aScreen = screen.getGraphicsScreen(); - AbstractGraphicsDevice aDevice = screen.getDisplay().getGraphicsDevice(); - - config = GraphicsConfigurationFactory.getFactory(aDevice).chooseGraphicsConfiguration(caps, null, aScreen); - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - - synchronized(Window.class) { - windowHandle = nextWindowHandle++; - } - } - - protected void closeNative() { - if(0!=surfaceHandle) { - synchronized(Window.class) { - CloseSurface(getDisplayHandle(), surfaceHandle); - } - surfaceHandle = 0; - ((Display)screen.getDisplay()).setFocus(null); - } - } - - public void setVisible(boolean visible) { - if(this.visible!=visible) { - this.visible=visible; - if(visible && 0==surfaceHandle) { - synchronized(Window.class) { - AbstractGraphicsDevice aDevice = screen.getDisplay().getGraphicsDevice(); - surfaceHandle = CreateSurface(aDevice.getHandle(), screen.getWidth(), screen.getHeight(), x, y, width, height); - } - if (surfaceHandle == 0) { - throw new NativeWindowException("Error creating window"); - } - ((Display)screen.getDisplay()).setFocus(this); - } - } - } - - public void setSize(int width, int height) { - Screen screen = (Screen) getScreen(); - if((x+width)>screen.getWidth()) { - width=screen.getWidth()-x; - } - if((y+height)>screen.getHeight()) { - height=screen.getHeight()-y; - } - this.width = width; - this.height = height; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - if(0!=surfaceHandle) { - SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, width, height); - } - } - - public void setPosition(int x, int y) { - Screen screen = (Screen) getScreen(); - if((x+width)>screen.getWidth()) { - x=screen.getWidth()-width; - } - if((y+height)>screen.getHeight()) { - y=screen.getHeight()-height; - } - this.x = x; - this.y = y; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - if(0!=surfaceHandle) { - SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, width, height); - } - } - - public boolean setFullscreen(boolean fullscreen) { - if(this.fullscreen!=fullscreen) { - int x,y,w,h; - this.fullscreen=fullscreen; - if(fullscreen) { - x = 0; y = 0; - w = screen.getWidth(); - h = screen.getHeight(); - } else { - x = nfs_x; - y = nfs_y; - w = nfs_width; - h = nfs_height; - } - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("IntelGDL Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); - } - if(0!=surfaceHandle) { - SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, w, h); - } - } - return fullscreen; - } - - public void requestFocus() { - ((Display)screen.getDisplay()).setFocus(this); - } - - public long getSurfaceHandle() { - return surfaceHandle; - } - - //---------------------------------------------------------------------- - // Internals only - // - - protected static native boolean initIDs(); - private native long CreateSurface(long displayHandle, int scrn_width, int scrn_height, int x, int y, int width, int height); - private native void CloseSurface(long displayHandle, long surfaceHandle); - private native void SetBounds0(long surfaceHandle, int scrn_width, int scrn_height, int x, int y, int width, int height); - - private void updateBounds(int x, int y, int width, int height) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - - private long surfaceHandle; - private int nfs_width, nfs_height, nfs_x, nfs_y; -} diff --git a/src/newt/classes/com/sun/javafx/newt/macosx/MacDisplay.java b/src/newt/classes/com/sun/javafx/newt/macosx/MacDisplay.java deleted file mode 100755 index cd22b2b36..000000000 --- a/src/newt/classes/com/sun/javafx/newt/macosx/MacDisplay.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.macosx; - -import javax.media.nativewindow.*; -import javax.media.nativewindow.macosx.*; -import com.sun.javafx.newt.*; -import com.sun.javafx.newt.impl.*; -import com.sun.javafx.newt.util.MainThread; - -public class MacDisplay extends Display { - static { - NativeLibLoader.loadNEWT(); - - if(!initNSApplication()) { - throw new NativeWindowException("Failed to initialize native Application hook"); - } - if(!MacWindow.initIDs()) { - throw new NativeWindowException("Failed to initialize jmethodIDs"); - } - if(DEBUG) System.out.println("MacDisplay.init App and IDs OK "+Thread.currentThread().getName()); - } - - public static void initSingleton() { - // just exist to ensure static init has been run - } - - public MacDisplay() { - } - - class DispatchAction implements Runnable { - public void run() { - dispatchMessages0(); - } - } - private DispatchAction dispatchAction = new DispatchAction(); - - public void dispatchMessages() { - MainThread.invoke(false, dispatchAction); - } - - protected void createNative() { - aDevice = new MacOSXGraphicsDevice(); - } - - protected void closeNative() { } - - private static native boolean initNSApplication(); - protected native void dispatchMessages0(); -} - diff --git a/src/newt/classes/com/sun/javafx/newt/macosx/MacScreen.java b/src/newt/classes/com/sun/javafx/newt/macosx/MacScreen.java deleted file mode 100755 index 8983b8803..000000000 --- a/src/newt/classes/com/sun/javafx/newt/macosx/MacScreen.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.macosx; - -import com.sun.javafx.newt.*; -import javax.media.nativewindow.*; - -public class MacScreen extends Screen { - static { - MacDisplay.initSingleton(); - } - - public MacScreen() { - } - - protected void createNative(int index) { - aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); - setScreenSize(getWidthImpl(getIndex()), getHeightImpl(getIndex())); - } - - protected void closeNative() { } - - private static native int getWidthImpl(int scrn_idx); - private static native int getHeightImpl(int scrn_idx); -} diff --git a/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java b/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java deleted file mode 100755 index 9f501ac9b..000000000 --- a/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java +++ /dev/null @@ -1,600 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.macosx; - -import javax.media.nativewindow.*; - -import com.sun.javafx.newt.util.MainThread; -import com.sun.javafx.newt.*; -import com.sun.javafx.newt.impl.*; - -public class MacWindow extends Window { - - // Window styles - private static final int NSBorderlessWindowMask = 0; - private static final int NSTitledWindowMask = 1 << 0; - private static final int NSClosableWindowMask = 1 << 1; - private static final int NSMiniaturizableWindowMask = 1 << 2; - private static final int NSResizableWindowMask = 1 << 3; - - // Window backing store types - private static final int NSBackingStoreRetained = 0; - private static final int NSBackingStoreNonretained = 1; - private static final int NSBackingStoreBuffered = 2; - - // Key constants handled differently on Mac OS X than other platforms - private static final int NSUpArrowFunctionKey = 0xF700; - private static final int NSDownArrowFunctionKey = 0xF701; - private static final int NSLeftArrowFunctionKey = 0xF702; - private static final int NSRightArrowFunctionKey = 0xF703; - private static final int NSF1FunctionKey = 0xF704; - private static final int NSF2FunctionKey = 0xF705; - private static final int NSF3FunctionKey = 0xF706; - private static final int NSF4FunctionKey = 0xF707; - private static final int NSF5FunctionKey = 0xF708; - private static final int NSF6FunctionKey = 0xF709; - private static final int NSF7FunctionKey = 0xF70A; - private static final int NSF8FunctionKey = 0xF70B; - private static final int NSF9FunctionKey = 0xF70C; - private static final int NSF10FunctionKey = 0xF70D; - private static final int NSF11FunctionKey = 0xF70E; - private static final int NSF12FunctionKey = 0xF70F; - private static final int NSF13FunctionKey = 0xF710; - private static final int NSF14FunctionKey = 0xF711; - private static final int NSF15FunctionKey = 0xF712; - private static final int NSF16FunctionKey = 0xF713; - private static final int NSF17FunctionKey = 0xF714; - private static final int NSF18FunctionKey = 0xF715; - private static final int NSF19FunctionKey = 0xF716; - private static final int NSF20FunctionKey = 0xF717; - private static final int NSF21FunctionKey = 0xF718; - private static final int NSF22FunctionKey = 0xF719; - private static final int NSF23FunctionKey = 0xF71A; - private static final int NSF24FunctionKey = 0xF71B; - private static final int NSF25FunctionKey = 0xF71C; - private static final int NSF26FunctionKey = 0xF71D; - private static final int NSF27FunctionKey = 0xF71E; - private static final int NSF28FunctionKey = 0xF71F; - private static final int NSF29FunctionKey = 0xF720; - private static final int NSF30FunctionKey = 0xF721; - private static final int NSF31FunctionKey = 0xF722; - private static final int NSF32FunctionKey = 0xF723; - private static final int NSF33FunctionKey = 0xF724; - private static final int NSF34FunctionKey = 0xF725; - private static final int NSF35FunctionKey = 0xF726; - private static final int NSInsertFunctionKey = 0xF727; - private static final int NSDeleteFunctionKey = 0xF728; - private static final int NSHomeFunctionKey = 0xF729; - private static final int NSBeginFunctionKey = 0xF72A; - private static final int NSEndFunctionKey = 0xF72B; - private static final int NSPageUpFunctionKey = 0xF72C; - private static final int NSPageDownFunctionKey = 0xF72D; - private static final int NSPrintScreenFunctionKey = 0xF72E; - private static final int NSScrollLockFunctionKey = 0xF72F; - private static final int NSPauseFunctionKey = 0xF730; - private static final int NSSysReqFunctionKey = 0xF731; - private static final int NSBreakFunctionKey = 0xF732; - private static final int NSResetFunctionKey = 0xF733; - private static final int NSStopFunctionKey = 0xF734; - private static final int NSMenuFunctionKey = 0xF735; - private static final int NSUserFunctionKey = 0xF736; - private static final int NSSystemFunctionKey = 0xF737; - private static final int NSPrintFunctionKey = 0xF738; - private static final int NSClearLineFunctionKey = 0xF739; - private static final int NSClearDisplayFunctionKey = 0xF73A; - private static final int NSInsertLineFunctionKey = 0xF73B; - private static final int NSDeleteLineFunctionKey = 0xF73C; - private static final int NSInsertCharFunctionKey = 0xF73D; - private static final int NSDeleteCharFunctionKey = 0xF73E; - private static final int NSPrevFunctionKey = 0xF73F; - private static final int NSNextFunctionKey = 0xF740; - private static final int NSSelectFunctionKey = 0xF741; - private static final int NSExecuteFunctionKey = 0xF742; - private static final int NSUndoFunctionKey = 0xF743; - private static final int NSRedoFunctionKey = 0xF744; - private static final int NSFindFunctionKey = 0xF745; - private static final int NSHelpFunctionKey = 0xF746; - private static final int NSModeSwitchFunctionKey = 0xF747; - - private volatile long surfaceHandle; - private long parentWindowHandle; - - // non fullscreen dimensions .. - private int nfs_width, nfs_height, nfs_x, nfs_y; - private final Insets insets = new Insets(0,0,0,0); - - static { - MacDisplay.initSingleton(); - } - - public MacWindow() { - } - - protected void createNative(long parentWindowHandle, Capabilities caps) { - this.parentWindowHandle=parentWindowHandle; - config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - } - - class CloseAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.CloseAction "+Thread.currentThread().getName()); - if (windowHandle != 0) { - close0(windowHandle); - windowHandle = 0; - } - } finally { - nsViewLock.unlock(); - } - } - } - private CloseAction closeAction = new CloseAction(); - - protected void closeNative() { - MainThread.invoke(true, closeAction); - } - - public long getWindowHandle() { - nsViewLock.lock(); - try { - return windowHandle; - } finally { - nsViewLock.unlock(); - } - } - - public long getSurfaceHandle() { - nsViewLock.lock(); - try { - return surfaceHandle; - } finally { - nsViewLock.unlock(); - } - } - - class EnsureWindowCreatedAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - createWindow(parentWindowHandle, false); - } finally { - nsViewLock.unlock(); - } - } - } - private EnsureWindowCreatedAction ensureWindowCreatedAction = - new EnsureWindowCreatedAction(); - - public Insets getInsets() { - // in order to properly calculate insets we need the window to be - // created - MainThread.invoke(true, ensureWindowCreatedAction); - nsViewLock.lock(); - try { - return (Insets) insets.clone(); - } finally { - nsViewLock.unlock(); - } - } - - private ToolkitLock nsViewLock = new ToolkitLock() { - private Thread owner; - private int recursionCount; - - public synchronized void lock() { - Thread cur = Thread.currentThread(); - if (owner == cur) { - ++recursionCount; - return; - } - while (owner != null) { - try { - wait(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - owner = cur; - } - - public synchronized void unlock() { - if (owner != Thread.currentThread()) { - throw new RuntimeException("Not owner"); - } - if (recursionCount > 0) { - --recursionCount; - return; - } - owner = null; - notifyAll(); - } - }; - - public synchronized int lockSurface() throws NativeWindowException { - nsViewLock.lock(); - return super.lockSurface(); - } - - public void unlockSurface() { - super.unlockSurface(); - nsViewLock.unlock(); - } - - class VisibleAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.VisibleAction "+visible+" "+Thread.currentThread().getName()); - if (visible) { - createWindow(parentWindowHandle, false); - if (windowHandle != 0) { - makeKeyAndOrderFront(windowHandle); - } - } else { - if (windowHandle != 0) { - orderOut(windowHandle); - } - } - } finally { - nsViewLock.unlock(); - } - } - } - private VisibleAction visibleAction = new VisibleAction(); - - public void setVisible(boolean visible) { - this.visible = visible; - MainThread.invoke(true, visibleAction); - } - - class TitleAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if (windowHandle != 0) { - setTitle0(windowHandle, title); - } - } finally { - nsViewLock.unlock(); - } - } - } - private TitleAction titleAction = new TitleAction(); - - public void setTitle(String title) { - super.setTitle(title); - MainThread.invoke(true, titleAction); - } - - class FocusAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if (windowHandle != 0) { - makeKey(windowHandle); - } - } finally { - nsViewLock.unlock(); - } - } - } - private FocusAction focusAction = new FocusAction(); - - public void requestFocus() { - super.requestFocus(); - MainThread.invoke(true, focusAction); - } - - class SizeAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if (windowHandle != 0) { - setContentSize(windowHandle, width, height); - } - } finally { - nsViewLock.unlock(); - } - } - } - private SizeAction sizeAction = new SizeAction(); - - public void setSize(int width, int height) { - this.width=width; - this.height=height; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - MainThread.invoke(true, sizeAction); - } - - class PositionAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if (windowHandle != 0) { - setFrameTopLeftPoint(parentWindowHandle, windowHandle, x, y); - } - } finally { - nsViewLock.unlock(); - } - } - } - private PositionAction positionAction = new PositionAction(); - - public void setPosition(int x, int y) { - this.x=x; - this.y=y; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - MainThread.invoke(true, positionAction); - } - - class FullscreenAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("MacWindow fs: "+fullscreen+" "+x+"/"+y+" "+width+"x"+height); - } - createWindow(parentWindowHandle, true); - if (windowHandle != 0) { - makeKeyAndOrderFront(windowHandle); - } - } finally { - nsViewLock.unlock(); - } - } - } - private FullscreenAction fullscreenAction = new FullscreenAction(); - - public boolean setFullscreen(boolean fullscreen) { - if(this.fullscreen!=fullscreen) { - this.fullscreen=fullscreen; - if(fullscreen) { - x = 0; - y = 0; - width = screen.getWidth(); - height = screen.getHeight(); - } else { - x = nfs_x; - y = nfs_y; - width = nfs_width; - height = nfs_height; - } - MainThread.invoke(true, fullscreenAction); - } - return fullscreen; - } - - private void sizeChanged(int newWidth, int newHeight) { - if (DEBUG_IMPLEMENTATION) { - System.out.println(Thread.currentThread().getName()+" Size changed to " + newWidth + ", " + newHeight); - } - width = newWidth; - height = newHeight; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - if (DEBUG_IMPLEMENTATION) { - System.out.println(" Posted WINDOW_RESIZED event"); - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); - } - - private void insetsChanged(int left, int top, int right, int bottom) { - if (DEBUG_IMPLEMENTATION) { - System.out.println(Thread.currentThread().getName()+ - " Insets changed to " + left + ", " + top + ", " + right + ", " + bottom); - } - if (left != -1 && top != -1 && right != -1 && bottom != -1) { - insets.left = left; - insets.top = top; - insets.right = right; - insets.bottom = bottom; - } - } - - private void positionChanged(int newX, int newY) { - if (DEBUG_IMPLEMENTATION) { - System.out.println(Thread.currentThread().getName()+" Position changed to " + newX + ", " + newY); - } - x = newX; - y = newY; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - if (DEBUG_IMPLEMENTATION) { - System.out.println(" Posted WINDOW_MOVED event"); - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); - } - - private void focusChanged(boolean focusGained) { - if (focusGained) { - sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); - } else { - sendWindowEvent(WindowEvent.EVENT_WINDOW_LOST_FOCUS); - } - } - - private char convertKeyChar(char keyChar) { - if (keyChar == '\r') { - // Turn these into \n - return '\n'; - } - - if (keyChar >= NSUpArrowFunctionKey && keyChar <= NSModeSwitchFunctionKey) { - switch (keyChar) { - case NSUpArrowFunctionKey: return KeyEvent.VK_UP; - case NSDownArrowFunctionKey: return KeyEvent.VK_DOWN; - case NSLeftArrowFunctionKey: return KeyEvent.VK_LEFT; - case NSRightArrowFunctionKey: return KeyEvent.VK_RIGHT; - case NSF1FunctionKey: return KeyEvent.VK_F1; - case NSF2FunctionKey: return KeyEvent.VK_F2; - case NSF3FunctionKey: return KeyEvent.VK_F3; - case NSF4FunctionKey: return KeyEvent.VK_F4; - case NSF5FunctionKey: return KeyEvent.VK_F5; - case NSF6FunctionKey: return KeyEvent.VK_F6; - case NSF7FunctionKey: return KeyEvent.VK_F7; - case NSF8FunctionKey: return KeyEvent.VK_F8; - case NSF9FunctionKey: return KeyEvent.VK_F9; - case NSF10FunctionKey: return KeyEvent.VK_F10; - case NSF11FunctionKey: return KeyEvent.VK_F11; - case NSF12FunctionKey: return KeyEvent.VK_F12; - case NSF13FunctionKey: return KeyEvent.VK_F13; - case NSF14FunctionKey: return KeyEvent.VK_F14; - case NSF15FunctionKey: return KeyEvent.VK_F15; - case NSF16FunctionKey: return KeyEvent.VK_F16; - case NSF17FunctionKey: return KeyEvent.VK_F17; - case NSF18FunctionKey: return KeyEvent.VK_F18; - case NSF19FunctionKey: return KeyEvent.VK_F19; - case NSF20FunctionKey: return KeyEvent.VK_F20; - case NSF21FunctionKey: return KeyEvent.VK_F21; - case NSF22FunctionKey: return KeyEvent.VK_F22; - case NSF23FunctionKey: return KeyEvent.VK_F23; - case NSF24FunctionKey: return KeyEvent.VK_F24; - case NSInsertFunctionKey: return KeyEvent.VK_INSERT; - case NSDeleteFunctionKey: return KeyEvent.VK_DELETE; - case NSHomeFunctionKey: return KeyEvent.VK_HOME; - case NSBeginFunctionKey: return KeyEvent.VK_BEGIN; - case NSEndFunctionKey: return KeyEvent.VK_END; - case NSPageUpFunctionKey: return KeyEvent.VK_PAGE_UP; - case NSPageDownFunctionKey: return KeyEvent.VK_PAGE_DOWN; - case NSPrintScreenFunctionKey: return KeyEvent.VK_PRINTSCREEN; - case NSScrollLockFunctionKey: return KeyEvent.VK_SCROLL_LOCK; - case NSPauseFunctionKey: return KeyEvent.VK_PAUSE; - // Not handled: - // NSSysReqFunctionKey - // NSBreakFunctionKey - // NSResetFunctionKey - case NSStopFunctionKey: return KeyEvent.VK_STOP; - // Not handled: - // NSMenuFunctionKey - // NSUserFunctionKey - // NSSystemFunctionKey - // NSPrintFunctionKey - // NSClearLineFunctionKey - // NSClearDisplayFunctionKey - // NSInsertLineFunctionKey - // NSDeleteLineFunctionKey - // NSInsertCharFunctionKey - // NSDeleteCharFunctionKey - // NSPrevFunctionKey - // NSNextFunctionKey - // NSSelectFunctionKey - // NSExecuteFunctionKey - // NSUndoFunctionKey - // NSRedoFunctionKey - // NSFindFunctionKey - // NSHelpFunctionKey - // NSModeSwitchFunctionKey - default: break; - } - } - - // NSEvent's charactersIgnoringModifiers doesn't ignore the shift key - if (keyChar >= 'a' && keyChar <= 'z') { - return Character.toUpperCase(keyChar); - } - - return keyChar; - } - - protected void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { - int key = convertKeyChar(keyChar); - if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.sendKeyEvent "+Thread.currentThread().getName()); - // Note that we send the key char for the key code on this - // platform -- we do not get any useful key codes out of the system - super.sendKeyEvent(eventType, modifiers, key, keyChar); - } - - private void createWindow(long parentWindowHandle, boolean recreate) { - if(0!=windowHandle && !recreate) { - return; - } - if(0!=windowHandle) { - // save the view .. close the window - surfaceHandle = changeContentView(parentWindowHandle, windowHandle, 0); - if(recreate && 0==surfaceHandle) { - throw new NativeWindowException("Internal Error - recreate, window but no view"); - } - close0(windowHandle); - windowHandle=0; - } else { - surfaceHandle = 0; - } - windowHandle = createWindow0(parentWindowHandle, - getX(), getY(), getWidth(), getHeight(), fullscreen, - (isUndecorated() ? - NSBorderlessWindowMask : - NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask), - NSBackingStoreBuffered, - getScreen().getIndex(), surfaceHandle); - if (windowHandle == 0) { - throw new NativeWindowException("Could create native window "+Thread.currentThread().getName()+" "+this); - } - surfaceHandle = contentView(windowHandle); - setTitle0(windowHandle, getTitle()); - // don't make the window visible on window creation -// makeKeyAndOrderFront(windowHandle); - sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); - sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); - sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); - } - - protected static native boolean initIDs(); - private native long createWindow0(long parentWindowHandle, int x, int y, int w, int h, - boolean fullscreen, int windowStyle, - int backingStoreType, - int screen_idx, long view); - private native void makeKeyAndOrderFront(long window); - private native void makeKey(long window); - private native void orderOut(long window); - private native void close0(long window); - private native void setTitle0(long window, String title); - private native long contentView(long window); - private native long changeContentView(long parentWindowHandle, long window, long view); - private native void setContentSize(long window, int w, int h); - private native void setFrameTopLeftPoint(long parentWindowHandle, long window, int x, int y); -} diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java b/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java deleted file mode 100644 index 98010b2f1..000000000 --- a/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java +++ /dev/null @@ -1,628 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.opengl; - -import com.sun.javafx.newt.*; -import javax.media.nativewindow.*; -import javax.media.opengl.*; -import com.jogamp.opengl.impl.GLDrawableHelper; -import java.util.*; - -/** - * An implementation of {@link Window} which is customized for OpenGL - * use, and which implements the {@link javax.media.opengl.GLAutoDrawable} interface. - *

- * This implementation does not make the OpenGL context current
- * before calling the various input EventListener callbacks (MouseListener, KeyListener, - * etc.).
- * This design decision is made to favor a more performant and simplified - * implementation, as well as the event dispatcher shall be allowed - * not having a notion about OpenGL. - *

- */ -public class GLWindow extends Window implements GLAutoDrawable { - private static List/*GLWindow*/ glwindows = new ArrayList(); - - private boolean ownerOfWinScrDpy; - private Window window; - private boolean runPumpMessages; - - /** Constructor. Do not call this directly -- use {@link - create()} instead. */ - protected GLWindow(Window window, boolean ownerOfWinScrDpy) { - this.ownerOfWinScrDpy = ownerOfWinScrDpy; - this.window = window; - this.window.setAutoDrawableClient(true); - this.runPumpMessages = ( null == getScreen().getDisplay().getEDT() ) ; - window.addWindowListener(new WindowListener() { - public void windowResized(WindowEvent e) { - sendReshape = true; - } - - public void windowMoved(WindowEvent e) { - } - - public void windowGainedFocus(WindowEvent e) { - } - - public void windowLostFocus(WindowEvent e) { - } - - public void windowDestroyNotify(WindowEvent e) { - sendDestroy = true; - } - }); - - List newglw = (List) ((ArrayList) glwindows).clone(); - newglw.add(this); - glwindows=newglw; - } - - /** Creates a new GLWindow on the local display, screen 0, with a - dummy visual ID, and with the default GLCapabilities. */ - public static GLWindow create() { - return create(null, null, false); - } - - public static GLWindow create(boolean undecorated) { - return create(null, null, undecorated); - } - - /** Creates a new GLWindow referring to the given window. */ - public static GLWindow create(Window window) { - return create(window, null, false); - } - public static GLWindow create(GLCapabilities caps) { - return create(null, caps, false); - } - - /** Creates a new GLWindow on the local display, screen 0, with a - dummy visual ID, and with the given GLCapabilities. */ - public static GLWindow create(GLCapabilities caps, boolean undecorated) { - return create(null, caps, undecorated); - } - - /** Either or: window (prio), or caps and undecorated (2nd choice) */ - private static GLWindow create(Window window, - GLCapabilities caps, - boolean undecorated) { - Display display; - boolean ownerOfWinScrDpy=false; - if (window == null) { - if (caps == null) { - caps = new GLCapabilities(null); // default .. - } - ownerOfWinScrDpy = true; - display = NewtFactory.createDisplay(null); // local display - Screen screen = NewtFactory.createScreen(display, 0); // screen 0 - window = NewtFactory.createWindow(screen, caps, undecorated); - } - - return new GLWindow(window, ownerOfWinScrDpy); - } - - /** - * EXPERIMENTAL
- * Enable or disables running the {@link Display#pumpMessages} in the {@link #display()} call.
- * The default behavior is to run {@link Display#pumpMessages}.

- * - * The idea was that in a single threaded environment with one {@link Display} and many {@link Window}'s, - * a performance benefit was expected while disabling the implicit {@link Display#pumpMessages} and - * do it once via {@link GLWindow#runCurrentThreadPumpMessage()}
- * This could not have been verified. No measurable difference could have been recognized.

- * - * Best performance has been achieved with one GLWindow per thread.
- * - * Enabling local pump messages while using the EDT, - * {@link com.sun.javafx.newt.NewtFactory#setUseEDT(boolean)}, - * will result in an exception. - * - * @deprecated EXPERIMENTAL, semantic is about to be removed after further verification. - */ - public void setRunPumpMessages(boolean onoff) { - if( onoff && null!=getScreen().getDisplay().getEDT() ) { - throw new GLException("GLWindow.setRunPumpMessages(true) - Can't do with EDT on"); - } - runPumpMessages = onoff; - } - - protected void createNative(long parentWindowHandle, Capabilities caps) { - shouldNotCallThis(); - } - - protected void closeNative() { - shouldNotCallThis(); - } - - protected void dispose(boolean regenerate, boolean sendEvent) { - if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { - Exception e1 = new Exception("GLWindow.dispose("+regenerate+") "+Thread.currentThread()+", 1"); - e1.printStackTrace(); - } - - if(sendEvent) { - sendDisposeEvent(); - } - - if (context != null) { - context.destroy(); - } - if (drawable != null) { - drawable.setRealized(false); - } - - if(regenerate) { - if(null==window) { - throw new GLException("GLWindow.dispose(true): null window"); - } - - // recreate GLDrawable, to reflect the new graphics configurations - NativeWindow nw; - if (window.getWrappedWindow() != null) { - nw = NativeWindowFactory.getNativeWindow(window.getWrappedWindow(), window.getGraphicsConfiguration()); - } else { - nw = window; - } - drawable = factory.createGLDrawable(nw); - drawable.setRealized(true); - context = drawable.createContext(null); - sendReshape = true; // ensure a reshape event is send .. - } - - if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { - System.out.println("GLWindow.dispose("+regenerate+") "+Thread.currentThread()+", fin: "+this); - } - } - - public synchronized void destroy() { - destroy(true); - } - - /** @param sendDisposeEvent should be false in a [time,reliable] critical shutdown */ - public synchronized void destroy(boolean sendDisposeEvent) { - if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { - Exception e1 = new Exception("GLWindow.destroy "+Thread.currentThread()+", 1: "+this); - e1.printStackTrace(); - } - - List newglw = (List) ((ArrayList) glwindows).clone(); - newglw.remove(this); - glwindows=newglw; - - dispose(false, sendDisposeEvent); - - if(null!=window) { - if(ownerOfWinScrDpy) { - window.destroy(true); - } - } - - drawable = null; - context = null; - window = null; - - if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { - System.out.println("GLWindow.destroy "+Thread.currentThread()+", fin: "+this); - } - } - - public boolean getPerfLogEnabled() { return perfLog; } - - public void enablePerfLog(boolean v) { - perfLog = v; - } - - public void setVisible(boolean visible) { - if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { - System.out.println(Thread.currentThread()+" GLWindow.setVisible("+visible+") START ; isVisible "+this.visible+" ; has context "+(null!=context)); - } - this.visible=visible; - window.setVisible(visible); - if (visible && context == null) { - NativeWindow nw; - if (window.getWrappedWindow() != null) { - nw = NativeWindowFactory.getNativeWindow(window.getWrappedWindow(), window.getGraphicsConfiguration()); - } else { - nw = window; - } - GLCapabilities glCaps = (GLCapabilities) nw.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); - factory = GLDrawableFactory.getFactory(glCaps.getGLProfile()); - drawable = factory.createGLDrawable(nw); - drawable.setRealized(true); - context = drawable.createContext(null); - sendReshape = true; // ensure a reshape event is send .. - } - if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { - System.out.println(Thread.currentThread()+" GLWindow.setVisible("+visible+") END ; has context "+(null!=context)); - } - } - - public Screen getScreen() { - return window.getScreen(); - } - - public void setTitle(String title) { - window.setTitle(title); - } - - public String getTitle() { - return window.getTitle(); - } - - public void setUndecorated(boolean value) { - window.setUndecorated(value); - } - - public boolean isUndecorated() { - return window.isUndecorated(); - } - - public void setSize(int width, int height) { - window.setSize(width, height); - } - - public void setPosition(int x, int y) { - window.setPosition(x, y); - } - - public Insets getInsets() { - return window.getInsets(); - } - - public boolean setFullscreen(boolean fullscreen) { - return window.setFullscreen(fullscreen); - } - - public boolean isVisible() { - return window.isVisible(); - } - - public int getX() { - return window.getX(); - } - - public int getY() { - return window.getY(); - } - - public int getWidth() { - return window.getWidth(); - } - - public int getHeight() { - return window.getHeight(); - } - - public boolean isFullscreen() { - return window.isFullscreen(); - } - - public void addSurfaceUpdatedListener(SurfaceUpdatedListener l) { - window.addSurfaceUpdatedListener(l); - } - public void removeSurfaceUpdatedListener(SurfaceUpdatedListener l) { - window.removeSurfaceUpdatedListener(l); - } - public SurfaceUpdatedListener[] getSurfaceUpdatedListener() { - return window.getSurfaceUpdatedListener(); - } - public void surfaceUpdated(Object updater, NativeWindow window0, long when) { - window.surfaceUpdated(updater, window, when); - } - - public void addMouseListener(MouseListener l) { - window.addMouseListener(l); - } - - public void removeMouseListener(MouseListener l) { - window.removeMouseListener(l); - } - - public MouseListener[] getMouseListeners() { - return window.getMouseListeners(); - } - - public void addKeyListener(KeyListener l) { - window.addKeyListener(l); - } - - public void removeKeyListener(KeyListener l) { - window.removeKeyListener(l); - } - - public KeyListener[] getKeyListeners() { - return window.getKeyListeners(); - } - - public void addWindowListener(WindowListener l) { - window.addWindowListener(l); - } - - public void removeWindowListener(WindowListener l) { - window.removeWindowListener(l); - } - - public WindowListener[] getWindowListeners() { - return window.getWindowListeners(); - } - - public String toString() { - return "NEWT-GLWindow[ \n\tDrawable: "+drawable+", \n\tWindow: "+window+", \n\tHelper: "+helper+", \n\tFactory: "+factory+"]"; - } - - //---------------------------------------------------------------------- - // OpenGL-related methods and state - // - - private GLDrawableFactory factory; - private GLDrawable drawable; - private GLContext context; - private GLDrawableHelper helper = new GLDrawableHelper(); - // To make reshape events be sent immediately before a display event - private boolean sendReshape=false; - private boolean sendDestroy=false; - private boolean perfLog = false; - - public GLDrawableFactory getFactory() { - return factory; - } - - public void setContext(GLContext newCtx) { - context = newCtx; - } - - public GLContext getContext() { - return context; - } - - public GL getGL() { - if (context == null) { - return null; - } - return context.getGL(); - } - - public GL setGL(GL gl) { - if (context != null) { - context.setGL(gl); - return gl; - } - return null; - } - - public void addGLEventListener(GLEventListener listener) { - helper.addGLEventListener(listener); - } - - public void removeGLEventListener(GLEventListener listener) { - helper.removeGLEventListener(listener); - } - - public void display() { - display(false); - } - - public void display(boolean forceReshape) { - if(window!=null && drawable!=null && context != null) { - if(runPumpMessages) { - window.getScreen().getDisplay().pumpMessages(); - } - if(window.hasDeviceChanged() && GLAutoDrawable.SCREEN_CHANGE_ACTION_ENABLED) { - dispose(true, true); - } - if (sendDestroy) { - destroy(); - sendDestroy=false; - } else { - if(forceReshape) { - sendReshape = true; - } - helper.invokeGL(drawable, context, displayAction, initAction); - } - } - } - - private void sendDisposeEvent() { - if(drawable!=null && context != null) { - helper.invokeGL(drawable, context, disposeAction, null); - } - } - - /** This implementation uses a static value */ - public void setAutoSwapBufferMode(boolean onOrOff) { - helper.setAutoSwapBufferMode(onOrOff); - } - - /** This implementation uses a static value */ - public boolean getAutoSwapBufferMode() { - return helper.getAutoSwapBufferMode(); - } - - public void swapBuffers() { - if(drawable!=null && context != null) { - if (context != GLContext.getCurrent()) { - // Assume we should try to make the context current before swapping the buffers - helper.invokeGL(drawable, context, swapBuffersAction, initAction); - } else { - drawable.swapBuffers(); - } - } - } - - class InitAction implements Runnable { - public void run() { - helper.init(GLWindow.this); - startTime = System.currentTimeMillis(); - curTime = startTime; - if(perfLog) { - lastCheck = startTime; - totalFrames = 0; lastFrames = 0; - } - } - } - private InitAction initAction = new InitAction(); - - class DisposeAction implements Runnable { - public void run() { - helper.dispose(GLWindow.this); - } - } - private DisposeAction disposeAction = new DisposeAction(); - - class DisplayAction implements Runnable { - public void run() { - if (sendReshape) { - int width = getWidth(); - int height = getHeight(); - getGL().glViewport(0, 0, width, height); - helper.reshape(GLWindow.this, 0, 0, width, height); - sendReshape = false; - } - - helper.display(GLWindow.this); - - curTime = System.currentTimeMillis(); - totalFrames++; - - if(perfLog) { - long dt0, dt1; - lastFrames++; - dt0 = curTime-lastCheck; - if ( dt0 > 5000 ) { - dt1 = curTime-startTime; - System.out.println(dt0/1000 +"s: "+ lastFrames + "f, " + (lastFrames*1000)/dt0 + " fps, "+dt0/lastFrames+" ms/f; "+ - "total: "+ dt1/1000+"s, "+(totalFrames*1000)/dt1 + " fps, "+dt1/totalFrames+" ms/f"); - lastCheck=curTime; - lastFrames=0; - } - } - } - } - private DisplayAction displayAction = new DisplayAction(); - - public long getStartTime() { return startTime; } - public long getCurrentTime() { return curTime; } - public long getDuration() { return curTime-startTime; } - public int getTotalFrames() { return totalFrames; } - - private long startTime = 0; - private long curTime = 0; - private long lastCheck = 0; - private int totalFrames = 0, lastFrames = 0; - - class SwapBuffersAction implements Runnable { - public void run() { - drawable.swapBuffers(); - } - } - private SwapBuffersAction swapBuffersAction = new SwapBuffersAction(); - - //---------------------------------------------------------------------- - // GLDrawable methods - // - - public NativeWindow getNativeWindow() { - return null!=drawable ? drawable.getNativeWindow() : null; - } - - public synchronized int lockSurface() throws NativeWindowException { - if(null!=drawable) return drawable.getNativeWindow().lockSurface(); - return NativeWindow.LOCK_SURFACE_NOT_READY; - } - - public synchronized void unlockSurface() { - if(null!=drawable) drawable.getNativeWindow().unlockSurface(); - else throw new NativeWindowException("NEWT-GLWindow not locked"); - } - - public synchronized boolean isSurfaceLocked() { - if(null!=drawable) return drawable.getNativeWindow().isSurfaceLocked(); - return false; - } - - public synchronized Exception getLockedStack() { - if(null!=drawable) return drawable.getNativeWindow().getLockedStack(); - return null; - } - - public boolean surfaceSwap() { - if(null!=drawable) return drawable.getNativeWindow().surfaceSwap(); - return super.surfaceSwap(); - } - - public long getWindowHandle() { - if(null!=drawable) return drawable.getNativeWindow().getWindowHandle(); - return super.getWindowHandle(); - } - - public long getSurfaceHandle() { - if(null!=drawable) return drawable.getNativeWindow().getSurfaceHandle(); - return super.getSurfaceHandle(); - } - - //---------------------------------------------------------------------- - // GLDrawable methods that are not really needed - // - - public GLContext createContext(GLContext shareWith) { - return drawable.createContext(shareWith); - } - - public void setRealized(boolean realized) { - } - - public GLCapabilities getChosenGLCapabilities() { - if (drawable == null) { - throw new GLException("No drawable yet"); - } - - return drawable.getChosenGLCapabilities(); - } - - public GLProfile getGLProfile() { - if (drawable == null) { - throw new GLException("No drawable yet"); - } - - return drawable.getGLProfile(); - } - - //---------------------------------------------------------------------- - // Internals only below this point - // - - private void shouldNotCallThis() { - throw new NativeWindowException("Should not call this"); - } -} diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/egl/Display.java b/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/egl/Display.java deleted file mode 100644 index 1b74aebc3..000000000 --- a/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/egl/Display.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.opengl.broadcom.egl; - -import com.sun.javafx.newt.impl.*; -import com.jogamp.opengl.impl.egl.*; -import javax.media.nativewindow.*; -import javax.media.nativewindow.egl.*; - -public class Display extends com.sun.javafx.newt.Display { - - static { - NativeLibLoader.loadNEWT(); - - if (!Window.initIDs()) { - throw new NativeWindowException("Failed to initialize BCEGL Window jmethodIDs"); - } - } - - public static void initSingleton() { - // just exist to ensure static init has been run - } - - - public Display() { - } - - protected void createNative() { - long handle = CreateDisplay(Screen.fixedWidth, Screen.fixedHeight); - if (handle == EGL.EGL_NO_DISPLAY) { - throw new NativeWindowException("BC EGL CreateDisplay failed"); - } - aDevice = new EGLGraphicsDevice(handle); - } - - protected void closeNative() { - if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) { - DestroyDisplay(aDevice.getHandle()); - } - } - - protected void dispatchMessages() { - // n/a .. DispatchMessages(); - } - - private native long CreateDisplay(int width, int height); - private native void DestroyDisplay(long dpy); - private native void DispatchMessages(); -} - diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/egl/Screen.java b/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/egl/Screen.java deleted file mode 100755 index 28f7211c3..000000000 --- a/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/egl/Screen.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.opengl.broadcom.egl; - -import com.sun.javafx.newt.impl.*; -import javax.media.nativewindow.*; - -public class Screen extends com.sun.javafx.newt.Screen { - - static { - Display.initSingleton(); - } - - - public Screen() { - } - - protected void createNative(int index) { - aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); - setScreenSize(fixedWidth, fixedHeight); - } - - protected void closeNative() { } - - //---------------------------------------------------------------------- - // Internals only - // - - static final int fixedWidth = 1920; - static final int fixedHeight = 1080; -} - diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/egl/Window.java b/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/egl/Window.java deleted file mode 100755 index 8446ec20f..000000000 --- a/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/egl/Window.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.opengl.broadcom.egl; - -import com.sun.javafx.newt.impl.*; -import com.jogamp.opengl.impl.egl.*; -import javax.media.nativewindow.*; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLProfile; -import javax.media.nativewindow.NativeWindowException; - -public class Window extends com.sun.javafx.newt.Window { - static { - Display.initSingleton(); - } - - public Window() { - } - - protected void createNative(long parentWindowHandle, Capabilities caps) { - if(0!=parentWindowHandle) { - throw new RuntimeException("Window parenting not supported (yet)"); - } - // query a good configuration .. even thought we drop this one - // and reuse the EGLUtil choosen one later. - config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - setSizeImpl(getScreen().getWidth(), getScreen().getHeight()); - } - - protected void closeNative() { - if(0!=windowHandleClose) { - CloseWindow(getDisplayHandle(), windowHandleClose); - } - } - - public void setVisible(boolean visible) { - if(this.visible!=visible) { - this.visible=visible; - if ( 0==windowHandle ) { - windowHandle = realizeWindow(true, width, height); - if (0 == windowHandle) { - throw new NativeWindowException("Error native Window Handle is null"); - } - } - clearEventMask(); - } - } - - public void setSize(int width, int height) { - System.err.println("setSize "+width+"x"+height+" n/a in BroadcomEGL"); - } - - void setSizeImpl(int width, int height) { - if(0!=windowHandle) { - // n/a in BroadcomEGL - System.err.println("BCEGL Window.setSizeImpl n/a in BroadcomEGL with realized window"); - } else { - if(DEBUG_IMPLEMENTATION) { - Exception e = new Exception("BCEGL Window.setSizeImpl() "+this.width+"x"+this.height+" -> "+width+"x"+height); - e.printStackTrace(); - } - this.width = width; - this.height = height; - } - } - - public void setPosition(int x, int y) { - // n/a in BroadcomEGL - System.err.println("setPosition n/a in BroadcomEGL"); - } - - public boolean setFullscreen(boolean fullscreen) { - // n/a in BroadcomEGL - System.err.println("setFullscreen n/a in BroadcomEGL"); - return false; - } - - public boolean surfaceSwap() { - if ( 0!=windowHandle ) { - SwapWindow(getDisplayHandle(), windowHandle); - return true; - } - return false; - } - - //---------------------------------------------------------------------- - // Internals only - // - - protected static native boolean initIDs(); - private native long CreateWindow(long eglDisplayHandle, boolean chromaKey, int width, int height); - private native void CloseWindow(long eglDisplayHandle, long eglWindowHandle); - private native void SwapWindow(long eglDisplayHandle, long eglWindowHandle); - - - private long realizeWindow(boolean chromaKey, int width, int height) { - if(DEBUG_IMPLEMENTATION) { - System.out.println("BCEGL Window.realizeWindow() with: chroma "+chromaKey+", "+width+"x"+height+", "+config); - } - long handle = CreateWindow(getDisplayHandle(), chromaKey, width, height); - if (0 == handle) { - throw new NativeWindowException("Error native Window Handle is null"); - } - windowHandleClose = handle; - return handle; - } - - private void windowCreated(int cfgID, int width, int height) { - this.width = width; - this.height = height; - GLCapabilities capsReq = (GLCapabilities) config.getRequestedCapabilities(); - config = EGLGraphicsConfiguration.create(capsReq, screen.getGraphicsScreen(), cfgID); - if (config == null) { - throw new NativeWindowException("Error creating EGLGraphicsConfiguration from id: "+cfgID+", "+this); - } - if(DEBUG_IMPLEMENTATION) { - System.out.println("BCEGL Window.windowCreated(): "+toHexString(cfgID)+", "+width+"x"+height+", "+config); - } - } - - private long windowHandleClose; -} diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDDisplay.java b/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDDisplay.java deleted file mode 100755 index 9e328a223..000000000 --- a/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDDisplay.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.opengl.kd; - -import com.sun.javafx.newt.*; -import com.sun.javafx.newt.impl.*; -import com.jogamp.opengl.impl.egl.*; -import javax.media.nativewindow.*; -import javax.media.nativewindow.egl.*; - -public class KDDisplay extends Display { - - static { - NativeLibLoader.loadNEWT(); - - if (!KDWindow.initIDs()) { - throw new NativeWindowException("Failed to initialize KDWindow jmethodIDs"); - } - } - - public static void initSingleton() { - // just exist to ensure static init has been run - } - - - public KDDisplay() { - } - - protected void createNative() { - // FIXME: map name to EGL_*_DISPLAY - long handle = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY); - if (handle == EGL.EGL_NO_DISPLAY) { - throw new NativeWindowException("eglGetDisplay failed"); - } - if (!EGL.eglInitialize(handle, null, null)) { - throw new NativeWindowException("eglInitialize failed"); - } - aDevice = new EGLGraphicsDevice(handle); - } - - protected void closeNative() { - if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) { - EGL.eglTerminate(aDevice.getHandle()); - } - } - - protected void dispatchMessages() { - DispatchMessages(); - } - - private native void DispatchMessages(); -} - diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDScreen.java b/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDScreen.java deleted file mode 100755 index 1767c1240..000000000 --- a/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDScreen.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.opengl.kd; - -import com.sun.javafx.newt.*; -import javax.media.nativewindow.*; - -public class KDScreen extends Screen { - static { - KDDisplay.initSingleton(); - } - - public KDScreen() { - } - - protected void createNative(int index) { - aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); - } - - protected void closeNative() { } - - // elevate access to this package .. - protected void setScreenSize(int w, int h) { - super.setScreenSize(w, h); - } -} diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java b/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java deleted file mode 100755 index 9919d1f6f..000000000 --- a/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.opengl.kd; - -import com.sun.javafx.newt.*; -import com.sun.javafx.newt.impl.*; -import com.jogamp.opengl.impl.egl.*; -import javax.media.nativewindow.*; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLProfile; -import javax.media.nativewindow.NativeWindowException; - -public class KDWindow extends Window { - private static final String WINDOW_CLASS_NAME = "NewtWindow"; - // non fullscreen dimensions .. - private int nfs_width, nfs_height, nfs_x, nfs_y; - - static { - KDDisplay.initSingleton(); - } - - public KDWindow() { - } - - protected void createNative(long parentWindowHandle, Capabilities caps) { - if(0!=parentWindowHandle) { - throw new RuntimeException("Window parenting not supported (yet)"); - } - config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - - GLCapabilities eglCaps = (GLCapabilities)config.getChosenCapabilities(); - int[] eglAttribs = EGLGraphicsConfiguration.GLCapabilities2AttribList(eglCaps); - - windowHandle = 0; - eglWindowHandle = CreateWindow(getDisplayHandle(), eglAttribs); - if (eglWindowHandle == 0) { - throw new NativeWindowException("Error creating egl window: "+config); - } - setVisible0(eglWindowHandle, false); - windowHandleClose = eglWindowHandle; - } - - protected void closeNative() { - if(0!=windowHandleClose) { - CloseWindow(windowHandleClose, windowUserData); - windowUserData=0; - } - } - - public void setVisible(boolean visible) { - if(0!=eglWindowHandle && this.visible!=visible) { - this.visible=visible; - setVisible0(eglWindowHandle, visible); - if ( 0==windowHandle ) { - windowHandle = RealizeWindow(eglWindowHandle); - if (0 == windowHandle) { - throw new NativeWindowException("Error native Window Handle is null"); - } - } - clearEventMask(); - } - } - - public void setSize(int width, int height) { - if(0!=eglWindowHandle) { - setSize0(eglWindowHandle, width, height); - } - } - - public void setPosition(int x, int y) { - // n/a in KD - System.err.println("setPosition n/a in KD"); - } - - public boolean setFullscreen(boolean fullscreen) { - if(0!=eglWindowHandle && this.fullscreen!=fullscreen) { - this.fullscreen=fullscreen; - if(this.fullscreen) { - setFullScreen0(eglWindowHandle, true); - } else { - setFullScreen0(eglWindowHandle, false); - setSize0(eglWindowHandle, nfs_width, nfs_height); - } - } - return true; - } - - //---------------------------------------------------------------------- - // Internals only - // - - protected static native boolean initIDs(); - private native long CreateWindow(long displayHandle, int[] attributes); - private native long RealizeWindow(long eglWindowHandle); - private native int CloseWindow(long eglWindowHandle, long userData); - private native void setVisible0(long eglWindowHandle, boolean visible); - private native void setSize0(long eglWindowHandle, int width, int height); - private native void setFullScreen0(long eglWindowHandle, boolean fullscreen); - - private void windowCreated(long userData) { - windowUserData=userData; - } - - private void sizeChanged(int newWidth, int newHeight) { - width = newWidth; - height = newHeight; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } else { - ((KDScreen)screen).setScreenSize(width, height); - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); - } - - private long eglWindowHandle; - private long windowHandleClose; - private long windowUserData; -} diff --git a/src/newt/classes/com/sun/javafx/newt/util/EventDispatchThread.java b/src/newt/classes/com/sun/javafx/newt/util/EventDispatchThread.java deleted file mode 100644 index a98ebab93..000000000 --- a/src/newt/classes/com/sun/javafx/newt/util/EventDispatchThread.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright (c) 2009 Sun Microsystems, Inc. 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 com.sun.javafx.newt.util; - -import com.sun.javafx.newt.Display; -import com.sun.javafx.newt.impl.Debug; -import java.util.*; - -public class EventDispatchThread { - public static final boolean DEBUG = Debug.debug("EDT"); - - private ThreadGroup threadGroup; - private volatile boolean shouldStop = false; - private TaskWorker taskWorker = null; - private Object taskWorkerLock = new Object(); - private ArrayList tasks = new ArrayList(); // one shot tasks - private Display display = null; - private String name; - private long edtPollGranularity = 10; - - public EventDispatchThread(Display display, ThreadGroup tg, String name) { - this.display = display; - this.threadGroup = tg; - this.name=new String("EDT-Display_"+display.getName()+"-"+name); - } - - public String getName() { return name; } - - public ThreadGroup getThreadGroup() { return threadGroup; } - - public void start() { - start(false); - } - - /** - * @param externalStimuli true indicates that another thread stimulates, - * ie. calls this TaskManager's run() loop method. - * Hence no own thread is started in this case. - * - * @return The started Runnable, which handles the run-loop. - * Usefull in combination with externalStimuli=true, - * so an external stimuli can call it. - */ - public Runnable start(boolean externalStimuli) { - synchronized(taskWorkerLock) { - if(null==taskWorker) { - taskWorker = new TaskWorker(threadGroup, name); - } - if(!taskWorker.isRunning()) { - shouldStop = false; - taskWorker.start(externalStimuli); - } - taskWorkerLock.notifyAll(); - } - return taskWorker; - } - - public void stop() { - synchronized(taskWorkerLock) { - if(null!=taskWorker && taskWorker.isRunning()) { - shouldStop = true; - } - taskWorkerLock.notifyAll(); - if(DEBUG) { - System.out.println(Thread.currentThread()+": EDT signal STOP"); - } - } - } - - public boolean isThreadEDT(Thread thread) { - return null!=taskWorker && taskWorker == thread; - } - - public boolean isCurrentThreadEDT() { - return null!=taskWorker && taskWorker == Thread.currentThread(); - } - - public boolean isRunning() { - return null!=taskWorker && taskWorker.isRunning() ; - } - - public void invokeLater(Runnable task) { - if(task == null) { - return; - } - synchronized(taskWorkerLock) { - if(null!=taskWorker && taskWorker.isRunning() && taskWorker != Thread.currentThread() ) { - tasks.add(task); - taskWorkerLock.notifyAll(); - } else { - // if !running or isEDTThread, do it right away - task.run(); - } - } - } - - public void invokeAndWait(Runnable task) { - if(task == null) { - return; - } - invokeLater(task); - waitOnWorker(); - } - - public void waitOnWorker() { - synchronized(taskWorkerLock) { - if(null!=taskWorker && taskWorker.isRunning() && tasks.size()>0 && taskWorker != Thread.currentThread() ) { - try { - taskWorkerLock.wait(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - } - - public void waitUntilStopped() { - synchronized(taskWorkerLock) { - while(null!=taskWorker && taskWorker.isRunning() && taskWorker != Thread.currentThread() ) { - try { - taskWorkerLock.wait(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - } - - class TaskWorker extends Thread { - boolean isRunning = false; - boolean externalStimuli = false; - - public TaskWorker(ThreadGroup tg, String name) { - super(tg, name); - } - - public synchronized boolean isRunning() { - return isRunning; - } - - public void start(boolean externalStimuli) throws IllegalThreadStateException { - synchronized(this) { - this.externalStimuli = externalStimuli; - isRunning = true; - } - if(!externalStimuli) { - super.start(); - } - } - - /** - * Utilizing taskWorkerLock only for local resources and task execution, - * not for event dispatching. - */ - public void run() { - if(DEBUG) { - System.out.println(Thread.currentThread()+": EDT run() START"); - } - while(!shouldStop) { - try { - // wait for something todo - while(!shouldStop && tasks.size()==0) { - synchronized(taskWorkerLock) { - if(!shouldStop && tasks.size()==0) { - try { - taskWorkerLock.wait(edtPollGranularity); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - display.pumpMessages(); // event dispatch - } - if(!shouldStop && tasks.size()>0) { - synchronized(taskWorkerLock) { - if(!shouldStop && tasks.size()>0) { - Runnable task = (Runnable) tasks.remove(0); - task.run(); - taskWorkerLock.notifyAll(); - } - } - display.pumpMessages(); // event dispatch - } - } catch (Throwable t) { - // handle errors .. - t.printStackTrace(); - } finally { - // epilog - unlock locked stuff - } - if(externalStimuli) break; // no loop if called by external stimuli - } - synchronized(this) { - isRunning = !shouldStop; - } - if(!isRunning) { - synchronized(taskWorkerLock) { - taskWorkerLock.notifyAll(); - } - } - if(DEBUG) { - System.out.println(Thread.currentThread()+": EDT run() EXIT"); - } - } - } -} - diff --git a/src/newt/classes/com/sun/javafx/newt/util/MainThread.java b/src/newt/classes/com/sun/javafx/newt/util/MainThread.java deleted file mode 100644 index abfe3f0c7..000000000 --- a/src/newt/classes/com/sun/javafx/newt/util/MainThread.java +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright (c) 2009 Sun Microsystems, Inc. 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 com.sun.javafx.newt.util; - -import java.util.*; -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; -import java.security.*; - -import javax.media.nativewindow.*; - -import com.sun.javafx.newt.*; -import com.sun.javafx.newt.impl.*; -import com.sun.javafx.newt.macosx.MacDisplay; -import com.sun.nativewindow.impl.NWReflection; - -/** - * NEWT Utility class MainThread

- * - * This class provides a startup singleton main thread, - * from which a new thread with the users main class is launched.
- * - * Such behavior is necessary for native windowing toolkits, - * where the windowing management must happen on the so called - * main thread e.g. for Mac OS X !
- * - * Utilizing this class as a launchpad, now you are able to - * use a NEWT multithreaded application with window handling within the different threads, - * even on these restricted platforms.
- * - * To support your NEWT Window platform, - * you have to pass your main thread actions to {@link #invoke invoke(..)}, - * have a look at the {@link com.sun.javafx.newt.macosx.MacWindow MacWindow} implementation.
- * TODO: Some hardcoded dependencies exist in this implementation, - * where you have to patch this code or factor it out.

- * - * If your platform is not Mac OS X, but you want to test your code without modifying - * this class, you have to set the system property newt.MainThread.force to true.

- * - * The code is compatible with all other platform, which support multithreaded windowing handling. - * Since those platforms won't trigger the main thread serialization, the main method - * will be simply executed, in case you haven't set newt.MainThread.force to true.

- * - * Test case on Mac OS X (or any other platform): -

-    java -XstartOnFirstThread com.sun.javafx.newt.util.MainThread demos.es1.RedSquare -GL2 -GL2 -GL2 -GL2
- 
- * Which starts 4 threads, each with a window and OpenGL rendering.
- */ -public class MainThread { - private static AccessControlContext localACC = AccessController.getContext(); - public static final boolean USE_MAIN_THREAD = NativeWindowFactory.TYPE_MACOSX.equals(NativeWindowFactory.getNativeWindowType(false)) || - Debug.getBooleanProperty("newt.MainThread.force", true, localACC); - - protected static final boolean DEBUG = Debug.debug("MainThread"); - - private static boolean isExit=false; - private static volatile boolean isRunning=false; - private static Object taskWorkerLock=new Object(); - private static boolean shouldStop; - private static ArrayList tasks; - private static ArrayList tasksBlock; - private static Thread mainThread; - - static class MainAction extends Thread { - private String mainClassName; - private String[] mainClassArgs; - - private Class mainClass; - private Method mainClassMain; - - public MainAction(String mainClassName, String[] mainClassArgs) { - this.mainClassName=mainClassName; - this.mainClassArgs=mainClassArgs; - } - - public void run() { - if ( USE_MAIN_THREAD ) { - // we have to start first to provide the service .. - MainThread.waitUntilRunning(); - } - - // start user app .. - try { - Class mainClass = NWReflection.getClass(mainClassName, true); - if(null==mainClass) { - throw new RuntimeException(new ClassNotFoundException("MainThread couldn't find main class "+mainClassName)); - } - try { - mainClassMain = mainClass.getDeclaredMethod("main", new Class[] { String[].class }); - mainClassMain.setAccessible(true); - } catch (Throwable t) { - throw new RuntimeException(t); - } - if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" invoke "+mainClassName); - mainClassMain.invoke(null, new Object[] { mainClassArgs } ); - } catch (InvocationTargetException ite) { - ite.getTargetException().printStackTrace(); - } catch (Throwable t) { - t.printStackTrace(); - } - - if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" user app fin"); - - if ( USE_MAIN_THREAD ) { - MainThread.exit(); - if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" MainThread fin - exit"); - System.exit(0); - } - } - } - private static MainAction mainAction; - - /** Your new java application main entry, which pipelines your application */ - public static void main(String[] args) { - if(DEBUG) System.err.println("MainThread.main(): "+Thread.currentThread().getName()+" USE_MAIN_THREAD "+ USE_MAIN_THREAD ); - - if(args.length==0) { - return; - } - - String mainClassName=args[0]; - String[] mainClassArgs=new String[args.length-1]; - if(args.length>1) { - System.arraycopy(args, 1, mainClassArgs, 0, args.length-1); - } - - NativeLibLoader.loadNEWT(); - - shouldStop = false; - tasks = new ArrayList(); - tasksBlock = new ArrayList(); - mainThread = Thread.currentThread(); - - mainAction = new MainAction(mainClassName, mainClassArgs); - - if(NativeWindowFactory.TYPE_MACOSX.equals(NativeWindowFactory.getNativeWindowType(false))) { - MacDisplay.initSingleton(); - } - - if ( USE_MAIN_THREAD ) { - // dispatch user's main thread .. - mainAction.start(); - - // do our main thread task scheduling - run(); - } else { - // run user's main in this thread - mainAction.run(); - } - } - - /** invokes the given Runnable */ - public static void invoke(boolean wait, Runnable r) { - if(r == null) { - return; - } - - // if this main thread is not being used or - // if this is already the main thread .. just execute. - if( !isRunning() || mainThread == Thread.currentThread() ) { - r.run(); - return; - } - - synchronized(taskWorkerLock) { - tasks.add(r); - if(wait) { - tasksBlock.add(r); - } - taskWorkerLock.notifyAll(); - if(wait) { - while(tasksBlock.size()>0) { - try { - taskWorkerLock.wait(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - } - } - - public static void exit() { - if(DEBUG) System.err.println("MainThread.exit(): "+Thread.currentThread().getName()+" start"); - synchronized(taskWorkerLock) { - if(isRunning) { - shouldStop = true; - } - taskWorkerLock.notifyAll(); - } - if(DEBUG) System.err.println("MainThread.exit(): "+Thread.currentThread().getName()+" end"); - } - - public static boolean isRunning() { - synchronized(taskWorkerLock) { - return isRunning; - } - } - - private static void waitUntilRunning() { - synchronized(taskWorkerLock) { - if(isExit) return; - - while(!isRunning) { - try { - taskWorkerLock.wait(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - } - - public static void run() { - if(DEBUG) System.err.println("MainThread.run(): "+Thread.currentThread().getName()); - synchronized(taskWorkerLock) { - isRunning = true; - taskWorkerLock.notifyAll(); - } - while(!shouldStop) { - try { - ArrayList localTasks=null; - - // wait for something todo .. - synchronized(taskWorkerLock) { - while(!shouldStop && tasks.size()==0) { - try { - taskWorkerLock.wait(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - // seq. process all tasks until no blocking one exists in the list - for(Iterator i = tasks.iterator(); tasksBlock.size()>0 && i.hasNext(); ) { - Runnable task = (Runnable) i.next(); - task.run(); - i.remove(); - tasksBlock.remove(task); - } - - // take over the tasks .. - if(tasks.size()>0) { - localTasks = tasks; - tasks = new ArrayList(); - } - taskWorkerLock.notifyAll(); - } - - // seq. process all unblocking tasks .. - if(null!=localTasks) { - for(Iterator i = localTasks.iterator(); i.hasNext(); ) { - Runnable task = (Runnable) i.next(); - task.run(); - } - } - } catch (Throwable t) { - // handle errors .. - t.printStackTrace(); - } finally { - // epilog - unlock locked stuff - } - } - if(DEBUG) System.err.println("MainThread.run(): "+Thread.currentThread().getName()+" fin"); - synchronized(taskWorkerLock) { - isRunning = false; - isExit = true; - taskWorkerLock.notifyAll(); - } - } -} - - diff --git a/src/newt/classes/com/sun/javafx/newt/windows/WindowsDisplay.java b/src/newt/classes/com/sun/javafx/newt/windows/WindowsDisplay.java deleted file mode 100755 index 80485ed67..000000000 --- a/src/newt/classes/com/sun/javafx/newt/windows/WindowsDisplay.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.windows; - -import javax.media.nativewindow.*; -import javax.media.nativewindow.windows.*; -import com.sun.javafx.newt.*; -import com.sun.javafx.newt.impl.*; - -public class WindowsDisplay extends Display { - - protected static final String WINDOW_CLASS_NAME = "NewtWindowClass"; - private static int windowClassAtom; - private static long hInstance; - - static { - NativeLibLoader.loadNEWT(); - - if (!WindowsWindow.initIDs()) { - throw new NativeWindowException("Failed to initialize WindowsWindow jmethodIDs"); - } - } - - public static void initSingleton() { - // just exist to ensure static init has been run - } - - - public WindowsDisplay() { - } - - protected void createNative() { - aDevice = new WindowsGraphicsDevice(); - } - - protected void closeNative() { - // Can't do .. only at application shutdown - // UnregisterWindowClass(getWindowClassAtom(), getHInstance()); - } - - protected void dispatchMessages() { - DispatchMessages(); - } - - protected static synchronized int getWindowClassAtom() { - if(0 == windowClassAtom) { - windowClassAtom = RegisterWindowClass(WINDOW_CLASS_NAME, getHInstance()); - if (0 == windowClassAtom) { - throw new NativeWindowException("Error while registering window class"); - } - } - return windowClassAtom; - } - - protected static synchronized long getHInstance() { - if(0 == hInstance) { - hInstance = LoadLibraryW("newt"); - if (0 == hInstance) { - throw new NativeWindowException("Error finding HINSTANCE for \"newt\""); - } - } - return hInstance; - } - - //---------------------------------------------------------------------- - // Internals only - // - private static native long LoadLibraryW(String libraryName); - private static native int RegisterWindowClass(String windowClassName, long hInstance); - private static native void UnregisterWindowClass(int wndClassAtom, long hInstance); - - private static native void DispatchMessages(); -} - diff --git a/src/newt/classes/com/sun/javafx/newt/windows/WindowsScreen.java b/src/newt/classes/com/sun/javafx/newt/windows/WindowsScreen.java deleted file mode 100755 index 87ae1b49d..000000000 --- a/src/newt/classes/com/sun/javafx/newt/windows/WindowsScreen.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.windows; - -import com.sun.javafx.newt.*; -import com.sun.javafx.newt.impl.*; -import javax.media.nativewindow.*; - -public class WindowsScreen extends Screen { - static { - WindowsDisplay.initSingleton(); - } - - - public WindowsScreen() { - } - - protected void createNative(int index) { - aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); - setScreenSize(getWidthImpl(getIndex()), getHeightImpl(getIndex())); - } - - protected void closeNative() { } - - private native int getWidthImpl(int scrn_idx); - private native int getHeightImpl(int scrn_idx); -} diff --git a/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java b/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java deleted file mode 100755 index 1b5bf80cf..000000000 --- a/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.windows; - -import javax.media.nativewindow.*; -import com.sun.javafx.newt.*; - -public class WindowsWindow extends Window { - - private long hmon; - private long hdc; - private long windowHandleClose; - private long parentWindowHandle; - // non fullscreen dimensions .. - private int nfs_width, nfs_height, nfs_x, nfs_y; - private final Insets insets = new Insets(0, 0, 0, 0); - - static { - WindowsDisplay.initSingleton(); - } - - public WindowsWindow() { - } - - Thread hdcOwner = null; - - public synchronized int lockSurface() throws NativeWindowException { - int res = super.lockSurface(); - if(LOCK_SUCCESS==res && 0!=windowHandle) { - if(hdc!=0) { - throw new NativeWindowException("NEWT Surface handle set HDC "+toHexString(hdc)+" - "+Thread.currentThread().getName()+" ; "+this); - } - hdc = GetDC(windowHandle); - hmon = MonitorFromWindow(windowHandle); - hdcOwner = Thread.currentThread(); - } - return res; - } - - public synchronized void unlockSurface() { - // prevalidate, before we change data .. - Thread cur = Thread.currentThread(); - if ( getSurfaceLockOwner() != cur ) { - getLockedStack().printStackTrace(); - throw new NativeWindowException(cur+": Not owner, owner is "+getSurfaceLockOwner()); - } - if (0!=hdc && 0!=windowHandle) { - if(hdcOwner != cur) { - throw new NativeWindowException("NEWT Surface handle set HDC "+toHexString(hdc)+" by other thread "+hdcOwner+", this "+cur+" ; "+this); - } - ReleaseDC(windowHandle, hdc); - hdc=0; - hdcOwner=null; - } - super.unlockSurface(); - } - - public long getSurfaceHandle() { - return hdc; - } - - public boolean hasDeviceChanged() { - if(0!=windowHandle) { - long _hmon = MonitorFromWindow(windowHandle); - if (hmon != _hmon) { - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - Exception e = new Exception("!!! Window Device Changed "+Thread.currentThread().getName()+ - ", HMON "+toHexString(hmon)+" -> "+toHexString(_hmon)); - e.printStackTrace(); - } - hmon = _hmon; - return true; - } - } - return false; - } - - protected void createNative(long parentWindowHandle, Capabilities caps) { - WindowsScreen screen = (WindowsScreen) getScreen(); - WindowsDisplay display = (WindowsDisplay) screen.getDisplay(); - config = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, screen.getGraphicsScreen()); - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - windowHandle = CreateWindow(parentWindowHandle, - display.getWindowClassAtom(), display.WINDOW_CLASS_NAME, display.getHInstance(), - 0, undecorated, x, y, width, height); - if (windowHandle == 0) { - throw new NativeWindowException("Error creating window"); - } - this.parentWindowHandle = parentWindowHandle; - windowHandleClose = windowHandle; - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - Exception e = new Exception("!!! Window new window handle "+Thread.currentThread().getName()+ - " (Parent HWND "+toHexString(parentWindowHandle)+ - ") : HWND "+toHexString(windowHandle)+", "+Thread.currentThread()); - e.printStackTrace(); - } - } - - protected void closeNative() { - if (hdc != 0) { - if(windowHandleClose != 0) { - ReleaseDC(windowHandleClose, hdc); - } - hdc = 0; - } - if(windowHandleClose != 0) { - DestroyWindow(windowHandleClose); - windowHandleClose = 0; - } - } - - protected void windowDestroyed() { - windowHandleClose = 0; - super.windowDestroyed(); - } - - public void setVisible(boolean visible) { - if(this.visible!=visible && 0!=windowHandle) { - this.visible=visible; - setVisible0(windowHandle, visible); - } - } - - // @Override - public void setSize(int width, int height) { - if (0!=windowHandle && (width != this.width || this.height != height)) { - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - this.width = width; - this.height = height; - setSize0(parentWindowHandle, windowHandle, x, y, width, height); - } - } - - //@Override - public void setPosition(int x, int y) { - if (0!=windowHandle && (this.x != x || this.y != y)) { - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - this.x = x; - this.y = y; - setPosition(parentWindowHandle, windowHandle, x , y); - } - } - - public boolean setFullscreen(boolean fullscreen) { - if(0!=windowHandle && (this.fullscreen!=fullscreen)) { - int x,y,w,h; - this.fullscreen=fullscreen; - if(fullscreen) { - x = 0; y = 0; - w = screen.getWidth(); - h = screen.getHeight(); - } else { - x = nfs_x; - y = nfs_y; - w = nfs_width; - h = nfs_height; - } - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("WindowsWindow fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); - } - setFullscreen0(parentWindowHandle, windowHandle, x, y, w, h, undecorated, fullscreen); - } - return fullscreen; - } - - // @Override - public void requestFocus() { - super.requestFocus(); - if (windowHandle != 0L) { - requestFocus(windowHandle); - } - } - - // @Override - public void setTitle(String title) { - if (title == null) { - title = ""; - } - if (0!=windowHandle && !title.equals(getTitle())) { - super.setTitle(title); - setTitle(windowHandle, title); - } - } - - public Insets getInsets() { - return (Insets)insets.clone(); - } - - //---------------------------------------------------------------------- - // Internals only - // - protected static native boolean initIDs(); - private native long CreateWindow(long parentWindowHandle, - int wndClassAtom, String wndName, - long hInstance, long visualID, - boolean isUndecorated, - int x, int y, int width, int height); - private native void DestroyWindow(long windowHandle); - private native long GetDC(long windowHandle); - private native void ReleaseDC(long windowHandle, long hdc); - private native long MonitorFromWindow(long windowHandle); - private static native void setVisible0(long windowHandle, boolean visible); - private native void setSize0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height); - private native void setPosition(long parentWindowHandle, long windowHandle, int x, int y); - private native void setFullscreen0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height, boolean isUndecorated, boolean on); - private static native void setTitle(long windowHandle, String title); - private static native void requestFocus(long windowHandle); - - private void insetsChanged(int left, int top, int right, int bottom) { - if (left != -1 && top != -1 && right != -1 && bottom != -1) { - insets.left = left; - insets.top = top; - insets.right = right; - insets.bottom = bottom; - } - } - private void sizeChanged(int newWidth, int newHeight) { - width = newWidth; - height = newHeight; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); - } - - private void positionChanged(int newX, int newY) { - x = newX; - y = newY; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); - } - - /** - * - * @param focusOwner if focusGained is true, focusOwner is the previous - * focus owner, if focusGained is false, focusOwner is the new focus owner - * @param focusGained - */ - private void focusChanged(long focusOwner, boolean focusGained) { - if (focusGained) { - sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); - } else { - sendWindowEvent(WindowEvent.EVENT_WINDOW_LOST_FOCUS); - } - } -} diff --git a/src/newt/classes/com/sun/javafx/newt/x11/X11Display.java b/src/newt/classes/com/sun/javafx/newt/x11/X11Display.java deleted file mode 100755 index ae23c4423..000000000 --- a/src/newt/classes/com/sun/javafx/newt/x11/X11Display.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.x11; - -import javax.media.nativewindow.*; -import javax.media.nativewindow.x11.*; -import com.sun.javafx.newt.*; -import com.sun.javafx.newt.impl.*; -import com.sun.nativewindow.impl.x11.X11Util; - -public class X11Display extends Display { - static { - NativeLibLoader.loadNEWT(); - - if (!initIDs()) { - throw new NativeWindowException("Failed to initialize X11Display jmethodIDs"); - } - - if (!X11Window.initIDs()) { - throw new NativeWindowException("Failed to initialize X11Window jmethodIDs"); - } - } - - public static void initSingleton() { - // just exist to ensure static init has been run - } - - - public X11Display() { - } - - protected void createNative() { - long handle= X11Util.getThreadLocalDisplay(name); - if (handle == 0 ) { - throw new RuntimeException("Error creating display: "+name); - } - try { - CompleteDisplay(handle); - } catch(RuntimeException e) { - X11Util.closeThreadLocalDisplay(name); - throw e; - } - aDevice = new X11GraphicsDevice(handle); - } - - protected void closeNative() { - if(0==X11Util.closeThreadLocalDisplay(name)) { - throw new NativeWindowException(this+" was not mapped"); - } - } - - protected void dispatchMessages() { - DispatchMessages(getHandle(), javaObjectAtom, windowDeleteAtom); - } - - protected void lockDisplay() { - super.lockDisplay(); - LockDisplay(getHandle()); - } - - protected void unlockDisplay() { - UnlockDisplay(getHandle()); - super.unlockDisplay(); - } - - protected long getJavaObjectAtom() { return javaObjectAtom; } - protected long getWindowDeleteAtom() { return windowDeleteAtom; } - - //---------------------------------------------------------------------- - // Internals only - // - private static native boolean initIDs(); - - private native void LockDisplay(long handle); - private native void UnlockDisplay(long handle); - - private native void CompleteDisplay(long handle); - - private native void DispatchMessages(long display, long javaObjectAtom, long windowDeleteAtom); - - private void displayCompleted(long javaObjectAtom, long windowDeleteAtom) { - this.javaObjectAtom=javaObjectAtom; - this.windowDeleteAtom=windowDeleteAtom; - } - - private long windowDeleteAtom; - private long javaObjectAtom; -} - diff --git a/src/newt/classes/com/sun/javafx/newt/x11/X11Screen.java b/src/newt/classes/com/sun/javafx/newt/x11/X11Screen.java deleted file mode 100755 index cee576e2c..000000000 --- a/src/newt/classes/com/sun/javafx/newt/x11/X11Screen.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.x11; - -import com.sun.javafx.newt.*; -import com.sun.javafx.newt.impl.*; -import javax.media.nativewindow.*; -import javax.media.nativewindow.x11.*; - -public class X11Screen extends Screen { - - static { - X11Display.initSingleton(); - } - - - public X11Screen() { - } - - protected void createNative(int index) { - long handle = GetScreen(display.getHandle(), index); - if (handle == 0 ) { - throw new RuntimeException("Error creating screen: "+index); - } - aScreen = new X11GraphicsScreen((X11GraphicsDevice)getDisplay().getGraphicsDevice(), index); - setScreenSize(getWidth0(display.getHandle(), index), - getHeight0(display.getHandle(), index)); - } - - protected void closeNative() { } - - //---------------------------------------------------------------------- - // Internals only - // - - private native long GetScreen(long dpy, int scrn_idx); - private native int getWidth0(long display, int scrn_idx); - private native int getHeight0(long display, int scrn_idx); -} - diff --git a/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java b/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java deleted file mode 100755 index f46ae9564..000000000 --- a/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.sun.javafx.newt.x11; - -import com.sun.javafx.newt.*; -import com.sun.javafx.newt.impl.*; -import javax.media.nativewindow.*; -import javax.media.nativewindow.x11.*; - -public class X11Window extends Window { - private static final String WINDOW_CLASS_NAME = "NewtWindow"; - // non fullscreen dimensions .. - private int nfs_width, nfs_height, nfs_x, nfs_y; - - static { - X11Display.initSingleton(); - } - - public X11Window() { - } - - protected void createNative(long parentWindowHandle, Capabilities caps) { - X11Screen screen = (X11Screen) getScreen(); - X11Display display = (X11Display) screen.getDisplay(); - config = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, screen.getGraphicsScreen()); - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - X11GraphicsConfiguration x11config = (X11GraphicsConfiguration) config; - long visualID = x11config.getVisualID(); - long w = CreateWindow(parentWindowHandle, - display.getHandle(), screen.getIndex(), visualID, - display.getJavaObjectAtom(), display.getWindowDeleteAtom(), x, y, width, height); - if (w == 0 || w!=windowHandle) { - throw new NativeWindowException("Error creating window: "+w); - } - this.parentWindowHandle = parentWindowHandle; - windowHandleClose = windowHandle; - displayHandleClose = display.getHandle(); - } - - protected void closeNative() { - if(0!=displayHandleClose && 0!=windowHandleClose && null!=getScreen() ) { - X11Display display = (X11Display) getScreen().getDisplay(); - CloseWindow(displayHandleClose, windowHandleClose, display.getJavaObjectAtom()); - windowHandleClose = 0; - displayHandleClose = 0; - } - } - - protected void windowDestroyed() { - windowHandleClose = 0; - displayHandleClose = 0; - super.windowDestroyed(); - } - - public void setVisible(boolean visible) { - if(0!=windowHandle && this.visible!=visible) { - this.visible=visible; - setVisible0(getDisplayHandle(), windowHandle, visible); - clearEventMask(); - } - } - - public void requestFocus() { - super.requestFocus(); - } - - public void setSize(int width, int height) { - if(DEBUG_IMPLEMENTATION) { - System.err.println("X11Window setSize: "+this.x+"/"+this.y+" "+this.width+"x"+this.height+" -> "+width+"x"+height); - // Exception e = new Exception("XXXXXXXXXX"); - // e.printStackTrace(); - } - this.width = width; - this.height = height; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - if(0!=windowHandle) { - setSize0(parentWindowHandle, getDisplayHandle(), getScreenIndex(), windowHandle, x, y, width, height, (undecorated||fullscreen)?-1:1, false); - } - } - - public void setPosition(int x, int y) { - if(DEBUG_IMPLEMENTATION) { - System.err.println("X11Window setPosition: "+this.x+"/"+this.y+" -> "+x+"/"+y); - // Exception e = new Exception("XXXXXXXXXX"); - // e.printStackTrace(); - } - this.x = x; - this.y = y; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - if(0!=windowHandle) { - setPosition0(getDisplayHandle(), windowHandle, x, y); - } - } - - public boolean setFullscreen(boolean fullscreen) { - if(0!=windowHandle && this.fullscreen!=fullscreen) { - int x,y,w,h; - this.fullscreen=fullscreen; - if(fullscreen) { - x = 0; y = 0; - w = screen.getWidth(); - h = screen.getHeight(); - } else { - x = nfs_x; - y = nfs_y; - w = nfs_width; - h = nfs_height; - } - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("X11Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); - } - setSize0(parentWindowHandle, getDisplayHandle(), getScreenIndex(), windowHandle, x, y, w, h, (undecorated||fullscreen)?-1:1, false); - } - return fullscreen; - } - - //---------------------------------------------------------------------- - // Internals only - // - - protected static native boolean initIDs(); - private native long CreateWindow(long parentWindowHandle, long display, int screen_index, - long visualID, long javaObjectAtom, long windowDeleteAtom, int x, int y, int width, int height); - private native void CloseWindow(long display, long windowHandle, long javaObjectAtom); - private native void setVisible0(long display, long windowHandle, boolean visible); - private native void setSize0(long parentWindowHandle, long display, int screen_index, long windowHandle, - int x, int y, int width, int height, int decorationToggle, boolean setVisible); - private native void setPosition0(long display, long windowHandle, int x, int y); - - private void windowChanged(int newX, int newY, int newWidth, int newHeight) { - if(width != newWidth || height != newHeight) { - if(DEBUG_IMPLEMENTATION) { - System.err.println("X11Window windowChanged size: "+this.width+"x"+this.height+" -> "+newWidth+"x"+newHeight); - } - width = newWidth; - height = newHeight; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); - } - if( 0==parentWindowHandle && ( x != newX || y != newY ) ) { - if(DEBUG_IMPLEMENTATION) { - System.err.println("X11Window windowChanged position: "+this.x+"/"+this.y+" -> "+newX+"x"+newY); - } - x = newX; - y = newY; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); - } - } - - private void windowCreated(long windowHandle) { - this.windowHandle = windowHandle; - } - - private long windowHandleClose; - private long displayHandleClose; - private long parentWindowHandle; -} diff --git a/src/newt/native/BroadcomEGL.c b/src/newt/native/BroadcomEGL.c index 55688f9d1..8a9c5f948 100755 --- a/src/newt/native/BroadcomEGL.c +++ b/src/newt/native/BroadcomEGL.c @@ -41,7 +41,7 @@ #include #include -#include "com_sun_javafx_newt_opengl_broadcom_egl_Window.h" +#include "com_jogamp_javafx_newt_opengl_broadcom_egl_Window.h" #include "EventListener.h" #include "MouseEvent.h" @@ -72,7 +72,7 @@ static jmethodID windowCreatedID = NULL; * Display */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_broadcom_egl_Display_DispatchMessages +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_broadcom_egl_Display_DispatchMessages (JNIEnv *env, jobject obj) { // FIXME: n/a @@ -80,7 +80,7 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_broadcom_egl_Display_Disp (void) obj; } -JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_opengl_broadcom_egl_Display_CreateDisplay +JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_opengl_broadcom_egl_Display_CreateDisplay (JNIEnv *env, jobject obj, jint width, jint height) { (void) env; @@ -94,7 +94,7 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_opengl_broadcom_egl_Display_Cre return (jlong) (intptr_t) dpy; } -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_broadcom_egl_Display_DestroyDisplay +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_broadcom_egl_Display_DestroyDisplay (JNIEnv *env, jobject obj, jlong display) { EGLDisplay dpy = (EGLDisplay)(intptr_t)display; @@ -111,7 +111,7 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_broadcom_egl_Display_Dest * Window */ -JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_opengl_broadcom_egl_Window_initIDs +JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_opengl_broadcom_egl_Window_initIDs (JNIEnv *env, jclass clazz) { windowCreatedID = (*env)->GetMethodID(env, clazz, "windowCreated", "(III)V"); @@ -123,7 +123,7 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_opengl_broadcom_egl_Window_i return JNI_TRUE; } -JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_opengl_broadcom_egl_Window_CreateWindow +JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_opengl_broadcom_egl_Window_CreateWindow (JNIEnv *env, jobject obj, jlong display, jboolean chromaKey, jint width, jint height) { EGLDisplay dpy = (EGLDisplay)(intptr_t)display; @@ -167,7 +167,7 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_opengl_broadcom_egl_Window_Crea return (jlong) (intptr_t) window; } -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_broadcom_egl_Window_CloseWindow +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_broadcom_egl_Window_CloseWindow (JNIEnv *env, jobject obj, jlong display, jlong window) { EGLDisplay dpy = (EGLDisplay) (intptr_t) display; @@ -180,7 +180,7 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_broadcom_egl_Window_Close DBG_PRINT( "[CloseWindow] X\n"); } -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_broadcom_egl_Window_SwapWindow +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_broadcom_egl_Window_SwapWindow (JNIEnv *env, jobject obj, jlong display, jlong window) { EGLDisplay dpy = (EGLDisplay) (intptr_t) display; diff --git a/src/newt/native/IntelGDL.c b/src/newt/native/IntelGDL.c index 1bc43cd0e..77f582885 100644 --- a/src/newt/native/IntelGDL.c +++ b/src/newt/native/IntelGDL.c @@ -37,9 +37,9 @@ #include #include -#include "com_sun_javafx_newt_intel_gdl_Display.h" -#include "com_sun_javafx_newt_intel_gdl_Screen.h" -#include "com_sun_javafx_newt_intel_gdl_Window.h" +#include "com_jogamp_javafx_newt_intel_gdl_Display.h" +#include "com_jogamp_javafx_newt_intel_gdl_Screen.h" +#include "com_jogamp_javafx_newt_intel_gdl_Window.h" #include "EventListener.h" #include "MouseEvent.h" @@ -123,7 +123,7 @@ static void JNI_ThrowNew(JNIEnv *env, const char *throwable, const char* message * Display */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_intel_gdl_Display_DispatchMessages +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Display_DispatchMessages (JNIEnv *env, jobject obj, jlong displayHandle, jobject focusedWindow) { // FIXME: n/a @@ -138,7 +138,7 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_intel_gdl_Display_DispatchMessag } */ } -JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_intel_gdl_Display_CreateDisplay +JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Display_CreateDisplay (JNIEnv *env, jobject obj) { gdl_ret_t retval; @@ -171,7 +171,7 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_intel_gdl_Display_CreateDisplay return (jlong) (intptr_t) p_driver_info; } -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_intel_gdl_Display_DestroyDisplay +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Display_DestroyDisplay (JNIEnv *env, jobject obj, jlong displayHandle) { gdl_driver_info_t * p_driver_info = (gdl_driver_info_t *) (intptr_t) displayHandle; @@ -190,7 +190,7 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_intel_gdl_Display_DestroyDisplay * Screen */ -JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_intel_gdl_Screen_initIDs +JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Screen_initIDs (JNIEnv *env, jclass clazz) { screenCreatedID = (*env)->GetMethodID(env, clazz, "screenCreated", "(II)V"); @@ -202,7 +202,7 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_intel_gdl_Screen_initIDs return JNI_TRUE; } -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_intel_gdl_Screen_GetScreenInfo +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Screen_GetScreenInfo (JNIEnv *env, jobject obj, jlong displayHandle, jint idx) { gdl_driver_info_t * p_driver_info = (gdl_driver_info_t *) (intptr_t) displayHandle; @@ -234,7 +234,7 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_intel_gdl_Screen_GetScreenInfo * Window */ -JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_intel_gdl_Window_initIDs +JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Window_initIDs (JNIEnv *env, jclass clazz) { updateBoundsID = (*env)->GetMethodID(env, clazz, "updateBounds", "(IIII)V"); @@ -246,7 +246,7 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_intel_gdl_Window_initIDs return JNI_TRUE; } -JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_intel_gdl_Window_CreateSurface +JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Window_CreateSurface (JNIEnv *env, jobject obj, jlong displayHandle, jint scr_width, jint scr_height, jint x, jint y, jint width, jint height) { gdl_driver_info_t * p_driver_info = (gdl_driver_info_t *) (intptr_t) displayHandle; @@ -339,7 +339,7 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_intel_gdl_Window_CreateSurface return (jlong) (intptr_t) plane; } -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_intel_gdl_Window_CloseSurface +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Window_CloseSurface (JNIEnv *env, jobject obj, jlong display, jlong surface) { gdl_plane_id_t plane = (gdl_plane_id_t) (intptr_t) surface ; @@ -348,7 +348,7 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_intel_gdl_Window_CloseSurface DBG_PRINT("[CloseSurface] plane %d\n", plane); } -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_intel_gdl_Window_SetBounds0 +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Window_SetBounds0 (JNIEnv *env, jobject obj, jlong surface, jint scr_width, jint scr_height, jint x, jint y, jint width, jint height) { gdl_plane_id_t plane = (gdl_plane_id_t) (intptr_t) surface ; diff --git a/src/newt/native/KDWindow.c b/src/newt/native/KDWindow.c index 6c7aa7731..31e8017f4 100755 --- a/src/newt/native/KDWindow.c +++ b/src/newt/native/KDWindow.c @@ -64,7 +64,7 @@ #include #include -#include "com_sun_javafx_newt_opengl_kd_KDWindow.h" +#include "com_jogamp_javafx_newt_opengl_kd_KDWindow.h" #include "EventListener.h" #include "MouseEvent.h" @@ -103,7 +103,7 @@ static jmethodID sendKeyEventID = NULL; * Display */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_kd_KDDisplay_DispatchMessages +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDDisplay_DispatchMessages (JNIEnv *env, jobject obj) { const KDEvent * evt; @@ -200,7 +200,7 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_kd_KDDisplay_DispatchMess * Window */ -JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_opengl_kd_KDWindow_initIDs +JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDWindow_initIDs (JNIEnv *env, jclass clazz) { #ifdef VERBOSE_ON @@ -228,7 +228,7 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_opengl_kd_KDWindow_initIDs return JNI_TRUE; } -JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_opengl_kd_KDWindow_CreateWindow +JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDWindow_CreateWindow (JNIEnv *env, jobject obj, jlong display, jintArray jAttrs) { jint * attrs = NULL; @@ -270,7 +270,7 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_opengl_kd_KDWindow_CreateWindow return (jlong) (intptr_t) window; } -JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_opengl_kd_KDWindow_RealizeWindow +JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDWindow_RealizeWindow (JNIEnv *env, jobject obj, jlong window) { KDWindow *w = (KDWindow*) (intptr_t) window; @@ -285,7 +285,7 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_opengl_kd_KDWindow_RealizeWindo return (jlong) (intptr_t) nativeWindow; } -JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_opengl_kd_KDWindow_CloseWindow +JNIEXPORT jint JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDWindow_CloseWindow (JNIEnv *env, jobject obj, jlong window, jlong juserData) { KDWindow *w = (KDWindow*) (intptr_t) window; @@ -299,11 +299,11 @@ JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_opengl_kd_KDWindow_CloseWindow } /* - * Class: com_sun_javafx_newt_opengl_kd_KDWindow + * Class: com_jogamp_javafx_newt_opengl_kd_KDWindow * Method: setVisible0 * Signature: (JJZ)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_kd_KDWindow_setVisible0 +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDWindow_setVisible0 (JNIEnv *env, jobject obj, jlong window, jboolean visible) { KDWindow *w = (KDWindow*) (intptr_t) window; @@ -312,7 +312,7 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_kd_KDWindow_setVisible0 DBG_PRINT( "[setVisible] v=%d\n", visible); } -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_kd_KDWindow_setFullScreen0 +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDWindow_setFullScreen0 (JNIEnv *env, jobject obj, jlong window, jboolean fullscreen) { KDWindow *w = (KDWindow*) (intptr_t) window; @@ -323,7 +323,7 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_kd_KDWindow_setFullScreen (void)res; } -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_kd_KDWindow_setSize0 +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDWindow_setSize0 (JNIEnv *env, jobject obj, jlong window, jint width, jint height) { KDWindow *w = (KDWindow*) (intptr_t) window; diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c index 5445ca372..d39b96d0b 100755 --- a/src/newt/native/WindowsWindow.c +++ b/src/newt/native/WindowsWindow.c @@ -89,7 +89,7 @@ #define MONITOR_DEFAULTTONEAREST 2 #endif -#include "com_sun_javafx_newt_windows_WindowsWindow.h" +#include "com_jogamp_javafx_newt_windows_WindowsWindow.h" #include "EventListener.h" #include "MouseEvent.h" @@ -902,11 +902,11 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, } /* - * Class: com_sun_javafx_newt_windows_WindowsDisplay + * Class: com_jogamp_javafx_newt_windows_WindowsDisplay * Method: DispatchMessages * Signature: ()V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsDisplay_DispatchMessages +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsDisplay_DispatchMessages (JNIEnv *env, jclass clazz) { int i = 0; @@ -925,11 +925,11 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsDisplay_DispatchM } /* - * Class: com_sun_javafx_newt_windows_WindowsDisplay + * Class: com_jogamp_javafx_newt_windows_WindowsDisplay * Method: LoadLibraryW * Signature: (Ljava/lang/String;)J */ -JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsDisplay_LoadLibraryW +JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_windows_WindowsDisplay_LoadLibraryW (JNIEnv *env, jclass clazz, jstring dllName) { jchar* _dllName = GetNullTerminatedStringChars(env, dllName); @@ -939,11 +939,11 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsDisplay_LoadLibr } /* - * Class: com_sun_javafx_newt_windows_WindowsDisplay + * Class: com_jogamp_javafx_newt_windows_WindowsDisplay * Method: RegisterWindowClass * Signature: (Ljava/lang/String;J)I */ -JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_windows_WindowsDisplay_RegisterWindowClass +JNIEXPORT jint JNICALL Java_com_jogamp_javafx_newt_windows_WindowsDisplay_RegisterWindowClass (JNIEnv *env, jclass clazz, jstring wndClassName, jlong hInstance) { ATOM res; @@ -979,44 +979,44 @@ JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_windows_WindowsDisplay_RegisterW } /* - * Class: com_sun_javafx_newt_windows_WindowsDisplay + * Class: com_jogamp_javafx_newt_windows_WindowsDisplay * Method: CleanupWindowResources * Signature: (java/lang/String;J)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsDisplay_UnregisterWindowClass +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsDisplay_UnregisterWindowClass (JNIEnv *env, jclass clazz, jint wndClassAtom, jlong hInstance) { UnregisterClass(MAKEINTATOM(wndClassAtom), (HINSTANCE) (intptr_t) hInstance); } /* - * Class: com_sun_javafx_newt_windows_WindowsScreen + * Class: com_jogamp_javafx_newt_windows_WindowsScreen * Method: getWidthImpl * Signature: (I)I */ -JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_windows_WindowsScreen_getWidthImpl +JNIEXPORT jint JNICALL Java_com_jogamp_javafx_newt_windows_WindowsScreen_getWidthImpl (JNIEnv *env, jobject obj, jint scrn_idx) { return (jint)GetSystemMetrics(SM_CXSCREEN); } /* - * Class: com_sun_javafx_newt_windows_WindowsScreen + * Class: com_jogamp_javafx_newt_windows_WindowsScreen * Method: getWidthImpl * Signature: (I)I */ -JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_windows_WindowsScreen_getHeightImpl +JNIEXPORT jint JNICALL Java_com_jogamp_javafx_newt_windows_WindowsScreen_getHeightImpl (JNIEnv *env, jobject obj, jint scrn_idx) { return (jint)GetSystemMetrics(SM_CYSCREEN); } /* - * Class: com_sun_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_javafx_newt_windows_WindowsWindow * Method: initIDs * Signature: ()Z */ -JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_initIDs +JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_initIDs (JNIEnv *env, jclass clazz) { sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V"); @@ -1045,11 +1045,11 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_initID } /* - * Class: com_sun_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_javafx_newt_windows_WindowsWindow * Method: CreateWindow * Signature: (JILjava/lang/String;JJZIIII)J */ -JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_CreateWindow +JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_CreateWindow (JNIEnv *env, jobject obj, jlong parent, jint wndClassAtom, jstring jWndName, jlong hInstance, jlong visualID, jboolean bIsUndecorated, jint jx, jint jy, jint defaultWidth, jint defaultHeight) @@ -1113,44 +1113,44 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_CreateWin } /* - * Class: com_sun_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_javafx_newt_windows_WindowsWindow * Method: DestroyWindow * Signature: (J)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_DestroyWindow +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_DestroyWindow (JNIEnv *env, jobject obj, jlong window) { DestroyWindow((HWND) (intptr_t) window); } /* - * Class: com_sun_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_javafx_newt_windows_WindowsWindow * Method: GetDC * Signature: (J)J */ -JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_GetDC +JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_GetDC (JNIEnv *env, jobject obj, jlong window) { return (jlong) (intptr_t) GetDC((HWND) (intptr_t) window); } /* - * Class: com_sun_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_javafx_newt_windows_WindowsWindow * Method: ReleaseDC * Signature: (JJ)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_ReleaseDC +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_ReleaseDC (JNIEnv *env, jobject obj, jlong window, jlong dc) { ReleaseDC((HWND) (intptr_t) window, (HDC) (intptr_t) dc); } /* - * Class: com_sun_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_javafx_newt_windows_WindowsWindow * Method: MonitorFromWindow * Signature: (J)J */ -JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_MonitorFromWindow +JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_MonitorFromWindow (JNIEnv *env, jobject obj, jlong window) { #if (_WIN32_WINNT >= 0x0500 || _WIN32_WINDOWS >= 0x0410 || WINVER >= 0x0500) && !defined(_WIN32_WCE) @@ -1161,11 +1161,11 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_MonitorFr } /* - * Class: com_sun_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_javafx_newt_windows_WindowsWindow * Method: setVisible0 * Signature: (JZ)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_setVisible0 +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_setVisible0 (JNIEnv *_env, jclass clazz, jlong window, jboolean visible) { HWND hWnd = (HWND) (intptr_t) window; @@ -1178,11 +1178,11 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_setVisible } /* - * Class: com_sun_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_javafx_newt_windows_WindowsWindow * Method: setSize0 * Signature: (JII)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_setSize0 +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_setSize0 (JNIEnv *env, jobject obj, jlong parent, jlong window, jint x, jint y, jint width, jint height) { HWND hwndP = (HWND) (intptr_t) parent; @@ -1215,11 +1215,11 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_setSize0 } /* - * Class: com_sun_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_javafx_newt_windows_WindowsWindow * Method: setPosition * Signature: (JII)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_setPosition +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_setPosition (JNIEnv *env, jobject obj, jlong parent, jlong window, jint x, jint y) { UINT flags = SWP_NOACTIVATE | SWP_NOSIZE; @@ -1236,11 +1236,11 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_setPositio } /* - * Class: com_sun_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_javafx_newt_windows_WindowsWindow * Method: setFullscreen * Signature: (JIIIIZZ)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_setFullscreen0 +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_setFullscreen0 (JNIEnv *env, jobject obj, jlong parent, jlong window, jint x, jint y, jint width, jint height, jboolean bIsUndecorated, jboolean on) { UINT flags; @@ -1272,11 +1272,11 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_setFullscr } /* - * Class: com_sun_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_javafx_newt_windows_WindowsWindow * Method: setTitle * Signature: (JLjava/lang/String;)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_setTitle +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_setTitle (JNIEnv *env, jclass clazz, jlong window, jstring title) { HWND hwnd = (HWND) (intptr_t) window; @@ -1290,11 +1290,11 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_setTitle } /* - * Class: com_sun_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_javafx_newt_windows_WindowsWindow * Method: requestFocus * Signature: (J)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_requestFocus +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_requestFocus (JNIEnv *env, jclass clazz, jlong window) { HWND hwnd = (HWND) (intptr_t) window; diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index b6b2bbe26..682184da0 100755 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -46,7 +46,7 @@ #include #include -#include "com_sun_javafx_newt_x11_X11Window.h" +#include "com_jogamp_javafx_newt_x11_X11Window.h" #include "EventListener.h" #include "MouseEvent.h" @@ -154,7 +154,7 @@ static const char * const ClazzNameRuntimeException = static jclass runtimeExceptionClz=NULL; static const char * const ClazzNameNewtWindow = - "com/sun/javafx/newt/Window"; + "com/jogamp/javafx/newt/Window"; static jclass newtWindowClz=NULL; static jmethodID windowChangedID = NULL; @@ -187,11 +187,11 @@ static void _throwNewRuntimeException(Display * unlockDisplay, JNIEnv *env, cons */ /* - * Class: com_sun_javafx_newt_x11_X11Display + * Class: com_jogamp_javafx_newt_x11_X11Display * Method: initIDs * Signature: ()Z */ -JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_x11_X11Display_initIDs +JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_x11_X11Display_initIDs (JNIEnv *env, jclass clazz) { jclass c; @@ -237,11 +237,11 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_x11_X11Display_initIDs } /* - * Class: com_sun_javafx_newt_x11_X11Display + * Class: com_jogamp_javafx_newt_x11_X11Display * Method: LockDisplay * Signature: (J)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Display_LockDisplay +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Display_LockDisplay (JNIEnv *env, jobject obj, jlong display) { Display * dpy = (Display *)(intptr_t)display; @@ -253,11 +253,11 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Display_LockDisplay /* - * Class: com_sun_javafx_newt_x11_X11Display + * Class: com_jogamp_javafx_newt_x11_X11Display * Method: UnlockDisplay * Signature: (J)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Display_UnlockDisplay +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Display_UnlockDisplay (JNIEnv *env, jobject obj, jlong display) { Display * dpy = (Display *)(intptr_t)display; @@ -269,11 +269,11 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Display_UnlockDisplay /* - * Class: com_sun_javafx_newt_x11_X11Display + * Class: com_jogamp_javafx_newt_x11_X11Display * Method: CompleteDisplay * Signature: (J)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Display_CompleteDisplay +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Display_CompleteDisplay (JNIEnv *env, jobject obj, jlong display) { Display * dpy = (Display *)(intptr_t)display; @@ -381,11 +381,11 @@ static jobject getJavaWindowProperty(JNIEnv *env, Display *dpy, Window window, j } /* - * Class: com_sun_javafx_newt_x11_X11Display + * Class: com_jogamp_javafx_newt_x11_X11Display * Method: DispatchMessages * Signature: (JIJJ)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Display_DispatchMessages +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Display_DispatchMessages (JNIEnv *env, jobject obj, jlong display, jlong javaObjectAtom, jlong wmDeleteAtom) { Display * dpy = (Display *) (intptr_t) display; @@ -532,11 +532,11 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Display_DispatchMessages */ /* - * Class: com_sun_javafx_newt_x11_X11Screen + * Class: com_jogamp_javafx_newt_x11_X11Screen * Method: GetScreen * Signature: (JI)J */ -JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_x11_X11Screen_GetScreen +JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_x11_X11Screen_GetScreen (JNIEnv *env, jobject obj, jlong display, jint screen_index) { Display * dpy = (Display *)(intptr_t)display; @@ -559,14 +559,14 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_x11_X11Screen_GetScreen return (jlong) (intptr_t) scrn; } -JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_x11_X11Screen_getWidth0 +JNIEXPORT jint JNICALL Java_com_jogamp_javafx_newt_x11_X11Screen_getWidth0 (JNIEnv *env, jobject obj, jlong display, jint scrn_idx) { Display * dpy = (Display *) (intptr_t) display; return (jint) XDisplayWidth( dpy, scrn_idx); } -JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_x11_X11Screen_getHeight0 +JNIEXPORT jint JNICALL Java_com_jogamp_javafx_newt_x11_X11Screen_getHeight0 (JNIEnv *env, jobject obj, jlong display, jint scrn_idx) { Display * dpy = (Display *) (intptr_t) display; @@ -579,11 +579,11 @@ JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_x11_X11Screen_getHeight0 */ /* - * Class: com_sun_javafx_newt_x11_X11Window + * Class: com_jogamp_javafx_newt_x11_X11Window * Method: initIDs * Signature: ()Z */ -JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_x11_X11Window_initIDs +JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_x11_X11Window_initIDs (JNIEnv *env, jclass clazz) { windowChangedID = (*env)->GetMethodID(env, clazz, "windowChanged", "(IIII)V"); @@ -605,11 +605,11 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_x11_X11Window_initIDs } /* - * Class: com_sun_javafx_newt_x11_X11Window + * Class: com_jogamp_javafx_newt_x11_X11Window * Method: CreateWindow * Signature: (JJIJIIII)J */ -JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_x11_X11Window_CreateWindow +JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_x11_X11Window_CreateWindow (JNIEnv *env, jobject obj, jlong parent, jlong display, jint screen_index, jlong visualID, jlong javaObjectAtom, jlong windowDeleteAtom, @@ -734,11 +734,11 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_x11_X11Window_CreateWindow } /* - * Class: com_sun_javafx_newt_x11_X11Window + * Class: com_jogamp_javafx_newt_x11_X11Window * Method: CloseWindow * Signature: (JJ)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_CloseWindow +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Window_CloseWindow (JNIEnv *env, jobject obj, jlong display, jlong window, jlong javaObjectAtom) { Display * dpy = (Display *) (intptr_t) display; @@ -779,11 +779,11 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_CloseWindow } /* - * Class: com_sun_javafx_newt_x11_X11Window + * Class: com_jogamp_javafx_newt_x11_X11Window * Method: setVisible0 * Signature: (JJZ)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_setVisible0 +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Window_setVisible0 (JNIEnv *env, jobject obj, jlong display, jlong window, jboolean visible) { Display * dpy = (Display *) (intptr_t) display; @@ -823,11 +823,11 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_setVisible0 #endif /* - * Class: com_sun_javafx_newt_x11_X11Window + * Class: com_jogamp_javafx_newt_x11_X11Window * Method: setSize0 * Signature: (JIJIIIIIZ)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_setSize0 +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Window_setSize0 (JNIEnv *env, jobject obj, jlong jparent, jlong display, jint screen_index, jlong window, jint x, jint y, jint width, jint height, jint decorationToggle, jboolean setVisible) { Display * dpy = (Display *) (intptr_t) display; @@ -887,11 +887,11 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_setSize0 } /* - * Class: com_sun_javafx_newt_x11_X11Window + * Class: com_jogamp_javafx_newt_x11_X11Window * Method: setPosition0 * Signature: (JJII)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_setPosition0 +JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Window_setPosition0 (JNIEnv *env, jobject obj, jlong display, jlong window, jint x, jint y) { Display * dpy = (Display *) (intptr_t) display; -- cgit v1.2.3 From 2d57c25287542dcbad59c6b4782e87f86bd0fbc6 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Mon, 29 Mar 2010 04:40:53 +0200 Subject: moved com.jogamp.javafx.* to com.jogamp.*. --- doc/wiki/FAQ.xml | 6 +- doxygen/doxygen-all-pub.cfg | 2 +- make/build-jogl.xml | 10 +- make/build-newt.xml | 40 +- make/build.xml | 6 +- make/newtRIversion | 2 +- make/newtRIversion-cdc | 2 +- make/newtversion | 2 +- make/newtversion-cdc | 2 +- .../com/jogamp/audio/windows/waveout/Audio.java | 66 ++ .../com/jogamp/audio/windows/waveout/Mixer.java | 362 ++++++++ .../jogamp/audio/windows/waveout/SoundBuffer.java | 124 +++ .../audio/windows/waveout/TestSpatialization.java | 89 ++ .../com/jogamp/audio/windows/waveout/Track.java | 206 +++++ .../com/jogamp/audio/windows/waveout/Vec3f.java | 212 +++++ .../jogamp/javafx/audio/windows/waveout/Audio.java | 66 -- .../jogamp/javafx/audio/windows/waveout/Mixer.java | 362 -------- .../javafx/audio/windows/waveout/SoundBuffer.java | 124 --- .../audio/windows/waveout/TestSpatialization.java | 89 -- .../jogamp/javafx/audio/windows/waveout/Track.java | 206 ----- .../jogamp/javafx/audio/windows/waveout/Vec3f.java | 212 ----- src/jogl/native/audio/Mixer.cpp | 26 +- .../native/openmax/com_sun_openmax_OMXInstance.c | 6 +- .../classes/javax/media/nativewindow/package.html | 2 +- .../classes/com/jogamp/javafx/newt/Display.java | 276 ------ src/newt/classes/com/jogamp/javafx/newt/Event.java | 86 -- .../com/jogamp/javafx/newt/EventListener.java | 44 - .../classes/com/jogamp/javafx/newt/InputEvent.java | 97 --- .../classes/com/jogamp/javafx/newt/Insets.java | 105 --- .../classes/com/jogamp/javafx/newt/KeyEvent.java | 738 ---------------- .../com/jogamp/javafx/newt/KeyListener.java | 42 - .../classes/com/jogamp/javafx/newt/MouseEvent.java | 110 --- .../com/jogamp/javafx/newt/MouseListener.java | 47 -- .../com/jogamp/javafx/newt/NewtFactory.java | 181 ---- .../com/jogamp/javafx/newt/OffscreenWindow.java | 108 --- .../classes/com/jogamp/javafx/newt/PaintEvent.java | 74 -- .../com/jogamp/javafx/newt/PaintListener.java | 42 - .../classes/com/jogamp/javafx/newt/Screen.java | 147 ---- .../classes/com/jogamp/javafx/newt/Window.java | 929 --------------------- .../com/jogamp/javafx/newt/WindowEvent.java | 67 -- .../com/jogamp/javafx/newt/WindowListener.java | 42 - .../com/jogamp/javafx/newt/awt/AWTCanvas.java | 264 ------ .../com/jogamp/javafx/newt/awt/AWTDisplay.java | 168 ---- .../com/jogamp/javafx/newt/awt/AWTScreen.java | 65 -- .../com/jogamp/javafx/newt/awt/AWTWindow.java | 429 ---------- .../classes/com/jogamp/javafx/newt/impl/Debug.java | 140 ---- .../jogamp/javafx/newt/impl/NativeLibLoader.java | 62 -- .../com/jogamp/javafx/newt/intel/gdl/Display.java | 104 --- .../com/jogamp/javafx/newt/intel/gdl/Screen.java | 68 -- .../com/jogamp/javafx/newt/intel/gdl/Window.java | 179 ---- .../com/jogamp/javafx/newt/macosx/MacDisplay.java | 82 -- .../com/jogamp/javafx/newt/macosx/MacScreen.java | 56 -- .../com/jogamp/javafx/newt/macosx/MacWindow.java | 600 ------------- .../com/jogamp/javafx/newt/opengl/GLWindow.java | 628 -------------- .../javafx/newt/opengl/broadcom/egl/Display.java | 81 -- .../javafx/newt/opengl/broadcom/egl/Screen.java | 63 -- .../javafx/newt/opengl/broadcom/egl/Window.java | 156 ---- .../jogamp/javafx/newt/opengl/kd/KDDisplay.java | 84 -- .../com/jogamp/javafx/newt/opengl/kd/KDScreen.java | 57 -- .../com/jogamp/javafx/newt/opengl/kd/KDWindow.java | 153 ---- .../javafx/newt/util/EventDispatchThread.java | 240 ------ .../com/jogamp/javafx/newt/util/MainThread.java | 307 ------- .../jogamp/javafx/newt/windows/WindowsDisplay.java | 105 --- .../jogamp/javafx/newt/windows/WindowsScreen.java | 58 -- .../jogamp/javafx/newt/windows/WindowsWindow.java | 289 ------- .../com/jogamp/javafx/newt/x11/X11Display.java | 120 --- .../com/jogamp/javafx/newt/x11/X11Screen.java | 71 -- .../com/jogamp/javafx/newt/x11/X11Window.java | 203 ----- src/newt/classes/com/jogamp/newt/Display.java | 276 ++++++ src/newt/classes/com/jogamp/newt/Event.java | 86 ++ .../classes/com/jogamp/newt/EventListener.java | 44 + src/newt/classes/com/jogamp/newt/InputEvent.java | 97 +++ src/newt/classes/com/jogamp/newt/Insets.java | 105 +++ src/newt/classes/com/jogamp/newt/KeyEvent.java | 738 ++++++++++++++++ src/newt/classes/com/jogamp/newt/KeyListener.java | 42 + src/newt/classes/com/jogamp/newt/MouseEvent.java | 110 +++ .../classes/com/jogamp/newt/MouseListener.java | 47 ++ src/newt/classes/com/jogamp/newt/NewtFactory.java | 181 ++++ .../classes/com/jogamp/newt/OffscreenWindow.java | 108 +++ src/newt/classes/com/jogamp/newt/PaintEvent.java | 74 ++ .../classes/com/jogamp/newt/PaintListener.java | 42 + src/newt/classes/com/jogamp/newt/Screen.java | 147 ++++ src/newt/classes/com/jogamp/newt/Window.java | 929 +++++++++++++++++++++ src/newt/classes/com/jogamp/newt/WindowEvent.java | 67 ++ .../classes/com/jogamp/newt/WindowListener.java | 42 + .../classes/com/jogamp/newt/awt/AWTCanvas.java | 264 ++++++ .../classes/com/jogamp/newt/awt/AWTDisplay.java | 168 ++++ .../classes/com/jogamp/newt/awt/AWTScreen.java | 65 ++ .../classes/com/jogamp/newt/awt/AWTWindow.java | 429 ++++++++++ src/newt/classes/com/jogamp/newt/impl/Debug.java | 140 ++++ .../com/jogamp/newt/impl/NativeLibLoader.java | 62 ++ .../classes/com/jogamp/newt/intel/gdl/Display.java | 104 +++ .../classes/com/jogamp/newt/intel/gdl/Screen.java | 68 ++ .../classes/com/jogamp/newt/intel/gdl/Window.java | 179 ++++ .../classes/com/jogamp/newt/macosx/MacDisplay.java | 82 ++ .../classes/com/jogamp/newt/macosx/MacScreen.java | 56 ++ .../classes/com/jogamp/newt/macosx/MacWindow.java | 600 +++++++++++++ .../classes/com/jogamp/newt/opengl/GLWindow.java | 628 ++++++++++++++ .../jogamp/newt/opengl/broadcom/egl/Display.java | 81 ++ .../jogamp/newt/opengl/broadcom/egl/Screen.java | 62 ++ .../jogamp/newt/opengl/broadcom/egl/Window.java | 154 ++++ .../com/jogamp/newt/opengl/kd/KDDisplay.java | 84 ++ .../com/jogamp/newt/opengl/kd/KDScreen.java | 57 ++ .../com/jogamp/newt/opengl/kd/KDWindow.java | 153 ++++ .../com/jogamp/newt/util/EventDispatchThread.java | 240 ++++++ .../classes/com/jogamp/newt/util/MainThread.java | 307 +++++++ .../com/jogamp/newt/windows/WindowsDisplay.java | 105 +++ .../com/jogamp/newt/windows/WindowsScreen.java | 57 ++ .../com/jogamp/newt/windows/WindowsWindow.java | 289 +++++++ .../classes/com/jogamp/newt/x11/X11Display.java | 120 +++ .../classes/com/jogamp/newt/x11/X11Screen.java | 69 ++ .../classes/com/jogamp/newt/x11/X11Window.java | 202 +++++ src/newt/native/BroadcomEGL.c | 16 +- src/newt/native/IntelGDL.c | 24 +- src/newt/native/KDWindow.c | 20 +- src/newt/native/MacWindow.m | 62 +- src/newt/native/WindowsWindow.c | 74 +- src/newt/native/X11Window.c | 56 +- 118 files changed, 9198 insertions(+), 9205 deletions(-) create mode 100755 src/jogl/classes/com/jogamp/audio/windows/waveout/Audio.java create mode 100755 src/jogl/classes/com/jogamp/audio/windows/waveout/Mixer.java create mode 100755 src/jogl/classes/com/jogamp/audio/windows/waveout/SoundBuffer.java create mode 100755 src/jogl/classes/com/jogamp/audio/windows/waveout/TestSpatialization.java create mode 100755 src/jogl/classes/com/jogamp/audio/windows/waveout/Track.java create mode 100755 src/jogl/classes/com/jogamp/audio/windows/waveout/Vec3f.java delete mode 100755 src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Audio.java delete mode 100755 src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Mixer.java delete mode 100755 src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/SoundBuffer.java delete mode 100755 src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/TestSpatialization.java delete mode 100755 src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Track.java delete mode 100755 src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Vec3f.java delete mode 100755 src/newt/classes/com/jogamp/javafx/newt/Display.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/Event.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/EventListener.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/InputEvent.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/Insets.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/KeyEvent.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/KeyListener.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/MouseEvent.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/MouseListener.java delete mode 100755 src/newt/classes/com/jogamp/javafx/newt/NewtFactory.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/OffscreenWindow.java delete mode 100755 src/newt/classes/com/jogamp/javafx/newt/PaintEvent.java delete mode 100755 src/newt/classes/com/jogamp/javafx/newt/PaintListener.java delete mode 100755 src/newt/classes/com/jogamp/javafx/newt/Screen.java delete mode 100755 src/newt/classes/com/jogamp/javafx/newt/Window.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/WindowEvent.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/WindowListener.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/awt/AWTCanvas.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/awt/AWTDisplay.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/awt/AWTScreen.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/awt/AWTWindow.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/impl/Debug.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/impl/NativeLibLoader.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Display.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Screen.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Window.java delete mode 100755 src/newt/classes/com/jogamp/javafx/newt/macosx/MacDisplay.java delete mode 100755 src/newt/classes/com/jogamp/javafx/newt/macosx/MacScreen.java delete mode 100755 src/newt/classes/com/jogamp/javafx/newt/macosx/MacWindow.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/opengl/GLWindow.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Display.java delete mode 100755 src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Screen.java delete mode 100755 src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Window.java delete mode 100755 src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDDisplay.java delete mode 100755 src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDScreen.java delete mode 100755 src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDWindow.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/util/EventDispatchThread.java delete mode 100644 src/newt/classes/com/jogamp/javafx/newt/util/MainThread.java delete mode 100755 src/newt/classes/com/jogamp/javafx/newt/windows/WindowsDisplay.java delete mode 100755 src/newt/classes/com/jogamp/javafx/newt/windows/WindowsScreen.java delete mode 100755 src/newt/classes/com/jogamp/javafx/newt/windows/WindowsWindow.java delete mode 100755 src/newt/classes/com/jogamp/javafx/newt/x11/X11Display.java delete mode 100755 src/newt/classes/com/jogamp/javafx/newt/x11/X11Screen.java delete mode 100755 src/newt/classes/com/jogamp/javafx/newt/x11/X11Window.java create mode 100755 src/newt/classes/com/jogamp/newt/Display.java create mode 100644 src/newt/classes/com/jogamp/newt/Event.java create mode 100644 src/newt/classes/com/jogamp/newt/EventListener.java create mode 100644 src/newt/classes/com/jogamp/newt/InputEvent.java create mode 100644 src/newt/classes/com/jogamp/newt/Insets.java create mode 100644 src/newt/classes/com/jogamp/newt/KeyEvent.java create mode 100644 src/newt/classes/com/jogamp/newt/KeyListener.java create mode 100644 src/newt/classes/com/jogamp/newt/MouseEvent.java create mode 100644 src/newt/classes/com/jogamp/newt/MouseListener.java create mode 100755 src/newt/classes/com/jogamp/newt/NewtFactory.java create mode 100644 src/newt/classes/com/jogamp/newt/OffscreenWindow.java create mode 100755 src/newt/classes/com/jogamp/newt/PaintEvent.java create mode 100755 src/newt/classes/com/jogamp/newt/PaintListener.java create mode 100755 src/newt/classes/com/jogamp/newt/Screen.java create mode 100755 src/newt/classes/com/jogamp/newt/Window.java create mode 100644 src/newt/classes/com/jogamp/newt/WindowEvent.java create mode 100644 src/newt/classes/com/jogamp/newt/WindowListener.java create mode 100644 src/newt/classes/com/jogamp/newt/awt/AWTCanvas.java create mode 100644 src/newt/classes/com/jogamp/newt/awt/AWTDisplay.java create mode 100644 src/newt/classes/com/jogamp/newt/awt/AWTScreen.java create mode 100644 src/newt/classes/com/jogamp/newt/awt/AWTWindow.java create mode 100644 src/newt/classes/com/jogamp/newt/impl/Debug.java create mode 100644 src/newt/classes/com/jogamp/newt/impl/NativeLibLoader.java create mode 100644 src/newt/classes/com/jogamp/newt/intel/gdl/Display.java create mode 100644 src/newt/classes/com/jogamp/newt/intel/gdl/Screen.java create mode 100644 src/newt/classes/com/jogamp/newt/intel/gdl/Window.java create mode 100755 src/newt/classes/com/jogamp/newt/macosx/MacDisplay.java create mode 100755 src/newt/classes/com/jogamp/newt/macosx/MacScreen.java create mode 100755 src/newt/classes/com/jogamp/newt/macosx/MacWindow.java create mode 100644 src/newt/classes/com/jogamp/newt/opengl/GLWindow.java create mode 100644 src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Display.java create mode 100755 src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Screen.java create mode 100755 src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Window.java create mode 100755 src/newt/classes/com/jogamp/newt/opengl/kd/KDDisplay.java create mode 100755 src/newt/classes/com/jogamp/newt/opengl/kd/KDScreen.java create mode 100755 src/newt/classes/com/jogamp/newt/opengl/kd/KDWindow.java create mode 100644 src/newt/classes/com/jogamp/newt/util/EventDispatchThread.java create mode 100644 src/newt/classes/com/jogamp/newt/util/MainThread.java create mode 100755 src/newt/classes/com/jogamp/newt/windows/WindowsDisplay.java create mode 100755 src/newt/classes/com/jogamp/newt/windows/WindowsScreen.java create mode 100755 src/newt/classes/com/jogamp/newt/windows/WindowsWindow.java create mode 100755 src/newt/classes/com/jogamp/newt/x11/X11Display.java create mode 100755 src/newt/classes/com/jogamp/newt/x11/X11Screen.java create mode 100755 src/newt/classes/com/jogamp/newt/x11/X11Window.java (limited to 'src/nativewindow/classes') diff --git a/doc/wiki/FAQ.xml b/doc/wiki/FAQ.xml index 9c14bc7ce..d01413d50 100644 --- a/doc/wiki/FAQ.xml +++ b/doc/wiki/FAQ.xml @@ -289,13 +289,13 @@ Below you see the invocation of the ES2 RedSquare jogl-demos utilizing multiple * Single thread (Unix, Win32)
java -Djava.awt.headless=true demos.es2.RedSquare -GL2
* Single thread (MacOSX)
java -XstartOnFirstThread -Djava.awt.headless=true demos.es2.RedSquare -GL2
* Multiple threads & windows (Unix, Win32)
java -Djava.awt.headless=true demos.es2.RedSquare -GL2 -GL2 -GL2 -GL2
-* Multiple threads & windows (MacOSX)
java -XstartOnFirstThread -Djava.awt.headless=true com.jogamp.javafx.newt.util.MainThread demos.es2.RedSquare -GL2 -GL2 -GL2 -GL2
+* Multiple threads & windows (MacOSX)
java -XstartOnFirstThread -Djava.awt.headless=true com.jogamp.newt.util.MainThread demos.es2.RedSquare -GL2 -GL2 -GL2 -GL2
-The serialization of the main Java class through ''com.jogamp.javafx.newt.util.MainThread'' +The serialization of the main Java class through ''com.jogamp.newt.util.MainThread'' may be used for all platforms, since it only takes effect on ''MacOSX''. This allows you an almost platform independent invocation of your multithreaded Java applications. -On ''MacOSX'', ''com.jogamp.javafx.newt.util.MainThread'' will occupy the main thread and +On ''MacOSX'', ''com.jogamp.newt.util.MainThread'' will occupy the main thread and serializes all native window related tasks through it. This mechanism is thread safe utilizes reentrant locking. diff --git a/doxygen/doxygen-all-pub.cfg b/doxygen/doxygen-all-pub.cfg index a7f4711df..a94c49fb0 100644 --- a/doxygen/doxygen-all-pub.cfg +++ b/doxygen/doxygen-all-pub.cfg @@ -462,7 +462,7 @@ WARN_LOGFILE = INPUT = ../src/jogl/classes/javax INPUT += ../build-x86_64/jogl/gensrc/classes/javax INPUT += ../src/jogl/classes/com/jogamp/opengl/util -INPUT += ../src/newt/classes/com/jogamp/javafx/newt +INPUT += ../src/newt/classes/com/jogamp/newt # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp diff --git a/make/build-jogl.xml b/make/build-jogl.xml index c3bc96bd8..4a0bac4d5 100644 --- a/make/build-jogl.xml +++ b/make/build-jogl.xml @@ -191,10 +191,10 @@ + value="com.jogamp.opengl.impl.gl2.fixme.*,com.jogamp.audio.windows.waveout.TestSpatialization"/> + value="com/jogamp/opengl/impl/gl2/fixme/** com/jogamp/audio/windows/waveout/TestSpatialization.java" /> @@ -1590,7 +1590,7 @@ - + @@ -1826,7 +1826,7 @@ - + @@ -1835,7 +1835,7 @@ + value="com/jogamp/newt/*, com/jogamp/newt/util/*, com/jogamp/newt/impl/*, com/jogamp/newt/intel/gdl/*"/> + value="com/jogamp/newt/x11/*"/> + value="com/jogamp/newt/windows/*"/> + value="com/jogamp/newt/macosx/*"/> + value="com/jogamp/newt/opengl/*, com/jogamp/newt/opengl/kd/*"/> + value="com/jogamp/newt/opengl/broadcom/egl/*"/> + value="com/jogamp/newt/awt/*"/> @@ -279,11 +279,11 @@ - + - + @@ -596,23 +596,23 @@ - + - - - + + + - + - - - + + + @@ -759,14 +759,14 @@ + includes="com/jogamp/newt/**" /> @@ -774,7 +774,7 @@ diff --git a/make/build.xml b/make/build.xml index e73235cac..54b6a8e67 100644 --- a/make/build.xml +++ b/make/build.xml @@ -43,12 +43,12 @@ - + - + - + diff --git a/make/newtRIversion b/make/newtRIversion index 7b8608290..82cc0c0e9 100644 --- a/make/newtRIversion +++ b/make/newtRIversion @@ -4,5 +4,5 @@ Specification-Vendor: Sun Microsystems, Inc. Implementation-Title: NEWT Runtime Environment Implementation-Version: @BASEVERSION@ Implementation-Vendor: Sun Microsystems, Inc. -Extension-Name: com.sun.javafx.newt +Extension-Name: com.sun.newt Implementation-Vendor-Id: com.sun diff --git a/make/newtRIversion-cdc b/make/newtRIversion-cdc index 0dd17ee93..5dcfecad8 100644 --- a/make/newtRIversion-cdc +++ b/make/newtRIversion-cdc @@ -4,5 +4,5 @@ Specification-Vendor: Sun Microsystems, Inc. Implementation-Title: NEWT Runtime Environment CDC Implementation-Version: @BASEVERSION@ Implementation-Vendor: Sun Microsystems, Inc. -Extension-Name: com.sun.javafx.newt +Extension-Name: com.sun.newt Implementation-Vendor-Id: com.sun diff --git a/make/newtversion b/make/newtversion index 3c9335cf5..d1734f756 100644 --- a/make/newtversion +++ b/make/newtversion @@ -4,5 +4,5 @@ Specification-Vendor: Sun Microsystems, Inc. Implementation-Title: NEWT Runtime Environment Implementation-Version: @VERSION@ Implementation-Vendor: java.net JOGL community -Extension-Name: com.sun.javafx.newt +Extension-Name: com.sun.newt Implementation-Vendor-Id: com.sun diff --git a/make/newtversion-cdc b/make/newtversion-cdc index 624111760..8227a4d42 100644 --- a/make/newtversion-cdc +++ b/make/newtversion-cdc @@ -4,5 +4,5 @@ Specification-Vendor: Sun Microsystems, Inc. Implementation-Title: NEWT Runtime Environment CDC Implementation-Version: @VERSION@ Implementation-Vendor: java.net JOGL community -Extension-Name: com.sun.javafx.newt +Extension-Name: com.sun.newt Implementation-Vendor-Id: com.sun diff --git a/src/jogl/classes/com/jogamp/audio/windows/waveout/Audio.java b/src/jogl/classes/com/jogamp/audio/windows/waveout/Audio.java new file mode 100755 index 000000000..2b51be164 --- /dev/null +++ b/src/jogl/classes/com/jogamp/audio/windows/waveout/Audio.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + */ + +package com.jogamp.audio.windows.waveout; + +import java.io.*; + +public class Audio { + private static Audio instance = null; + private Mixer mixer; + + public synchronized static Audio getInstance() { + if (instance == null) { + instance = new Audio(); + } + return instance; + } + + private Audio() { + mixer = Mixer.getMixer(); + } + + public Mixer getMixer() { + return mixer; + } + + public Track newTrack(File file) throws IOException + { + Track res = new Track(file); + mixer.add(res); + return res; + } + + public void shutdown() { + mixer.shutdown(); + } +} diff --git a/src/jogl/classes/com/jogamp/audio/windows/waveout/Mixer.java b/src/jogl/classes/com/jogamp/audio/windows/waveout/Mixer.java new file mode 100755 index 000000000..60972873e --- /dev/null +++ b/src/jogl/classes/com/jogamp/audio/windows/waveout/Mixer.java @@ -0,0 +1,362 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + */ + +package com.jogamp.audio.windows.waveout; + +import java.io.*; +import java.nio.*; +import java.util.*; + +// Needed only for NIO workarounds on CVM +import java.lang.reflect.*; + +public class Mixer { + // This class is a singleton + private static Mixer mixer; + + private volatile boolean shutdown; + private volatile Object shutdownLock = new Object(); + private volatile boolean shutdownDone; + + // Windows Event object + private long event; + + private volatile ArrayList/**/ tracks = new ArrayList(); + + private Vec3f leftSpeakerPosition = new Vec3f(-1, 0, 0); + private Vec3f rightSpeakerPosition = new Vec3f( 1, 0, 0); + + private float falloffFactor = 1.0f; + + static { + mixer = new Mixer(); + } + + private Mixer() { + event = CreateEvent(); + new FillerThread().start(); + MixerThread m = new MixerThread(); + m.setPriority(Thread.MAX_PRIORITY - 1); + m.start(); + } + + public static Mixer getMixer() { + return mixer; + } + + synchronized void add(Track track) { + ArrayList/**/ newTracks = (ArrayList) tracks.clone(); + newTracks.add(track); + tracks = newTracks; + } + + synchronized void remove(Track track) { + ArrayList/**/ newTracks = (ArrayList) tracks.clone(); + newTracks.remove(track); + tracks = newTracks; + } + + // NOTE: due to a bug on the APX device, we only have mono sounds, + // so we currently only pay attention to the position of the left + // speaker + public void setLeftSpeakerPosition(float x, float y, float z) { + leftSpeakerPosition.set(x, y, z); + } + + // NOTE: due to a bug on the APX device, we only have mono sounds, + // so we currently only pay attention to the position of the left + // speaker + public void setRightSpeakerPosition(float x, float y, float z) { + rightSpeakerPosition.set(x, y, z); + } + + /** This defines a scale factor of sorts -- the higher the number, + the larger an area the sound will affect. Default value is + 1.0f. Valid values are [1.0f, ...]. The formula for the gain + for each channel is +
+     falloffFactor
+  -------------------
+  falloffFactor + r^2
+
+*/ + public void setFalloffFactor(float factor) { + falloffFactor = factor; + } + + public void shutdown() { + synchronized(shutdownLock) { + shutdown = true; + SetEvent(event); + try { + shutdownLock.wait(); + } catch (InterruptedException e) { + } + } + } + + class FillerThread extends Thread { + FillerThread() { + super("Mixer Thread"); + } + + public void run() { + while (!shutdown) { + List/**/ curTracks = tracks; + + for (Iterator iter = curTracks.iterator(); iter.hasNext(); ) { + Track track = (Track) iter.next(); + try { + track.fill(); + } catch (IOException e) { + e.printStackTrace(); + remove(track); + } + } + + try { + // Run ten times per second + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + + class MixerThread extends Thread { + // Temporary mixing buffer + // Interleaved left and right channels + float[] mixingBuffer; + private Vec3f temp = new Vec3f(); + + MixerThread() { + super("Mixer Thread"); + if (!initializeWaveOut(event)) { + throw new InternalError("Error initializing waveout device"); + } + } + + public void run() { + while (!shutdown) { + // Get the next buffer + long mixerBuffer = getNextMixerBuffer(); + if (mixerBuffer != 0) { + ByteBuffer buf = getMixerBufferData(mixerBuffer); + + if (buf == null) { + // This is happening on CVM because + // JNI_NewDirectByteBuffer isn't implemented + // by default and isn't compatible with the + // JSR-239 NIO implementation (apparently) + buf = newDirectByteBuffer(getMixerBufferDataAddress(mixerBuffer), + getMixerBufferDataCapacity(mixerBuffer)); + } + + if (buf == null) { + throw new InternalError("Couldn't wrap the native address with a direct byte buffer"); + } + + // System.out.println("Mixing buffer"); + + // If we don't have enough samples in our mixing buffer, expand it + // FIXME: knowledge of native output rendering format + if ((mixingBuffer == null) || (mixingBuffer.length < (buf.capacity() / 2 /* bytes / sample */))) { + mixingBuffer = new float[buf.capacity() / 2]; + } else { + // Zap it + for (int i = 0; i < mixingBuffer.length; i++) { + mixingBuffer[i] = 0.0f; + } + } + + // This assertion should be in place if we have stereo + if ((mixingBuffer.length % 2) != 0) { + String msg = "FATAL ERROR: odd number of samples in the mixing buffer"; + System.out.println(msg); + throw new InternalError(msg); + } + + // Run down all of the registered tracks mixing them in + List/**/ curTracks = tracks; + + for (Iterator iter = curTracks.iterator(); iter.hasNext(); ) { + Track track = (Track) iter.next(); + // Consider only playing tracks + if (track.isPlaying()) { + // First recompute its gain + Vec3f pos = track.getPosition(); + float leftGain = gain(pos, leftSpeakerPosition); + float rightGain = gain(pos, rightSpeakerPosition); + // Now mix it in + int i = 0; + while (i < mixingBuffer.length) { + if (track.hasNextSample()) { + float sample = track.nextSample(); + mixingBuffer[i++] = sample * leftGain; + mixingBuffer[i++] = sample * rightGain; + } else { + // This allows tracks to stall without being abruptly cancelled + if (track.done()) { + remove(track); + } + break; + } + } + } + } + + // Now that we have our data, send it down to the card + int outPos = 0; + for (int i = 0; i < mixingBuffer.length; i++) { + short val = (short) mixingBuffer[i]; + buf.put(outPos++, (byte) val); + buf.put(outPos++, (byte) (val >> 8)); + } + if (!prepareMixerBuffer(mixerBuffer)) { + throw new RuntimeException("Error preparing mixer buffer"); + } + if (!writeMixerBuffer(mixerBuffer)) { + throw new RuntimeException("Error writing mixer buffer to device"); + } + } else { + // System.out.println("No mixer buffer available"); + + // Wait for a buffer to become available + if (!WaitForSingleObject(event)) { + throw new RuntimeException("Error while waiting for event object"); + } + + /* + try { + Thread.sleep(10); + } catch (InterruptedException e) { + } + */ + } + } + + // Need to shut down + shutdownWaveOut(); + synchronized(shutdownLock) { + shutdownLock.notifyAll(); + } + } + + // This defines the 3D spatialization gain function. + // The function is defined as: + // falloffFactor + // ------------------- + // falloffFactor + r^2 + private float gain(Vec3f pos, Vec3f speakerPos) { + temp.sub(pos, speakerPos); + float dotp = temp.dot(temp); + return (falloffFactor / (falloffFactor + dotp)); + } + } + + // Initializes waveout device + private static native boolean initializeWaveOut(long eventObject); + // Shuts down waveout device + private static native void shutdownWaveOut(); + + // Gets the next (opaque) buffer of data to fill from the native + // code, or 0 if none was available yet (it should not happen that + // none is available the way the code is written). + private static native long getNextMixerBuffer(); + // Gets the next ByteBuffer to fill out of the mixer buffer. It + // requires interleaved left and right channel samples, 16 signed + // bits per sample, little endian. Implicit 44.1 kHz sample rate. + private static native ByteBuffer getMixerBufferData(long mixerBuffer); + // We need these to work around the lack of + // JNI_NewDirectByteBuffer in CVM + the JSR 239 NIO classes + private static native long getMixerBufferDataAddress(long mixerBuffer); + private static native int getMixerBufferDataCapacity(long mixerBuffer); + // Prepares this mixer buffer for writing to the device. + private static native boolean prepareMixerBuffer(long mixerBuffer); + // Writes this mixer buffer to the device. + private static native boolean writeMixerBuffer(long mixerBuffer); + + // Helpers to prevent mixer thread from busy waiting + private static native long CreateEvent(); + private static native boolean WaitForSingleObject(long event); + private static native void SetEvent(long event); + private static native void CloseHandle(long handle); + + // We need a reflective hack to wrap a direct ByteBuffer around + // the native memory because JNI_NewDirectByteBuffer doesn't work + // in CVM + JSR-239 NIO + private static Class directByteBufferClass; + private static Constructor directByteBufferConstructor; + private static Map createdBuffers = new HashMap(); // Map Long, ByteBuffer + + private static ByteBuffer newDirectByteBuffer(long address, long capacity) { + Long key = new Long(address); + ByteBuffer buf = (ByteBuffer) createdBuffers.get(key); + if (buf == null) { + buf = newDirectByteBufferImpl(address, capacity); + if (buf != null) { + createdBuffers.put(key, buf); + } + } + return buf; + } + private static ByteBuffer newDirectByteBufferImpl(long address, long capacity) { + if (directByteBufferClass == null) { + try { + directByteBufferClass = Class.forName("java.nio.DirectByteBuffer"); + byte[] tmp = new byte[0]; + directByteBufferConstructor = + directByteBufferClass.getDeclaredConstructor(new Class[] { Integer.TYPE, + tmp.getClass(), + Integer.TYPE }); + directByteBufferConstructor.setAccessible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + + if (directByteBufferConstructor != null) { + try { + return (ByteBuffer) + directByteBufferConstructor.newInstance(new Object[] { + new Integer((int) capacity), + null, + new Integer((int) address) + }); + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } +} diff --git a/src/jogl/classes/com/jogamp/audio/windows/waveout/SoundBuffer.java b/src/jogl/classes/com/jogamp/audio/windows/waveout/SoundBuffer.java new file mode 100755 index 000000000..c45430d23 --- /dev/null +++ b/src/jogl/classes/com/jogamp/audio/windows/waveout/SoundBuffer.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + */ + +package com.jogamp.audio.windows.waveout; + +import java.io.*; + +class SoundBuffer { + private byte[] data; + private boolean needsByteSwap; + private int numBytes; + private int bytesPerSample; + private int numSamples; + private boolean playing; + private boolean empty; + + // Note: needsByteSwap argument makes assumptions about the format + SoundBuffer(int size, int bytesPerSample, boolean needsByteSwap) { + this.bytesPerSample = bytesPerSample; + this.needsByteSwap = needsByteSwap; + data = new byte[size * bytesPerSample]; + empty = true; + } + + boolean playing() { + return playing; + } + + void playing(boolean playing) { + this.playing = playing; + } + + boolean empty() { + return empty; + } + + void empty(boolean empty) { + this.empty = empty; + } + + void fill(InputStream input) throws IOException { + synchronized(this) { + if (playing) { + throw new IllegalStateException("Can not fill a buffer that is playing"); + } + } + + empty(true); + int num = input.read(data); + if (num > 0) { + numBytes = num; + numSamples = numBytes / bytesPerSample; + empty(false); + if ((numBytes % bytesPerSample) != 0) { + System.out.println("WARNING: needed integral multiple of " + bytesPerSample + + " bytes, but read " + numBytes + " bytes"); + } + } else { + numBytes = 0; + } + } + + int numSamples() { + return numSamples; + } + + // This is called by the mixer and must be extremely fast + // FIXME: may want to reconsider use of floating point at this point + // FIXME: assumes all sounds are of the same format to avoid normalization + float getSample(int sample) { + int startByte = sample * bytesPerSample; + // FIXME: assumes no more than 4 bytes per sample + int res = 0; + if (needsByteSwap) { + for (int i = startByte + bytesPerSample - 1; i >= startByte; i--) { + res <<= 8; + res |= (data[i] & 0xff); + } + } else { + int endByte = startByte + bytesPerSample - 1; + for (int i = startByte; i <= endByte; i++) { + res <<= 8; + res |= (data[i] & 0xff); + } + } + // Sign extend + if (bytesPerSample == 2) { + res = (short) res; + } else if (bytesPerSample == 1) { + res = (byte) res; + } + + return (float) res; + } +} diff --git a/src/jogl/classes/com/jogamp/audio/windows/waveout/TestSpatialization.java b/src/jogl/classes/com/jogamp/audio/windows/waveout/TestSpatialization.java new file mode 100755 index 000000000..78fb3493f --- /dev/null +++ b/src/jogl/classes/com/jogamp/audio/windows/waveout/TestSpatialization.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + */ + +package com.jogamp.audio.windows.waveout; + +import java.io.*; +import javax.media.nativewindow.NativeWindow; +import javax.media.opengl.GLDrawableFactory; + +public class TestSpatialization { + public static void main(String[] args) { + if (args.length != 1) { + System.out.println("Usage: TestSpatialization [file name]"); + System.exit(1); + } + + try { + // FIXME: this is a hack to get the native library loaded + try { + GLDrawableFactory.getFactory(NativeWindow.class); + } catch (Exception e) {} + // Initialize the audio subsystem + Audio audio = Audio.getInstance(); + // Create a track + Track track = audio.newTrack(new File(args[0])); + track.setPosition(1, 0, 0); + // Run for ten seconds + long startTime = System.currentTimeMillis(); + long duration = 10000; + long curTime = 0; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + } + System.out.println("Playing..."); + track.setLooping(true); + track.play(); + while ((curTime = System.currentTimeMillis()) < startTime + duration) { + // Make one revolution every two seconds + float rads = (float) (((2 * Math.PI) * (((float) (curTime - startTime)) / 1000.0f)) / 2); + track.setPosition((float) Math.cos(rads), 0, (float) Math.sin(rads)); + // Would like to make it go in a circle, but since + // stereo doesn't work now, make it move along a line + // track.setPosition(-1.0f, 0, 2.0f * (float) Math.sin(rads)); + // Sleep a little between updates + try { + Thread.sleep(10); + } catch (InterruptedException e) { + } + } + System.out.println("Shutting down audio subsystem"); + audio.shutdown(); + System.out.println("Exiting."); + System.exit(0); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } +} diff --git a/src/jogl/classes/com/jogamp/audio/windows/waveout/Track.java b/src/jogl/classes/com/jogamp/audio/windows/waveout/Track.java new file mode 100755 index 000000000..b57bf1dc6 --- /dev/null +++ b/src/jogl/classes/com/jogamp/audio/windows/waveout/Track.java @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + */ + +package com.jogamp.audio.windows.waveout; + +import java.io.*; +import java.nio.*; + +public class Track { + // Default number of samples per buffer + private static final int BUFFER_SIZE = 32768; + // Number of bytes per sample (FIXME: dependence on audio format) + static final int BYTES_PER_SAMPLE = 2; + // Whether we need byte swapping (FIXME: dependence on audio format) + static final boolean NEEDS_BYTE_SWAP = true; + + // This is the buffer this track is currently playing from + private SoundBuffer activeBuffer; + // This is the sample position in the active buffer + private int samplePosition; + // This is the total number of samples in the file + private int totalSamples; + // This is the total number of samples we have read + private int samplesRead; + // This is the buffer that the background filler thread may be filling + private SoundBuffer fillingBuffer; + // If we're playing the file, this is its input stream + private InputStream input; + // Keep around the file name + private File file; + // Whether we're playing this sound + private boolean playing; + // Whether we're looping this sound + private boolean looping; + // The position of this sound; defaults to being at the origin + private volatile Vec3f position = new Vec3f(); + + Track(File file) throws IOException { + if (!file.getName().endsWith(".rawsound")) { + throw new IOException("Unsupported file format (currently supports only raw sounds)"); + } + + this.file = file; + openInput(); + + // Allocate the buffers + activeBuffer = new SoundBuffer(BUFFER_SIZE, BYTES_PER_SAMPLE, NEEDS_BYTE_SWAP); + fillingBuffer = new SoundBuffer(BUFFER_SIZE, BYTES_PER_SAMPLE, NEEDS_BYTE_SWAP); + + // Fill the first buffer immediately + fill(); + swapBuffers(); + } + + private void openInput() throws IOException { + input = new BufferedInputStream(new FileInputStream(file)); + totalSamples = (int) file.length() / BYTES_PER_SAMPLE; + } + + public File getFile() { + return file; + } + + public synchronized void play() { + if (input == null) { + try { + openInput(); + // Fill it immediately + fill(); + } catch (IOException e) { + e.printStackTrace(); + return; + } + } + + playing = true; + } + + public synchronized boolean isPlaying() { + return playing; + } + + public synchronized void setLooping(boolean looping) { + this.looping = looping; + } + + public synchronized boolean isLooping() { + return looping; + } + + public void setPosition(float x, float y, float z) { + position = new Vec3f(x, y, z); + } + + synchronized void fill() throws IOException { + if (input == null) { + return; + } + SoundBuffer curBuffer = fillingBuffer; + if (!curBuffer.empty()) { + return; + } + curBuffer.fill(input); + if (curBuffer.empty()) { + // End of file + InputStream tmp = null; + synchronized(this) { + tmp = input; + input = null; + } + tmp.close(); + + // If looping, re-open + if (isLooping()) { + openInput(); + // and fill + fill(); + } + } + } + + // These are only for use by the Mixer + private float leftGain; + private float rightGain; + + void setLeftGain(float leftGain) { + this.leftGain = leftGain; + } + + float getLeftGain() { + return leftGain; + } + + void setRightGain(float rightGain) { + this.rightGain = rightGain; + } + + float getRightGain() { + return rightGain; + } + + Vec3f getPosition() { + return position; + } + + // This is called by the mixer and must be extremely fast + // Note this assumes mono sounds (FIXME) + boolean hasNextSample() { + return (!activeBuffer.empty() && samplePosition < activeBuffer.numSamples()); + } + + // This is called by the mixer and must be extremely fast + float nextSample() { + float res = activeBuffer.getSample(samplePosition++); + ++samplesRead; + if (!hasNextSample()) { + swapBuffers(); + samplePosition = 0; + if (done()) { + playing = false; + } + } + return res; + } + + synchronized void swapBuffers() { + SoundBuffer tmp = activeBuffer; + activeBuffer = fillingBuffer; + fillingBuffer = tmp; + fillingBuffer.empty(true); + } + + // This provides a more robust termination condition + boolean done() { + return (samplesRead == totalSamples) && !looping; + } +} diff --git a/src/jogl/classes/com/jogamp/audio/windows/waveout/Vec3f.java b/src/jogl/classes/com/jogamp/audio/windows/waveout/Vec3f.java new file mode 100755 index 000000000..1afdaf081 --- /dev/null +++ b/src/jogl/classes/com/jogamp/audio/windows/waveout/Vec3f.java @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + */ + +package com.jogamp.audio.windows.waveout; + +/** 3-element single-precision vector */ + +class Vec3f { + public static final Vec3f X_AXIS = new Vec3f( 1, 0, 0); + public static final Vec3f Y_AXIS = new Vec3f( 0, 1, 0); + public static final Vec3f Z_AXIS = new Vec3f( 0, 0, 1); + public static final Vec3f NEG_X_AXIS = new Vec3f(-1, 0, 0); + public static final Vec3f NEG_Y_AXIS = new Vec3f( 0, -1, 0); + public static final Vec3f NEG_Z_AXIS = new Vec3f( 0, 0, -1); + + private float x; + private float y; + private float z; + + public Vec3f() {} + + public Vec3f(Vec3f arg) { + set(arg); + } + + public Vec3f(float x, float y, float z) { + set(x, y, z); + } + + public Vec3f copy() { + return new Vec3f(this); + } + + public void set(Vec3f arg) { + set(arg.x, arg.y, arg.z); + } + + public void set(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + } + + /** Sets the ith component, 0 <= i < 3 */ + public void set(int i, float val) { + switch (i) { + case 0: x = val; break; + case 1: y = val; break; + case 2: z = val; break; + default: throw new IndexOutOfBoundsException(); + } + } + + /** Gets the ith component, 0 <= i < 3 */ + public float get(int i) { + switch (i) { + case 0: return x; + case 1: return y; + case 2: return z; + default: throw new IndexOutOfBoundsException(); + } + } + + public float x() { return x; } + public float y() { return y; } + public float z() { return z; } + + public void setX(float x) { this.x = x; } + public void setY(float y) { this.y = y; } + public void setZ(float z) { this.z = z; } + + public float dot(Vec3f arg) { + return x * arg.x + y * arg.y + z * arg.z; + } + + public float length() { + return (float) Math.sqrt(lengthSquared()); + } + + public float lengthSquared() { + return this.dot(this); + } + + public void normalize() { + float len = length(); + if (len == 0.0f) return; + scale(1.0f / len); + } + + /** Returns this * val; creates new vector */ + public Vec3f times(float val) { + Vec3f tmp = new Vec3f(this); + tmp.scale(val); + return tmp; + } + + /** this = this * val */ + public void scale(float val) { + x *= val; + y *= val; + z *= val; + } + + /** Returns this + arg; creates new vector */ + public Vec3f plus(Vec3f arg) { + Vec3f tmp = new Vec3f(); + tmp.add(this, arg); + return tmp; + } + + /** this = this + b */ + public void add(Vec3f b) { + add(this, b); + } + + /** this = a + b */ + public void add(Vec3f a, Vec3f b) { + x = a.x + b.x; + y = a.y + b.y; + z = a.z + b.z; + } + + /** Returns this + s * arg; creates new vector */ + public Vec3f addScaled(float s, Vec3f arg) { + Vec3f tmp = new Vec3f(); + tmp.addScaled(this, s, arg); + return tmp; + } + + /** this = a + s * b */ + public void addScaled(Vec3f a, float s, Vec3f b) { + x = a.x + s * b.x; + y = a.y + s * b.y; + z = a.z + s * b.z; + } + + /** Returns this - arg; creates new vector */ + public Vec3f minus(Vec3f arg) { + Vec3f tmp = new Vec3f(); + tmp.sub(this, arg); + return tmp; + } + + /** this = this - b */ + public void sub(Vec3f b) { + sub(this, b); + } + + /** this = a - b */ + public void sub(Vec3f a, Vec3f b) { + x = a.x - b.x; + y = a.y - b.y; + z = a.z - b.z; + } + + /** Returns this cross arg; creates new vector */ + public Vec3f cross(Vec3f arg) { + Vec3f tmp = new Vec3f(); + tmp.cross(this, arg); + return tmp; + } + + /** this = a cross b. NOTE: "this" must be a different vector than + both a and b. */ + public void cross(Vec3f a, Vec3f b) { + x = a.y * b.z - a.z * b.y; + y = a.z * b.x - a.x * b.z; + z = a.x * b.y - a.y * b.x; + } + + /** Sets each component of this vector to the product of the + component with the corresponding component of the argument + vector. */ + public void componentMul(Vec3f arg) { + x *= arg.x; + y *= arg.y; + z *= arg.z; + } + + public String toString() { + return "(" + x + ", " + y + ", " + z + ")"; + } +} diff --git a/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Audio.java b/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Audio.java deleted file mode 100755 index fe77c7c48..000000000 --- a/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Audio.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - */ - -package com.jogamp.javafx.audio.windows.waveout; - -import java.io.*; - -public class Audio { - private static Audio instance = null; - private Mixer mixer; - - public synchronized static Audio getInstance() { - if (instance == null) { - instance = new Audio(); - } - return instance; - } - - private Audio() { - mixer = Mixer.getMixer(); - } - - public Mixer getMixer() { - return mixer; - } - - public Track newTrack(File file) throws IOException - { - Track res = new Track(file); - mixer.add(res); - return res; - } - - public void shutdown() { - mixer.shutdown(); - } -} diff --git a/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Mixer.java b/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Mixer.java deleted file mode 100755 index 59877052f..000000000 --- a/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Mixer.java +++ /dev/null @@ -1,362 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - */ - -package com.jogamp.javafx.audio.windows.waveout; - -import java.io.*; -import java.nio.*; -import java.util.*; - -// Needed only for NIO workarounds on CVM -import java.lang.reflect.*; - -public class Mixer { - // This class is a singleton - private static Mixer mixer; - - private volatile boolean shutdown; - private volatile Object shutdownLock = new Object(); - private volatile boolean shutdownDone; - - // Windows Event object - private long event; - - private volatile ArrayList/**/ tracks = new ArrayList(); - - private Vec3f leftSpeakerPosition = new Vec3f(-1, 0, 0); - private Vec3f rightSpeakerPosition = new Vec3f( 1, 0, 0); - - private float falloffFactor = 1.0f; - - static { - mixer = new Mixer(); - } - - private Mixer() { - event = CreateEvent(); - new FillerThread().start(); - MixerThread m = new MixerThread(); - m.setPriority(Thread.MAX_PRIORITY - 1); - m.start(); - } - - public static Mixer getMixer() { - return mixer; - } - - synchronized void add(Track track) { - ArrayList/**/ newTracks = (ArrayList) tracks.clone(); - newTracks.add(track); - tracks = newTracks; - } - - synchronized void remove(Track track) { - ArrayList/**/ newTracks = (ArrayList) tracks.clone(); - newTracks.remove(track); - tracks = newTracks; - } - - // NOTE: due to a bug on the APX device, we only have mono sounds, - // so we currently only pay attention to the position of the left - // speaker - public void setLeftSpeakerPosition(float x, float y, float z) { - leftSpeakerPosition.set(x, y, z); - } - - // NOTE: due to a bug on the APX device, we only have mono sounds, - // so we currently only pay attention to the position of the left - // speaker - public void setRightSpeakerPosition(float x, float y, float z) { - rightSpeakerPosition.set(x, y, z); - } - - /** This defines a scale factor of sorts -- the higher the number, - the larger an area the sound will affect. Default value is - 1.0f. Valid values are [1.0f, ...]. The formula for the gain - for each channel is -
-     falloffFactor
-  -------------------
-  falloffFactor + r^2
-
-*/ - public void setFalloffFactor(float factor) { - falloffFactor = factor; - } - - public void shutdown() { - synchronized(shutdownLock) { - shutdown = true; - SetEvent(event); - try { - shutdownLock.wait(); - } catch (InterruptedException e) { - } - } - } - - class FillerThread extends Thread { - FillerThread() { - super("Mixer Thread"); - } - - public void run() { - while (!shutdown) { - List/**/ curTracks = tracks; - - for (Iterator iter = curTracks.iterator(); iter.hasNext(); ) { - Track track = (Track) iter.next(); - try { - track.fill(); - } catch (IOException e) { - e.printStackTrace(); - remove(track); - } - } - - try { - // Run ten times per second - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - } - - class MixerThread extends Thread { - // Temporary mixing buffer - // Interleaved left and right channels - float[] mixingBuffer; - private Vec3f temp = new Vec3f(); - - MixerThread() { - super("Mixer Thread"); - if (!initializeWaveOut(event)) { - throw new InternalError("Error initializing waveout device"); - } - } - - public void run() { - while (!shutdown) { - // Get the next buffer - long mixerBuffer = getNextMixerBuffer(); - if (mixerBuffer != 0) { - ByteBuffer buf = getMixerBufferData(mixerBuffer); - - if (buf == null) { - // This is happening on CVM because - // JNI_NewDirectByteBuffer isn't implemented - // by default and isn't compatible with the - // JSR-239 NIO implementation (apparently) - buf = newDirectByteBuffer(getMixerBufferDataAddress(mixerBuffer), - getMixerBufferDataCapacity(mixerBuffer)); - } - - if (buf == null) { - throw new InternalError("Couldn't wrap the native address with a direct byte buffer"); - } - - // System.out.println("Mixing buffer"); - - // If we don't have enough samples in our mixing buffer, expand it - // FIXME: knowledge of native output rendering format - if ((mixingBuffer == null) || (mixingBuffer.length < (buf.capacity() / 2 /* bytes / sample */))) { - mixingBuffer = new float[buf.capacity() / 2]; - } else { - // Zap it - for (int i = 0; i < mixingBuffer.length; i++) { - mixingBuffer[i] = 0.0f; - } - } - - // This assertion should be in place if we have stereo - if ((mixingBuffer.length % 2) != 0) { - String msg = "FATAL ERROR: odd number of samples in the mixing buffer"; - System.out.println(msg); - throw new InternalError(msg); - } - - // Run down all of the registered tracks mixing them in - List/**/ curTracks = tracks; - - for (Iterator iter = curTracks.iterator(); iter.hasNext(); ) { - Track track = (Track) iter.next(); - // Consider only playing tracks - if (track.isPlaying()) { - // First recompute its gain - Vec3f pos = track.getPosition(); - float leftGain = gain(pos, leftSpeakerPosition); - float rightGain = gain(pos, rightSpeakerPosition); - // Now mix it in - int i = 0; - while (i < mixingBuffer.length) { - if (track.hasNextSample()) { - float sample = track.nextSample(); - mixingBuffer[i++] = sample * leftGain; - mixingBuffer[i++] = sample * rightGain; - } else { - // This allows tracks to stall without being abruptly cancelled - if (track.done()) { - remove(track); - } - break; - } - } - } - } - - // Now that we have our data, send it down to the card - int outPos = 0; - for (int i = 0; i < mixingBuffer.length; i++) { - short val = (short) mixingBuffer[i]; - buf.put(outPos++, (byte) val); - buf.put(outPos++, (byte) (val >> 8)); - } - if (!prepareMixerBuffer(mixerBuffer)) { - throw new RuntimeException("Error preparing mixer buffer"); - } - if (!writeMixerBuffer(mixerBuffer)) { - throw new RuntimeException("Error writing mixer buffer to device"); - } - } else { - // System.out.println("No mixer buffer available"); - - // Wait for a buffer to become available - if (!WaitForSingleObject(event)) { - throw new RuntimeException("Error while waiting for event object"); - } - - /* - try { - Thread.sleep(10); - } catch (InterruptedException e) { - } - */ - } - } - - // Need to shut down - shutdownWaveOut(); - synchronized(shutdownLock) { - shutdownLock.notifyAll(); - } - } - - // This defines the 3D spatialization gain function. - // The function is defined as: - // falloffFactor - // ------------------- - // falloffFactor + r^2 - private float gain(Vec3f pos, Vec3f speakerPos) { - temp.sub(pos, speakerPos); - float dotp = temp.dot(temp); - return (falloffFactor / (falloffFactor + dotp)); - } - } - - // Initializes waveout device - private static native boolean initializeWaveOut(long eventObject); - // Shuts down waveout device - private static native void shutdownWaveOut(); - - // Gets the next (opaque) buffer of data to fill from the native - // code, or 0 if none was available yet (it should not happen that - // none is available the way the code is written). - private static native long getNextMixerBuffer(); - // Gets the next ByteBuffer to fill out of the mixer buffer. It - // requires interleaved left and right channel samples, 16 signed - // bits per sample, little endian. Implicit 44.1 kHz sample rate. - private static native ByteBuffer getMixerBufferData(long mixerBuffer); - // We need these to work around the lack of - // JNI_NewDirectByteBuffer in CVM + the JSR 239 NIO classes - private static native long getMixerBufferDataAddress(long mixerBuffer); - private static native int getMixerBufferDataCapacity(long mixerBuffer); - // Prepares this mixer buffer for writing to the device. - private static native boolean prepareMixerBuffer(long mixerBuffer); - // Writes this mixer buffer to the device. - private static native boolean writeMixerBuffer(long mixerBuffer); - - // Helpers to prevent mixer thread from busy waiting - private static native long CreateEvent(); - private static native boolean WaitForSingleObject(long event); - private static native void SetEvent(long event); - private static native void CloseHandle(long handle); - - // We need a reflective hack to wrap a direct ByteBuffer around - // the native memory because JNI_NewDirectByteBuffer doesn't work - // in CVM + JSR-239 NIO - private static Class directByteBufferClass; - private static Constructor directByteBufferConstructor; - private static Map createdBuffers = new HashMap(); // Map Long, ByteBuffer - - private static ByteBuffer newDirectByteBuffer(long address, long capacity) { - Long key = new Long(address); - ByteBuffer buf = (ByteBuffer) createdBuffers.get(key); - if (buf == null) { - buf = newDirectByteBufferImpl(address, capacity); - if (buf != null) { - createdBuffers.put(key, buf); - } - } - return buf; - } - private static ByteBuffer newDirectByteBufferImpl(long address, long capacity) { - if (directByteBufferClass == null) { - try { - directByteBufferClass = Class.forName("java.nio.DirectByteBuffer"); - byte[] tmp = new byte[0]; - directByteBufferConstructor = - directByteBufferClass.getDeclaredConstructor(new Class[] { Integer.TYPE, - tmp.getClass(), - Integer.TYPE }); - directByteBufferConstructor.setAccessible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - - if (directByteBufferConstructor != null) { - try { - return (ByteBuffer) - directByteBufferConstructor.newInstance(new Object[] { - new Integer((int) capacity), - null, - new Integer((int) address) - }); - } catch (Exception e) { - e.printStackTrace(); - } - } - return null; - } -} diff --git a/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/SoundBuffer.java b/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/SoundBuffer.java deleted file mode 100755 index 6b75450eb..000000000 --- a/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/SoundBuffer.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - */ - -package com.jogamp.javafx.audio.windows.waveout; - -import java.io.*; - -class SoundBuffer { - private byte[] data; - private boolean needsByteSwap; - private int numBytes; - private int bytesPerSample; - private int numSamples; - private boolean playing; - private boolean empty; - - // Note: needsByteSwap argument makes assumptions about the format - SoundBuffer(int size, int bytesPerSample, boolean needsByteSwap) { - this.bytesPerSample = bytesPerSample; - this.needsByteSwap = needsByteSwap; - data = new byte[size * bytesPerSample]; - empty = true; - } - - boolean playing() { - return playing; - } - - void playing(boolean playing) { - this.playing = playing; - } - - boolean empty() { - return empty; - } - - void empty(boolean empty) { - this.empty = empty; - } - - void fill(InputStream input) throws IOException { - synchronized(this) { - if (playing) { - throw new IllegalStateException("Can not fill a buffer that is playing"); - } - } - - empty(true); - int num = input.read(data); - if (num > 0) { - numBytes = num; - numSamples = numBytes / bytesPerSample; - empty(false); - if ((numBytes % bytesPerSample) != 0) { - System.out.println("WARNING: needed integral multiple of " + bytesPerSample + - " bytes, but read " + numBytes + " bytes"); - } - } else { - numBytes = 0; - } - } - - int numSamples() { - return numSamples; - } - - // This is called by the mixer and must be extremely fast - // FIXME: may want to reconsider use of floating point at this point - // FIXME: assumes all sounds are of the same format to avoid normalization - float getSample(int sample) { - int startByte = sample * bytesPerSample; - // FIXME: assumes no more than 4 bytes per sample - int res = 0; - if (needsByteSwap) { - for (int i = startByte + bytesPerSample - 1; i >= startByte; i--) { - res <<= 8; - res |= (data[i] & 0xff); - } - } else { - int endByte = startByte + bytesPerSample - 1; - for (int i = startByte; i <= endByte; i++) { - res <<= 8; - res |= (data[i] & 0xff); - } - } - // Sign extend - if (bytesPerSample == 2) { - res = (short) res; - } else if (bytesPerSample == 1) { - res = (byte) res; - } - - return (float) res; - } -} diff --git a/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/TestSpatialization.java b/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/TestSpatialization.java deleted file mode 100755 index 38e3bb808..000000000 --- a/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/TestSpatialization.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - */ - -package com.jogamp.javafx.audio.windows.waveout; - -import java.io.*; -import javax.media.nativewindow.NativeWindow; -import javax.media.opengl.GLDrawableFactory; - -public class TestSpatialization { - public static void main(String[] args) { - if (args.length != 1) { - System.out.println("Usage: TestSpatialization [file name]"); - System.exit(1); - } - - try { - // FIXME: this is a hack to get the native library loaded - try { - GLDrawableFactory.getFactory(NativeWindow.class); - } catch (Exception e) {} - // Initialize the audio subsystem - Audio audio = Audio.getInstance(); - // Create a track - Track track = audio.newTrack(new File(args[0])); - track.setPosition(1, 0, 0); - // Run for ten seconds - long startTime = System.currentTimeMillis(); - long duration = 10000; - long curTime = 0; - try { - Thread.sleep(500); - } catch (InterruptedException e) { - } - System.out.println("Playing..."); - track.setLooping(true); - track.play(); - while ((curTime = System.currentTimeMillis()) < startTime + duration) { - // Make one revolution every two seconds - float rads = (float) (((2 * Math.PI) * (((float) (curTime - startTime)) / 1000.0f)) / 2); - track.setPosition((float) Math.cos(rads), 0, (float) Math.sin(rads)); - // Would like to make it go in a circle, but since - // stereo doesn't work now, make it move along a line - // track.setPosition(-1.0f, 0, 2.0f * (float) Math.sin(rads)); - // Sleep a little between updates - try { - Thread.sleep(10); - } catch (InterruptedException e) { - } - } - System.out.println("Shutting down audio subsystem"); - audio.shutdown(); - System.out.println("Exiting."); - System.exit(0); - } catch (Exception e) { - e.printStackTrace(); - System.exit(1); - } - } -} diff --git a/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Track.java b/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Track.java deleted file mode 100755 index 40c39e755..000000000 --- a/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Track.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - */ - -package com.jogamp.javafx.audio.windows.waveout; - -import java.io.*; -import java.nio.*; - -public class Track { - // Default number of samples per buffer - private static final int BUFFER_SIZE = 32768; - // Number of bytes per sample (FIXME: dependence on audio format) - static final int BYTES_PER_SAMPLE = 2; - // Whether we need byte swapping (FIXME: dependence on audio format) - static final boolean NEEDS_BYTE_SWAP = true; - - // This is the buffer this track is currently playing from - private SoundBuffer activeBuffer; - // This is the sample position in the active buffer - private int samplePosition; - // This is the total number of samples in the file - private int totalSamples; - // This is the total number of samples we have read - private int samplesRead; - // This is the buffer that the background filler thread may be filling - private SoundBuffer fillingBuffer; - // If we're playing the file, this is its input stream - private InputStream input; - // Keep around the file name - private File file; - // Whether we're playing this sound - private boolean playing; - // Whether we're looping this sound - private boolean looping; - // The position of this sound; defaults to being at the origin - private volatile Vec3f position = new Vec3f(); - - Track(File file) throws IOException { - if (!file.getName().endsWith(".rawsound")) { - throw new IOException("Unsupported file format (currently supports only raw sounds)"); - } - - this.file = file; - openInput(); - - // Allocate the buffers - activeBuffer = new SoundBuffer(BUFFER_SIZE, BYTES_PER_SAMPLE, NEEDS_BYTE_SWAP); - fillingBuffer = new SoundBuffer(BUFFER_SIZE, BYTES_PER_SAMPLE, NEEDS_BYTE_SWAP); - - // Fill the first buffer immediately - fill(); - swapBuffers(); - } - - private void openInput() throws IOException { - input = new BufferedInputStream(new FileInputStream(file)); - totalSamples = (int) file.length() / BYTES_PER_SAMPLE; - } - - public File getFile() { - return file; - } - - public synchronized void play() { - if (input == null) { - try { - openInput(); - // Fill it immediately - fill(); - } catch (IOException e) { - e.printStackTrace(); - return; - } - } - - playing = true; - } - - public synchronized boolean isPlaying() { - return playing; - } - - public synchronized void setLooping(boolean looping) { - this.looping = looping; - } - - public synchronized boolean isLooping() { - return looping; - } - - public void setPosition(float x, float y, float z) { - position = new Vec3f(x, y, z); - } - - synchronized void fill() throws IOException { - if (input == null) { - return; - } - SoundBuffer curBuffer = fillingBuffer; - if (!curBuffer.empty()) { - return; - } - curBuffer.fill(input); - if (curBuffer.empty()) { - // End of file - InputStream tmp = null; - synchronized(this) { - tmp = input; - input = null; - } - tmp.close(); - - // If looping, re-open - if (isLooping()) { - openInput(); - // and fill - fill(); - } - } - } - - // These are only for use by the Mixer - private float leftGain; - private float rightGain; - - void setLeftGain(float leftGain) { - this.leftGain = leftGain; - } - - float getLeftGain() { - return leftGain; - } - - void setRightGain(float rightGain) { - this.rightGain = rightGain; - } - - float getRightGain() { - return rightGain; - } - - Vec3f getPosition() { - return position; - } - - // This is called by the mixer and must be extremely fast - // Note this assumes mono sounds (FIXME) - boolean hasNextSample() { - return (!activeBuffer.empty() && samplePosition < activeBuffer.numSamples()); - } - - // This is called by the mixer and must be extremely fast - float nextSample() { - float res = activeBuffer.getSample(samplePosition++); - ++samplesRead; - if (!hasNextSample()) { - swapBuffers(); - samplePosition = 0; - if (done()) { - playing = false; - } - } - return res; - } - - synchronized void swapBuffers() { - SoundBuffer tmp = activeBuffer; - activeBuffer = fillingBuffer; - fillingBuffer = tmp; - fillingBuffer.empty(true); - } - - // This provides a more robust termination condition - boolean done() { - return (samplesRead == totalSamples) && !looping; - } -} diff --git a/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Vec3f.java b/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Vec3f.java deleted file mode 100755 index 5b480a513..000000000 --- a/src/jogl/classes/com/jogamp/javafx/audio/windows/waveout/Vec3f.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - */ - -package com.jogamp.javafx.audio.windows.waveout; - -/** 3-element single-precision vector */ - -class Vec3f { - public static final Vec3f X_AXIS = new Vec3f( 1, 0, 0); - public static final Vec3f Y_AXIS = new Vec3f( 0, 1, 0); - public static final Vec3f Z_AXIS = new Vec3f( 0, 0, 1); - public static final Vec3f NEG_X_AXIS = new Vec3f(-1, 0, 0); - public static final Vec3f NEG_Y_AXIS = new Vec3f( 0, -1, 0); - public static final Vec3f NEG_Z_AXIS = new Vec3f( 0, 0, -1); - - private float x; - private float y; - private float z; - - public Vec3f() {} - - public Vec3f(Vec3f arg) { - set(arg); - } - - public Vec3f(float x, float y, float z) { - set(x, y, z); - } - - public Vec3f copy() { - return new Vec3f(this); - } - - public void set(Vec3f arg) { - set(arg.x, arg.y, arg.z); - } - - public void set(float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - } - - /** Sets the ith component, 0 <= i < 3 */ - public void set(int i, float val) { - switch (i) { - case 0: x = val; break; - case 1: y = val; break; - case 2: z = val; break; - default: throw new IndexOutOfBoundsException(); - } - } - - /** Gets the ith component, 0 <= i < 3 */ - public float get(int i) { - switch (i) { - case 0: return x; - case 1: return y; - case 2: return z; - default: throw new IndexOutOfBoundsException(); - } - } - - public float x() { return x; } - public float y() { return y; } - public float z() { return z; } - - public void setX(float x) { this.x = x; } - public void setY(float y) { this.y = y; } - public void setZ(float z) { this.z = z; } - - public float dot(Vec3f arg) { - return x * arg.x + y * arg.y + z * arg.z; - } - - public float length() { - return (float) Math.sqrt(lengthSquared()); - } - - public float lengthSquared() { - return this.dot(this); - } - - public void normalize() { - float len = length(); - if (len == 0.0f) return; - scale(1.0f / len); - } - - /** Returns this * val; creates new vector */ - public Vec3f times(float val) { - Vec3f tmp = new Vec3f(this); - tmp.scale(val); - return tmp; - } - - /** this = this * val */ - public void scale(float val) { - x *= val; - y *= val; - z *= val; - } - - /** Returns this + arg; creates new vector */ - public Vec3f plus(Vec3f arg) { - Vec3f tmp = new Vec3f(); - tmp.add(this, arg); - return tmp; - } - - /** this = this + b */ - public void add(Vec3f b) { - add(this, b); - } - - /** this = a + b */ - public void add(Vec3f a, Vec3f b) { - x = a.x + b.x; - y = a.y + b.y; - z = a.z + b.z; - } - - /** Returns this + s * arg; creates new vector */ - public Vec3f addScaled(float s, Vec3f arg) { - Vec3f tmp = new Vec3f(); - tmp.addScaled(this, s, arg); - return tmp; - } - - /** this = a + s * b */ - public void addScaled(Vec3f a, float s, Vec3f b) { - x = a.x + s * b.x; - y = a.y + s * b.y; - z = a.z + s * b.z; - } - - /** Returns this - arg; creates new vector */ - public Vec3f minus(Vec3f arg) { - Vec3f tmp = new Vec3f(); - tmp.sub(this, arg); - return tmp; - } - - /** this = this - b */ - public void sub(Vec3f b) { - sub(this, b); - } - - /** this = a - b */ - public void sub(Vec3f a, Vec3f b) { - x = a.x - b.x; - y = a.y - b.y; - z = a.z - b.z; - } - - /** Returns this cross arg; creates new vector */ - public Vec3f cross(Vec3f arg) { - Vec3f tmp = new Vec3f(); - tmp.cross(this, arg); - return tmp; - } - - /** this = a cross b. NOTE: "this" must be a different vector than - both a and b. */ - public void cross(Vec3f a, Vec3f b) { - x = a.y * b.z - a.z * b.y; - y = a.z * b.x - a.x * b.z; - z = a.x * b.y - a.y * b.x; - } - - /** Sets each component of this vector to the product of the - component with the corresponding component of the argument - vector. */ - public void componentMul(Vec3f arg) { - x *= arg.x; - y *= arg.y; - z *= arg.z; - } - - public String toString() { - return "(" + x + ", " + y + ", " + z + ")"; - } -} diff --git a/src/jogl/native/audio/Mixer.cpp b/src/jogl/native/audio/Mixer.cpp index 821a03246..9fa5b61bc 100755 --- a/src/jogl/native/audio/Mixer.cpp +++ b/src/jogl/native/audio/Mixer.cpp @@ -2,7 +2,7 @@ #include #include #include -#include "com_jogamp_javafx_audio_windows_waveout_Mixer.h" +#include "com_jogamp_audio_windows_waveout_Mixer.h" static HANDLE event = NULL; static HWAVEOUT output = NULL; @@ -57,7 +57,7 @@ void CALLBACK playbackCallback(HWAVEOUT output, } } -JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_initializeWaveOut +JNIEXPORT jboolean JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_initializeWaveOut (JNIEnv *env, jclass unused, jlong eventObject) { event = (HANDLE) eventObject; @@ -98,7 +98,7 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_in return JNI_TRUE; } -JNIEXPORT void JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_shutdownWaveOut +JNIEXPORT void JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_shutdownWaveOut (JNIEnv *env, jclass unused) { // writeString("Pausing\n"); @@ -109,7 +109,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_shutdo waveOutClose(output); } -JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_getNextMixerBuffer +JNIEXPORT jlong JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_getNextMixerBuffer (JNIEnv *env, jclass unused) { WAVEHDR* hdr = NULL; @@ -123,28 +123,28 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_getNe return (jlong) hdr; } -JNIEXPORT jobject JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_getMixerBufferData +JNIEXPORT jobject JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_getMixerBufferData (JNIEnv *env, jclass unused, jlong mixerBuffer) { WAVEHDR* hdr = (WAVEHDR*) mixerBuffer; return env->NewDirectByteBuffer(hdr->lpData, hdr->dwBufferLength); } -JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_getMixerBufferDataAddress +JNIEXPORT jlong JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_getMixerBufferDataAddress (JNIEnv *env, jclass unused, jlong mixerBuffer) { WAVEHDR* hdr = (WAVEHDR*) mixerBuffer; return (jlong) hdr->lpData; } -JNIEXPORT jint JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_getMixerBufferDataCapacity +JNIEXPORT jint JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_getMixerBufferDataCapacity (JNIEnv *env, jclass unused, jlong mixerBuffer) { WAVEHDR* hdr = (WAVEHDR*) mixerBuffer; return (jint) hdr->dwBufferLength; } -JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_prepareMixerBuffer +JNIEXPORT jboolean JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_prepareMixerBuffer (JNIEnv *env, jclass unused, jlong mixerBuffer) { MMRESULT res = waveOutPrepareHeader(output, @@ -156,7 +156,7 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_pr return JNI_FALSE; } -JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_writeMixerBuffer +JNIEXPORT jboolean JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_writeMixerBuffer (JNIEnv *env, jclass unused, jlong mixerBuffer) { MMRESULT res = waveOutWrite(output, @@ -170,13 +170,13 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_wr return JNI_FALSE; } -JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_CreateEvent +JNIEXPORT jlong JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_CreateEvent (JNIEnv *env, jclass unused) { return (jlong) CreateEvent(NULL, FALSE, TRUE, NULL); } -JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_WaitForSingleObject +JNIEXPORT jboolean JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_WaitForSingleObject (JNIEnv *env, jclass unused, jlong eventObject) { DWORD res = WaitForSingleObject((HANDLE) eventObject, INFINITE); @@ -186,13 +186,13 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_Wa return JNI_FALSE; } -JNIEXPORT void JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_SetEvent +JNIEXPORT void JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_SetEvent (JNIEnv *env, jclass unused, jlong eventObject) { SetEvent((HANDLE) eventObject); } -JNIEXPORT void JNICALL Java_com_jogamp_javafx_audio_windows_waveout_Mixer_CloseHandle +JNIEXPORT void JNICALL Java_com_jogamp_audio_windows_waveout_Mixer_CloseHandle (JNIEnv *env, jclass unused, jlong eventObject) { CloseHandle((HANDLE) eventObject); diff --git a/src/jogl/native/openmax/com_sun_openmax_OMXInstance.c b/src/jogl/native/openmax/com_sun_openmax_OMXInstance.c index 1ca973097..5317c2abc 100644 --- a/src/jogl/native/openmax/com_sun_openmax_OMXInstance.c +++ b/src/jogl/native/openmax/com_sun_openmax_OMXInstance.c @@ -1,5 +1,5 @@ /* - * javafx_media_video_Movie.c + * media_video_Movie.c * JFXFramework * * Created by sun on 17/02/08. @@ -21,8 +21,8 @@ static const char * const ClazzNameRuntimeException = "java/lang/RuntimeException"; static jclass runtimeExceptionClz=NULL; #ifdef _WIN32_WCE - #define STDOUT_FILE "\\Storage Card\\javafx_demos\\stdout.txt" - #define STDERR_FILE "\\Storage Card\\javafx_demos\\stderr.txt" + #define STDOUT_FILE "\\Storage Card\\demos\\stdout.txt" + #define STDERR_FILE "\\Storage Card\\demos\\stderr.txt" #endif static void _initStatics(JNIEnv *env) diff --git a/src/nativewindow/classes/javax/media/nativewindow/package.html b/src/nativewindow/classes/javax/media/nativewindow/package.html index d30b4a8df..fa422b2ab 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/package.html +++ b/src/nativewindow/classes/javax/media/nativewindow/package.html @@ -41,7 +41,7 @@
This protocol does not describe how to create native windows, but how to bind a native window to an implementation of {@link javax.media.nativewindow.NativeWindow NativeWindow}.
- However, an implementation of this protocol (e.g. {@link com.jogamp.javafx.newt}) may support the creation.
+ However, an implementation of this protocol (e.g. {@link com.jogamp.newt}) may support the creation.

Dependencies

This binding has dependencies to the following:

diff --git a/src/newt/classes/com/jogamp/javafx/newt/Display.java b/src/newt/classes/com/jogamp/javafx/newt/Display.java deleted file mode 100755 index 5c5db0338..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/Display.java +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt; - -import javax.media.nativewindow.*; -import com.jogamp.javafx.newt.impl.Debug; -import com.jogamp.javafx.newt.util.EventDispatchThread; -import java.util.*; - -public abstract class Display { - public static final boolean DEBUG = Debug.debug("Display"); - - private static Class getDisplayClass(String type) - throws ClassNotFoundException - { - Class displayClass = NewtFactory.getCustomClass(type, "Display"); - if(null==displayClass) { - if (NativeWindowFactory.TYPE_EGL.equals(type)) { - displayClass = Class.forName("com.jogamp.javafx.newt.opengl.kd.KDDisplay"); - } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) { - displayClass = Class.forName("com.jogamp.javafx.newt.windows.WindowsDisplay"); - } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { - displayClass = Class.forName("com.jogamp.javafx.newt.macosx.MacDisplay"); - } else if (NativeWindowFactory.TYPE_X11.equals(type)) { - displayClass = Class.forName("com.jogamp.javafx.newt.x11.X11Display"); - } else if (NativeWindowFactory.TYPE_AWT.equals(type)) { - displayClass = Class.forName("com.jogamp.javafx.newt.awt.AWTDisplay"); - } else { - throw new RuntimeException("Unknown display type \"" + type + "\""); - } - } - return displayClass; - } - - // Unique Display for each thread - private static ThreadLocal currentDisplayMap = new ThreadLocal(); - - /** Returns the thread local display map */ - public static Map getCurrentDisplayMap() { - Map displayMap = (Map) currentDisplayMap.get(); - if(null==displayMap) { - displayMap = new HashMap(); - currentDisplayMap.set( displayMap ); - } - return displayMap; - } - - /** maps the given display to the thread local display map - * and notifies all threads synchronized to this display map. */ - protected static Display setCurrentDisplay(Display display) { - Map displayMap = getCurrentDisplayMap(); - Display oldDisplay = null; - synchronized(displayMap) { - String name = display.getName(); - if(null==name) name="nil"; - oldDisplay = (Display) displayMap.put(name, display); - displayMap.notifyAll(); - } - return oldDisplay; - } - - /** removes the mapping of the given name from the thread local display map - * and notifies all threads synchronized to this display map. */ - protected static Display removeCurrentDisplay(String name) { - if(null==name) name="nil"; - Map displayMap = getCurrentDisplayMap(); - Display oldDisplay = null; - synchronized(displayMap) { - oldDisplay = (Display) displayMap.remove(name); - displayMap.notifyAll(); - } - return oldDisplay; - } - - /** Returns the thread local display mapped to the given name */ - public static Display getCurrentDisplay(String name) { - if(null==name) name="nil"; - Map displayMap = getCurrentDisplayMap(); - Display display = (Display) displayMap.get(name); - return display; - } - - public static void dumpDisplayMap(String prefix) { - Map displayMap = getCurrentDisplayMap(); - Set entrySet = displayMap.entrySet(); - Iterator i = entrySet.iterator(); - System.err.println(prefix+" DisplayMap["+entrySet.size()+"] "+Thread.currentThread()); - for(int j=0; i.hasNext(); j++) { - Map.Entry entry = (Map.Entry) i.next(); - System.err.println(" ["+j+"] "+entry.getKey()+" -> "+entry.getValue()); - } - } - - /** Returns the thread local display collection */ - public static Collection getCurrentDisplays() { - return getCurrentDisplayMap().values(); - } - - /** Make sure to reuse a Display with the same name */ - protected static Display create(String type, String name) { - try { - if(DEBUG) { - dumpDisplayMap("Display.create("+name+") BEGIN"); - } - Display display = getCurrentDisplay(name); - if(null==display) { - Class displayClass = getDisplayClass(type); - display = (Display) displayClass.newInstance(); - display.name=name; - display.refCount=1; - - if(NewtFactory.useEDT()) { - Thread current = Thread.currentThread(); - display.eventDispatchThread = new EventDispatchThread(display, current.getThreadGroup(), current.getName()); - display.eventDispatchThread.start(); - final Display f_dpy = display; - display.eventDispatchThread.invokeAndWait(new Runnable() { - public void run() { - f_dpy.createNative(); - } - } ); - } else { - display.createNative(); - } - if(null==display.aDevice) { - throw new RuntimeException("Display.createNative() failed to instanciate an AbstractGraphicsDevice"); - } - setCurrentDisplay(display); - if(DEBUG) { - System.err.println("Display.create("+name+") NEW: "+display+" "+Thread.currentThread()); - } - } else { - synchronized(display) { - display.refCount++; - if(DEBUG) { - System.err.println("Display.create("+name+") REUSE: refCount "+display.refCount+", "+display+" "+Thread.currentThread()); - } - } - } - if(DEBUG) { - dumpDisplayMap("Display.create("+name+") END"); - } - return display; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - protected static Display wrapHandle(String type, String name, AbstractGraphicsDevice aDevice) { - try { - Class displayClass = getDisplayClass(type); - Display display = (Display) displayClass.newInstance(); - display.name=name; - display.aDevice=aDevice; - return display; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public EventDispatchThread getEDT() { return eventDispatchThread; } - - public synchronized void destroy() { - if(DEBUG) { - dumpDisplayMap("Display.destroy("+name+") BEGIN"); - } - refCount--; - if(0==refCount) { - removeCurrentDisplay(name); - if(DEBUG) { - System.err.println("Display.destroy("+name+") REMOVE: "+this+" "+Thread.currentThread()); - } - if(null!=eventDispatchThread) { - final Display f_dpy = this; - final EventDispatchThread f_edt = eventDispatchThread; - eventDispatchThread.invokeAndWait(new Runnable() { - public void run() { - f_dpy.closeNative(); - f_edt.stop(); - } - } ); - } else { - closeNative(); - } - if(null!=eventDispatchThread) { - eventDispatchThread.waitUntilStopped(); - eventDispatchThread=null; - } - aDevice = null; - } else { - if(DEBUG) { - System.err.println("Display.destroy("+name+") KEEP: refCount "+refCount+", "+this+" "+Thread.currentThread()); - } - } - if(DEBUG) { - dumpDisplayMap("Display.destroy("+name+") END"); - } - } - - protected abstract void createNative(); - protected abstract void closeNative(); - - public String getName() { - return name; - } - - public long getHandle() { - if(null!=aDevice) { - return aDevice.getHandle(); - } - return 0; - } - - public AbstractGraphicsDevice getGraphicsDevice() { - return aDevice; - } - - public void pumpMessages() { - if(null!=eventDispatchThread) { - dispatchMessages(); - } else { - synchronized(this) { - dispatchMessages(); - } - } - } - - public String toString() { - return "NEWT-Display["+name+", refCount "+refCount+", "+aDevice+"]"; - } - - protected abstract void dispatchMessages(); - - /** Default impl. nop - Currently only X11 needs a Display lock */ - protected void lockDisplay() { } - - /** Default impl. nop - Currently only X11 needs a Display lock */ - protected void unlockDisplay() { } - - protected EventDispatchThread eventDispatchThread = null; - protected String name; - protected int refCount; - protected AbstractGraphicsDevice aDevice; -} - diff --git a/src/newt/classes/com/jogamp/javafx/newt/Event.java b/src/newt/classes/com/jogamp/javafx/newt/Event.java deleted file mode 100644 index 4274454ab..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/Event.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt; - -public class Event { - private boolean isSystemEvent; - private int eventType; - private Window source; - private long when; - - Event(boolean isSystemEvent, int eventType, Window source, long when) { - this.isSystemEvent = isSystemEvent; - this.eventType = eventType; - this.source = source; - this.when = when; - } - - protected Event(int eventType, Window source, long when) { - this(false, eventType, source, when); - } - - /** Indicates whether this event was produced by the system or - generated by user code. */ - public final boolean isSystemEvent() { - return isSystemEvent; - } - - /** Returns the event type of this event. */ - public final int getEventType() { - return eventType; - } - - /** Returns the source Window which produced this Event. */ - public final Window getSource() { - return source; - } - - /** Returns the timestamp, in milliseconds, of this event. */ - public final long getWhen() { - return when; - } - - public String toString() { - return "Event[sys:"+isSystemEvent()+", source:"+getSource()+", when:"+getWhen()+"]"; - } - - public static String toHexString(int hex) { - return "0x" + Integer.toHexString(hex); - } - - public static String toHexString(long hex) { - return "0x" + Long.toHexString(hex); - } - -} diff --git a/src/newt/classes/com/jogamp/javafx/newt/EventListener.java b/src/newt/classes/com/jogamp/javafx/newt/EventListener.java deleted file mode 100644 index 065cc1de3..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/EventListener.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt; - -public interface EventListener -{ - public static final int WINDOW = 1 << 0; - public static final int MOUSE = 1 << 1; - public static final int KEY = 1 << 2; - public static final int SURFACE = 1 << 3; - -} - diff --git a/src/newt/classes/com/jogamp/javafx/newt/InputEvent.java b/src/newt/classes/com/jogamp/javafx/newt/InputEvent.java deleted file mode 100644 index 0cfaaa4c0..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/InputEvent.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt; - -public abstract class InputEvent extends Event -{ - public static final int SHIFT_MASK = 1 << 0; - public static final int CTRL_MASK = 1 << 1; - public static final int META_MASK = 1 << 2; - public static final int ALT_MASK = 1 << 3; - public static final int ALT_GRAPH_MASK = 1 << 5; - public static final int BUTTON1_MASK = 1 << 6; - public static final int BUTTON2_MASK = 1 << 7; - public static final int BUTTON3_MASK = 1 << 8; - - protected InputEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers) { - super(sysEvent, eventType, source, when); - this.consumed=false; - this.modifiers=modifiers; - } - - public void consume() { - consumed=true; - } - - public boolean isConsumed() { - return consumed; - } - public int getModifiers() { - return modifiers; - } - public boolean isAltDown() { - return (modifiers&ALT_MASK)!=0; - } - public boolean isAltGraphDown() { - return (modifiers&ALT_GRAPH_MASK)!=0; - } - public boolean isControlDown() { - return (modifiers&CTRL_MASK)!=0; - } - public boolean isMetaDown() { - return (modifiers&META_MASK)!=0; - } - public boolean isShiftDown() { - return (modifiers&SHIFT_MASK)!=0; - } - - public boolean isButton1Down() { - return (modifiers&BUTTON1_MASK)!=0; - } - - public boolean isButton2Down() { - return (modifiers&BUTTON2_MASK)!=0; - } - - public boolean isButton3Down() { - return (modifiers&BUTTON3_MASK)!=0; - } - - public String toString() { - return "InputEvent[modifiers:"+modifiers+"]"; - } - - private boolean consumed; - private int modifiers; -} diff --git a/src/newt/classes/com/jogamp/javafx/newt/Insets.java b/src/newt/classes/com/jogamp/javafx/newt/Insets.java deleted file mode 100644 index 5c91847f4..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/Insets.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2009 Sun Microsystems, Inc. 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. - * - */ -package com.jogamp.javafx.newt; - -/** - * Simple class representing insets. - * - * @author tdv - */ -public class Insets implements Cloneable { - public int top; - public int left; - public int bottom; - public int right; - - /** - * Creates and initializes a new Insets object with the - * specified top, left, bottom, and right insets. - * @param top the inset from the top. - * @param left the inset from the left. - * @param bottom the inset from the bottom. - * @param right the inset from the right. - */ - public Insets(int top, int left, int bottom, int right) { - this.top = top; - this.left = left; - this.bottom = bottom; - this.right = right; - } - - /** - * Checks whether two insets objects are equal. Two instances - * of Insets are equal if the four integer values - * of the fields top, left, - * bottom, and right are all equal. - * @return true if the two insets are equal; - * otherwise false. - */ - public boolean equals(Object obj) { - if (obj instanceof Insets) { - Insets insets = (Insets)obj; - return ((top == insets.top) && (left == insets.left) && - (bottom == insets.bottom) && (right == insets.right)); - } - return false; - } - - /** - * Returns the hash code for this Insets. - * - * @return a hash code for this Insets. - */ - public int hashCode() { - int sum1 = left + bottom; - int sum2 = right + top; - int val1 = sum1 * (sum1 + 1)/2 + left; - int val2 = sum2 * (sum2 + 1)/2 + top; - int sum3 = val1 + val2; - return sum3 * (sum3 + 1)/2 + val2; - } - - public String toString() { - return getClass().getName() + "[top=" + top + ",left=" + left + - ",bottom=" + bottom + ",right=" + right + "]"; - } - - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException ex) { - throw new InternalError(); - } - } - -} diff --git a/src/newt/classes/com/jogamp/javafx/newt/KeyEvent.java b/src/newt/classes/com/jogamp/javafx/newt/KeyEvent.java deleted file mode 100644 index 8ae92464c..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/KeyEvent.java +++ /dev/null @@ -1,738 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt; - -public class KeyEvent extends InputEvent -{ - KeyEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers, int keyCode, char keyChar) { - super(sysEvent, eventType, source, when, modifiers); - this.keyCode=keyCode; - this.keyChar=keyChar; - } - public KeyEvent(int eventType, Window source, long when, int modifiers, int keyCode, char keyChar) { - this(false, eventType, source, when, modifiers, keyCode, keyChar); - } - - public char getKeyChar() { - return keyChar; - } - public int getKeyCode() { - return keyCode; - } - - public String toString() { - return "KeyEvent["+getEventTypeString(getEventType())+ - ", code "+keyCode+"("+toHexString(keyCode)+"), char <"+keyChar+"> ("+toHexString((int)keyChar)+"), isActionKey "+isActionKey()+", "+super.toString()+"]"; - } - - public static String getEventTypeString(int type) { - switch(type) { - case EVENT_KEY_PRESSED: return "EVENT_KEY_PRESSED"; - case EVENT_KEY_RELEASED: return "EVENT_KEY_RELEASED"; - case EVENT_KEY_TYPED: return "EVENT_KEY_TYPED"; - default: return "unknown (" + type + ")"; - } - } - - public boolean isActionKey() { - switch (keyCode) { - case VK_HOME: - case VK_END: - case VK_PAGE_UP: - case VK_PAGE_DOWN: - case VK_UP: - case VK_DOWN: - case VK_LEFT: - case VK_RIGHT: - - case VK_F1: - case VK_F2: - case VK_F3: - case VK_F4: - case VK_F5: - case VK_F6: - case VK_F7: - case VK_F8: - case VK_F9: - case VK_F10: - case VK_F11: - case VK_F12: - case VK_F13: - case VK_F14: - case VK_F15: - case VK_F16: - case VK_F17: - case VK_F18: - case VK_F19: - case VK_F20: - case VK_F21: - case VK_F22: - case VK_F23: - case VK_F24: - case VK_PRINTSCREEN: - case VK_CAPS_LOCK: - case VK_PAUSE: - case VK_INSERT: - - case VK_HELP: - case VK_WINDOWS: - return true; - } - return false; - } - - private int keyCode; - private char keyChar; - - public static final int EVENT_KEY_PRESSED = 300; - public static final int EVENT_KEY_RELEASED= 301; - public static final int EVENT_KEY_TYPED = 302; - - /* Virtual key codes. */ - - public static final int VK_ENTER = '\n'; - public static final int VK_BACK_SPACE = '\b'; - public static final int VK_TAB = '\t'; - public static final int VK_CANCEL = 0x03; - public static final int VK_CLEAR = 0x0C; - public static final int VK_SHIFT = 0x10; - public static final int VK_CONTROL = 0x11; - public static final int VK_ALT = 0x12; - public static final int VK_PAUSE = 0x13; - public static final int VK_CAPS_LOCK = 0x14; - public static final int VK_ESCAPE = 0x1B; - public static final int VK_SPACE = 0x20; - public static final int VK_PAGE_UP = 0x21; - public static final int VK_PAGE_DOWN = 0x22; - public static final int VK_END = 0x23; - public static final int VK_HOME = 0x24; - - /** - * Constant for the non-numpad left arrow key. - * @see #VK_KP_LEFT - */ - public static final int VK_LEFT = 0x25; - - /** - * Constant for the non-numpad up arrow key. - * @see #VK_KP_UP - */ - public static final int VK_UP = 0x26; - - /** - * Constant for the non-numpad right arrow key. - * @see #VK_KP_RIGHT - */ - public static final int VK_RIGHT = 0x27; - - /** - * Constant for the non-numpad down arrow key. - * @see #VK_KP_DOWN - */ - public static final int VK_DOWN = 0x28; - - /** - * Constant for the comma key, "," - */ - public static final int VK_COMMA = 0x2C; - - /** - * Constant for the minus key, "-" - * @since 1.2 - */ - public static final int VK_MINUS = 0x2D; - - /** - * Constant for the period key, "." - */ - public static final int VK_PERIOD = 0x2E; - - /** - * Constant for the forward slash key, "/" - */ - public static final int VK_SLASH = 0x2F; - - /** VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */ - public static final int VK_0 = 0x30; - public static final int VK_1 = 0x31; - public static final int VK_2 = 0x32; - public static final int VK_3 = 0x33; - public static final int VK_4 = 0x34; - public static final int VK_5 = 0x35; - public static final int VK_6 = 0x36; - public static final int VK_7 = 0x37; - public static final int VK_8 = 0x38; - public static final int VK_9 = 0x39; - - /** - * Constant for the semicolon key, ";" - */ - public static final int VK_SEMICOLON = 0x3B; - - /** - * Constant for the equals key, "=" - */ - public static final int VK_EQUALS = 0x3D; - - /** VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */ - public static final int VK_A = 0x41; - public static final int VK_B = 0x42; - public static final int VK_C = 0x43; - public static final int VK_D = 0x44; - public static final int VK_E = 0x45; - public static final int VK_F = 0x46; - public static final int VK_G = 0x47; - public static final int VK_H = 0x48; - public static final int VK_I = 0x49; - public static final int VK_J = 0x4A; - public static final int VK_K = 0x4B; - public static final int VK_L = 0x4C; - public static final int VK_M = 0x4D; - public static final int VK_N = 0x4E; - public static final int VK_O = 0x4F; - public static final int VK_P = 0x50; - public static final int VK_Q = 0x51; - public static final int VK_R = 0x52; - public static final int VK_S = 0x53; - public static final int VK_T = 0x54; - public static final int VK_U = 0x55; - public static final int VK_V = 0x56; - public static final int VK_W = 0x57; - public static final int VK_X = 0x58; - public static final int VK_Y = 0x59; - public static final int VK_Z = 0x5A; - - /** - * Constant for the open bracket key, "[" - */ - public static final int VK_OPEN_BRACKET = 0x5B; - - /** - * Constant for the back slash key, "\" - */ - public static final int VK_BACK_SLASH = 0x5C; - - /** - * Constant for the close bracket key, "]" - */ - public static final int VK_CLOSE_BRACKET = 0x5D; - - public static final int VK_NUMPAD0 = 0x60; - public static final int VK_NUMPAD1 = 0x61; - public static final int VK_NUMPAD2 = 0x62; - public static final int VK_NUMPAD3 = 0x63; - public static final int VK_NUMPAD4 = 0x64; - public static final int VK_NUMPAD5 = 0x65; - public static final int VK_NUMPAD6 = 0x66; - public static final int VK_NUMPAD7 = 0x67; - public static final int VK_NUMPAD8 = 0x68; - public static final int VK_NUMPAD9 = 0x69; - public static final int VK_MULTIPLY = 0x6A; - public static final int VK_ADD = 0x6B; - - /** - * This constant is obsolete, and is included only for backwards - * compatibility. - * @see #VK_SEPARATOR - */ - public static final int VK_SEPARATER = 0x6C; - - /** - * Constant for the Numpad Separator key. - * @since 1.4 - */ - public static final int VK_SEPARATOR = VK_SEPARATER; - - public static final int VK_SUBTRACT = 0x6D; - public static final int VK_DECIMAL = 0x6E; - public static final int VK_DIVIDE = 0x6F; - public static final int VK_DELETE = 0x7F; /* ASCII DEL */ - public static final int VK_NUM_LOCK = 0x90; - public static final int VK_SCROLL_LOCK = 0x91; - - /** Constant for the F1 function key. */ - public static final int VK_F1 = 0x70; - - /** Constant for the F2 function key. */ - public static final int VK_F2 = 0x71; - - /** Constant for the F3 function key. */ - public static final int VK_F3 = 0x72; - - /** Constant for the F4 function key. */ - public static final int VK_F4 = 0x73; - - /** Constant for the F5 function key. */ - public static final int VK_F5 = 0x74; - - /** Constant for the F6 function key. */ - public static final int VK_F6 = 0x75; - - /** Constant for the F7 function key. */ - public static final int VK_F7 = 0x76; - - /** Constant for the F8 function key. */ - public static final int VK_F8 = 0x77; - - /** Constant for the F9 function key. */ - public static final int VK_F9 = 0x78; - - /** Constant for the F10 function key. */ - public static final int VK_F10 = 0x79; - - /** Constant for the F11 function key. */ - public static final int VK_F11 = 0x7A; - - /** Constant for the F12 function key. */ - public static final int VK_F12 = 0x7B; - - /** - * Constant for the F13 function key. - * @since 1.2 - */ - /* F13 - F24 are used on IBM 3270 keyboard; use random range for constants. */ - public static final int VK_F13 = 0xF000; - - /** - * Constant for the F14 function key. - * @since 1.2 - */ - public static final int VK_F14 = 0xF001; - - /** - * Constant for the F15 function key. - * @since 1.2 - */ - public static final int VK_F15 = 0xF002; - - /** - * Constant for the F16 function key. - * @since 1.2 - */ - public static final int VK_F16 = 0xF003; - - /** - * Constant for the F17 function key. - * @since 1.2 - */ - public static final int VK_F17 = 0xF004; - - /** - * Constant for the F18 function key. - * @since 1.2 - */ - public static final int VK_F18 = 0xF005; - - /** - * Constant for the F19 function key. - * @since 1.2 - */ - public static final int VK_F19 = 0xF006; - - /** - * Constant for the F20 function key. - * @since 1.2 - */ - public static final int VK_F20 = 0xF007; - - /** - * Constant for the F21 function key. - * @since 1.2 - */ - public static final int VK_F21 = 0xF008; - - /** - * Constant for the F22 function key. - * @since 1.2 - */ - public static final int VK_F22 = 0xF009; - - /** - * Constant for the F23 function key. - * @since 1.2 - */ - public static final int VK_F23 = 0xF00A; - - /** - * Constant for the F24 function key. - * @since 1.2 - */ - public static final int VK_F24 = 0xF00B; - - public static final int VK_PRINTSCREEN = 0x9A; - public static final int VK_INSERT = 0x9B; - public static final int VK_HELP = 0x9C; - public static final int VK_META = 0x9D; - - public static final int VK_BACK_QUOTE = 0xC0; - public static final int VK_QUOTE = 0xDE; - - /** - * Constant for the numeric keypad up arrow key. - * @see #VK_UP - * @since 1.2 - */ - public static final int VK_KP_UP = 0xE0; - - /** - * Constant for the numeric keypad down arrow key. - * @see #VK_DOWN - * @since 1.2 - */ - public static final int VK_KP_DOWN = 0xE1; - - /** - * Constant for the numeric keypad left arrow key. - * @see #VK_LEFT - * @since 1.2 - */ - public static final int VK_KP_LEFT = 0xE2; - - /** - * Constant for the numeric keypad right arrow key. - * @see #VK_RIGHT - * @since 1.2 - */ - public static final int VK_KP_RIGHT = 0xE3; - - /* For European keyboards */ - /** @since 1.2 */ - public static final int VK_DEAD_GRAVE = 0x80; - /** @since 1.2 */ - public static final int VK_DEAD_ACUTE = 0x81; - /** @since 1.2 */ - public static final int VK_DEAD_CIRCUMFLEX = 0x82; - /** @since 1.2 */ - public static final int VK_DEAD_TILDE = 0x83; - /** @since 1.2 */ - public static final int VK_DEAD_MACRON = 0x84; - /** @since 1.2 */ - public static final int VK_DEAD_BREVE = 0x85; - /** @since 1.2 */ - public static final int VK_DEAD_ABOVEDOT = 0x86; - /** @since 1.2 */ - public static final int VK_DEAD_DIAERESIS = 0x87; - /** @since 1.2 */ - public static final int VK_DEAD_ABOVERING = 0x88; - /** @since 1.2 */ - public static final int VK_DEAD_DOUBLEACUTE = 0x89; - /** @since 1.2 */ - public static final int VK_DEAD_CARON = 0x8a; - /** @since 1.2 */ - public static final int VK_DEAD_CEDILLA = 0x8b; - /** @since 1.2 */ - public static final int VK_DEAD_OGONEK = 0x8c; - /** @since 1.2 */ - public static final int VK_DEAD_IOTA = 0x8d; - /** @since 1.2 */ - public static final int VK_DEAD_VOICED_SOUND = 0x8e; - /** @since 1.2 */ - public static final int VK_DEAD_SEMIVOICED_SOUND = 0x8f; - - /** @since 1.2 */ - public static final int VK_AMPERSAND = 0x96; - /** @since 1.2 */ - public static final int VK_ASTERISK = 0x97; - /** @since 1.2 */ - public static final int VK_QUOTEDBL = 0x98; - /** @since 1.2 */ - public static final int VK_LESS = 0x99; - - /** @since 1.2 */ - public static final int VK_GREATER = 0xa0; - /** @since 1.2 */ - public static final int VK_BRACELEFT = 0xa1; - /** @since 1.2 */ - public static final int VK_BRACERIGHT = 0xa2; - - /** - * Constant for the "@" key. - * @since 1.2 - */ - public static final int VK_AT = 0x0200; - - /** - * Constant for the ":" key. - * @since 1.2 - */ - public static final int VK_COLON = 0x0201; - - /** - * Constant for the "^" key. - * @since 1.2 - */ - public static final int VK_CIRCUMFLEX = 0x0202; - - /** - * Constant for the "$" key. - * @since 1.2 - */ - public static final int VK_DOLLAR = 0x0203; - - /** - * Constant for the Euro currency sign key. - * @since 1.2 - */ - public static final int VK_EURO_SIGN = 0x0204; - - /** - * Constant for the "!" key. - * @since 1.2 - */ - public static final int VK_EXCLAMATION_MARK = 0x0205; - - /** - * Constant for the inverted exclamation mark key. - * @since 1.2 - */ - public static final int VK_INVERTED_EXCLAMATION_MARK = 0x0206; - - /** - * Constant for the "(" key. - * @since 1.2 - */ - public static final int VK_LEFT_PARENTHESIS = 0x0207; - - /** - * Constant for the "#" key. - * @since 1.2 - */ - public static final int VK_NUMBER_SIGN = 0x0208; - - /** - * Constant for the "+" key. - * @since 1.2 - */ - public static final int VK_PLUS = 0x0209; - - /** - * Constant for the ")" key. - * @since 1.2 - */ - public static final int VK_RIGHT_PARENTHESIS = 0x020A; - - /** - * Constant for the "_" key. - * @since 1.2 - */ - public static final int VK_UNDERSCORE = 0x020B; - - /** - * Constant for the Microsoft Windows "Windows" key. - * It is used for both the left and right version of the key. - * @see #getKeyLocation() - * @since 1.5 - */ - public static final int VK_WINDOWS = 0x020C; - - /** - * Constant for the Microsoft Windows Context Menu key. - * @since 1.5 - */ - public static final int VK_CONTEXT_MENU = 0x020D; - - /* for input method support on Asian Keyboards */ - - /* not clear what this means - listed in Microsoft Windows API */ - public static final int VK_FINAL = 0x0018; - - /** Constant for the Convert function key. */ - /* Japanese PC 106 keyboard, Japanese Solaris keyboard: henkan */ - public static final int VK_CONVERT = 0x001C; - - /** Constant for the Don't Convert function key. */ - /* Japanese PC 106 keyboard: muhenkan */ - public static final int VK_NONCONVERT = 0x001D; - - /** Constant for the Accept or Commit function key. */ - /* Japanese Solaris keyboard: kakutei */ - public static final int VK_ACCEPT = 0x001E; - - /* not clear what this means - listed in Microsoft Windows API */ - public static final int VK_MODECHANGE = 0x001F; - - /* replaced by VK_KANA_LOCK for Microsoft Windows and Solaris; - might still be used on other platforms */ - public static final int VK_KANA = 0x0015; - - /* replaced by VK_INPUT_METHOD_ON_OFF for Microsoft Windows and Solaris; - might still be used for other platforms */ - public static final int VK_KANJI = 0x0019; - - /** - * Constant for the Alphanumeric function key. - * @since 1.2 - */ - /* Japanese PC 106 keyboard: eisuu */ - public static final int VK_ALPHANUMERIC = 0x00F0; - - /** - * Constant for the Katakana function key. - * @since 1.2 - */ - /* Japanese PC 106 keyboard: katakana */ - public static final int VK_KATAKANA = 0x00F1; - - /** - * Constant for the Hiragana function key. - * @since 1.2 - */ - /* Japanese PC 106 keyboard: hiragana */ - public static final int VK_HIRAGANA = 0x00F2; - - /** - * Constant for the Full-Width Characters function key. - * @since 1.2 - */ - /* Japanese PC 106 keyboard: zenkaku */ - public static final int VK_FULL_WIDTH = 0x00F3; - - /** - * Constant for the Half-Width Characters function key. - * @since 1.2 - */ - /* Japanese PC 106 keyboard: hankaku */ - public static final int VK_HALF_WIDTH = 0x00F4; - - /** - * Constant for the Roman Characters function key. - * @since 1.2 - */ - /* Japanese PC 106 keyboard: roumaji */ - public static final int VK_ROMAN_CHARACTERS = 0x00F5; - - /** - * Constant for the All Candidates function key. - * @since 1.2 - */ - /* Japanese PC 106 keyboard - VK_CONVERT + ALT: zenkouho */ - public static final int VK_ALL_CANDIDATES = 0x0100; - - /** - * Constant for the Previous Candidate function key. - * @since 1.2 - */ - /* Japanese PC 106 keyboard - VK_CONVERT + SHIFT: maekouho */ - public static final int VK_PREVIOUS_CANDIDATE = 0x0101; - - /** - * Constant for the Code Input function key. - * @since 1.2 - */ - /* Japanese PC 106 keyboard - VK_ALPHANUMERIC + ALT: kanji bangou */ - public static final int VK_CODE_INPUT = 0x0102; - - /** - * Constant for the Japanese-Katakana function key. - * This key switches to a Japanese input method and selects its Katakana input mode. - * @since 1.2 - */ - /* Japanese Macintosh keyboard - VK_JAPANESE_HIRAGANA + SHIFT */ - public static final int VK_JAPANESE_KATAKANA = 0x0103; - - /** - * Constant for the Japanese-Hiragana function key. - * This key switches to a Japanese input method and selects its Hiragana input mode. - * @since 1.2 - */ - /* Japanese Macintosh keyboard */ - public static final int VK_JAPANESE_HIRAGANA = 0x0104; - - /** - * Constant for the Japanese-Roman function key. - * This key switches to a Japanese input method and selects its Roman-Direct input mode. - * @since 1.2 - */ - /* Japanese Macintosh keyboard */ - public static final int VK_JAPANESE_ROMAN = 0x0105; - - /** - * Constant for the locking Kana function key. - * This key locks the keyboard into a Kana layout. - * @since 1.3 - */ - /* Japanese PC 106 keyboard with special Windows driver - eisuu + Control; Japanese Solaris keyboard: kana */ - public static final int VK_KANA_LOCK = 0x0106; - - /** - * Constant for the input method on/off key. - * @since 1.3 - */ - /* Japanese PC 106 keyboard: kanji. Japanese Solaris keyboard: nihongo */ - public static final int VK_INPUT_METHOD_ON_OFF = 0x0107; - - /* for Sun keyboards */ - /** @since 1.2 */ - public static final int VK_CUT = 0xFFD1; - /** @since 1.2 */ - public static final int VK_COPY = 0xFFCD; - /** @since 1.2 */ - public static final int VK_PASTE = 0xFFCF; - /** @since 1.2 */ - public static final int VK_UNDO = 0xFFCB; - /** @since 1.2 */ - public static final int VK_AGAIN = 0xFFC9; - /** @since 1.2 */ - public static final int VK_FIND = 0xFFD0; - /** @since 1.2 */ - public static final int VK_PROPS = 0xFFCA; - /** @since 1.2 */ - public static final int VK_STOP = 0xFFC8; - - /** - * Constant for the Compose function key. - * @since 1.2 - */ - public static final int VK_COMPOSE = 0xFF20; - - /** - * Constant for the AltGraph function key. - * @since 1.2 - */ - public static final int VK_ALT_GRAPH = 0xFF7E; - - /** - * Constant for the Begin key. - * @since 1.5 - */ - public static final int VK_BEGIN = 0xFF58; - - /** - * This value is used to indicate that the keyCode is unknown. - * KEY_TYPED events do not have a keyCode value; this value - * is used instead. - */ - public static final int VK_UNDEFINED = 0x0; -} - diff --git a/src/newt/classes/com/jogamp/javafx/newt/KeyListener.java b/src/newt/classes/com/jogamp/javafx/newt/KeyListener.java deleted file mode 100644 index 7921a0a97..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/KeyListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt; - -public interface KeyListener extends EventListener -{ - public void keyPressed(KeyEvent e); - public void keyReleased(KeyEvent e); - public void keyTyped(KeyEvent e) ; -} - diff --git a/src/newt/classes/com/jogamp/javafx/newt/MouseEvent.java b/src/newt/classes/com/jogamp/javafx/newt/MouseEvent.java deleted file mode 100644 index 82989e216..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/MouseEvent.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt; - -public class MouseEvent extends InputEvent -{ - public static final int BUTTON1 = 1; - public static final int BUTTON2 = 2; - public static final int BUTTON3 = 3; - public static final int BUTTON4 = 4; - public static final int BUTTON5 = 5; - public static final int BUTTON6 = 6; - public static final int BUTTON_NUMBER = 6; - - protected MouseEvent(boolean sysEvent, int eventType, Window source, long when, - int modifiers, int x, int y, int clickCount, int button, - int rotation) - { - super(sysEvent, eventType, source, when, modifiers); - this.x=x; - this.y=y; - this.clickCount=clickCount; - this.button=button; - this.wheelRotation = rotation; - } - public MouseEvent(int eventType, Window source, long when, int modifiers, - int x, int y, int clickCount, int button, int rotation) { - this(false, eventType, source, when, modifiers, x, y, clickCount, button, - rotation); - } - - public int getButton() { - return button; - } - public int getClickCount() { - return clickCount; - } - public int getX() { - return x; - } - public int getY() { - return y; - } - public int getWheelRotation() { - return wheelRotation; - } - - public String toString() { - return "MouseEvent["+getEventTypeString(getEventType())+ - ", "+x+"/"+y+", button "+button+", count "+clickCount+ - ", wheel rotation "+wheelRotation+ - ", "+super.toString()+"]"; - } - - public static String getEventTypeString(int type) { - switch(type) { - case EVENT_MOUSE_CLICKED: return "EVENT_MOUSE_CLICKED"; - case EVENT_MOUSE_ENTERED: return "EVENT_MOUSE_ENTERED"; - case EVENT_MOUSE_EXITED: return "EVENT_MOUSE_EXITED"; - case EVENT_MOUSE_PRESSED: return "EVENT_MOUSE_PRESSED"; - case EVENT_MOUSE_RELEASED: return "EVENT_MOUSE_RELEASED"; - case EVENT_MOUSE_MOVED: return "EVENT_MOUSE_MOVED"; - case EVENT_MOUSE_DRAGGED: return "EVENT_MOUSE_DRAGGED"; - case EVENT_MOUSE_WHEEL_MOVED: return "EVENT_MOUSE_WHEEL_MOVED"; - default: return "unknown (" + type + ")"; - } - } - - private int x, y, clickCount, button, wheelRotation; - - public static final int EVENT_MOUSE_CLICKED = 200; - public static final int EVENT_MOUSE_ENTERED = 201; - public static final int EVENT_MOUSE_EXITED = 202; - public static final int EVENT_MOUSE_PRESSED = 203; - public static final int EVENT_MOUSE_RELEASED = 204; - public static final int EVENT_MOUSE_MOVED = 205; - public static final int EVENT_MOUSE_DRAGGED = 206; - public static final int EVENT_MOUSE_WHEEL_MOVED = 207; -} diff --git a/src/newt/classes/com/jogamp/javafx/newt/MouseListener.java b/src/newt/classes/com/jogamp/javafx/newt/MouseListener.java deleted file mode 100644 index a0d42f738..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/MouseListener.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt; - -public interface MouseListener extends EventListener -{ - public void mouseClicked(MouseEvent e); - public void mouseEntered(MouseEvent e); - public void mouseExited(MouseEvent e); - public void mousePressed(MouseEvent e); - public void mouseReleased(MouseEvent e); - public void mouseMoved(MouseEvent e); - public void mouseDragged(MouseEvent e); - public void mouseWheelMoved(MouseEvent e); -} - diff --git a/src/newt/classes/com/jogamp/javafx/newt/NewtFactory.java b/src/newt/classes/com/jogamp/javafx/newt/NewtFactory.java deleted file mode 100755 index aae51aaf6..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/NewtFactory.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt; - -import javax.media.nativewindow.*; -import java.util.ArrayList; -import java.util.Iterator; -import com.jogamp.nativewindow.impl.jvm.JVMUtil; - -public abstract class NewtFactory { - // Work-around for initialization order problems on Mac OS X - // between native Newt and (apparently) Fmod - static { - JVMUtil.initSingleton(); - Window.init(NativeWindowFactory.getNativeWindowType(true)); - } - - static Class getCustomClass(String packageName, String classBaseName) { - Class clazz = null; - if(packageName!=null || classBaseName!=null) { - String clazzName = packageName + "." + classBaseName ; - try { - clazz = Class.forName(clazzName); - } catch (Throwable t) {} - } - return clazz; - } - - private static boolean useEDT = true; - - /** - * Toggles the usage of an EventDispatchThread while creating a Display.
- * The default is enabled.
- * The EventDispatchThread is thread local to the Display instance.
- */ - public static synchronized void setUseEDT(boolean onoff) { - useEDT = onoff; - } - - /** @see #setUseEDT(boolean) */ - public static boolean useEDT() { return useEDT; } - - /** - * Create a Display entity, incl native creation - */ - public static Display createDisplay(String name) { - return Display.create(NativeWindowFactory.getNativeWindowType(true), name); - } - - /** - * Create a Display entity using the given implementation type, incl native creation - */ - public static Display createDisplay(String type, String name) { - return Display.create(type, name); - } - - /** - * Create a Screen entity, incl native creation - */ - public static Screen createScreen(Display display, int index) { - return Screen.create(NativeWindowFactory.getNativeWindowType(true), display, index); - } - - /** - * Create a Screen entity using the given implementation type, incl native creation - */ - public static Screen createScreen(String type, Display display, int index) { - return Screen.create(type, display, index); - } - - /** - * Create a Window entity, incl native creation - */ - public static Window createWindow(Screen screen, Capabilities caps) { - return Window.create(NativeWindowFactory.getNativeWindowType(true), 0, screen, caps, false); - } - - public static Window createWindow(Screen screen, Capabilities caps, boolean undecorated) { - return Window.create(NativeWindowFactory.getNativeWindowType(true), 0, screen, caps, undecorated); - } - - public static Window createWindow(long parentWindowHandle, Screen screen, Capabilities caps, boolean undecorated) { - return Window.create(NativeWindowFactory.getNativeWindowType(true), parentWindowHandle, screen, caps, undecorated); - } - - /** - * Ability to try a Window type with a construnctor argument, if supported ..

- * Currently only valid is AWTWindow(Frame frame) , - * to support an external created AWT Frame, ie the browsers embedded frame. - */ - public static Window createWindow(Object[] cstrArguments, Screen screen, Capabilities caps, boolean undecorated) { - return Window.create(NativeWindowFactory.getNativeWindowType(true), cstrArguments, screen, caps, undecorated); - } - - /** - * Create a Window entity using the given implementation type, incl native creation - */ - public static Window createWindow(String type, Screen screen, Capabilities caps) { - return Window.create(type, 0, screen, caps, false); - } - - public static Window createWindow(String type, Screen screen, Capabilities caps, boolean undecorated) { - return Window.create(type, 0, screen, caps, undecorated); - } - - public static Window createWindow(String type, long parentWindowHandle, Screen screen, Capabilities caps, boolean undecorated) { - return Window.create(type, parentWindowHandle, screen, caps, undecorated); - } - - public static Window createWindow(String type, Object[] cstrArguments, Screen screen, Capabilities caps, boolean undecorated) { - return Window.create(type, cstrArguments, screen, caps, undecorated); - } - - /** - * Instantiate a Display entity using the native handle. - */ - public static Display wrapDisplay(String name, AbstractGraphicsDevice device) { - return Display.wrapHandle(NativeWindowFactory.getNativeWindowType(true), name, device); - } - - /** - * Instantiate a Screen entity using the native handle. - */ - public static Screen wrapScreen(Display display, AbstractGraphicsScreen screen) { - return Screen.wrapHandle(NativeWindowFactory.getNativeWindowType(true), display, screen); - } - - /** - * Instantiate a Window entity using the native handle. - */ - public static Window wrapWindow(Screen screen, AbstractGraphicsConfiguration config, - long windowHandle, boolean fullscreen, boolean visible, - int x, int y, int width, int height) { - return Window.wrapHandle(NativeWindowFactory.getNativeWindowType(true), screen, config, - windowHandle, fullscreen, visible, x, y, width, height); - } - - private static final boolean instanceOf(Object obj, String clazzName) { - Class clazz = obj.getClass(); - do { - if(clazz.getName().equals(clazzName)) { - return true; - } - clazz = clazz.getSuperclass(); - } while (clazz!=null); - return false; - } - -} - diff --git a/src/newt/classes/com/jogamp/javafx/newt/OffscreenWindow.java b/src/newt/classes/com/jogamp/javafx/newt/OffscreenWindow.java deleted file mode 100644 index 015e9b8d2..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/OffscreenWindow.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt; - -import javax.media.nativewindow.*; - -public class OffscreenWindow extends Window implements SurfaceChangeable { - - long surfaceHandle = 0; - - public OffscreenWindow() { - } - - static long nextWindowHandle = 0x100; // start here - a marker - - protected void createNative(long parentWindowHandle, Capabilities caps) { - if(0!=parentWindowHandle) { - throw new NativeWindowException("OffscreenWindow does not support window parenting"); - } - if(caps.isOnscreen()) { - throw new NativeWindowException("Capabilities is onscreen"); - } - AbstractGraphicsScreen aScreen = screen.getGraphicsScreen(); - config = GraphicsConfigurationFactory.getFactory(aScreen.getDevice()).chooseGraphicsConfiguration(caps, null, aScreen); - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - - synchronized(OffscreenWindow.class) { - windowHandle = nextWindowHandle++; - } - } - - protected void closeNative() { - // nop - } - - public void invalidate() { - super.invalidate(); - surfaceHandle = 0; - } - - public synchronized void destroy() { - surfaceHandle = 0; - } - - public void setSurfaceHandle(long handle) { - surfaceHandle = handle ; - } - - public long getSurfaceHandle() { - return surfaceHandle; - } - - public void setVisible(boolean visible) { - if(!visible) { - this.visible = visible; - } - } - - public void setSize(int width, int height) { - if(!visible) { - this.width = width; - this.height = height; - } - } - - public void setPosition(int x, int y) { - // nop - } - - public boolean setFullscreen(boolean fullscreen) { - // nop - return false; - } -} - diff --git a/src/newt/classes/com/jogamp/javafx/newt/PaintEvent.java b/src/newt/classes/com/jogamp/javafx/newt/PaintEvent.java deleted file mode 100755 index 8543246a7..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/PaintEvent.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2009 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt; - -/** - * - * @author tdv - */ -public class PaintEvent extends Event { - - // bounds of the damage region - private int x, y, width, height; - public PaintEvent(int eventType, Window source, - long when, int x, int y, int w, int h) - { - super(true, eventType, source, when); - this.x = x; - this.y = y; - this.width = w; - this.height = h; - } - - public int getHeight() { - return height; - } - - public int getWidth() { - return width; - } - - public int getX() { - return x; - } - - public int getY() { - return y; - } - - public String toString() { - return "ExposeEvent[modifiers: x="+x+" y="+y+" w="+width+" h="+height +"]"; - } - -} diff --git a/src/newt/classes/com/jogamp/javafx/newt/PaintListener.java b/src/newt/classes/com/jogamp/javafx/newt/PaintListener.java deleted file mode 100755 index adfd78f18..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/PaintListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2009 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt; - -/** - * - * @author tdv - */ -public interface PaintListener { - public void exposed(PaintEvent e); -} diff --git a/src/newt/classes/com/jogamp/javafx/newt/Screen.java b/src/newt/classes/com/jogamp/javafx/newt/Screen.java deleted file mode 100755 index b02a7ef00..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/Screen.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt; - -import com.jogamp.javafx.newt.impl.*; - -import javax.media.nativewindow.*; -import java.security.*; - -public abstract class Screen { - - private static Class getScreenClass(String type) - throws ClassNotFoundException - { - Class screenClass = NewtFactory.getCustomClass(type, "Screen"); - if(null==screenClass) { - if (NativeWindowFactory.TYPE_EGL.equals(type)) { - screenClass = Class.forName("com.jogamp.javafx.newt.opengl.kd.KDScreen"); - } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) { - screenClass = Class.forName("com.jogamp.javafx.newt.windows.WindowsScreen"); - } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { - screenClass = Class.forName("com.jogamp.javafx.newt.macosx.MacScreen"); - } else if (NativeWindowFactory.TYPE_X11.equals(type)) { - screenClass = Class.forName("com.jogamp.javafx.newt.x11.X11Screen"); - } else if (NativeWindowFactory.TYPE_AWT.equals(type)) { - screenClass = Class.forName("com.jogamp.javafx.newt.awt.AWTScreen"); - } else { - throw new RuntimeException("Unknown window type \"" + type + "\""); - } - } - return screenClass; - } - - protected static Screen create(String type, Display display, int idx) { - try { - if(usrWidth<0 || usrHeight<0) { - usrWidth = Debug.getIntProperty("newt.ws.swidth", true, localACC); - usrHeight = Debug.getIntProperty("newt.ws.sheight", true, localACC); - System.out.println("User screen size "+usrWidth+"x"+usrHeight); - } - Class screenClass = getScreenClass(type); - Screen screen = (Screen) screenClass.newInstance(); - screen.display = display; - screen.createNative(idx); - if(null==screen.aScreen) { - throw new RuntimeException("Screen.createNative() failed to instanciate an AbstractGraphicsScreen"); - } - return screen; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public synchronized void destroy() { - closeNative(); - display = null; - aScreen = null; - } - - protected static Screen wrapHandle(String type, Display display, AbstractGraphicsScreen aScreen) { - try { - Class screenClass = getScreenClass(type); - Screen screen = (Screen) screenClass.newInstance(); - screen.display = display; - screen.aScreen = aScreen; - return screen; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - protected abstract void createNative(int index); - protected abstract void closeNative(); - - protected void setScreenSize(int w, int h) { - System.out.println("Detected screen size "+w+"x"+h); - width=w; height=h; - } - - public Display getDisplay() { - return display; - } - - public int getIndex() { - return aScreen.getIndex(); - } - - public AbstractGraphicsScreen getGraphicsScreen() { - return aScreen; - } - - /** - * The actual implementation shall return the detected display value, - * if not we return 800. - * This can be overwritten with the user property 'newt.ws.swidth', - */ - public int getWidth() { - return (usrWidth>0) ? usrWidth : (width>0) ? width : 480; - } - - /** - * The actual implementation shall return the detected display value, - * if not we return 480. - * This can be overwritten with the user property 'newt.ws.sheight', - */ - public int getHeight() { - return (usrHeight>0) ? usrHeight : (height>0) ? height : 480; - } - - protected Display display; - protected AbstractGraphicsScreen aScreen; - protected int width=-1, height=-1; // detected values: set using setScreenSize - protected static int usrWidth=-1, usrHeight=-1; // property values: newt.ws.swidth and newt.ws.sheight - private static AccessControlContext localACC = AccessController.getContext(); -} - diff --git a/src/newt/classes/com/jogamp/javafx/newt/Window.java b/src/newt/classes/com/jogamp/javafx/newt/Window.java deleted file mode 100755 index 2d9341e13..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/Window.java +++ /dev/null @@ -1,929 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt; - -import com.jogamp.javafx.newt.impl.Debug; -import com.jogamp.javafx.newt.util.EventDispatchThread; - -import javax.media.nativewindow.*; -import com.jogamp.nativewindow.impl.NWReflection; - -import java.util.ArrayList; -import java.util.Iterator; -import java.lang.reflect.Method; - -public abstract class Window implements NativeWindow -{ - public static final boolean DEBUG_MOUSE_EVENT = Debug.debug("Window.MouseEvent"); - public static final boolean DEBUG_KEY_EVENT = Debug.debug("Window.KeyEvent"); - public static final boolean DEBUG_WINDOW_EVENT = Debug.debug("Window.WindowEvent"); - public static final boolean DEBUG_IMPLEMENTATION = Debug.debug("Window"); - - // Workaround for initialization order problems on Mac OS X - // between native Newt and (apparently) Fmod -- if Fmod is - // initialized first then the connection to the window server - // breaks, leading to errors from deep within the AppKit - static void init(String type) { - if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { - try { - getWindowClass(type); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - private static Class getWindowClass(String type) - throws ClassNotFoundException - { - Class windowClass = NewtFactory.getCustomClass(type, "Window"); - if(null==windowClass) { - if (NativeWindowFactory.TYPE_EGL.equals(type)) { - windowClass = Class.forName("com.jogamp.javafx.newt.opengl.kd.KDWindow"); - } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) { - windowClass = Class.forName("com.jogamp.javafx.newt.windows.WindowsWindow"); - } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { - windowClass = Class.forName("com.jogamp.javafx.newt.macosx.MacWindow"); - } else if (NativeWindowFactory.TYPE_X11.equals(type)) { - windowClass = Class.forName("com.jogamp.javafx.newt.x11.X11Window"); - } else if (NativeWindowFactory.TYPE_AWT.equals(type)) { - windowClass = Class.forName("com.jogamp.javafx.newt.awt.AWTWindow"); - } else { - throw new NativeWindowException("Unknown window type \"" + type + "\""); - } - } - return windowClass; - } - - protected static Window create(String type, final long parentWindowHandle, Screen screen, final Capabilities caps, boolean undecorated) { - try { - Class windowClass; - if(caps.isOnscreen()) { - windowClass = getWindowClass(type); - } else { - windowClass = OffscreenWindow.class; - } - Window window = (Window) windowClass.newInstance(); - window.invalidate(); - window.screen = screen; - window.setUndecorated(undecorated||0!=parentWindowHandle); - EventDispatchThread edt = screen.getDisplay().getEDT(); - if(null!=edt) { - final Window f_win = window; - edt.invokeAndWait(new Runnable() { - public void run() { - f_win.createNative(parentWindowHandle, caps); - } - } ); - } else { - window.createNative(parentWindowHandle, caps); - } - return window; - } catch (Throwable t) { - t.printStackTrace(); - throw new NativeWindowException(t); - } - } - - protected static Window create(String type, Object[] cstrArguments, Screen screen, final Capabilities caps, boolean undecorated) { - try { - Class windowClass = getWindowClass(type); - Class[] cstrArgumentTypes = getCustomConstructorArgumentTypes(windowClass); - if(null==cstrArgumentTypes) { - throw new NativeWindowException("WindowClass "+windowClass+" doesn't support custom arguments in constructor"); - } - int argsChecked = verifyConstructorArgumentTypes(cstrArgumentTypes, cstrArguments); - if ( argsChecked < cstrArguments.length ) { - throw new NativeWindowException("WindowClass "+windowClass+" constructor mismatch at argument #"+argsChecked+"; Constructor: "+getTypeStrList(cstrArgumentTypes)+", arguments: "+getArgsStrList(cstrArguments)); - } - Window window = (Window) NWReflection.createInstance( windowClass, cstrArgumentTypes, cstrArguments ) ; - window.invalidate(); - window.screen = screen; - window.setUndecorated(undecorated); - EventDispatchThread edt = screen.getDisplay().getEDT(); - if(null!=edt) { - final Window f_win = window; - edt.invokeAndWait(new Runnable() { - public void run() { - f_win.createNative(0, caps); - } - } ); - } else { - window.createNative(0, caps); - } - return window; - } catch (Throwable t) { - t.printStackTrace(); - throw new NativeWindowException(t); - } - } - - protected static Window wrapHandle(String type, Screen screen, AbstractGraphicsConfiguration config, - long windowHandle, boolean fullscreen, boolean visible, - int x, int y, int width, int height) - { - try { - Class windowClass = getWindowClass(type); - Window window = (Window) windowClass.newInstance(); - window.invalidate(); - window.screen = screen; - window.config = config; - window.windowHandle = windowHandle; - window.fullscreen=fullscreen; - window.visible=visible; - window.x=x; - window.y=y; - window.width=width; - window.height=height; - return window; - } catch (Throwable t) { - t.printStackTrace(); - throw new NativeWindowException(t); - } - } - - public static String toHexString(int hex) { - return "0x" + Integer.toHexString(hex); - } - - public static String toHexString(long hex) { - return "0x" + Long.toHexString(hex); - } - - protected Screen screen; - - protected AbstractGraphicsConfiguration config; - protected long windowHandle; - protected boolean fullscreen, visible; - protected int width, height, x, y; - protected int eventMask; - - protected String title = "Newt Window"; - protected boolean undecorated = false; - - /** - * Create native windowHandle, ie creates a new native invisible window. - * - * The parentWindowHandle may be null, in which case no window parenting - * is requested. - * - * Shall use the capabilities to determine the graphics configuration - * and shall set the chosen capabilities. - */ - protected abstract void createNative(long parentWindowHandle, Capabilities caps); - - protected abstract void closeNative(); - - public Screen getScreen() { - return screen; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - - sb.append(getClass().getName()+"[config "+config+ - ", windowHandle "+toHexString(getWindowHandle())+ - ", surfaceHandle "+toHexString(getSurfaceHandle())+ - ", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+ - ", visible "+isVisible()+ - ", undecorated "+undecorated+ - ", fullscreen "+fullscreen+ - ", "+screen+ - ", wrappedWindow "+getWrappedWindow()); - - sb.append(", SurfaceUpdatedListeners num "+surfaceUpdatedListeners.size()+" ["); - for (Iterator iter = surfaceUpdatedListeners.iterator(); iter.hasNext(); ) { - sb.append(iter.next()+", "); - } - sb.append("], WindowListeners num "+windowListeners.size()+" ["); - for (Iterator iter = windowListeners.iterator(); iter.hasNext(); ) { - sb.append(iter.next()+", "); - } - sb.append("], MouseListeners num "+mouseListeners.size()+" ["); - for (Iterator iter = mouseListeners.iterator(); iter.hasNext(); ) { - sb.append(iter.next()+", "); - } - sb.append("], KeyListeners num "+keyListeners.size()+" ["); - for (Iterator iter = keyListeners.iterator(); iter.hasNext(); ) { - sb.append(iter.next()+", "); - } - sb.append("] ]"); - return sb.toString(); - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public void setUndecorated(boolean value) { - undecorated = value; - } - - public boolean isUndecorated() { - return undecorated; - } - - public void requestFocus() { - } - - // - // NativeWindow impl - // - private Thread owner; - private int recursionCount; - protected Exception lockedStack = null; - - /** Recursive and blocking lockSurface() implementation */ - public synchronized int lockSurface() { - // We leave the ToolkitLock lock to the specializtion's discretion, - // ie the implicit JAWTWindow in case of AWTWindow - Thread cur = Thread.currentThread(); - if (owner == cur) { - ++recursionCount; - return LOCK_SUCCESS; - } - while (owner != null) { - try { - wait(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - owner = cur; - lockedStack = new Exception("NEWT Surface previously locked by "+Thread.currentThread()); - screen.getDisplay().lockDisplay(); - return LOCK_SUCCESS; - } - - /** Recursive and unblocking unlockSurface() implementation */ - public synchronized void unlockSurface() throws NativeWindowException { - Thread cur = Thread.currentThread(); - if (owner != cur) { - lockedStack.printStackTrace(); - throw new NativeWindowException(cur+": Not owner, owner is "+owner); - } - if (recursionCount > 0) { - --recursionCount; - return; - } - owner = null; - lockedStack = null; - screen.getDisplay().unlockDisplay(); - notifyAll(); - // We leave the ToolkitLock unlock to the specializtion's discretion, - // ie the implicit JAWTWindow in case of AWTWindow - } - - public synchronized boolean isSurfaceLocked() { - return null!=owner; - } - - public synchronized Thread getSurfaceLockOwner() { - return owner; - } - - public synchronized Exception getLockedStack() { - return lockedStack; - } - - public synchronized void destroy() { - destroy(false); - } - - /** @param deep If true, the linked Screen and Display will be destroyed as well. */ - public synchronized void destroy(boolean deep) { - if(DEBUG_WINDOW_EVENT) { - System.out.println("Window.destroy() start (deep "+deep+" - "+Thread.currentThread()); - } - synchronized(surfaceUpdatedListeners) { - surfaceUpdatedListeners = new ArrayList(); - } - synchronized(windowListeners) { - windowListeners = new ArrayList(); - } - synchronized(mouseListeners) { - mouseListeners = new ArrayList(); - } - synchronized(keyListeners) { - keyListeners = new ArrayList(); - } - Screen scr = screen; - Display dpy = (null!=screen) ? screen.getDisplay() : null; - EventDispatchThread edt = (null!=dpy) ? dpy.getEDT() : null; - if(null!=edt) { - final Window f_win = this; - edt.invokeAndWait(new Runnable() { - public void run() { - f_win.closeNative(); - } - } ); - } else { - closeNative(); - } - invalidate(); - if(deep) { - if(null!=scr) { - scr.destroy(); - } - if(null!=dpy) { - dpy.destroy(); - } - } - if(DEBUG_WINDOW_EVENT) { - System.out.println("Window.destroy() end "+Thread.currentThread()); - } - } - - public void invalidate() { - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - Exception e = new Exception("!!! Window Invalidate "+Thread.currentThread()); - e.printStackTrace(); - } - screen = null; - windowHandle = 0; - fullscreen=false; - visible=false; - eventMask = 0; - - // Default position and dimension will be re-set immediately by user - width = 100; - height = 100; - x=0; - y=0; - } - - public boolean surfaceSwap() { - return false; - } - - protected void clearEventMask() { - eventMask=0; - } - - public long getDisplayHandle() { - return screen.getDisplay().getHandle(); - } - - public int getScreenIndex() { - return screen.getIndex(); - } - - public long getWindowHandle() { - return windowHandle; - } - - public long getSurfaceHandle() { - return windowHandle; // default: return window handle - } - - public AbstractGraphicsConfiguration getGraphicsConfiguration() { - return config; - } - - /** - * Returns the width of the client area of this window - * @return width of the client area - */ - public int getWidth() { - return width; - } - - /** - * Returns the height of the client area of this window - * @return height of the client area - */ - public int getHeight() { - return height; - } - - /** - * Returns the insets for this native window (the difference between the - * size of the toplevel window with the decorations and the client area). - * - * @return insets for this platform window - */ - // this probably belongs to NativeWindow interface - public Insets getInsets() { - return new Insets(0,0,0,0); - } - - /** If this Window actually wraps one from another toolkit such as - the AWT, this will return a non-null value. */ - public Object getWrappedWindow() { - return null; - } - - // - // Additional methods - // - - public int getX() { - return x; - } - - public int getY() { - return y; - } - - public boolean isVisible() { - return visible; - } - - public boolean isFullscreen() { - return fullscreen; - } - - private boolean autoDrawableMember = false; - - /** If the implementation is capable of detecting a device change - return true and clear the status/reason of the change. */ - public boolean hasDeviceChanged() { - return false; - } - - /** - * If set to true, - * certain action will be performed by the owning - * AutoDrawable, ie the destroy() call within windowDestroyNotify() - */ - public void setAutoDrawableClient(boolean b) { - autoDrawableMember = b; - } - - protected void windowDestroyNotify() { - if(DEBUG_WINDOW_EVENT) { - System.out.println("Window.windowDestroyeNotify start "+Thread.currentThread()); - } - - sendWindowEvent(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY); - - if(!autoDrawableMember) { - destroy(); - } - - if(DEBUG_WINDOW_EVENT) { - System.out.println("Window.windowDestroyeNotify end "+Thread.currentThread()); - } - } - - protected void windowDestroyed() { - if(DEBUG_WINDOW_EVENT) { - System.out.println("Window.windowDestroyed "+Thread.currentThread()); - } - invalidate(); - } - - public abstract void setVisible(boolean visible); - /** - * Sets the size of the client area of the window, excluding decorations - * Total size of the window will be - * {@code width+insets.left+insets.right, height+insets.top+insets.bottom} - * @param width of the client area of the window - * @param height of the client area of the window - */ - public abstract void setSize(int width, int height); - /** - * Sets the location of the top left corner of the window, including - * decorations (so the client area will be placed at - * {@code x+insets.left,y+insets.top}. - * @param x coord of the top left corner - * @param y coord of the top left corner - */ - public abstract void setPosition(int x, int y); - public abstract boolean setFullscreen(boolean fullscreen); - - // - // SurfaceUpdatedListener Support - // - private ArrayList surfaceUpdatedListeners = new ArrayList(); - - public void addSurfaceUpdatedListener(SurfaceUpdatedListener l) { - if(l == null) { - return; - } - synchronized(surfaceUpdatedListeners) { - ArrayList newSurfaceUpdatedListeners = (ArrayList) surfaceUpdatedListeners.clone(); - newSurfaceUpdatedListeners.add(l); - surfaceUpdatedListeners = newSurfaceUpdatedListeners; - } - } - - public void removeSurfaceUpdatedListener(SurfaceUpdatedListener l) { - if (l == null) { - return; - } - synchronized(surfaceUpdatedListeners) { - ArrayList newSurfaceUpdatedListeners = (ArrayList) surfaceUpdatedListeners.clone(); - newSurfaceUpdatedListeners.remove(l); - surfaceUpdatedListeners = newSurfaceUpdatedListeners; - } - } - - public SurfaceUpdatedListener[] getSurfaceUpdatedListener() { - synchronized(surfaceUpdatedListeners) { - return (SurfaceUpdatedListener[]) surfaceUpdatedListeners.toArray(); - } - } - - public void surfaceUpdated(Object updater, NativeWindow window, long when) { - ArrayList listeners = null; - synchronized(surfaceUpdatedListeners) { - listeners = surfaceUpdatedListeners; - } - for(Iterator i = listeners.iterator(); i.hasNext(); ) { - SurfaceUpdatedListener l = (SurfaceUpdatedListener) i.next(); - l.surfaceUpdated(updater, window, when); - } - } - - // - // MouseListener Support - // - - public void addMouseListener(MouseListener l) { - if(l == null) { - return; - } - synchronized(mouseListeners) { - ArrayList newMouseListeners = (ArrayList) mouseListeners.clone(); - newMouseListeners.add(l); - mouseListeners = newMouseListeners; - } - } - - public void removeMouseListener(MouseListener l) { - if (l == null) { - return; - } - synchronized(mouseListeners) { - ArrayList newMouseListeners = (ArrayList) mouseListeners.clone(); - newMouseListeners.remove(l); - mouseListeners = newMouseListeners; - } - } - - public MouseListener[] getMouseListeners() { - synchronized(mouseListeners) { - return (MouseListener[]) mouseListeners.toArray(); - } - } - - private ArrayList mouseListeners = new ArrayList(); - private int mouseButtonPressed = 0; // current pressed mouse button number - private long lastMousePressed = 0; // last time when a mouse button was pressed - private int lastMouseClickCount = 0; // last mouse button click count - public static final int ClickTimeout = 300; - - protected void sendMouseEvent(int eventType, int modifiers, - int x, int y, int button, int rotation) { - if(x<0||y<0||x>=width||y>=height) { - return; // .. invalid .. - } - if(DEBUG_MOUSE_EVENT) { - System.out.println("sendMouseEvent: "+MouseEvent.getEventTypeString(eventType)+ - ", mod "+modifiers+", pos "+x+"/"+y+", button "+button); - } - if(button<0||button>MouseEvent.BUTTON_NUMBER) { - throw new NativeWindowException("Invalid mouse button number" + button); - } - long when = System.currentTimeMillis(); - MouseEvent eClicked = null; - MouseEvent e = null; - - if(MouseEvent.EVENT_MOUSE_PRESSED==eventType) { - if(when-lastMousePressed0) { - e = new MouseEvent(true, MouseEvent.EVENT_MOUSE_DRAGGED, this, when, - modifiers, x, y, 1, mouseButtonPressed, 0); - } else { - e = new MouseEvent(true, eventType, this, when, - modifiers, x, y, 0, button, 0); - } - } else if(MouseEvent.EVENT_MOUSE_WHEEL_MOVED==eventType) { - e = new MouseEvent(true, eventType, this, when, modifiers, x, y, 0, button, rotation); - } else { - e = new MouseEvent(true, eventType, this, when, modifiers, x, y, 0, button, 0); - } - - if(DEBUG_MOUSE_EVENT) { - System.out.println("sendMouseEvent: event: "+e); - if(null!=eClicked) { - System.out.println("sendMouseEvent: event Clicked: "+eClicked); - } - } - - ArrayList listeners = null; - synchronized(mouseListeners) { - listeners = mouseListeners; - } - for(Iterator i = listeners.iterator(); i.hasNext(); ) { - MouseListener l = (MouseListener) i.next(); - switch(e.getEventType()) { - case MouseEvent.EVENT_MOUSE_CLICKED: - l.mouseClicked(e); - break; - case MouseEvent.EVENT_MOUSE_ENTERED: - l.mouseEntered(e); - break; - case MouseEvent.EVENT_MOUSE_EXITED: - l.mouseExited(e); - break; - case MouseEvent.EVENT_MOUSE_PRESSED: - l.mousePressed(e); - break; - case MouseEvent.EVENT_MOUSE_RELEASED: - l.mouseReleased(e); - if(null!=eClicked) { - l.mouseClicked(eClicked); - } - break; - case MouseEvent.EVENT_MOUSE_MOVED: - l.mouseMoved(e); - break; - case MouseEvent.EVENT_MOUSE_DRAGGED: - l.mouseDragged(e); - break; - case MouseEvent.EVENT_MOUSE_WHEEL_MOVED: - l.mouseWheelMoved(e); - break; - default: - throw new NativeWindowException("Unexpected mouse event type " + e.getEventType()); - } - } - } - - // - // KeyListener Support - // - - public void addKeyListener(KeyListener l) { - if(l == null) { - return; - } - synchronized(keyListeners) { - ArrayList newKeyListeners = (ArrayList) keyListeners.clone(); - newKeyListeners.add(l); - keyListeners = newKeyListeners; - } - } - - public void removeKeyListener(KeyListener l) { - if (l == null) { - return; - } - synchronized(keyListeners) { - ArrayList newKeyListeners = (ArrayList) keyListeners.clone(); - newKeyListeners.remove(l); - keyListeners = newKeyListeners; - } - } - - public KeyListener[] getKeyListeners() { - synchronized(keyListeners) { - return (KeyListener[]) keyListeners.toArray(); - } - } - - private ArrayList keyListeners = new ArrayList(); - - protected void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { - KeyEvent e = new KeyEvent(true, eventType, this, System.currentTimeMillis(), - modifiers, keyCode, keyChar); - if(DEBUG_KEY_EVENT) { - System.out.println("sendKeyEvent: "+e); - } - ArrayList listeners = null; - synchronized(keyListeners) { - listeners = keyListeners; - } - for(Iterator i = listeners.iterator(); i.hasNext(); ) { - KeyListener l = (KeyListener) i.next(); - switch(eventType) { - case KeyEvent.EVENT_KEY_PRESSED: - l.keyPressed(e); - break; - case KeyEvent.EVENT_KEY_RELEASED: - l.keyReleased(e); - break; - case KeyEvent.EVENT_KEY_TYPED: - l.keyTyped(e); - break; - default: - throw new NativeWindowException("Unexpected key event type " + e.getEventType()); - } - } - } - - // - // WindowListener Support - // - - private ArrayList windowListeners = new ArrayList(); - - public void addWindowListener(WindowListener l) { - if(l == null) { - return; - } - synchronized(windowListeners) { - ArrayList newWindowListeners = (ArrayList) windowListeners.clone(); - newWindowListeners.add(l); - windowListeners = newWindowListeners; - } - } - - public void removeWindowListener(WindowListener l) { - if (l == null) { - return; - } - synchronized(windowListeners) { - ArrayList newWindowListeners = (ArrayList) windowListeners.clone(); - newWindowListeners.remove(l); - windowListeners = newWindowListeners; - } - } - - public WindowListener[] getWindowListeners() { - synchronized(windowListeners) { - return (WindowListener[]) windowListeners.toArray(); - } - } - - protected void sendWindowEvent(int eventType) { - WindowEvent e = new WindowEvent(true, eventType, this, System.currentTimeMillis()); - if(DEBUG_WINDOW_EVENT) { - System.out.println("sendWindowEvent: "+e); - } - ArrayList listeners = null; - synchronized(windowListeners) { - listeners = windowListeners; - } - for(Iterator i = listeners.iterator(); i.hasNext(); ) { - WindowListener l = (WindowListener) i.next(); - switch(eventType) { - case WindowEvent.EVENT_WINDOW_RESIZED: - l.windowResized(e); - break; - case WindowEvent.EVENT_WINDOW_MOVED: - l.windowMoved(e); - break; - case WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY: - l.windowDestroyNotify(e); - break; - case WindowEvent.EVENT_WINDOW_GAINED_FOCUS: - l.windowGainedFocus(e); - break; - case WindowEvent.EVENT_WINDOW_LOST_FOCUS: - l.windowLostFocus(e); - break; - default: - throw - new NativeWindowException("Unexpected window event type " - + e.getEventType()); - } - } - } - - - // - // WindowListener Support - // - - private ArrayList paintListeners = new ArrayList(); - - public void addPaintListener(PaintListener l) { - if(l == null) { - return; - } - synchronized(paintListeners) { - ArrayList newPaintListeners = (ArrayList) paintListeners.clone(); - newPaintListeners.add(l); - paintListeners = newPaintListeners; - } - } - - public void removePaintListener(PaintListener l) { - if (l == null) { - return; - } - synchronized(paintListeners) { - ArrayList newPaintListeners = (ArrayList) paintListeners.clone(); - newPaintListeners.remove(l); - paintListeners = newPaintListeners; - } - } - - protected void sendPaintEvent(int eventType, int x, int y, int w, int h) { - PaintEvent e = - new PaintEvent(eventType, this, System.currentTimeMillis(), x, y, w, h); - ArrayList listeners = null; - synchronized(paintListeners) { - listeners = paintListeners; - } - for(Iterator i = listeners.iterator(); i.hasNext(); ) { - PaintListener l = (PaintListener) i.next(); - l.exposed(e); - } - } - - // - // Reflection helper .. - // - - private static Class[] getCustomConstructorArgumentTypes(Class windowClass) { - Class[] argTypes = null; - try { - Method m = windowClass.getDeclaredMethod("getCustomConstructorArgumentTypes", new Class[] {}); - argTypes = (Class[]) m.invoke(null, null); - } catch (Throwable t) {} - return argTypes; - } - - private static int verifyConstructorArgumentTypes(Class[] types, Object[] args) { - if(types.length != args.length) { - return -1; - } - for(int i=0; i*/ events = new LinkedList(); - - static class AWTEventWrapper { - AWTWindow window; - int type; - InputEvent e; - - AWTEventWrapper(AWTWindow w, int type, InputEvent e) { - this.window = w; - this.type = type; - this.e = e; - } - - public AWTWindow getWindow() { - return window; - } - - public int getType() { - return type; - } - - public InputEvent getEvent() { - return e; - } - } - - private static int convertModifiers(InputEvent e) { - int newtMods = 0; - int mods = e.getModifiers(); - if ((mods & InputEvent.SHIFT_MASK) != 0) newtMods |= com.jogamp.javafx.newt.InputEvent.SHIFT_MASK; - if ((mods & InputEvent.CTRL_MASK) != 0) newtMods |= com.jogamp.javafx.newt.InputEvent.CTRL_MASK; - if ((mods & InputEvent.META_MASK) != 0) newtMods |= com.jogamp.javafx.newt.InputEvent.META_MASK; - if ((mods & InputEvent.ALT_MASK) != 0) newtMods |= com.jogamp.javafx.newt.InputEvent.ALT_MASK; - if ((mods & InputEvent.ALT_GRAPH_MASK) != 0) newtMods |= com.jogamp.javafx.newt.InputEvent.ALT_GRAPH_MASK; - return newtMods; - } - - private static int convertButton(MouseEvent e) { - switch (e.getButton()) { - case MouseEvent.BUTTON1: return com.jogamp.javafx.newt.MouseEvent.BUTTON1; - case MouseEvent.BUTTON2: return com.jogamp.javafx.newt.MouseEvent.BUTTON2; - case MouseEvent.BUTTON3: return com.jogamp.javafx.newt.MouseEvent.BUTTON3; - } - return 0; - } - -} diff --git a/src/newt/classes/com/jogamp/javafx/newt/awt/AWTScreen.java b/src/newt/classes/com/jogamp/javafx/newt/awt/AWTScreen.java deleted file mode 100644 index 00da66078..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/awt/AWTScreen.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.awt; - -import com.jogamp.javafx.newt.*; -import java.awt.DisplayMode; -import javax.media.nativewindow.*; -import javax.media.nativewindow.awt.*; - -public class AWTScreen extends Screen { - public AWTScreen() { - } - - protected void createNative(int index) { - aScreen = new AWTGraphicsScreen((AWTGraphicsDevice)display.getGraphicsDevice()); - - DisplayMode mode = ((AWTGraphicsDevice)getDisplay().getGraphicsDevice()).getGraphicsDevice().getDisplayMode(); - int w = mode.getWidth(); - int h = mode.getHeight(); - setScreenSize(w, h); - } - - protected void setAWTGraphicsScreen(AWTGraphicsScreen s) { - aScreen = s; - } - - // done by AWTWindow .. - protected void setScreenSize(int w, int h) { - super.setScreenSize(w, h); - } - - protected void closeNative() { } - -} diff --git a/src/newt/classes/com/jogamp/javafx/newt/awt/AWTWindow.java b/src/newt/classes/com/jogamp/javafx/newt/awt/AWTWindow.java deleted file mode 100644 index a0c2b6a89..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/awt/AWTWindow.java +++ /dev/null @@ -1,429 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.awt; - -import java.awt.BorderLayout; -import java.awt.Canvas; -import java.awt.Container; -import java.awt.DisplayMode; -import java.awt.EventQueue; -import java.awt.Frame; -import java.awt.GraphicsDevice; -import java.awt.GraphicsEnvironment; -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; -import java.awt.event.*; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.*; -import com.jogamp.javafx.newt.Window; -import java.awt.Insets; -import javax.media.nativewindow.*; -import javax.media.nativewindow.awt.*; - -/** An implementation of the Newt Window class built using the - AWT. This is provided for convenience of porting to platforms - supporting Java SE. */ - -public class AWTWindow extends Window { - - public AWTWindow() { - this(null); - } - - public static Class[] getCustomConstructorArgumentTypes() { - return new Class[] { Container.class } ; - } - - public AWTWindow(Container container) { - super(); - title = "AWT NewtWindow"; - this.container = container; - if(container instanceof Frame) { - frame = (Frame) container; - } - } - - private boolean owningFrame; - private Container container = null; - private Frame frame = null; // same instance as container, just for impl. convenience - private AWTCanvas canvas; - // non fullscreen dimensions .. - private int nfs_width, nfs_height, nfs_x, nfs_y; - - public void setTitle(final String title) { - super.setTitle(title); - runOnEDT(true, new Runnable() { - public void run() { - if (frame != null) { - frame.setTitle(title); - } - } - }); - } - - protected void createNative(long parentWindowHandle, final Capabilities caps) { - - if(0!=parentWindowHandle) { - throw new RuntimeException("Window parenting not supported in AWT, use AWTWindow(Frame) cstr for wrapping instead"); - } - - final AWTWindow awtWindow = this; - - 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(caps); - Listener listener = new Listener(awtWindow); - canvas.addMouseListener(listener); - canvas.addMouseMotionListener(listener); - canvas.addKeyListener(listener); - canvas.addComponentListener(listener); - container.add(canvas, BorderLayout.CENTER); - container.setSize(width, height); - container.setLocation(x, y); - container.addComponentListener(new MoveListener(awtWindow)); - if(null!=frame) { - frame.setUndecorated(undecorated||fullscreen); - frame.addWindowListener(new WindowEventListener(awtWindow)); - } - } - }); - } - - protected void closeNative() { - runOnEDT(true, new Runnable() { - public void run() { - if(owningFrame && null!=frame) { - frame.dispose(); - owningFrame=false; - } - frame = null; - } - }); - } - - public boolean hasDeviceChanged() { - boolean res = canvas.hasDeviceChanged(); - if(res) { - config = canvas.getAWTGraphicsConfiguration(); - if (config == null) { - throw new NativeWindowException("Error Device change null GraphicsConfiguration: "+this); - } - updateDeviceData(); - } - return res; - } - - public void setVisible(final boolean visible) { - runOnEDT(true, new Runnable() { - public void run() { - container.setVisible(visible); - } - }); - - config = canvas.getAWTGraphicsConfiguration(); - - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - - updateDeviceData(); - } - - private void updateDeviceData() { - // propagate new info .. - ((AWTScreen)getScreen()).setAWTGraphicsScreen((AWTGraphicsScreen)config.getScreen()); - ((AWTDisplay)getScreen().getDisplay()).setAWTGraphicsDevice((AWTGraphicsDevice)config.getScreen().getDevice()); - - DisplayMode mode = ((AWTGraphicsDevice)config.getScreen().getDevice()).getGraphicsDevice().getDisplayMode(); - int w = mode.getWidth(); - int h = mode.getHeight(); - ((AWTScreen)screen).setScreenSize(w, h); - } - - public void setSize(final int width, final int height) { - this.width = width; - this.height = height; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - /** An AWT event on setSize() would bring us in a deadlock situation, hence invokeLater() */ - runOnEDT(false, new Runnable() { - public void run() { - Insets insets = container.getInsets(); - container.setSize(width + insets.left + insets.right, - height + insets.top + insets.bottom); - } - }); - } - - public com.jogamp.javafx.newt.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; - } - }); - return new com.jogamp.javafx.newt. - Insets(insets[0],insets[1],insets[2],insets[3]); - } - - public void setPosition(final int x, final int y) { - this.x = x; - this.y = y; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - runOnEDT(true, new Runnable() { - public void run() { - container.setLocation(x, y); - } - }); - } - - public boolean setFullscreen(final boolean fullscreen) { - if(this.fullscreen!=fullscreen) { - final int x,y,w,h; - this.fullscreen=fullscreen; - if(fullscreen) { - x = 0; y = 0; - w = screen.getWidth(); - h = screen.getHeight(); - } else { - x = nfs_x; - y = nfs_y; - w = nfs_width; - h = nfs_height; - } - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("AWTWindow fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); - } - /** An AWT event on setSize() would bring us in a deadlock situation, hence invokeLater() */ - runOnEDT(false, new Runnable() { - public void run() { - if(null!=frame) { - if(!container.isDisplayable()) { - frame.setUndecorated(undecorated||fullscreen); - } else { - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("AWTWindow can't undecorate already created frame"); - } - } - } - container.setLocation(x, y); - container.setSize(w, h); - } - }); - } - return true; - } - - public Object getWrappedWindow() { - return canvas; - } - - protected void sendWindowEvent(int eventType) { - super.sendWindowEvent(eventType); - } - - protected void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { - super.sendKeyEvent(eventType, modifiers, keyCode, keyChar); - } - - protected void sendMouseEvent(int eventType, int modifiers, - int x, int y, int button, int rotation) { - super.sendMouseEvent(eventType, modifiers, x, y, button, rotation); - } - - private static void runOnEDT(boolean wait, Runnable r) { - if (EventQueue.isDispatchThread()) { - r.run(); - } else { - try { - if(wait) { - EventQueue.invokeAndWait(r); - } else { - EventQueue.invokeLater(r); - } - } catch (Exception e) { - throw new NativeWindowException(e); - } - } - } - - private static final int WINDOW_EVENT = 1; - private static final int KEY_EVENT = 2; - private static final int MOUSE_EVENT = 3; - - class MoveListener implements ComponentListener { - private AWTWindow window; - private AWTDisplay display; - - public MoveListener(AWTWindow w) { - window = w; - display = (AWTDisplay)window.getScreen().getDisplay(); - } - - public void componentResized(ComponentEvent e) { - } - - public void componentMoved(ComponentEvent e) { - if(null!=container) { - x = container.getX(); - y = container.getY(); - } - display.enqueueEvent(window, com.jogamp.javafx.newt.WindowEvent.EVENT_WINDOW_MOVED, null); - } - - public void componentShown(ComponentEvent e) { - } - - public void componentHidden(ComponentEvent e) { - } - - } - - class Listener implements ComponentListener, MouseListener, MouseMotionListener, KeyListener { - private AWTWindow window; - private AWTDisplay display; - - public Listener(AWTWindow w) { - window = w; - display = (AWTDisplay)window.getScreen().getDisplay(); - } - - public void componentResized(ComponentEvent e) { - width = canvas.getWidth(); - height = canvas.getHeight(); - display.enqueueEvent(window, com.jogamp.javafx.newt.WindowEvent.EVENT_WINDOW_RESIZED, null); - } - - public void componentMoved(ComponentEvent e) { - } - - public void componentShown(ComponentEvent e) { - } - - public void componentHidden(ComponentEvent e) { - } - - public void mouseClicked(MouseEvent e) { - // We ignore these as we synthesize them ourselves out of - // mouse pressed and released events - } - - public void mouseEntered(MouseEvent e) { - display.enqueueEvent(window, com.jogamp.javafx.newt.MouseEvent.EVENT_MOUSE_ENTERED, e); - } - - public void mouseExited(MouseEvent e) { - display.enqueueEvent(window, com.jogamp.javafx.newt.MouseEvent.EVENT_MOUSE_EXITED, e); - } - - public void mousePressed(MouseEvent e) { - display.enqueueEvent(window, com.jogamp.javafx.newt.MouseEvent.EVENT_MOUSE_PRESSED, e); - } - - public void mouseReleased(MouseEvent e) { - display.enqueueEvent(window, com.jogamp.javafx.newt.MouseEvent.EVENT_MOUSE_RELEASED, e); - } - - public void mouseMoved(MouseEvent e) { - display.enqueueEvent(window, com.jogamp.javafx.newt.MouseEvent.EVENT_MOUSE_MOVED, e); - } - - public void mouseDragged(MouseEvent e) { - display.enqueueEvent(window, com.jogamp.javafx.newt.MouseEvent.EVENT_MOUSE_DRAGGED, e); - } - - public void keyPressed(KeyEvent e) { - display.enqueueEvent(window, com.jogamp.javafx.newt.KeyEvent.EVENT_KEY_PRESSED, e); - } - - public void keyReleased(KeyEvent e) { - display.enqueueEvent(window, com.jogamp.javafx.newt.KeyEvent.EVENT_KEY_RELEASED, e); - } - - public void keyTyped(KeyEvent e) { - display.enqueueEvent(window, com.jogamp.javafx.newt.KeyEvent.EVENT_KEY_TYPED, e); - } - } - - class WindowEventListener implements WindowListener { - private AWTWindow window; - private AWTDisplay display; - - public WindowEventListener(AWTWindow w) { - window = w; - display = (AWTDisplay)window.getScreen().getDisplay(); - } - - public void windowActivated(WindowEvent e) { - } - public void windowClosed(WindowEvent e) { - } - public void windowClosing(WindowEvent e) { - display.enqueueEvent(window, com.jogamp.javafx.newt.WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY, null); - } - public void windowDeactivated(WindowEvent e) { - } - public void windowDeiconified(WindowEvent e) { - } - public void windowIconified(WindowEvent e) { - } - public void windowOpened(WindowEvent e) { - } - } -} diff --git a/src/newt/classes/com/jogamp/javafx/newt/impl/Debug.java b/src/newt/classes/com/jogamp/javafx/newt/impl/Debug.java deleted file mode 100644 index bbabe72df..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/impl/Debug.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) 2003-2005 Sun Microsystems, Inc. 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. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.javafx.newt.impl; - -import java.security.*; - -/** Helper routines for logging and debugging. */ - -public class Debug { - // Some common properties - private static boolean verbose; - private static boolean debugAll; - private static AccessControlContext localACC; - - static { - localACC=AccessController.getContext(); - verbose = isPropertyDefined("newt.verbose", true); - debugAll = isPropertyDefined("newt.debug", true); - if (verbose) { - Package p = Package.getPackage("com.jogamp.javafx.newt"); - System.err.println("NEWT specification version " + p.getSpecificationVersion()); - System.err.println("NEWT implementation version " + p.getImplementationVersion()); - System.err.println("NEWT implementation vendor " + p.getImplementationVendor()); - } - } - - static int getIntProperty(final String property, final boolean jnlpAlias) { - return getIntProperty(property, jnlpAlias, localACC); - } - - public static int getIntProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { - int i=0; - try { - Integer iv = Integer.valueOf(Debug.getProperty(property, jnlpAlias, acc)); - i = iv.intValue(); - } catch (NumberFormatException nfe) {} - return i; - } - - static boolean getBooleanProperty(final String property, final boolean jnlpAlias) { - return getBooleanProperty(property, jnlpAlias, localACC); - } - - public static boolean getBooleanProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { - Boolean b = Boolean.valueOf(Debug.getProperty(property, jnlpAlias, acc)); - return b.booleanValue(); - } - - static boolean isPropertyDefined(final String property, final boolean jnlpAlias) { - return isPropertyDefined(property, jnlpAlias, localACC); - } - - public static boolean isPropertyDefined(final String property, final boolean jnlpAlias, final AccessControlContext acc) { - return (Debug.getProperty(property, jnlpAlias, acc) != null) ? true : false; - } - - static String getProperty(final String property, final boolean jnlpAlias) { - return getProperty(property, jnlpAlias, localACC); - } - - public static String getProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { - String s=null; - if(null!=acc && acc.equals(localACC)) { - s = (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - String val=null; - try { - val = System.getProperty(property); - } catch (Exception e) {} - if(null==val && jnlpAlias && !property.startsWith(jnlp_prefix)) { - try { - val = System.getProperty(jnlp_prefix + property); - } catch (Exception e) {} - } - return val; - } - }); - } else { - try { - s = System.getProperty(property); - } catch (Exception e) {} - if(null==s && jnlpAlias && !property.startsWith(jnlp_prefix)) { - try { - s = System.getProperty(jnlp_prefix + property); - } catch (Exception e) {} - } - } - return s; - } - public static final String jnlp_prefix = "jnlp." ; - - public static boolean verbose() { - return verbose; - } - - public static boolean debugAll() { - return debugAll; - } - - public static boolean debug(String subcomponent) { - return debugAll() || isPropertyDefined("newt.debug." + subcomponent, true); - } -} diff --git a/src/newt/classes/com/jogamp/javafx/newt/impl/NativeLibLoader.java b/src/newt/classes/com/jogamp/javafx/newt/impl/NativeLibLoader.java deleted file mode 100644 index 9bbfc5921..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/impl/NativeLibLoader.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. 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. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.javafx.newt.impl; - -// FIXME: refactor Java SE dependencies -//import java.awt.Toolkit; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.HashSet; -import com.jogamp.nativewindow.impl.NativeLibLoaderBase; - -public class NativeLibLoader extends NativeLibLoaderBase { - - public static void loadNEWT() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - loadLibrary("newt", null, true); - return null; - } - }); - } - -} diff --git a/src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Display.java b/src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Display.java deleted file mode 100644 index 3198c7511..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Display.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.intel.gdl; - -import com.jogamp.javafx.newt.impl.*; -import javax.media.nativewindow.*; - -public class Display extends com.jogamp.javafx.newt.Display { - static int initCounter = 0; - - static { - NativeLibLoader.loadNEWT(); - - if (!Screen.initIDs()) { - throw new NativeWindowException("Failed to initialize GDL Screen jmethodIDs"); - } - if (!Window.initIDs()) { - throw new NativeWindowException("Failed to initialize GDL Window jmethodIDs"); - } - } - - public static void initSingleton() { - // just exist to ensure static init has been run - } - - - public Display() { - } - - protected void createNative() { - synchronized(Display.class) { - if(0==initCounter) { - displayHandle = CreateDisplay(); - if(0==displayHandle) { - throw new NativeWindowException("Couldn't initialize GDL Display"); - } - } - initCounter++; - } - aDevice = new DefaultGraphicsDevice(NativeWindowFactory.TYPE_DEFAULT, displayHandle); - } - - protected void closeNative() { - if(0==displayHandle) { - throw new NativeWindowException("displayHandle null; initCnt "+initCounter); - } - synchronized(Display.class) { - if(initCounter>0) { - initCounter--; - if(0==initCounter) { - DestroyDisplay(displayHandle); - } - } - } - } - - protected void dispatchMessages() { - if(0!=displayHandle) { - DispatchMessages(displayHandle, focusedWindow); - } - } - - protected void setFocus(Window focus) { - focusedWindow = focus; - } - - private long displayHandle = 0; - private Window focusedWindow = null; - private native long CreateDisplay(); - private native void DestroyDisplay(long displayHandle); - private native void DispatchMessages(long displayHandle, Window focusedWindow); -} - diff --git a/src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Screen.java b/src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Screen.java deleted file mode 100644 index a09b1e790..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Screen.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.intel.gdl; - -import com.jogamp.javafx.newt.impl.*; -import javax.media.nativewindow.*; - -public class Screen extends com.jogamp.javafx.newt.Screen { - - static { - Display.initSingleton(); - } - - public Screen() { - } - - protected void createNative(int index) { - AbstractGraphicsDevice adevice = getDisplay().getGraphicsDevice(); - GetScreenInfo(adevice.getHandle(), index); - aScreen = new DefaultGraphicsScreen(adevice, index); - } - - protected void closeNative() { } - - //---------------------------------------------------------------------- - // Internals only - // - - protected static native boolean initIDs(); - private native void GetScreenInfo(long displayHandle, int screen_idx); - - // called by GetScreenInfo() .. - private void screenCreated(int width, int height) { - setScreenSize(width, height); - } -} - diff --git a/src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Window.java b/src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Window.java deleted file mode 100644 index 28ffa1296..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/intel/gdl/Window.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.intel.gdl; - -import javax.media.nativewindow.*; - -public class Window extends com.jogamp.javafx.newt.Window { - static { - Display.initSingleton(); - } - - public Window() { - } - - static long nextWindowHandle = 1; - - protected void createNative(long parentWindowHandle, Capabilities caps) { - if(0!=parentWindowHandle) { - throw new NativeWindowException("GDL Window does not support window parenting"); - } - AbstractGraphicsScreen aScreen = screen.getGraphicsScreen(); - AbstractGraphicsDevice aDevice = screen.getDisplay().getGraphicsDevice(); - - config = GraphicsConfigurationFactory.getFactory(aDevice).chooseGraphicsConfiguration(caps, null, aScreen); - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - - synchronized(Window.class) { - windowHandle = nextWindowHandle++; - } - } - - protected void closeNative() { - if(0!=surfaceHandle) { - synchronized(Window.class) { - CloseSurface(getDisplayHandle(), surfaceHandle); - } - surfaceHandle = 0; - ((Display)screen.getDisplay()).setFocus(null); - } - } - - public void setVisible(boolean visible) { - if(this.visible!=visible) { - this.visible=visible; - if(visible && 0==surfaceHandle) { - synchronized(Window.class) { - AbstractGraphicsDevice aDevice = screen.getDisplay().getGraphicsDevice(); - surfaceHandle = CreateSurface(aDevice.getHandle(), screen.getWidth(), screen.getHeight(), x, y, width, height); - } - if (surfaceHandle == 0) { - throw new NativeWindowException("Error creating window"); - } - ((Display)screen.getDisplay()).setFocus(this); - } - } - } - - public void setSize(int width, int height) { - Screen screen = (Screen) getScreen(); - if((x+width)>screen.getWidth()) { - width=screen.getWidth()-x; - } - if((y+height)>screen.getHeight()) { - height=screen.getHeight()-y; - } - this.width = width; - this.height = height; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - if(0!=surfaceHandle) { - SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, width, height); - } - } - - public void setPosition(int x, int y) { - Screen screen = (Screen) getScreen(); - if((x+width)>screen.getWidth()) { - x=screen.getWidth()-width; - } - if((y+height)>screen.getHeight()) { - y=screen.getHeight()-height; - } - this.x = x; - this.y = y; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - if(0!=surfaceHandle) { - SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, width, height); - } - } - - public boolean setFullscreen(boolean fullscreen) { - if(this.fullscreen!=fullscreen) { - int x,y,w,h; - this.fullscreen=fullscreen; - if(fullscreen) { - x = 0; y = 0; - w = screen.getWidth(); - h = screen.getHeight(); - } else { - x = nfs_x; - y = nfs_y; - w = nfs_width; - h = nfs_height; - } - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("IntelGDL Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); - } - if(0!=surfaceHandle) { - SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, w, h); - } - } - return fullscreen; - } - - public void requestFocus() { - ((Display)screen.getDisplay()).setFocus(this); - } - - public long getSurfaceHandle() { - return surfaceHandle; - } - - //---------------------------------------------------------------------- - // Internals only - // - - protected static native boolean initIDs(); - private native long CreateSurface(long displayHandle, int scrn_width, int scrn_height, int x, int y, int width, int height); - private native void CloseSurface(long displayHandle, long surfaceHandle); - private native void SetBounds0(long surfaceHandle, int scrn_width, int scrn_height, int x, int y, int width, int height); - - private void updateBounds(int x, int y, int width, int height) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - - private long surfaceHandle; - private int nfs_width, nfs_height, nfs_x, nfs_y; -} diff --git a/src/newt/classes/com/jogamp/javafx/newt/macosx/MacDisplay.java b/src/newt/classes/com/jogamp/javafx/newt/macosx/MacDisplay.java deleted file mode 100755 index 4d78358d7..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/macosx/MacDisplay.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.macosx; - -import javax.media.nativewindow.*; -import javax.media.nativewindow.macosx.*; -import com.jogamp.javafx.newt.*; -import com.jogamp.javafx.newt.impl.*; -import com.jogamp.javafx.newt.util.MainThread; - -public class MacDisplay extends Display { - static { - NativeLibLoader.loadNEWT(); - - if(!initNSApplication()) { - throw new NativeWindowException("Failed to initialize native Application hook"); - } - if(!MacWindow.initIDs()) { - throw new NativeWindowException("Failed to initialize jmethodIDs"); - } - if(DEBUG) System.out.println("MacDisplay.init App and IDs OK "+Thread.currentThread().getName()); - } - - public static void initSingleton() { - // just exist to ensure static init has been run - } - - public MacDisplay() { - } - - class DispatchAction implements Runnable { - public void run() { - dispatchMessages0(); - } - } - private DispatchAction dispatchAction = new DispatchAction(); - - public void dispatchMessages() { - MainThread.invoke(false, dispatchAction); - } - - protected void createNative() { - aDevice = new MacOSXGraphicsDevice(); - } - - protected void closeNative() { } - - private static native boolean initNSApplication(); - protected native void dispatchMessages0(); -} - diff --git a/src/newt/classes/com/jogamp/javafx/newt/macosx/MacScreen.java b/src/newt/classes/com/jogamp/javafx/newt/macosx/MacScreen.java deleted file mode 100755 index 8d0be80dc..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/macosx/MacScreen.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.macosx; - -import com.jogamp.javafx.newt.*; -import javax.media.nativewindow.*; - -public class MacScreen extends Screen { - static { - MacDisplay.initSingleton(); - } - - public MacScreen() { - } - - protected void createNative(int index) { - aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); - setScreenSize(getWidthImpl(getIndex()), getHeightImpl(getIndex())); - } - - protected void closeNative() { } - - private static native int getWidthImpl(int scrn_idx); - private static native int getHeightImpl(int scrn_idx); -} diff --git a/src/newt/classes/com/jogamp/javafx/newt/macosx/MacWindow.java b/src/newt/classes/com/jogamp/javafx/newt/macosx/MacWindow.java deleted file mode 100755 index f1698bfcd..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/macosx/MacWindow.java +++ /dev/null @@ -1,600 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.macosx; - -import javax.media.nativewindow.*; - -import com.jogamp.javafx.newt.util.MainThread; -import com.jogamp.javafx.newt.*; -import com.jogamp.javafx.newt.impl.*; - -public class MacWindow extends Window { - - // Window styles - private static final int NSBorderlessWindowMask = 0; - private static final int NSTitledWindowMask = 1 << 0; - private static final int NSClosableWindowMask = 1 << 1; - private static final int NSMiniaturizableWindowMask = 1 << 2; - private static final int NSResizableWindowMask = 1 << 3; - - // Window backing store types - private static final int NSBackingStoreRetained = 0; - private static final int NSBackingStoreNonretained = 1; - private static final int NSBackingStoreBuffered = 2; - - // Key constants handled differently on Mac OS X than other platforms - private static final int NSUpArrowFunctionKey = 0xF700; - private static final int NSDownArrowFunctionKey = 0xF701; - private static final int NSLeftArrowFunctionKey = 0xF702; - private static final int NSRightArrowFunctionKey = 0xF703; - private static final int NSF1FunctionKey = 0xF704; - private static final int NSF2FunctionKey = 0xF705; - private static final int NSF3FunctionKey = 0xF706; - private static final int NSF4FunctionKey = 0xF707; - private static final int NSF5FunctionKey = 0xF708; - private static final int NSF6FunctionKey = 0xF709; - private static final int NSF7FunctionKey = 0xF70A; - private static final int NSF8FunctionKey = 0xF70B; - private static final int NSF9FunctionKey = 0xF70C; - private static final int NSF10FunctionKey = 0xF70D; - private static final int NSF11FunctionKey = 0xF70E; - private static final int NSF12FunctionKey = 0xF70F; - private static final int NSF13FunctionKey = 0xF710; - private static final int NSF14FunctionKey = 0xF711; - private static final int NSF15FunctionKey = 0xF712; - private static final int NSF16FunctionKey = 0xF713; - private static final int NSF17FunctionKey = 0xF714; - private static final int NSF18FunctionKey = 0xF715; - private static final int NSF19FunctionKey = 0xF716; - private static final int NSF20FunctionKey = 0xF717; - private static final int NSF21FunctionKey = 0xF718; - private static final int NSF22FunctionKey = 0xF719; - private static final int NSF23FunctionKey = 0xF71A; - private static final int NSF24FunctionKey = 0xF71B; - private static final int NSF25FunctionKey = 0xF71C; - private static final int NSF26FunctionKey = 0xF71D; - private static final int NSF27FunctionKey = 0xF71E; - private static final int NSF28FunctionKey = 0xF71F; - private static final int NSF29FunctionKey = 0xF720; - private static final int NSF30FunctionKey = 0xF721; - private static final int NSF31FunctionKey = 0xF722; - private static final int NSF32FunctionKey = 0xF723; - private static final int NSF33FunctionKey = 0xF724; - private static final int NSF34FunctionKey = 0xF725; - private static final int NSF35FunctionKey = 0xF726; - private static final int NSInsertFunctionKey = 0xF727; - private static final int NSDeleteFunctionKey = 0xF728; - private static final int NSHomeFunctionKey = 0xF729; - private static final int NSBeginFunctionKey = 0xF72A; - private static final int NSEndFunctionKey = 0xF72B; - private static final int NSPageUpFunctionKey = 0xF72C; - private static final int NSPageDownFunctionKey = 0xF72D; - private static final int NSPrintScreenFunctionKey = 0xF72E; - private static final int NSScrollLockFunctionKey = 0xF72F; - private static final int NSPauseFunctionKey = 0xF730; - private static final int NSSysReqFunctionKey = 0xF731; - private static final int NSBreakFunctionKey = 0xF732; - private static final int NSResetFunctionKey = 0xF733; - private static final int NSStopFunctionKey = 0xF734; - private static final int NSMenuFunctionKey = 0xF735; - private static final int NSUserFunctionKey = 0xF736; - private static final int NSSystemFunctionKey = 0xF737; - private static final int NSPrintFunctionKey = 0xF738; - private static final int NSClearLineFunctionKey = 0xF739; - private static final int NSClearDisplayFunctionKey = 0xF73A; - private static final int NSInsertLineFunctionKey = 0xF73B; - private static final int NSDeleteLineFunctionKey = 0xF73C; - private static final int NSInsertCharFunctionKey = 0xF73D; - private static final int NSDeleteCharFunctionKey = 0xF73E; - private static final int NSPrevFunctionKey = 0xF73F; - private static final int NSNextFunctionKey = 0xF740; - private static final int NSSelectFunctionKey = 0xF741; - private static final int NSExecuteFunctionKey = 0xF742; - private static final int NSUndoFunctionKey = 0xF743; - private static final int NSRedoFunctionKey = 0xF744; - private static final int NSFindFunctionKey = 0xF745; - private static final int NSHelpFunctionKey = 0xF746; - private static final int NSModeSwitchFunctionKey = 0xF747; - - private volatile long surfaceHandle; - private long parentWindowHandle; - - // non fullscreen dimensions .. - private int nfs_width, nfs_height, nfs_x, nfs_y; - private final Insets insets = new Insets(0,0,0,0); - - static { - MacDisplay.initSingleton(); - } - - public MacWindow() { - } - - protected void createNative(long parentWindowHandle, Capabilities caps) { - this.parentWindowHandle=parentWindowHandle; - config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - } - - class CloseAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.CloseAction "+Thread.currentThread().getName()); - if (windowHandle != 0) { - close0(windowHandle); - windowHandle = 0; - } - } finally { - nsViewLock.unlock(); - } - } - } - private CloseAction closeAction = new CloseAction(); - - protected void closeNative() { - MainThread.invoke(true, closeAction); - } - - public long getWindowHandle() { - nsViewLock.lock(); - try { - return windowHandle; - } finally { - nsViewLock.unlock(); - } - } - - public long getSurfaceHandle() { - nsViewLock.lock(); - try { - return surfaceHandle; - } finally { - nsViewLock.unlock(); - } - } - - class EnsureWindowCreatedAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - createWindow(parentWindowHandle, false); - } finally { - nsViewLock.unlock(); - } - } - } - private EnsureWindowCreatedAction ensureWindowCreatedAction = - new EnsureWindowCreatedAction(); - - public Insets getInsets() { - // in order to properly calculate insets we need the window to be - // created - MainThread.invoke(true, ensureWindowCreatedAction); - nsViewLock.lock(); - try { - return (Insets) insets.clone(); - } finally { - nsViewLock.unlock(); - } - } - - private ToolkitLock nsViewLock = new ToolkitLock() { - private Thread owner; - private int recursionCount; - - public synchronized void lock() { - Thread cur = Thread.currentThread(); - if (owner == cur) { - ++recursionCount; - return; - } - while (owner != null) { - try { - wait(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - owner = cur; - } - - public synchronized void unlock() { - if (owner != Thread.currentThread()) { - throw new RuntimeException("Not owner"); - } - if (recursionCount > 0) { - --recursionCount; - return; - } - owner = null; - notifyAll(); - } - }; - - public synchronized int lockSurface() throws NativeWindowException { - nsViewLock.lock(); - return super.lockSurface(); - } - - public void unlockSurface() { - super.unlockSurface(); - nsViewLock.unlock(); - } - - class VisibleAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.VisibleAction "+visible+" "+Thread.currentThread().getName()); - if (visible) { - createWindow(parentWindowHandle, false); - if (windowHandle != 0) { - makeKeyAndOrderFront(windowHandle); - } - } else { - if (windowHandle != 0) { - orderOut(windowHandle); - } - } - } finally { - nsViewLock.unlock(); - } - } - } - private VisibleAction visibleAction = new VisibleAction(); - - public void setVisible(boolean visible) { - this.visible = visible; - MainThread.invoke(true, visibleAction); - } - - class TitleAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if (windowHandle != 0) { - setTitle0(windowHandle, title); - } - } finally { - nsViewLock.unlock(); - } - } - } - private TitleAction titleAction = new TitleAction(); - - public void setTitle(String title) { - super.setTitle(title); - MainThread.invoke(true, titleAction); - } - - class FocusAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if (windowHandle != 0) { - makeKey(windowHandle); - } - } finally { - nsViewLock.unlock(); - } - } - } - private FocusAction focusAction = new FocusAction(); - - public void requestFocus() { - super.requestFocus(); - MainThread.invoke(true, focusAction); - } - - class SizeAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if (windowHandle != 0) { - setContentSize(windowHandle, width, height); - } - } finally { - nsViewLock.unlock(); - } - } - } - private SizeAction sizeAction = new SizeAction(); - - public void setSize(int width, int height) { - this.width=width; - this.height=height; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - MainThread.invoke(true, sizeAction); - } - - class PositionAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if (windowHandle != 0) { - setFrameTopLeftPoint(parentWindowHandle, windowHandle, x, y); - } - } finally { - nsViewLock.unlock(); - } - } - } - private PositionAction positionAction = new PositionAction(); - - public void setPosition(int x, int y) { - this.x=x; - this.y=y; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - MainThread.invoke(true, positionAction); - } - - class FullscreenAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("MacWindow fs: "+fullscreen+" "+x+"/"+y+" "+width+"x"+height); - } - createWindow(parentWindowHandle, true); - if (windowHandle != 0) { - makeKeyAndOrderFront(windowHandle); - } - } finally { - nsViewLock.unlock(); - } - } - } - private FullscreenAction fullscreenAction = new FullscreenAction(); - - public boolean setFullscreen(boolean fullscreen) { - if(this.fullscreen!=fullscreen) { - this.fullscreen=fullscreen; - if(fullscreen) { - x = 0; - y = 0; - width = screen.getWidth(); - height = screen.getHeight(); - } else { - x = nfs_x; - y = nfs_y; - width = nfs_width; - height = nfs_height; - } - MainThread.invoke(true, fullscreenAction); - } - return fullscreen; - } - - private void sizeChanged(int newWidth, int newHeight) { - if (DEBUG_IMPLEMENTATION) { - System.out.println(Thread.currentThread().getName()+" Size changed to " + newWidth + ", " + newHeight); - } - width = newWidth; - height = newHeight; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - if (DEBUG_IMPLEMENTATION) { - System.out.println(" Posted WINDOW_RESIZED event"); - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); - } - - private void insetsChanged(int left, int top, int right, int bottom) { - if (DEBUG_IMPLEMENTATION) { - System.out.println(Thread.currentThread().getName()+ - " Insets changed to " + left + ", " + top + ", " + right + ", " + bottom); - } - if (left != -1 && top != -1 && right != -1 && bottom != -1) { - insets.left = left; - insets.top = top; - insets.right = right; - insets.bottom = bottom; - } - } - - private void positionChanged(int newX, int newY) { - if (DEBUG_IMPLEMENTATION) { - System.out.println(Thread.currentThread().getName()+" Position changed to " + newX + ", " + newY); - } - x = newX; - y = newY; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - if (DEBUG_IMPLEMENTATION) { - System.out.println(" Posted WINDOW_MOVED event"); - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); - } - - private void focusChanged(boolean focusGained) { - if (focusGained) { - sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); - } else { - sendWindowEvent(WindowEvent.EVENT_WINDOW_LOST_FOCUS); - } - } - - private char convertKeyChar(char keyChar) { - if (keyChar == '\r') { - // Turn these into \n - return '\n'; - } - - if (keyChar >= NSUpArrowFunctionKey && keyChar <= NSModeSwitchFunctionKey) { - switch (keyChar) { - case NSUpArrowFunctionKey: return KeyEvent.VK_UP; - case NSDownArrowFunctionKey: return KeyEvent.VK_DOWN; - case NSLeftArrowFunctionKey: return KeyEvent.VK_LEFT; - case NSRightArrowFunctionKey: return KeyEvent.VK_RIGHT; - case NSF1FunctionKey: return KeyEvent.VK_F1; - case NSF2FunctionKey: return KeyEvent.VK_F2; - case NSF3FunctionKey: return KeyEvent.VK_F3; - case NSF4FunctionKey: return KeyEvent.VK_F4; - case NSF5FunctionKey: return KeyEvent.VK_F5; - case NSF6FunctionKey: return KeyEvent.VK_F6; - case NSF7FunctionKey: return KeyEvent.VK_F7; - case NSF8FunctionKey: return KeyEvent.VK_F8; - case NSF9FunctionKey: return KeyEvent.VK_F9; - case NSF10FunctionKey: return KeyEvent.VK_F10; - case NSF11FunctionKey: return KeyEvent.VK_F11; - case NSF12FunctionKey: return KeyEvent.VK_F12; - case NSF13FunctionKey: return KeyEvent.VK_F13; - case NSF14FunctionKey: return KeyEvent.VK_F14; - case NSF15FunctionKey: return KeyEvent.VK_F15; - case NSF16FunctionKey: return KeyEvent.VK_F16; - case NSF17FunctionKey: return KeyEvent.VK_F17; - case NSF18FunctionKey: return KeyEvent.VK_F18; - case NSF19FunctionKey: return KeyEvent.VK_F19; - case NSF20FunctionKey: return KeyEvent.VK_F20; - case NSF21FunctionKey: return KeyEvent.VK_F21; - case NSF22FunctionKey: return KeyEvent.VK_F22; - case NSF23FunctionKey: return KeyEvent.VK_F23; - case NSF24FunctionKey: return KeyEvent.VK_F24; - case NSInsertFunctionKey: return KeyEvent.VK_INSERT; - case NSDeleteFunctionKey: return KeyEvent.VK_DELETE; - case NSHomeFunctionKey: return KeyEvent.VK_HOME; - case NSBeginFunctionKey: return KeyEvent.VK_BEGIN; - case NSEndFunctionKey: return KeyEvent.VK_END; - case NSPageUpFunctionKey: return KeyEvent.VK_PAGE_UP; - case NSPageDownFunctionKey: return KeyEvent.VK_PAGE_DOWN; - case NSPrintScreenFunctionKey: return KeyEvent.VK_PRINTSCREEN; - case NSScrollLockFunctionKey: return KeyEvent.VK_SCROLL_LOCK; - case NSPauseFunctionKey: return KeyEvent.VK_PAUSE; - // Not handled: - // NSSysReqFunctionKey - // NSBreakFunctionKey - // NSResetFunctionKey - case NSStopFunctionKey: return KeyEvent.VK_STOP; - // Not handled: - // NSMenuFunctionKey - // NSUserFunctionKey - // NSSystemFunctionKey - // NSPrintFunctionKey - // NSClearLineFunctionKey - // NSClearDisplayFunctionKey - // NSInsertLineFunctionKey - // NSDeleteLineFunctionKey - // NSInsertCharFunctionKey - // NSDeleteCharFunctionKey - // NSPrevFunctionKey - // NSNextFunctionKey - // NSSelectFunctionKey - // NSExecuteFunctionKey - // NSUndoFunctionKey - // NSRedoFunctionKey - // NSFindFunctionKey - // NSHelpFunctionKey - // NSModeSwitchFunctionKey - default: break; - } - } - - // NSEvent's charactersIgnoringModifiers doesn't ignore the shift key - if (keyChar >= 'a' && keyChar <= 'z') { - return Character.toUpperCase(keyChar); - } - - return keyChar; - } - - protected void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { - int key = convertKeyChar(keyChar); - if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.sendKeyEvent "+Thread.currentThread().getName()); - // Note that we send the key char for the key code on this - // platform -- we do not get any useful key codes out of the system - super.sendKeyEvent(eventType, modifiers, key, keyChar); - } - - private void createWindow(long parentWindowHandle, boolean recreate) { - if(0!=windowHandle && !recreate) { - return; - } - if(0!=windowHandle) { - // save the view .. close the window - surfaceHandle = changeContentView(parentWindowHandle, windowHandle, 0); - if(recreate && 0==surfaceHandle) { - throw new NativeWindowException("Internal Error - recreate, window but no view"); - } - close0(windowHandle); - windowHandle=0; - } else { - surfaceHandle = 0; - } - windowHandle = createWindow0(parentWindowHandle, - getX(), getY(), getWidth(), getHeight(), fullscreen, - (isUndecorated() ? - NSBorderlessWindowMask : - NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask), - NSBackingStoreBuffered, - getScreen().getIndex(), surfaceHandle); - if (windowHandle == 0) { - throw new NativeWindowException("Could create native window "+Thread.currentThread().getName()+" "+this); - } - surfaceHandle = contentView(windowHandle); - setTitle0(windowHandle, getTitle()); - // don't make the window visible on window creation -// makeKeyAndOrderFront(windowHandle); - sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); - sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); - sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); - } - - protected static native boolean initIDs(); - private native long createWindow0(long parentWindowHandle, int x, int y, int w, int h, - boolean fullscreen, int windowStyle, - int backingStoreType, - int screen_idx, long view); - private native void makeKeyAndOrderFront(long window); - private native void makeKey(long window); - private native void orderOut(long window); - private native void close0(long window); - private native void setTitle0(long window, String title); - private native long contentView(long window); - private native long changeContentView(long parentWindowHandle, long window, long view); - private native void setContentSize(long window, int w, int h); - private native void setFrameTopLeftPoint(long parentWindowHandle, long window, int x, int y); -} diff --git a/src/newt/classes/com/jogamp/javafx/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/javafx/newt/opengl/GLWindow.java deleted file mode 100644 index b299d011e..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/opengl/GLWindow.java +++ /dev/null @@ -1,628 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.opengl; - -import com.jogamp.javafx.newt.*; -import javax.media.nativewindow.*; -import javax.media.opengl.*; -import com.jogamp.opengl.impl.GLDrawableHelper; -import java.util.*; - -/** - * An implementation of {@link Window} which is customized for OpenGL - * use, and which implements the {@link javax.media.opengl.GLAutoDrawable} interface. - *

- * This implementation does not make the OpenGL context current
- * before calling the various input EventListener callbacks (MouseListener, KeyListener, - * etc.).
- * This design decision is made to favor a more performant and simplified - * implementation, as well as the event dispatcher shall be allowed - * not having a notion about OpenGL. - *

- */ -public class GLWindow extends Window implements GLAutoDrawable { - private static List/*GLWindow*/ glwindows = new ArrayList(); - - private boolean ownerOfWinScrDpy; - private Window window; - private boolean runPumpMessages; - - /** Constructor. Do not call this directly -- use {@link - create()} instead. */ - protected GLWindow(Window window, boolean ownerOfWinScrDpy) { - this.ownerOfWinScrDpy = ownerOfWinScrDpy; - this.window = window; - this.window.setAutoDrawableClient(true); - this.runPumpMessages = ( null == getScreen().getDisplay().getEDT() ) ; - window.addWindowListener(new WindowListener() { - public void windowResized(WindowEvent e) { - sendReshape = true; - } - - public void windowMoved(WindowEvent e) { - } - - public void windowGainedFocus(WindowEvent e) { - } - - public void windowLostFocus(WindowEvent e) { - } - - public void windowDestroyNotify(WindowEvent e) { - sendDestroy = true; - } - }); - - List newglw = (List) ((ArrayList) glwindows).clone(); - newglw.add(this); - glwindows=newglw; - } - - /** Creates a new GLWindow on the local display, screen 0, with a - dummy visual ID, and with the default GLCapabilities. */ - public static GLWindow create() { - return create(null, null, false); - } - - public static GLWindow create(boolean undecorated) { - return create(null, null, undecorated); - } - - /** Creates a new GLWindow referring to the given window. */ - public static GLWindow create(Window window) { - return create(window, null, false); - } - public static GLWindow create(GLCapabilities caps) { - return create(null, caps, false); - } - - /** Creates a new GLWindow on the local display, screen 0, with a - dummy visual ID, and with the given GLCapabilities. */ - public static GLWindow create(GLCapabilities caps, boolean undecorated) { - return create(null, caps, undecorated); - } - - /** Either or: window (prio), or caps and undecorated (2nd choice) */ - private static GLWindow create(Window window, - GLCapabilities caps, - boolean undecorated) { - Display display; - boolean ownerOfWinScrDpy=false; - if (window == null) { - if (caps == null) { - caps = new GLCapabilities(null); // default .. - } - ownerOfWinScrDpy = true; - display = NewtFactory.createDisplay(null); // local display - Screen screen = NewtFactory.createScreen(display, 0); // screen 0 - window = NewtFactory.createWindow(screen, caps, undecorated); - } - - return new GLWindow(window, ownerOfWinScrDpy); - } - - /** - * EXPERIMENTAL
- * Enable or disables running the {@link Display#pumpMessages} in the {@link #display()} call.
- * The default behavior is to run {@link Display#pumpMessages}.

- * - * The idea was that in a single threaded environment with one {@link Display} and many {@link Window}'s, - * a performance benefit was expected while disabling the implicit {@link Display#pumpMessages} and - * do it once via {@link GLWindow#runCurrentThreadPumpMessage()}
- * This could not have been verified. No measurable difference could have been recognized.

- * - * Best performance has been achieved with one GLWindow per thread.
- * - * Enabling local pump messages while using the EDT, - * {@link com.jogamp.javafx.newt.NewtFactory#setUseEDT(boolean)}, - * will result in an exception. - * - * @deprecated EXPERIMENTAL, semantic is about to be removed after further verification. - */ - public void setRunPumpMessages(boolean onoff) { - if( onoff && null!=getScreen().getDisplay().getEDT() ) { - throw new GLException("GLWindow.setRunPumpMessages(true) - Can't do with EDT on"); - } - runPumpMessages = onoff; - } - - protected void createNative(long parentWindowHandle, Capabilities caps) { - shouldNotCallThis(); - } - - protected void closeNative() { - shouldNotCallThis(); - } - - protected void dispose(boolean regenerate, boolean sendEvent) { - if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { - Exception e1 = new Exception("GLWindow.dispose("+regenerate+") "+Thread.currentThread()+", 1"); - e1.printStackTrace(); - } - - if(sendEvent) { - sendDisposeEvent(); - } - - if (context != null) { - context.destroy(); - } - if (drawable != null) { - drawable.setRealized(false); - } - - if(regenerate) { - if(null==window) { - throw new GLException("GLWindow.dispose(true): null window"); - } - - // recreate GLDrawable, to reflect the new graphics configurations - NativeWindow nw; - if (window.getWrappedWindow() != null) { - nw = NativeWindowFactory.getNativeWindow(window.getWrappedWindow(), window.getGraphicsConfiguration()); - } else { - nw = window; - } - drawable = factory.createGLDrawable(nw); - drawable.setRealized(true); - context = drawable.createContext(null); - sendReshape = true; // ensure a reshape event is send .. - } - - if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { - System.out.println("GLWindow.dispose("+regenerate+") "+Thread.currentThread()+", fin: "+this); - } - } - - public synchronized void destroy() { - destroy(true); - } - - /** @param sendDisposeEvent should be false in a [time,reliable] critical shutdown */ - public synchronized void destroy(boolean sendDisposeEvent) { - if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { - Exception e1 = new Exception("GLWindow.destroy "+Thread.currentThread()+", 1: "+this); - e1.printStackTrace(); - } - - List newglw = (List) ((ArrayList) glwindows).clone(); - newglw.remove(this); - glwindows=newglw; - - dispose(false, sendDisposeEvent); - - if(null!=window) { - if(ownerOfWinScrDpy) { - window.destroy(true); - } - } - - drawable = null; - context = null; - window = null; - - if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { - System.out.println("GLWindow.destroy "+Thread.currentThread()+", fin: "+this); - } - } - - public boolean getPerfLogEnabled() { return perfLog; } - - public void enablePerfLog(boolean v) { - perfLog = v; - } - - public void setVisible(boolean visible) { - if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { - System.out.println(Thread.currentThread()+" GLWindow.setVisible("+visible+") START ; isVisible "+this.visible+" ; has context "+(null!=context)); - } - this.visible=visible; - window.setVisible(visible); - if (visible && context == null) { - NativeWindow nw; - if (window.getWrappedWindow() != null) { - nw = NativeWindowFactory.getNativeWindow(window.getWrappedWindow(), window.getGraphicsConfiguration()); - } else { - nw = window; - } - GLCapabilities glCaps = (GLCapabilities) nw.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); - factory = GLDrawableFactory.getFactory(glCaps.getGLProfile()); - drawable = factory.createGLDrawable(nw); - drawable.setRealized(true); - context = drawable.createContext(null); - sendReshape = true; // ensure a reshape event is send .. - } - if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { - System.out.println(Thread.currentThread()+" GLWindow.setVisible("+visible+") END ; has context "+(null!=context)); - } - } - - public Screen getScreen() { - return window.getScreen(); - } - - public void setTitle(String title) { - window.setTitle(title); - } - - public String getTitle() { - return window.getTitle(); - } - - public void setUndecorated(boolean value) { - window.setUndecorated(value); - } - - public boolean isUndecorated() { - return window.isUndecorated(); - } - - public void setSize(int width, int height) { - window.setSize(width, height); - } - - public void setPosition(int x, int y) { - window.setPosition(x, y); - } - - public Insets getInsets() { - return window.getInsets(); - } - - public boolean setFullscreen(boolean fullscreen) { - return window.setFullscreen(fullscreen); - } - - public boolean isVisible() { - return window.isVisible(); - } - - public int getX() { - return window.getX(); - } - - public int getY() { - return window.getY(); - } - - public int getWidth() { - return window.getWidth(); - } - - public int getHeight() { - return window.getHeight(); - } - - public boolean isFullscreen() { - return window.isFullscreen(); - } - - public void addSurfaceUpdatedListener(SurfaceUpdatedListener l) { - window.addSurfaceUpdatedListener(l); - } - public void removeSurfaceUpdatedListener(SurfaceUpdatedListener l) { - window.removeSurfaceUpdatedListener(l); - } - public SurfaceUpdatedListener[] getSurfaceUpdatedListener() { - return window.getSurfaceUpdatedListener(); - } - public void surfaceUpdated(Object updater, NativeWindow window0, long when) { - window.surfaceUpdated(updater, window, when); - } - - public void addMouseListener(MouseListener l) { - window.addMouseListener(l); - } - - public void removeMouseListener(MouseListener l) { - window.removeMouseListener(l); - } - - public MouseListener[] getMouseListeners() { - return window.getMouseListeners(); - } - - public void addKeyListener(KeyListener l) { - window.addKeyListener(l); - } - - public void removeKeyListener(KeyListener l) { - window.removeKeyListener(l); - } - - public KeyListener[] getKeyListeners() { - return window.getKeyListeners(); - } - - public void addWindowListener(WindowListener l) { - window.addWindowListener(l); - } - - public void removeWindowListener(WindowListener l) { - window.removeWindowListener(l); - } - - public WindowListener[] getWindowListeners() { - return window.getWindowListeners(); - } - - public String toString() { - return "NEWT-GLWindow[ \n\tDrawable: "+drawable+", \n\tWindow: "+window+", \n\tHelper: "+helper+", \n\tFactory: "+factory+"]"; - } - - //---------------------------------------------------------------------- - // OpenGL-related methods and state - // - - private GLDrawableFactory factory; - private GLDrawable drawable; - private GLContext context; - private GLDrawableHelper helper = new GLDrawableHelper(); - // To make reshape events be sent immediately before a display event - private boolean sendReshape=false; - private boolean sendDestroy=false; - private boolean perfLog = false; - - public GLDrawableFactory getFactory() { - return factory; - } - - public void setContext(GLContext newCtx) { - context = newCtx; - } - - public GLContext getContext() { - return context; - } - - public GL getGL() { - if (context == null) { - return null; - } - return context.getGL(); - } - - public GL setGL(GL gl) { - if (context != null) { - context.setGL(gl); - return gl; - } - return null; - } - - public void addGLEventListener(GLEventListener listener) { - helper.addGLEventListener(listener); - } - - public void removeGLEventListener(GLEventListener listener) { - helper.removeGLEventListener(listener); - } - - public void display() { - display(false); - } - - public void display(boolean forceReshape) { - if(window!=null && drawable!=null && context != null) { - if(runPumpMessages) { - window.getScreen().getDisplay().pumpMessages(); - } - if(window.hasDeviceChanged() && GLAutoDrawable.SCREEN_CHANGE_ACTION_ENABLED) { - dispose(true, true); - } - if (sendDestroy) { - destroy(); - sendDestroy=false; - } else { - if(forceReshape) { - sendReshape = true; - } - helper.invokeGL(drawable, context, displayAction, initAction); - } - } - } - - private void sendDisposeEvent() { - if(drawable!=null && context != null) { - helper.invokeGL(drawable, context, disposeAction, null); - } - } - - /** This implementation uses a static value */ - public void setAutoSwapBufferMode(boolean onOrOff) { - helper.setAutoSwapBufferMode(onOrOff); - } - - /** This implementation uses a static value */ - public boolean getAutoSwapBufferMode() { - return helper.getAutoSwapBufferMode(); - } - - public void swapBuffers() { - if(drawable!=null && context != null) { - if (context != GLContext.getCurrent()) { - // Assume we should try to make the context current before swapping the buffers - helper.invokeGL(drawable, context, swapBuffersAction, initAction); - } else { - drawable.swapBuffers(); - } - } - } - - class InitAction implements Runnable { - public void run() { - helper.init(GLWindow.this); - startTime = System.currentTimeMillis(); - curTime = startTime; - if(perfLog) { - lastCheck = startTime; - totalFrames = 0; lastFrames = 0; - } - } - } - private InitAction initAction = new InitAction(); - - class DisposeAction implements Runnable { - public void run() { - helper.dispose(GLWindow.this); - } - } - private DisposeAction disposeAction = new DisposeAction(); - - class DisplayAction implements Runnable { - public void run() { - if (sendReshape) { - int width = getWidth(); - int height = getHeight(); - getGL().glViewport(0, 0, width, height); - helper.reshape(GLWindow.this, 0, 0, width, height); - sendReshape = false; - } - - helper.display(GLWindow.this); - - curTime = System.currentTimeMillis(); - totalFrames++; - - if(perfLog) { - long dt0, dt1; - lastFrames++; - dt0 = curTime-lastCheck; - if ( dt0 > 5000 ) { - dt1 = curTime-startTime; - System.out.println(dt0/1000 +"s: "+ lastFrames + "f, " + (lastFrames*1000)/dt0 + " fps, "+dt0/lastFrames+" ms/f; "+ - "total: "+ dt1/1000+"s, "+(totalFrames*1000)/dt1 + " fps, "+dt1/totalFrames+" ms/f"); - lastCheck=curTime; - lastFrames=0; - } - } - } - } - private DisplayAction displayAction = new DisplayAction(); - - public long getStartTime() { return startTime; } - public long getCurrentTime() { return curTime; } - public long getDuration() { return curTime-startTime; } - public int getTotalFrames() { return totalFrames; } - - private long startTime = 0; - private long curTime = 0; - private long lastCheck = 0; - private int totalFrames = 0, lastFrames = 0; - - class SwapBuffersAction implements Runnable { - public void run() { - drawable.swapBuffers(); - } - } - private SwapBuffersAction swapBuffersAction = new SwapBuffersAction(); - - //---------------------------------------------------------------------- - // GLDrawable methods - // - - public NativeWindow getNativeWindow() { - return null!=drawable ? drawable.getNativeWindow() : null; - } - - public synchronized int lockSurface() throws NativeWindowException { - if(null!=drawable) return drawable.getNativeWindow().lockSurface(); - return NativeWindow.LOCK_SURFACE_NOT_READY; - } - - public synchronized void unlockSurface() { - if(null!=drawable) drawable.getNativeWindow().unlockSurface(); - else throw new NativeWindowException("NEWT-GLWindow not locked"); - } - - public synchronized boolean isSurfaceLocked() { - if(null!=drawable) return drawable.getNativeWindow().isSurfaceLocked(); - return false; - } - - public synchronized Exception getLockedStack() { - if(null!=drawable) return drawable.getNativeWindow().getLockedStack(); - return null; - } - - public boolean surfaceSwap() { - if(null!=drawable) return drawable.getNativeWindow().surfaceSwap(); - return super.surfaceSwap(); - } - - public long getWindowHandle() { - if(null!=drawable) return drawable.getNativeWindow().getWindowHandle(); - return super.getWindowHandle(); - } - - public long getSurfaceHandle() { - if(null!=drawable) return drawable.getNativeWindow().getSurfaceHandle(); - return super.getSurfaceHandle(); - } - - //---------------------------------------------------------------------- - // GLDrawable methods that are not really needed - // - - public GLContext createContext(GLContext shareWith) { - return drawable.createContext(shareWith); - } - - public void setRealized(boolean realized) { - } - - public GLCapabilities getChosenGLCapabilities() { - if (drawable == null) { - throw new GLException("No drawable yet"); - } - - return drawable.getChosenGLCapabilities(); - } - - public GLProfile getGLProfile() { - if (drawable == null) { - throw new GLException("No drawable yet"); - } - - return drawable.getGLProfile(); - } - - //---------------------------------------------------------------------- - // Internals only below this point - // - - private void shouldNotCallThis() { - throw new NativeWindowException("Should not call this"); - } -} diff --git a/src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Display.java b/src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Display.java deleted file mode 100644 index c0c1ee5fd..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Display.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.opengl.broadcom.egl; - -import com.jogamp.javafx.newt.impl.*; -import com.jogamp.opengl.impl.egl.*; -import javax.media.nativewindow.*; -import javax.media.nativewindow.egl.*; - -public class Display extends com.jogamp.javafx.newt.Display { - - static { - NativeLibLoader.loadNEWT(); - - if (!Window.initIDs()) { - throw new NativeWindowException("Failed to initialize BCEGL Window jmethodIDs"); - } - } - - public static void initSingleton() { - // just exist to ensure static init has been run - } - - - public Display() { - } - - protected void createNative() { - long handle = CreateDisplay(Screen.fixedWidth, Screen.fixedHeight); - if (handle == EGL.EGL_NO_DISPLAY) { - throw new NativeWindowException("BC EGL CreateDisplay failed"); - } - aDevice = new EGLGraphicsDevice(handle); - } - - protected void closeNative() { - if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) { - DestroyDisplay(aDevice.getHandle()); - } - } - - protected void dispatchMessages() { - // n/a .. DispatchMessages(); - } - - private native long CreateDisplay(int width, int height); - private native void DestroyDisplay(long dpy); - private native void DispatchMessages(); -} - diff --git a/src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Screen.java b/src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Screen.java deleted file mode 100755 index f7abe3836..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Screen.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.opengl.broadcom.egl; - -import com.jogamp.javafx.newt.impl.*; -import javax.media.nativewindow.*; - -public class Screen extends com.jogamp.javafx.newt.Screen { - - static { - Display.initSingleton(); - } - - - public Screen() { - } - - protected void createNative(int index) { - aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); - setScreenSize(fixedWidth, fixedHeight); - } - - protected void closeNative() { } - - //---------------------------------------------------------------------- - // Internals only - // - - static final int fixedWidth = 1920; - static final int fixedHeight = 1080; -} - diff --git a/src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Window.java b/src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Window.java deleted file mode 100755 index bd2d7930e..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/opengl/broadcom/egl/Window.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.opengl.broadcom.egl; - -import com.jogamp.javafx.newt.impl.*; -import com.jogamp.opengl.impl.egl.*; -import javax.media.nativewindow.*; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLProfile; -import javax.media.nativewindow.NativeWindowException; - -public class Window extends com.jogamp.javafx.newt.Window { - static { - Display.initSingleton(); - } - - public Window() { - } - - protected void createNative(long parentWindowHandle, Capabilities caps) { - if(0!=parentWindowHandle) { - throw new RuntimeException("Window parenting not supported (yet)"); - } - // query a good configuration .. even thought we drop this one - // and reuse the EGLUtil choosen one later. - config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - setSizeImpl(getScreen().getWidth(), getScreen().getHeight()); - } - - protected void closeNative() { - if(0!=windowHandleClose) { - CloseWindow(getDisplayHandle(), windowHandleClose); - } - } - - public void setVisible(boolean visible) { - if(this.visible!=visible) { - this.visible=visible; - if ( 0==windowHandle ) { - windowHandle = realizeWindow(true, width, height); - if (0 == windowHandle) { - throw new NativeWindowException("Error native Window Handle is null"); - } - } - clearEventMask(); - } - } - - public void setSize(int width, int height) { - System.err.println("setSize "+width+"x"+height+" n/a in BroadcomEGL"); - } - - void setSizeImpl(int width, int height) { - if(0!=windowHandle) { - // n/a in BroadcomEGL - System.err.println("BCEGL Window.setSizeImpl n/a in BroadcomEGL with realized window"); - } else { - if(DEBUG_IMPLEMENTATION) { - Exception e = new Exception("BCEGL Window.setSizeImpl() "+this.width+"x"+this.height+" -> "+width+"x"+height); - e.printStackTrace(); - } - this.width = width; - this.height = height; - } - } - - public void setPosition(int x, int y) { - // n/a in BroadcomEGL - System.err.println("setPosition n/a in BroadcomEGL"); - } - - public boolean setFullscreen(boolean fullscreen) { - // n/a in BroadcomEGL - System.err.println("setFullscreen n/a in BroadcomEGL"); - return false; - } - - public boolean surfaceSwap() { - if ( 0!=windowHandle ) { - SwapWindow(getDisplayHandle(), windowHandle); - return true; - } - return false; - } - - //---------------------------------------------------------------------- - // Internals only - // - - protected static native boolean initIDs(); - private native long CreateWindow(long eglDisplayHandle, boolean chromaKey, int width, int height); - private native void CloseWindow(long eglDisplayHandle, long eglWindowHandle); - private native void SwapWindow(long eglDisplayHandle, long eglWindowHandle); - - - private long realizeWindow(boolean chromaKey, int width, int height) { - if(DEBUG_IMPLEMENTATION) { - System.out.println("BCEGL Window.realizeWindow() with: chroma "+chromaKey+", "+width+"x"+height+", "+config); - } - long handle = CreateWindow(getDisplayHandle(), chromaKey, width, height); - if (0 == handle) { - throw new NativeWindowException("Error native Window Handle is null"); - } - windowHandleClose = handle; - return handle; - } - - private void windowCreated(int cfgID, int width, int height) { - this.width = width; - this.height = height; - GLCapabilities capsReq = (GLCapabilities) config.getRequestedCapabilities(); - config = EGLGraphicsConfiguration.create(capsReq, screen.getGraphicsScreen(), cfgID); - if (config == null) { - throw new NativeWindowException("Error creating EGLGraphicsConfiguration from id: "+cfgID+", "+this); - } - if(DEBUG_IMPLEMENTATION) { - System.out.println("BCEGL Window.windowCreated(): "+toHexString(cfgID)+", "+width+"x"+height+", "+config); - } - } - - private long windowHandleClose; -} diff --git a/src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDDisplay.java b/src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDDisplay.java deleted file mode 100755 index 40a37115d..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDDisplay.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.opengl.kd; - -import com.jogamp.javafx.newt.*; -import com.jogamp.javafx.newt.impl.*; -import com.jogamp.opengl.impl.egl.*; -import javax.media.nativewindow.*; -import javax.media.nativewindow.egl.*; - -public class KDDisplay extends Display { - - static { - NativeLibLoader.loadNEWT(); - - if (!KDWindow.initIDs()) { - throw new NativeWindowException("Failed to initialize KDWindow jmethodIDs"); - } - } - - public static void initSingleton() { - // just exist to ensure static init has been run - } - - - public KDDisplay() { - } - - protected void createNative() { - // FIXME: map name to EGL_*_DISPLAY - long handle = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY); - if (handle == EGL.EGL_NO_DISPLAY) { - throw new NativeWindowException("eglGetDisplay failed"); - } - if (!EGL.eglInitialize(handle, null, null)) { - throw new NativeWindowException("eglInitialize failed"); - } - aDevice = new EGLGraphicsDevice(handle); - } - - protected void closeNative() { - if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) { - EGL.eglTerminate(aDevice.getHandle()); - } - } - - protected void dispatchMessages() { - DispatchMessages(); - } - - private native void DispatchMessages(); -} - diff --git a/src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDScreen.java b/src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDScreen.java deleted file mode 100755 index 4bc7f8257..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDScreen.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.opengl.kd; - -import com.jogamp.javafx.newt.*; -import javax.media.nativewindow.*; - -public class KDScreen extends Screen { - static { - KDDisplay.initSingleton(); - } - - public KDScreen() { - } - - protected void createNative(int index) { - aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); - } - - protected void closeNative() { } - - // elevate access to this package .. - protected void setScreenSize(int w, int h) { - super.setScreenSize(w, h); - } -} diff --git a/src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDWindow.java b/src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDWindow.java deleted file mode 100755 index d5be2207c..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/opengl/kd/KDWindow.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.opengl.kd; - -import com.jogamp.javafx.newt.*; -import com.jogamp.javafx.newt.impl.*; -import com.jogamp.opengl.impl.egl.*; -import javax.media.nativewindow.*; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLProfile; -import javax.media.nativewindow.NativeWindowException; - -public class KDWindow extends Window { - private static final String WINDOW_CLASS_NAME = "NewtWindow"; - // non fullscreen dimensions .. - private int nfs_width, nfs_height, nfs_x, nfs_y; - - static { - KDDisplay.initSingleton(); - } - - public KDWindow() { - } - - protected void createNative(long parentWindowHandle, Capabilities caps) { - if(0!=parentWindowHandle) { - throw new RuntimeException("Window parenting not supported (yet)"); - } - config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - - GLCapabilities eglCaps = (GLCapabilities)config.getChosenCapabilities(); - int[] eglAttribs = EGLGraphicsConfiguration.GLCapabilities2AttribList(eglCaps); - - windowHandle = 0; - eglWindowHandle = CreateWindow(getDisplayHandle(), eglAttribs); - if (eglWindowHandle == 0) { - throw new NativeWindowException("Error creating egl window: "+config); - } - setVisible0(eglWindowHandle, false); - windowHandleClose = eglWindowHandle; - } - - protected void closeNative() { - if(0!=windowHandleClose) { - CloseWindow(windowHandleClose, windowUserData); - windowUserData=0; - } - } - - public void setVisible(boolean visible) { - if(0!=eglWindowHandle && this.visible!=visible) { - this.visible=visible; - setVisible0(eglWindowHandle, visible); - if ( 0==windowHandle ) { - windowHandle = RealizeWindow(eglWindowHandle); - if (0 == windowHandle) { - throw new NativeWindowException("Error native Window Handle is null"); - } - } - clearEventMask(); - } - } - - public void setSize(int width, int height) { - if(0!=eglWindowHandle) { - setSize0(eglWindowHandle, width, height); - } - } - - public void setPosition(int x, int y) { - // n/a in KD - System.err.println("setPosition n/a in KD"); - } - - public boolean setFullscreen(boolean fullscreen) { - if(0!=eglWindowHandle && this.fullscreen!=fullscreen) { - this.fullscreen=fullscreen; - if(this.fullscreen) { - setFullScreen0(eglWindowHandle, true); - } else { - setFullScreen0(eglWindowHandle, false); - setSize0(eglWindowHandle, nfs_width, nfs_height); - } - } - return true; - } - - //---------------------------------------------------------------------- - // Internals only - // - - protected static native boolean initIDs(); - private native long CreateWindow(long displayHandle, int[] attributes); - private native long RealizeWindow(long eglWindowHandle); - private native int CloseWindow(long eglWindowHandle, long userData); - private native void setVisible0(long eglWindowHandle, boolean visible); - private native void setSize0(long eglWindowHandle, int width, int height); - private native void setFullScreen0(long eglWindowHandle, boolean fullscreen); - - private void windowCreated(long userData) { - windowUserData=userData; - } - - private void sizeChanged(int newWidth, int newHeight) { - width = newWidth; - height = newHeight; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } else { - ((KDScreen)screen).setScreenSize(width, height); - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); - } - - private long eglWindowHandle; - private long windowHandleClose; - private long windowUserData; -} diff --git a/src/newt/classes/com/jogamp/javafx/newt/util/EventDispatchThread.java b/src/newt/classes/com/jogamp/javafx/newt/util/EventDispatchThread.java deleted file mode 100644 index db3f97ee6..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/util/EventDispatchThread.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright (c) 2009 Sun Microsystems, Inc. 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 com.jogamp.javafx.newt.util; - -import com.jogamp.javafx.newt.Display; -import com.jogamp.javafx.newt.impl.Debug; -import java.util.*; - -public class EventDispatchThread { - public static final boolean DEBUG = Debug.debug("EDT"); - - private ThreadGroup threadGroup; - private volatile boolean shouldStop = false; - private TaskWorker taskWorker = null; - private Object taskWorkerLock = new Object(); - private ArrayList tasks = new ArrayList(); // one shot tasks - private Display display = null; - private String name; - private long edtPollGranularity = 10; - - public EventDispatchThread(Display display, ThreadGroup tg, String name) { - this.display = display; - this.threadGroup = tg; - this.name=new String("EDT-Display_"+display.getName()+"-"+name); - } - - public String getName() { return name; } - - public ThreadGroup getThreadGroup() { return threadGroup; } - - public void start() { - start(false); - } - - /** - * @param externalStimuli true indicates that another thread stimulates, - * ie. calls this TaskManager's run() loop method. - * Hence no own thread is started in this case. - * - * @return The started Runnable, which handles the run-loop. - * Usefull in combination with externalStimuli=true, - * so an external stimuli can call it. - */ - public Runnable start(boolean externalStimuli) { - synchronized(taskWorkerLock) { - if(null==taskWorker) { - taskWorker = new TaskWorker(threadGroup, name); - } - if(!taskWorker.isRunning()) { - shouldStop = false; - taskWorker.start(externalStimuli); - } - taskWorkerLock.notifyAll(); - } - return taskWorker; - } - - public void stop() { - synchronized(taskWorkerLock) { - if(null!=taskWorker && taskWorker.isRunning()) { - shouldStop = true; - } - taskWorkerLock.notifyAll(); - if(DEBUG) { - System.out.println(Thread.currentThread()+": EDT signal STOP"); - } - } - } - - public boolean isThreadEDT(Thread thread) { - return null!=taskWorker && taskWorker == thread; - } - - public boolean isCurrentThreadEDT() { - return null!=taskWorker && taskWorker == Thread.currentThread(); - } - - public boolean isRunning() { - return null!=taskWorker && taskWorker.isRunning() ; - } - - public void invokeLater(Runnable task) { - if(task == null) { - return; - } - synchronized(taskWorkerLock) { - if(null!=taskWorker && taskWorker.isRunning() && taskWorker != Thread.currentThread() ) { - tasks.add(task); - taskWorkerLock.notifyAll(); - } else { - // if !running or isEDTThread, do it right away - task.run(); - } - } - } - - public void invokeAndWait(Runnable task) { - if(task == null) { - return; - } - invokeLater(task); - waitOnWorker(); - } - - public void waitOnWorker() { - synchronized(taskWorkerLock) { - if(null!=taskWorker && taskWorker.isRunning() && tasks.size()>0 && taskWorker != Thread.currentThread() ) { - try { - taskWorkerLock.wait(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - } - - public void waitUntilStopped() { - synchronized(taskWorkerLock) { - while(null!=taskWorker && taskWorker.isRunning() && taskWorker != Thread.currentThread() ) { - try { - taskWorkerLock.wait(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - } - - class TaskWorker extends Thread { - boolean isRunning = false; - boolean externalStimuli = false; - - public TaskWorker(ThreadGroup tg, String name) { - super(tg, name); - } - - public synchronized boolean isRunning() { - return isRunning; - } - - public void start(boolean externalStimuli) throws IllegalThreadStateException { - synchronized(this) { - this.externalStimuli = externalStimuli; - isRunning = true; - } - if(!externalStimuli) { - super.start(); - } - } - - /** - * Utilizing taskWorkerLock only for local resources and task execution, - * not for event dispatching. - */ - public void run() { - if(DEBUG) { - System.out.println(Thread.currentThread()+": EDT run() START"); - } - while(!shouldStop) { - try { - // wait for something todo - while(!shouldStop && tasks.size()==0) { - synchronized(taskWorkerLock) { - if(!shouldStop && tasks.size()==0) { - try { - taskWorkerLock.wait(edtPollGranularity); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - display.pumpMessages(); // event dispatch - } - if(!shouldStop && tasks.size()>0) { - synchronized(taskWorkerLock) { - if(!shouldStop && tasks.size()>0) { - Runnable task = (Runnable) tasks.remove(0); - task.run(); - taskWorkerLock.notifyAll(); - } - } - display.pumpMessages(); // event dispatch - } - } catch (Throwable t) { - // handle errors .. - t.printStackTrace(); - } finally { - // epilog - unlock locked stuff - } - if(externalStimuli) break; // no loop if called by external stimuli - } - synchronized(this) { - isRunning = !shouldStop; - } - if(!isRunning) { - synchronized(taskWorkerLock) { - taskWorkerLock.notifyAll(); - } - } - if(DEBUG) { - System.out.println(Thread.currentThread()+": EDT run() EXIT"); - } - } - } -} - diff --git a/src/newt/classes/com/jogamp/javafx/newt/util/MainThread.java b/src/newt/classes/com/jogamp/javafx/newt/util/MainThread.java deleted file mode 100644 index 9bf25098f..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/util/MainThread.java +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright (c) 2009 Sun Microsystems, Inc. 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 com.jogamp.javafx.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.javafx.newt.*; -import com.jogamp.javafx.newt.impl.*; -import com.jogamp.javafx.newt.macosx.MacDisplay; -import com.jogamp.nativewindow.impl.NWReflection; - -/** - * NEWT Utility class MainThread

- * - * This class provides a startup singleton main thread, - * from which a new thread with the users main class is launched.
- * - * Such behavior is necessary for native windowing toolkits, - * where the windowing management must happen on the so called - * main thread e.g. for Mac OS X !
- * - * Utilizing this class as a launchpad, now you are able to - * use a NEWT multithreaded application with window handling within the different threads, - * even on these restricted platforms.
- * - * To support your NEWT Window platform, - * you have to pass your main thread actions to {@link #invoke invoke(..)}, - * have a look at the {@link com.jogamp.javafx.newt.macosx.MacWindow MacWindow} implementation.
- * TODO: Some hardcoded dependencies exist in this implementation, - * where you have to patch this code or factor it out.

- * - * If your platform is not Mac OS X, but you want to test your code without modifying - * this class, you have to set the system property newt.MainThread.force to true.

- * - * The code is compatible with all other platform, which support multithreaded windowing handling. - * Since those platforms won't trigger the main thread serialization, the main method - * will be simply executed, in case you haven't set newt.MainThread.force to true.

- * - * Test case on Mac OS X (or any other platform): -

-    java -XstartOnFirstThread com.jogamp.javafx.newt.util.MainThread demos.es1.RedSquare -GL2 -GL2 -GL2 -GL2
- 
- * Which starts 4 threads, each with a window and OpenGL rendering.
- */ -public class MainThread { - private static AccessControlContext localACC = AccessController.getContext(); - public static final boolean USE_MAIN_THREAD = NativeWindowFactory.TYPE_MACOSX.equals(NativeWindowFactory.getNativeWindowType(false)) || - Debug.getBooleanProperty("newt.MainThread.force", true, localACC); - - protected static final boolean DEBUG = Debug.debug("MainThread"); - - private static boolean isExit=false; - private static volatile boolean isRunning=false; - private static Object taskWorkerLock=new Object(); - private static boolean shouldStop; - private static ArrayList tasks; - private static ArrayList tasksBlock; - private static Thread mainThread; - - static class MainAction extends Thread { - private String mainClassName; - private String[] mainClassArgs; - - private Class mainClass; - private Method mainClassMain; - - public MainAction(String mainClassName, String[] mainClassArgs) { - this.mainClassName=mainClassName; - this.mainClassArgs=mainClassArgs; - } - - public void run() { - if ( USE_MAIN_THREAD ) { - // we have to start first to provide the service .. - MainThread.waitUntilRunning(); - } - - // start user app .. - try { - Class mainClass = NWReflection.getClass(mainClassName, true); - if(null==mainClass) { - throw new RuntimeException(new ClassNotFoundException("MainThread couldn't find main class "+mainClassName)); - } - try { - mainClassMain = mainClass.getDeclaredMethod("main", new Class[] { String[].class }); - mainClassMain.setAccessible(true); - } catch (Throwable t) { - throw new RuntimeException(t); - } - if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" invoke "+mainClassName); - mainClassMain.invoke(null, new Object[] { mainClassArgs } ); - } catch (InvocationTargetException ite) { - ite.getTargetException().printStackTrace(); - } catch (Throwable t) { - t.printStackTrace(); - } - - if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" user app fin"); - - if ( USE_MAIN_THREAD ) { - MainThread.exit(); - if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" MainThread fin - exit"); - System.exit(0); - } - } - } - private static MainAction mainAction; - - /** Your new java application main entry, which pipelines your application */ - public static void main(String[] args) { - if(DEBUG) System.err.println("MainThread.main(): "+Thread.currentThread().getName()+" USE_MAIN_THREAD "+ USE_MAIN_THREAD ); - - if(args.length==0) { - return; - } - - String mainClassName=args[0]; - String[] mainClassArgs=new String[args.length-1]; - if(args.length>1) { - System.arraycopy(args, 1, mainClassArgs, 0, args.length-1); - } - - NativeLibLoader.loadNEWT(); - - shouldStop = false; - tasks = new ArrayList(); - tasksBlock = new ArrayList(); - mainThread = Thread.currentThread(); - - mainAction = new MainAction(mainClassName, mainClassArgs); - - if(NativeWindowFactory.TYPE_MACOSX.equals(NativeWindowFactory.getNativeWindowType(false))) { - MacDisplay.initSingleton(); - } - - if ( USE_MAIN_THREAD ) { - // dispatch user's main thread .. - mainAction.start(); - - // do our main thread task scheduling - run(); - } else { - // run user's main in this thread - mainAction.run(); - } - } - - /** invokes the given Runnable */ - public static void invoke(boolean wait, Runnable r) { - if(r == null) { - return; - } - - // if this main thread is not being used or - // if this is already the main thread .. just execute. - if( !isRunning() || mainThread == Thread.currentThread() ) { - r.run(); - return; - } - - synchronized(taskWorkerLock) { - tasks.add(r); - if(wait) { - tasksBlock.add(r); - } - taskWorkerLock.notifyAll(); - if(wait) { - while(tasksBlock.size()>0) { - try { - taskWorkerLock.wait(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - } - } - - public static void exit() { - if(DEBUG) System.err.println("MainThread.exit(): "+Thread.currentThread().getName()+" start"); - synchronized(taskWorkerLock) { - if(isRunning) { - shouldStop = true; - } - taskWorkerLock.notifyAll(); - } - if(DEBUG) System.err.println("MainThread.exit(): "+Thread.currentThread().getName()+" end"); - } - - public static boolean isRunning() { - synchronized(taskWorkerLock) { - return isRunning; - } - } - - private static void waitUntilRunning() { - synchronized(taskWorkerLock) { - if(isExit) return; - - while(!isRunning) { - try { - taskWorkerLock.wait(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - } - - public static void run() { - if(DEBUG) System.err.println("MainThread.run(): "+Thread.currentThread().getName()); - synchronized(taskWorkerLock) { - isRunning = true; - taskWorkerLock.notifyAll(); - } - while(!shouldStop) { - try { - ArrayList localTasks=null; - - // wait for something todo .. - synchronized(taskWorkerLock) { - while(!shouldStop && tasks.size()==0) { - try { - taskWorkerLock.wait(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - // seq. process all tasks until no blocking one exists in the list - for(Iterator i = tasks.iterator(); tasksBlock.size()>0 && i.hasNext(); ) { - Runnable task = (Runnable) i.next(); - task.run(); - i.remove(); - tasksBlock.remove(task); - } - - // take over the tasks .. - if(tasks.size()>0) { - localTasks = tasks; - tasks = new ArrayList(); - } - taskWorkerLock.notifyAll(); - } - - // seq. process all unblocking tasks .. - if(null!=localTasks) { - for(Iterator i = localTasks.iterator(); i.hasNext(); ) { - Runnable task = (Runnable) i.next(); - task.run(); - } - } - } catch (Throwable t) { - // handle errors .. - t.printStackTrace(); - } finally { - // epilog - unlock locked stuff - } - } - if(DEBUG) System.err.println("MainThread.run(): "+Thread.currentThread().getName()+" fin"); - synchronized(taskWorkerLock) { - isRunning = false; - isExit = true; - taskWorkerLock.notifyAll(); - } - } -} - - diff --git a/src/newt/classes/com/jogamp/javafx/newt/windows/WindowsDisplay.java b/src/newt/classes/com/jogamp/javafx/newt/windows/WindowsDisplay.java deleted file mode 100755 index f2e8d21ef..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/windows/WindowsDisplay.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.windows; - -import javax.media.nativewindow.*; -import javax.media.nativewindow.windows.*; -import com.jogamp.javafx.newt.*; -import com.jogamp.javafx.newt.impl.*; - -public class WindowsDisplay extends Display { - - protected static final String WINDOW_CLASS_NAME = "NewtWindowClass"; - private static int windowClassAtom; - private static long hInstance; - - static { - NativeLibLoader.loadNEWT(); - - if (!WindowsWindow.initIDs()) { - throw new NativeWindowException("Failed to initialize WindowsWindow jmethodIDs"); - } - } - - public static void initSingleton() { - // just exist to ensure static init has been run - } - - - public WindowsDisplay() { - } - - protected void createNative() { - aDevice = new WindowsGraphicsDevice(); - } - - protected void closeNative() { - // Can't do .. only at application shutdown - // UnregisterWindowClass(getWindowClassAtom(), getHInstance()); - } - - protected void dispatchMessages() { - DispatchMessages(); - } - - protected static synchronized int getWindowClassAtom() { - if(0 == windowClassAtom) { - windowClassAtom = RegisterWindowClass(WINDOW_CLASS_NAME, getHInstance()); - if (0 == windowClassAtom) { - throw new NativeWindowException("Error while registering window class"); - } - } - return windowClassAtom; - } - - protected static synchronized long getHInstance() { - if(0 == hInstance) { - hInstance = LoadLibraryW("newt"); - if (0 == hInstance) { - throw new NativeWindowException("Error finding HINSTANCE for \"newt\""); - } - } - return hInstance; - } - - //---------------------------------------------------------------------- - // Internals only - // - private static native long LoadLibraryW(String libraryName); - private static native int RegisterWindowClass(String windowClassName, long hInstance); - private static native void UnregisterWindowClass(int wndClassAtom, long hInstance); - - private static native void DispatchMessages(); -} - diff --git a/src/newt/classes/com/jogamp/javafx/newt/windows/WindowsScreen.java b/src/newt/classes/com/jogamp/javafx/newt/windows/WindowsScreen.java deleted file mode 100755 index ab11f97dd..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/windows/WindowsScreen.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.windows; - -import com.jogamp.javafx.newt.*; -import com.jogamp.javafx.newt.impl.*; -import javax.media.nativewindow.*; - -public class WindowsScreen extends Screen { - static { - WindowsDisplay.initSingleton(); - } - - - public WindowsScreen() { - } - - protected void createNative(int index) { - aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); - setScreenSize(getWidthImpl(getIndex()), getHeightImpl(getIndex())); - } - - protected void closeNative() { } - - private native int getWidthImpl(int scrn_idx); - private native int getHeightImpl(int scrn_idx); -} diff --git a/src/newt/classes/com/jogamp/javafx/newt/windows/WindowsWindow.java b/src/newt/classes/com/jogamp/javafx/newt/windows/WindowsWindow.java deleted file mode 100755 index 7c8864190..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/windows/WindowsWindow.java +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.windows; - -import javax.media.nativewindow.*; -import com.jogamp.javafx.newt.*; - -public class WindowsWindow extends Window { - - private long hmon; - private long hdc; - private long windowHandleClose; - private long parentWindowHandle; - // non fullscreen dimensions .. - private int nfs_width, nfs_height, nfs_x, nfs_y; - private final Insets insets = new Insets(0, 0, 0, 0); - - static { - WindowsDisplay.initSingleton(); - } - - public WindowsWindow() { - } - - Thread hdcOwner = null; - - public synchronized int lockSurface() throws NativeWindowException { - int res = super.lockSurface(); - if(LOCK_SUCCESS==res && 0!=windowHandle) { - if(hdc!=0) { - throw new NativeWindowException("NEWT Surface handle set HDC "+toHexString(hdc)+" - "+Thread.currentThread().getName()+" ; "+this); - } - hdc = GetDC(windowHandle); - hmon = MonitorFromWindow(windowHandle); - hdcOwner = Thread.currentThread(); - } - return res; - } - - public synchronized void unlockSurface() { - // prevalidate, before we change data .. - Thread cur = Thread.currentThread(); - if ( getSurfaceLockOwner() != cur ) { - getLockedStack().printStackTrace(); - throw new NativeWindowException(cur+": Not owner, owner is "+getSurfaceLockOwner()); - } - if (0!=hdc && 0!=windowHandle) { - if(hdcOwner != cur) { - throw new NativeWindowException("NEWT Surface handle set HDC "+toHexString(hdc)+" by other thread "+hdcOwner+", this "+cur+" ; "+this); - } - ReleaseDC(windowHandle, hdc); - hdc=0; - hdcOwner=null; - } - super.unlockSurface(); - } - - public long getSurfaceHandle() { - return hdc; - } - - public boolean hasDeviceChanged() { - if(0!=windowHandle) { - long _hmon = MonitorFromWindow(windowHandle); - if (hmon != _hmon) { - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - Exception e = new Exception("!!! Window Device Changed "+Thread.currentThread().getName()+ - ", HMON "+toHexString(hmon)+" -> "+toHexString(_hmon)); - e.printStackTrace(); - } - hmon = _hmon; - return true; - } - } - return false; - } - - protected void createNative(long parentWindowHandle, Capabilities caps) { - WindowsScreen screen = (WindowsScreen) getScreen(); - WindowsDisplay display = (WindowsDisplay) screen.getDisplay(); - config = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, screen.getGraphicsScreen()); - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - windowHandle = CreateWindow(parentWindowHandle, - display.getWindowClassAtom(), display.WINDOW_CLASS_NAME, display.getHInstance(), - 0, undecorated, x, y, width, height); - if (windowHandle == 0) { - throw new NativeWindowException("Error creating window"); - } - this.parentWindowHandle = parentWindowHandle; - windowHandleClose = windowHandle; - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - Exception e = new Exception("!!! Window new window handle "+Thread.currentThread().getName()+ - " (Parent HWND "+toHexString(parentWindowHandle)+ - ") : HWND "+toHexString(windowHandle)+", "+Thread.currentThread()); - e.printStackTrace(); - } - } - - protected void closeNative() { - if (hdc != 0) { - if(windowHandleClose != 0) { - ReleaseDC(windowHandleClose, hdc); - } - hdc = 0; - } - if(windowHandleClose != 0) { - DestroyWindow(windowHandleClose); - windowHandleClose = 0; - } - } - - protected void windowDestroyed() { - windowHandleClose = 0; - super.windowDestroyed(); - } - - public void setVisible(boolean visible) { - if(this.visible!=visible && 0!=windowHandle) { - this.visible=visible; - setVisible0(windowHandle, visible); - } - } - - // @Override - public void setSize(int width, int height) { - if (0!=windowHandle && (width != this.width || this.height != height)) { - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - this.width = width; - this.height = height; - setSize0(parentWindowHandle, windowHandle, x, y, width, height); - } - } - - //@Override - public void setPosition(int x, int y) { - if (0!=windowHandle && (this.x != x || this.y != y)) { - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - this.x = x; - this.y = y; - setPosition(parentWindowHandle, windowHandle, x , y); - } - } - - public boolean setFullscreen(boolean fullscreen) { - if(0!=windowHandle && (this.fullscreen!=fullscreen)) { - int x,y,w,h; - this.fullscreen=fullscreen; - if(fullscreen) { - x = 0; y = 0; - w = screen.getWidth(); - h = screen.getHeight(); - } else { - x = nfs_x; - y = nfs_y; - w = nfs_width; - h = nfs_height; - } - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("WindowsWindow fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); - } - setFullscreen0(parentWindowHandle, windowHandle, x, y, w, h, undecorated, fullscreen); - } - return fullscreen; - } - - // @Override - public void requestFocus() { - super.requestFocus(); - if (windowHandle != 0L) { - requestFocus(windowHandle); - } - } - - // @Override - public void setTitle(String title) { - if (title == null) { - title = ""; - } - if (0!=windowHandle && !title.equals(getTitle())) { - super.setTitle(title); - setTitle(windowHandle, title); - } - } - - public Insets getInsets() { - return (Insets)insets.clone(); - } - - //---------------------------------------------------------------------- - // Internals only - // - protected static native boolean initIDs(); - private native long CreateWindow(long parentWindowHandle, - int wndClassAtom, String wndName, - long hInstance, long visualID, - boolean isUndecorated, - int x, int y, int width, int height); - private native void DestroyWindow(long windowHandle); - private native long GetDC(long windowHandle); - private native void ReleaseDC(long windowHandle, long hdc); - private native long MonitorFromWindow(long windowHandle); - private static native void setVisible0(long windowHandle, boolean visible); - private native void setSize0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height); - private native void setPosition(long parentWindowHandle, long windowHandle, int x, int y); - private native void setFullscreen0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height, boolean isUndecorated, boolean on); - private static native void setTitle(long windowHandle, String title); - private static native void requestFocus(long windowHandle); - - private void insetsChanged(int left, int top, int right, int bottom) { - if (left != -1 && top != -1 && right != -1 && bottom != -1) { - insets.left = left; - insets.top = top; - insets.right = right; - insets.bottom = bottom; - } - } - private void sizeChanged(int newWidth, int newHeight) { - width = newWidth; - height = newHeight; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); - } - - private void positionChanged(int newX, int newY) { - x = newX; - y = newY; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); - } - - /** - * - * @param focusOwner if focusGained is true, focusOwner is the previous - * focus owner, if focusGained is false, focusOwner is the new focus owner - * @param focusGained - */ - private void focusChanged(long focusOwner, boolean focusGained) { - if (focusGained) { - sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); - } else { - sendWindowEvent(WindowEvent.EVENT_WINDOW_LOST_FOCUS); - } - } -} diff --git a/src/newt/classes/com/jogamp/javafx/newt/x11/X11Display.java b/src/newt/classes/com/jogamp/javafx/newt/x11/X11Display.java deleted file mode 100755 index 96d55c082..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/x11/X11Display.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.x11; - -import javax.media.nativewindow.*; -import javax.media.nativewindow.x11.*; -import com.jogamp.javafx.newt.*; -import com.jogamp.javafx.newt.impl.*; -import com.jogamp.nativewindow.impl.x11.X11Util; - -public class X11Display extends Display { - static { - NativeLibLoader.loadNEWT(); - - if (!initIDs()) { - throw new NativeWindowException("Failed to initialize X11Display jmethodIDs"); - } - - if (!X11Window.initIDs()) { - throw new NativeWindowException("Failed to initialize X11Window jmethodIDs"); - } - } - - public static void initSingleton() { - // just exist to ensure static init has been run - } - - - public X11Display() { - } - - protected void createNative() { - long handle= X11Util.getThreadLocalDisplay(name); - if (handle == 0 ) { - throw new RuntimeException("Error creating display: "+name); - } - try { - CompleteDisplay(handle); - } catch(RuntimeException e) { - X11Util.closeThreadLocalDisplay(name); - throw e; - } - aDevice = new X11GraphicsDevice(handle); - } - - protected void closeNative() { - if(0==X11Util.closeThreadLocalDisplay(name)) { - throw new NativeWindowException(this+" was not mapped"); - } - } - - protected void dispatchMessages() { - DispatchMessages(getHandle(), javaObjectAtom, windowDeleteAtom); - } - - protected void lockDisplay() { - super.lockDisplay(); - LockDisplay(getHandle()); - } - - protected void unlockDisplay() { - UnlockDisplay(getHandle()); - super.unlockDisplay(); - } - - protected long getJavaObjectAtom() { return javaObjectAtom; } - protected long getWindowDeleteAtom() { return windowDeleteAtom; } - - //---------------------------------------------------------------------- - // Internals only - // - private static native boolean initIDs(); - - private native void LockDisplay(long handle); - private native void UnlockDisplay(long handle); - - private native void CompleteDisplay(long handle); - - private native void DispatchMessages(long display, long javaObjectAtom, long windowDeleteAtom); - - private void displayCompleted(long javaObjectAtom, long windowDeleteAtom) { - this.javaObjectAtom=javaObjectAtom; - this.windowDeleteAtom=windowDeleteAtom; - } - - private long windowDeleteAtom; - private long javaObjectAtom; -} - diff --git a/src/newt/classes/com/jogamp/javafx/newt/x11/X11Screen.java b/src/newt/classes/com/jogamp/javafx/newt/x11/X11Screen.java deleted file mode 100755 index d90b1868d..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/x11/X11Screen.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.x11; - -import com.jogamp.javafx.newt.*; -import com.jogamp.javafx.newt.impl.*; -import javax.media.nativewindow.*; -import javax.media.nativewindow.x11.*; - -public class X11Screen extends Screen { - - static { - X11Display.initSingleton(); - } - - - public X11Screen() { - } - - protected void createNative(int index) { - long handle = GetScreen(display.getHandle(), index); - if (handle == 0 ) { - throw new RuntimeException("Error creating screen: "+index); - } - aScreen = new X11GraphicsScreen((X11GraphicsDevice)getDisplay().getGraphicsDevice(), index); - setScreenSize(getWidth0(display.getHandle(), index), - getHeight0(display.getHandle(), index)); - } - - protected void closeNative() { } - - //---------------------------------------------------------------------- - // Internals only - // - - private native long GetScreen(long dpy, int scrn_idx); - private native int getWidth0(long display, int scrn_idx); - private native int getHeight0(long display, int scrn_idx); -} - diff --git a/src/newt/classes/com/jogamp/javafx/newt/x11/X11Window.java b/src/newt/classes/com/jogamp/javafx/newt/x11/X11Window.java deleted file mode 100755 index 8387160c9..000000000 --- a/src/newt/classes/com/jogamp/javafx/newt/x11/X11Window.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. 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. - * - */ - -package com.jogamp.javafx.newt.x11; - -import com.jogamp.javafx.newt.*; -import com.jogamp.javafx.newt.impl.*; -import javax.media.nativewindow.*; -import javax.media.nativewindow.x11.*; - -public class X11Window extends Window { - private static final String WINDOW_CLASS_NAME = "NewtWindow"; - // non fullscreen dimensions .. - private int nfs_width, nfs_height, nfs_x, nfs_y; - - static { - X11Display.initSingleton(); - } - - public X11Window() { - } - - protected void createNative(long parentWindowHandle, Capabilities caps) { - X11Screen screen = (X11Screen) getScreen(); - X11Display display = (X11Display) screen.getDisplay(); - config = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, screen.getGraphicsScreen()); - if (config == null) { - throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); - } - X11GraphicsConfiguration x11config = (X11GraphicsConfiguration) config; - long visualID = x11config.getVisualID(); - long w = CreateWindow(parentWindowHandle, - display.getHandle(), screen.getIndex(), visualID, - display.getJavaObjectAtom(), display.getWindowDeleteAtom(), x, y, width, height); - if (w == 0 || w!=windowHandle) { - throw new NativeWindowException("Error creating window: "+w); - } - this.parentWindowHandle = parentWindowHandle; - windowHandleClose = windowHandle; - displayHandleClose = display.getHandle(); - } - - protected void closeNative() { - if(0!=displayHandleClose && 0!=windowHandleClose && null!=getScreen() ) { - X11Display display = (X11Display) getScreen().getDisplay(); - CloseWindow(displayHandleClose, windowHandleClose, display.getJavaObjectAtom()); - windowHandleClose = 0; - displayHandleClose = 0; - } - } - - protected void windowDestroyed() { - windowHandleClose = 0; - displayHandleClose = 0; - super.windowDestroyed(); - } - - public void setVisible(boolean visible) { - if(0!=windowHandle && this.visible!=visible) { - this.visible=visible; - setVisible0(getDisplayHandle(), windowHandle, visible); - clearEventMask(); - } - } - - public void requestFocus() { - super.requestFocus(); - } - - public void setSize(int width, int height) { - if(DEBUG_IMPLEMENTATION) { - System.err.println("X11Window setSize: "+this.x+"/"+this.y+" "+this.width+"x"+this.height+" -> "+width+"x"+height); - // Exception e = new Exception("XXXXXXXXXX"); - // e.printStackTrace(); - } - this.width = width; - this.height = height; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - if(0!=windowHandle) { - setSize0(parentWindowHandle, getDisplayHandle(), getScreenIndex(), windowHandle, x, y, width, height, (undecorated||fullscreen)?-1:1, false); - } - } - - public void setPosition(int x, int y) { - if(DEBUG_IMPLEMENTATION) { - System.err.println("X11Window setPosition: "+this.x+"/"+this.y+" -> "+x+"/"+y); - // Exception e = new Exception("XXXXXXXXXX"); - // e.printStackTrace(); - } - this.x = x; - this.y = y; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - if(0!=windowHandle) { - setPosition0(getDisplayHandle(), windowHandle, x, y); - } - } - - public boolean setFullscreen(boolean fullscreen) { - if(0!=windowHandle && this.fullscreen!=fullscreen) { - int x,y,w,h; - this.fullscreen=fullscreen; - if(fullscreen) { - x = 0; y = 0; - w = screen.getWidth(); - h = screen.getHeight(); - } else { - x = nfs_x; - y = nfs_y; - w = nfs_width; - h = nfs_height; - } - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("X11Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); - } - setSize0(parentWindowHandle, getDisplayHandle(), getScreenIndex(), windowHandle, x, y, w, h, (undecorated||fullscreen)?-1:1, false); - } - return fullscreen; - } - - //---------------------------------------------------------------------- - // Internals only - // - - protected static native boolean initIDs(); - private native long CreateWindow(long parentWindowHandle, long display, int screen_index, - long visualID, long javaObjectAtom, long windowDeleteAtom, int x, int y, int width, int height); - private native void CloseWindow(long display, long windowHandle, long javaObjectAtom); - private native void setVisible0(long display, long windowHandle, boolean visible); - private native void setSize0(long parentWindowHandle, long display, int screen_index, long windowHandle, - int x, int y, int width, int height, int decorationToggle, boolean setVisible); - private native void setPosition0(long display, long windowHandle, int x, int y); - - private void windowChanged(int newX, int newY, int newWidth, int newHeight) { - if(width != newWidth || height != newHeight) { - if(DEBUG_IMPLEMENTATION) { - System.err.println("X11Window windowChanged size: "+this.width+"x"+this.height+" -> "+newWidth+"x"+newHeight); - } - width = newWidth; - height = newHeight; - if(!fullscreen) { - nfs_width=width; - nfs_height=height; - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); - } - if( 0==parentWindowHandle && ( x != newX || y != newY ) ) { - if(DEBUG_IMPLEMENTATION) { - System.err.println("X11Window windowChanged position: "+this.x+"/"+this.y+" -> "+newX+"x"+newY); - } - x = newX; - y = newY; - if(!fullscreen) { - nfs_x=x; - nfs_y=y; - } - sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); - } - } - - private void windowCreated(long windowHandle) { - this.windowHandle = windowHandle; - } - - private long windowHandleClose; - private long displayHandleClose; - private long parentWindowHandle; -} diff --git a/src/newt/classes/com/jogamp/newt/Display.java b/src/newt/classes/com/jogamp/newt/Display.java new file mode 100755 index 000000000..88f6dd34b --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/Display.java @@ -0,0 +1,276 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt; + +import javax.media.nativewindow.*; +import com.jogamp.newt.impl.Debug; +import com.jogamp.newt.util.EventDispatchThread; +import java.util.*; + +public abstract class Display { + public static final boolean DEBUG = Debug.debug("Display"); + + private static Class getDisplayClass(String type) + throws ClassNotFoundException + { + Class displayClass = NewtFactory.getCustomClass(type, "Display"); + if(null==displayClass) { + if (NativeWindowFactory.TYPE_EGL.equals(type)) { + displayClass = Class.forName("com.jogamp.newt.opengl.kd.KDDisplay"); + } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) { + displayClass = Class.forName("com.jogamp.newt.windows.WindowsDisplay"); + } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { + displayClass = Class.forName("com.jogamp.newt.macosx.MacDisplay"); + } else if (NativeWindowFactory.TYPE_X11.equals(type)) { + displayClass = Class.forName("com.jogamp.newt.x11.X11Display"); + } else if (NativeWindowFactory.TYPE_AWT.equals(type)) { + displayClass = Class.forName("com.jogamp.newt.awt.AWTDisplay"); + } else { + throw new RuntimeException("Unknown display type \"" + type + "\""); + } + } + return displayClass; + } + + // Unique Display for each thread + private static ThreadLocal currentDisplayMap = new ThreadLocal(); + + /** Returns the thread local display map */ + public static Map getCurrentDisplayMap() { + Map displayMap = (Map) currentDisplayMap.get(); + if(null==displayMap) { + displayMap = new HashMap(); + currentDisplayMap.set( displayMap ); + } + return displayMap; + } + + /** maps the given display to the thread local display map + * and notifies all threads synchronized to this display map. */ + protected static Display setCurrentDisplay(Display display) { + Map displayMap = getCurrentDisplayMap(); + Display oldDisplay = null; + synchronized(displayMap) { + String name = display.getName(); + if(null==name) name="nil"; + oldDisplay = (Display) displayMap.put(name, display); + displayMap.notifyAll(); + } + return oldDisplay; + } + + /** removes the mapping of the given name from the thread local display map + * and notifies all threads synchronized to this display map. */ + protected static Display removeCurrentDisplay(String name) { + if(null==name) name="nil"; + Map displayMap = getCurrentDisplayMap(); + Display oldDisplay = null; + synchronized(displayMap) { + oldDisplay = (Display) displayMap.remove(name); + displayMap.notifyAll(); + } + return oldDisplay; + } + + /** Returns the thread local display mapped to the given name */ + public static Display getCurrentDisplay(String name) { + if(null==name) name="nil"; + Map displayMap = getCurrentDisplayMap(); + Display display = (Display) displayMap.get(name); + return display; + } + + public static void dumpDisplayMap(String prefix) { + Map displayMap = getCurrentDisplayMap(); + Set entrySet = displayMap.entrySet(); + Iterator i = entrySet.iterator(); + System.err.println(prefix+" DisplayMap["+entrySet.size()+"] "+Thread.currentThread()); + for(int j=0; i.hasNext(); j++) { + Map.Entry entry = (Map.Entry) i.next(); + System.err.println(" ["+j+"] "+entry.getKey()+" -> "+entry.getValue()); + } + } + + /** Returns the thread local display collection */ + public static Collection getCurrentDisplays() { + return getCurrentDisplayMap().values(); + } + + /** Make sure to reuse a Display with the same name */ + protected static Display create(String type, String name) { + try { + if(DEBUG) { + dumpDisplayMap("Display.create("+name+") BEGIN"); + } + Display display = getCurrentDisplay(name); + if(null==display) { + Class displayClass = getDisplayClass(type); + display = (Display) displayClass.newInstance(); + display.name=name; + display.refCount=1; + + if(NewtFactory.useEDT()) { + Thread current = Thread.currentThread(); + display.eventDispatchThread = new EventDispatchThread(display, current.getThreadGroup(), current.getName()); + display.eventDispatchThread.start(); + final Display f_dpy = display; + display.eventDispatchThread.invokeAndWait(new Runnable() { + public void run() { + f_dpy.createNative(); + } + } ); + } else { + display.createNative(); + } + if(null==display.aDevice) { + throw new RuntimeException("Display.createNative() failed to instanciate an AbstractGraphicsDevice"); + } + setCurrentDisplay(display); + if(DEBUG) { + System.err.println("Display.create("+name+") NEW: "+display+" "+Thread.currentThread()); + } + } else { + synchronized(display) { + display.refCount++; + if(DEBUG) { + System.err.println("Display.create("+name+") REUSE: refCount "+display.refCount+", "+display+" "+Thread.currentThread()); + } + } + } + if(DEBUG) { + dumpDisplayMap("Display.create("+name+") END"); + } + return display; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected static Display wrapHandle(String type, String name, AbstractGraphicsDevice aDevice) { + try { + Class displayClass = getDisplayClass(type); + Display display = (Display) displayClass.newInstance(); + display.name=name; + display.aDevice=aDevice; + return display; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public EventDispatchThread getEDT() { return eventDispatchThread; } + + public synchronized void destroy() { + if(DEBUG) { + dumpDisplayMap("Display.destroy("+name+") BEGIN"); + } + refCount--; + if(0==refCount) { + removeCurrentDisplay(name); + if(DEBUG) { + System.err.println("Display.destroy("+name+") REMOVE: "+this+" "+Thread.currentThread()); + } + if(null!=eventDispatchThread) { + final Display f_dpy = this; + final EventDispatchThread f_edt = eventDispatchThread; + eventDispatchThread.invokeAndWait(new Runnable() { + public void run() { + f_dpy.closeNative(); + f_edt.stop(); + } + } ); + } else { + closeNative(); + } + if(null!=eventDispatchThread) { + eventDispatchThread.waitUntilStopped(); + eventDispatchThread=null; + } + aDevice = null; + } else { + if(DEBUG) { + System.err.println("Display.destroy("+name+") KEEP: refCount "+refCount+", "+this+" "+Thread.currentThread()); + } + } + if(DEBUG) { + dumpDisplayMap("Display.destroy("+name+") END"); + } + } + + protected abstract void createNative(); + protected abstract void closeNative(); + + public String getName() { + return name; + } + + public long getHandle() { + if(null!=aDevice) { + return aDevice.getHandle(); + } + return 0; + } + + public AbstractGraphicsDevice getGraphicsDevice() { + return aDevice; + } + + public void pumpMessages() { + if(null!=eventDispatchThread) { + dispatchMessages(); + } else { + synchronized(this) { + dispatchMessages(); + } + } + } + + public String toString() { + return "NEWT-Display["+name+", refCount "+refCount+", "+aDevice+"]"; + } + + protected abstract void dispatchMessages(); + + /** Default impl. nop - Currently only X11 needs a Display lock */ + protected void lockDisplay() { } + + /** Default impl. nop - Currently only X11 needs a Display lock */ + protected void unlockDisplay() { } + + protected EventDispatchThread eventDispatchThread = null; + protected String name; + protected int refCount; + protected AbstractGraphicsDevice aDevice; +} + diff --git a/src/newt/classes/com/jogamp/newt/Event.java b/src/newt/classes/com/jogamp/newt/Event.java new file mode 100644 index 000000000..d42a95735 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/Event.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt; + +public class Event { + private boolean isSystemEvent; + private int eventType; + private Window source; + private long when; + + Event(boolean isSystemEvent, int eventType, Window source, long when) { + this.isSystemEvent = isSystemEvent; + this.eventType = eventType; + this.source = source; + this.when = when; + } + + protected Event(int eventType, Window source, long when) { + this(false, eventType, source, when); + } + + /** Indicates whether this event was produced by the system or + generated by user code. */ + public final boolean isSystemEvent() { + return isSystemEvent; + } + + /** Returns the event type of this event. */ + public final int getEventType() { + return eventType; + } + + /** Returns the source Window which produced this Event. */ + public final Window getSource() { + return source; + } + + /** Returns the timestamp, in milliseconds, of this event. */ + public final long getWhen() { + return when; + } + + public String toString() { + return "Event[sys:"+isSystemEvent()+", source:"+getSource()+", when:"+getWhen()+"]"; + } + + public static String toHexString(int hex) { + return "0x" + Integer.toHexString(hex); + } + + public static String toHexString(long hex) { + return "0x" + Long.toHexString(hex); + } + +} diff --git a/src/newt/classes/com/jogamp/newt/EventListener.java b/src/newt/classes/com/jogamp/newt/EventListener.java new file mode 100644 index 000000000..75cb487dd --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/EventListener.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt; + +public interface EventListener +{ + public static final int WINDOW = 1 << 0; + public static final int MOUSE = 1 << 1; + public static final int KEY = 1 << 2; + public static final int SURFACE = 1 << 3; + +} + diff --git a/src/newt/classes/com/jogamp/newt/InputEvent.java b/src/newt/classes/com/jogamp/newt/InputEvent.java new file mode 100644 index 000000000..d4c3f6905 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/InputEvent.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt; + +public abstract class InputEvent extends Event +{ + public static final int SHIFT_MASK = 1 << 0; + public static final int CTRL_MASK = 1 << 1; + public static final int META_MASK = 1 << 2; + public static final int ALT_MASK = 1 << 3; + public static final int ALT_GRAPH_MASK = 1 << 5; + public static final int BUTTON1_MASK = 1 << 6; + public static final int BUTTON2_MASK = 1 << 7; + public static final int BUTTON3_MASK = 1 << 8; + + protected InputEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers) { + super(sysEvent, eventType, source, when); + this.consumed=false; + this.modifiers=modifiers; + } + + public void consume() { + consumed=true; + } + + public boolean isConsumed() { + return consumed; + } + public int getModifiers() { + return modifiers; + } + public boolean isAltDown() { + return (modifiers&ALT_MASK)!=0; + } + public boolean isAltGraphDown() { + return (modifiers&ALT_GRAPH_MASK)!=0; + } + public boolean isControlDown() { + return (modifiers&CTRL_MASK)!=0; + } + public boolean isMetaDown() { + return (modifiers&META_MASK)!=0; + } + public boolean isShiftDown() { + return (modifiers&SHIFT_MASK)!=0; + } + + public boolean isButton1Down() { + return (modifiers&BUTTON1_MASK)!=0; + } + + public boolean isButton2Down() { + return (modifiers&BUTTON2_MASK)!=0; + } + + public boolean isButton3Down() { + return (modifiers&BUTTON3_MASK)!=0; + } + + public String toString() { + return "InputEvent[modifiers:"+modifiers+"]"; + } + + private boolean consumed; + private int modifiers; +} diff --git a/src/newt/classes/com/jogamp/newt/Insets.java b/src/newt/classes/com/jogamp/newt/Insets.java new file mode 100644 index 000000000..e440892f0 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/Insets.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. 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. + * + */ +package com.jogamp.newt; + +/** + * Simple class representing insets. + * + * @author tdv + */ +public class Insets implements Cloneable { + public int top; + public int left; + public int bottom; + public int right; + + /** + * Creates and initializes a new Insets object with the + * specified top, left, bottom, and right insets. + * @param top the inset from the top. + * @param left the inset from the left. + * @param bottom the inset from the bottom. + * @param right the inset from the right. + */ + public Insets(int top, int left, int bottom, int right) { + this.top = top; + this.left = left; + this.bottom = bottom; + this.right = right; + } + + /** + * Checks whether two insets objects are equal. Two instances + * of Insets are equal if the four integer values + * of the fields top, left, + * bottom, and right are all equal. + * @return true if the two insets are equal; + * otherwise false. + */ + public boolean equals(Object obj) { + if (obj instanceof Insets) { + Insets insets = (Insets)obj; + return ((top == insets.top) && (left == insets.left) && + (bottom == insets.bottom) && (right == insets.right)); + } + return false; + } + + /** + * Returns the hash code for this Insets. + * + * @return a hash code for this Insets. + */ + public int hashCode() { + int sum1 = left + bottom; + int sum2 = right + top; + int val1 = sum1 * (sum1 + 1)/2 + left; + int val2 = sum2 * (sum2 + 1)/2 + top; + int sum3 = val1 + val2; + return sum3 * (sum3 + 1)/2 + val2; + } + + public String toString() { + return getClass().getName() + "[top=" + top + ",left=" + left + + ",bottom=" + bottom + ",right=" + right + "]"; + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException ex) { + throw new InternalError(); + } + } + +} diff --git a/src/newt/classes/com/jogamp/newt/KeyEvent.java b/src/newt/classes/com/jogamp/newt/KeyEvent.java new file mode 100644 index 000000000..bec77160b --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/KeyEvent.java @@ -0,0 +1,738 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt; + +public class KeyEvent extends InputEvent +{ + KeyEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers, int keyCode, char keyChar) { + super(sysEvent, eventType, source, when, modifiers); + this.keyCode=keyCode; + this.keyChar=keyChar; + } + public KeyEvent(int eventType, Window source, long when, int modifiers, int keyCode, char keyChar) { + this(false, eventType, source, when, modifiers, keyCode, keyChar); + } + + public char getKeyChar() { + return keyChar; + } + public int getKeyCode() { + return keyCode; + } + + public String toString() { + return "KeyEvent["+getEventTypeString(getEventType())+ + ", code "+keyCode+"("+toHexString(keyCode)+"), char <"+keyChar+"> ("+toHexString((int)keyChar)+"), isActionKey "+isActionKey()+", "+super.toString()+"]"; + } + + public static String getEventTypeString(int type) { + switch(type) { + case EVENT_KEY_PRESSED: return "EVENT_KEY_PRESSED"; + case EVENT_KEY_RELEASED: return "EVENT_KEY_RELEASED"; + case EVENT_KEY_TYPED: return "EVENT_KEY_TYPED"; + default: return "unknown (" + type + ")"; + } + } + + public boolean isActionKey() { + switch (keyCode) { + case VK_HOME: + case VK_END: + case VK_PAGE_UP: + case VK_PAGE_DOWN: + case VK_UP: + case VK_DOWN: + case VK_LEFT: + case VK_RIGHT: + + case VK_F1: + case VK_F2: + case VK_F3: + case VK_F4: + case VK_F5: + case VK_F6: + case VK_F7: + case VK_F8: + case VK_F9: + case VK_F10: + case VK_F11: + case VK_F12: + case VK_F13: + case VK_F14: + case VK_F15: + case VK_F16: + case VK_F17: + case VK_F18: + case VK_F19: + case VK_F20: + case VK_F21: + case VK_F22: + case VK_F23: + case VK_F24: + case VK_PRINTSCREEN: + case VK_CAPS_LOCK: + case VK_PAUSE: + case VK_INSERT: + + case VK_HELP: + case VK_WINDOWS: + return true; + } + return false; + } + + private int keyCode; + private char keyChar; + + public static final int EVENT_KEY_PRESSED = 300; + public static final int EVENT_KEY_RELEASED= 301; + public static final int EVENT_KEY_TYPED = 302; + + /* Virtual key codes. */ + + public static final int VK_ENTER = '\n'; + public static final int VK_BACK_SPACE = '\b'; + public static final int VK_TAB = '\t'; + public static final int VK_CANCEL = 0x03; + public static final int VK_CLEAR = 0x0C; + public static final int VK_SHIFT = 0x10; + public static final int VK_CONTROL = 0x11; + public static final int VK_ALT = 0x12; + public static final int VK_PAUSE = 0x13; + public static final int VK_CAPS_LOCK = 0x14; + public static final int VK_ESCAPE = 0x1B; + public static final int VK_SPACE = 0x20; + public static final int VK_PAGE_UP = 0x21; + public static final int VK_PAGE_DOWN = 0x22; + public static final int VK_END = 0x23; + public static final int VK_HOME = 0x24; + + /** + * Constant for the non-numpad left arrow key. + * @see #VK_KP_LEFT + */ + public static final int VK_LEFT = 0x25; + + /** + * Constant for the non-numpad up arrow key. + * @see #VK_KP_UP + */ + public static final int VK_UP = 0x26; + + /** + * Constant for the non-numpad right arrow key. + * @see #VK_KP_RIGHT + */ + public static final int VK_RIGHT = 0x27; + + /** + * Constant for the non-numpad down arrow key. + * @see #VK_KP_DOWN + */ + public static final int VK_DOWN = 0x28; + + /** + * Constant for the comma key, "," + */ + public static final int VK_COMMA = 0x2C; + + /** + * Constant for the minus key, "-" + * @since 1.2 + */ + public static final int VK_MINUS = 0x2D; + + /** + * Constant for the period key, "." + */ + public static final int VK_PERIOD = 0x2E; + + /** + * Constant for the forward slash key, "/" + */ + public static final int VK_SLASH = 0x2F; + + /** VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */ + public static final int VK_0 = 0x30; + public static final int VK_1 = 0x31; + public static final int VK_2 = 0x32; + public static final int VK_3 = 0x33; + public static final int VK_4 = 0x34; + public static final int VK_5 = 0x35; + public static final int VK_6 = 0x36; + public static final int VK_7 = 0x37; + public static final int VK_8 = 0x38; + public static final int VK_9 = 0x39; + + /** + * Constant for the semicolon key, ";" + */ + public static final int VK_SEMICOLON = 0x3B; + + /** + * Constant for the equals key, "=" + */ + public static final int VK_EQUALS = 0x3D; + + /** VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */ + public static final int VK_A = 0x41; + public static final int VK_B = 0x42; + public static final int VK_C = 0x43; + public static final int VK_D = 0x44; + public static final int VK_E = 0x45; + public static final int VK_F = 0x46; + public static final int VK_G = 0x47; + public static final int VK_H = 0x48; + public static final int VK_I = 0x49; + public static final int VK_J = 0x4A; + public static final int VK_K = 0x4B; + public static final int VK_L = 0x4C; + public static final int VK_M = 0x4D; + public static final int VK_N = 0x4E; + public static final int VK_O = 0x4F; + public static final int VK_P = 0x50; + public static final int VK_Q = 0x51; + public static final int VK_R = 0x52; + public static final int VK_S = 0x53; + public static final int VK_T = 0x54; + public static final int VK_U = 0x55; + public static final int VK_V = 0x56; + public static final int VK_W = 0x57; + public static final int VK_X = 0x58; + public static final int VK_Y = 0x59; + public static final int VK_Z = 0x5A; + + /** + * Constant for the open bracket key, "[" + */ + public static final int VK_OPEN_BRACKET = 0x5B; + + /** + * Constant for the back slash key, "\" + */ + public static final int VK_BACK_SLASH = 0x5C; + + /** + * Constant for the close bracket key, "]" + */ + public static final int VK_CLOSE_BRACKET = 0x5D; + + public static final int VK_NUMPAD0 = 0x60; + public static final int VK_NUMPAD1 = 0x61; + public static final int VK_NUMPAD2 = 0x62; + public static final int VK_NUMPAD3 = 0x63; + public static final int VK_NUMPAD4 = 0x64; + public static final int VK_NUMPAD5 = 0x65; + public static final int VK_NUMPAD6 = 0x66; + public static final int VK_NUMPAD7 = 0x67; + public static final int VK_NUMPAD8 = 0x68; + public static final int VK_NUMPAD9 = 0x69; + public static final int VK_MULTIPLY = 0x6A; + public static final int VK_ADD = 0x6B; + + /** + * This constant is obsolete, and is included only for backwards + * compatibility. + * @see #VK_SEPARATOR + */ + public static final int VK_SEPARATER = 0x6C; + + /** + * Constant for the Numpad Separator key. + * @since 1.4 + */ + public static final int VK_SEPARATOR = VK_SEPARATER; + + public static final int VK_SUBTRACT = 0x6D; + public static final int VK_DECIMAL = 0x6E; + public static final int VK_DIVIDE = 0x6F; + public static final int VK_DELETE = 0x7F; /* ASCII DEL */ + public static final int VK_NUM_LOCK = 0x90; + public static final int VK_SCROLL_LOCK = 0x91; + + /** Constant for the F1 function key. */ + public static final int VK_F1 = 0x70; + + /** Constant for the F2 function key. */ + public static final int VK_F2 = 0x71; + + /** Constant for the F3 function key. */ + public static final int VK_F3 = 0x72; + + /** Constant for the F4 function key. */ + public static final int VK_F4 = 0x73; + + /** Constant for the F5 function key. */ + public static final int VK_F5 = 0x74; + + /** Constant for the F6 function key. */ + public static final int VK_F6 = 0x75; + + /** Constant for the F7 function key. */ + public static final int VK_F7 = 0x76; + + /** Constant for the F8 function key. */ + public static final int VK_F8 = 0x77; + + /** Constant for the F9 function key. */ + public static final int VK_F9 = 0x78; + + /** Constant for the F10 function key. */ + public static final int VK_F10 = 0x79; + + /** Constant for the F11 function key. */ + public static final int VK_F11 = 0x7A; + + /** Constant for the F12 function key. */ + public static final int VK_F12 = 0x7B; + + /** + * Constant for the F13 function key. + * @since 1.2 + */ + /* F13 - F24 are used on IBM 3270 keyboard; use random range for constants. */ + public static final int VK_F13 = 0xF000; + + /** + * Constant for the F14 function key. + * @since 1.2 + */ + public static final int VK_F14 = 0xF001; + + /** + * Constant for the F15 function key. + * @since 1.2 + */ + public static final int VK_F15 = 0xF002; + + /** + * Constant for the F16 function key. + * @since 1.2 + */ + public static final int VK_F16 = 0xF003; + + /** + * Constant for the F17 function key. + * @since 1.2 + */ + public static final int VK_F17 = 0xF004; + + /** + * Constant for the F18 function key. + * @since 1.2 + */ + public static final int VK_F18 = 0xF005; + + /** + * Constant for the F19 function key. + * @since 1.2 + */ + public static final int VK_F19 = 0xF006; + + /** + * Constant for the F20 function key. + * @since 1.2 + */ + public static final int VK_F20 = 0xF007; + + /** + * Constant for the F21 function key. + * @since 1.2 + */ + public static final int VK_F21 = 0xF008; + + /** + * Constant for the F22 function key. + * @since 1.2 + */ + public static final int VK_F22 = 0xF009; + + /** + * Constant for the F23 function key. + * @since 1.2 + */ + public static final int VK_F23 = 0xF00A; + + /** + * Constant for the F24 function key. + * @since 1.2 + */ + public static final int VK_F24 = 0xF00B; + + public static final int VK_PRINTSCREEN = 0x9A; + public static final int VK_INSERT = 0x9B; + public static final int VK_HELP = 0x9C; + public static final int VK_META = 0x9D; + + public static final int VK_BACK_QUOTE = 0xC0; + public static final int VK_QUOTE = 0xDE; + + /** + * Constant for the numeric keypad up arrow key. + * @see #VK_UP + * @since 1.2 + */ + public static final int VK_KP_UP = 0xE0; + + /** + * Constant for the numeric keypad down arrow key. + * @see #VK_DOWN + * @since 1.2 + */ + public static final int VK_KP_DOWN = 0xE1; + + /** + * Constant for the numeric keypad left arrow key. + * @see #VK_LEFT + * @since 1.2 + */ + public static final int VK_KP_LEFT = 0xE2; + + /** + * Constant for the numeric keypad right arrow key. + * @see #VK_RIGHT + * @since 1.2 + */ + public static final int VK_KP_RIGHT = 0xE3; + + /* For European keyboards */ + /** @since 1.2 */ + public static final int VK_DEAD_GRAVE = 0x80; + /** @since 1.2 */ + public static final int VK_DEAD_ACUTE = 0x81; + /** @since 1.2 */ + public static final int VK_DEAD_CIRCUMFLEX = 0x82; + /** @since 1.2 */ + public static final int VK_DEAD_TILDE = 0x83; + /** @since 1.2 */ + public static final int VK_DEAD_MACRON = 0x84; + /** @since 1.2 */ + public static final int VK_DEAD_BREVE = 0x85; + /** @since 1.2 */ + public static final int VK_DEAD_ABOVEDOT = 0x86; + /** @since 1.2 */ + public static final int VK_DEAD_DIAERESIS = 0x87; + /** @since 1.2 */ + public static final int VK_DEAD_ABOVERING = 0x88; + /** @since 1.2 */ + public static final int VK_DEAD_DOUBLEACUTE = 0x89; + /** @since 1.2 */ + public static final int VK_DEAD_CARON = 0x8a; + /** @since 1.2 */ + public static final int VK_DEAD_CEDILLA = 0x8b; + /** @since 1.2 */ + public static final int VK_DEAD_OGONEK = 0x8c; + /** @since 1.2 */ + public static final int VK_DEAD_IOTA = 0x8d; + /** @since 1.2 */ + public static final int VK_DEAD_VOICED_SOUND = 0x8e; + /** @since 1.2 */ + public static final int VK_DEAD_SEMIVOICED_SOUND = 0x8f; + + /** @since 1.2 */ + public static final int VK_AMPERSAND = 0x96; + /** @since 1.2 */ + public static final int VK_ASTERISK = 0x97; + /** @since 1.2 */ + public static final int VK_QUOTEDBL = 0x98; + /** @since 1.2 */ + public static final int VK_LESS = 0x99; + + /** @since 1.2 */ + public static final int VK_GREATER = 0xa0; + /** @since 1.2 */ + public static final int VK_BRACELEFT = 0xa1; + /** @since 1.2 */ + public static final int VK_BRACERIGHT = 0xa2; + + /** + * Constant for the "@" key. + * @since 1.2 + */ + public static final int VK_AT = 0x0200; + + /** + * Constant for the ":" key. + * @since 1.2 + */ + public static final int VK_COLON = 0x0201; + + /** + * Constant for the "^" key. + * @since 1.2 + */ + public static final int VK_CIRCUMFLEX = 0x0202; + + /** + * Constant for the "$" key. + * @since 1.2 + */ + public static final int VK_DOLLAR = 0x0203; + + /** + * Constant for the Euro currency sign key. + * @since 1.2 + */ + public static final int VK_EURO_SIGN = 0x0204; + + /** + * Constant for the "!" key. + * @since 1.2 + */ + public static final int VK_EXCLAMATION_MARK = 0x0205; + + /** + * Constant for the inverted exclamation mark key. + * @since 1.2 + */ + public static final int VK_INVERTED_EXCLAMATION_MARK = 0x0206; + + /** + * Constant for the "(" key. + * @since 1.2 + */ + public static final int VK_LEFT_PARENTHESIS = 0x0207; + + /** + * Constant for the "#" key. + * @since 1.2 + */ + public static final int VK_NUMBER_SIGN = 0x0208; + + /** + * Constant for the "+" key. + * @since 1.2 + */ + public static final int VK_PLUS = 0x0209; + + /** + * Constant for the ")" key. + * @since 1.2 + */ + public static final int VK_RIGHT_PARENTHESIS = 0x020A; + + /** + * Constant for the "_" key. + * @since 1.2 + */ + public static final int VK_UNDERSCORE = 0x020B; + + /** + * Constant for the Microsoft Windows "Windows" key. + * It is used for both the left and right version of the key. + * @see #getKeyLocation() + * @since 1.5 + */ + public static final int VK_WINDOWS = 0x020C; + + /** + * Constant for the Microsoft Windows Context Menu key. + * @since 1.5 + */ + public static final int VK_CONTEXT_MENU = 0x020D; + + /* for input method support on Asian Keyboards */ + + /* not clear what this means - listed in Microsoft Windows API */ + public static final int VK_FINAL = 0x0018; + + /** Constant for the Convert function key. */ + /* Japanese PC 106 keyboard, Japanese Solaris keyboard: henkan */ + public static final int VK_CONVERT = 0x001C; + + /** Constant for the Don't Convert function key. */ + /* Japanese PC 106 keyboard: muhenkan */ + public static final int VK_NONCONVERT = 0x001D; + + /** Constant for the Accept or Commit function key. */ + /* Japanese Solaris keyboard: kakutei */ + public static final int VK_ACCEPT = 0x001E; + + /* not clear what this means - listed in Microsoft Windows API */ + public static final int VK_MODECHANGE = 0x001F; + + /* replaced by VK_KANA_LOCK for Microsoft Windows and Solaris; + might still be used on other platforms */ + public static final int VK_KANA = 0x0015; + + /* replaced by VK_INPUT_METHOD_ON_OFF for Microsoft Windows and Solaris; + might still be used for other platforms */ + public static final int VK_KANJI = 0x0019; + + /** + * Constant for the Alphanumeric function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: eisuu */ + public static final int VK_ALPHANUMERIC = 0x00F0; + + /** + * Constant for the Katakana function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: katakana */ + public static final int VK_KATAKANA = 0x00F1; + + /** + * Constant for the Hiragana function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: hiragana */ + public static final int VK_HIRAGANA = 0x00F2; + + /** + * Constant for the Full-Width Characters function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: zenkaku */ + public static final int VK_FULL_WIDTH = 0x00F3; + + /** + * Constant for the Half-Width Characters function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: hankaku */ + public static final int VK_HALF_WIDTH = 0x00F4; + + /** + * Constant for the Roman Characters function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: roumaji */ + public static final int VK_ROMAN_CHARACTERS = 0x00F5; + + /** + * Constant for the All Candidates function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard - VK_CONVERT + ALT: zenkouho */ + public static final int VK_ALL_CANDIDATES = 0x0100; + + /** + * Constant for the Previous Candidate function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard - VK_CONVERT + SHIFT: maekouho */ + public static final int VK_PREVIOUS_CANDIDATE = 0x0101; + + /** + * Constant for the Code Input function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard - VK_ALPHANUMERIC + ALT: kanji bangou */ + public static final int VK_CODE_INPUT = 0x0102; + + /** + * Constant for the Japanese-Katakana function key. + * This key switches to a Japanese input method and selects its Katakana input mode. + * @since 1.2 + */ + /* Japanese Macintosh keyboard - VK_JAPANESE_HIRAGANA + SHIFT */ + public static final int VK_JAPANESE_KATAKANA = 0x0103; + + /** + * Constant for the Japanese-Hiragana function key. + * This key switches to a Japanese input method and selects its Hiragana input mode. + * @since 1.2 + */ + /* Japanese Macintosh keyboard */ + public static final int VK_JAPANESE_HIRAGANA = 0x0104; + + /** + * Constant for the Japanese-Roman function key. + * This key switches to a Japanese input method and selects its Roman-Direct input mode. + * @since 1.2 + */ + /* Japanese Macintosh keyboard */ + public static final int VK_JAPANESE_ROMAN = 0x0105; + + /** + * Constant for the locking Kana function key. + * This key locks the keyboard into a Kana layout. + * @since 1.3 + */ + /* Japanese PC 106 keyboard with special Windows driver - eisuu + Control; Japanese Solaris keyboard: kana */ + public static final int VK_KANA_LOCK = 0x0106; + + /** + * Constant for the input method on/off key. + * @since 1.3 + */ + /* Japanese PC 106 keyboard: kanji. Japanese Solaris keyboard: nihongo */ + public static final int VK_INPUT_METHOD_ON_OFF = 0x0107; + + /* for Sun keyboards */ + /** @since 1.2 */ + public static final int VK_CUT = 0xFFD1; + /** @since 1.2 */ + public static final int VK_COPY = 0xFFCD; + /** @since 1.2 */ + public static final int VK_PASTE = 0xFFCF; + /** @since 1.2 */ + public static final int VK_UNDO = 0xFFCB; + /** @since 1.2 */ + public static final int VK_AGAIN = 0xFFC9; + /** @since 1.2 */ + public static final int VK_FIND = 0xFFD0; + /** @since 1.2 */ + public static final int VK_PROPS = 0xFFCA; + /** @since 1.2 */ + public static final int VK_STOP = 0xFFC8; + + /** + * Constant for the Compose function key. + * @since 1.2 + */ + public static final int VK_COMPOSE = 0xFF20; + + /** + * Constant for the AltGraph function key. + * @since 1.2 + */ + public static final int VK_ALT_GRAPH = 0xFF7E; + + /** + * Constant for the Begin key. + * @since 1.5 + */ + public static final int VK_BEGIN = 0xFF58; + + /** + * This value is used to indicate that the keyCode is unknown. + * KEY_TYPED events do not have a keyCode value; this value + * is used instead. + */ + public static final int VK_UNDEFINED = 0x0; +} + diff --git a/src/newt/classes/com/jogamp/newt/KeyListener.java b/src/newt/classes/com/jogamp/newt/KeyListener.java new file mode 100644 index 000000000..28e2b833b --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/KeyListener.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt; + +public interface KeyListener extends EventListener +{ + public void keyPressed(KeyEvent e); + public void keyReleased(KeyEvent e); + public void keyTyped(KeyEvent e) ; +} + diff --git a/src/newt/classes/com/jogamp/newt/MouseEvent.java b/src/newt/classes/com/jogamp/newt/MouseEvent.java new file mode 100644 index 000000000..d5412c0cc --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/MouseEvent.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt; + +public class MouseEvent extends InputEvent +{ + public static final int BUTTON1 = 1; + public static final int BUTTON2 = 2; + public static final int BUTTON3 = 3; + public static final int BUTTON4 = 4; + public static final int BUTTON5 = 5; + public static final int BUTTON6 = 6; + public static final int BUTTON_NUMBER = 6; + + protected MouseEvent(boolean sysEvent, int eventType, Window source, long when, + int modifiers, int x, int y, int clickCount, int button, + int rotation) + { + super(sysEvent, eventType, source, when, modifiers); + this.x=x; + this.y=y; + this.clickCount=clickCount; + this.button=button; + this.wheelRotation = rotation; + } + public MouseEvent(int eventType, Window source, long when, int modifiers, + int x, int y, int clickCount, int button, int rotation) { + this(false, eventType, source, when, modifiers, x, y, clickCount, button, + rotation); + } + + public int getButton() { + return button; + } + public int getClickCount() { + return clickCount; + } + public int getX() { + return x; + } + public int getY() { + return y; + } + public int getWheelRotation() { + return wheelRotation; + } + + public String toString() { + return "MouseEvent["+getEventTypeString(getEventType())+ + ", "+x+"/"+y+", button "+button+", count "+clickCount+ + ", wheel rotation "+wheelRotation+ + ", "+super.toString()+"]"; + } + + public static String getEventTypeString(int type) { + switch(type) { + case EVENT_MOUSE_CLICKED: return "EVENT_MOUSE_CLICKED"; + case EVENT_MOUSE_ENTERED: return "EVENT_MOUSE_ENTERED"; + case EVENT_MOUSE_EXITED: return "EVENT_MOUSE_EXITED"; + case EVENT_MOUSE_PRESSED: return "EVENT_MOUSE_PRESSED"; + case EVENT_MOUSE_RELEASED: return "EVENT_MOUSE_RELEASED"; + case EVENT_MOUSE_MOVED: return "EVENT_MOUSE_MOVED"; + case EVENT_MOUSE_DRAGGED: return "EVENT_MOUSE_DRAGGED"; + case EVENT_MOUSE_WHEEL_MOVED: return "EVENT_MOUSE_WHEEL_MOVED"; + default: return "unknown (" + type + ")"; + } + } + + private int x, y, clickCount, button, wheelRotation; + + public static final int EVENT_MOUSE_CLICKED = 200; + public static final int EVENT_MOUSE_ENTERED = 201; + public static final int EVENT_MOUSE_EXITED = 202; + public static final int EVENT_MOUSE_PRESSED = 203; + public static final int EVENT_MOUSE_RELEASED = 204; + public static final int EVENT_MOUSE_MOVED = 205; + public static final int EVENT_MOUSE_DRAGGED = 206; + public static final int EVENT_MOUSE_WHEEL_MOVED = 207; +} diff --git a/src/newt/classes/com/jogamp/newt/MouseListener.java b/src/newt/classes/com/jogamp/newt/MouseListener.java new file mode 100644 index 000000000..6d931dd31 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/MouseListener.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt; + +public interface MouseListener extends EventListener +{ + public void mouseClicked(MouseEvent e); + public void mouseEntered(MouseEvent e); + public void mouseExited(MouseEvent e); + public void mousePressed(MouseEvent e); + public void mouseReleased(MouseEvent e); + public void mouseMoved(MouseEvent e); + public void mouseDragged(MouseEvent e); + public void mouseWheelMoved(MouseEvent e); +} + diff --git a/src/newt/classes/com/jogamp/newt/NewtFactory.java b/src/newt/classes/com/jogamp/newt/NewtFactory.java new file mode 100755 index 000000000..2a696aa07 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/NewtFactory.java @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt; + +import javax.media.nativewindow.*; +import java.util.ArrayList; +import java.util.Iterator; +import com.jogamp.nativewindow.impl.jvm.JVMUtil; + +public abstract class NewtFactory { + // Work-around for initialization order problems on Mac OS X + // between native Newt and (apparently) Fmod + static { + JVMUtil.initSingleton(); + Window.init(NativeWindowFactory.getNativeWindowType(true)); + } + + static Class getCustomClass(String packageName, String classBaseName) { + Class clazz = null; + if(packageName!=null || classBaseName!=null) { + String clazzName = packageName + "." + classBaseName ; + try { + clazz = Class.forName(clazzName); + } catch (Throwable t) {} + } + return clazz; + } + + private static boolean useEDT = true; + + /** + * Toggles the usage of an EventDispatchThread while creating a Display.
+ * The default is enabled.
+ * The EventDispatchThread is thread local to the Display instance.
+ */ + public static synchronized void setUseEDT(boolean onoff) { + useEDT = onoff; + } + + /** @see #setUseEDT(boolean) */ + public static boolean useEDT() { return useEDT; } + + /** + * Create a Display entity, incl native creation + */ + public static Display createDisplay(String name) { + return Display.create(NativeWindowFactory.getNativeWindowType(true), name); + } + + /** + * Create a Display entity using the given implementation type, incl native creation + */ + public static Display createDisplay(String type, String name) { + return Display.create(type, name); + } + + /** + * Create a Screen entity, incl native creation + */ + public static Screen createScreen(Display display, int index) { + return Screen.create(NativeWindowFactory.getNativeWindowType(true), display, index); + } + + /** + * Create a Screen entity using the given implementation type, incl native creation + */ + public static Screen createScreen(String type, Display display, int index) { + return Screen.create(type, display, index); + } + + /** + * Create a Window entity, incl native creation + */ + public static Window createWindow(Screen screen, Capabilities caps) { + return Window.create(NativeWindowFactory.getNativeWindowType(true), 0, screen, caps, false); + } + + public static Window createWindow(Screen screen, Capabilities caps, boolean undecorated) { + return Window.create(NativeWindowFactory.getNativeWindowType(true), 0, screen, caps, undecorated); + } + + public static Window createWindow(long parentWindowHandle, Screen screen, Capabilities caps, boolean undecorated) { + return Window.create(NativeWindowFactory.getNativeWindowType(true), parentWindowHandle, screen, caps, undecorated); + } + + /** + * Ability to try a Window type with a construnctor argument, if supported ..

+ * Currently only valid is AWTWindow(Frame frame) , + * to support an external created AWT Frame, ie the browsers embedded frame. + */ + public static Window createWindow(Object[] cstrArguments, Screen screen, Capabilities caps, boolean undecorated) { + return Window.create(NativeWindowFactory.getNativeWindowType(true), cstrArguments, screen, caps, undecorated); + } + + /** + * Create a Window entity using the given implementation type, incl native creation + */ + public static Window createWindow(String type, Screen screen, Capabilities caps) { + return Window.create(type, 0, screen, caps, false); + } + + public static Window createWindow(String type, Screen screen, Capabilities caps, boolean undecorated) { + return Window.create(type, 0, screen, caps, undecorated); + } + + public static Window createWindow(String type, long parentWindowHandle, Screen screen, Capabilities caps, boolean undecorated) { + return Window.create(type, parentWindowHandle, screen, caps, undecorated); + } + + public static Window createWindow(String type, Object[] cstrArguments, Screen screen, Capabilities caps, boolean undecorated) { + return Window.create(type, cstrArguments, screen, caps, undecorated); + } + + /** + * Instantiate a Display entity using the native handle. + */ + public static Display wrapDisplay(String name, AbstractGraphicsDevice device) { + return Display.wrapHandle(NativeWindowFactory.getNativeWindowType(true), name, device); + } + + /** + * Instantiate a Screen entity using the native handle. + */ + public static Screen wrapScreen(Display display, AbstractGraphicsScreen screen) { + return Screen.wrapHandle(NativeWindowFactory.getNativeWindowType(true), display, screen); + } + + /** + * Instantiate a Window entity using the native handle. + */ + public static Window wrapWindow(Screen screen, AbstractGraphicsConfiguration config, + long windowHandle, boolean fullscreen, boolean visible, + int x, int y, int width, int height) { + return Window.wrapHandle(NativeWindowFactory.getNativeWindowType(true), screen, config, + windowHandle, fullscreen, visible, x, y, width, height); + } + + private static final boolean instanceOf(Object obj, String clazzName) { + Class clazz = obj.getClass(); + do { + if(clazz.getName().equals(clazzName)) { + return true; + } + clazz = clazz.getSuperclass(); + } while (clazz!=null); + return false; + } + +} + diff --git a/src/newt/classes/com/jogamp/newt/OffscreenWindow.java b/src/newt/classes/com/jogamp/newt/OffscreenWindow.java new file mode 100644 index 000000000..c9c56fc61 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/OffscreenWindow.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt; + +import javax.media.nativewindow.*; + +public class OffscreenWindow extends Window implements SurfaceChangeable { + + long surfaceHandle = 0; + + public OffscreenWindow() { + } + + static long nextWindowHandle = 0x100; // start here - a marker + + protected void createNative(long parentWindowHandle, Capabilities caps) { + if(0!=parentWindowHandle) { + throw new NativeWindowException("OffscreenWindow does not support window parenting"); + } + if(caps.isOnscreen()) { + throw new NativeWindowException("Capabilities is onscreen"); + } + AbstractGraphicsScreen aScreen = screen.getGraphicsScreen(); + config = GraphicsConfigurationFactory.getFactory(aScreen.getDevice()).chooseGraphicsConfiguration(caps, null, aScreen); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + + synchronized(OffscreenWindow.class) { + windowHandle = nextWindowHandle++; + } + } + + protected void closeNative() { + // nop + } + + public void invalidate() { + super.invalidate(); + surfaceHandle = 0; + } + + public synchronized void destroy() { + surfaceHandle = 0; + } + + public void setSurfaceHandle(long handle) { + surfaceHandle = handle ; + } + + public long getSurfaceHandle() { + return surfaceHandle; + } + + public void setVisible(boolean visible) { + if(!visible) { + this.visible = visible; + } + } + + public void setSize(int width, int height) { + if(!visible) { + this.width = width; + this.height = height; + } + } + + public void setPosition(int x, int y) { + // nop + } + + public boolean setFullscreen(boolean fullscreen) { + // nop + return false; + } +} + diff --git a/src/newt/classes/com/jogamp/newt/PaintEvent.java b/src/newt/classes/com/jogamp/newt/PaintEvent.java new file mode 100755 index 000000000..51c43725a --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/PaintEvent.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt; + +/** + * + * @author tdv + */ +public class PaintEvent extends Event { + + // bounds of the damage region + private int x, y, width, height; + public PaintEvent(int eventType, Window source, + long when, int x, int y, int w, int h) + { + super(true, eventType, source, when); + this.x = x; + this.y = y; + this.width = w; + this.height = h; + } + + public int getHeight() { + return height; + } + + public int getWidth() { + return width; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public String toString() { + return "ExposeEvent[modifiers: x="+x+" y="+y+" w="+width+" h="+height +"]"; + } + +} diff --git a/src/newt/classes/com/jogamp/newt/PaintListener.java b/src/newt/classes/com/jogamp/newt/PaintListener.java new file mode 100755 index 000000000..6fbc9c8fc --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/PaintListener.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt; + +/** + * + * @author tdv + */ +public interface PaintListener { + public void exposed(PaintEvent e); +} diff --git a/src/newt/classes/com/jogamp/newt/Screen.java b/src/newt/classes/com/jogamp/newt/Screen.java new file mode 100755 index 000000000..b393d30de --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/Screen.java @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt; + +import com.jogamp.newt.impl.*; + +import javax.media.nativewindow.*; +import java.security.*; + +public abstract class Screen { + + private static Class getScreenClass(String type) + throws ClassNotFoundException + { + Class screenClass = NewtFactory.getCustomClass(type, "Screen"); + if(null==screenClass) { + if (NativeWindowFactory.TYPE_EGL.equals(type)) { + screenClass = Class.forName("com.jogamp.newt.opengl.kd.KDScreen"); + } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) { + screenClass = Class.forName("com.jogamp.newt.windows.WindowsScreen"); + } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { + screenClass = Class.forName("com.jogamp.newt.macosx.MacScreen"); + } else if (NativeWindowFactory.TYPE_X11.equals(type)) { + screenClass = Class.forName("com.jogamp.newt.x11.X11Screen"); + } else if (NativeWindowFactory.TYPE_AWT.equals(type)) { + screenClass = Class.forName("com.jogamp.newt.awt.AWTScreen"); + } else { + throw new RuntimeException("Unknown window type \"" + type + "\""); + } + } + return screenClass; + } + + protected static Screen create(String type, Display display, int idx) { + try { + if(usrWidth<0 || usrHeight<0) { + usrWidth = Debug.getIntProperty("newt.ws.swidth", true, localACC); + usrHeight = Debug.getIntProperty("newt.ws.sheight", true, localACC); + System.out.println("User screen size "+usrWidth+"x"+usrHeight); + } + Class screenClass = getScreenClass(type); + Screen screen = (Screen) screenClass.newInstance(); + screen.display = display; + screen.createNative(idx); + if(null==screen.aScreen) { + throw new RuntimeException("Screen.createNative() failed to instanciate an AbstractGraphicsScreen"); + } + return screen; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public synchronized void destroy() { + closeNative(); + display = null; + aScreen = null; + } + + protected static Screen wrapHandle(String type, Display display, AbstractGraphicsScreen aScreen) { + try { + Class screenClass = getScreenClass(type); + Screen screen = (Screen) screenClass.newInstance(); + screen.display = display; + screen.aScreen = aScreen; + return screen; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected abstract void createNative(int index); + protected abstract void closeNative(); + + protected void setScreenSize(int w, int h) { + System.out.println("Detected screen size "+w+"x"+h); + width=w; height=h; + } + + public Display getDisplay() { + return display; + } + + public int getIndex() { + return aScreen.getIndex(); + } + + public AbstractGraphicsScreen getGraphicsScreen() { + return aScreen; + } + + /** + * The actual implementation shall return the detected display value, + * if not we return 800. + * This can be overwritten with the user property 'newt.ws.swidth', + */ + public int getWidth() { + return (usrWidth>0) ? usrWidth : (width>0) ? width : 480; + } + + /** + * The actual implementation shall return the detected display value, + * if not we return 480. + * This can be overwritten with the user property 'newt.ws.sheight', + */ + public int getHeight() { + return (usrHeight>0) ? usrHeight : (height>0) ? height : 480; + } + + protected Display display; + protected AbstractGraphicsScreen aScreen; + protected int width=-1, height=-1; // detected values: set using setScreenSize + protected static int usrWidth=-1, usrHeight=-1; // property values: newt.ws.swidth and newt.ws.sheight + private static AccessControlContext localACC = AccessController.getContext(); +} + diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java new file mode 100755 index 000000000..410144653 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/Window.java @@ -0,0 +1,929 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt; + +import com.jogamp.newt.impl.Debug; +import com.jogamp.newt.util.EventDispatchThread; + +import javax.media.nativewindow.*; +import com.jogamp.nativewindow.impl.NWReflection; + +import java.util.ArrayList; +import java.util.Iterator; +import java.lang.reflect.Method; + +public abstract class Window implements NativeWindow +{ + public static final boolean DEBUG_MOUSE_EVENT = Debug.debug("Window.MouseEvent"); + public static final boolean DEBUG_KEY_EVENT = Debug.debug("Window.KeyEvent"); + public static final boolean DEBUG_WINDOW_EVENT = Debug.debug("Window.WindowEvent"); + public static final boolean DEBUG_IMPLEMENTATION = Debug.debug("Window"); + + // Workaround for initialization order problems on Mac OS X + // between native Newt and (apparently) Fmod -- if Fmod is + // initialized first then the connection to the window server + // breaks, leading to errors from deep within the AppKit + static void init(String type) { + if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { + try { + getWindowClass(type); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + private static Class getWindowClass(String type) + throws ClassNotFoundException + { + Class windowClass = NewtFactory.getCustomClass(type, "Window"); + if(null==windowClass) { + if (NativeWindowFactory.TYPE_EGL.equals(type)) { + windowClass = Class.forName("com.jogamp.newt.opengl.kd.KDWindow"); + } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) { + windowClass = Class.forName("com.jogamp.newt.windows.WindowsWindow"); + } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) { + windowClass = Class.forName("com.jogamp.newt.macosx.MacWindow"); + } else if (NativeWindowFactory.TYPE_X11.equals(type)) { + windowClass = Class.forName("com.jogamp.newt.x11.X11Window"); + } else if (NativeWindowFactory.TYPE_AWT.equals(type)) { + windowClass = Class.forName("com.jogamp.newt.awt.AWTWindow"); + } else { + throw new NativeWindowException("Unknown window type \"" + type + "\""); + } + } + return windowClass; + } + + protected static Window create(String type, final long parentWindowHandle, Screen screen, final Capabilities caps, boolean undecorated) { + try { + Class windowClass; + if(caps.isOnscreen()) { + windowClass = getWindowClass(type); + } else { + windowClass = OffscreenWindow.class; + } + Window window = (Window) windowClass.newInstance(); + window.invalidate(); + window.screen = screen; + window.setUndecorated(undecorated||0!=parentWindowHandle); + EventDispatchThread edt = screen.getDisplay().getEDT(); + if(null!=edt) { + final Window f_win = window; + edt.invokeAndWait(new Runnable() { + public void run() { + f_win.createNative(parentWindowHandle, caps); + } + } ); + } else { + window.createNative(parentWindowHandle, caps); + } + return window; + } catch (Throwable t) { + t.printStackTrace(); + throw new NativeWindowException(t); + } + } + + protected static Window create(String type, Object[] cstrArguments, Screen screen, final Capabilities caps, boolean undecorated) { + try { + Class windowClass = getWindowClass(type); + Class[] cstrArgumentTypes = getCustomConstructorArgumentTypes(windowClass); + if(null==cstrArgumentTypes) { + throw new NativeWindowException("WindowClass "+windowClass+" doesn't support custom arguments in constructor"); + } + int argsChecked = verifyConstructorArgumentTypes(cstrArgumentTypes, cstrArguments); + if ( argsChecked < cstrArguments.length ) { + throw new NativeWindowException("WindowClass "+windowClass+" constructor mismatch at argument #"+argsChecked+"; Constructor: "+getTypeStrList(cstrArgumentTypes)+", arguments: "+getArgsStrList(cstrArguments)); + } + Window window = (Window) NWReflection.createInstance( windowClass, cstrArgumentTypes, cstrArguments ) ; + window.invalidate(); + window.screen = screen; + window.setUndecorated(undecorated); + EventDispatchThread edt = screen.getDisplay().getEDT(); + if(null!=edt) { + final Window f_win = window; + edt.invokeAndWait(new Runnable() { + public void run() { + f_win.createNative(0, caps); + } + } ); + } else { + window.createNative(0, caps); + } + return window; + } catch (Throwable t) { + t.printStackTrace(); + throw new NativeWindowException(t); + } + } + + protected static Window wrapHandle(String type, Screen screen, AbstractGraphicsConfiguration config, + long windowHandle, boolean fullscreen, boolean visible, + int x, int y, int width, int height) + { + try { + Class windowClass = getWindowClass(type); + Window window = (Window) windowClass.newInstance(); + window.invalidate(); + window.screen = screen; + window.config = config; + window.windowHandle = windowHandle; + window.fullscreen=fullscreen; + window.visible=visible; + window.x=x; + window.y=y; + window.width=width; + window.height=height; + return window; + } catch (Throwable t) { + t.printStackTrace(); + throw new NativeWindowException(t); + } + } + + public static String toHexString(int hex) { + return "0x" + Integer.toHexString(hex); + } + + public static String toHexString(long hex) { + return "0x" + Long.toHexString(hex); + } + + protected Screen screen; + + protected AbstractGraphicsConfiguration config; + protected long windowHandle; + protected boolean fullscreen, visible; + protected int width, height, x, y; + protected int eventMask; + + protected String title = "Newt Window"; + protected boolean undecorated = false; + + /** + * Create native windowHandle, ie creates a new native invisible window. + * + * The parentWindowHandle may be null, in which case no window parenting + * is requested. + * + * Shall use the capabilities to determine the graphics configuration + * and shall set the chosen capabilities. + */ + protected abstract void createNative(long parentWindowHandle, Capabilities caps); + + protected abstract void closeNative(); + + public Screen getScreen() { + return screen; + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + + sb.append(getClass().getName()+"[config "+config+ + ", windowHandle "+toHexString(getWindowHandle())+ + ", surfaceHandle "+toHexString(getSurfaceHandle())+ + ", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+ + ", visible "+isVisible()+ + ", undecorated "+undecorated+ + ", fullscreen "+fullscreen+ + ", "+screen+ + ", wrappedWindow "+getWrappedWindow()); + + sb.append(", SurfaceUpdatedListeners num "+surfaceUpdatedListeners.size()+" ["); + for (Iterator iter = surfaceUpdatedListeners.iterator(); iter.hasNext(); ) { + sb.append(iter.next()+", "); + } + sb.append("], WindowListeners num "+windowListeners.size()+" ["); + for (Iterator iter = windowListeners.iterator(); iter.hasNext(); ) { + sb.append(iter.next()+", "); + } + sb.append("], MouseListeners num "+mouseListeners.size()+" ["); + for (Iterator iter = mouseListeners.iterator(); iter.hasNext(); ) { + sb.append(iter.next()+", "); + } + sb.append("], KeyListeners num "+keyListeners.size()+" ["); + for (Iterator iter = keyListeners.iterator(); iter.hasNext(); ) { + sb.append(iter.next()+", "); + } + sb.append("] ]"); + return sb.toString(); + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public void setUndecorated(boolean value) { + undecorated = value; + } + + public boolean isUndecorated() { + return undecorated; + } + + public void requestFocus() { + } + + // + // NativeWindow impl + // + private Thread owner; + private int recursionCount; + protected Exception lockedStack = null; + + /** Recursive and blocking lockSurface() implementation */ + public synchronized int lockSurface() { + // We leave the ToolkitLock lock to the specializtion's discretion, + // ie the implicit JAWTWindow in case of AWTWindow + Thread cur = Thread.currentThread(); + if (owner == cur) { + ++recursionCount; + return LOCK_SUCCESS; + } + while (owner != null) { + try { + wait(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + owner = cur; + lockedStack = new Exception("NEWT Surface previously locked by "+Thread.currentThread()); + screen.getDisplay().lockDisplay(); + return LOCK_SUCCESS; + } + + /** Recursive and unblocking unlockSurface() implementation */ + public synchronized void unlockSurface() throws NativeWindowException { + Thread cur = Thread.currentThread(); + if (owner != cur) { + lockedStack.printStackTrace(); + throw new NativeWindowException(cur+": Not owner, owner is "+owner); + } + if (recursionCount > 0) { + --recursionCount; + return; + } + owner = null; + lockedStack = null; + screen.getDisplay().unlockDisplay(); + notifyAll(); + // We leave the ToolkitLock unlock to the specializtion's discretion, + // ie the implicit JAWTWindow in case of AWTWindow + } + + public synchronized boolean isSurfaceLocked() { + return null!=owner; + } + + public synchronized Thread getSurfaceLockOwner() { + return owner; + } + + public synchronized Exception getLockedStack() { + return lockedStack; + } + + public synchronized void destroy() { + destroy(false); + } + + /** @param deep If true, the linked Screen and Display will be destroyed as well. */ + public synchronized void destroy(boolean deep) { + if(DEBUG_WINDOW_EVENT) { + System.out.println("Window.destroy() start (deep "+deep+" - "+Thread.currentThread()); + } + synchronized(surfaceUpdatedListeners) { + surfaceUpdatedListeners = new ArrayList(); + } + synchronized(windowListeners) { + windowListeners = new ArrayList(); + } + synchronized(mouseListeners) { + mouseListeners = new ArrayList(); + } + synchronized(keyListeners) { + keyListeners = new ArrayList(); + } + Screen scr = screen; + Display dpy = (null!=screen) ? screen.getDisplay() : null; + EventDispatchThread edt = (null!=dpy) ? dpy.getEDT() : null; + if(null!=edt) { + final Window f_win = this; + edt.invokeAndWait(new Runnable() { + public void run() { + f_win.closeNative(); + } + } ); + } else { + closeNative(); + } + invalidate(); + if(deep) { + if(null!=scr) { + scr.destroy(); + } + if(null!=dpy) { + dpy.destroy(); + } + } + if(DEBUG_WINDOW_EVENT) { + System.out.println("Window.destroy() end "+Thread.currentThread()); + } + } + + public void invalidate() { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + Exception e = new Exception("!!! Window Invalidate "+Thread.currentThread()); + e.printStackTrace(); + } + screen = null; + windowHandle = 0; + fullscreen=false; + visible=false; + eventMask = 0; + + // Default position and dimension will be re-set immediately by user + width = 100; + height = 100; + x=0; + y=0; + } + + public boolean surfaceSwap() { + return false; + } + + protected void clearEventMask() { + eventMask=0; + } + + public long getDisplayHandle() { + return screen.getDisplay().getHandle(); + } + + public int getScreenIndex() { + return screen.getIndex(); + } + + public long getWindowHandle() { + return windowHandle; + } + + public long getSurfaceHandle() { + return windowHandle; // default: return window handle + } + + public AbstractGraphicsConfiguration getGraphicsConfiguration() { + return config; + } + + /** + * Returns the width of the client area of this window + * @return width of the client area + */ + public int getWidth() { + return width; + } + + /** + * Returns the height of the client area of this window + * @return height of the client area + */ + public int getHeight() { + return height; + } + + /** + * Returns the insets for this native window (the difference between the + * size of the toplevel window with the decorations and the client area). + * + * @return insets for this platform window + */ + // this probably belongs to NativeWindow interface + public Insets getInsets() { + return new Insets(0,0,0,0); + } + + /** If this Window actually wraps one from another toolkit such as + the AWT, this will return a non-null value. */ + public Object getWrappedWindow() { + return null; + } + + // + // Additional methods + // + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public boolean isVisible() { + return visible; + } + + public boolean isFullscreen() { + return fullscreen; + } + + private boolean autoDrawableMember = false; + + /** If the implementation is capable of detecting a device change + return true and clear the status/reason of the change. */ + public boolean hasDeviceChanged() { + return false; + } + + /** + * If set to true, + * certain action will be performed by the owning + * AutoDrawable, ie the destroy() call within windowDestroyNotify() + */ + public void setAutoDrawableClient(boolean b) { + autoDrawableMember = b; + } + + protected void windowDestroyNotify() { + if(DEBUG_WINDOW_EVENT) { + System.out.println("Window.windowDestroyeNotify start "+Thread.currentThread()); + } + + sendWindowEvent(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY); + + if(!autoDrawableMember) { + destroy(); + } + + if(DEBUG_WINDOW_EVENT) { + System.out.println("Window.windowDestroyeNotify end "+Thread.currentThread()); + } + } + + protected void windowDestroyed() { + if(DEBUG_WINDOW_EVENT) { + System.out.println("Window.windowDestroyed "+Thread.currentThread()); + } + invalidate(); + } + + public abstract void setVisible(boolean visible); + /** + * Sets the size of the client area of the window, excluding decorations + * Total size of the window will be + * {@code width+insets.left+insets.right, height+insets.top+insets.bottom} + * @param width of the client area of the window + * @param height of the client area of the window + */ + public abstract void setSize(int width, int height); + /** + * Sets the location of the top left corner of the window, including + * decorations (so the client area will be placed at + * {@code x+insets.left,y+insets.top}. + * @param x coord of the top left corner + * @param y coord of the top left corner + */ + public abstract void setPosition(int x, int y); + public abstract boolean setFullscreen(boolean fullscreen); + + // + // SurfaceUpdatedListener Support + // + private ArrayList surfaceUpdatedListeners = new ArrayList(); + + public void addSurfaceUpdatedListener(SurfaceUpdatedListener l) { + if(l == null) { + return; + } + synchronized(surfaceUpdatedListeners) { + ArrayList newSurfaceUpdatedListeners = (ArrayList) surfaceUpdatedListeners.clone(); + newSurfaceUpdatedListeners.add(l); + surfaceUpdatedListeners = newSurfaceUpdatedListeners; + } + } + + public void removeSurfaceUpdatedListener(SurfaceUpdatedListener l) { + if (l == null) { + return; + } + synchronized(surfaceUpdatedListeners) { + ArrayList newSurfaceUpdatedListeners = (ArrayList) surfaceUpdatedListeners.clone(); + newSurfaceUpdatedListeners.remove(l); + surfaceUpdatedListeners = newSurfaceUpdatedListeners; + } + } + + public SurfaceUpdatedListener[] getSurfaceUpdatedListener() { + synchronized(surfaceUpdatedListeners) { + return (SurfaceUpdatedListener[]) surfaceUpdatedListeners.toArray(); + } + } + + public void surfaceUpdated(Object updater, NativeWindow window, long when) { + ArrayList listeners = null; + synchronized(surfaceUpdatedListeners) { + listeners = surfaceUpdatedListeners; + } + for(Iterator i = listeners.iterator(); i.hasNext(); ) { + SurfaceUpdatedListener l = (SurfaceUpdatedListener) i.next(); + l.surfaceUpdated(updater, window, when); + } + } + + // + // MouseListener Support + // + + public void addMouseListener(MouseListener l) { + if(l == null) { + return; + } + synchronized(mouseListeners) { + ArrayList newMouseListeners = (ArrayList) mouseListeners.clone(); + newMouseListeners.add(l); + mouseListeners = newMouseListeners; + } + } + + public void removeMouseListener(MouseListener l) { + if (l == null) { + return; + } + synchronized(mouseListeners) { + ArrayList newMouseListeners = (ArrayList) mouseListeners.clone(); + newMouseListeners.remove(l); + mouseListeners = newMouseListeners; + } + } + + public MouseListener[] getMouseListeners() { + synchronized(mouseListeners) { + return (MouseListener[]) mouseListeners.toArray(); + } + } + + private ArrayList mouseListeners = new ArrayList(); + private int mouseButtonPressed = 0; // current pressed mouse button number + private long lastMousePressed = 0; // last time when a mouse button was pressed + private int lastMouseClickCount = 0; // last mouse button click count + public static final int ClickTimeout = 300; + + protected void sendMouseEvent(int eventType, int modifiers, + int x, int y, int button, int rotation) { + if(x<0||y<0||x>=width||y>=height) { + return; // .. invalid .. + } + if(DEBUG_MOUSE_EVENT) { + System.out.println("sendMouseEvent: "+MouseEvent.getEventTypeString(eventType)+ + ", mod "+modifiers+", pos "+x+"/"+y+", button "+button); + } + if(button<0||button>MouseEvent.BUTTON_NUMBER) { + throw new NativeWindowException("Invalid mouse button number" + button); + } + long when = System.currentTimeMillis(); + MouseEvent eClicked = null; + MouseEvent e = null; + + if(MouseEvent.EVENT_MOUSE_PRESSED==eventType) { + if(when-lastMousePressed0) { + e = new MouseEvent(true, MouseEvent.EVENT_MOUSE_DRAGGED, this, when, + modifiers, x, y, 1, mouseButtonPressed, 0); + } else { + e = new MouseEvent(true, eventType, this, when, + modifiers, x, y, 0, button, 0); + } + } else if(MouseEvent.EVENT_MOUSE_WHEEL_MOVED==eventType) { + e = new MouseEvent(true, eventType, this, when, modifiers, x, y, 0, button, rotation); + } else { + e = new MouseEvent(true, eventType, this, when, modifiers, x, y, 0, button, 0); + } + + if(DEBUG_MOUSE_EVENT) { + System.out.println("sendMouseEvent: event: "+e); + if(null!=eClicked) { + System.out.println("sendMouseEvent: event Clicked: "+eClicked); + } + } + + ArrayList listeners = null; + synchronized(mouseListeners) { + listeners = mouseListeners; + } + for(Iterator i = listeners.iterator(); i.hasNext(); ) { + MouseListener l = (MouseListener) i.next(); + switch(e.getEventType()) { + case MouseEvent.EVENT_MOUSE_CLICKED: + l.mouseClicked(e); + break; + case MouseEvent.EVENT_MOUSE_ENTERED: + l.mouseEntered(e); + break; + case MouseEvent.EVENT_MOUSE_EXITED: + l.mouseExited(e); + break; + case MouseEvent.EVENT_MOUSE_PRESSED: + l.mousePressed(e); + break; + case MouseEvent.EVENT_MOUSE_RELEASED: + l.mouseReleased(e); + if(null!=eClicked) { + l.mouseClicked(eClicked); + } + break; + case MouseEvent.EVENT_MOUSE_MOVED: + l.mouseMoved(e); + break; + case MouseEvent.EVENT_MOUSE_DRAGGED: + l.mouseDragged(e); + break; + case MouseEvent.EVENT_MOUSE_WHEEL_MOVED: + l.mouseWheelMoved(e); + break; + default: + throw new NativeWindowException("Unexpected mouse event type " + e.getEventType()); + } + } + } + + // + // KeyListener Support + // + + public void addKeyListener(KeyListener l) { + if(l == null) { + return; + } + synchronized(keyListeners) { + ArrayList newKeyListeners = (ArrayList) keyListeners.clone(); + newKeyListeners.add(l); + keyListeners = newKeyListeners; + } + } + + public void removeKeyListener(KeyListener l) { + if (l == null) { + return; + } + synchronized(keyListeners) { + ArrayList newKeyListeners = (ArrayList) keyListeners.clone(); + newKeyListeners.remove(l); + keyListeners = newKeyListeners; + } + } + + public KeyListener[] getKeyListeners() { + synchronized(keyListeners) { + return (KeyListener[]) keyListeners.toArray(); + } + } + + private ArrayList keyListeners = new ArrayList(); + + protected void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { + KeyEvent e = new KeyEvent(true, eventType, this, System.currentTimeMillis(), + modifiers, keyCode, keyChar); + if(DEBUG_KEY_EVENT) { + System.out.println("sendKeyEvent: "+e); + } + ArrayList listeners = null; + synchronized(keyListeners) { + listeners = keyListeners; + } + for(Iterator i = listeners.iterator(); i.hasNext(); ) { + KeyListener l = (KeyListener) i.next(); + switch(eventType) { + case KeyEvent.EVENT_KEY_PRESSED: + l.keyPressed(e); + break; + case KeyEvent.EVENT_KEY_RELEASED: + l.keyReleased(e); + break; + case KeyEvent.EVENT_KEY_TYPED: + l.keyTyped(e); + break; + default: + throw new NativeWindowException("Unexpected key event type " + e.getEventType()); + } + } + } + + // + // WindowListener Support + // + + private ArrayList windowListeners = new ArrayList(); + + public void addWindowListener(WindowListener l) { + if(l == null) { + return; + } + synchronized(windowListeners) { + ArrayList newWindowListeners = (ArrayList) windowListeners.clone(); + newWindowListeners.add(l); + windowListeners = newWindowListeners; + } + } + + public void removeWindowListener(WindowListener l) { + if (l == null) { + return; + } + synchronized(windowListeners) { + ArrayList newWindowListeners = (ArrayList) windowListeners.clone(); + newWindowListeners.remove(l); + windowListeners = newWindowListeners; + } + } + + public WindowListener[] getWindowListeners() { + synchronized(windowListeners) { + return (WindowListener[]) windowListeners.toArray(); + } + } + + protected void sendWindowEvent(int eventType) { + WindowEvent e = new WindowEvent(true, eventType, this, System.currentTimeMillis()); + if(DEBUG_WINDOW_EVENT) { + System.out.println("sendWindowEvent: "+e); + } + ArrayList listeners = null; + synchronized(windowListeners) { + listeners = windowListeners; + } + for(Iterator i = listeners.iterator(); i.hasNext(); ) { + WindowListener l = (WindowListener) i.next(); + switch(eventType) { + case WindowEvent.EVENT_WINDOW_RESIZED: + l.windowResized(e); + break; + case WindowEvent.EVENT_WINDOW_MOVED: + l.windowMoved(e); + break; + case WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY: + l.windowDestroyNotify(e); + break; + case WindowEvent.EVENT_WINDOW_GAINED_FOCUS: + l.windowGainedFocus(e); + break; + case WindowEvent.EVENT_WINDOW_LOST_FOCUS: + l.windowLostFocus(e); + break; + default: + throw + new NativeWindowException("Unexpected window event type " + + e.getEventType()); + } + } + } + + + // + // WindowListener Support + // + + private ArrayList paintListeners = new ArrayList(); + + public void addPaintListener(PaintListener l) { + if(l == null) { + return; + } + synchronized(paintListeners) { + ArrayList newPaintListeners = (ArrayList) paintListeners.clone(); + newPaintListeners.add(l); + paintListeners = newPaintListeners; + } + } + + public void removePaintListener(PaintListener l) { + if (l == null) { + return; + } + synchronized(paintListeners) { + ArrayList newPaintListeners = (ArrayList) paintListeners.clone(); + newPaintListeners.remove(l); + paintListeners = newPaintListeners; + } + } + + protected void sendPaintEvent(int eventType, int x, int y, int w, int h) { + PaintEvent e = + new PaintEvent(eventType, this, System.currentTimeMillis(), x, y, w, h); + ArrayList listeners = null; + synchronized(paintListeners) { + listeners = paintListeners; + } + for(Iterator i = listeners.iterator(); i.hasNext(); ) { + PaintListener l = (PaintListener) i.next(); + l.exposed(e); + } + } + + // + // Reflection helper .. + // + + private static Class[] getCustomConstructorArgumentTypes(Class windowClass) { + Class[] argTypes = null; + try { + Method m = windowClass.getDeclaredMethod("getCustomConstructorArgumentTypes", new Class[] {}); + argTypes = (Class[]) m.invoke(null, null); + } catch (Throwable t) {} + return argTypes; + } + + private static int verifyConstructorArgumentTypes(Class[] types, Object[] args) { + if(types.length != args.length) { + return -1; + } + for(int i=0; i*/ events = new LinkedList(); + + static class AWTEventWrapper { + AWTWindow window; + int type; + InputEvent e; + + AWTEventWrapper(AWTWindow w, int type, InputEvent e) { + this.window = w; + this.type = type; + this.e = e; + } + + public AWTWindow getWindow() { + return window; + } + + public int getType() { + return type; + } + + public InputEvent getEvent() { + return e; + } + } + + private static int convertModifiers(InputEvent e) { + int newtMods = 0; + int mods = e.getModifiers(); + if ((mods & InputEvent.SHIFT_MASK) != 0) newtMods |= com.jogamp.newt.InputEvent.SHIFT_MASK; + if ((mods & InputEvent.CTRL_MASK) != 0) newtMods |= com.jogamp.newt.InputEvent.CTRL_MASK; + if ((mods & InputEvent.META_MASK) != 0) newtMods |= com.jogamp.newt.InputEvent.META_MASK; + if ((mods & InputEvent.ALT_MASK) != 0) newtMods |= com.jogamp.newt.InputEvent.ALT_MASK; + if ((mods & InputEvent.ALT_GRAPH_MASK) != 0) newtMods |= com.jogamp.newt.InputEvent.ALT_GRAPH_MASK; + return newtMods; + } + + private static int convertButton(MouseEvent e) { + switch (e.getButton()) { + case MouseEvent.BUTTON1: return com.jogamp.newt.MouseEvent.BUTTON1; + case MouseEvent.BUTTON2: return com.jogamp.newt.MouseEvent.BUTTON2; + case MouseEvent.BUTTON3: return com.jogamp.newt.MouseEvent.BUTTON3; + } + return 0; + } + +} diff --git a/src/newt/classes/com/jogamp/newt/awt/AWTScreen.java b/src/newt/classes/com/jogamp/newt/awt/AWTScreen.java new file mode 100644 index 000000000..c804bce06 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/awt/AWTScreen.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.awt; + +import com.jogamp.newt.*; +import java.awt.DisplayMode; +import javax.media.nativewindow.*; +import javax.media.nativewindow.awt.*; + +public class AWTScreen extends Screen { + public AWTScreen() { + } + + protected void createNative(int index) { + aScreen = new AWTGraphicsScreen((AWTGraphicsDevice)display.getGraphicsDevice()); + + DisplayMode mode = ((AWTGraphicsDevice)getDisplay().getGraphicsDevice()).getGraphicsDevice().getDisplayMode(); + int w = mode.getWidth(); + int h = mode.getHeight(); + setScreenSize(w, h); + } + + protected void setAWTGraphicsScreen(AWTGraphicsScreen s) { + aScreen = s; + } + + // done by AWTWindow .. + protected void setScreenSize(int w, int h) { + super.setScreenSize(w, h); + } + + protected void closeNative() { } + +} diff --git a/src/newt/classes/com/jogamp/newt/awt/AWTWindow.java b/src/newt/classes/com/jogamp/newt/awt/AWTWindow.java new file mode 100644 index 000000000..98cd64ab8 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/awt/AWTWindow.java @@ -0,0 +1,429 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.awt; + +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.Container; +import java.awt.DisplayMode; +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; +import java.awt.event.*; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.*; +import com.jogamp.newt.Window; +import java.awt.Insets; +import javax.media.nativewindow.*; +import javax.media.nativewindow.awt.*; + +/** An implementation of the Newt Window class built using the + AWT. This is provided for convenience of porting to platforms + supporting Java SE. */ + +public class AWTWindow extends Window { + + public AWTWindow() { + this(null); + } + + public static Class[] getCustomConstructorArgumentTypes() { + return new Class[] { Container.class } ; + } + + public AWTWindow(Container container) { + super(); + title = "AWT NewtWindow"; + this.container = container; + if(container instanceof Frame) { + frame = (Frame) container; + } + } + + private boolean owningFrame; + private Container container = null; + private Frame frame = null; // same instance as container, just for impl. convenience + private AWTCanvas canvas; + // non fullscreen dimensions .. + private int nfs_width, nfs_height, nfs_x, nfs_y; + + public void setTitle(final String title) { + super.setTitle(title); + runOnEDT(true, new Runnable() { + public void run() { + if (frame != null) { + frame.setTitle(title); + } + } + }); + } + + protected void createNative(long parentWindowHandle, final Capabilities caps) { + + if(0!=parentWindowHandle) { + throw new RuntimeException("Window parenting not supported in AWT, use AWTWindow(Frame) cstr for wrapping instead"); + } + + final AWTWindow awtWindow = this; + + 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(caps); + Listener listener = new Listener(awtWindow); + canvas.addMouseListener(listener); + canvas.addMouseMotionListener(listener); + canvas.addKeyListener(listener); + canvas.addComponentListener(listener); + container.add(canvas, BorderLayout.CENTER); + container.setSize(width, height); + container.setLocation(x, y); + container.addComponentListener(new MoveListener(awtWindow)); + if(null!=frame) { + frame.setUndecorated(undecorated||fullscreen); + frame.addWindowListener(new WindowEventListener(awtWindow)); + } + } + }); + } + + protected void closeNative() { + runOnEDT(true, new Runnable() { + public void run() { + if(owningFrame && null!=frame) { + frame.dispose(); + owningFrame=false; + } + frame = null; + } + }); + } + + public boolean hasDeviceChanged() { + boolean res = canvas.hasDeviceChanged(); + if(res) { + config = canvas.getAWTGraphicsConfiguration(); + if (config == null) { + throw new NativeWindowException("Error Device change null GraphicsConfiguration: "+this); + } + updateDeviceData(); + } + return res; + } + + public void setVisible(final boolean visible) { + runOnEDT(true, new Runnable() { + public void run() { + container.setVisible(visible); + } + }); + + config = canvas.getAWTGraphicsConfiguration(); + + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + + updateDeviceData(); + } + + private void updateDeviceData() { + // propagate new info .. + ((AWTScreen)getScreen()).setAWTGraphicsScreen((AWTGraphicsScreen)config.getScreen()); + ((AWTDisplay)getScreen().getDisplay()).setAWTGraphicsDevice((AWTGraphicsDevice)config.getScreen().getDevice()); + + DisplayMode mode = ((AWTGraphicsDevice)config.getScreen().getDevice()).getGraphicsDevice().getDisplayMode(); + int w = mode.getWidth(); + int h = mode.getHeight(); + ((AWTScreen)screen).setScreenSize(w, h); + } + + public void setSize(final int width, final int height) { + this.width = width; + this.height = height; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + /** An AWT event on setSize() would bring us in a deadlock situation, hence invokeLater() */ + runOnEDT(false, new Runnable() { + public void run() { + Insets insets = container.getInsets(); + container.setSize(width + insets.left + insets.right, + height + insets.top + insets.bottom); + } + }); + } + + public com.jogamp.newt.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; + } + }); + return new com.jogamp.newt. + Insets(insets[0],insets[1],insets[2],insets[3]); + } + + public void setPosition(final int x, final int y) { + this.x = x; + this.y = y; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + runOnEDT(true, new Runnable() { + public void run() { + container.setLocation(x, y); + } + }); + } + + public boolean setFullscreen(final boolean fullscreen) { + if(this.fullscreen!=fullscreen) { + final int x,y,w,h; + this.fullscreen=fullscreen; + if(fullscreen) { + x = 0; y = 0; + w = screen.getWidth(); + h = screen.getHeight(); + } else { + x = nfs_x; + y = nfs_y; + w = nfs_width; + h = nfs_height; + } + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("AWTWindow fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); + } + /** An AWT event on setSize() would bring us in a deadlock situation, hence invokeLater() */ + runOnEDT(false, new Runnable() { + public void run() { + if(null!=frame) { + if(!container.isDisplayable()) { + frame.setUndecorated(undecorated||fullscreen); + } else { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("AWTWindow can't undecorate already created frame"); + } + } + } + container.setLocation(x, y); + container.setSize(w, h); + } + }); + } + return true; + } + + public Object getWrappedWindow() { + return canvas; + } + + protected void sendWindowEvent(int eventType) { + super.sendWindowEvent(eventType); + } + + protected void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { + super.sendKeyEvent(eventType, modifiers, keyCode, keyChar); + } + + protected void sendMouseEvent(int eventType, int modifiers, + int x, int y, int button, int rotation) { + super.sendMouseEvent(eventType, modifiers, x, y, button, rotation); + } + + private static void runOnEDT(boolean wait, Runnable r) { + if (EventQueue.isDispatchThread()) { + r.run(); + } else { + try { + if(wait) { + EventQueue.invokeAndWait(r); + } else { + EventQueue.invokeLater(r); + } + } catch (Exception e) { + throw new NativeWindowException(e); + } + } + } + + private static final int WINDOW_EVENT = 1; + private static final int KEY_EVENT = 2; + private static final int MOUSE_EVENT = 3; + + class MoveListener implements ComponentListener { + private AWTWindow window; + private AWTDisplay display; + + public MoveListener(AWTWindow w) { + window = w; + display = (AWTDisplay)window.getScreen().getDisplay(); + } + + public void componentResized(ComponentEvent e) { + } + + public void componentMoved(ComponentEvent e) { + if(null!=container) { + x = container.getX(); + y = container.getY(); + } + display.enqueueEvent(window, com.jogamp.newt.WindowEvent.EVENT_WINDOW_MOVED, null); + } + + public void componentShown(ComponentEvent e) { + } + + public void componentHidden(ComponentEvent e) { + } + + } + + class Listener implements ComponentListener, MouseListener, MouseMotionListener, KeyListener { + private AWTWindow window; + private AWTDisplay display; + + public Listener(AWTWindow w) { + window = w; + display = (AWTDisplay)window.getScreen().getDisplay(); + } + + public void componentResized(ComponentEvent e) { + width = canvas.getWidth(); + height = canvas.getHeight(); + display.enqueueEvent(window, com.jogamp.newt.WindowEvent.EVENT_WINDOW_RESIZED, null); + } + + public void componentMoved(ComponentEvent e) { + } + + public void componentShown(ComponentEvent e) { + } + + public void componentHidden(ComponentEvent e) { + } + + public void mouseClicked(MouseEvent e) { + // We ignore these as we synthesize them ourselves out of + // mouse pressed and released events + } + + public void mouseEntered(MouseEvent e) { + display.enqueueEvent(window, com.jogamp.newt.MouseEvent.EVENT_MOUSE_ENTERED, e); + } + + public void mouseExited(MouseEvent e) { + display.enqueueEvent(window, com.jogamp.newt.MouseEvent.EVENT_MOUSE_EXITED, e); + } + + public void mousePressed(MouseEvent e) { + display.enqueueEvent(window, com.jogamp.newt.MouseEvent.EVENT_MOUSE_PRESSED, e); + } + + public void mouseReleased(MouseEvent e) { + display.enqueueEvent(window, com.jogamp.newt.MouseEvent.EVENT_MOUSE_RELEASED, e); + } + + public void mouseMoved(MouseEvent e) { + display.enqueueEvent(window, com.jogamp.newt.MouseEvent.EVENT_MOUSE_MOVED, e); + } + + public void mouseDragged(MouseEvent e) { + display.enqueueEvent(window, com.jogamp.newt.MouseEvent.EVENT_MOUSE_DRAGGED, e); + } + + public void keyPressed(KeyEvent e) { + display.enqueueEvent(window, com.jogamp.newt.KeyEvent.EVENT_KEY_PRESSED, e); + } + + public void keyReleased(KeyEvent e) { + display.enqueueEvent(window, com.jogamp.newt.KeyEvent.EVENT_KEY_RELEASED, e); + } + + public void keyTyped(KeyEvent e) { + display.enqueueEvent(window, com.jogamp.newt.KeyEvent.EVENT_KEY_TYPED, e); + } + } + + class WindowEventListener implements WindowListener { + private AWTWindow window; + private AWTDisplay display; + + public WindowEventListener(AWTWindow w) { + window = w; + display = (AWTDisplay)window.getScreen().getDisplay(); + } + + public void windowActivated(WindowEvent e) { + } + public void windowClosed(WindowEvent e) { + } + public void windowClosing(WindowEvent e) { + display.enqueueEvent(window, com.jogamp.newt.WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY, null); + } + public void windowDeactivated(WindowEvent e) { + } + public void windowDeiconified(WindowEvent e) { + } + public void windowIconified(WindowEvent e) { + } + public void windowOpened(WindowEvent e) { + } + } +} diff --git a/src/newt/classes/com/jogamp/newt/impl/Debug.java b/src/newt/classes/com/jogamp/newt/impl/Debug.java new file mode 100644 index 000000000..62c261d2e --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/Debug.java @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2003-2005 Sun Microsystems, Inc. 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. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.newt.impl; + +import java.security.*; + +/** Helper routines for logging and debugging. */ + +public class Debug { + // Some common properties + private static boolean verbose; + private static boolean debugAll; + private static AccessControlContext localACC; + + static { + localACC=AccessController.getContext(); + verbose = isPropertyDefined("newt.verbose", true); + debugAll = isPropertyDefined("newt.debug", true); + if (verbose) { + Package p = Package.getPackage("com.jogamp.newt"); + System.err.println("NEWT specification version " + p.getSpecificationVersion()); + System.err.println("NEWT implementation version " + p.getImplementationVersion()); + System.err.println("NEWT implementation vendor " + p.getImplementationVendor()); + } + } + + static int getIntProperty(final String property, final boolean jnlpAlias) { + return getIntProperty(property, jnlpAlias, localACC); + } + + public static int getIntProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + int i=0; + try { + Integer iv = Integer.valueOf(Debug.getProperty(property, jnlpAlias, acc)); + i = iv.intValue(); + } catch (NumberFormatException nfe) {} + return i; + } + + static boolean getBooleanProperty(final String property, final boolean jnlpAlias) { + return getBooleanProperty(property, jnlpAlias, localACC); + } + + public static boolean getBooleanProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + Boolean b = Boolean.valueOf(Debug.getProperty(property, jnlpAlias, acc)); + return b.booleanValue(); + } + + static boolean isPropertyDefined(final String property, final boolean jnlpAlias) { + return isPropertyDefined(property, jnlpAlias, localACC); + } + + public static boolean isPropertyDefined(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + return (Debug.getProperty(property, jnlpAlias, acc) != null) ? true : false; + } + + static String getProperty(final String property, final boolean jnlpAlias) { + return getProperty(property, jnlpAlias, localACC); + } + + public static String getProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + String s=null; + if(null!=acc && acc.equals(localACC)) { + s = (String) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String val=null; + try { + val = System.getProperty(property); + } catch (Exception e) {} + if(null==val && jnlpAlias && !property.startsWith(jnlp_prefix)) { + try { + val = System.getProperty(jnlp_prefix + property); + } catch (Exception e) {} + } + return val; + } + }); + } else { + try { + s = System.getProperty(property); + } catch (Exception e) {} + if(null==s && jnlpAlias && !property.startsWith(jnlp_prefix)) { + try { + s = System.getProperty(jnlp_prefix + property); + } catch (Exception e) {} + } + } + return s; + } + public static final String jnlp_prefix = "jnlp." ; + + public static boolean verbose() { + return verbose; + } + + public static boolean debugAll() { + return debugAll; + } + + public static boolean debug(String subcomponent) { + return debugAll() || isPropertyDefined("newt.debug." + subcomponent, true); + } +} diff --git a/src/newt/classes/com/jogamp/newt/impl/NativeLibLoader.java b/src/newt/classes/com/jogamp/newt/impl/NativeLibLoader.java new file mode 100644 index 000000000..52e4c0dc3 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/NativeLibLoader.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. 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. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.newt.impl; + +// FIXME: refactor Java SE dependencies +//import java.awt.Toolkit; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.HashSet; +import com.jogamp.nativewindow.impl.NativeLibLoaderBase; + +public class NativeLibLoader extends NativeLibLoaderBase { + + public static void loadNEWT() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + loadLibrary("newt", null, true); + return null; + } + }); + } + +} diff --git a/src/newt/classes/com/jogamp/newt/intel/gdl/Display.java b/src/newt/classes/com/jogamp/newt/intel/gdl/Display.java new file mode 100644 index 000000000..eb93943ee --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/intel/gdl/Display.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.intel.gdl; + +import com.jogamp.newt.impl.*; +import javax.media.nativewindow.*; + +public class Display extends com.jogamp.newt.Display { + static int initCounter = 0; + + static { + NativeLibLoader.loadNEWT(); + + if (!Screen.initIDs()) { + throw new NativeWindowException("Failed to initialize GDL Screen jmethodIDs"); + } + if (!Window.initIDs()) { + throw new NativeWindowException("Failed to initialize GDL Window jmethodIDs"); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + + public Display() { + } + + protected void createNative() { + synchronized(Display.class) { + if(0==initCounter) { + displayHandle = CreateDisplay(); + if(0==displayHandle) { + throw new NativeWindowException("Couldn't initialize GDL Display"); + } + } + initCounter++; + } + aDevice = new DefaultGraphicsDevice(NativeWindowFactory.TYPE_DEFAULT, displayHandle); + } + + protected void closeNative() { + if(0==displayHandle) { + throw new NativeWindowException("displayHandle null; initCnt "+initCounter); + } + synchronized(Display.class) { + if(initCounter>0) { + initCounter--; + if(0==initCounter) { + DestroyDisplay(displayHandle); + } + } + } + } + + protected void dispatchMessages() { + if(0!=displayHandle) { + DispatchMessages(displayHandle, focusedWindow); + } + } + + protected void setFocus(Window focus) { + focusedWindow = focus; + } + + private long displayHandle = 0; + private Window focusedWindow = null; + private native long CreateDisplay(); + private native void DestroyDisplay(long displayHandle); + private native void DispatchMessages(long displayHandle, Window focusedWindow); +} + diff --git a/src/newt/classes/com/jogamp/newt/intel/gdl/Screen.java b/src/newt/classes/com/jogamp/newt/intel/gdl/Screen.java new file mode 100644 index 000000000..873d1d009 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/intel/gdl/Screen.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.intel.gdl; + +import com.jogamp.newt.impl.*; +import javax.media.nativewindow.*; + +public class Screen extends com.jogamp.newt.Screen { + + static { + Display.initSingleton(); + } + + public Screen() { + } + + protected void createNative(int index) { + AbstractGraphicsDevice adevice = getDisplay().getGraphicsDevice(); + GetScreenInfo(adevice.getHandle(), index); + aScreen = new DefaultGraphicsScreen(adevice, index); + } + + protected void closeNative() { } + + //---------------------------------------------------------------------- + // Internals only + // + + protected static native boolean initIDs(); + private native void GetScreenInfo(long displayHandle, int screen_idx); + + // called by GetScreenInfo() .. + private void screenCreated(int width, int height) { + setScreenSize(width, height); + } +} + diff --git a/src/newt/classes/com/jogamp/newt/intel/gdl/Window.java b/src/newt/classes/com/jogamp/newt/intel/gdl/Window.java new file mode 100644 index 000000000..879fc6134 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/intel/gdl/Window.java @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.intel.gdl; + +import javax.media.nativewindow.*; + +public class Window extends com.jogamp.newt.Window { + static { + Display.initSingleton(); + } + + public Window() { + } + + static long nextWindowHandle = 1; + + protected void createNative(long parentWindowHandle, Capabilities caps) { + if(0!=parentWindowHandle) { + throw new NativeWindowException("GDL Window does not support window parenting"); + } + AbstractGraphicsScreen aScreen = screen.getGraphicsScreen(); + AbstractGraphicsDevice aDevice = screen.getDisplay().getGraphicsDevice(); + + config = GraphicsConfigurationFactory.getFactory(aDevice).chooseGraphicsConfiguration(caps, null, aScreen); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + + synchronized(Window.class) { + windowHandle = nextWindowHandle++; + } + } + + protected void closeNative() { + if(0!=surfaceHandle) { + synchronized(Window.class) { + CloseSurface(getDisplayHandle(), surfaceHandle); + } + surfaceHandle = 0; + ((Display)screen.getDisplay()).setFocus(null); + } + } + + public void setVisible(boolean visible) { + if(this.visible!=visible) { + this.visible=visible; + if(visible && 0==surfaceHandle) { + synchronized(Window.class) { + AbstractGraphicsDevice aDevice = screen.getDisplay().getGraphicsDevice(); + surfaceHandle = CreateSurface(aDevice.getHandle(), screen.getWidth(), screen.getHeight(), x, y, width, height); + } + if (surfaceHandle == 0) { + throw new NativeWindowException("Error creating window"); + } + ((Display)screen.getDisplay()).setFocus(this); + } + } + } + + public void setSize(int width, int height) { + Screen screen = (Screen) getScreen(); + if((x+width)>screen.getWidth()) { + width=screen.getWidth()-x; + } + if((y+height)>screen.getHeight()) { + height=screen.getHeight()-y; + } + this.width = width; + this.height = height; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + if(0!=surfaceHandle) { + SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, width, height); + } + } + + public void setPosition(int x, int y) { + Screen screen = (Screen) getScreen(); + if((x+width)>screen.getWidth()) { + x=screen.getWidth()-width; + } + if((y+height)>screen.getHeight()) { + y=screen.getHeight()-height; + } + this.x = x; + this.y = y; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + if(0!=surfaceHandle) { + SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, width, height); + } + } + + public boolean setFullscreen(boolean fullscreen) { + if(this.fullscreen!=fullscreen) { + int x,y,w,h; + this.fullscreen=fullscreen; + if(fullscreen) { + x = 0; y = 0; + w = screen.getWidth(); + h = screen.getHeight(); + } else { + x = nfs_x; + y = nfs_y; + w = nfs_width; + h = nfs_height; + } + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("IntelGDL Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); + } + if(0!=surfaceHandle) { + SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, w, h); + } + } + return fullscreen; + } + + public void requestFocus() { + ((Display)screen.getDisplay()).setFocus(this); + } + + public long getSurfaceHandle() { + return surfaceHandle; + } + + //---------------------------------------------------------------------- + // Internals only + // + + protected static native boolean initIDs(); + private native long CreateSurface(long displayHandle, int scrn_width, int scrn_height, int x, int y, int width, int height); + private native void CloseSurface(long displayHandle, long surfaceHandle); + private native void SetBounds0(long surfaceHandle, int scrn_width, int scrn_height, int x, int y, int width, int height); + + private void updateBounds(int x, int y, int width, int height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + private long surfaceHandle; + private int nfs_width, nfs_height, nfs_x, nfs_y; +} diff --git a/src/newt/classes/com/jogamp/newt/macosx/MacDisplay.java b/src/newt/classes/com/jogamp/newt/macosx/MacDisplay.java new file mode 100755 index 000000000..2f86125f8 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/macosx/MacDisplay.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.macosx; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.macosx.*; +import com.jogamp.newt.*; +import com.jogamp.newt.impl.*; +import com.jogamp.newt.util.MainThread; + +public class MacDisplay extends Display { + static { + NativeLibLoader.loadNEWT(); + + if(!initNSApplication()) { + throw new NativeWindowException("Failed to initialize native Application hook"); + } + if(!MacWindow.initIDs()) { + throw new NativeWindowException("Failed to initialize jmethodIDs"); + } + if(DEBUG) System.out.println("MacDisplay.init App and IDs OK "+Thread.currentThread().getName()); + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + public MacDisplay() { + } + + class DispatchAction implements Runnable { + public void run() { + dispatchMessages0(); + } + } + private DispatchAction dispatchAction = new DispatchAction(); + + public void dispatchMessages() { + MainThread.invoke(false, dispatchAction); + } + + protected void createNative() { + aDevice = new MacOSXGraphicsDevice(); + } + + protected void closeNative() { } + + private static native boolean initNSApplication(); + protected native void dispatchMessages0(); +} + diff --git a/src/newt/classes/com/jogamp/newt/macosx/MacScreen.java b/src/newt/classes/com/jogamp/newt/macosx/MacScreen.java new file mode 100755 index 000000000..92f8e908c --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/macosx/MacScreen.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.macosx; + +import com.jogamp.newt.*; +import javax.media.nativewindow.*; + +public class MacScreen extends Screen { + static { + MacDisplay.initSingleton(); + } + + public MacScreen() { + } + + protected void createNative(int index) { + aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); + setScreenSize(getWidthImpl(getIndex()), getHeightImpl(getIndex())); + } + + protected void closeNative() { } + + private static native int getWidthImpl(int scrn_idx); + private static native int getHeightImpl(int scrn_idx); +} diff --git a/src/newt/classes/com/jogamp/newt/macosx/MacWindow.java b/src/newt/classes/com/jogamp/newt/macosx/MacWindow.java new file mode 100755 index 000000000..06e73caa5 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/macosx/MacWindow.java @@ -0,0 +1,600 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.macosx; + +import javax.media.nativewindow.*; + +import com.jogamp.newt.util.MainThread; +import com.jogamp.newt.*; +import com.jogamp.newt.impl.*; + +public class MacWindow extends Window { + + // Window styles + private static final int NSBorderlessWindowMask = 0; + private static final int NSTitledWindowMask = 1 << 0; + private static final int NSClosableWindowMask = 1 << 1; + private static final int NSMiniaturizableWindowMask = 1 << 2; + private static final int NSResizableWindowMask = 1 << 3; + + // Window backing store types + private static final int NSBackingStoreRetained = 0; + private static final int NSBackingStoreNonretained = 1; + private static final int NSBackingStoreBuffered = 2; + + // Key constants handled differently on Mac OS X than other platforms + private static final int NSUpArrowFunctionKey = 0xF700; + private static final int NSDownArrowFunctionKey = 0xF701; + private static final int NSLeftArrowFunctionKey = 0xF702; + private static final int NSRightArrowFunctionKey = 0xF703; + private static final int NSF1FunctionKey = 0xF704; + private static final int NSF2FunctionKey = 0xF705; + private static final int NSF3FunctionKey = 0xF706; + private static final int NSF4FunctionKey = 0xF707; + private static final int NSF5FunctionKey = 0xF708; + private static final int NSF6FunctionKey = 0xF709; + private static final int NSF7FunctionKey = 0xF70A; + private static final int NSF8FunctionKey = 0xF70B; + private static final int NSF9FunctionKey = 0xF70C; + private static final int NSF10FunctionKey = 0xF70D; + private static final int NSF11FunctionKey = 0xF70E; + private static final int NSF12FunctionKey = 0xF70F; + private static final int NSF13FunctionKey = 0xF710; + private static final int NSF14FunctionKey = 0xF711; + private static final int NSF15FunctionKey = 0xF712; + private static final int NSF16FunctionKey = 0xF713; + private static final int NSF17FunctionKey = 0xF714; + private static final int NSF18FunctionKey = 0xF715; + private static final int NSF19FunctionKey = 0xF716; + private static final int NSF20FunctionKey = 0xF717; + private static final int NSF21FunctionKey = 0xF718; + private static final int NSF22FunctionKey = 0xF719; + private static final int NSF23FunctionKey = 0xF71A; + private static final int NSF24FunctionKey = 0xF71B; + private static final int NSF25FunctionKey = 0xF71C; + private static final int NSF26FunctionKey = 0xF71D; + private static final int NSF27FunctionKey = 0xF71E; + private static final int NSF28FunctionKey = 0xF71F; + private static final int NSF29FunctionKey = 0xF720; + private static final int NSF30FunctionKey = 0xF721; + private static final int NSF31FunctionKey = 0xF722; + private static final int NSF32FunctionKey = 0xF723; + private static final int NSF33FunctionKey = 0xF724; + private static final int NSF34FunctionKey = 0xF725; + private static final int NSF35FunctionKey = 0xF726; + private static final int NSInsertFunctionKey = 0xF727; + private static final int NSDeleteFunctionKey = 0xF728; + private static final int NSHomeFunctionKey = 0xF729; + private static final int NSBeginFunctionKey = 0xF72A; + private static final int NSEndFunctionKey = 0xF72B; + private static final int NSPageUpFunctionKey = 0xF72C; + private static final int NSPageDownFunctionKey = 0xF72D; + private static final int NSPrintScreenFunctionKey = 0xF72E; + private static final int NSScrollLockFunctionKey = 0xF72F; + private static final int NSPauseFunctionKey = 0xF730; + private static final int NSSysReqFunctionKey = 0xF731; + private static final int NSBreakFunctionKey = 0xF732; + private static final int NSResetFunctionKey = 0xF733; + private static final int NSStopFunctionKey = 0xF734; + private static final int NSMenuFunctionKey = 0xF735; + private static final int NSUserFunctionKey = 0xF736; + private static final int NSSystemFunctionKey = 0xF737; + private static final int NSPrintFunctionKey = 0xF738; + private static final int NSClearLineFunctionKey = 0xF739; + private static final int NSClearDisplayFunctionKey = 0xF73A; + private static final int NSInsertLineFunctionKey = 0xF73B; + private static final int NSDeleteLineFunctionKey = 0xF73C; + private static final int NSInsertCharFunctionKey = 0xF73D; + private static final int NSDeleteCharFunctionKey = 0xF73E; + private static final int NSPrevFunctionKey = 0xF73F; + private static final int NSNextFunctionKey = 0xF740; + private static final int NSSelectFunctionKey = 0xF741; + private static final int NSExecuteFunctionKey = 0xF742; + private static final int NSUndoFunctionKey = 0xF743; + private static final int NSRedoFunctionKey = 0xF744; + private static final int NSFindFunctionKey = 0xF745; + private static final int NSHelpFunctionKey = 0xF746; + private static final int NSModeSwitchFunctionKey = 0xF747; + + private volatile long surfaceHandle; + private long parentWindowHandle; + + // non fullscreen dimensions .. + private int nfs_width, nfs_height, nfs_x, nfs_y; + private final Insets insets = new Insets(0,0,0,0); + + static { + MacDisplay.initSingleton(); + } + + public MacWindow() { + } + + protected void createNative(long parentWindowHandle, Capabilities caps) { + this.parentWindowHandle=parentWindowHandle; + config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + } + + class CloseAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.CloseAction "+Thread.currentThread().getName()); + if (windowHandle != 0) { + close0(windowHandle); + windowHandle = 0; + } + } finally { + nsViewLock.unlock(); + } + } + } + private CloseAction closeAction = new CloseAction(); + + protected void closeNative() { + MainThread.invoke(true, closeAction); + } + + public long getWindowHandle() { + nsViewLock.lock(); + try { + return windowHandle; + } finally { + nsViewLock.unlock(); + } + } + + public long getSurfaceHandle() { + nsViewLock.lock(); + try { + return surfaceHandle; + } finally { + nsViewLock.unlock(); + } + } + + class EnsureWindowCreatedAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + createWindow(parentWindowHandle, false); + } finally { + nsViewLock.unlock(); + } + } + } + private EnsureWindowCreatedAction ensureWindowCreatedAction = + new EnsureWindowCreatedAction(); + + public Insets getInsets() { + // in order to properly calculate insets we need the window to be + // created + MainThread.invoke(true, ensureWindowCreatedAction); + nsViewLock.lock(); + try { + return (Insets) insets.clone(); + } finally { + nsViewLock.unlock(); + } + } + + private ToolkitLock nsViewLock = new ToolkitLock() { + private Thread owner; + private int recursionCount; + + public synchronized void lock() { + Thread cur = Thread.currentThread(); + if (owner == cur) { + ++recursionCount; + return; + } + while (owner != null) { + try { + wait(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + owner = cur; + } + + public synchronized void unlock() { + if (owner != Thread.currentThread()) { + throw new RuntimeException("Not owner"); + } + if (recursionCount > 0) { + --recursionCount; + return; + } + owner = null; + notifyAll(); + } + }; + + public synchronized int lockSurface() throws NativeWindowException { + nsViewLock.lock(); + return super.lockSurface(); + } + + public void unlockSurface() { + super.unlockSurface(); + nsViewLock.unlock(); + } + + class VisibleAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.VisibleAction "+visible+" "+Thread.currentThread().getName()); + if (visible) { + createWindow(parentWindowHandle, false); + if (windowHandle != 0) { + makeKeyAndOrderFront(windowHandle); + } + } else { + if (windowHandle != 0) { + orderOut(windowHandle); + } + } + } finally { + nsViewLock.unlock(); + } + } + } + private VisibleAction visibleAction = new VisibleAction(); + + public void setVisible(boolean visible) { + this.visible = visible; + MainThread.invoke(true, visibleAction); + } + + class TitleAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if (windowHandle != 0) { + setTitle0(windowHandle, title); + } + } finally { + nsViewLock.unlock(); + } + } + } + private TitleAction titleAction = new TitleAction(); + + public void setTitle(String title) { + super.setTitle(title); + MainThread.invoke(true, titleAction); + } + + class FocusAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if (windowHandle != 0) { + makeKey(windowHandle); + } + } finally { + nsViewLock.unlock(); + } + } + } + private FocusAction focusAction = new FocusAction(); + + public void requestFocus() { + super.requestFocus(); + MainThread.invoke(true, focusAction); + } + + class SizeAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if (windowHandle != 0) { + setContentSize(windowHandle, width, height); + } + } finally { + nsViewLock.unlock(); + } + } + } + private SizeAction sizeAction = new SizeAction(); + + public void setSize(int width, int height) { + this.width=width; + this.height=height; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + MainThread.invoke(true, sizeAction); + } + + class PositionAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if (windowHandle != 0) { + setFrameTopLeftPoint(parentWindowHandle, windowHandle, x, y); + } + } finally { + nsViewLock.unlock(); + } + } + } + private PositionAction positionAction = new PositionAction(); + + public void setPosition(int x, int y) { + this.x=x; + this.y=y; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + MainThread.invoke(true, positionAction); + } + + class FullscreenAction implements Runnable { + public void run() { + nsViewLock.lock(); + try { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("MacWindow fs: "+fullscreen+" "+x+"/"+y+" "+width+"x"+height); + } + createWindow(parentWindowHandle, true); + if (windowHandle != 0) { + makeKeyAndOrderFront(windowHandle); + } + } finally { + nsViewLock.unlock(); + } + } + } + private FullscreenAction fullscreenAction = new FullscreenAction(); + + public boolean setFullscreen(boolean fullscreen) { + if(this.fullscreen!=fullscreen) { + this.fullscreen=fullscreen; + if(fullscreen) { + x = 0; + y = 0; + width = screen.getWidth(); + height = screen.getHeight(); + } else { + x = nfs_x; + y = nfs_y; + width = nfs_width; + height = nfs_height; + } + MainThread.invoke(true, fullscreenAction); + } + return fullscreen; + } + + private void sizeChanged(int newWidth, int newHeight) { + if (DEBUG_IMPLEMENTATION) { + System.out.println(Thread.currentThread().getName()+" Size changed to " + newWidth + ", " + newHeight); + } + width = newWidth; + height = newHeight; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + if (DEBUG_IMPLEMENTATION) { + System.out.println(" Posted WINDOW_RESIZED event"); + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + } + + private void insetsChanged(int left, int top, int right, int bottom) { + if (DEBUG_IMPLEMENTATION) { + System.out.println(Thread.currentThread().getName()+ + " Insets changed to " + left + ", " + top + ", " + right + ", " + bottom); + } + if (left != -1 && top != -1 && right != -1 && bottom != -1) { + insets.left = left; + insets.top = top; + insets.right = right; + insets.bottom = bottom; + } + } + + private void positionChanged(int newX, int newY) { + if (DEBUG_IMPLEMENTATION) { + System.out.println(Thread.currentThread().getName()+" Position changed to " + newX + ", " + newY); + } + x = newX; + y = newY; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + if (DEBUG_IMPLEMENTATION) { + System.out.println(" Posted WINDOW_MOVED event"); + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); + } + + private void focusChanged(boolean focusGained) { + if (focusGained) { + sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); + } else { + sendWindowEvent(WindowEvent.EVENT_WINDOW_LOST_FOCUS); + } + } + + private char convertKeyChar(char keyChar) { + if (keyChar == '\r') { + // Turn these into \n + return '\n'; + } + + if (keyChar >= NSUpArrowFunctionKey && keyChar <= NSModeSwitchFunctionKey) { + switch (keyChar) { + case NSUpArrowFunctionKey: return KeyEvent.VK_UP; + case NSDownArrowFunctionKey: return KeyEvent.VK_DOWN; + case NSLeftArrowFunctionKey: return KeyEvent.VK_LEFT; + case NSRightArrowFunctionKey: return KeyEvent.VK_RIGHT; + case NSF1FunctionKey: return KeyEvent.VK_F1; + case NSF2FunctionKey: return KeyEvent.VK_F2; + case NSF3FunctionKey: return KeyEvent.VK_F3; + case NSF4FunctionKey: return KeyEvent.VK_F4; + case NSF5FunctionKey: return KeyEvent.VK_F5; + case NSF6FunctionKey: return KeyEvent.VK_F6; + case NSF7FunctionKey: return KeyEvent.VK_F7; + case NSF8FunctionKey: return KeyEvent.VK_F8; + case NSF9FunctionKey: return KeyEvent.VK_F9; + case NSF10FunctionKey: return KeyEvent.VK_F10; + case NSF11FunctionKey: return KeyEvent.VK_F11; + case NSF12FunctionKey: return KeyEvent.VK_F12; + case NSF13FunctionKey: return KeyEvent.VK_F13; + case NSF14FunctionKey: return KeyEvent.VK_F14; + case NSF15FunctionKey: return KeyEvent.VK_F15; + case NSF16FunctionKey: return KeyEvent.VK_F16; + case NSF17FunctionKey: return KeyEvent.VK_F17; + case NSF18FunctionKey: return KeyEvent.VK_F18; + case NSF19FunctionKey: return KeyEvent.VK_F19; + case NSF20FunctionKey: return KeyEvent.VK_F20; + case NSF21FunctionKey: return KeyEvent.VK_F21; + case NSF22FunctionKey: return KeyEvent.VK_F22; + case NSF23FunctionKey: return KeyEvent.VK_F23; + case NSF24FunctionKey: return KeyEvent.VK_F24; + case NSInsertFunctionKey: return KeyEvent.VK_INSERT; + case NSDeleteFunctionKey: return KeyEvent.VK_DELETE; + case NSHomeFunctionKey: return KeyEvent.VK_HOME; + case NSBeginFunctionKey: return KeyEvent.VK_BEGIN; + case NSEndFunctionKey: return KeyEvent.VK_END; + case NSPageUpFunctionKey: return KeyEvent.VK_PAGE_UP; + case NSPageDownFunctionKey: return KeyEvent.VK_PAGE_DOWN; + case NSPrintScreenFunctionKey: return KeyEvent.VK_PRINTSCREEN; + case NSScrollLockFunctionKey: return KeyEvent.VK_SCROLL_LOCK; + case NSPauseFunctionKey: return KeyEvent.VK_PAUSE; + // Not handled: + // NSSysReqFunctionKey + // NSBreakFunctionKey + // NSResetFunctionKey + case NSStopFunctionKey: return KeyEvent.VK_STOP; + // Not handled: + // NSMenuFunctionKey + // NSUserFunctionKey + // NSSystemFunctionKey + // NSPrintFunctionKey + // NSClearLineFunctionKey + // NSClearDisplayFunctionKey + // NSInsertLineFunctionKey + // NSDeleteLineFunctionKey + // NSInsertCharFunctionKey + // NSDeleteCharFunctionKey + // NSPrevFunctionKey + // NSNextFunctionKey + // NSSelectFunctionKey + // NSExecuteFunctionKey + // NSUndoFunctionKey + // NSRedoFunctionKey + // NSFindFunctionKey + // NSHelpFunctionKey + // NSModeSwitchFunctionKey + default: break; + } + } + + // NSEvent's charactersIgnoringModifiers doesn't ignore the shift key + if (keyChar >= 'a' && keyChar <= 'z') { + return Character.toUpperCase(keyChar); + } + + return keyChar; + } + + protected void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { + int key = convertKeyChar(keyChar); + if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.sendKeyEvent "+Thread.currentThread().getName()); + // Note that we send the key char for the key code on this + // platform -- we do not get any useful key codes out of the system + super.sendKeyEvent(eventType, modifiers, key, keyChar); + } + + private void createWindow(long parentWindowHandle, boolean recreate) { + if(0!=windowHandle && !recreate) { + return; + } + if(0!=windowHandle) { + // save the view .. close the window + surfaceHandle = changeContentView(parentWindowHandle, windowHandle, 0); + if(recreate && 0==surfaceHandle) { + throw new NativeWindowException("Internal Error - recreate, window but no view"); + } + close0(windowHandle); + windowHandle=0; + } else { + surfaceHandle = 0; + } + windowHandle = createWindow0(parentWindowHandle, + getX(), getY(), getWidth(), getHeight(), fullscreen, + (isUndecorated() ? + NSBorderlessWindowMask : + NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask), + NSBackingStoreBuffered, + getScreen().getIndex(), surfaceHandle); + if (windowHandle == 0) { + throw new NativeWindowException("Could create native window "+Thread.currentThread().getName()+" "+this); + } + surfaceHandle = contentView(windowHandle); + setTitle0(windowHandle, getTitle()); + // don't make the window visible on window creation +// makeKeyAndOrderFront(windowHandle); + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); + } + + protected static native boolean initIDs(); + private native long createWindow0(long parentWindowHandle, int x, int y, int w, int h, + boolean fullscreen, int windowStyle, + int backingStoreType, + int screen_idx, long view); + private native void makeKeyAndOrderFront(long window); + private native void makeKey(long window); + private native void orderOut(long window); + private native void close0(long window); + private native void setTitle0(long window, String title); + private native long contentView(long window); + private native long changeContentView(long parentWindowHandle, long window, long view); + private native void setContentSize(long window, int w, int h); + private native void setFrameTopLeftPoint(long parentWindowHandle, long window, int x, int y); +} diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java new file mode 100644 index 000000000..800e38105 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -0,0 +1,628 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.opengl; + +import com.jogamp.newt.*; +import javax.media.nativewindow.*; +import javax.media.opengl.*; +import com.jogamp.opengl.impl.GLDrawableHelper; +import java.util.*; + +/** + * An implementation of {@link Window} which is customized for OpenGL + * use, and which implements the {@link javax.media.opengl.GLAutoDrawable} interface. + *

+ * This implementation does not make the OpenGL context current
+ * before calling the various input EventListener callbacks (MouseListener, KeyListener, + * etc.).
+ * This design decision is made to favor a more performant and simplified + * implementation, as well as the event dispatcher shall be allowed + * not having a notion about OpenGL. + *

+ */ +public class GLWindow extends Window implements GLAutoDrawable { + private static List/*GLWindow*/ glwindows = new ArrayList(); + + private boolean ownerOfWinScrDpy; + private Window window; + private boolean runPumpMessages; + + /** Constructor. Do not call this directly -- use {@link + create()} instead. */ + protected GLWindow(Window window, boolean ownerOfWinScrDpy) { + this.ownerOfWinScrDpy = ownerOfWinScrDpy; + this.window = window; + this.window.setAutoDrawableClient(true); + this.runPumpMessages = ( null == getScreen().getDisplay().getEDT() ) ; + window.addWindowListener(new WindowListener() { + public void windowResized(WindowEvent e) { + sendReshape = true; + } + + public void windowMoved(WindowEvent e) { + } + + public void windowGainedFocus(WindowEvent e) { + } + + public void windowLostFocus(WindowEvent e) { + } + + public void windowDestroyNotify(WindowEvent e) { + sendDestroy = true; + } + }); + + List newglw = (List) ((ArrayList) glwindows).clone(); + newglw.add(this); + glwindows=newglw; + } + + /** Creates a new GLWindow on the local display, screen 0, with a + dummy visual ID, and with the default GLCapabilities. */ + public static GLWindow create() { + return create(null, null, false); + } + + public static GLWindow create(boolean undecorated) { + return create(null, null, undecorated); + } + + /** Creates a new GLWindow referring to the given window. */ + public static GLWindow create(Window window) { + return create(window, null, false); + } + public static GLWindow create(GLCapabilities caps) { + return create(null, caps, false); + } + + /** Creates a new GLWindow on the local display, screen 0, with a + dummy visual ID, and with the given GLCapabilities. */ + public static GLWindow create(GLCapabilities caps, boolean undecorated) { + return create(null, caps, undecorated); + } + + /** Either or: window (prio), or caps and undecorated (2nd choice) */ + private static GLWindow create(Window window, + GLCapabilities caps, + boolean undecorated) { + Display display; + boolean ownerOfWinScrDpy=false; + if (window == null) { + if (caps == null) { + caps = new GLCapabilities(null); // default .. + } + ownerOfWinScrDpy = true; + display = NewtFactory.createDisplay(null); // local display + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + window = NewtFactory.createWindow(screen, caps, undecorated); + } + + return new GLWindow(window, ownerOfWinScrDpy); + } + + /** + * EXPERIMENTAL
+ * Enable or disables running the {@link Display#pumpMessages} in the {@link #display()} call.
+ * The default behavior is to run {@link Display#pumpMessages}.

+ * + * The idea was that in a single threaded environment with one {@link Display} and many {@link Window}'s, + * a performance benefit was expected while disabling the implicit {@link Display#pumpMessages} and + * do it once via {@link GLWindow#runCurrentThreadPumpMessage()}
+ * This could not have been verified. No measurable difference could have been recognized.

+ * + * Best performance has been achieved with one GLWindow per thread.
+ * + * Enabling local pump messages while using the EDT, + * {@link com.jogamp.newt.NewtFactory#setUseEDT(boolean)}, + * will result in an exception. + * + * @deprecated EXPERIMENTAL, semantic is about to be removed after further verification. + */ + public void setRunPumpMessages(boolean onoff) { + if( onoff && null!=getScreen().getDisplay().getEDT() ) { + throw new GLException("GLWindow.setRunPumpMessages(true) - Can't do with EDT on"); + } + runPumpMessages = onoff; + } + + protected void createNative(long parentWindowHandle, Capabilities caps) { + shouldNotCallThis(); + } + + protected void closeNative() { + shouldNotCallThis(); + } + + protected void dispose(boolean regenerate, boolean sendEvent) { + if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { + Exception e1 = new Exception("GLWindow.dispose("+regenerate+") "+Thread.currentThread()+", 1"); + e1.printStackTrace(); + } + + if(sendEvent) { + sendDisposeEvent(); + } + + if (context != null) { + context.destroy(); + } + if (drawable != null) { + drawable.setRealized(false); + } + + if(regenerate) { + if(null==window) { + throw new GLException("GLWindow.dispose(true): null window"); + } + + // recreate GLDrawable, to reflect the new graphics configurations + NativeWindow nw; + if (window.getWrappedWindow() != null) { + nw = NativeWindowFactory.getNativeWindow(window.getWrappedWindow(), window.getGraphicsConfiguration()); + } else { + nw = window; + } + drawable = factory.createGLDrawable(nw); + drawable.setRealized(true); + context = drawable.createContext(null); + sendReshape = true; // ensure a reshape event is send .. + } + + if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { + System.out.println("GLWindow.dispose("+regenerate+") "+Thread.currentThread()+", fin: "+this); + } + } + + public synchronized void destroy() { + destroy(true); + } + + /** @param sendDisposeEvent should be false in a [time,reliable] critical shutdown */ + public synchronized void destroy(boolean sendDisposeEvent) { + if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { + Exception e1 = new Exception("GLWindow.destroy "+Thread.currentThread()+", 1: "+this); + e1.printStackTrace(); + } + + List newglw = (List) ((ArrayList) glwindows).clone(); + newglw.remove(this); + glwindows=newglw; + + dispose(false, sendDisposeEvent); + + if(null!=window) { + if(ownerOfWinScrDpy) { + window.destroy(true); + } + } + + drawable = null; + context = null; + window = null; + + if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { + System.out.println("GLWindow.destroy "+Thread.currentThread()+", fin: "+this); + } + } + + public boolean getPerfLogEnabled() { return perfLog; } + + public void enablePerfLog(boolean v) { + perfLog = v; + } + + public void setVisible(boolean visible) { + if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { + System.out.println(Thread.currentThread()+" GLWindow.setVisible("+visible+") START ; isVisible "+this.visible+" ; has context "+(null!=context)); + } + this.visible=visible; + window.setVisible(visible); + if (visible && context == null) { + NativeWindow nw; + if (window.getWrappedWindow() != null) { + nw = NativeWindowFactory.getNativeWindow(window.getWrappedWindow(), window.getGraphicsConfiguration()); + } else { + nw = window; + } + GLCapabilities glCaps = (GLCapabilities) nw.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + factory = GLDrawableFactory.getFactory(glCaps.getGLProfile()); + drawable = factory.createGLDrawable(nw); + drawable.setRealized(true); + context = drawable.createContext(null); + sendReshape = true; // ensure a reshape event is send .. + } + if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { + System.out.println(Thread.currentThread()+" GLWindow.setVisible("+visible+") END ; has context "+(null!=context)); + } + } + + public Screen getScreen() { + return window.getScreen(); + } + + public void setTitle(String title) { + window.setTitle(title); + } + + public String getTitle() { + return window.getTitle(); + } + + public void setUndecorated(boolean value) { + window.setUndecorated(value); + } + + public boolean isUndecorated() { + return window.isUndecorated(); + } + + public void setSize(int width, int height) { + window.setSize(width, height); + } + + public void setPosition(int x, int y) { + window.setPosition(x, y); + } + + public Insets getInsets() { + return window.getInsets(); + } + + public boolean setFullscreen(boolean fullscreen) { + return window.setFullscreen(fullscreen); + } + + public boolean isVisible() { + return window.isVisible(); + } + + public int getX() { + return window.getX(); + } + + public int getY() { + return window.getY(); + } + + public int getWidth() { + return window.getWidth(); + } + + public int getHeight() { + return window.getHeight(); + } + + public boolean isFullscreen() { + return window.isFullscreen(); + } + + public void addSurfaceUpdatedListener(SurfaceUpdatedListener l) { + window.addSurfaceUpdatedListener(l); + } + public void removeSurfaceUpdatedListener(SurfaceUpdatedListener l) { + window.removeSurfaceUpdatedListener(l); + } + public SurfaceUpdatedListener[] getSurfaceUpdatedListener() { + return window.getSurfaceUpdatedListener(); + } + public void surfaceUpdated(Object updater, NativeWindow window0, long when) { + window.surfaceUpdated(updater, window, when); + } + + public void addMouseListener(MouseListener l) { + window.addMouseListener(l); + } + + public void removeMouseListener(MouseListener l) { + window.removeMouseListener(l); + } + + public MouseListener[] getMouseListeners() { + return window.getMouseListeners(); + } + + public void addKeyListener(KeyListener l) { + window.addKeyListener(l); + } + + public void removeKeyListener(KeyListener l) { + window.removeKeyListener(l); + } + + public KeyListener[] getKeyListeners() { + return window.getKeyListeners(); + } + + public void addWindowListener(WindowListener l) { + window.addWindowListener(l); + } + + public void removeWindowListener(WindowListener l) { + window.removeWindowListener(l); + } + + public WindowListener[] getWindowListeners() { + return window.getWindowListeners(); + } + + public String toString() { + return "NEWT-GLWindow[ \n\tDrawable: "+drawable+", \n\tWindow: "+window+", \n\tHelper: "+helper+", \n\tFactory: "+factory+"]"; + } + + //---------------------------------------------------------------------- + // OpenGL-related methods and state + // + + private GLDrawableFactory factory; + private GLDrawable drawable; + private GLContext context; + private GLDrawableHelper helper = new GLDrawableHelper(); + // To make reshape events be sent immediately before a display event + private boolean sendReshape=false; + private boolean sendDestroy=false; + private boolean perfLog = false; + + public GLDrawableFactory getFactory() { + return factory; + } + + public void setContext(GLContext newCtx) { + context = newCtx; + } + + public GLContext getContext() { + return context; + } + + public GL getGL() { + if (context == null) { + return null; + } + return context.getGL(); + } + + public GL setGL(GL gl) { + if (context != null) { + context.setGL(gl); + return gl; + } + return null; + } + + public void addGLEventListener(GLEventListener listener) { + helper.addGLEventListener(listener); + } + + public void removeGLEventListener(GLEventListener listener) { + helper.removeGLEventListener(listener); + } + + public void display() { + display(false); + } + + public void display(boolean forceReshape) { + if(window!=null && drawable!=null && context != null) { + if(runPumpMessages) { + window.getScreen().getDisplay().pumpMessages(); + } + if(window.hasDeviceChanged() && GLAutoDrawable.SCREEN_CHANGE_ACTION_ENABLED) { + dispose(true, true); + } + if (sendDestroy) { + destroy(); + sendDestroy=false; + } else { + if(forceReshape) { + sendReshape = true; + } + helper.invokeGL(drawable, context, displayAction, initAction); + } + } + } + + private void sendDisposeEvent() { + if(drawable!=null && context != null) { + helper.invokeGL(drawable, context, disposeAction, null); + } + } + + /** This implementation uses a static value */ + public void setAutoSwapBufferMode(boolean onOrOff) { + helper.setAutoSwapBufferMode(onOrOff); + } + + /** This implementation uses a static value */ + public boolean getAutoSwapBufferMode() { + return helper.getAutoSwapBufferMode(); + } + + public void swapBuffers() { + if(drawable!=null && context != null) { + if (context != GLContext.getCurrent()) { + // Assume we should try to make the context current before swapping the buffers + helper.invokeGL(drawable, context, swapBuffersAction, initAction); + } else { + drawable.swapBuffers(); + } + } + } + + class InitAction implements Runnable { + public void run() { + helper.init(GLWindow.this); + startTime = System.currentTimeMillis(); + curTime = startTime; + if(perfLog) { + lastCheck = startTime; + totalFrames = 0; lastFrames = 0; + } + } + } + private InitAction initAction = new InitAction(); + + class DisposeAction implements Runnable { + public void run() { + helper.dispose(GLWindow.this); + } + } + private DisposeAction disposeAction = new DisposeAction(); + + class DisplayAction implements Runnable { + public void run() { + if (sendReshape) { + int width = getWidth(); + int height = getHeight(); + getGL().glViewport(0, 0, width, height); + helper.reshape(GLWindow.this, 0, 0, width, height); + sendReshape = false; + } + + helper.display(GLWindow.this); + + curTime = System.currentTimeMillis(); + totalFrames++; + + if(perfLog) { + long dt0, dt1; + lastFrames++; + dt0 = curTime-lastCheck; + if ( dt0 > 5000 ) { + dt1 = curTime-startTime; + System.out.println(dt0/1000 +"s: "+ lastFrames + "f, " + (lastFrames*1000)/dt0 + " fps, "+dt0/lastFrames+" ms/f; "+ + "total: "+ dt1/1000+"s, "+(totalFrames*1000)/dt1 + " fps, "+dt1/totalFrames+" ms/f"); + lastCheck=curTime; + lastFrames=0; + } + } + } + } + private DisplayAction displayAction = new DisplayAction(); + + public long getStartTime() { return startTime; } + public long getCurrentTime() { return curTime; } + public long getDuration() { return curTime-startTime; } + public int getTotalFrames() { return totalFrames; } + + private long startTime = 0; + private long curTime = 0; + private long lastCheck = 0; + private int totalFrames = 0, lastFrames = 0; + + class SwapBuffersAction implements Runnable { + public void run() { + drawable.swapBuffers(); + } + } + private SwapBuffersAction swapBuffersAction = new SwapBuffersAction(); + + //---------------------------------------------------------------------- + // GLDrawable methods + // + + public NativeWindow getNativeWindow() { + return null!=drawable ? drawable.getNativeWindow() : null; + } + + public synchronized int lockSurface() throws NativeWindowException { + if(null!=drawable) return drawable.getNativeWindow().lockSurface(); + return NativeWindow.LOCK_SURFACE_NOT_READY; + } + + public synchronized void unlockSurface() { + if(null!=drawable) drawable.getNativeWindow().unlockSurface(); + else throw new NativeWindowException("NEWT-GLWindow not locked"); + } + + public synchronized boolean isSurfaceLocked() { + if(null!=drawable) return drawable.getNativeWindow().isSurfaceLocked(); + return false; + } + + public synchronized Exception getLockedStack() { + if(null!=drawable) return drawable.getNativeWindow().getLockedStack(); + return null; + } + + public boolean surfaceSwap() { + if(null!=drawable) return drawable.getNativeWindow().surfaceSwap(); + return super.surfaceSwap(); + } + + public long getWindowHandle() { + if(null!=drawable) return drawable.getNativeWindow().getWindowHandle(); + return super.getWindowHandle(); + } + + public long getSurfaceHandle() { + if(null!=drawable) return drawable.getNativeWindow().getSurfaceHandle(); + return super.getSurfaceHandle(); + } + + //---------------------------------------------------------------------- + // GLDrawable methods that are not really needed + // + + public GLContext createContext(GLContext shareWith) { + return drawable.createContext(shareWith); + } + + public void setRealized(boolean realized) { + } + + public GLCapabilities getChosenGLCapabilities() { + if (drawable == null) { + throw new GLException("No drawable yet"); + } + + return drawable.getChosenGLCapabilities(); + } + + public GLProfile getGLProfile() { + if (drawable == null) { + throw new GLException("No drawable yet"); + } + + return drawable.getGLProfile(); + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private void shouldNotCallThis() { + throw new NativeWindowException("Should not call this"); + } +} diff --git a/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Display.java b/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Display.java new file mode 100644 index 000000000..a375181ac --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Display.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.opengl.broadcom.egl; + +import com.jogamp.newt.impl.*; +import com.jogamp.opengl.impl.egl.*; +import javax.media.nativewindow.*; +import javax.media.nativewindow.egl.*; + +public class Display extends com.jogamp.newt.Display { + + static { + NativeLibLoader.loadNEWT(); + + if (!Window.initIDs()) { + throw new NativeWindowException("Failed to initialize BCEGL Window jmethodIDs"); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + + public Display() { + } + + protected void createNative() { + long handle = CreateDisplay(Screen.fixedWidth, Screen.fixedHeight); + if (handle == EGL.EGL_NO_DISPLAY) { + throw new NativeWindowException("BC EGL CreateDisplay failed"); + } + aDevice = new EGLGraphicsDevice(handle); + } + + protected void closeNative() { + if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) { + DestroyDisplay(aDevice.getHandle()); + } + } + + protected void dispatchMessages() { + // n/a .. DispatchMessages(); + } + + private native long CreateDisplay(int width, int height); + private native void DestroyDisplay(long dpy); + private native void DispatchMessages(); +} + diff --git a/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Screen.java b/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Screen.java new file mode 100755 index 000000000..b4f07599b --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Screen.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.opengl.broadcom.egl; + +import javax.media.nativewindow.*; + +public class Screen extends com.jogamp.newt.Screen { + + static { + Display.initSingleton(); + } + + + public Screen() { + } + + protected void createNative(int index) { + aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); + setScreenSize(fixedWidth, fixedHeight); + } + + protected void closeNative() { } + + //---------------------------------------------------------------------- + // Internals only + // + + static final int fixedWidth = 1920; + static final int fixedHeight = 1080; +} + diff --git a/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Window.java b/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Window.java new file mode 100755 index 000000000..185dc97b9 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Window.java @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.opengl.broadcom.egl; + +import com.jogamp.opengl.impl.egl.*; +import javax.media.nativewindow.*; +import javax.media.opengl.GLCapabilities; +import javax.media.nativewindow.NativeWindowException; + +public class Window extends com.jogamp.newt.Window { + static { + Display.initSingleton(); + } + + public Window() { + } + + protected void createNative(long parentWindowHandle, Capabilities caps) { + if(0!=parentWindowHandle) { + throw new RuntimeException("Window parenting not supported (yet)"); + } + // query a good configuration .. even thought we drop this one + // and reuse the EGLUtil choosen one later. + config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + setSizeImpl(getScreen().getWidth(), getScreen().getHeight()); + } + + protected void closeNative() { + if(0!=windowHandleClose) { + CloseWindow(getDisplayHandle(), windowHandleClose); + } + } + + public void setVisible(boolean visible) { + if(this.visible!=visible) { + this.visible=visible; + if ( 0==windowHandle ) { + windowHandle = realizeWindow(true, width, height); + if (0 == windowHandle) { + throw new NativeWindowException("Error native Window Handle is null"); + } + } + clearEventMask(); + } + } + + public void setSize(int width, int height) { + System.err.println("setSize "+width+"x"+height+" n/a in BroadcomEGL"); + } + + void setSizeImpl(int width, int height) { + if(0!=windowHandle) { + // n/a in BroadcomEGL + System.err.println("BCEGL Window.setSizeImpl n/a in BroadcomEGL with realized window"); + } else { + if(DEBUG_IMPLEMENTATION) { + Exception e = new Exception("BCEGL Window.setSizeImpl() "+this.width+"x"+this.height+" -> "+width+"x"+height); + e.printStackTrace(); + } + this.width = width; + this.height = height; + } + } + + public void setPosition(int x, int y) { + // n/a in BroadcomEGL + System.err.println("setPosition n/a in BroadcomEGL"); + } + + public boolean setFullscreen(boolean fullscreen) { + // n/a in BroadcomEGL + System.err.println("setFullscreen n/a in BroadcomEGL"); + return false; + } + + public boolean surfaceSwap() { + if ( 0!=windowHandle ) { + SwapWindow(getDisplayHandle(), windowHandle); + return true; + } + return false; + } + + //---------------------------------------------------------------------- + // Internals only + // + + protected static native boolean initIDs(); + private native long CreateWindow(long eglDisplayHandle, boolean chromaKey, int width, int height); + private native void CloseWindow(long eglDisplayHandle, long eglWindowHandle); + private native void SwapWindow(long eglDisplayHandle, long eglWindowHandle); + + + private long realizeWindow(boolean chromaKey, int width, int height) { + if(DEBUG_IMPLEMENTATION) { + System.out.println("BCEGL Window.realizeWindow() with: chroma "+chromaKey+", "+width+"x"+height+", "+config); + } + long handle = CreateWindow(getDisplayHandle(), chromaKey, width, height); + if (0 == handle) { + throw new NativeWindowException("Error native Window Handle is null"); + } + windowHandleClose = handle; + return handle; + } + + private void windowCreated(int cfgID, int width, int height) { + this.width = width; + this.height = height; + GLCapabilities capsReq = (GLCapabilities) config.getRequestedCapabilities(); + config = EGLGraphicsConfiguration.create(capsReq, screen.getGraphicsScreen(), cfgID); + if (config == null) { + throw new NativeWindowException("Error creating EGLGraphicsConfiguration from id: "+cfgID+", "+this); + } + if(DEBUG_IMPLEMENTATION) { + System.out.println("BCEGL Window.windowCreated(): "+toHexString(cfgID)+", "+width+"x"+height+", "+config); + } + } + + private long windowHandleClose; +} diff --git a/src/newt/classes/com/jogamp/newt/opengl/kd/KDDisplay.java b/src/newt/classes/com/jogamp/newt/opengl/kd/KDDisplay.java new file mode 100755 index 000000000..b09568237 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/opengl/kd/KDDisplay.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.opengl.kd; + +import com.jogamp.newt.*; +import com.jogamp.newt.impl.*; +import com.jogamp.opengl.impl.egl.*; +import javax.media.nativewindow.*; +import javax.media.nativewindow.egl.*; + +public class KDDisplay extends Display { + + static { + NativeLibLoader.loadNEWT(); + + if (!KDWindow.initIDs()) { + throw new NativeWindowException("Failed to initialize KDWindow jmethodIDs"); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + + public KDDisplay() { + } + + protected void createNative() { + // FIXME: map name to EGL_*_DISPLAY + long handle = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY); + if (handle == EGL.EGL_NO_DISPLAY) { + throw new NativeWindowException("eglGetDisplay failed"); + } + if (!EGL.eglInitialize(handle, null, null)) { + throw new NativeWindowException("eglInitialize failed"); + } + aDevice = new EGLGraphicsDevice(handle); + } + + protected void closeNative() { + if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) { + EGL.eglTerminate(aDevice.getHandle()); + } + } + + protected void dispatchMessages() { + DispatchMessages(); + } + + private native void DispatchMessages(); +} + diff --git a/src/newt/classes/com/jogamp/newt/opengl/kd/KDScreen.java b/src/newt/classes/com/jogamp/newt/opengl/kd/KDScreen.java new file mode 100755 index 000000000..cd53c8152 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/opengl/kd/KDScreen.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.opengl.kd; + +import com.jogamp.newt.*; +import javax.media.nativewindow.*; + +public class KDScreen extends Screen { + static { + KDDisplay.initSingleton(); + } + + public KDScreen() { + } + + protected void createNative(int index) { + aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); + } + + protected void closeNative() { } + + // elevate access to this package .. + protected void setScreenSize(int w, int h) { + super.setScreenSize(w, h); + } +} diff --git a/src/newt/classes/com/jogamp/newt/opengl/kd/KDWindow.java b/src/newt/classes/com/jogamp/newt/opengl/kd/KDWindow.java new file mode 100755 index 000000000..555f54599 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/opengl/kd/KDWindow.java @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.opengl.kd; + +import com.jogamp.newt.*; +import com.jogamp.newt.impl.*; +import com.jogamp.opengl.impl.egl.*; +import javax.media.nativewindow.*; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; +import javax.media.nativewindow.NativeWindowException; + +public class KDWindow extends Window { + private static final String WINDOW_CLASS_NAME = "NewtWindow"; + // non fullscreen dimensions .. + private int nfs_width, nfs_height, nfs_x, nfs_y; + + static { + KDDisplay.initSingleton(); + } + + public KDWindow() { + } + + protected void createNative(long parentWindowHandle, Capabilities caps) { + if(0!=parentWindowHandle) { + throw new RuntimeException("Window parenting not supported (yet)"); + } + config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + + GLCapabilities eglCaps = (GLCapabilities)config.getChosenCapabilities(); + int[] eglAttribs = EGLGraphicsConfiguration.GLCapabilities2AttribList(eglCaps); + + windowHandle = 0; + eglWindowHandle = CreateWindow(getDisplayHandle(), eglAttribs); + if (eglWindowHandle == 0) { + throw new NativeWindowException("Error creating egl window: "+config); + } + setVisible0(eglWindowHandle, false); + windowHandleClose = eglWindowHandle; + } + + protected void closeNative() { + if(0!=windowHandleClose) { + CloseWindow(windowHandleClose, windowUserData); + windowUserData=0; + } + } + + public void setVisible(boolean visible) { + if(0!=eglWindowHandle && this.visible!=visible) { + this.visible=visible; + setVisible0(eglWindowHandle, visible); + if ( 0==windowHandle ) { + windowHandle = RealizeWindow(eglWindowHandle); + if (0 == windowHandle) { + throw new NativeWindowException("Error native Window Handle is null"); + } + } + clearEventMask(); + } + } + + public void setSize(int width, int height) { + if(0!=eglWindowHandle) { + setSize0(eglWindowHandle, width, height); + } + } + + public void setPosition(int x, int y) { + // n/a in KD + System.err.println("setPosition n/a in KD"); + } + + public boolean setFullscreen(boolean fullscreen) { + if(0!=eglWindowHandle && this.fullscreen!=fullscreen) { + this.fullscreen=fullscreen; + if(this.fullscreen) { + setFullScreen0(eglWindowHandle, true); + } else { + setFullScreen0(eglWindowHandle, false); + setSize0(eglWindowHandle, nfs_width, nfs_height); + } + } + return true; + } + + //---------------------------------------------------------------------- + // Internals only + // + + protected static native boolean initIDs(); + private native long CreateWindow(long displayHandle, int[] attributes); + private native long RealizeWindow(long eglWindowHandle); + private native int CloseWindow(long eglWindowHandle, long userData); + private native void setVisible0(long eglWindowHandle, boolean visible); + private native void setSize0(long eglWindowHandle, int width, int height); + private native void setFullScreen0(long eglWindowHandle, boolean fullscreen); + + private void windowCreated(long userData) { + windowUserData=userData; + } + + private void sizeChanged(int newWidth, int newHeight) { + width = newWidth; + height = newHeight; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } else { + ((KDScreen)screen).setScreenSize(width, height); + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + } + + private long eglWindowHandle; + private long windowHandleClose; + private long windowUserData; +} diff --git a/src/newt/classes/com/jogamp/newt/util/EventDispatchThread.java b/src/newt/classes/com/jogamp/newt/util/EventDispatchThread.java new file mode 100644 index 000000000..675c6f322 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/util/EventDispatchThread.java @@ -0,0 +1,240 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. 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 com.jogamp.newt.util; + +import com.jogamp.newt.Display; +import com.jogamp.newt.impl.Debug; +import java.util.*; + +public class EventDispatchThread { + public static final boolean DEBUG = Debug.debug("EDT"); + + private ThreadGroup threadGroup; + private volatile boolean shouldStop = false; + private TaskWorker taskWorker = null; + private Object taskWorkerLock = new Object(); + private ArrayList tasks = new ArrayList(); // one shot tasks + private Display display = null; + private String name; + private long edtPollGranularity = 10; + + public EventDispatchThread(Display display, ThreadGroup tg, String name) { + this.display = display; + this.threadGroup = tg; + this.name=new String("EDT-Display_"+display.getName()+"-"+name); + } + + public String getName() { return name; } + + public ThreadGroup getThreadGroup() { return threadGroup; } + + public void start() { + start(false); + } + + /** + * @param externalStimuli true indicates that another thread stimulates, + * ie. calls this TaskManager's run() loop method. + * Hence no own thread is started in this case. + * + * @return The started Runnable, which handles the run-loop. + * Usefull in combination with externalStimuli=true, + * so an external stimuli can call it. + */ + public Runnable start(boolean externalStimuli) { + synchronized(taskWorkerLock) { + if(null==taskWorker) { + taskWorker = new TaskWorker(threadGroup, name); + } + if(!taskWorker.isRunning()) { + shouldStop = false; + taskWorker.start(externalStimuli); + } + taskWorkerLock.notifyAll(); + } + return taskWorker; + } + + public void stop() { + synchronized(taskWorkerLock) { + if(null!=taskWorker && taskWorker.isRunning()) { + shouldStop = true; + } + taskWorkerLock.notifyAll(); + if(DEBUG) { + System.out.println(Thread.currentThread()+": EDT signal STOP"); + } + } + } + + public boolean isThreadEDT(Thread thread) { + return null!=taskWorker && taskWorker == thread; + } + + public boolean isCurrentThreadEDT() { + return null!=taskWorker && taskWorker == Thread.currentThread(); + } + + public boolean isRunning() { + return null!=taskWorker && taskWorker.isRunning() ; + } + + public void invokeLater(Runnable task) { + if(task == null) { + return; + } + synchronized(taskWorkerLock) { + if(null!=taskWorker && taskWorker.isRunning() && taskWorker != Thread.currentThread() ) { + tasks.add(task); + taskWorkerLock.notifyAll(); + } else { + // if !running or isEDTThread, do it right away + task.run(); + } + } + } + + public void invokeAndWait(Runnable task) { + if(task == null) { + return; + } + invokeLater(task); + waitOnWorker(); + } + + public void waitOnWorker() { + synchronized(taskWorkerLock) { + if(null!=taskWorker && taskWorker.isRunning() && tasks.size()>0 && taskWorker != Thread.currentThread() ) { + try { + taskWorkerLock.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + + public void waitUntilStopped() { + synchronized(taskWorkerLock) { + while(null!=taskWorker && taskWorker.isRunning() && taskWorker != Thread.currentThread() ) { + try { + taskWorkerLock.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + + class TaskWorker extends Thread { + boolean isRunning = false; + boolean externalStimuli = false; + + public TaskWorker(ThreadGroup tg, String name) { + super(tg, name); + } + + public synchronized boolean isRunning() { + return isRunning; + } + + public void start(boolean externalStimuli) throws IllegalThreadStateException { + synchronized(this) { + this.externalStimuli = externalStimuli; + isRunning = true; + } + if(!externalStimuli) { + super.start(); + } + } + + /** + * Utilizing taskWorkerLock only for local resources and task execution, + * not for event dispatching. + */ + public void run() { + if(DEBUG) { + System.out.println(Thread.currentThread()+": EDT run() START"); + } + while(!shouldStop) { + try { + // wait for something todo + while(!shouldStop && tasks.size()==0) { + synchronized(taskWorkerLock) { + if(!shouldStop && tasks.size()==0) { + try { + taskWorkerLock.wait(edtPollGranularity); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + display.pumpMessages(); // event dispatch + } + if(!shouldStop && tasks.size()>0) { + synchronized(taskWorkerLock) { + if(!shouldStop && tasks.size()>0) { + Runnable task = (Runnable) tasks.remove(0); + task.run(); + taskWorkerLock.notifyAll(); + } + } + display.pumpMessages(); // event dispatch + } + } catch (Throwable t) { + // handle errors .. + t.printStackTrace(); + } finally { + // epilog - unlock locked stuff + } + if(externalStimuli) break; // no loop if called by external stimuli + } + synchronized(this) { + isRunning = !shouldStop; + } + if(!isRunning) { + synchronized(taskWorkerLock) { + taskWorkerLock.notifyAll(); + } + } + if(DEBUG) { + System.out.println(Thread.currentThread()+": EDT run() EXIT"); + } + } + } +} + diff --git a/src/newt/classes/com/jogamp/newt/util/MainThread.java b/src/newt/classes/com/jogamp/newt/util/MainThread.java new file mode 100644 index 000000000..6cd4f8c69 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/util/MainThread.java @@ -0,0 +1,307 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. 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 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.newt.*; +import com.jogamp.newt.impl.*; +import com.jogamp.newt.macosx.MacDisplay; +import com.jogamp.nativewindow.impl.NWReflection; + +/** + * NEWT Utility class MainThread

+ * + * This class provides a startup singleton main thread, + * from which a new thread with the users main class is launched.
+ * + * Such behavior is necessary for native windowing toolkits, + * where the windowing management must happen on the so called + * main thread e.g. for Mac OS X !
+ * + * Utilizing this class as a launchpad, now you are able to + * use a NEWT multithreaded application with window handling within the different threads, + * even on these restricted platforms.
+ * + * To support your NEWT Window platform, + * you have to pass your main thread actions to {@link #invoke invoke(..)}, + * have a look at the {@link com.jogamp.newt.macosx.MacWindow MacWindow} implementation.
+ * TODO: Some hardcoded dependencies exist in this implementation, + * where you have to patch this code or factor it out.

+ * + * If your platform is not Mac OS X, but you want to test your code without modifying + * this class, you have to set the system property newt.MainThread.force to true.

+ * + * The code is compatible with all other platform, which support multithreaded windowing handling. + * Since those platforms won't trigger the main thread serialization, the main method + * will be simply executed, in case you haven't set newt.MainThread.force to true.

+ * + * Test case on Mac OS X (or any other platform): +

+    java -XstartOnFirstThread com.jogamp.newt.util.MainThread demos.es1.RedSquare -GL2 -GL2 -GL2 -GL2
+ 
+ * Which starts 4 threads, each with a window and OpenGL rendering.
+ */ +public class MainThread { + private static AccessControlContext localACC = AccessController.getContext(); + public static final boolean USE_MAIN_THREAD = NativeWindowFactory.TYPE_MACOSX.equals(NativeWindowFactory.getNativeWindowType(false)) || + Debug.getBooleanProperty("newt.MainThread.force", true, localACC); + + protected static final boolean DEBUG = Debug.debug("MainThread"); + + private static boolean isExit=false; + private static volatile boolean isRunning=false; + private static Object taskWorkerLock=new Object(); + private static boolean shouldStop; + private static ArrayList tasks; + private static ArrayList tasksBlock; + private static Thread mainThread; + + static class MainAction extends Thread { + private String mainClassName; + private String[] mainClassArgs; + + private Class mainClass; + private Method mainClassMain; + + public MainAction(String mainClassName, String[] mainClassArgs) { + this.mainClassName=mainClassName; + this.mainClassArgs=mainClassArgs; + } + + public void run() { + if ( USE_MAIN_THREAD ) { + // we have to start first to provide the service .. + MainThread.waitUntilRunning(); + } + + // start user app .. + try { + Class mainClass = NWReflection.getClass(mainClassName, true); + if(null==mainClass) { + throw new RuntimeException(new ClassNotFoundException("MainThread couldn't find main class "+mainClassName)); + } + try { + mainClassMain = mainClass.getDeclaredMethod("main", new Class[] { String[].class }); + mainClassMain.setAccessible(true); + } catch (Throwable t) { + throw new RuntimeException(t); + } + if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" invoke "+mainClassName); + mainClassMain.invoke(null, new Object[] { mainClassArgs } ); + } catch (InvocationTargetException ite) { + ite.getTargetException().printStackTrace(); + } catch (Throwable t) { + t.printStackTrace(); + } + + if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" user app fin"); + + if ( USE_MAIN_THREAD ) { + MainThread.exit(); + if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" MainThread fin - exit"); + System.exit(0); + } + } + } + private static MainAction mainAction; + + /** Your new java application main entry, which pipelines your application */ + public static void main(String[] args) { + if(DEBUG) System.err.println("MainThread.main(): "+Thread.currentThread().getName()+" USE_MAIN_THREAD "+ USE_MAIN_THREAD ); + + if(args.length==0) { + return; + } + + String mainClassName=args[0]; + String[] mainClassArgs=new String[args.length-1]; + if(args.length>1) { + System.arraycopy(args, 1, mainClassArgs, 0, args.length-1); + } + + NativeLibLoader.loadNEWT(); + + shouldStop = false; + tasks = new ArrayList(); + tasksBlock = new ArrayList(); + mainThread = Thread.currentThread(); + + mainAction = new MainAction(mainClassName, mainClassArgs); + + if(NativeWindowFactory.TYPE_MACOSX.equals(NativeWindowFactory.getNativeWindowType(false))) { + MacDisplay.initSingleton(); + } + + if ( USE_MAIN_THREAD ) { + // dispatch user's main thread .. + mainAction.start(); + + // do our main thread task scheduling + run(); + } else { + // run user's main in this thread + mainAction.run(); + } + } + + /** invokes the given Runnable */ + public static void invoke(boolean wait, Runnable r) { + if(r == null) { + return; + } + + // if this main thread is not being used or + // if this is already the main thread .. just execute. + if( !isRunning() || mainThread == Thread.currentThread() ) { + r.run(); + return; + } + + synchronized(taskWorkerLock) { + tasks.add(r); + if(wait) { + tasksBlock.add(r); + } + taskWorkerLock.notifyAll(); + if(wait) { + while(tasksBlock.size()>0) { + try { + taskWorkerLock.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + } + + public static void exit() { + if(DEBUG) System.err.println("MainThread.exit(): "+Thread.currentThread().getName()+" start"); + synchronized(taskWorkerLock) { + if(isRunning) { + shouldStop = true; + } + taskWorkerLock.notifyAll(); + } + if(DEBUG) System.err.println("MainThread.exit(): "+Thread.currentThread().getName()+" end"); + } + + public static boolean isRunning() { + synchronized(taskWorkerLock) { + return isRunning; + } + } + + private static void waitUntilRunning() { + synchronized(taskWorkerLock) { + if(isExit) return; + + while(!isRunning) { + try { + taskWorkerLock.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + + public static void run() { + if(DEBUG) System.err.println("MainThread.run(): "+Thread.currentThread().getName()); + synchronized(taskWorkerLock) { + isRunning = true; + taskWorkerLock.notifyAll(); + } + while(!shouldStop) { + try { + ArrayList localTasks=null; + + // wait for something todo .. + synchronized(taskWorkerLock) { + while(!shouldStop && tasks.size()==0) { + try { + taskWorkerLock.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + // seq. process all tasks until no blocking one exists in the list + for(Iterator i = tasks.iterator(); tasksBlock.size()>0 && i.hasNext(); ) { + Runnable task = (Runnable) i.next(); + task.run(); + i.remove(); + tasksBlock.remove(task); + } + + // take over the tasks .. + if(tasks.size()>0) { + localTasks = tasks; + tasks = new ArrayList(); + } + taskWorkerLock.notifyAll(); + } + + // seq. process all unblocking tasks .. + if(null!=localTasks) { + for(Iterator i = localTasks.iterator(); i.hasNext(); ) { + Runnable task = (Runnable) i.next(); + task.run(); + } + } + } catch (Throwable t) { + // handle errors .. + t.printStackTrace(); + } finally { + // epilog - unlock locked stuff + } + } + if(DEBUG) System.err.println("MainThread.run(): "+Thread.currentThread().getName()+" fin"); + synchronized(taskWorkerLock) { + isRunning = false; + isExit = true; + taskWorkerLock.notifyAll(); + } + } +} + + diff --git a/src/newt/classes/com/jogamp/newt/windows/WindowsDisplay.java b/src/newt/classes/com/jogamp/newt/windows/WindowsDisplay.java new file mode 100755 index 000000000..05cab1a0a --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/windows/WindowsDisplay.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.windows; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.windows.*; +import com.jogamp.newt.*; +import com.jogamp.newt.impl.*; + +public class WindowsDisplay extends Display { + + protected static final String WINDOW_CLASS_NAME = "NewtWindowClass"; + private static int windowClassAtom; + private static long hInstance; + + static { + NativeLibLoader.loadNEWT(); + + if (!WindowsWindow.initIDs()) { + throw new NativeWindowException("Failed to initialize WindowsWindow jmethodIDs"); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + + public WindowsDisplay() { + } + + protected void createNative() { + aDevice = new WindowsGraphicsDevice(); + } + + protected void closeNative() { + // Can't do .. only at application shutdown + // UnregisterWindowClass(getWindowClassAtom(), getHInstance()); + } + + protected void dispatchMessages() { + DispatchMessages(); + } + + protected static synchronized int getWindowClassAtom() { + if(0 == windowClassAtom) { + windowClassAtom = RegisterWindowClass(WINDOW_CLASS_NAME, getHInstance()); + if (0 == windowClassAtom) { + throw new NativeWindowException("Error while registering window class"); + } + } + return windowClassAtom; + } + + protected static synchronized long getHInstance() { + if(0 == hInstance) { + hInstance = LoadLibraryW("newt"); + if (0 == hInstance) { + throw new NativeWindowException("Error finding HINSTANCE for \"newt\""); + } + } + return hInstance; + } + + //---------------------------------------------------------------------- + // Internals only + // + private static native long LoadLibraryW(String libraryName); + private static native int RegisterWindowClass(String windowClassName, long hInstance); + private static native void UnregisterWindowClass(int wndClassAtom, long hInstance); + + private static native void DispatchMessages(); +} + diff --git a/src/newt/classes/com/jogamp/newt/windows/WindowsScreen.java b/src/newt/classes/com/jogamp/newt/windows/WindowsScreen.java new file mode 100755 index 000000000..aea3cd439 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/windows/WindowsScreen.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.windows; + +import com.jogamp.newt.*; +import javax.media.nativewindow.*; + +public class WindowsScreen extends Screen { + static { + WindowsDisplay.initSingleton(); + } + + + public WindowsScreen() { + } + + protected void createNative(int index) { + aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index); + setScreenSize(getWidthImpl(getIndex()), getHeightImpl(getIndex())); + } + + protected void closeNative() { } + + private native int getWidthImpl(int scrn_idx); + private native int getHeightImpl(int scrn_idx); +} diff --git a/src/newt/classes/com/jogamp/newt/windows/WindowsWindow.java b/src/newt/classes/com/jogamp/newt/windows/WindowsWindow.java new file mode 100755 index 000000000..4a468ae86 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/windows/WindowsWindow.java @@ -0,0 +1,289 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.windows; + +import javax.media.nativewindow.*; +import com.jogamp.newt.*; + +public class WindowsWindow extends Window { + + private long hmon; + private long hdc; + private long windowHandleClose; + private long parentWindowHandle; + // non fullscreen dimensions .. + private int nfs_width, nfs_height, nfs_x, nfs_y; + private final Insets insets = new Insets(0, 0, 0, 0); + + static { + WindowsDisplay.initSingleton(); + } + + public WindowsWindow() { + } + + Thread hdcOwner = null; + + public synchronized int lockSurface() throws NativeWindowException { + int res = super.lockSurface(); + if(LOCK_SUCCESS==res && 0!=windowHandle) { + if(hdc!=0) { + throw new NativeWindowException("NEWT Surface handle set HDC "+toHexString(hdc)+" - "+Thread.currentThread().getName()+" ; "+this); + } + hdc = GetDC(windowHandle); + hmon = MonitorFromWindow(windowHandle); + hdcOwner = Thread.currentThread(); + } + return res; + } + + public synchronized void unlockSurface() { + // prevalidate, before we change data .. + Thread cur = Thread.currentThread(); + if ( getSurfaceLockOwner() != cur ) { + getLockedStack().printStackTrace(); + throw new NativeWindowException(cur+": Not owner, owner is "+getSurfaceLockOwner()); + } + if (0!=hdc && 0!=windowHandle) { + if(hdcOwner != cur) { + throw new NativeWindowException("NEWT Surface handle set HDC "+toHexString(hdc)+" by other thread "+hdcOwner+", this "+cur+" ; "+this); + } + ReleaseDC(windowHandle, hdc); + hdc=0; + hdcOwner=null; + } + super.unlockSurface(); + } + + public long getSurfaceHandle() { + return hdc; + } + + public boolean hasDeviceChanged() { + if(0!=windowHandle) { + long _hmon = MonitorFromWindow(windowHandle); + if (hmon != _hmon) { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + Exception e = new Exception("!!! Window Device Changed "+Thread.currentThread().getName()+ + ", HMON "+toHexString(hmon)+" -> "+toHexString(_hmon)); + e.printStackTrace(); + } + hmon = _hmon; + return true; + } + } + return false; + } + + protected void createNative(long parentWindowHandle, Capabilities caps) { + WindowsScreen screen = (WindowsScreen) getScreen(); + WindowsDisplay display = (WindowsDisplay) screen.getDisplay(); + config = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, screen.getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + windowHandle = CreateWindow(parentWindowHandle, + display.getWindowClassAtom(), display.WINDOW_CLASS_NAME, display.getHInstance(), + 0, undecorated, x, y, width, height); + if (windowHandle == 0) { + throw new NativeWindowException("Error creating window"); + } + this.parentWindowHandle = parentWindowHandle; + windowHandleClose = windowHandle; + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + Exception e = new Exception("!!! Window new window handle "+Thread.currentThread().getName()+ + " (Parent HWND "+toHexString(parentWindowHandle)+ + ") : HWND "+toHexString(windowHandle)+", "+Thread.currentThread()); + e.printStackTrace(); + } + } + + protected void closeNative() { + if (hdc != 0) { + if(windowHandleClose != 0) { + ReleaseDC(windowHandleClose, hdc); + } + hdc = 0; + } + if(windowHandleClose != 0) { + DestroyWindow(windowHandleClose); + windowHandleClose = 0; + } + } + + protected void windowDestroyed() { + windowHandleClose = 0; + super.windowDestroyed(); + } + + public void setVisible(boolean visible) { + if(this.visible!=visible && 0!=windowHandle) { + this.visible=visible; + setVisible0(windowHandle, visible); + } + } + + // @Override + public void setSize(int width, int height) { + if (0!=windowHandle && (width != this.width || this.height != height)) { + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + this.width = width; + this.height = height; + setSize0(parentWindowHandle, windowHandle, x, y, width, height); + } + } + + //@Override + public void setPosition(int x, int y) { + if (0!=windowHandle && (this.x != x || this.y != y)) { + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + this.x = x; + this.y = y; + setPosition(parentWindowHandle, windowHandle, x , y); + } + } + + public boolean setFullscreen(boolean fullscreen) { + if(0!=windowHandle && (this.fullscreen!=fullscreen)) { + int x,y,w,h; + this.fullscreen=fullscreen; + if(fullscreen) { + x = 0; y = 0; + w = screen.getWidth(); + h = screen.getHeight(); + } else { + x = nfs_x; + y = nfs_y; + w = nfs_width; + h = nfs_height; + } + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("WindowsWindow fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); + } + setFullscreen0(parentWindowHandle, windowHandle, x, y, w, h, undecorated, fullscreen); + } + return fullscreen; + } + + // @Override + public void requestFocus() { + super.requestFocus(); + if (windowHandle != 0L) { + requestFocus(windowHandle); + } + } + + // @Override + public void setTitle(String title) { + if (title == null) { + title = ""; + } + if (0!=windowHandle && !title.equals(getTitle())) { + super.setTitle(title); + setTitle(windowHandle, title); + } + } + + public Insets getInsets() { + return (Insets)insets.clone(); + } + + //---------------------------------------------------------------------- + // Internals only + // + protected static native boolean initIDs(); + private native long CreateWindow(long parentWindowHandle, + int wndClassAtom, String wndName, + long hInstance, long visualID, + boolean isUndecorated, + int x, int y, int width, int height); + private native void DestroyWindow(long windowHandle); + private native long GetDC(long windowHandle); + private native void ReleaseDC(long windowHandle, long hdc); + private native long MonitorFromWindow(long windowHandle); + private static native void setVisible0(long windowHandle, boolean visible); + private native void setSize0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height); + private native void setPosition(long parentWindowHandle, long windowHandle, int x, int y); + private native void setFullscreen0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height, boolean isUndecorated, boolean on); + private static native void setTitle(long windowHandle, String title); + private static native void requestFocus(long windowHandle); + + private void insetsChanged(int left, int top, int right, int bottom) { + if (left != -1 && top != -1 && right != -1 && bottom != -1) { + insets.left = left; + insets.top = top; + insets.right = right; + insets.bottom = bottom; + } + } + private void sizeChanged(int newWidth, int newHeight) { + width = newWidth; + height = newHeight; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + } + + private void positionChanged(int newX, int newY) { + x = newX; + y = newY; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); + } + + /** + * + * @param focusOwner if focusGained is true, focusOwner is the previous + * focus owner, if focusGained is false, focusOwner is the new focus owner + * @param focusGained + */ + private void focusChanged(long focusOwner, boolean focusGained) { + if (focusGained) { + sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); + } else { + sendWindowEvent(WindowEvent.EVENT_WINDOW_LOST_FOCUS); + } + } +} diff --git a/src/newt/classes/com/jogamp/newt/x11/X11Display.java b/src/newt/classes/com/jogamp/newt/x11/X11Display.java new file mode 100755 index 000000000..b8eb80b39 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/x11/X11Display.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.x11; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; +import com.jogamp.newt.*; +import com.jogamp.newt.impl.*; +import com.jogamp.nativewindow.impl.x11.X11Util; + +public class X11Display extends Display { + static { + NativeLibLoader.loadNEWT(); + + if (!initIDs()) { + throw new NativeWindowException("Failed to initialize X11Display jmethodIDs"); + } + + if (!X11Window.initIDs()) { + throw new NativeWindowException("Failed to initialize X11Window jmethodIDs"); + } + } + + public static void initSingleton() { + // just exist to ensure static init has been run + } + + + public X11Display() { + } + + protected void createNative() { + long handle= X11Util.getThreadLocalDisplay(name); + if (handle == 0 ) { + throw new RuntimeException("Error creating display: "+name); + } + try { + CompleteDisplay(handle); + } catch(RuntimeException e) { + X11Util.closeThreadLocalDisplay(name); + throw e; + } + aDevice = new X11GraphicsDevice(handle); + } + + protected void closeNative() { + if(0==X11Util.closeThreadLocalDisplay(name)) { + throw new NativeWindowException(this+" was not mapped"); + } + } + + protected void dispatchMessages() { + DispatchMessages(getHandle(), javaObjectAtom, windowDeleteAtom); + } + + protected void lockDisplay() { + super.lockDisplay(); + LockDisplay(getHandle()); + } + + protected void unlockDisplay() { + UnlockDisplay(getHandle()); + super.unlockDisplay(); + } + + protected long getJavaObjectAtom() { return javaObjectAtom; } + protected long getWindowDeleteAtom() { return windowDeleteAtom; } + + //---------------------------------------------------------------------- + // Internals only + // + private static native boolean initIDs(); + + private native void LockDisplay(long handle); + private native void UnlockDisplay(long handle); + + private native void CompleteDisplay(long handle); + + private native void DispatchMessages(long display, long javaObjectAtom, long windowDeleteAtom); + + private void displayCompleted(long javaObjectAtom, long windowDeleteAtom) { + this.javaObjectAtom=javaObjectAtom; + this.windowDeleteAtom=windowDeleteAtom; + } + + private long windowDeleteAtom; + private long javaObjectAtom; +} + diff --git a/src/newt/classes/com/jogamp/newt/x11/X11Screen.java b/src/newt/classes/com/jogamp/newt/x11/X11Screen.java new file mode 100755 index 000000000..e053d99c0 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/x11/X11Screen.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.x11; + +import com.jogamp.newt.*; +import javax.media.nativewindow.x11.*; + +public class X11Screen extends Screen { + + static { + X11Display.initSingleton(); + } + + + public X11Screen() { + } + + protected void createNative(int index) { + long handle = GetScreen(display.getHandle(), index); + if (handle == 0 ) { + throw new RuntimeException("Error creating screen: "+index); + } + aScreen = new X11GraphicsScreen((X11GraphicsDevice)getDisplay().getGraphicsDevice(), index); + setScreenSize(getWidth0(display.getHandle(), index), + getHeight0(display.getHandle(), index)); + } + + protected void closeNative() { } + + //---------------------------------------------------------------------- + // Internals only + // + + private native long GetScreen(long dpy, int scrn_idx); + private native int getWidth0(long display, int scrn_idx); + private native int getHeight0(long display, int scrn_idx); +} + diff --git a/src/newt/classes/com/jogamp/newt/x11/X11Window.java b/src/newt/classes/com/jogamp/newt/x11/X11Window.java new file mode 100755 index 000000000..cc3aa58a2 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/x11/X11Window.java @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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. + * + */ + +package com.jogamp.newt.x11; + +import com.jogamp.newt.*; +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; + +public class X11Window extends Window { + private static final String WINDOW_CLASS_NAME = "NewtWindow"; + // non fullscreen dimensions .. + private int nfs_width, nfs_height, nfs_x, nfs_y; + + static { + X11Display.initSingleton(); + } + + public X11Window() { + } + + protected void createNative(long parentWindowHandle, Capabilities caps) { + X11Screen screen = (X11Screen) getScreen(); + X11Display display = (X11Display) screen.getDisplay(); + config = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, screen.getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + X11GraphicsConfiguration x11config = (X11GraphicsConfiguration) config; + long visualID = x11config.getVisualID(); + long w = CreateWindow(parentWindowHandle, + display.getHandle(), screen.getIndex(), visualID, + display.getJavaObjectAtom(), display.getWindowDeleteAtom(), x, y, width, height); + if (w == 0 || w!=windowHandle) { + throw new NativeWindowException("Error creating window: "+w); + } + this.parentWindowHandle = parentWindowHandle; + windowHandleClose = windowHandle; + displayHandleClose = display.getHandle(); + } + + protected void closeNative() { + if(0!=displayHandleClose && 0!=windowHandleClose && null!=getScreen() ) { + X11Display display = (X11Display) getScreen().getDisplay(); + CloseWindow(displayHandleClose, windowHandleClose, display.getJavaObjectAtom()); + windowHandleClose = 0; + displayHandleClose = 0; + } + } + + protected void windowDestroyed() { + windowHandleClose = 0; + displayHandleClose = 0; + super.windowDestroyed(); + } + + public void setVisible(boolean visible) { + if(0!=windowHandle && this.visible!=visible) { + this.visible=visible; + setVisible0(getDisplayHandle(), windowHandle, visible); + clearEventMask(); + } + } + + public void requestFocus() { + super.requestFocus(); + } + + public void setSize(int width, int height) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("X11Window setSize: "+this.x+"/"+this.y+" "+this.width+"x"+this.height+" -> "+width+"x"+height); + // Exception e = new Exception("XXXXXXXXXX"); + // e.printStackTrace(); + } + this.width = width; + this.height = height; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + if(0!=windowHandle) { + setSize0(parentWindowHandle, getDisplayHandle(), getScreenIndex(), windowHandle, x, y, width, height, (undecorated||fullscreen)?-1:1, false); + } + } + + public void setPosition(int x, int y) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("X11Window setPosition: "+this.x+"/"+this.y+" -> "+x+"/"+y); + // Exception e = new Exception("XXXXXXXXXX"); + // e.printStackTrace(); + } + this.x = x; + this.y = y; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + if(0!=windowHandle) { + setPosition0(getDisplayHandle(), windowHandle, x, y); + } + } + + public boolean setFullscreen(boolean fullscreen) { + if(0!=windowHandle && this.fullscreen!=fullscreen) { + int x,y,w,h; + this.fullscreen=fullscreen; + if(fullscreen) { + x = 0; y = 0; + w = screen.getWidth(); + h = screen.getHeight(); + } else { + x = nfs_x; + y = nfs_y; + w = nfs_width; + h = nfs_height; + } + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("X11Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); + } + setSize0(parentWindowHandle, getDisplayHandle(), getScreenIndex(), windowHandle, x, y, w, h, (undecorated||fullscreen)?-1:1, false); + } + return fullscreen; + } + + //---------------------------------------------------------------------- + // Internals only + // + + protected static native boolean initIDs(); + private native long CreateWindow(long parentWindowHandle, long display, int screen_index, + long visualID, long javaObjectAtom, long windowDeleteAtom, int x, int y, int width, int height); + private native void CloseWindow(long display, long windowHandle, long javaObjectAtom); + private native void setVisible0(long display, long windowHandle, boolean visible); + private native void setSize0(long parentWindowHandle, long display, int screen_index, long windowHandle, + int x, int y, int width, int height, int decorationToggle, boolean setVisible); + private native void setPosition0(long display, long windowHandle, int x, int y); + + private void windowChanged(int newX, int newY, int newWidth, int newHeight) { + if(width != newWidth || height != newHeight) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("X11Window windowChanged size: "+this.width+"x"+this.height+" -> "+newWidth+"x"+newHeight); + } + width = newWidth; + height = newHeight; + if(!fullscreen) { + nfs_width=width; + nfs_height=height; + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + } + if( 0==parentWindowHandle && ( x != newX || y != newY ) ) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("X11Window windowChanged position: "+this.x+"/"+this.y+" -> "+newX+"x"+newY); + } + x = newX; + y = newY; + if(!fullscreen) { + nfs_x=x; + nfs_y=y; + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); + } + } + + private void windowCreated(long windowHandle) { + this.windowHandle = windowHandle; + } + + private long windowHandleClose; + private long displayHandleClose; + private long parentWindowHandle; +} diff --git a/src/newt/native/BroadcomEGL.c b/src/newt/native/BroadcomEGL.c index 8a9c5f948..9aac90abb 100755 --- a/src/newt/native/BroadcomEGL.c +++ b/src/newt/native/BroadcomEGL.c @@ -41,7 +41,7 @@ #include #include -#include "com_jogamp_javafx_newt_opengl_broadcom_egl_Window.h" +#include "com_jogamp_newt_opengl_broadcom_egl_Window.h" #include "EventListener.h" #include "MouseEvent.h" @@ -72,7 +72,7 @@ static jmethodID windowCreatedID = NULL; * Display */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_broadcom_egl_Display_DispatchMessages +JNIEXPORT void JNICALL Java_com_jogamp_newt_opengl_broadcom_egl_Display_DispatchMessages (JNIEnv *env, jobject obj) { // FIXME: n/a @@ -80,7 +80,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_broadcom_egl_Display_D (void) obj; } -JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_opengl_broadcom_egl_Display_CreateDisplay +JNIEXPORT jlong JNICALL Java_com_jogamp_newt_opengl_broadcom_egl_Display_CreateDisplay (JNIEnv *env, jobject obj, jint width, jint height) { (void) env; @@ -94,7 +94,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_opengl_broadcom_egl_Display_ return (jlong) (intptr_t) dpy; } -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_broadcom_egl_Display_DestroyDisplay +JNIEXPORT void JNICALL Java_com_jogamp_newt_opengl_broadcom_egl_Display_DestroyDisplay (JNIEnv *env, jobject obj, jlong display) { EGLDisplay dpy = (EGLDisplay)(intptr_t)display; @@ -111,7 +111,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_broadcom_egl_Display_D * Window */ -JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_opengl_broadcom_egl_Window_initIDs +JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_opengl_broadcom_egl_Window_initIDs (JNIEnv *env, jclass clazz) { windowCreatedID = (*env)->GetMethodID(env, clazz, "windowCreated", "(III)V"); @@ -123,7 +123,7 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_opengl_broadcom_egl_Windo return JNI_TRUE; } -JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_opengl_broadcom_egl_Window_CreateWindow +JNIEXPORT jlong JNICALL Java_com_jogamp_newt_opengl_broadcom_egl_Window_CreateWindow (JNIEnv *env, jobject obj, jlong display, jboolean chromaKey, jint width, jint height) { EGLDisplay dpy = (EGLDisplay)(intptr_t)display; @@ -167,7 +167,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_opengl_broadcom_egl_Window_C return (jlong) (intptr_t) window; } -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_broadcom_egl_Window_CloseWindow +JNIEXPORT void JNICALL Java_com_jogamp_newt_opengl_broadcom_egl_Window_CloseWindow (JNIEnv *env, jobject obj, jlong display, jlong window) { EGLDisplay dpy = (EGLDisplay) (intptr_t) display; @@ -180,7 +180,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_broadcom_egl_Window_Cl DBG_PRINT( "[CloseWindow] X\n"); } -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_broadcom_egl_Window_SwapWindow +JNIEXPORT void JNICALL Java_com_jogamp_newt_opengl_broadcom_egl_Window_SwapWindow (JNIEnv *env, jobject obj, jlong display, jlong window) { EGLDisplay dpy = (EGLDisplay) (intptr_t) display; diff --git a/src/newt/native/IntelGDL.c b/src/newt/native/IntelGDL.c index 77f582885..7857b594f 100644 --- a/src/newt/native/IntelGDL.c +++ b/src/newt/native/IntelGDL.c @@ -37,9 +37,9 @@ #include #include -#include "com_jogamp_javafx_newt_intel_gdl_Display.h" -#include "com_jogamp_javafx_newt_intel_gdl_Screen.h" -#include "com_jogamp_javafx_newt_intel_gdl_Window.h" +#include "com_jogamp_newt_intel_gdl_Display.h" +#include "com_jogamp_newt_intel_gdl_Screen.h" +#include "com_jogamp_newt_intel_gdl_Window.h" #include "EventListener.h" #include "MouseEvent.h" @@ -123,7 +123,7 @@ static void JNI_ThrowNew(JNIEnv *env, const char *throwable, const char* message * Display */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Display_DispatchMessages +JNIEXPORT void JNICALL Java_com_jogamp_newt_intel_gdl_Display_DispatchMessages (JNIEnv *env, jobject obj, jlong displayHandle, jobject focusedWindow) { // FIXME: n/a @@ -138,7 +138,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Display_DispatchMes } */ } -JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Display_CreateDisplay +JNIEXPORT jlong JNICALL Java_com_jogamp_newt_intel_gdl_Display_CreateDisplay (JNIEnv *env, jobject obj) { gdl_ret_t retval; @@ -171,7 +171,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Display_CreateDisp return (jlong) (intptr_t) p_driver_info; } -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Display_DestroyDisplay +JNIEXPORT void JNICALL Java_com_jogamp_newt_intel_gdl_Display_DestroyDisplay (JNIEnv *env, jobject obj, jlong displayHandle) { gdl_driver_info_t * p_driver_info = (gdl_driver_info_t *) (intptr_t) displayHandle; @@ -190,7 +190,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Display_DestroyDisp * Screen */ -JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Screen_initIDs +JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_intel_gdl_Screen_initIDs (JNIEnv *env, jclass clazz) { screenCreatedID = (*env)->GetMethodID(env, clazz, "screenCreated", "(II)V"); @@ -202,7 +202,7 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Screen_initIDs return JNI_TRUE; } -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Screen_GetScreenInfo +JNIEXPORT void JNICALL Java_com_jogamp_newt_intel_gdl_Screen_GetScreenInfo (JNIEnv *env, jobject obj, jlong displayHandle, jint idx) { gdl_driver_info_t * p_driver_info = (gdl_driver_info_t *) (intptr_t) displayHandle; @@ -234,7 +234,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Screen_GetScreenInf * Window */ -JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Window_initIDs +JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_intel_gdl_Window_initIDs (JNIEnv *env, jclass clazz) { updateBoundsID = (*env)->GetMethodID(env, clazz, "updateBounds", "(IIII)V"); @@ -246,7 +246,7 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Window_initIDs return JNI_TRUE; } -JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Window_CreateSurface +JNIEXPORT jlong JNICALL Java_com_jogamp_newt_intel_gdl_Window_CreateSurface (JNIEnv *env, jobject obj, jlong displayHandle, jint scr_width, jint scr_height, jint x, jint y, jint width, jint height) { gdl_driver_info_t * p_driver_info = (gdl_driver_info_t *) (intptr_t) displayHandle; @@ -339,7 +339,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Window_CreateSurfa return (jlong) (intptr_t) plane; } -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Window_CloseSurface +JNIEXPORT void JNICALL Java_com_jogamp_newt_intel_gdl_Window_CloseSurface (JNIEnv *env, jobject obj, jlong display, jlong surface) { gdl_plane_id_t plane = (gdl_plane_id_t) (intptr_t) surface ; @@ -348,7 +348,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Window_CloseSurface DBG_PRINT("[CloseSurface] plane %d\n", plane); } -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_intel_gdl_Window_SetBounds0 +JNIEXPORT void JNICALL Java_com_jogamp_newt_intel_gdl_Window_SetBounds0 (JNIEnv *env, jobject obj, jlong surface, jint scr_width, jint scr_height, jint x, jint y, jint width, jint height) { gdl_plane_id_t plane = (gdl_plane_id_t) (intptr_t) surface ; diff --git a/src/newt/native/KDWindow.c b/src/newt/native/KDWindow.c index 31e8017f4..15bef7582 100755 --- a/src/newt/native/KDWindow.c +++ b/src/newt/native/KDWindow.c @@ -64,7 +64,7 @@ #include #include -#include "com_jogamp_javafx_newt_opengl_kd_KDWindow.h" +#include "com_jogamp_newt_opengl_kd_KDWindow.h" #include "EventListener.h" #include "MouseEvent.h" @@ -103,7 +103,7 @@ static jmethodID sendKeyEventID = NULL; * Display */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDDisplay_DispatchMessages +JNIEXPORT void JNICALL Java_com_jogamp_newt_opengl_kd_KDDisplay_DispatchMessages (JNIEnv *env, jobject obj) { const KDEvent * evt; @@ -200,7 +200,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDDisplay_DispatchM * Window */ -JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDWindow_initIDs +JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_opengl_kd_KDWindow_initIDs (JNIEnv *env, jclass clazz) { #ifdef VERBOSE_ON @@ -228,7 +228,7 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDWindow_initID return JNI_TRUE; } -JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDWindow_CreateWindow +JNIEXPORT jlong JNICALL Java_com_jogamp_newt_opengl_kd_KDWindow_CreateWindow (JNIEnv *env, jobject obj, jlong display, jintArray jAttrs) { jint * attrs = NULL; @@ -270,7 +270,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDWindow_CreateWin return (jlong) (intptr_t) window; } -JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDWindow_RealizeWindow +JNIEXPORT jlong JNICALL Java_com_jogamp_newt_opengl_kd_KDWindow_RealizeWindow (JNIEnv *env, jobject obj, jlong window) { KDWindow *w = (KDWindow*) (intptr_t) window; @@ -285,7 +285,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDWindow_RealizeWi return (jlong) (intptr_t) nativeWindow; } -JNIEXPORT jint JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDWindow_CloseWindow +JNIEXPORT jint JNICALL Java_com_jogamp_newt_opengl_kd_KDWindow_CloseWindow (JNIEnv *env, jobject obj, jlong window, jlong juserData) { KDWindow *w = (KDWindow*) (intptr_t) window; @@ -299,11 +299,11 @@ JNIEXPORT jint JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDWindow_CloseWindo } /* - * Class: com_jogamp_javafx_newt_opengl_kd_KDWindow + * Class: com_jogamp_newt_opengl_kd_KDWindow * Method: setVisible0 * Signature: (JJZ)V */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDWindow_setVisible0 +JNIEXPORT void JNICALL Java_com_jogamp_newt_opengl_kd_KDWindow_setVisible0 (JNIEnv *env, jobject obj, jlong window, jboolean visible) { KDWindow *w = (KDWindow*) (intptr_t) window; @@ -312,7 +312,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDWindow_setVisible DBG_PRINT( "[setVisible] v=%d\n", visible); } -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDWindow_setFullScreen0 +JNIEXPORT void JNICALL Java_com_jogamp_newt_opengl_kd_KDWindow_setFullScreen0 (JNIEnv *env, jobject obj, jlong window, jboolean fullscreen) { KDWindow *w = (KDWindow*) (intptr_t) window; @@ -323,7 +323,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDWindow_setFullScr (void)res; } -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_opengl_kd_KDWindow_setSize0 +JNIEXPORT void JNICALL Java_com_jogamp_newt_opengl_kd_KDWindow_setSize0 (JNIEnv *env, jobject obj, jlong window, jint width, jint height) { KDWindow *w = (KDWindow*) (intptr_t) window; diff --git a/src/newt/native/MacWindow.m b/src/newt/native/MacWindow.m index 1749805c8..01563a0d1 100644 --- a/src/newt/native/MacWindow.m +++ b/src/newt/native/MacWindow.m @@ -33,7 +33,7 @@ #import -#import "com_sun_javafx_newt_macosx_MacWindow.h" +#import "com_sun_newt_macosx_MacWindow.h" #import "NewtMacWindow.h" #import "EventListener.h" @@ -121,11 +121,11 @@ NS_ENDHANDLER } /* - * Class: com_sun_javafx_newt_macosx_MacDisplay + * Class: com_sun_newt_macosx_MacDisplay * Method: initIDs * Signature: ()Z */ -JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_macosx_MacDisplay_initNSApplication +JNIEXPORT jboolean JNICALL Java_com_sun_newt_macosx_MacDisplay_initNSApplication (JNIEnv *env, jclass clazz) { static int initialized = 0; @@ -155,11 +155,11 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_macosx_MacDisplay_initNSAppl } /* - * Class: com_sun_javafx_newt_macosx_MacDisplay + * Class: com_sun_newt_macosx_MacDisplay * Method: dispatchMessages0 * Signature: ()V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacDisplay_dispatchMessages0 +JNIEXPORT void JNICALL Java_com_sun_newt_macosx_MacDisplay_dispatchMessages0 (JNIEnv *env, jobject unused, jlong window, jint eventMask) { NSEvent* event = NULL; @@ -195,11 +195,11 @@ NS_ENDHANDLER } /* - * Class: com_sun_javafx_newt_macosx_MacScreen + * Class: com_sun_newt_macosx_MacScreen * Method: getWidthImpl * Signature: (I)I */ -JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_macosx_MacScreen_getWidthImpl +JNIEXPORT jint JNICALL Java_com_sun_newt_macosx_MacScreen_getWidthImpl (JNIEnv *env, jclass clazz, jint screen_idx) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; @@ -216,11 +216,11 @@ JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_macosx_MacScreen_getWidthImpl } /* - * Class: com_sun_javafx_newt_macosx_MacScreen + * Class: com_sun_newt_macosx_MacScreen * Method: getHeightImpl * Signature: (I)I */ -JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_macosx_MacScreen_getHeightImpl +JNIEXPORT jint JNICALL Java_com_sun_newt_macosx_MacScreen_getHeightImpl (JNIEnv *env, jclass clazz, jint screen_idx) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; @@ -237,11 +237,11 @@ JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_macosx_MacScreen_getHeightImpl } /* - * Class: com_sun_javafx_newt_macosx_MacWindow + * Class: com_sun_newt_macosx_MacWindow * Method: initIDs * Signature: ()Z */ -JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_initIDs +JNIEXPORT jboolean JNICALL Java_com_sun_newt_macosx_MacWindow_initIDs (JNIEnv *env, jclass clazz) { static int initialized = 0; @@ -258,11 +258,11 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_initIDs } /* - * Class: com_sun_javafx_newt_macosx_MacWindow + * Class: com_sun_newt_macosx_MacWindow * Method: createWindow0 * Signature: (JIIIIZIIIJ)J */ -JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_createWindow0 +JNIEXPORT jlong JNICALL Java_com_sun_newt_macosx_MacWindow_createWindow0 (JNIEnv *env, jobject jthis, jlong parent, jint x, jint y, jint w, jint h, jboolean fullscreen, jint styleMask, jint bufferingType, jint screen_idx, jlong jview) { @@ -334,11 +334,11 @@ NS_ENDHANDLER } /* - * Class: com_sun_javafx_newt_macosx_MacWindow + * Class: com_sun_newt_macosx_MacWindow * Method: makeKeyAndOrderFront * Signature: (J)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_makeKeyAndOrderFront +JNIEXPORT void JNICALL Java_com_sun_newt_macosx_MacWindow_makeKeyAndOrderFront (JNIEnv *env, jobject unused, jlong window) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; @@ -348,11 +348,11 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_makeKeyAndOrder } /* - * Class: com_sun_javafx_newt_macosx_MacWindow + * Class: com_sun_newt_macosx_MacWindow * Method: makeKey * Signature: (J)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_makeKey +JNIEXPORT void JNICALL Java_com_sun_newt_macosx_MacWindow_makeKey (JNIEnv *env, jobject unused, jlong window) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; @@ -362,11 +362,11 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_makeKey } /* - * Class: com_sun_javafx_newt_macosx_MacWindow + * Class: com_sun_newt_macosx_MacWindow * Method: orderOut * Signature: (J)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_orderOut +JNIEXPORT void JNICALL Java_com_sun_newt_macosx_MacWindow_orderOut (JNIEnv *env, jobject unused, jlong window) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; @@ -376,11 +376,11 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_orderOut } /* - * Class: com_sun_javafx_newt_macosx_MacWindow + * Class: com_sun_newt_macosx_MacWindow * Method: close0 * Signature: (J)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_close0 +JNIEXPORT void JNICALL Java_com_sun_newt_macosx_MacWindow_close0 (JNIEnv *env, jobject unused, jlong window) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; @@ -401,11 +401,11 @@ NS_ENDHANDLER } /* - * Class: com_sun_javafx_newt_macosx_MacWindow + * Class: com_sun_newt_macosx_MacWindow * Method: setTitle0 * Signature: (JLjava/lang/String;)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_setTitle0 +JNIEXPORT void JNICALL Java_com_sun_newt_macosx_MacWindow_setTitle0 (JNIEnv *env, jobject unused, jlong window, jstring title) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; @@ -417,11 +417,11 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_setTitle0 } /* - * Class: com_sun_javafx_newt_macosx_MacWindow + * Class: com_sun_newt_macosx_MacWindow * Method: contentView * Signature: (J)J */ -JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_contentView +JNIEXPORT jlong JNICALL Java_com_sun_newt_macosx_MacWindow_contentView (JNIEnv *env, jobject unused, jlong window) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; @@ -432,11 +432,11 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_contentView } /* - * Class: com_sun_javafx_newt_macosx_MacWindow + * Class: com_sun_newt_macosx_MacWindow * Method: changeContentView * Signature: (J)J */ -JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_changeContentView +JNIEXPORT jlong JNICALL Java_com_sun_newt_macosx_MacWindow_changeContentView (JNIEnv *env, jobject jthis, jlong parent, jlong window, jlong jview) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; @@ -452,11 +452,11 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_changeContentV } /* - * Class: com_sun_javafx_newt_macosx_MacWindow + * Class: com_sun_newt_macosx_MacWindow * Method: setContentSize * Signature: (JII)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_setContentSize +JNIEXPORT void JNICALL Java_com_sun_newt_macosx_MacWindow_setContentSize (JNIEnv *env, jobject unused, jlong window, jint w, jint h) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; @@ -467,11 +467,11 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_setContentSize } /* - * Class: com_sun_javafx_newt_macosx_MacWindow + * Class: com_sun_newt_macosx_MacWindow * Method: setFrameTopLeftPoint * Signature: (JII)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_setFrameTopLeftPoint +JNIEXPORT void JNICALL Java_com_sun_newt_macosx_MacWindow_setFrameTopLeftPoint (JNIEnv *env, jobject unused, jlong parent, jlong window, jint x, jint y) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c index d39b96d0b..67da99b1f 100755 --- a/src/newt/native/WindowsWindow.c +++ b/src/newt/native/WindowsWindow.c @@ -89,7 +89,7 @@ #define MONITOR_DEFAULTTONEAREST 2 #endif -#include "com_jogamp_javafx_newt_windows_WindowsWindow.h" +#include "com_jogamp_newt_windows_WindowsWindow.h" #include "EventListener.h" #include "MouseEvent.h" @@ -902,11 +902,11 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, } /* - * Class: com_jogamp_javafx_newt_windows_WindowsDisplay + * Class: com_jogamp_newt_windows_WindowsDisplay * Method: DispatchMessages * Signature: ()V */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsDisplay_DispatchMessages +JNIEXPORT void JNICALL Java_com_jogamp_newt_windows_WindowsDisplay_DispatchMessages (JNIEnv *env, jclass clazz) { int i = 0; @@ -925,11 +925,11 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsDisplay_Dispat } /* - * Class: com_jogamp_javafx_newt_windows_WindowsDisplay + * Class: com_jogamp_newt_windows_WindowsDisplay * Method: LoadLibraryW * Signature: (Ljava/lang/String;)J */ -JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_windows_WindowsDisplay_LoadLibraryW +JNIEXPORT jlong JNICALL Java_com_jogamp_newt_windows_WindowsDisplay_LoadLibraryW (JNIEnv *env, jclass clazz, jstring dllName) { jchar* _dllName = GetNullTerminatedStringChars(env, dllName); @@ -939,11 +939,11 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_windows_WindowsDisplay_LoadL } /* - * Class: com_jogamp_javafx_newt_windows_WindowsDisplay + * Class: com_jogamp_newt_windows_WindowsDisplay * Method: RegisterWindowClass * Signature: (Ljava/lang/String;J)I */ -JNIEXPORT jint JNICALL Java_com_jogamp_javafx_newt_windows_WindowsDisplay_RegisterWindowClass +JNIEXPORT jint JNICALL Java_com_jogamp_newt_windows_WindowsDisplay_RegisterWindowClass (JNIEnv *env, jclass clazz, jstring wndClassName, jlong hInstance) { ATOM res; @@ -979,44 +979,44 @@ JNIEXPORT jint JNICALL Java_com_jogamp_javafx_newt_windows_WindowsDisplay_Regist } /* - * Class: com_jogamp_javafx_newt_windows_WindowsDisplay + * Class: com_jogamp_newt_windows_WindowsDisplay * Method: CleanupWindowResources * Signature: (java/lang/String;J)V */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsDisplay_UnregisterWindowClass +JNIEXPORT void JNICALL Java_com_jogamp_newt_windows_WindowsDisplay_UnregisterWindowClass (JNIEnv *env, jclass clazz, jint wndClassAtom, jlong hInstance) { UnregisterClass(MAKEINTATOM(wndClassAtom), (HINSTANCE) (intptr_t) hInstance); } /* - * Class: com_jogamp_javafx_newt_windows_WindowsScreen + * Class: com_jogamp_newt_windows_WindowsScreen * Method: getWidthImpl * Signature: (I)I */ -JNIEXPORT jint JNICALL Java_com_jogamp_javafx_newt_windows_WindowsScreen_getWidthImpl +JNIEXPORT jint JNICALL Java_com_jogamp_newt_windows_WindowsScreen_getWidthImpl (JNIEnv *env, jobject obj, jint scrn_idx) { return (jint)GetSystemMetrics(SM_CXSCREEN); } /* - * Class: com_jogamp_javafx_newt_windows_WindowsScreen + * Class: com_jogamp_newt_windows_WindowsScreen * Method: getWidthImpl * Signature: (I)I */ -JNIEXPORT jint JNICALL Java_com_jogamp_javafx_newt_windows_WindowsScreen_getHeightImpl +JNIEXPORT jint JNICALL Java_com_jogamp_newt_windows_WindowsScreen_getHeightImpl (JNIEnv *env, jobject obj, jint scrn_idx) { return (jint)GetSystemMetrics(SM_CYSCREEN); } /* - * Class: com_jogamp_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_newt_windows_WindowsWindow * Method: initIDs * Signature: ()Z */ -JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_initIDs +JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_windows_WindowsWindow_initIDs (JNIEnv *env, jclass clazz) { sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V"); @@ -1045,11 +1045,11 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_ini } /* - * Class: com_jogamp_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_newt_windows_WindowsWindow * Method: CreateWindow * Signature: (JILjava/lang/String;JJZIIII)J */ -JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_CreateWindow +JNIEXPORT jlong JNICALL Java_com_jogamp_newt_windows_WindowsWindow_CreateWindow (JNIEnv *env, jobject obj, jlong parent, jint wndClassAtom, jstring jWndName, jlong hInstance, jlong visualID, jboolean bIsUndecorated, jint jx, jint jy, jint defaultWidth, jint defaultHeight) @@ -1113,44 +1113,44 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_Create } /* - * Class: com_jogamp_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_newt_windows_WindowsWindow * Method: DestroyWindow * Signature: (J)V */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_DestroyWindow +JNIEXPORT void JNICALL Java_com_jogamp_newt_windows_WindowsWindow_DestroyWindow (JNIEnv *env, jobject obj, jlong window) { DestroyWindow((HWND) (intptr_t) window); } /* - * Class: com_jogamp_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_newt_windows_WindowsWindow * Method: GetDC * Signature: (J)J */ -JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_GetDC +JNIEXPORT jlong JNICALL Java_com_jogamp_newt_windows_WindowsWindow_GetDC (JNIEnv *env, jobject obj, jlong window) { return (jlong) (intptr_t) GetDC((HWND) (intptr_t) window); } /* - * Class: com_jogamp_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_newt_windows_WindowsWindow * Method: ReleaseDC * Signature: (JJ)V */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_ReleaseDC +JNIEXPORT void JNICALL Java_com_jogamp_newt_windows_WindowsWindow_ReleaseDC (JNIEnv *env, jobject obj, jlong window, jlong dc) { ReleaseDC((HWND) (intptr_t) window, (HDC) (intptr_t) dc); } /* - * Class: com_jogamp_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_newt_windows_WindowsWindow * Method: MonitorFromWindow * Signature: (J)J */ -JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_MonitorFromWindow +JNIEXPORT jlong JNICALL Java_com_jogamp_newt_windows_WindowsWindow_MonitorFromWindow (JNIEnv *env, jobject obj, jlong window) { #if (_WIN32_WINNT >= 0x0500 || _WIN32_WINDOWS >= 0x0410 || WINVER >= 0x0500) && !defined(_WIN32_WCE) @@ -1161,11 +1161,11 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_Monito } /* - * Class: com_jogamp_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_newt_windows_WindowsWindow * Method: setVisible0 * Signature: (JZ)V */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_setVisible0 +JNIEXPORT void JNICALL Java_com_jogamp_newt_windows_WindowsWindow_setVisible0 (JNIEnv *_env, jclass clazz, jlong window, jboolean visible) { HWND hWnd = (HWND) (intptr_t) window; @@ -1178,11 +1178,11 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_setVisi } /* - * Class: com_jogamp_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_newt_windows_WindowsWindow * Method: setSize0 * Signature: (JII)V */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_setSize0 +JNIEXPORT void JNICALL Java_com_jogamp_newt_windows_WindowsWindow_setSize0 (JNIEnv *env, jobject obj, jlong parent, jlong window, jint x, jint y, jint width, jint height) { HWND hwndP = (HWND) (intptr_t) parent; @@ -1215,11 +1215,11 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_setSize } /* - * Class: com_jogamp_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_newt_windows_WindowsWindow * Method: setPosition * Signature: (JII)V */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_setPosition +JNIEXPORT void JNICALL Java_com_jogamp_newt_windows_WindowsWindow_setPosition (JNIEnv *env, jobject obj, jlong parent, jlong window, jint x, jint y) { UINT flags = SWP_NOACTIVATE | SWP_NOSIZE; @@ -1236,11 +1236,11 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_setPosi } /* - * Class: com_jogamp_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_newt_windows_WindowsWindow * Method: setFullscreen * Signature: (JIIIIZZ)V */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_setFullscreen0 +JNIEXPORT void JNICALL Java_com_jogamp_newt_windows_WindowsWindow_setFullscreen0 (JNIEnv *env, jobject obj, jlong parent, jlong window, jint x, jint y, jint width, jint height, jboolean bIsUndecorated, jboolean on) { UINT flags; @@ -1272,11 +1272,11 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_setFull } /* - * Class: com_jogamp_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_newt_windows_WindowsWindow * Method: setTitle * Signature: (JLjava/lang/String;)V */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_setTitle +JNIEXPORT void JNICALL Java_com_jogamp_newt_windows_WindowsWindow_setTitle (JNIEnv *env, jclass clazz, jlong window, jstring title) { HWND hwnd = (HWND) (intptr_t) window; @@ -1290,11 +1290,11 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_setTitl } /* - * Class: com_jogamp_javafx_newt_windows_WindowsWindow + * Class: com_jogamp_newt_windows_WindowsWindow * Method: requestFocus * Signature: (J)V */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_windows_WindowsWindow_requestFocus +JNIEXPORT void JNICALL Java_com_jogamp_newt_windows_WindowsWindow_requestFocus (JNIEnv *env, jclass clazz, jlong window) { HWND hwnd = (HWND) (intptr_t) window; diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index 682184da0..11f7d0f6c 100755 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -46,7 +46,7 @@ #include #include -#include "com_jogamp_javafx_newt_x11_X11Window.h" +#include "com_jogamp_newt_x11_X11Window.h" #include "EventListener.h" #include "MouseEvent.h" @@ -154,7 +154,7 @@ static const char * const ClazzNameRuntimeException = static jclass runtimeExceptionClz=NULL; static const char * const ClazzNameNewtWindow = - "com/jogamp/javafx/newt/Window"; + "com/jogamp/newt/Window"; static jclass newtWindowClz=NULL; static jmethodID windowChangedID = NULL; @@ -187,11 +187,11 @@ static void _throwNewRuntimeException(Display * unlockDisplay, JNIEnv *env, cons */ /* - * Class: com_jogamp_javafx_newt_x11_X11Display + * Class: com_jogamp_newt_x11_X11Display * Method: initIDs * Signature: ()Z */ -JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_x11_X11Display_initIDs +JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_x11_X11Display_initIDs (JNIEnv *env, jclass clazz) { jclass c; @@ -237,11 +237,11 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_x11_X11Display_initIDs } /* - * Class: com_jogamp_javafx_newt_x11_X11Display + * Class: com_jogamp_newt_x11_X11Display * Method: LockDisplay * Signature: (J)V */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Display_LockDisplay +JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Display_LockDisplay (JNIEnv *env, jobject obj, jlong display) { Display * dpy = (Display *)(intptr_t)display; @@ -253,11 +253,11 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Display_LockDisplay /* - * Class: com_jogamp_javafx_newt_x11_X11Display + * Class: com_jogamp_newt_x11_X11Display * Method: UnlockDisplay * Signature: (J)V */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Display_UnlockDisplay +JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Display_UnlockDisplay (JNIEnv *env, jobject obj, jlong display) { Display * dpy = (Display *)(intptr_t)display; @@ -269,11 +269,11 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Display_UnlockDisplay /* - * Class: com_jogamp_javafx_newt_x11_X11Display + * Class: com_jogamp_newt_x11_X11Display * Method: CompleteDisplay * Signature: (J)V */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Display_CompleteDisplay +JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Display_CompleteDisplay (JNIEnv *env, jobject obj, jlong display) { Display * dpy = (Display *)(intptr_t)display; @@ -381,11 +381,11 @@ static jobject getJavaWindowProperty(JNIEnv *env, Display *dpy, Window window, j } /* - * Class: com_jogamp_javafx_newt_x11_X11Display + * Class: com_jogamp_newt_x11_X11Display * Method: DispatchMessages * Signature: (JIJJ)V */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Display_DispatchMessages +JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Display_DispatchMessages (JNIEnv *env, jobject obj, jlong display, jlong javaObjectAtom, jlong wmDeleteAtom) { Display * dpy = (Display *) (intptr_t) display; @@ -532,11 +532,11 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Display_DispatchMessag */ /* - * Class: com_jogamp_javafx_newt_x11_X11Screen + * Class: com_jogamp_newt_x11_X11Screen * Method: GetScreen * Signature: (JI)J */ -JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_x11_X11Screen_GetScreen +JNIEXPORT jlong JNICALL Java_com_jogamp_newt_x11_X11Screen_GetScreen (JNIEnv *env, jobject obj, jlong display, jint screen_index) { Display * dpy = (Display *)(intptr_t)display; @@ -559,14 +559,14 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_x11_X11Screen_GetScreen return (jlong) (intptr_t) scrn; } -JNIEXPORT jint JNICALL Java_com_jogamp_javafx_newt_x11_X11Screen_getWidth0 +JNIEXPORT jint JNICALL Java_com_jogamp_newt_x11_X11Screen_getWidth0 (JNIEnv *env, jobject obj, jlong display, jint scrn_idx) { Display * dpy = (Display *) (intptr_t) display; return (jint) XDisplayWidth( dpy, scrn_idx); } -JNIEXPORT jint JNICALL Java_com_jogamp_javafx_newt_x11_X11Screen_getHeight0 +JNIEXPORT jint JNICALL Java_com_jogamp_newt_x11_X11Screen_getHeight0 (JNIEnv *env, jobject obj, jlong display, jint scrn_idx) { Display * dpy = (Display *) (intptr_t) display; @@ -579,11 +579,11 @@ JNIEXPORT jint JNICALL Java_com_jogamp_javafx_newt_x11_X11Screen_getHeight0 */ /* - * Class: com_jogamp_javafx_newt_x11_X11Window + * Class: com_jogamp_newt_x11_X11Window * Method: initIDs * Signature: ()Z */ -JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_x11_X11Window_initIDs +JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_x11_X11Window_initIDs (JNIEnv *env, jclass clazz) { windowChangedID = (*env)->GetMethodID(env, clazz, "windowChanged", "(IIII)V"); @@ -605,11 +605,11 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_javafx_newt_x11_X11Window_initIDs } /* - * Class: com_jogamp_javafx_newt_x11_X11Window + * Class: com_jogamp_newt_x11_X11Window * Method: CreateWindow * Signature: (JJIJIIII)J */ -JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_x11_X11Window_CreateWindow +JNIEXPORT jlong JNICALL Java_com_jogamp_newt_x11_X11Window_CreateWindow (JNIEnv *env, jobject obj, jlong parent, jlong display, jint screen_index, jlong visualID, jlong javaObjectAtom, jlong windowDeleteAtom, @@ -734,11 +734,11 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_javafx_newt_x11_X11Window_CreateWindow } /* - * Class: com_jogamp_javafx_newt_x11_X11Window + * Class: com_jogamp_newt_x11_X11Window * Method: CloseWindow * Signature: (JJ)V */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Window_CloseWindow +JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Window_CloseWindow (JNIEnv *env, jobject obj, jlong display, jlong window, jlong javaObjectAtom) { Display * dpy = (Display *) (intptr_t) display; @@ -779,11 +779,11 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Window_CloseWindow } /* - * Class: com_jogamp_javafx_newt_x11_X11Window + * Class: com_jogamp_newt_x11_X11Window * Method: setVisible0 * Signature: (JJZ)V */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Window_setVisible0 +JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Window_setVisible0 (JNIEnv *env, jobject obj, jlong display, jlong window, jboolean visible) { Display * dpy = (Display *) (intptr_t) display; @@ -823,11 +823,11 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Window_setVisible0 #endif /* - * Class: com_jogamp_javafx_newt_x11_X11Window + * Class: com_jogamp_newt_x11_X11Window * Method: setSize0 * Signature: (JIJIIIIIZ)V */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Window_setSize0 +JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Window_setSize0 (JNIEnv *env, jobject obj, jlong jparent, jlong display, jint screen_index, jlong window, jint x, jint y, jint width, jint height, jint decorationToggle, jboolean setVisible) { Display * dpy = (Display *) (intptr_t) display; @@ -887,11 +887,11 @@ JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Window_setSize0 } /* - * Class: com_jogamp_javafx_newt_x11_X11Window + * Class: com_jogamp_newt_x11_X11Window * Method: setPosition0 * Signature: (JJII)V */ -JNIEXPORT void JNICALL Java_com_jogamp_javafx_newt_x11_X11Window_setPosition0 +JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Window_setPosition0 (JNIEnv *env, jobject obj, jlong display, jlong window, jint x, jint y) { Display * dpy = (Display *) (intptr_t) display; -- cgit v1.2.3 From 2df3bea10859ee2f2c4b3622f3b610b17a5749d6 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 13 Apr 2010 21:24:44 +0200 Subject: ATI (fglrx) PBuffer/X11Display bug workaround/cleanup - See https://bugzilla.mozilla.org/show_bug.cgi?id=486277 - Description: - To use PBuffer, a context must be current - X11Display cannot be switched while using the PBuffer [within one thread]. Hence we shall try harder to reuse _the_ user configured X11Display - whenever possible. This is actually a good thing, ie cleanup up our code again. - Changes to workaround/cleanup: - GLDrawableFactory* methods 'canCreate*()' are changed to 'canCreate*(AbstractGraphicsDevice)' to allow pipelining the X11Display. This reduces the overhead of using a local TLS X11Display. - WindowsDummyWGLDrawable cstr gets the GLProfile as a parameter now, this is done while adding X11DummyGLXDrawable - forseeing the usecase to query available GLProfiles at startup. - X11DummyGLXDrawable added, following the WindowsDummyWGLDrawable path to have a dummy GLContext current to fix the ATI bug. NativeWindow X11: - Add XIOErrorHandler to identify the fatal failure of closing a Display (-> ATI bug). Build: - Adding ant.jar and ant-junit.jar to the junit compile/run classpath - Misc: - Fix: CreateDummyWindow(..) returns a HWND, not a HDC - mapToRealGLFunctionName: Added mapping for X11/GLX. - X11GLXGraphicsConfigurationFactory: Uncommented dead code 'createDefaultGraphicsConfigurationFBConfig' Tests: Passed (Linux64bit: NVidia/ATI) Todo: More tests on ATI, especially multithreading/X11Display usage. --- make/build-common.xml | 8 +- make/build-jogl.xml | 2 +- make/build-junit.xml | 2 +- make/config/nativewindow/x11-CustomCCode.c | 61 +++++++++++++++ make/config/nativewindow/x11-CustomJavaCode.java | 5 ++ make/config/nativewindow/x11-lib.cfg | 5 +- make/stub_includes/win32/wingdi.h | 2 +- .../com/jogamp/opengl/impl/GLContextImpl.java | 26 ++++++- .../jogamp/opengl/impl/GLDrawableFactoryImpl.java | 13 ++-- .../com/jogamp/opengl/impl/GLDrawableImpl.java | 8 +- .../com/jogamp/opengl/impl/egl/EGLContext.java | 8 +- .../jogamp/opengl/impl/egl/EGLDrawableFactory.java | 6 +- .../opengl/impl/macosx/cgl/MacOSXCGLContext.java | 14 +--- .../impl/macosx/cgl/MacOSXCGLDrawableFactory.java | 6 +- .../cgl/awt/MacOSXAWTCGLDrawableFactory.java | 3 +- .../impl/windows/wgl/WindowsDummyWGLDrawable.java | 7 +- .../opengl/impl/windows/wgl/WindowsWGLContext.java | 18 +---- .../windows/wgl/WindowsWGLDrawableFactory.java | 20 +++-- .../WindowsWGLGraphicsConfigurationFactory.java | 15 ++-- .../opengl/impl/x11/glx/X11DummyGLXDrawable.java | 85 +++++++++++++++++++++ .../jogamp/opengl/impl/x11/glx/X11GLXContext.java | 22 +++--- .../opengl/impl/x11/glx/X11GLXDrawableFactory.java | 88 +++++++++++++++------- .../glx/X11GLXGraphicsConfigurationFactory.java | 5 +- .../javax/media/opengl/GLDrawableFactory.java | 7 +- .../classes/javax/media/opengl/awt/GLJPanel.java | 7 +- .../com/jogamp/nativewindow/impl/x11/X11Util.java | 4 +- 26 files changed, 317 insertions(+), 130 deletions(-) create mode 100644 src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java (limited to 'src/nativewindow/classes') diff --git a/make/build-common.xml b/make/build-common.xml index 10f37c3e4..d6c39c1ed 100644 --- a/make/build-common.xml +++ b/make/build-common.xml @@ -121,6 +121,8 @@ + + @@ -179,6 +181,8 @@ + + @@ -187,6 +191,8 @@ + + @@ -194,7 +200,7 @@ + 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}"/> diff --git a/make/build-jogl.xml b/make/build-jogl.xml index b1f0a02eb..93cf7bf6f 100644 --- a/make/build-jogl.xml +++ b/make/build-jogl.xml @@ -396,7 +396,7 @@ - + diff --git a/make/build-junit.xml b/make/build-junit.xml index 58e8e3b7f..887060084 100644 --- a/make/build-junit.xml +++ b/make/build-junit.xml @@ -113,7 +113,7 @@ relative="true" failonerror="false"> - + diff --git a/make/config/nativewindow/x11-CustomCCode.c b/make/config/nativewindow/x11-CustomCCode.c index 8eded9aa2..982a39f7e 100755 --- a/make/config/nativewindow/x11-CustomCCode.c +++ b/make/config/nativewindow/x11-CustomCCode.c @@ -167,3 +167,64 @@ Java_com_jogamp_nativewindow_impl_x11_X11Lib_XGetVisualInfoCopied1__JJLjava_nio_ return jbyteCopy; } + +static XIOErrorHandler origIOErrorHandler = NULL; + +static int displayIOErrorHandler(Display *dpy) +{ + fprintf(stderr, "Fatal: Nativewindow X11 IOError: Display %p not available\n", dpy); + origIOErrorHandler(dpy); + return 0; +} + +static void displayIOErrorHandlerEnable(int onoff) { + if(onoff) { + if(NULL==origIOErrorHandler) { + origIOErrorHandler = XSetIOErrorHandler(displayIOErrorHandler); + } + } else { + XSetIOErrorHandler(origIOErrorHandler); + origIOErrorHandler = NULL; + } +} + +/* Java->C glue code: + * Java package: com.jogamp.nativewindow.impl.x11.X11Lib + * Java method: int XCloseDisplay(long display) + * C function: int XCloseDisplay(Display * display); + */ +JNIEXPORT jint JNICALL +Java_com_jogamp_nativewindow_impl_x11_X11Lib_XCloseDisplay__J(JNIEnv *env, jclass _unused, jlong display) { + int _res; + // fprintf(stderr, "X11Lib.XCloseDisplay: %p\n", (Display *) (intptr_t) display); + displayIOErrorHandlerEnable(1); + _res = XCloseDisplay((Display *) (intptr_t) display); + displayIOErrorHandlerEnable(0); + return _res; +} + +/* Java->C glue code: + * Java package: com.jogamp.nativewindow.impl.x11.X11Lib + * Java method: long XOpenDisplay(java.lang.String arg0) + * C function: Display * XOpenDisplay(const char * ); + */ +JNIEXPORT jlong JNICALL +Java_com_jogamp_nativewindow_impl_x11_X11Lib_XOpenDisplay__Ljava_lang_String_2(JNIEnv *env, jclass _unused, jstring arg0) { + const char* _strchars_arg0 = NULL; + Display * _res; + if ( NULL != arg0 ) { + _strchars_arg0 = (*env)->GetStringUTFChars(env, arg0, (jboolean*)NULL); + if ( NULL == _strchars_arg0 ) { + (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/OutOfMemoryError"), + "Failed to get UTF-8 chars for argument \"arg0\" in native dispatcher for \"XOpenDisplay\""); + return 0; + } + } + _res = XOpenDisplay((char *) _strchars_arg0); + // fprintf(stderr, "X11Lib.XOpenDisplay: %s -> %p\n", _strchars_arg0, _res); + if ( NULL != arg0 ) { + (*env)->ReleaseStringUTFChars(env, arg0, _strchars_arg0); + } + return (jlong) (intptr_t) _res; +} + diff --git a/make/config/nativewindow/x11-CustomJavaCode.java b/make/config/nativewindow/x11-CustomJavaCode.java index 5c269c6c8..d631c92cb 100644 --- a/make/config/nativewindow/x11-CustomJavaCode.java +++ b/make/config/nativewindow/x11-CustomJavaCode.java @@ -24,3 +24,8 @@ /** Entry point to C language function: XVisualInfo * XGetVisualInfo(Display * , long, XVisualInfo * , int * ); */ private static native java.nio.ByteBuffer XGetVisualInfoCopied1(long arg0, long arg1, java.nio.ByteBuffer arg2, Object arg3, int arg3_byte_offset); + public static native long XOpenDisplay(String arg0); + public static native int XCloseDisplay(long display); + public static native long dlopen(String name); + public static native long dlsym(String name); + diff --git a/make/config/nativewindow/x11-lib.cfg b/make/config/nativewindow/x11-lib.cfg index 7a64307da..394dd230a 100644 --- a/make/config/nativewindow/x11-lib.cfg +++ b/make/config/nativewindow/x11-lib.cfg @@ -20,8 +20,9 @@ Opaque long Display * Opaque boolean Bool Opaque long GLXFBConfig -CustomJavaCode X11Lib public static native long dlopen(String name); -CustomJavaCode X11Lib public static native long dlsym(String name); +# Manually implement XOpenDisplay, XCloseDisplay, catching XIOError +ManuallyImplement XCloseDisplay +ManuallyImplement XOpenDisplay IncludeAs CustomJavaCode X11Lib x11-CustomJavaCode.java IncludeAs CustomCCode x11-CustomCCode.c diff --git a/make/stub_includes/win32/wingdi.h b/make/stub_includes/win32/wingdi.h index 46aeec2b6..fbf2ec5ec 100644 --- a/make/stub_includes/win32/wingdi.h +++ b/make/stub_includes/win32/wingdi.h @@ -212,7 +212,7 @@ WINGDIAPI HGDIOBJ WINAPI SelectObject(HDC, HGDIOBJ); // Routines for creation of a dummy window, device context and OpenGL // context for the purposes of getting wglChoosePixelFormatARB and // associated routines -HDC CreateDummyWindow(int,int,int,int); +HWND CreateDummyWindow( int x, int y, int width, int height ) ; WINUSERAPI BOOL WINAPI ShowWindow(HWND hWnd, int nCmdShow); WINUSERAPI HDC WINAPI GetDC(HWND); WINUSERAPI int WINAPI ReleaseDC(HWND hWnd, HDC hDC); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java index 893827a8c..7543a1084 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java @@ -41,6 +41,7 @@ package com.jogamp.opengl.impl; import com.jogamp.common.os.DynamicLookupHelper; import java.nio.*; +import java.util.*; import javax.media.opengl.*; import com.jogamp.nativewindow.impl.NWReflection; @@ -346,13 +347,30 @@ public abstract class GLContextImpl extends GLContext { /** Maps the given "platform-independent" function name to a real function name. Currently this is only used to map "glAllocateMemoryNV" and associated routines to wglAllocateMemoryNV / glXAllocateMemoryNV. */ - protected abstract String mapToRealGLFunctionName(String glFunctionName); + protected String mapToRealGLFunctionName(String glFunctionName) { + Map/**/ map = getFunctionNameMap(); + String lookup = ( null != map ) ? (String) map.get(glFunctionName) : null; + if (lookup != null) { + return lookup; + } + return glFunctionName; + } + protected abstract Map/**/ getFunctionNameMap() ; /** Maps the given "platform-independent" extension name to a real function name. Currently this is only used to map - "GL_ARB_pbuffer" and "GL_ARB_pixel_format" to "WGL_ARB_pbuffer" - and "WGL_ARB_pixel_format" (not yet mapped to X11). */ - protected abstract String mapToRealGLExtensionName(String glExtensionName); + "GL_ARB_pbuffer" to "WGL_ARB_pbuffer/GLX_SGIX_pbuffer" and + "GL_ARB_pixel_format" to "WGL_ARB_pixel_format/n.a." + */ + protected String mapToRealGLExtensionName(String glExtensionName) { + Map/**/ map = getExtensionNameMap(); + String lookup = ( null != map ) ? (String) map.get(glExtensionName) : null; + if (lookup != null) { + return lookup; + } + return glExtensionName; + } + protected abstract Map/**/ getExtensionNameMap() ; /** Helper routine which resets a ProcAddressTable generated by the GLEmitter by looking up anew all of its function pointers. */ diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java index c8faf0f65..35810678c 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java @@ -54,6 +54,9 @@ import java.lang.reflect.*; public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { protected static final boolean DEBUG = Debug.debug("GLDrawableFactory"); + public void shutdown() { + } + //--------------------------------------------------------------------------- // Dispatching GLDrawable construction in respect to the NativeWindow Capabilities // @@ -76,7 +79,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { if( ! ( target instanceof SurfaceChangeable ) ) { throw new IllegalArgumentException("Passed NativeWindow must implement SurfaceChangeable for offscreen: "+target); } - if(caps.isPBuffer() && canCreateGLPbuffer()) { + if(caps.isPBuffer()) { if(DEBUG) { System.out.println("GLDrawableFactoryImpl.createGLDrawable -> PbufferDrawable: "+target); } @@ -111,7 +114,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { protected abstract GLDrawableImpl createGLPbufferDrawableImpl(NativeWindow target); protected GLDrawableImpl createGLPbufferDrawable(NativeWindow target) { - if (!canCreateGLPbuffer()) { + if (!canCreateGLPbuffer(target.getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice())) { throw new GLException("Pbuffer support not available with current graphics card"); } return createGLPbufferDrawableImpl(target); @@ -215,7 +218,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { // implement this functionality on all other platforms // - public abstract boolean canCreateContextOnJava2DSurface(); + public abstract boolean canCreateContextOnJava2DSurface(AbstractGraphicsDevice device); public abstract GLContext createContextOnJava2DSurface(Object graphics, GLContext shareWith) throws GLException; @@ -312,7 +315,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { throw new IllegalArgumentException("Should not call this unless setDisplayGamma called first"); } resetGammaRamp(originalGammaRamp); - unregisterGammeShutdownHook(); + unregisterGammaShutdownHook(); } //------------------------------------------------------ @@ -364,7 +367,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { gammaShutdownHookRegistered = true; } - private synchronized void unregisterGammeShutdownHook() { + private synchronized void unregisterGammaShutdownHook() { if (!gammaShutdownHookRegistered) return; if (gammaShutdownHook == null) { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableImpl.java index 10c70db99..04114a445 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableImpl.java @@ -153,11 +153,9 @@ public abstract class GLDrawableImpl implements GLDrawable { } public String toString() { - return getClass().getName()+"[realized "+getRealized()+ - ",\n\tfactory "+getFactory()+ - ",\n\twindow "+getNativeWindow()+ - ",\n\trequested "+getRequestedGLCapabilities()+ - ",\n\tchosen "+getChosenGLCapabilities()+"]"; + return getClass().getName()+"[Realized "+getRealized()+ + ",\n\tFactory "+getFactory()+ + ",\n\tWindow "+getNativeWindow()+"]"; } protected GLDrawableFactory factory; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java index ec2677559..a96736c00 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java @@ -80,13 +80,9 @@ public abstract class EGLContext extends GLContextImpl { return eglExtProcAddressTable; } - protected String mapToRealGLFunctionName(String glFunctionName) { - return glFunctionName; - } + protected Map/**/ getFunctionNameMap() { return null; } - protected String mapToRealGLExtensionName(String glExtensionName) { - return glExtensionName; - } + protected Map/**/ getExtensionNameMap() { return null; } public long getContext() { return eglContext; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java index 34b039b3a..5a193b2ff 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java @@ -70,7 +70,7 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { throw new GLException("Not yet implemented"); } - public boolean canCreateGLPbuffer() { + public boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { return true; } @@ -89,7 +89,7 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { return new EGLExternalContext(absScreen); } - public boolean canCreateExternalGLDrawable() { + public boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device) { return false; } @@ -100,7 +100,7 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { public void loadGLULibrary() { } - public boolean canCreateContextOnJava2DSurface() { + public boolean canCreateContextOnJava2DSurface(AbstractGraphicsDevice device) { return false; } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java index bf4023c1c..d3a634792 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java @@ -84,16 +84,10 @@ public abstract class MacOSXCGLContext extends GLContextImpl return cglExtProcAddressTable; } - protected String mapToRealGLFunctionName(String glFunctionName) - { - return glFunctionName; - } - - protected String mapToRealGLExtensionName(String glExtensionName) - { - return glExtensionName; - } - + protected Map/**/ getFunctionNameMap() { return null; } + + protected Map/**/ getExtensionNameMap() { return null; } + protected abstract boolean create(); /** diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java index 641e482bc..906088642 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java @@ -71,7 +71,7 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl implements D return new MacOSXOffscreenCGLDrawable(this, target); } - public boolean canCreateGLPbuffer() { + public boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { return true; } @@ -103,7 +103,7 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl implements D return MacOSXExternalCGLContext.create(this, null); } - public boolean canCreateExternalGLDrawable() { + public boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device) { return false; } @@ -121,7 +121,7 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl implements D return CGL.getProcAddress(glFuncName); } - public boolean canCreateContextOnJava2DSurface() { + public boolean canCreateContextOnJava2DSurface(AbstractGraphicsDevice device) { return false; } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXAWTCGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXAWTCGLDrawableFactory.java index cc973c56a..eff01ca18 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXAWTCGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXAWTCGLDrawableFactory.java @@ -42,6 +42,7 @@ package com.jogamp.opengl.impl.macosx.cgl.awt; import java.lang.reflect.InvocationTargetException; import java.nio.*; import java.util.*; +import javax.media.nativewindow.*; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; import com.jogamp.opengl.impl.awt.*; @@ -53,7 +54,7 @@ public class MacOSXAWTCGLDrawableFactory extends MacOSXCGLDrawableFactory { super(); } - public boolean canCreateContextOnJava2DSurface() { + public boolean canCreateContextOnJava2DSurface(AbstractGraphicsDevice device) { return true; } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java index 49e646844..87a37da04 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java @@ -46,8 +46,8 @@ import com.jogamp.nativewindow.impl.NullWindow; public class WindowsDummyWGLDrawable extends WindowsWGLDrawable { private long hwnd, hdc; - public WindowsDummyWGLDrawable(GLDrawableFactory factory) { - super(factory, new NullWindow(WindowsWGLGraphicsConfigurationFactory.createDefaultGraphicsConfiguration(null, true, true)), true); + public WindowsDummyWGLDrawable(GLDrawableFactory factory, GLProfile glp) { + super(factory, new NullWindow(WindowsWGLGraphicsConfigurationFactory.createDefaultGraphicsConfiguration(glp, null, true, true)), true); // All entries to CreateDummyWindow must synchronize on one object // to avoid accidentally registering the dummy window class twice synchronized (WindowsDummyWGLDrawable.class) { @@ -56,8 +56,9 @@ public class WindowsDummyWGLDrawable extends WindowsWGLDrawable { hdc = WGL.GetDC(hwnd); NullWindow nw = (NullWindow) getNativeWindow(); nw.setSurfaceHandle(hdc); + WindowsWGLGraphicsConfiguration config = (WindowsWGLGraphicsConfiguration)nw.getGraphicsConfiguration().getNativeGraphicsConfiguration(); // Choose a (hopefully hardware-accelerated) OpenGL pixel format for this device context - GLCapabilities caps = new GLCapabilities(null); + GLCapabilities caps = (GLCapabilities) config.getChosenCapabilities(); caps.setDepthBits(16); PIXELFORMATDESCRIPTOR pfd = WindowsWGLGraphicsConfiguration.GLCapabilities2PFD(caps); int pixelFormat = WGL.ChoosePixelFormat(hdc, pfd); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java index 08c77539c..b3f4c498c 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java @@ -118,21 +118,9 @@ public class WindowsWGLContext extends GLContextImpl { return wglExtProcAddressTable; } - protected String mapToRealGLFunctionName(String glFunctionName) { - String lookup = (String) functionNameMap.get(glFunctionName); - if (lookup != null) { - return lookup; - } - return glFunctionName; - } + protected Map/**/ getFunctionNameMap() { return functionNameMap; } - protected String mapToRealGLExtensionName(String glExtensionName) { - String lookup = (String) extensionNameMap.get(glExtensionName); - if (lookup != null) { - return lookup; - } - return glExtensionName; - } + protected Map/**/ getExtensionNameMap() { return extensionNameMap; } /** * Creates and initializes an appropriate OpenGL context. Should only be @@ -306,7 +294,7 @@ public class WindowsWGLContext extends GLContextImpl { if (WGL.wglGetCurrentContext() != hglrc) { if (!wglMakeContextCurrent(drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), hglrc)) { - throw new GLException("Error making context current: 0x" + Integer.toHexString(WGL.GetLastError())); + throw new GLException("Error making context current: 0x" + Integer.toHexString(WGL.GetLastError()) + ", " + this); } else { if (DEBUG && VERBOSE) { System.err.println(getThreadName() + ": wglMakeCurrent(hdc " + toHexString(drawable.getNativeWindow().getSurfaceHandle()) + diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java index 9e458c8d0..cb3ee19e0 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java @@ -85,12 +85,12 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements private boolean pbufferSupportInitialized = false; private boolean canCreateGLPbuffer = false; - public boolean canCreateGLPbuffer() { + public boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { if (!pbufferSupportInitialized) { final GLDrawableFactory factory = this; Runnable r = new Runnable() { public void run() { - WindowsDummyWGLDrawable dummyDrawable = new WindowsDummyWGLDrawable(factory); + WindowsDummyWGLDrawable dummyDrawable = new WindowsDummyWGLDrawable(factory, null); GLContext dummyContext = dummyDrawable.createContext(null); if (dummyContext != null) { GLContext lastContext = GLContext.getCurrent(); @@ -123,7 +123,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements final GLDrawableFactory factory = this; Runnable r = new Runnable() { public void run() { - WindowsDummyWGLDrawable dummyDrawable = new WindowsDummyWGLDrawable(factory); + WindowsDummyWGLDrawable dummyDrawable = new WindowsDummyWGLDrawable(factory, null); WindowsWGLContext dummyContext = (WindowsWGLContext) dummyDrawable.createContext(null); GLContext lastContext = GLContext.getCurrent(); if (lastContext != null) { @@ -136,10 +136,14 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements dummyDrawable, dummyWGLExt); returnList.add(pbufferDrawable); - dummyContext.release(); - dummyContext.destroy(); - dummyDrawable.destroy(); } finally { + if(null!=dummyContext) { + dummyContext.release(); + dummyContext.destroy(); + } + if(null!=dummyDrawable) { + dummyDrawable.destroy(); + } if (lastContext != null) { lastContext.makeCurrent(); } @@ -162,7 +166,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements return WindowsExternalWGLContext.create(this, null); } - public boolean canCreateExternalGLDrawable() { + public boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device) { return true; } @@ -222,7 +226,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements return detail; } - public boolean canCreateContextOnJava2DSurface() { + public boolean canCreateContextOnJava2DSurface(AbstractGraphicsDevice device) { return false; } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java index 563173682..55b30ef3a 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java @@ -58,22 +58,17 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio return chooseGraphicsConfigurationStatic(caps, chooser, absScreen); } - protected static WindowsWGLGraphicsConfiguration createDefaultGraphicsConfiguration(AbstractGraphicsScreen absScreen, boolean onscreen, boolean usePBuffer) { - GLCapabilities caps = new GLCapabilities(null); + protected static WindowsWGLGraphicsConfiguration createDefaultGraphicsConfiguration(GLProfile glp, AbstractGraphicsScreen absScreen, boolean onscreen, boolean usePBuffer) { + GLCapabilities caps = new GLCapabilities(glp); caps.setDoubleBuffered(onscreen); // FIXME DBLBUFOFFSCRN caps.setOnscreen (onscreen); caps.setPBuffer (usePBuffer); - GLCapabilities caps2 = (GLCapabilities) caps.clone(); - if(!caps2.isOnscreen()) { - // OFFSCREEN !DOUBLE_BUFFER // FIXME DBLBUFOFFSCRN - caps2.setDoubleBuffered(false); - } - if(null==absScreen) { absScreen = DefaultGraphicsScreen.createScreenDevice(0); } - return new WindowsWGLGraphicsConfiguration(absScreen, caps2, caps, WindowsWGLGraphicsConfiguration.GLCapabilities2PFD(caps2), -1, null); + return new WindowsWGLGraphicsConfiguration(absScreen, caps, caps, WindowsWGLGraphicsConfiguration.GLCapabilities2PFD(caps), -1, null); + } protected static WindowsWGLGraphicsConfiguration chooseGraphicsConfigurationStatic(GLCapabilities caps, @@ -143,7 +138,7 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio GLContextImpl dummyContext = null; WGLExt dummyWGLExt = null; if (capabilities.getSampleBuffers()) { - dummyDrawable = new WindowsDummyWGLDrawable(factory); + dummyDrawable = new WindowsDummyWGLDrawable(factory, glProfile); dummyContext = (GLContextImpl) dummyDrawable.createContext(null); if (dummyContext != null) { dummyContext.makeCurrent(); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java new file mode 100644 index 000000000..097689967 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2010 Sven Gothel. 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 Sven Gothel 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 + * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.jogamp.opengl.impl.x11.glx; + +import javax.media.opengl.*; +import com.jogamp.opengl.impl.*; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; +import com.jogamp.nativewindow.impl.*; +import com.jogamp.nativewindow.impl.x11.*; + +public class X11DummyGLXDrawable extends X11OnscreenGLXDrawable { + + /** + * Due to the ATI Bug https://bugzilla.mozilla.org/show_bug.cgi?id=486277, + * we cannot switch the Display as we please, + * hence we reuse the target's screen configuration. + */ + public X11DummyGLXDrawable(X11GraphicsScreen screen, GLDrawableFactory factory, GLProfile glp) { + super(factory, + new NullWindow(X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( + new GLCapabilities(glp), null, screen))); + this.realized = true; + + NullWindow nw = (NullWindow) getNativeWindow(); + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)nw.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilities caps = (GLCapabilities) config.getChosenCapabilities(); + + long dpy = config.getScreen().getDevice().getHandle(); + int scrn = config.getScreen().getIndex(); + // System.out.println("X11DummyGLXDrawable: dpy "+toHexString(dpy)+", scrn "+scrn); + X11Lib.XLockDisplay(dpy); + try{ + nw.setSurfaceHandle( X11Lib.RootWindow(dpy, scrn) ); + } finally { + X11Lib.XUnlockDisplay(dpy); + } + } + + public void setSize(int width, int height) { + } + + public int getWidth() { + return 1; + } + + public int getHeight() { + return 1; + } + + public void destroy() { + // nothing to do, but allowed + } +} diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java index ce846c0a4..055e7236c 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java @@ -54,6 +54,7 @@ public abstract class X11GLXContext extends GLContextImpl { private boolean glXQueryExtensionsStringInitialized; private boolean glXQueryExtensionsStringAvailable; private static final Map/**/ functionNameMap; + private static final Map/**/ extensionNameMap; private GLXExt glXExt; // Table that holds the addresses of the native C-language entry points for // GLX extension functions. @@ -63,6 +64,10 @@ public abstract class X11GLXContext extends GLContextImpl { functionNameMap = new HashMap(); functionNameMap.put("glAllocateMemoryNV", "glXAllocateMemoryNV"); functionNameMap.put("glFreeMemoryNV", "glXFreeMemoryNV"); + + extensionNameMap = new HashMap(); + extensionNameMap.put("GL_ARB_pbuffer", "GLX_SGIX_pbuffer"); + extensionNameMap.put("GL_ARB_pixel_format", "GLX_SGIX_pbuffer"); // good enough } public X11GLXContext(GLDrawableImpl drawable, GLDrawableImpl drawableRead, @@ -94,17 +99,9 @@ public abstract class X11GLXContext extends GLContextImpl { return glXExt; } - protected String mapToRealGLFunctionName(String glFunctionName) { - String lookup = (String) functionNameMap.get(glFunctionName); - if (lookup != null) { - return lookup; - } - return glFunctionName; - } + protected Map/**/ getFunctionNameMap() { return functionNameMap; } - protected String mapToRealGLExtensionName(String glExtensionName) { - return glExtensionName; - } + protected Map/**/ getExtensionNameMap() { return extensionNameMap; } /** Helper routine which usually just turns around and calls * createContext (except for pbuffers, which use a different context @@ -363,7 +360,7 @@ public abstract class X11GLXContext extends GLContextImpl { drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), context)) { - throw new GLException("Error making context current"); + throw new GLException("Error making context current: "+this); } if (DEBUG && (VERBOSE || created)) { System.err.println(getThreadName() + ": glXMakeCurrent(display " + @@ -485,7 +482,8 @@ public abstract class X11GLXContext extends GLContextImpl { public boolean isExtensionAvailable(String glExtensionName) { if (glExtensionName.equals("GL_ARB_pbuffer") || glExtensionName.equals("GL_ARB_pixel_format")) { - return getGLDrawable().getFactory().canCreateGLPbuffer(); + return getGLDrawable().getFactory().canCreateGLPbuffer( + drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice() ); } return super.isExtensionAvailable(glExtensionName); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java index 1a254843e..60ee431dc 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java @@ -73,14 +73,29 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna return new X11OffscreenGLXDrawable(this, target); } - private boolean pbufferSupportInitialized = false; - private boolean canCreateGLPbuffer = false; - public boolean canCreateGLPbuffer() { - if (!pbufferSupportInitialized) { - long display = X11Util.getThreadLocalDefaultDisplay(); + public boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { + return glxVersionGreaterEqualThan(device, 1, 3); + } + + private boolean glxVersionsQueried = false; + private int glxVersionMajor=0, glxVersionMinor=0; + public boolean glxVersionGreaterEqualThan(AbstractGraphicsDevice device, int majorReq, int minorReq) { + if (!glxVersionsQueried) { + if(null == device) { + GLContext ctx = GLContext.getCurrent(); + if( null != ctx) { + device = ctx.getGLDrawable().getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice(); + } + } + if(null == device) { + GLException gle = new GLException("FIXME: No AbstractGraphicsDevice (passed or queried via current context - Fallback to ThreadLocal Display .."); + gle.printStackTrace(); + + device = new X11GraphicsDevice(X11Util.getThreadLocalDisplay(null)); + } + long display = device.getHandle(); int[] major = new int[1]; int[] minor = new int[1]; - int screen = 0; // FIXME: provide way to specify this? if (!GLX.glXQueryVersion(display, major, 0, minor, 0)) { throw new GLException("glXQueryVersion failed"); @@ -94,34 +109,51 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna // only implement GLX version 1.2 on the server side if (major[0] == 1 && minor[0] == 2) { String str = GLX.glXGetClientString(display, GLX.GLX_VERSION); - if (str != null && str.startsWith("1.") && - (str.charAt(2) >= '3')) { - canCreateGLPbuffer = true; + try { + major[0] = Integer.valueOf(str.substring(0, 1)).intValue(); + minor[0] = Integer.valueOf(str.substring(2, 3)).intValue(); + } catch (NumberFormatException nfe) { + major[0] = 1; + minor[0] = 2; } - } else { - canCreateGLPbuffer = ((major[0] > 1) || (minor[0] > 2)); } - pbufferSupportInitialized = true; + glxVersionMajor = major[0]; + glxVersionMinor = minor[0]; + glxVersionsQueried = true; } - return canCreateGLPbuffer; + return ( glxVersionMajor > majorReq ) || ( glxVersionMajor == majorReq && glxVersionMinor >= minorReq ) ; } protected GLDrawableImpl createGLPbufferDrawableImpl(final NativeWindow target) { + GLDrawableImpl pbufferDrawable; + X11DummyGLXDrawable dummyDrawable=null; + GLContext dummyContext=null; + /** - * FIXME: Think about this .. - * should not be necessary ? .. - final List returnList = new ArrayList(); - final GLDrawableFactory factory = this; - Runnable r = new Runnable() { - public void run() { - returnList.add(new X11PbufferGLXDrawable(factory, target)); + * Due to the ATI Bug https://bugzilla.mozilla.org/show_bug.cgi?id=486277, + * we need to have a context current on the same Display to create a PBuffer. + * The dummy context shall also use the same Display, + * since switching Display in this regard is another ATI bug. + */ + if( null == GLContext.getCurrent() ) { + X11GraphicsScreen screen = (X11GraphicsScreen) target.getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen(); + dummyDrawable = new X11DummyGLXDrawable(screen, this, null); + dummyContext = dummyDrawable.createContext(null); + dummyContext.makeCurrent(); + } + try { + pbufferDrawable = new X11PbufferGLXDrawable(this, target); + } finally { + if(null!=dummyContext) { + dummyContext.release(); + dummyContext.destroy(); } - }; - maybeDoSingleThreadedWorkaround(r); - return (GLDrawableImpl) returnList.get(0); - */ - return new X11PbufferGLXDrawable(this, target); + if(null!=dummyDrawable) { + dummyDrawable.destroy(); + } + } + return pbufferDrawable; } @@ -136,8 +168,8 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna return X11ExternalGLXContext.create(this, null); } - public boolean canCreateExternalGLDrawable() { - return canCreateGLPbuffer(); + public boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device) { + return canCreateGLPbuffer(device); } public GLDrawable createExternalGLDrawable() { @@ -158,7 +190,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna return res; } - public boolean canCreateContextOnJava2DSurface() { + public boolean canCreateContextOnJava2DSurface(AbstractGraphicsDevice device) { return false; } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java index 16e341652..72551f928 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java @@ -59,7 +59,8 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac return chooseGraphicsConfigurationStatic(capabilities, chooser, absScreen); } - protected static X11GLXGraphicsConfiguration createDefaultGraphicsConfiguration(AbstractGraphicsScreen absScreen, boolean onscreen, boolean usePBuffer) { + /** + protected static X11GLXGraphicsConfiguration createDefaultGraphicsConfigurationFBConfig(AbstractGraphicsScreen absScreen, boolean onscreen, boolean usePBuffer) { if (absScreen == null) { throw new IllegalArgumentException("AbstractGraphicsScreen is null"); } @@ -110,7 +111,7 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac } return new X11GLXGraphicsConfiguration(x11Screen, (null!=capsFB)?capsFB:caps, caps, null, xvis, fbcfg, fbid); - } + } */ protected static X11GLXGraphicsConfiguration chooseGraphicsConfigurationStatic(Capabilities capabilities, CapabilitiesChooser chooser, diff --git a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java index d61ceb1f4..71cb3cb3b 100644 --- a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java +++ b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java @@ -173,8 +173,7 @@ public abstract class GLDrawableFactory { destroy any GLContexts and GLDrawables that have been created and are still in use. No further OpenGL calls may be made after shutting down the GLDrawableFactory. */ - public void shutdown() { - } + public abstract void shutdown(); //---------------------------------------------------------------------- // Methods to create high-level objects @@ -218,7 +217,7 @@ public abstract class GLDrawableFactory { * Returns true if it is possible to create a GLPbuffer. Some older * graphics cards do not have this capability. */ - public abstract boolean canCreateGLPbuffer(); + public abstract boolean canCreateGLPbuffer(AbstractGraphicsDevice device); /** * Creates a Pbuffer GLDrawable with the given capabilites and dimensions.

@@ -280,7 +279,7 @@ public abstract class GLDrawableFactory { * Returns true if it is possible to create an external GLDrawable * object via {@link #createExternalGLDrawable}. */ - public abstract boolean canCreateExternalGLDrawable(); + public abstract boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device); /** *

Creates a {@link GLDrawable} object representing an existing diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java index 43b2e1e1d..e8de00629 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java @@ -494,7 +494,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { backend = new J2DOGLBackend(); } else { if (!hardwareAccelerationDisabled && - factory.canCreateGLPbuffer()) { + factory.canCreateGLPbuffer(null)) { backend = new PbufferBackend(); } else { if (softwareRenderingDisabled) { @@ -1509,7 +1509,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { } } if (joglContext == null) { - if (factory.canCreateExternalGLDrawable()) { + AbstractGraphicsDevice device = j2dContext.getGLDrawable().getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice(); + if (factory.canCreateExternalGLDrawable(device)) { joglDrawable = factory.createExternalGLDrawable(); // FIXME: Need to share with j2d context, due to FBO resource .. // - ORIG: joglContext = joglDrawable.createContext(shareWith); @@ -1518,7 +1519,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { System.err.println("-- Created External Drawable: "+joglDrawable); System.err.println("-- Created Context: "+joglContext); } - } else if (factory.canCreateContextOnJava2DSurface()) { + } else if (factory.canCreateContextOnJava2DSurface(device)) { // Mac OS X code path // FIXME: Need to share with j2d context, due to FBO resource .. // - ORIG: joglContext = factory.createContextOnJava2DSurface(g, shareWith); diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java index 9fc986180..95fd6c72b 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java @@ -113,11 +113,11 @@ public class X11Util { return 0; } long dpy = namedDpy.getHandle(); - X11Lib.XCloseDisplay(dpy); if(DEBUG) { - Exception e = new Exception("X11Util.Display: Closed TLS Display("+name+") with handle 0x"+Long.toHexString(dpy)+" in thread "+Thread.currentThread().getName()); + Exception e = new Exception("X11Util.Display: Closing TLS Display("+name+") with handle 0x"+Long.toHexString(dpy)+" in thread "+Thread.currentThread().getName()); e.printStackTrace(); } + X11Lib.XCloseDisplay(dpy); return dpy; } -- cgit v1.2.3 From 2ae28d54858ff684bc2368e0476a7a357dc63432 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 15 Apr 2010 03:44:12 +0200 Subject: Further ATI (fglrx) X11Display bug workaround/cleanup - See https://bugzilla.mozilla.org/show_bug.cgi?id=486277 - Calling XCloseDisplay occasionally leads to a SIGSEGV, even thought the reference is valid and OK. Workaround is not to close any X11Display, but to hold them stashed and reuse them. Since we already pipeline all X11Display's via Nativewindow's X11Util, an added referenceCounter and a global active/passive list solved this problem. This workaround is only active in case 'isVendorATI()'. NEWT/NativeWindow X11: - Let XIOErrorHandler and invalid display references fail hard with FatalError, otherwise we won't see the stack trace - and those bugs are indeed fatal. NativeWindow X11: - Install XIOErrorHandler, which stays active. - X11Util.X11Display: - Add reference counter - Add global active/passive list. Passive if reference count == 0 and marked as 'un-closeable' (-> ATI). Reusing passive members when create a new display. - JOGL: - Use DeleteLocalRef() calls to free temp NIO buffer in manual *Copied implementation. - GLDrawableFactoryImpl: Be serious about the shutdown() semantics - *GraphicsConfiguration: - Fix the invalid Onscreen/PBuffer/Pixmap determination (X11/EGL/WGL) - Just return null if not valid - X11GLXGraphicsConfigurationFactory - FBConfig - Determine recommendedIndex properly .. - Don't bail out if a FBConfig is invalid .. - Use Chooser in case nothing is recommended .. - X11OffscreenGLXDrawable fixes bugs: - wrong (int) cast of parent window in XCreatePixmap call - setting display to zero too early in destruction, ie before XCloseDisplay - X11GLXDrawableFactory is using [singleton] shared dummy resources for - Screen, Drawable and Context which are utilized in case they are needed .. They are removed at shutdown call - GLXVersion gathering in GLXUtil now .. - DefaultGLCapabilitiesChooser: Respect PBuffer selection Tests: - Add DrawableFactory shutdown() - Add various Offscreen Capabilties - Add Offscreen and non-pbuffer case - JUnit Passed (Linux64bit: NVidia/ATI) - demos.jrefract.JRefract passed (Linux64bit: NVidia/ATI) --- make/build-nativewindow.xml | 3 + make/config/jogl/glx-CustomCCode.c | 7 +- make/config/nativewindow/x11-CustomCCode.c | 230 ---------- make/config/nativewindow/x11-CustomJavaCode.java | 12 +- make/config/nativewindow/x11-lib.cfg | 20 +- make/stub_includes/x11/window-lib.c | 3 + .../jogamp/opengl/impl/GLDrawableFactoryImpl.java | 17 + .../opengl/impl/egl/EGLGraphicsConfiguration.java | 19 +- .../wgl/WindowsWGLGraphicsConfiguration.java | 15 +- .../WindowsWGLGraphicsConfigurationFactory.java | 8 +- .../com/jogamp/opengl/impl/x11/glx/GLXUtil.java | 48 ++- .../opengl/impl/x11/glx/X11DummyGLXDrawable.java | 20 +- .../jogamp/opengl/impl/x11/glx/X11GLXContext.java | 36 +- .../opengl/impl/x11/glx/X11GLXDrawableFactory.java | 156 +++++-- .../impl/x11/glx/X11GLXGraphicsConfiguration.java | 57 ++- .../glx/X11GLXGraphicsConfigurationFactory.java | 92 +++- .../impl/x11/glx/X11OffscreenGLXDrawable.java | 12 +- .../awt/X11AWTGLXGraphicsConfigurationFactory.java | 2 +- .../media/opengl/DefaultGLCapabilitiesChooser.java | 11 +- .../javax/media/opengl/GLDrawableFactory.java | 2 + .../junit/jogl/drawable/TestDrawable01NEWT.java | 35 +- .../junit/jogl/offscreen/TestOffscreen01NEWT.java | 264 ++++++++++-- .../test/junit/jogl/offscreen/WindowUtilNEWT.java | 25 +- .../com/jogamp/nativewindow/impl/x11/X11Util.java | 228 ++++++++-- .../media/nativewindow/x11/X11GraphicsScreen.java | 2 +- src/nativewindow/native/x11/Xmisc.c | 471 +++++++++++++++++++++ .../classes/com/jogamp/newt/x11/X11Display.java | 6 +- src/newt/native/X11Window.c | 76 ++-- 28 files changed, 1369 insertions(+), 508 deletions(-) delete mode 100755 make/config/nativewindow/x11-CustomCCode.c create mode 100644 src/nativewindow/native/x11/Xmisc.c (limited to 'src/nativewindow/classes') diff --git a/make/build-nativewindow.xml b/make/build-nativewindow.xml index 3a62e9733..4b726bafb 100644 --- a/make/build-nativewindow.xml +++ b/make/build-nativewindow.xml @@ -530,6 +530,7 @@ + @@ -623,6 +624,8 @@ + + CallStaticObjectMethod(env, clazzInternalBufferUtil, cstrInternalBufferUtil, jbyteSource); - // FIXME: remove reference/gc jbyteSource ?? + (*env)->DeleteLocalRef(env, jbyteSource); XFree(_res); return jbyteCopy; @@ -118,8 +118,7 @@ Java_com_jogamp_opengl_impl_x11_glx_GLX_glXChooseFBConfigCopied1__JILjava_lang_O jbyteSource = (*env)->NewDirectByteBuffer(env, _res, count * sizeof(GLXFBConfig)); jbyteCopy = (*env)->CallStaticObjectMethod(env, clazzInternalBufferUtil, cstrInternalBufferUtil, jbyteSource); - - // FIXME: remove reference/gc jbyteSource ?? + (*env)->DeleteLocalRef(env, jbyteSource); XFree(_res); return jbyteCopy; @@ -151,7 +150,7 @@ Java_com_jogamp_opengl_impl_x11_glx_GLX_glXChooseVisualCopied1__JILjava_lang_Obj jbyteCopy = (*env)->CallStaticObjectMethod(env, clazzInternalBufferUtil, cstrInternalBufferUtil, jbyteSource); - // FIXME: remove reference/gc jbyteSource ?? + (*env)->DeleteLocalRef(env, jbyteSource); XFree(_res); return jbyteCopy; diff --git a/make/config/nativewindow/x11-CustomCCode.c b/make/config/nativewindow/x11-CustomCCode.c deleted file mode 100755 index 982a39f7e..000000000 --- a/make/config/nativewindow/x11-CustomCCode.c +++ /dev/null @@ -1,230 +0,0 @@ -#include -#include -#include -/* Linux headers don't work properly */ -#define __USE_GNU -#include -#undef __USE_GNU - -/* Current versions of Solaris don't expose the XF86 extensions, - although with the recent transition to Xorg this will probably - happen in an upcoming release */ -#if !defined(__sun) && !defined(_HPUX) -#include -#else -/* Need to provide stubs for these */ -Bool XF86VidModeGetGammaRampSize( - Display *display, - int screen, - int* size) -{ - return False; -} - -Bool XF86VidModeGetGammaRamp( - Display *display, - int screen, - int size, - unsigned short *red_array, - unsigned short *green_array, - unsigned short *blue_array) { - return False; -} -Bool XF86VidModeSetGammaRamp( - Display *display, - int screen, - int size, - unsigned short *red_array, - unsigned short *green_array, - unsigned short *blue_array) { - return False; -} -#endif - -/* HP-UX doesn't define RTLD_DEFAULT. */ -#if defined(_HPUX) && !defined(RTLD_DEFAULT) -#define RTLD_DEFAULT NULL -#endif - -/* Need to expose DefaultScreen and RootWindow macros to Java */ -JNIEXPORT jlong JNICALL -Java_com_jogamp_nativewindow_impl_x11_X11Lib_DefaultScreen(JNIEnv *env, jclass _unused, jlong display) { - return DefaultScreen((Display*) (intptr_t) display); -} - -JNIEXPORT jlong JNICALL -Java_com_jogamp_nativewindow_impl_x11_X11Lib_DefaultVisualID(JNIEnv *env, jclass _unused, jlong display, jint screen) { - return (jlong) XVisualIDFromVisual( DefaultVisual( (Display*) (intptr_t) display, screen ) ); -} - -JNIEXPORT jlong JNICALL -Java_com_jogamp_nativewindow_impl_x11_X11Lib_RootWindow(JNIEnv *env, jclass _unused, jlong display, jint screen) { - return RootWindow((Display*) (intptr_t) display, screen); -} - -JNIEXPORT jlong JNICALL -Java_com_jogamp_nativewindow_impl_x11_X11Lib_dlopen(JNIEnv *env, jclass _unused, jstring name) { - const jbyte* chars; - void* res; - chars = (*env)->GetStringUTFChars(env, name, NULL); - res = dlopen(chars, RTLD_LAZY | RTLD_GLOBAL); - (*env)->ReleaseStringUTFChars(env, name, chars); - return (jlong) ((intptr_t) res); -} - -JNIEXPORT jlong JNICALL -Java_com_jogamp_nativewindow_impl_x11_X11Lib_dlsym(JNIEnv *env, jclass _unused, jstring name) { - const jbyte* chars; - void* res; - chars = (*env)->GetStringUTFChars(env, name, NULL); - res = dlsym(RTLD_DEFAULT, chars); - (*env)->ReleaseStringUTFChars(env, name, chars); - return (jlong) ((intptr_t) res); -} - -/* Need to pull this in as we don't have a stub header for it */ -extern Bool XineramaEnabled(Display* display); - -static const char * clazzNameInternalBufferUtil = "com/jogamp/nativewindow/impl/InternalBufferUtil"; -static const char * clazzNameInternalBufferUtilStaticCstrName = "copyByteBuffer"; -static const char * clazzNameInternalBufferUtilStaticCstrSignature = "(Ljava/nio/ByteBuffer;)Ljava/nio/ByteBuffer;"; -static const char * clazzNameByteBuffer = "java/nio/ByteBuffer"; -static jclass clazzInternalBufferUtil = NULL; -static jmethodID cstrInternalBufferUtil = NULL; -static jclass clazzByteBuffer = NULL; - -static void _initClazzAccess(JNIEnv *env) { - jclass c; - - if(NULL!=cstrInternalBufferUtil) return ; - - c = (*env)->FindClass(env, clazzNameInternalBufferUtil); - if(NULL==c) { - fprintf(stderr, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s\n", clazzNameInternalBufferUtil); - (*env)->FatalError(env, clazzNameInternalBufferUtil); - } - clazzInternalBufferUtil = (jclass)(*env)->NewGlobalRef(env, c); - if(NULL==clazzInternalBufferUtil) { - fprintf(stderr, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s\n", clazzNameInternalBufferUtil); - (*env)->FatalError(env, clazzNameInternalBufferUtil); - } - c = (*env)->FindClass(env, clazzNameByteBuffer); - if(NULL==c) { - fprintf(stderr, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s\n", clazzNameByteBuffer); - (*env)->FatalError(env, clazzNameByteBuffer); - } - clazzByteBuffer = (jclass)(*env)->NewGlobalRef(env, c); - if(NULL==c) { - fprintf(stderr, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s\n", clazzNameByteBuffer); - (*env)->FatalError(env, clazzNameByteBuffer); - } - - cstrInternalBufferUtil = (*env)->GetStaticMethodID(env, clazzInternalBufferUtil, - clazzNameInternalBufferUtilStaticCstrName, clazzNameInternalBufferUtilStaticCstrSignature); - if(NULL==cstrInternalBufferUtil) { - fprintf(stderr, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib:: can't create %s.%s %s\n", - clazzNameInternalBufferUtil, - clazzNameInternalBufferUtilStaticCstrName, clazzNameInternalBufferUtilStaticCstrSignature); - (*env)->FatalError(env, clazzNameInternalBufferUtilStaticCstrName); - } -} - -/* Java->C glue code: - * Java package: com.jogamp.nativewindow.impl.x11.X11Lib - * Java method: XVisualInfo XGetVisualInfo(long arg0, long arg1, XVisualInfo arg2, java.nio.IntBuffer arg3) - * C function: XVisualInfo * XGetVisualInfo(Display * , long, XVisualInfo * , int * ); - */ -JNIEXPORT jobject JNICALL -Java_com_jogamp_nativewindow_impl_x11_X11Lib_XGetVisualInfoCopied1__JJLjava_nio_ByteBuffer_2Ljava_lang_Object_2I(JNIEnv *env, jclass _unused, jlong arg0, jlong arg1, jobject arg2, jobject arg3, jint arg3_byte_offset) { - XVisualInfo * _ptr2 = NULL; - int * _ptr3 = NULL; - XVisualInfo * _res; - int count; - jobject jbyteSource; - jobject jbyteCopy; - if (arg2 != NULL) { - _ptr2 = (XVisualInfo *) (((char*) (*env)->GetDirectBufferAddress(env, arg2)) + 0); - } - if (arg3 != NULL) { - _ptr3 = (int *) (((char*) (*env)->GetPrimitiveArrayCritical(env, arg3, NULL)) + arg3_byte_offset); - } - _res = XGetVisualInfo((Display *) (intptr_t) arg0, (long) arg1, (XVisualInfo *) _ptr2, (int *) _ptr3); - count = _ptr3[0]; - if (arg3 != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, arg3, _ptr3, 0); - } - if (_res == NULL) return NULL; - - _initClazzAccess(env); - - jbyteSource = (*env)->NewDirectByteBuffer(env, _res, count * sizeof(XVisualInfo)); - jbyteCopy = (*env)->CallStaticObjectMethod(env, - clazzInternalBufferUtil, cstrInternalBufferUtil, jbyteSource); - - // FIXME: remove reference/gc jbyteSource ?? - XFree(_res); - - return jbyteCopy; -} - - -static XIOErrorHandler origIOErrorHandler = NULL; - -static int displayIOErrorHandler(Display *dpy) -{ - fprintf(stderr, "Fatal: Nativewindow X11 IOError: Display %p not available\n", dpy); - origIOErrorHandler(dpy); - return 0; -} - -static void displayIOErrorHandlerEnable(int onoff) { - if(onoff) { - if(NULL==origIOErrorHandler) { - origIOErrorHandler = XSetIOErrorHandler(displayIOErrorHandler); - } - } else { - XSetIOErrorHandler(origIOErrorHandler); - origIOErrorHandler = NULL; - } -} - -/* Java->C glue code: - * Java package: com.jogamp.nativewindow.impl.x11.X11Lib - * Java method: int XCloseDisplay(long display) - * C function: int XCloseDisplay(Display * display); - */ -JNIEXPORT jint JNICALL -Java_com_jogamp_nativewindow_impl_x11_X11Lib_XCloseDisplay__J(JNIEnv *env, jclass _unused, jlong display) { - int _res; - // fprintf(stderr, "X11Lib.XCloseDisplay: %p\n", (Display *) (intptr_t) display); - displayIOErrorHandlerEnable(1); - _res = XCloseDisplay((Display *) (intptr_t) display); - displayIOErrorHandlerEnable(0); - return _res; -} - -/* Java->C glue code: - * Java package: com.jogamp.nativewindow.impl.x11.X11Lib - * Java method: long XOpenDisplay(java.lang.String arg0) - * C function: Display * XOpenDisplay(const char * ); - */ -JNIEXPORT jlong JNICALL -Java_com_jogamp_nativewindow_impl_x11_X11Lib_XOpenDisplay__Ljava_lang_String_2(JNIEnv *env, jclass _unused, jstring arg0) { - const char* _strchars_arg0 = NULL; - Display * _res; - if ( NULL != arg0 ) { - _strchars_arg0 = (*env)->GetStringUTFChars(env, arg0, (jboolean*)NULL); - if ( NULL == _strchars_arg0 ) { - (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/OutOfMemoryError"), - "Failed to get UTF-8 chars for argument \"arg0\" in native dispatcher for \"XOpenDisplay\""); - return 0; - } - } - _res = XOpenDisplay((char *) _strchars_arg0); - // fprintf(stderr, "X11Lib.XOpenDisplay: %s -> %p\n", _strchars_arg0, _res); - if ( NULL != arg0 ) { - (*env)->ReleaseStringUTFChars(env, arg0, _strchars_arg0); - } - return (jlong) (intptr_t) _res; -} - diff --git a/make/config/nativewindow/x11-CustomJavaCode.java b/make/config/nativewindow/x11-CustomJavaCode.java index d631c92cb..57f37bee7 100644 --- a/make/config/nativewindow/x11-CustomJavaCode.java +++ b/make/config/nativewindow/x11-CustomJavaCode.java @@ -24,8 +24,16 @@ /** Entry point to C language function: XVisualInfo * XGetVisualInfo(Display * , long, XVisualInfo * , int * ); */ private static native java.nio.ByteBuffer XGetVisualInfoCopied1(long arg0, long arg1, java.nio.ByteBuffer arg2, Object arg3, int arg3_byte_offset); - public static native long XOpenDisplay(String arg0); - public static native int XCloseDisplay(long display); + public static native long DefaultVisualID(long display, int screen); + + /** + public static native long CreateDummyWindow(long display, int screen_index, long visualID); + public static native void DestroyDummyWindow(long display, long window); */ + public static native long dlopen(String name); public static native long dlsym(String name); + public static native int XCloseDisplay(long display); + public static native void XUnlockDisplay(long display); + public static native void XLockDisplay(long display); + diff --git a/make/config/nativewindow/x11-lib.cfg b/make/config/nativewindow/x11-lib.cfg index 394dd230a..cf9642398 100644 --- a/make/config/nativewindow/x11-lib.cfg +++ b/make/config/nativewindow/x11-lib.cfg @@ -20,25 +20,25 @@ Opaque long Display * Opaque boolean Bool Opaque long GLXFBConfig -# Manually implement XOpenDisplay, XCloseDisplay, catching XIOError -ManuallyImplement XCloseDisplay -ManuallyImplement XOpenDisplay - IncludeAs CustomJavaCode X11Lib x11-CustomJavaCode.java -IncludeAs CustomCCode x11-CustomCCode.c +# Now resides in x11/Xmisc.c: IncludeAs CustomCCode x11-CustomCCode.c ArgumentIsString XOpenDisplay 0 -# Need to expose DefaultScreen and RootWindow macros to Java -CustomJavaCode X11Lib public static native int DefaultScreen(long display); -CustomJavaCode X11Lib public static native long DefaultVisualID(long display, int screen); -CustomJavaCode X11Lib public static native long RootWindow(long display, int screen); - # We have Custom code for the following Ignore XGetVisualInfo +ManuallyImplement XCloseDisplay +ManuallyImplement XUnlockDisplay +ManuallyImplement XLockDisplay + # Helper routine to make the ReturnedArrayLength expression below work correctly CustomJavaCode X11Lib private static int getFirstElement(IntBuffer buf) { return buf.get(buf.position()); } CustomJavaCode X11Lib private static int getFirstElement(int[] arr, int offset) { return arr[offset]; } CustomJavaCode XVisualInfo public static XVisualInfo create(XVisualInfo s) { XVisualInfo d = XVisualInfo.create(); d.getBuffer().put(s.getBuffer()); d.getBuffer().rewind(); s.getBuffer().rewind(); return d; } + +CustomCCode #include +CustomCCode #include +CustomCCode #include + diff --git a/make/stub_includes/x11/window-lib.c b/make/stub_includes/x11/window-lib.c index 3096cde4c..8fca86263 100644 --- a/make/stub_includes/x11/window-lib.c +++ b/make/stub_includes/x11/window-lib.c @@ -17,6 +17,9 @@ extern void XLockDisplay(Display *display); extern void XUnlockDisplay(Display *display); +extern Window RootWindow(Display *display, int screen_number); +extern int DefaultScreen(Display *display); + extern XVisualInfo *XGetVisualInfo( Display* /* display */, long /* vinfo_mask */, diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java index 35810678c..616640bad 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java @@ -54,13 +54,24 @@ import java.lang.reflect.*; public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { protected static final boolean DEBUG = Debug.debug("GLDrawableFactory"); + private boolean isValid = false; + public void shutdown() { + validate(); + isValid = false; + } + + protected final void validate() { + if(!isValid) { + throw new GLException("GLDrawableFactory is already shutdown!"); + } } //--------------------------------------------------------------------------- // Dispatching GLDrawable construction in respect to the NativeWindow Capabilities // public GLDrawable createGLDrawable(NativeWindow target) { + validate(); if (target == null) { throw new IllegalArgumentException("Null target"); } @@ -124,6 +135,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { GLCapabilitiesChooser chooser, int width, int height) { + validate(); if(height<=0 || height<=0) { throw new GLException("Width and height of pbuffer must be positive (were (" + width + ", " + height + "))"); @@ -139,6 +151,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { int width, int height, GLContext shareWith) { + validate(); return new GLPbufferImpl( (GLDrawableImpl) createGLPbufferDrawable(capabilities, chooser, height, height), shareWith); } @@ -155,6 +168,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { GLCapabilitiesChooser chooser, int width, int height) { + validate(); if(width<=0 || height<=0) { throw new GLException("Width and height of pbuffer must be positive (were (" + width + ", " + height + "))"); @@ -174,6 +188,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { protected GLDrawableFactoryImpl() { super(); + isValid = true; } protected void maybeDoSingleThreadedWorkaround(Runnable action) { @@ -279,6 +294,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { * out-of-bounds */ public boolean setDisplayGamma(float gamma, float brightness, float contrast) throws IllegalArgumentException { + validate(); if ((brightness < -1.0f) || (brightness > 1.0f)) { throw new IllegalArgumentException("Brightness must be between -1.0 and 1.0"); } @@ -311,6 +327,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { } public synchronized void resetDisplayGamma() { + validate(); if (gammaShutdownHook == null) { throw new IllegalArgumentException("Should not call this unless setDisplayGamma called first"); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfiguration.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfiguration.java index c8bc4fe0d..2d5154442 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfiguration.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfiguration.java @@ -122,10 +122,11 @@ public class EGLGraphicsConfiguration extends DefaultGraphicsConfiguration imple if ( onscreen ) { res = ( 0 != (val & EGL.EGL_WINDOW_BIT) ) ; } else { - res = ( 0 != (val & EGL.EGL_PIXMAP_BIT) ) || usePBuffer ; - } - if ( usePBuffer ) { - res = res && ( 0 != (val & EGL.EGL_PBUFFER_BIT) ) ; + if ( usePBuffer ) { + res = ( 0 != (val & EGL.EGL_PBUFFER_BIT) ) ; + } else { + res = ( 0 != (val & EGL.EGL_PIXMAP_BIT) ) ; + } } return res; @@ -187,17 +188,13 @@ public class EGLGraphicsConfiguration extends DefaultGraphicsConfiguration imple caps.setOnscreen( 0 != (val[0] & EGL.EGL_WINDOW_BIT) ); caps.setPBuffer ( 0 != (val[0] & EGL.EGL_PBUFFER_BIT) ); } else { - throw new GLException("EGL_SURFACE_TYPE does not match !!!"); - } - } else { - if(relaxed) { if(DEBUG) { - System.err.println("Could not determine EGL_SURFACE_TYPE !!!"); + System.err.println("EGL_SURFACE_TYPE does not match: req(onscrn "+onscreen+", pbuffer "+usePBuffer+"), got(onscreen "+( 0 != (val[0] & EGL.EGL_WINDOW_BIT) )+", pbuffer "+( 0 != (val[0] & EGL.EGL_PBUFFER_BIT) )+", pixmap "+( 0 != (val[0] & EGL.EGL_PIXMAP_BIT) )+")"); } return null; - } else { - throw new GLException("Could not determine EGL_SURFACE_TYPE !!!"); } + } else { + throw new GLException("Could not determine EGL_SURFACE_TYPE !!!"); } return caps; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfiguration.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfiguration.java index 5b34e40e1..aed4012a4 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfiguration.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfiguration.java @@ -412,14 +412,16 @@ public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguratio if ( onscreen ) { res = ( 0 != (val & WINDOW_BIT) ) ; } else { - res = ( 0 != (val & BITMAP_BIT) ) || usePBuffer ; - } - if ( usePBuffer ) { - res = res && ( 0 != (val & PBUFFER_BIT) ) ; + if ( usePBuffer ) { + res = ( 0 != (val & PBUFFER_BIT) ) ; + } else { + res = ( 0 != (val & BITMAP_BIT) ) ; + } } return res; } + public static GLCapabilities AttribList2GLCapabilities(GLProfile glp, int[] iattribs, int niattribs, int[] iresults, @@ -433,7 +435,10 @@ public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguratio res.setOnscreen( 0 != (drawableTypeBits & WINDOW_BIT) ); res.setPBuffer ( 0 != (drawableTypeBits & PBUFFER_BIT) ); } else { - throw new GLException("WGL DrawableType does not match !!!"); + if(DEBUG) { + System.err.println("WGL DrawableType does not match: req(onscrn "+onscreen+", pbuffer "+usePBuffer+"), got(onscreen "+( 0 != (drawableTypeBits & WINDOW_BIT) )+", pbuffer "+( 0 != (drawableTypeBits & PBUFFER_BIT) )+", pixmap "+( 0 != (drawableTypeBits & BITMAP_BIT))+")"); + } + return null; } for (int i = 0; i < niattribs; i++) { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java index 55b30ef3a..1a375699c 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java @@ -260,9 +260,11 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio } pixelFormat = 1; // default .. } else if ( pixelFormat > numFormats ) { - throw new GLException("Invalid result " + pixelFormat + - " from GLCapabilitiesChooser (should be between 1 and " + - numFormats + ")"); + // keep on going .. + if(DEBUG) { + System.err.println("GLCapabilitiesChooser specified invalid index (expected 1.." + numFormats + ", got "+pixelFormat+")"); + } + pixelFormat = 1; // default .. } } chosenCaps = availableCaps[pixelFormat-1]; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/GLXUtil.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/GLXUtil.java index 99c54332f..e3c1381f8 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/GLXUtil.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/GLXUtil.java @@ -54,13 +54,55 @@ public class GLXUtil { /** Workaround for apparent issue with ATI's proprietary drivers where direct contexts still send GLX tokens for GL calls */ - public static boolean isVendorATI(long display) { + public static String getVendorName(long display) { try { X11Lib.XLockDisplay(display); - String vendor = GLX.glXGetClientString(display, GLX.GLX_VENDOR); - return vendor != null && vendor.startsWith("ATI") ; + return GLX.glXGetClientString(display, GLX.GLX_VENDOR); } finally { X11Lib.XUnlockDisplay(display); } } + + public static boolean isVendorNVIDIA(String vendor) { + return vendor != null && vendor.startsWith("NVIDIA") ; + } + + public static boolean isVendorATI(String vendor) { + return vendor != null && vendor.startsWith("ATI") ; + } + + public static boolean isVendorATI(long display) { + return isVendorATI(getVendorName(display)); + } + + public static boolean isVendorNVIDIA(long display) { + return isVendorNVIDIA(getVendorName(display)); + } + + public static void getGLXVersion(long display, int major[], int minor[]) { + if(0 == display) { + throw new GLException("null display handle"); + } + if(major.length<1||minor.length<1) { + throw new GLException("passed int arrays size is not >= 1"); + } + + if (!GLX.glXQueryVersion(display, major, 0, minor, 0)) { + throw new GLException("glXQueryVersion failed"); + } + + // Work around bugs in ATI's Linux drivers where they report they + // only implement GLX version 1.2 on the server side + if (major[0] == 1 && minor[0] == 2) { + String str = GLX.glXGetClientString(display, GLX.GLX_VERSION); + try { + // e.g. "1.3" + major[0] = Integer.valueOf(str.substring(0, 1)).intValue(); + minor[0] = Integer.valueOf(str.substring(2, 3)).intValue(); + } catch (Exception e) { + major[0] = 1; + minor[0] = 2; + } + } + } } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java index 097689967..a865e91e8 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java @@ -42,6 +42,8 @@ import com.jogamp.nativewindow.impl.x11.*; public class X11DummyGLXDrawable extends X11OnscreenGLXDrawable { + // private long dummyWindow = 0; + /** * Due to the ATI Bug https://bugzilla.mozilla.org/show_bug.cgi?id=486277, * we cannot switch the Display as we please, @@ -57,12 +59,17 @@ public class X11DummyGLXDrawable extends X11OnscreenGLXDrawable { X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)nw.getGraphicsConfiguration().getNativeGraphicsConfiguration(); GLCapabilities caps = (GLCapabilities) config.getChosenCapabilities(); - long dpy = config.getScreen().getDevice().getHandle(); - int scrn = config.getScreen().getIndex(); - // System.out.println("X11DummyGLXDrawable: dpy "+toHexString(dpy)+", scrn "+scrn); + X11GraphicsDevice device = (X11GraphicsDevice) screen.getDevice(); + long dpy = device.getHandle(); + int scrn = screen.getIndex(); + // long visualID = config.getVisualID(); + // System.out.println("X11DummyGLXDrawable: dpy "+toHexString(dpy)+", scrn "+scrn+", visualID "+toHexString(visualID)); + X11Lib.XLockDisplay(dpy); try{ nw.setSurfaceHandle( X11Lib.RootWindow(dpy, scrn) ); + // dummyWindow = X11Lib.CreateDummyWindow(dpy, scrn, visualID); + // nw.setSurfaceHandle( dummyWindow ); } finally { X11Lib.XUnlockDisplay(dpy); } @@ -80,6 +87,11 @@ public class X11DummyGLXDrawable extends X11OnscreenGLXDrawable { } public void destroy() { - // nothing to do, but allowed + /** + if(0!=dummyWindow) { + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + long dpy = config.getScreen().getDevice().getHandle(); + X11Lib.DestroyDummyWindow(dpy, dummyWindow); + } */ } } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java index 055e7236c..142da672a 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java @@ -133,7 +133,7 @@ public abstract class X11GLXContext extends GLContextImpl { } GLCapabilities glCaps = (GLCapabilities) config.getChosenCapabilities(); - isVendorATI = GLXUtil.isVendorATI(display); + isVendorATI = ((X11GLXDrawableFactory)(drawable.getFactoryImpl())).isVendorATI(); if(config.getFBConfigID()<0) { // not able to use FBConfig @@ -148,11 +148,11 @@ public abstract class X11GLXContext extends GLContextImpl { drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), context)) { - throw new GLException("Error making temp context (old2) current: display 0x"+Long.toHexString(display)+", context 0x"+Long.toHexString(context)+", drawable "+drawable); + throw new GLException("Error making temp context (old2) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); } setGLFunctionAvailability(true); if(DEBUG) { - System.err.println("X11GLXContext.createContext done (old2 ctx) 0x"+Long.toHexString(context)); + System.err.println("X11GLXContext.createContext done (old2 ctx) "+toHexString(context)); } } else { @@ -167,7 +167,7 @@ public abstract class X11GLXContext extends GLContextImpl { drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), temp_context)) { - throw new GLException("Error making temp context (old) current: display 0x"+Long.toHexString(display)+", context 0x"+Long.toHexString(context)+", drawable "+drawable); + throw new GLException("Error making temp context (old) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); } setGLFunctionAvailability(true); @@ -182,7 +182,7 @@ public abstract class X11GLXContext extends GLContextImpl { // continue with temp context for GL < 3.0 context = temp_context; if(DEBUG) { - System.err.println("X11GLXContext.createContext done (old ctx < 3.0 - no GLX_ARB_create_context) 0x"+Long.toHexString(context)); + System.err.println("X11GLXContext.createContext done (old ctx < 3.0 - no GLX_ARB_create_context) "+toHexString(context)); } } else { GLXExt glXExt = getGLXExt(); @@ -209,7 +209,7 @@ public abstract class X11GLXContext extends GLContextImpl { /** * don't stricten requirements any further, even compatible would be fine * - } else { + else { attribs[8+0] = GLX.GLX_CONTEXT_PROFILE_MASK_ARB; attribs[8+1] = GLX.GLX_CONTEXT_CORE_PROFILE_BIT_ARB; } @@ -228,7 +228,7 @@ public abstract class X11GLXContext extends GLContextImpl { GLX.glXDestroyContext(display, context); context = 0; } else if(DEBUG) { - System.err.println("X11GLXContext.createContext >= 3.2 available 0x"+Long.toHexString(context)); + System.err.println("X11GLXContext.createContext >= 3.2 available "+toHexString(context)); } } else { if(DEBUG) { @@ -261,7 +261,7 @@ public abstract class X11GLXContext extends GLContextImpl { GLX.glXDestroyContext(display, context); context = 0; } else if(DEBUG) { - System.err.println("X11GLXContext.createContext >= 3.0 available 0x"+Long.toHexString(context)); + System.err.println("X11GLXContext.createContext >= 3.0 available "+toHexString(context)); } } else { if(DEBUG) { @@ -285,10 +285,10 @@ public abstract class X11GLXContext extends GLContextImpl { context)) { GLX.glXMakeContextCurrent(display, 0, 0, 0); GLX.glXDestroyContext(display, temp_context); - throw new GLException("Error making context (old) current: display 0x"+Long.toHexString(display)+", context 0x"+Long.toHexString(context)+", drawable "+drawable); + throw new GLException("Error making context (old) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); } if(DEBUG) { - System.err.println("X11GLXContext.createContext done (old ctx < 3.0 - no 3.0) 0x"+Long.toHexString(context)); + System.err.println("X11GLXContext.createContext done (old ctx < 3.0 - no 3.0) "+toHexString(context)); } } else { GLX.glXDestroyContext(display, temp_context); @@ -296,7 +296,7 @@ public abstract class X11GLXContext extends GLContextImpl { // need to update the GL func table .. updateGLProcAddressTable(); if(DEBUG) { - System.err.println("X11GLXContext.createContext done (new ctx >= 3.0) 0x"+Long.toHexString(context)); + System.err.println("X11GLXContext.createContext done (new ctx >= 3.0) "+toHexString(context)); } } } @@ -337,6 +337,8 @@ public abstract class X11GLXContext extends GLContextImpl { } protected int makeCurrentImplAfterLock() throws GLException { + long dpy = drawable.getNativeWindow().getDisplayHandle(); + getDrawableImpl().getFactoryImpl().lockToolkit(); try { if (drawable.getNativeWindow().getSurfaceHandle() == 0) { @@ -356,7 +358,7 @@ public abstract class X11GLXContext extends GLContextImpl { if (GLX.glXGetCurrentContext() != context) { - if (!GLX.glXMakeContextCurrent(drawable.getNativeWindow().getDisplayHandle(), + if (!GLX.glXMakeContextCurrent(dpy, drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), context)) { @@ -364,7 +366,7 @@ public abstract class X11GLXContext extends GLContextImpl { } if (DEBUG && (VERBOSE || created)) { System.err.println(getThreadName() + ": glXMakeCurrent(display " + - toHexString(drawable.getNativeWindow().getDisplayHandle()) + + toHexString(dpy)+ ", drawable " + toHexString(drawable.getNativeWindow().getSurfaceHandle()) + ", drawableRead " + toHexString(drawableRead.getNativeWindow().getSurfaceHandle()) + ", context " + toHexString(context) + ") succeeded"); @@ -397,10 +399,10 @@ public abstract class X11GLXContext extends GLContextImpl { try { if (context != 0) { if (DEBUG) { - System.err.println("glXDestroyContext(0x" + - Long.toHexString(drawable.getNativeWindow().getDisplayHandle()) + - ", 0x" + - Long.toHexString(context) + ")"); + System.err.println("glXDestroyContext(" + + toHexString(drawable.getNativeWindow().getDisplayHandle()) + + ", " + + toHexString(context) + ")"); } GLX.glXDestroyContext(drawable.getNativeWindow().getDisplayHandle(), context); if (DEBUG) { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java index 60ee431dc..eda480d5f 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java @@ -48,6 +48,7 @@ import com.jogamp.nativewindow.impl.NWReflection; import com.jogamp.nativewindow.impl.x11.*; public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements DynamicLookupHelper { + public X11GLXDrawableFactory() { super(); // Must initialize GLX support eagerly in case a pbuffer is the @@ -60,64 +61,121 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna NWReflection.createInstance("com.jogamp.opengl.impl.x11.glx.awt.X11AWTGLXGraphicsConfigurationFactory", new Object[] {}); } catch (Throwable t) { } + + X11GraphicsDevice sharedDevice = new X11GraphicsDevice(X11Util.createThreadLocalDisplay(null)); + vendorName = GLXUtil.getVendorName(sharedDevice.getHandle()); + isVendorATI = GLXUtil.isVendorATI(vendorName); + isVendorNVIDIA = GLXUtil.isVendorNVIDIA(vendorName); + if( isVendorATI() ) { + X11Util.markGlobalDisplayUndeletable(sharedDevice.getHandle()); // ATI hack .. + } + sharedScreen = new X11GraphicsScreen(sharedDevice, 0); + if (DEBUG) { + System.err.println("!!! Vendor: "+vendorName+", ATI: "+isVendorATI+", NV: "+isVendorNVIDIA); + System.err.println("!!! SharedScreen: "+sharedScreen); + } + } + + private X11GraphicsScreen sharedScreen; + private String vendorName; + private boolean isVendorATI; + private boolean isVendorNVIDIA; + + public String getVendorName() { return vendorName; } + public boolean isVendorATI() { return isVendorATI; } + public boolean isVendorNVIDIA() { return isVendorNVIDIA; } + + private X11DummyGLXDrawable sharedDrawable=null; + private GLContext sharedContext=null; + + private void initShared() { + if(null==sharedDrawable) { + X11Lib.XLockDisplay(sharedScreen.getDevice().getHandle()); + sharedDrawable = new X11DummyGLXDrawable(sharedScreen, this, null); + sharedContext = sharedDrawable.createContext(null); + sharedContext.makeCurrent(); + sharedContext.release(); + X11Lib.XUnlockDisplay(sharedScreen.getDevice().getHandle()); + if (DEBUG) { + System.err.println("!!! SharedContext: "+sharedContext); + } + } + } + + public void shutdown() { + super.shutdown(); + if (DEBUG) { + System.err.println("!!! Shutdown Shared:"); + System.err.println("!!! CTX : "+sharedContext); + System.err.println("!!! Drawable: "+sharedDrawable); + System.err.println("!!! Screen : "+sharedScreen); + Exception e = new Exception("Debug"); + e.printStackTrace(); + } + if(null!=sharedContext) { + sharedContext.destroy(); // implies release, if current + } + if(null!=sharedDrawable) { + sharedDrawable.destroy(); + } + if(null!=sharedScreen) { + X11GraphicsDevice sharedDevice = (X11GraphicsDevice) sharedScreen.getDevice(); + if(null!=sharedDevice) { + X11Util.closeThreadLocalDisplay(null); + } + sharedScreen = null; + } + X11Util.shutdown( !isVendorATI(), DEBUG ); } public GLDrawableImpl createOnscreenDrawable(NativeWindow target) { + validate(); if (target == null) { throw new IllegalArgumentException("Null target"); } + if( isVendorATI() ) { + X11Util.markGlobalDisplayUndeletable(target.getDisplayHandle()); // ATI hack .. + } return new X11OnscreenGLXDrawable(this, target); } protected GLDrawableImpl createOffscreenDrawable(NativeWindow target) { + if (target == null) { + throw new IllegalArgumentException("Null target"); + } + if( isVendorATI() ) { + X11Util.markGlobalDisplayUndeletable(target.getDisplayHandle()); // ATI hack .. + } + initShared(); return new X11OffscreenGLXDrawable(this, target); } public boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { + validate(); return glxVersionGreaterEqualThan(device, 1, 3); } private boolean glxVersionsQueried = false; private int glxVersionMajor=0, glxVersionMinor=0; public boolean glxVersionGreaterEqualThan(AbstractGraphicsDevice device, int majorReq, int minorReq) { + validate(); if (!glxVersionsQueried) { if(null == device) { - GLContext ctx = GLContext.getCurrent(); - if( null != ctx) { - device = ctx.getGLDrawable().getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice(); - } + device = (X11GraphicsDevice) sharedScreen.getDevice(); } if(null == device) { - GLException gle = new GLException("FIXME: No AbstractGraphicsDevice (passed or queried via current context - Fallback to ThreadLocal Display .."); - gle.printStackTrace(); - - device = new X11GraphicsDevice(X11Util.getThreadLocalDisplay(null)); + throw new GLException("FIXME: No AbstractGraphicsDevice (passed or shared-device"); } long display = device.getHandle(); int[] major = new int[1]; int[] minor = new int[1]; - if (!GLX.glXQueryVersion(display, major, 0, minor, 0)) { - throw new GLException("glXQueryVersion failed"); - } + GLXUtil.getGLXVersion(display, major, minor); if (DEBUG) { System.err.println("!!! GLX version: major " + major[0] + ", minor " + minor[0]); } - // Work around bugs in ATI's Linux drivers where they report they - // only implement GLX version 1.2 on the server side - if (major[0] == 1 && minor[0] == 2) { - String str = GLX.glXGetClientString(display, GLX.GLX_VERSION); - try { - major[0] = Integer.valueOf(str.substring(0, 1)).intValue(); - minor[0] = Integer.valueOf(str.substring(2, 3)).intValue(); - } catch (NumberFormatException nfe) { - major[0] = 1; - minor[0] = 2; - } - } - glxVersionMajor = major[0]; glxVersionMinor = minor[0]; glxVersionsQueried = true; @@ -127,8 +185,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna protected GLDrawableImpl createGLPbufferDrawableImpl(final NativeWindow target) { GLDrawableImpl pbufferDrawable; - X11DummyGLXDrawable dummyDrawable=null; - GLContext dummyContext=null; /** * Due to the ATI Bug https://bugzilla.mozilla.org/show_bug.cgi?id=486277, @@ -136,21 +192,20 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna * The dummy context shall also use the same Display, * since switching Display in this regard is another ATI bug. */ - if( null == GLContext.getCurrent() ) { - X11GraphicsScreen screen = (X11GraphicsScreen) target.getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen(); - dummyDrawable = new X11DummyGLXDrawable(screen, this, null); - dummyContext = dummyDrawable.createContext(null); - dummyContext.makeCurrent(); + boolean usedSharedContext=false; + if( isVendorATI() && null == GLContext.getCurrent() ) { + initShared(); + sharedContext.makeCurrent(); + usedSharedContext=true; + } + if( isVendorATI() ) { + X11Util.markGlobalDisplayUndeletable(target.getDisplayHandle()); // ATI hack .. } try { pbufferDrawable = new X11PbufferGLXDrawable(this, target); } finally { - if(null!=dummyContext) { - dummyContext.release(); - dummyContext.destroy(); - } - if(null!=dummyDrawable) { - dummyDrawable.destroy(); + if(usedSharedContext) { + sharedContext.release(); } } return pbufferDrawable; @@ -158,25 +213,30 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna protected NativeWindow createOffscreenWindow(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { - AbstractGraphicsScreen screen = X11GraphicsScreen.createDefault(); - NullWindow nw = new NullWindow(X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capabilities, chooser, screen)); + X11Lib.XLockDisplay(sharedScreen.getDevice().getHandle()); + NullWindow nw = new NullWindow(X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capabilities, chooser, sharedScreen)); + X11Lib.XUnlockDisplay(sharedScreen.getDevice().getHandle()); nw.setSize(width, height); return nw; } public GLContext createExternalGLContext() { + validate(); return X11ExternalGLXContext.create(this, null); } public boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device) { + validate(); return canCreateGLPbuffer(device); } public GLDrawable createExternalGLDrawable() { + validate(); return X11ExternalGLXDrawable.create(this, null); } public void loadGLULibrary() { + validate(); X11Lib.dlopen("/usr/lib/libGLU.so"); } @@ -191,6 +251,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna } public boolean canCreateContextOnJava2DSurface(AbstractGraphicsDevice device) { + validate(); return false; } @@ -210,9 +271,10 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna return gammaRampLength; } - long display = X11Util.getThreadLocalDefaultDisplay(); + long display = sharedScreen.getDevice().getHandle(); + + X11Lib.XLockDisplay(display); try { - X11Lib.XLockDisplay(display); int[] size = new int[1]; boolean res = X11Lib.XF86VidModeGetGammaRampSize(display, X11Lib.DefaultScreen(display), @@ -235,9 +297,9 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna rampData[i] = (short) (ramp[i] * 65535); } - long display = X11Util.getThreadLocalDefaultDisplay(); + long display = sharedScreen.getDevice().getHandle(); + X11Lib.XLockDisplay(display); try { - X11Lib.XLockDisplay(display); boolean res = X11Lib.XF86VidModeSetGammaRamp(display, X11Lib.DefaultScreen(display), rampData.length, @@ -262,9 +324,9 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna rampData.position(2 * size); rampData.limit(3 * size); ShortBuffer blueRampData = rampData.slice(); - long display = X11Util.getThreadLocalDefaultDisplay(); + long display = sharedScreen.getDevice().getHandle(); + X11Lib.XLockDisplay(display); try { - X11Lib.XLockDisplay(display); boolean res = X11Lib.XF86VidModeGetGammaRamp(display, X11Lib.DefaultScreen(display), size, @@ -298,9 +360,9 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna rampData.position(2 * size); rampData.limit(3 * size); ShortBuffer blueRampData = rampData.slice(); - long display = X11Util.getThreadLocalDefaultDisplay(); + long display = sharedScreen.getDevice().getHandle(); + X11Lib.XLockDisplay(display); try { - X11Lib.XLockDisplay(display); X11Lib.XF86VidModeSetGammaRamp(display, X11Lib.DefaultScreen(display), size, diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfiguration.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfiguration.java index b3a6e5b8c..35daf0ae0 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfiguration.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfiguration.java @@ -64,18 +64,18 @@ public class X11GLXGraphicsConfiguration extends X11GraphicsConfiguration implem int screen = x11Screen.getIndex(); long fbcfg = glXFBConfigID2FBConfig(display, screen, fbcfgID); if(0==fbcfg) { - throw new GLException("FBConfig null of 0x"+Integer.toHexString(fbcfgID)); + throw new GLException("FBConfig null of "+toHexString(fbcfgID)); } if(null==glp) { glp = GLProfile.getDefault(); } GLCapabilities caps = GLXFBConfig2GLCapabilities(glp, display, fbcfg, true, true, true, GLXUtil.isMultisampleAvailable(display)); if(null==caps) { - throw new GLException("GLCapabilities null of 0x"+Long.toHexString(fbcfg)); + throw new GLException("GLCapabilities null of "+toHexString(fbcfg)); } XVisualInfo xvi = GLX.glXGetVisualFromFBConfigCopied(display, fbcfg); if(null==xvi) { - throw new GLException("XVisualInfo null of 0x"+Long.toHexString(fbcfg)); + throw new GLException("XVisualInfo null of "+toHexString(fbcfg)); } return new X11GLXGraphicsConfiguration(x11Screen, caps, caps, new DefaultGLCapabilitiesChooser(), xvi, fbcfg, fbcfgID); } @@ -104,6 +104,10 @@ public class X11GLXGraphicsConfiguration extends X11GraphicsConfiguration implem } } + private static int nonZeroOrDontCare(int value) { + return value != 0 ? value : (int)GLX.GLX_DONT_CARE ; + } + public static int[] GLCapabilities2AttribList(GLCapabilities caps, boolean forFBAttr, boolean isMultisampleAvailable, @@ -222,10 +226,11 @@ public class X11GLXGraphicsConfiguration extends X11GraphicsConfiguration implem if ( onscreen ) { res = ( 0 != (val & GLX.GLX_WINDOW_BIT) ) ; } else { - res = ( 0 != (val & GLX.GLX_PIXMAP_BIT) ) || usePBuffer ; - } - if ( usePBuffer ) { - res = res && ( 0 != (val & GLX.GLX_PBUFFER_BIT) ) ; + if ( usePBuffer ) { + res = ( 0 != (val & GLX.GLX_PBUFFER_BIT) ) ; + } else { + res = ( 0 != (val & GLX.GLX_PIXMAP_BIT) ) ; + } } return res; @@ -237,7 +242,10 @@ public class X11GLXGraphicsConfiguration extends X11GraphicsConfiguration implem int val; val = glXGetFBConfig(display, fbcfg, GLX.GLX_RENDER_TYPE, tmp, 0); if (val != GLX.GLX_RGBA_BIT) { - throw new GLException("Visual does not support RGBA"); + if(DEBUG) { + System.err.println("FBConfig ("+toHexString(fbcfg)+") does not support RGBA: "+toHexString(val)); + } + return null; } GLCapabilities res = new GLCapabilities(glp); @@ -249,7 +257,10 @@ public class X11GLXGraphicsConfiguration extends X11GraphicsConfiguration implem res.setOnscreen( 0 != (val & GLX.GLX_WINDOW_BIT) ); res.setPBuffer ( 0 != (val & GLX.GLX_PBUFFER_BIT) ); } else { - throw new GLException("GLX_DRAWABLE_TYPE does not match !!!"); + if(DEBUG) { + System.err.println("FBConfig ("+toHexString(fbcfg)+") GLX_DRAWABLE_TYPE does not match: req(onscrn "+onscreen+", pbuffer "+usePBuffer+"), got(onscreen "+( 0 != (val & GLX.GLX_WINDOW_BIT) )+", pbuffer "+( 0 != (val & GLX.GLX_PBUFFER_BIT) )+", pixmap "+( 0 != (val & GLX.GLX_PIXMAP_BIT) )+")"); + } + return null; } res.setDoubleBuffered(glXGetFBConfig(display, fbcfg, GLX.GLX_DOUBLEBUFFER, tmp, 0) != 0); res.setStereo (glXGetFBConfig(display, fbcfg, GLX.GLX_STEREO, tmp, 0) != 0); @@ -302,7 +313,7 @@ public class X11GLXGraphicsConfiguration extends X11GraphicsConfiguration implem } int res = GLX.glXGetFBConfigAttrib(display, cfg, attrib, tmp, tmp_offset); if (res != 0) { - throw new GLException("glXGetFBConfig(0x"+Long.toHexString(attrib)+") failed: error code " + glXGetFBConfigErrorCode(res)); + throw new GLException("glXGetFBConfig("+toHexString(attrib)+") failed: error code " + glXGetFBConfigErrorCode(res)); } return tmp[tmp_offset]; } @@ -340,8 +351,8 @@ public class X11GLXGraphicsConfiguration extends X11GraphicsConfiguration implem NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); } if (DEBUG) { - System.err.println("!!! Fetched XVisualInfo for visual ID 0x" + Long.toHexString(visualID)); - System.err.println("!!! Resulting XVisualInfo: visualid = 0x" + Long.toHexString(res.getVisualid())); + System.err.println("!!! Fetched XVisualInfo for visual ID " + toHexString(visualID)); + System.err.println("!!! Resulting XVisualInfo: visualid = " + toHexString(res.getVisualid())); } return res; } @@ -350,11 +361,17 @@ public class X11GLXGraphicsConfiguration extends X11GraphicsConfiguration implem int[] tmp = new int[1]; int val = glXGetConfig(display, info, GLX.GLX_USE_GL, tmp, 0); if (val == 0) { - throw new GLException("Visual does not support OpenGL"); + if(DEBUG) { + System.err.println("Visual ("+toHexString(info.getVisualid())+") does not support OpenGL"); + } + return null; } val = glXGetConfig(display, info, GLX.GLX_RGBA, tmp, 0); if (val == 0) { - throw new GLException("Visual does not support RGBA"); + if(DEBUG) { + System.err.println("Visual ("+toHexString(info.getVisualid())+") does not support RGBA"); + } + return null; } GLCapabilities res = new GLCapabilities(glp); res.setOnscreen (onscreen); @@ -399,13 +416,21 @@ public class X11GLXGraphicsConfiguration extends X11GraphicsConfiguration implem } int res = GLX.glXGetConfig(display, info, attrib, tmp, tmp_offset); if (res != 0) { - throw new GLException("glXGetConfig(0x"+Long.toHexString(attrib)+") failed: error code " + glXGetConfigErrorCode(res)); + throw new GLException("glXGetConfig("+toHexString(attrib)+") failed: error code " + glXGetConfigErrorCode(res)); } return tmp[tmp_offset]; } + public static String toHexString(int val) { + return "0x"+Integer.toHexString(val); + } + + public static String toHexString(long val) { + return "0x"+Long.toHexString(val); + } + public String toString() { - return "X11GLXGraphicsConfiguration["+getScreen()+", visualID 0x" + Long.toHexString(getVisualID()) + ", fbConfigID 0x" + Long.toHexString(fbConfigID) + + return "X11GLXGraphicsConfiguration["+getScreen()+", visualID " + toHexString(getVisualID()) + ", fbConfigID " + toHexString(fbConfigID) + ",\n\trequested " + getRequestedCapabilities()+ ",\n\tchosen " + getChosenCapabilities()+ "]"; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java index 72551f928..477f2473c 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java @@ -79,9 +79,10 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac // GLCapabilities capsFB = null; long display = x11Screen.getDevice().getHandle(); + + NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); + X11Lib.XLockDisplay(display); try { - NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); - X11Lib.XLockDisplay(display); int screen = x11Screen.getIndex(); boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); @@ -154,14 +155,14 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac x11Screen); if(null==res) { if(usePBuffer) { - throw new GLException("Error: Couldn't create X11GLXGraphicsConfiguration based on FBConfig"); + throw new GLException("Error: Couldn't create X11GLXGraphicsConfiguration based on FBConfig for "+caps2); } res = chooseGraphicsConfigurationXVisual((GLCapabilities) caps2, (GLCapabilitiesChooser) chooser, x11Screen); } if(null==res) { - throw new GLException("Error: Couldn't create X11GLXGraphicsConfiguration"); + throw new GLException("Error: Couldn't create X11GLXGraphicsConfiguration based on FBConfig and XVisual for "+caps2); } if(DEBUG) { System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationStatic("+x11Screen+","+caps2+"): "+res); @@ -172,6 +173,7 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac protected static X11GLXGraphicsConfiguration chooseGraphicsConfigurationFBConfig(GLCapabilities capabilities, GLCapabilitiesChooser chooser, X11GraphicsScreen x11Screen) { + long recommendedFBConfig = 0; int recommendedIndex = -1; GLCapabilities[] caps = null; PointerBuffer fbcfgsL = null; @@ -186,37 +188,66 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac // AbstractGraphicsDevice absDevice = x11Screen.getDevice(); long display = absDevice.getHandle(); + + NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); + X11Lib.XLockDisplay(display); try { - NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); - X11Lib.XLockDisplay(display); int screen = x11Screen.getIndex(); boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList(capabilities, true, isMultisampleAvailable, display, screen); int[] count = { -1 }; + // determine the recommended FBConfig .. fbcfgsL = GLX.glXChooseFBConfigCopied(display, screen, attribs, 0, count, 0); if (fbcfgsL == null || fbcfgsL.limit()<1) { if(DEBUG) { System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXChooseFBConfig ("+x11Screen+","+capabilities+"): "+fbcfgsL+", "+count[0]); } - return null; + } else if( !X11GLXGraphicsConfiguration.GLXFBConfigValid( display, fbcfgsL.get(0) ) ) { + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed - GLX FBConfig invalid: ("+x11Screen+","+capabilities+"): "+fbcfgsL+", fbcfg: "+toHexString(fbcfgsL.get(0))); + } + } else { + recommendedFBConfig = fbcfgsL.get(0); } - if( !X11GLXGraphicsConfiguration.GLXFBConfigValid( display, fbcfgsL.get(0) ) ) { + + // get all, glXChooseFBConfig(.. attribs==null ..) == glXGetFBConfig(..) + fbcfgsL = GLX.glXChooseFBConfigCopied(display, screen, null, 0, count, 0); + if (fbcfgsL == null || fbcfgsL.limit()<1) { if(DEBUG) { - System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed - GLX FBConfig invalid: ("+x11Screen+","+capabilities+"): "+fbcfgsL+", fbcfg: 0x"+Long.toHexString(fbcfgsL.get(0))); + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXGetFBConfig ("+x11Screen+"): "+fbcfgsL+", "+count[0]); } return null; } - recommendedIndex = 0; // 1st match is always recommended .. + + // make GLCapabilities and seek the recommendedIndex caps = new GLCapabilities[fbcfgsL.limit()]; for (int i = 0; i < fbcfgsL.limit(); i++) { - caps[i] = X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(glProfile, display, fbcfgsL.get(i), - false, onscreen, usePBuffer, isMultisampleAvailable); + if( !X11GLXGraphicsConfiguration.GLXFBConfigValid( display, fbcfgsL.get(i) ) ) { + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: FBConfig invalid: ("+x11Screen+","+capabilities+"): fbcfg: "+toHexString(fbcfgsL.get(i))); + } + } else { + caps[i] = X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(glProfile, display, fbcfgsL.get(i), + false, onscreen, usePBuffer, isMultisampleAvailable); + if(caps[i]!=null && recommendedFBConfig==fbcfgsL.get(i)) { + recommendedIndex=i; + if (DEBUG) { + System.err.println("!!! glXChooseFBConfig recommended "+i+", "+caps[i]); + } + } + } } if(null==chooser) { - chosen = recommendedIndex; - } else { + chosen = recommendedIndex; // may still be -1 in case nothing was recommended (-1) + } + + if (chosen < 0) { + if(null==chooser) { + // nothing recommended .. so use our default implementation + chooser = new DefaultGLCapabilitiesChooser(); + } try { chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex); } catch (NativeWindowException e) { @@ -231,9 +262,20 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac if(DEBUG) { System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig Failed .. unable to choose config, using first"); } - chosen = 0; // default .. + // seek first available one .. + for(chosen = 0; chosen < caps.length && caps[chosen]==null; chosen++) ; + if(chosen==caps.length) { + // give up .. + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig Failed .. nothing available, bail out"); + } + return null; + } } else if (chosen >= caps.length) { - throw new GLException("GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); + if(DEBUG) { + System.err.println("GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ", got "+chosen+")"); + } + return null; } retFBID = X11GLXGraphicsConfiguration.glXFBConfig2FBConfigID(display, fbcfgsL.get(chosen)); @@ -276,9 +318,10 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac AbstractGraphicsDevice absDevice = x11Screen.getDevice(); long display = absDevice.getHandle(); + + NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); + X11Lib.XLockDisplay(display); try { - NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); - X11Lib.XLockDisplay(display); int screen = x11Screen.getIndex(); boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList(capabilities, false, isMultisampleAvailable, display, screen); @@ -290,7 +333,7 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac if (recommendedVis == null) { System.err.println("null visual"); } else { - System.err.println("visual id 0x" + Long.toHexString(recommendedVis.getVisualid())); + System.err.println("visual id " + toHexString(recommendedVis.getVisualid())); } } int[] count = new int[1]; @@ -326,7 +369,7 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac throw new GLException("GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); } if (infos[chosen] == null) { - throw new GLException("GLCapabilitiesChooser chose an invalid visual"); + throw new GLException("GLCapabilitiesChooser chose an invalid visual for "+caps[chosen]); } retXVisualInfo = XVisualInfo.create(infos[chosen]); } finally { @@ -335,5 +378,14 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac } return new X11GLXGraphicsConfiguration(x11Screen, caps[chosen], capabilities, chooser, retXVisualInfo, 0, -1); } + + public static String toHexString(int val) { + return "0x"+Integer.toHexString(val); + } + + public static String toHexString(long val) { + return "0x"+Long.toHexString(val); + } + } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java index ea855d28d..41f012122 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java @@ -75,9 +75,9 @@ public class X11OffscreenGLXDrawable extends X11GLXDrawable { int screen = aScreen.getIndex(); getFactoryImpl().lockToolkit(); + X11Lib.XLockDisplay(dpy); try { - X11Lib.XLockDisplay(dpy); - pixmap = X11Lib.XCreatePixmap(dpy, (int) X11Lib.RootWindow(dpy, screen), + pixmap = X11Lib.XCreatePixmap(dpy, X11Lib.RootWindow(dpy, screen), component.getWidth(), component.getHeight(), bitsPerPixel); if (pixmap == 0) { throw new GLException("XCreatePixmap failed"); @@ -105,10 +105,10 @@ public class X11OffscreenGLXDrawable extends X11GLXDrawable { NativeWindow nw = getNativeWindow(); long display = nw.getDisplayHandle(); - try { - getFactoryImpl().lockToolkit(); - X11Lib.XLockDisplay(display); + getFactoryImpl().lockToolkit(); + X11Lib.XLockDisplay(display); + try { long drawable = nw.getSurfaceHandle(); if (DEBUG) { System.err.println("Destroying pixmap " + toHexString(pixmap) + @@ -135,11 +135,11 @@ public class X11OffscreenGLXDrawable extends X11GLXDrawable { X11Lib.XFreePixmap(display, pixmap); drawable = 0; pixmap = 0; - display = 0; ((SurfaceChangeable)nw).setSurfaceHandle(0); } finally { X11Lib.XUnlockDisplay(display); getFactoryImpl().unlockToolkit(); + display = 0; } } protected void swapBuffersImpl() { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java index 63b350bd3..dc6c60664 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java @@ -92,7 +92,7 @@ public class X11AWTGLXGraphicsConfigurationFactory extends GraphicsConfiguration try { long displayHandle = X11SunJDKReflection.graphicsDeviceGetDisplay(device); if(0==displayHandle) { - displayHandle = X11Util.getThreadLocalDefaultDisplay(); + displayHandle = X11Util.createThreadLocalDefaultDisplay(); if(DEBUG) { System.err.println("X11AWTGLXGraphicsConfigurationFactory: using a thread local X11 display"); } diff --git a/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java b/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java index 8603c7184..c5ded88f6 100644 --- a/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java +++ b/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java @@ -89,11 +89,17 @@ public class DefaultGLCapabilitiesChooser implements GLCapabilitiesChooser { int windowSystemRecommendedChoice) { GLCapabilities _desired = (GLCapabilities) desired; GLCapabilities[] _available = (GLCapabilities[]) available; + int availnum = 0; + + for (int i = 0; i < _available.length; i++) { + if(null != _available[i]) { availnum++; } + } if (DEBUG) { System.err.println("Desired: " + _desired); + System.err.println("Available: Valid " + availnum + "/" + _available.length); for (int i = 0; i < _available.length; i++) { - System.err.println("Available " + i + ": " + _available[i]); + System.err.println(i + ": " + _available[i]); } System.err.println("Window system's recommended choice: " + windowSystemRecommendedChoice); } @@ -132,6 +138,9 @@ public class DefaultGLCapabilitiesChooser implements GLCapabilitiesChooser { if (_desired.isOnscreen() != cur.isOnscreen()) { continue; } + if (_desired.isPBuffer() != cur.isPBuffer()) { + continue; + } if (_desired.getStereo() != cur.getStereo()) { continue; } diff --git a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java index 71cb3cb3b..80c2c10e2 100644 --- a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java +++ b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java @@ -216,6 +216,7 @@ public abstract class GLDrawableFactory { /** * Returns true if it is possible to create a GLPbuffer. Some older * graphics cards do not have this capability. + * @param passing the device for the query, may be null */ public abstract boolean canCreateGLPbuffer(AbstractGraphicsDevice device); @@ -278,6 +279,7 @@ public abstract class GLDrawableFactory { /** * Returns true if it is possible to create an external GLDrawable * object via {@link #createExternalGLDrawable}. + * @param passing the device for the query, may be null */ public abstract boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device); diff --git a/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java b/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java index fa15e3fef..5abf02b97 100755 --- a/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java +++ b/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java @@ -40,6 +40,8 @@ import java.util.List; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.After; import org.junit.Test; import javax.media.opengl.*; @@ -50,21 +52,29 @@ import com.jogamp.newt.opengl.*; public class TestDrawable01NEWT { static GLProfile glp; + static GLDrawableFactory factory; static int width, height; GLCapabilities caps; Window window; GLDrawable drawable; GLContext context; - GLDrawableFactory factory; @BeforeClass public static void initClass() { glp = GLProfile.getDefault(); Assert.assertNotNull(glp); + factory = GLDrawableFactory.getFactory(glp); + Assert.assertNotNull(factory); width = 640; height = 480; } + @AfterClass + public static void releaseClass() { + factory.shutdown(); + factory=null; + } + @Before public void initTest() { caps = new GLCapabilities(glp); @@ -106,8 +116,6 @@ public class TestDrawable01NEWT { Assert.assertTrue(glCaps.getDoubleBuffered()==!onscreen); Assert.assertTrue(glCaps.getDepthBits()>4); - factory = GLDrawableFactory.getFactory(glCaps.getGLProfile()); - Assert.assertNotNull(factory); drawable = factory.createGLDrawable(window); Assert.assertNotNull(drawable); // System.out.println("Pre: "+drawable); @@ -149,10 +157,6 @@ public class TestDrawable01NEWT { drawable = null; context = null; window = null; - - // test code cont .. - factory.shutdown(); - factory = null; } @Test @@ -174,7 +178,22 @@ public class TestDrawable01NEWT { } public static void main(String args[]) { - org.junit.runner.JUnitCore.main(TestDrawable01NEWT.class.getName()); + String tstname = TestDrawable01NEWT.class.getName(); + try { + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } catch (Exception e) { + e.printStackTrace(); + } } } diff --git a/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java b/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java index 436167dbf..e5e7c4a52 100755 --- a/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java +++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java @@ -40,6 +40,8 @@ import java.util.List; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.After; import org.junit.Test; import javax.media.opengl.*; @@ -52,22 +54,194 @@ import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears; import com.jogamp.test.junit.jogl.demos.es1.RedSquare; public class TestOffscreen01NEWT { - int width, height; - GLProfile glp; + static GLProfile glp; + static GLDrawableFactory factory; + static int width, height; GLCapabilities caps; - @Before - public void init() { + @BeforeClass + public static void initClass() { glp = GLProfile.getDefault(); + Assert.assertNotNull(glp); + factory = GLDrawableFactory.getFactory(glp); + Assert.assertNotNull(factory); width = 640; height = 480; + } + + @AfterClass + public static void releaseClass() { + factory.shutdown(); + factory=null; + } + + @Before + public void init() { caps = new GLCapabilities(glp); } + private void do01OffscreenWindowPBuffer(GLCapabilities caps) { + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + Window window = NewtFactory.createWindow(screen, caps, false /* undecorated */); + Assert.assertNotNull(window); + window.setSize(width, height); + GLWindow glWindow = GLWindow.create(window); + Assert.assertNotNull(glWindow); + glWindow.setVisible(true); + GLEventListener demo = new RedSquare(); + WindowUtilNEWT.setDemoFields(demo, window, glWindow, false); + + while ( glWindow.getTotalFrames() < 2) { + glWindow.display(); + } + + if(null!=glWindow) { + glWindow.destroy(); + } + if(null!=window) { + window.destroy(); + } + if(null!=screen) { + screen.destroy(); + } + if(null!=display) { + display.destroy(); + } + } + + @Test + public void test01aOffscreenWindowPBuffer() { + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + do01OffscreenWindowPBuffer(caps2); + } + + @Test + public void test01bOffscreenWindowPBufferStencil() { + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + caps2.setStencilBits(8); + do01OffscreenWindowPBuffer(caps2); + } + @Test - public void test01OffscreenWindow() { + public void test01cOffscreenWindowPBufferStencilAlpha() { GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + caps2.setStencilBits(8); + caps2.setAlphaBits(8); + do01OffscreenWindowPBuffer(caps2); + } + + @Test + public void test01cOffscreenWindowPBuffer555() { + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + caps2.setRedBits(5); + caps2.setGreenBits(5); + caps2.setBlueBits(5); + do01OffscreenWindowPBuffer(caps2); + } + + @Test + public void test02Offscreen3Windows1DisplayPBuffer() { + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + int winnum = 3, i; + Window windows[] = new Window[winnum]; + GLWindow glWindows[] = new GLWindow[winnum]; + GLEventListener demos[] = new GLEventListener[winnum]; + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + + for(i=0; i - * as well as the static global discplay connection.
+ * as well as the static global display connection.
* * The TLS variant is thread safe per se, but be aware of the memory leak risk * where an application heavily utilizing this class on temporary new threads.
@@ -51,27 +54,98 @@ public class X11Util { static { NativeLibLoaderBase.loadNativeWindow("x11"); + installIOErrorHandler(); } private X11Util() {} private static ThreadLocal currentDisplayMap = new ThreadLocal(); + // not exactly thread safe, but good enough for our purpose, + // which is to tag a NamedDisplay uncloseable after creation. + private static Object globalLock = new Object(); + private static Collection globalNamedDisplayActive = new ArrayList(); + private static Collection globalNamedDisplayPassive = new ArrayList(); + + public static final String nullDeviceName = "nil" ; + public static class NamedDisplay implements Cloneable { - private String name; - private long handle; + String name; + long handle; + int refCount; + boolean unCloseable; protected NamedDisplay(String name, long handle) { this.name=name; this.handle=handle; + this.refCount=1; + this.unCloseable=false; } - public String getName() { return name; } - public long getHandle() { return handle; } + public final String getName() { return name; } + public final String getNameSafe() { return null == name ? nullDeviceName : name; } + public final long getHandle() { return handle; } + public final int getRefCount() { return refCount; } + public final boolean isUncloseable() { return unCloseable; } public Object clone() throws CloneNotSupportedException { return super.clone(); } + + public String toString() { + return "NamedX11Display["+name+", 0x"+Long.toHexString(handle)+", refCount "+refCount+", unCloseable "+unCloseable+"]"; + } + } + + /** Returns the number of unclosed X11 Displays. + * @param realXClosePendingDisplays if true, call XCloseDisplay on the remaining ones + */ + public static int shutdown(boolean realXClosePendingDisplays, boolean verbose) { + int num=0; + String msg; + if(DEBUG||verbose) { + msg = "X11Util.Display: Shutdown (active: "+globalNamedDisplayActive.size()+ + ", passive: "+globalNamedDisplayPassive.size() + ")"; + if(DEBUG) { + Exception e = new Exception(msg); + e.printStackTrace(); + } else if(verbose) { + System.err.println(msg); + } + } + + msg = realXClosePendingDisplays ? "Close" : "Keep" ; + + synchronized(globalLock) { + // for all passive displays .. + Collection namedDisplays = globalNamedDisplayPassive; + globalNamedDisplayPassive = new ArrayList(); + for(Iterator iter=namedDisplays.iterator(); iter.hasNext(); ) { + NamedDisplay ndpy = (NamedDisplay)iter.next(); + if(DEBUG||verbose) { + System.err.println(msg+" passive: "+ndpy); + } + if(realXClosePendingDisplays) { + X11Lib.XCloseDisplay(ndpy.getHandle()); + } + num++; + } + + // for all active displays .. + namedDisplays = globalNamedDisplayActive; + globalNamedDisplayActive = new ArrayList(); + for(Iterator iter=namedDisplays.iterator(); iter.hasNext(); ) { + NamedDisplay ndpy = (NamedDisplay)iter.next(); + if(DEBUG||verbose) { + System.err.println(msg+" active: "+ndpy); + } + if(realXClosePendingDisplays) { + X11Lib.XCloseDisplay(ndpy.getHandle()); + } + num++; + } + } + return num; } /** Returns a clone of the thread local display map, you may {@link Object#wait()} on it */ @@ -79,48 +153,120 @@ public class X11Util { return (Map) ((HashMap)getCurrentDisplayMapImpl()).clone(); } - /** Returns this thread current default display. If it doesn not exist, it is being created */ - public static long getThreadLocalDefaultDisplay() { - return getThreadLocalDisplay(null); + /** Returns this thread current default display. If it doesn not exist, it is being created, otherwise the reference count is increased */ + public static long createThreadLocalDefaultDisplay() { + return createThreadLocalDisplay(null); } - /** Returns this thread named display. If it doesn not exist, it is being created */ - public static long getThreadLocalDisplay(String name) { + /** Returns this thread named display. If it doesn not exist, it is being created, otherwise the reference count is increased */ + public static long createThreadLocalDisplay(String name) { NamedDisplay namedDpy = getCurrentDisplay(name); + if(null==namedDpy) { + synchronized(globalLock) { + namedDpy = getNamedDisplay(globalNamedDisplayPassive, name); + if(null != namedDpy) { + if(!globalNamedDisplayPassive.remove(namedDpy)) { throw new RuntimeException("Internal: "+namedDpy); } + globalNamedDisplayActive.add(namedDpy); + addCurrentDisplay( namedDpy ); + } + } + } if(null==namedDpy) { long dpy = X11Lib.XOpenDisplay(name); if(0==dpy) { throw new NativeWindowException("X11Util.Display: Unable to create a display("+name+") connection in Thread "+Thread.currentThread().getName()); } namedDpy = new NamedDisplay(name, dpy); - setCurrentDisplay( namedDpy ); + synchronized(globalLock) { + globalNamedDisplayActive.add(namedDpy); + addCurrentDisplay( namedDpy ); + } if(DEBUG) { - Exception e = new Exception("X11Util.Display: Created new TLS display("+name+") connection 0x"+Long.toHexString(dpy)+" in thread "+Thread.currentThread().getName()); + Exception e = new Exception("X11Util.Display: Created new TLS "+namedDpy+" in thread "+Thread.currentThread().getName()); + e.printStackTrace(); + } + } else { + namedDpy.refCount++; + if(DEBUG) { + Exception e = new Exception("X11Util.Display: Reused TLS "+namedDpy+" in thread "+Thread.currentThread().getName()); e.printStackTrace(); } } return namedDpy.getHandle(); } - /** Closes this thread named display. It returns the handle of the closed display or 0, if it does not exist. */ + /** Decrease the reference count of this thread named display. If it reaches 0, close it. + It returns the handle of the to be closed display. + It throws a RuntimeException in case the named display does not exist, + or the reference count goes below 0. + */ public static long closeThreadLocalDisplay(String name) { - NamedDisplay namedDpy = removeCurrentDisplay(name); + NamedDisplay namedDpy = getCurrentDisplay(name); if(null==namedDpy) { + throw new RuntimeException("X11Util.Display: Display("+name+") with given handle is not mapped to TLS in thread "+Thread.currentThread().getName()); + } + if(0==namedDpy.refCount) { + throw new RuntimeException("X11Util.Display: "+namedDpy+" has refCount already 0 in thread "+Thread.currentThread().getName()); + } + long dpy = namedDpy.getHandle(); + namedDpy.refCount--; + if(0==namedDpy.refCount) { + synchronized(globalLock) { + if(!globalNamedDisplayActive.remove(namedDpy)) { throw new RuntimeException("Internal: "+namedDpy); } + if(namedDpy.isUncloseable()) { + globalNamedDisplayPassive.add(namedDpy); + } else { + X11Lib.XCloseDisplay(dpy); + } + removeCurrentDisplay(namedDpy); + } if(DEBUG) { - Exception e = new Exception("X11Util.Display: Display("+name+") with given handle is not mapped to TLS in thread "+Thread.currentThread().getName()); + String type = namedDpy.isUncloseable() ? "passive" : "real" ; + Exception e = new Exception("X11Util.Display: Closing ( "+type+" ) TLS "+namedDpy+" in thread "+Thread.currentThread().getName()); e.printStackTrace(); } - return 0; - } - long dpy = namedDpy.getHandle(); - if(DEBUG) { - Exception e = new Exception("X11Util.Display: Closing TLS Display("+name+") with handle 0x"+Long.toHexString(dpy)+" in thread "+Thread.currentThread().getName()); + } else if(DEBUG) { + Exception e = new Exception("X11Util.Display: Keep TLS "+namedDpy+" in thread "+Thread.currentThread().getName()); e.printStackTrace(); } - X11Lib.XCloseDisplay(dpy); return dpy; } + public static String getThreadLocalDisplayName(long handle) { + NamedDisplay ndpy = getNamedDisplay(getCurrentDisplayMapImpl().values(), handle); + return null != ndpy ? ndpy.getName() : null; + } + + public static boolean markThreadLocalDisplayUndeletable(long handle) { + NamedDisplay ndpy = getNamedDisplay(getCurrentDisplayMapImpl().values(), handle); + if( null != ndpy ) { + ndpy.unCloseable=true; + return true; + } + return false; + } + + public static String getGlobalDisplayName(long handle, boolean active) { + String name; + synchronized(globalLock) { + NamedDisplay ndpy = getNamedDisplay(active ? globalNamedDisplayActive : globalNamedDisplayPassive, handle); + name = null != ndpy ? ndpy.getName() : null; + } + return name; + } + + public static boolean markGlobalDisplayUndeletable(long handle) { + boolean r=false; + synchronized(globalLock) { + NamedDisplay ndpy = getNamedDisplay(globalNamedDisplayActive, handle); + if( null != ndpy ) { + ndpy.unCloseable=true; + r=true; + } + } + return r; + } + private static Map getCurrentDisplayMapImpl() { Map displayMap = (Map) currentDisplayMap.get(); if(null==displayMap) { @@ -132,12 +278,11 @@ public class X11Util { /** maps the given display to the thread local display map * and notifies all threads synchronized to this display map. */ - private static NamedDisplay setCurrentDisplay(NamedDisplay newDisplay) { + private static NamedDisplay addCurrentDisplay(NamedDisplay newDisplay) { Map displayMap = getCurrentDisplayMapImpl(); NamedDisplay oldDisplay = null; synchronized(displayMap) { - String name = (null==newDisplay.getName())?"nil":newDisplay.getName(); - oldDisplay = (NamedDisplay) displayMap.put(name, newDisplay); + oldDisplay = (NamedDisplay) displayMap.put(newDisplay.getNameSafe(), newDisplay); displayMap.notifyAll(); } return oldDisplay; @@ -145,22 +290,45 @@ public class X11Util { /** removes the mapping of the given name from the thread local display map * and notifies all threads synchronized to this display map. */ - private static NamedDisplay removeCurrentDisplay(String name) { + private static NamedDisplay removeCurrentDisplay(NamedDisplay ndpy) { Map displayMap = getCurrentDisplayMapImpl(); - NamedDisplay oldDisplay = null; synchronized(displayMap) { - if(null==name) name="nil"; - oldDisplay = (NamedDisplay) displayMap.remove(name); + NamedDisplay ndpyDel = (NamedDisplay) displayMap.remove(ndpy.getNameSafe()); + if(ndpyDel!=ndpy) { + throw new RuntimeException("Wrong mapping req: "+ndpy+", got "+ndpyDel); + } displayMap.notifyAll(); } - return oldDisplay; + return ndpy; } /** Returns the thread local display mapped to the given name */ private static NamedDisplay getCurrentDisplay(String name) { - if(null==name) name="nil"; + if(null==name) name=nullDeviceName; Map displayMap = getCurrentDisplayMapImpl(); return (NamedDisplay) displayMap.get(name); } + private static NamedDisplay getNamedDisplay(Collection namedDisplays, String name) { + if(null==name) name=nullDeviceName; + for(Iterator iter=namedDisplays.iterator(); iter.hasNext(); ) { + NamedDisplay ndpy = (NamedDisplay)iter.next(); + if (ndpy.getNameSafe().equals(name)) { + return ndpy; + } + } + return null; + } + + private static NamedDisplay getNamedDisplay(Collection namedDisplays, long handle) { + for(Iterator iter=namedDisplays.iterator(); iter.hasNext(); ) { + NamedDisplay ndpy = (NamedDisplay)iter.next(); + if (ndpy.getHandle()==handle) { + return ndpy; + } + } + return null; + } + + private static native void installIOErrorHandler(); } diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java index 52f48660a..69ace3c52 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java +++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java @@ -57,7 +57,7 @@ public class X11GraphicsScreen extends DefaultGraphicsScreen implements Cloneabl /** Creates a new X11GraphicsScreen using a thread local display connection */ public static AbstractGraphicsScreen createDefault() { NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); - long display = X11Util.getThreadLocalDefaultDisplay(); + long display = X11Util.createThreadLocalDefaultDisplay(); try { X11Lib.XLockDisplay(display); int scrnIdx = X11Lib.DefaultScreen(display); diff --git a/src/nativewindow/native/x11/Xmisc.c b/src/nativewindow/native/x11/Xmisc.c new file mode 100644 index 000000000..4320a8f12 --- /dev/null +++ b/src/nativewindow/native/x11/Xmisc.c @@ -0,0 +1,471 @@ +/* + * Copyright (c) 2010 Sven Gothel. 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 Sven Gothel 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 + * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +#include +#include +#include +#include +#include +#include +#include +/* Linux headers don't work properly */ +#define __USE_GNU +#include +#undef __USE_GNU + +/* Current versions of Solaris don't expose the XF86 extensions, + although with the recent transition to Xorg this will probably + happen in an upcoming release */ +#if !defined(__sun) && !defined(_HPUX) +#include +#else +/* Need to provide stubs for these */ +Bool XF86VidModeGetGammaRampSize( + Display *display, + int screen, + int* size) +{ + return False; +} + +Bool XF86VidModeGetGammaRamp( + Display *display, + int screen, + int size, + unsigned short *red_array, + unsigned short *green_array, + unsigned short *blue_array) { + return False; +} +Bool XF86VidModeSetGammaRamp( + Display *display, + int screen, + int size, + unsigned short *red_array, + unsigned short *green_array, + unsigned short *blue_array) { + return False; +} +#endif /* defined(__sun) || defined(_HPUX) */ + +/* HP-UX doesn't define RTLD_DEFAULT. */ +#if defined(_HPUX) && !defined(RTLD_DEFAULT) +#define RTLD_DEFAULT NULL +#endif + +#include "com_jogamp_nativewindow_impl_x11_X11Lib.h" + +// #define VERBOSE_ON 1 + +#ifdef VERBOSE_ON + // Workaround for ancient compiler on Solaris/SPARC + // #define DBG_PRINT(args...) fprintf(stderr, args); + #define DBG_PRINT0(str) fprintf(stderr, str); + #define DBG_PRINT1(str, arg1) fprintf(stderr, str, arg1); + #define DBG_PRINT2(str, arg1, arg2) fprintf(stderr, str, arg1, arg2); + #define DBG_PRINT3(str, arg1, arg2, arg3) fprintf(stderr, str, arg1, arg2, arg3); + #define DBG_PRINT4(str, arg1, arg2, arg3, arg4) fprintf(stderr, str, arg1, arg2, arg3, arg4); + #define DBG_PRINT5(str, arg1, arg2, arg3, arg4, arg5) fprintf(stderr, str, arg1, arg2, arg3, arg4, arg5); + #define DBG_PRINT6(str, arg1, arg2, arg3, arg4, arg5, arg6) fprintf(stderr, str, arg1, arg2, arg3, arg4, arg5, arg6); + #define DBG_PRINT7(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7) fprintf(stderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + #define DBG_PRINT8(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) fprintf(stderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + +#else + + // Workaround for ancient compiler on Solaris/SPARC + // #define DBG_PRINT(args...) + #define DBG_PRINT0(str) + #define DBG_PRINT1(str, arg1) + #define DBG_PRINT2(str, arg1, arg2) + #define DBG_PRINT3(str, arg1, arg2, arg3) + #define DBG_PRINT4(str, arg1, arg2, arg3, arg4) + #define DBG_PRINT5(str, arg1, arg2, arg3, arg4, arg5) + #define DBG_PRINT6(str, arg1, arg2, arg3, arg4, arg5, arg6) + #define DBG_PRINT7(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7) + #define DBG_PRINT8(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) + +#endif + +/* Need to pull this in as we don't have a stub header for it */ +extern Bool XineramaEnabled(Display* display); + +static void _FatalError(JNIEnv *env, const char* msg, ...) +{ + char buffer[512]; + va_list ap; + + va_start(ap, msg); + vsnprintf(buffer, sizeof(buffer), msg, ap); + va_end(ap); + + fprintf(stderr, buffer); + (*env)->FatalError(env, buffer); +} + +static const char * const ClazzNameInternalBufferUtil = "com/jogamp/nativewindow/impl/InternalBufferUtil"; +static const char * const ClazzNameInternalBufferUtilStaticCstrName = "copyByteBuffer"; +static const char * const ClazzNameInternalBufferUtilStaticCstrSignature = "(Ljava/nio/ByteBuffer;)Ljava/nio/ByteBuffer;"; +static const char * const ClazzNameByteBuffer = "java/nio/ByteBuffer"; +static const char * const ClazzNameRuntimeException = "java/lang/RuntimeException"; +static jclass clazzInternalBufferUtil = NULL; +static jmethodID cstrInternalBufferUtil = NULL; +static jclass clazzByteBuffer = NULL; +static jclass clazzRuntimeException=NULL; + +static void _initClazzAccess(JNIEnv *env) { + jclass c; + + if(NULL!=clazzRuntimeException) return ; + + c = (*env)->FindClass(env, ClazzNameRuntimeException); + if(NULL==c) { + _FatalError(env, "Nativewindow X11Lib: can't find %s", ClazzNameRuntimeException); + } + clazzRuntimeException = (jclass)(*env)->NewGlobalRef(env, c); + (*env)->DeleteLocalRef(env, c); + if(NULL==clazzRuntimeException) { + _FatalError(env, "FatalError: NEWT X11Window: can't use %s", ClazzNameRuntimeException); + } + + c = (*env)->FindClass(env, ClazzNameInternalBufferUtil); + if(NULL==c) { + _FatalError(env, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameInternalBufferUtil); + } + clazzInternalBufferUtil = (jclass)(*env)->NewGlobalRef(env, c); + (*env)->DeleteLocalRef(env, c); + if(NULL==clazzInternalBufferUtil) { + _FatalError(env, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameInternalBufferUtil); + } + c = (*env)->FindClass(env, ClazzNameByteBuffer); + if(NULL==c) { + _FatalError(env, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameByteBuffer); + } + clazzByteBuffer = (jclass)(*env)->NewGlobalRef(env, c); + (*env)->DeleteLocalRef(env, c); + if(NULL==c) { + _FatalError(env, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameByteBuffer); + } + + cstrInternalBufferUtil = (*env)->GetStaticMethodID(env, clazzInternalBufferUtil, + ClazzNameInternalBufferUtilStaticCstrName, ClazzNameInternalBufferUtilStaticCstrSignature); + if(NULL==cstrInternalBufferUtil) { + _FatalError(env, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib:: can't create %s.%s %s", + ClazzNameInternalBufferUtil, ClazzNameInternalBufferUtilStaticCstrName, ClazzNameInternalBufferUtilStaticCstrSignature); + } +} + +static void _throwNewRuntimeException(Display * unlockDisplay, JNIEnv *env, const char* msg, ...) +{ + char buffer[512]; + va_list ap; + + if(NULL!=unlockDisplay) { + XUnlockDisplay(unlockDisplay); + } + + _initClazzAccess(env); + + va_start(ap, msg); + vsnprintf(buffer, sizeof(buffer), msg, ap); + va_end(ap); + + (*env)->ThrowNew(env, clazzRuntimeException, buffer); +} + +static XIOErrorHandler origIOErrorHandler = NULL; +static JNIEnv * displayIOErrorHandlerJNIEnv = NULL; + +static int displayIOErrorHandler(Display *dpy) +{ + _FatalError(displayIOErrorHandlerJNIEnv, "Nativewindow X11 IOError: Display %p not available", dpy); + origIOErrorHandler(dpy); + return 0; +} + +static void displayIOErrorHandlerEnable(int onoff, JNIEnv * env) { + if(onoff) { + if(NULL==origIOErrorHandler) { + displayIOErrorHandlerJNIEnv = env; + origIOErrorHandler = XSetIOErrorHandler(displayIOErrorHandler); + } + } else { + XSetIOErrorHandler(origIOErrorHandler); + origIOErrorHandler = NULL; + displayIOErrorHandlerJNIEnv = NULL; + } +} + +JNIEXPORT void JNICALL +Java_com_jogamp_nativewindow_impl_x11_X11Util_installIOErrorHandler(JNIEnv *env, jclass _unused) { + displayIOErrorHandlerEnable(1, env); +} + +JNIEXPORT jlong JNICALL +Java_com_jogamp_nativewindow_impl_x11_X11Lib_dlopen(JNIEnv *env, jclass _unused, jstring name) { + const jbyte* chars; + void* res; + chars = (*env)->GetStringUTFChars(env, name, NULL); + res = dlopen(chars, RTLD_LAZY | RTLD_GLOBAL); + (*env)->ReleaseStringUTFChars(env, name, chars); + return (jlong) ((intptr_t) res); +} + +JNIEXPORT jlong JNICALL +Java_com_jogamp_nativewindow_impl_x11_X11Lib_dlsym(JNIEnv *env, jclass _unused, jstring name) { + const jbyte* chars; + void* res; + chars = (*env)->GetStringUTFChars(env, name, NULL); + res = dlsym(RTLD_DEFAULT, chars); + (*env)->ReleaseStringUTFChars(env, name, chars); + return (jlong) ((intptr_t) res); +} + +/* Java->C glue code: + * Java package: com.jogamp.nativewindow.impl.x11.X11Lib + * Java method: XVisualInfo XGetVisualInfo(long arg0, long arg1, XVisualInfo arg2, java.nio.IntBuffer arg3) + * C function: XVisualInfo * XGetVisualInfo(Display * , long, XVisualInfo * , int * ); + */ +JNIEXPORT jobject JNICALL +Java_com_jogamp_nativewindow_impl_x11_X11Lib_XGetVisualInfoCopied1__JJLjava_nio_ByteBuffer_2Ljava_lang_Object_2I(JNIEnv *env, jclass _unused, jlong arg0, jlong arg1, jobject arg2, jobject arg3, jint arg3_byte_offset) { + XVisualInfo * _ptr2 = NULL; + int * _ptr3 = NULL; + XVisualInfo * _res; + int count; + jobject jbyteSource; + jobject jbyteCopy; + if(0==arg0) { + _FatalError(env, "invalid display connection.."); + } + if (arg2 != NULL) { + _ptr2 = (XVisualInfo *) (((char*) (*env)->GetDirectBufferAddress(env, arg2)) + 0); + } + if (arg3 != NULL) { + _ptr3 = (int *) (((char*) (*env)->GetPrimitiveArrayCritical(env, arg3, NULL)) + arg3_byte_offset); + } + _res = XGetVisualInfo((Display *) (intptr_t) arg0, (long) arg1, (XVisualInfo *) _ptr2, (int *) _ptr3); + count = _ptr3[0]; + if (arg3 != NULL) { + (*env)->ReleasePrimitiveArrayCritical(env, arg3, _ptr3, 0); + } + if (_res == NULL) return NULL; + + _initClazzAccess(env); + + jbyteSource = (*env)->NewDirectByteBuffer(env, _res, count * sizeof(XVisualInfo)); + jbyteCopy = (*env)->CallStaticObjectMethod(env, + clazzInternalBufferUtil, cstrInternalBufferUtil, jbyteSource); + + XFree(_res); + + return jbyteCopy; +} + +JNIEXPORT jlong JNICALL +Java_com_jogamp_nativewindow_impl_x11_X11Lib_DefaultVisualID(JNIEnv *env, jclass _unused, jlong display, jint screen) { + jlong r; + if(0==display) { + _FatalError(env, "invalid display connection.."); + } + r = (jlong) XVisualIDFromVisual( DefaultVisual( (Display*) (intptr_t) display, screen ) ); + return r; +} + +/* Java->C glue code: + * Java package: com.jogamp.nativewindow.impl.x11.X11Lib + * Java method: void XLockDisplay(long display) + * C function: void XLockDisplay(Display * display); + */ +JNIEXPORT void JNICALL +Java_com_jogamp_nativewindow_impl_x11_X11Lib_XLockDisplay__J(JNIEnv *env, jclass _unused, jlong display) { + if(0==display) { + _FatalError(env, "invalid display connection.."); + } + XLockDisplay((Display *) (intptr_t) display); +} + +/* Java->C glue code: + * Java package: com.jogamp.nativewindow.impl.x11.X11Lib + * Java method: void XUnlockDisplay(long display) + * C function: void XUnlockDisplay(Display * display); + */ +JNIEXPORT void JNICALL +Java_com_jogamp_nativewindow_impl_x11_X11Lib_XUnlockDisplay__J(JNIEnv *env, jclass _unused, jlong display) { + if(0==display) { + _FatalError(env, "invalid display connection.."); + } + XUnlockDisplay((Display *) (intptr_t) display); +} + + +/* Java->C glue code: + * Java package: com.jogamp.nativewindow.impl.x11.X11Lib + * Java method: int XCloseDisplay(long display) + * C function: int XCloseDisplay(Display * display); + */ +JNIEXPORT jint JNICALL +Java_com_jogamp_nativewindow_impl_x11_X11Lib_XCloseDisplay__J(JNIEnv *env, jclass _unused, jlong display) { + int _res; + if(0==display) { + _FatalError(env, "invalid display connection.."); + } + _res = XCloseDisplay((Display *) (intptr_t) display); + return _res; +} + +/* + * Class: com_jogamp_nativewindow_impl_x11_X11Lib + * Method: CreateDummyWindow + * Signature: (JIJ)J +JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_CreateDummyWindow + (JNIEnv *env, jobject obj, jlong display, jint screen_index, jlong visualID) +{ + Display * dpy = (Display *)(intptr_t)display; + int scrn_idx = (int)screen_index; + Window windowParent = 0; + Window window = 0; + + XVisualInfo visualTemplate; + XVisualInfo *pVisualQuery = NULL; + Visual *visual = NULL; + int depth; + + XSetWindowAttributes xswa; + unsigned long attrMask; + int n; + + Screen* scrn; + + if(NULL==dpy) { + _FatalError(env, "invalid display connection.."); + return 0; + } + + if(visualID<0) { + _throwNewRuntimeException(NULL, env, "invalid VisualID ..\n"); + return 0; + } + + XLockDisplay(dpy) ; + + XSync(dpy, False); + + scrn = ScreenOfDisplay(dpy, scrn_idx); + + // try given VisualID on screen + memset(&visualTemplate, 0, sizeof(XVisualInfo)); + visualTemplate.screen = scrn_idx; + visualTemplate.visualid = (VisualID)visualID; + pVisualQuery = XGetVisualInfo(dpy, VisualIDMask|VisualScreenMask, &visualTemplate,&n); + if(pVisualQuery!=NULL) { + visual = pVisualQuery->visual; + depth = pVisualQuery->depth; + visualID = (jlong)pVisualQuery->visualid; + XFree(pVisualQuery); + pVisualQuery=NULL; + } + DBG_PRINT5( "X11: [CreateWindow] trying given (dpy %p, screen %d, visualID: %d, parent %p) found: %p\n", dpy, scrn_idx, (int)visualID, windowParent, visual); + + if (visual==NULL) + { + _throwNewRuntimeException(dpy, env, "could not query Visual by given VisualID, bail out!\n"); + return 0; + } + + if(pVisualQuery!=NULL) { + XFree(pVisualQuery); + pVisualQuery=NULL; + } + + if(0==windowParent) { + windowParent = XRootWindowOfScreen(scrn); + } + + attrMask = (CWBackPixel | CWBorderPixel | CWColormap | CWOverrideRedirect) ; + + memset(&xswa, 0, sizeof(xswa)); + xswa.override_redirect = True; // not decorated + xswa.border_pixel = 0; + xswa.background_pixel = 0; + xswa.event_mask = 0 ; // no events + xswa.colormap = XCreateColormap(dpy, + XRootWindow(dpy, scrn_idx), + visual, + AllocNone); + + window = XCreateWindow(dpy, + windowParent, + 0, 0, + 64, 64, + 0, // border width + depth, + InputOutput, + visual, + attrMask, + &xswa); + + XSync(dpy, False); + + XUnlockDisplay(dpy) ; + + DBG_PRINT2( "X11: [CreateWindow] created window %p on display %p\n", window, dpy); + + return (jlong) window; +} + */ + + +/* + * Class: com_jogamp_nativewindow_impl_x11_X11Lib + * Method: DestroyDummyWindow + * Signature: (JJ)V +JNIEXPORT void JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_DestroyDummyWindow + (JNIEnv *env, jobject obj, jlong display, jlong window) +{ + Display * dpy = (Display *)(intptr_t)display; + Window w = (Window) window; + + if(NULL==dpy) { + _throwNewRuntimeException(NULL, env, "invalid display connection..\n"); + return; + } + XLockDisplay(dpy) ; + + XSync(dpy, False); + XUnmapWindow(dpy, w); + XSync(dpy, False); + XDestroyWindow(dpy, w); + XSync(dpy, False); + + XUnlockDisplay(dpy) ; +} + */ + diff --git a/src/newt/classes/com/jogamp/newt/x11/X11Display.java b/src/newt/classes/com/jogamp/newt/x11/X11Display.java index b8eb80b39..5fd6d9640 100755 --- a/src/newt/classes/com/jogamp/newt/x11/X11Display.java +++ b/src/newt/classes/com/jogamp/newt/x11/X11Display.java @@ -61,7 +61,7 @@ public class X11Display extends Display { } protected void createNative() { - long handle= X11Util.getThreadLocalDisplay(name); + long handle= X11Util.createThreadLocalDisplay(name); if (handle == 0 ) { throw new RuntimeException("Error creating display: "+name); } @@ -75,9 +75,7 @@ public class X11Display extends Display { } protected void closeNative() { - if(0==X11Util.closeThreadLocalDisplay(name)) { - throw new NativeWindowException(this+" was not mapped"); - } + X11Util.closeThreadLocalDisplay(name); } protected void dispatchMessages() { diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index 0fccc94bb..33c5324e2 100755 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -149,6 +149,19 @@ static jint X11KeySym2NewtVKey(KeySym keySym) { return keySym; } +static void _FatalError(JNIEnv *env, const char* msg, ...) +{ + char buffer[512]; + va_list ap; + + va_start(ap, msg); + vsnprintf(buffer, sizeof(buffer), msg, ap); + va_end(ap); + + fprintf(stderr, buffer); + (*env)->FatalError(env, buffer); +} + static const char * const ClazzNameRuntimeException = "java/lang/RuntimeException"; static jclass runtimeExceptionClz=NULL; @@ -217,26 +230,6 @@ static void displayDispatchErrorHandlerEnable(int onoff) { } } -static XIOErrorHandler origIOErrorHandler = NULL; - -static int displayDispatchIOErrorHandler(Display *dpy) -{ - fprintf(stderr, "Fatal: NEWT X11 IOError: Display %p not available\n", dpy); - return 0; -} - -static void displayDispatchIOErrorHandlerEnable(int onoff) { - if(onoff) { - if(NULL==origIOErrorHandler) { - origIOErrorHandler = XSetIOErrorHandler(displayDispatchIOErrorHandler); - } - } else { - XSetIOErrorHandler(origIOErrorHandler); - origIOErrorHandler = NULL; - } -} - - /* * Class: com_jogamp_newt_x11_X11Display * Method: initIDs @@ -259,28 +252,24 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_x11_X11Display_initIDs if(NULL==newtWindowClz) { c = (*env)->FindClass(env, ClazzNameNewtWindow); if(NULL==c) { - fprintf(stderr, "FatalError: NEWT X11Window: can't find %s\n", ClazzNameNewtWindow); - return JNI_FALSE; + _FatalError(env, "NEWT X11Window: can't find %s", ClazzNameNewtWindow); } newtWindowClz = (jclass)(*env)->NewGlobalRef(env, c); (*env)->DeleteLocalRef(env, c); if(NULL==newtWindowClz) { - fprintf(stderr, "FatalError: NEWT X11Window: can't use %s\n", ClazzNameNewtWindow); - return JNI_FALSE; + _FatalError(env, "NEWT X11Window: can't use %s", ClazzNameNewtWindow); } } if(NULL==runtimeExceptionClz) { c = (*env)->FindClass(env, ClazzNameRuntimeException); if(NULL==c) { - fprintf(stderr, "FatalError: NEWT X11Window: can't find %s\n", ClazzNameRuntimeException); - return JNI_FALSE; + _FatalError(env, "NEWT X11Window: can't find %s", ClazzNameRuntimeException); } runtimeExceptionClz = (jclass)(*env)->NewGlobalRef(env, c); (*env)->DeleteLocalRef(env, c); if(NULL==runtimeExceptionClz) { - fprintf(stderr, "FatalError: NEWT X11Window: can't use %s\n", ClazzNameRuntimeException); - return JNI_FALSE; + _FatalError(env, "NEWT X11Window: can't use %s", ClazzNameRuntimeException); } } @@ -297,7 +286,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Display_LockDisplay { Display * dpy = (Display *)(intptr_t)display; if(dpy==NULL) { - _throwNewRuntimeException(NULL, env, "given display connection is NULL\n"); + _FatalError(env, "invalid display connection.."); } XLockDisplay(dpy) ; DBG_PRINT1( "X11: LockDisplay 0x%X\n", dpy); @@ -314,7 +303,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Display_UnlockDisplay { Display * dpy = (Display *)(intptr_t)display; if(dpy==NULL) { - _throwNewRuntimeException(NULL, env, "given display connection is NULL\n"); + _FatalError(env, "invalid display connection.."); } XUnlockDisplay(dpy) ; DBG_PRINT1( "X11: UnlockDisplay 0x%X\n", dpy); @@ -334,7 +323,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Display_CompleteDisplay jlong windowDeleteAtom; if(dpy==NULL) { - _throwNewRuntimeException(NULL, env, "given display connection is NULL\n"); + _FatalError(env, "invalid display connection.."); } XLockDisplay(dpy) ; @@ -447,8 +436,6 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Display_DispatchMessages return; } - displayDispatchIOErrorHandlerEnable(1); - // Periodically take a break while( num_events > 0 ) { jobject jwindow = NULL; @@ -462,7 +449,6 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Display_DispatchMessages // num_events = XPending(dpy); // XEventsQueued(dpy, QueuedAfterFlush); // I/O Flush .. // num_events = XEventsQueued(dpy, QueuedAlready); // Better, no I/O .. if ( 0 >= XEventsQueued(dpy, QueuedAlready) ) { - displayDispatchIOErrorHandlerEnable(0); XUnlockDisplay(dpy) ; return; } @@ -470,8 +456,6 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Display_DispatchMessages XNextEvent(dpy, &evt); num_events--; - displayDispatchIOErrorHandlerEnable(0); - if( 0==evt.xany.window ) { _throwNewRuntimeException(dpy, env, "event window NULL, bail out!\n"); return ; @@ -606,8 +590,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_x11_X11Screen_GetScreen Screen * scrn= NULL; if(dpy==NULL) { - _throwNewRuntimeException(NULL, env, "invalid display connection..\n"); - return 0; + _FatalError(env, "invalid display connection.."); } XLockDisplay(dpy); @@ -698,8 +681,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_x11_X11Window_CreateWindow DBG_PRINT4( "X11: CreateWindow %x/%d %dx%d\n", x, y, width, height); if(dpy==NULL) { - _throwNewRuntimeException(NULL, env, "invalid display connection..\n"); - return 0; + _FatalError(env, "invalid display connection.."); } if(visualID<0) { @@ -711,7 +693,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_x11_X11Window_CreateWindow XSync(dpy, False); - scrn = ScreenOfDisplay(dpy, screen_index); + scrn = ScreenOfDisplay(dpy, scrn_idx); // try given VisualID on screen memset(&visualTemplate, 0, sizeof(XVisualInfo)); @@ -809,8 +791,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Window_CloseWindow jobject jwindow; if(dpy==NULL) { - _throwNewRuntimeException(NULL, env, "invalid display connection..\n"); - return; + _FatalError(env, "invalid display connection.."); } XLockDisplay(dpy) ; @@ -854,8 +835,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Window_setVisible0 DBG_PRINT1( "X11: setVisible0 vis %d\n", visible); if(dpy==NULL) { - _throwNewRuntimeException(NULL, env, "invalid display connection..\n"); - return; + _FatalError(env, "invalid display connection.."); } XLockDisplay(dpy) ; @@ -903,8 +883,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Window_setSize0 DBG_PRINT6( "X11: setSize0 %d/%d %dx%d, dec %d, vis %d\n", x, y, width, height, decorationToggle, setVisible); if(dpy==NULL) { - _throwNewRuntimeException(NULL, env, "invalid display connection..\n"); - return; + _FatalError(env, "invalid display connection.."); } XLockDisplay(dpy) ; @@ -963,8 +942,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Window_setPosition0 DBG_PRINT2( "X11: setPos0 . XConfigureWindow %d/%d\n", x, y); if(dpy==NULL) { - _throwNewRuntimeException(NULL, env, "invalid display connection..\n"); - return; + _FatalError(env, "invalid display connection.."); } XLockDisplay(dpy) ; -- cgit v1.2.3 From aa7084700bbf74d8bcc98cf0239f57cff2983423 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Sun, 18 Apr 2010 00:31:12 +0200 Subject: code review (http://jogamp.org/bugzilla/show_bug.cgi?id=396): improved exception handling in NWReflection and NativeLibLoaderBase. goal was to prevent catch(Throwable) and to fix or document empty catch blocks where it makes sense. --- .../com/jogamp/nativewindow/impl/NWReflection.java | 125 +++++++++++---------- .../nativewindow/impl/NativeLibLoaderBase.java | 32 ++++-- 2 files changed, 86 insertions(+), 71 deletions(-) (limited to 'src/nativewindow/classes') diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWReflection.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWReflection.java index 22bdedac9..9bac9477a 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWReflection.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWReflection.java @@ -40,73 +40,83 @@ import java.lang.reflect.*; import javax.media.nativewindow.*; public final class NWReflection { + public static final boolean DEBUG = Debug.debug("NWReflection"); - public static final boolean isClassAvailable(String clazzName) { - try { - Class clazz = Class.forName(clazzName, false, NWReflection.class.getClassLoader()); - return null!=clazz; - } catch (Throwable e) { } - return false; - } + /** + * Returns true only if the class could be loaded. + */ + public static final boolean isClassAvailable(String clazzName) { + try { + return null != Class.forName(clazzName, false, NWReflection.class.getClassLoader()); + } catch (ClassNotFoundException e) { + return false; + } + } - public static final Class getClass(String clazzName, boolean initialize) { - try { - return Class.forName(clazzName, initialize, NWReflection.class.getClassLoader()); - } catch (Throwable e) { } - return null; - } + /** + * Loads and returns the class or null. + * @see Class#forName(java.lang.String, boolean, java.lang.ClassLoader) + */ + public static final Class getClass(String clazzName, boolean initialize) { + try { + return getClassImpl(clazzName, initialize); + } catch (ClassNotFoundException e) { + return null; + } + } - public static final Constructor getConstructor(String clazzName, Class[] cstrArgTypes) { - Class factoryClass = null; - Constructor factory = null; + private static Class getClassImpl(String clazzName, boolean initialize) throws ClassNotFoundException { + return Class.forName(clazzName, initialize, NWReflection.class.getClassLoader()); + } - try { - factoryClass = getClass(clazzName, true); - if (factoryClass == null) { - throw new NativeWindowException(clazzName + " not available"); + /** + * @throws NativeWindowException if the constructor can not be delivered. + */ + public static final Constructor getConstructor(String clazzName, Class[] cstrArgTypes) { + try { + return getConstructor(getClassImpl(clazzName, true), cstrArgTypes); + } catch (ClassNotFoundException ex) { + throw new NativeWindowException(clazzName + " not available", ex); } - return getConstructor(factoryClass, cstrArgTypes); - } catch (Throwable e) { - if (DEBUG) { - e.printStackTrace(); - } - throw new NativeWindowException(e); } - } - - public static final Constructor getConstructor(Class clazz, Class[] cstrArgTypes) { - Constructor factory = null; - try { + /** + * @throws NativeWindowException if the constructor can not be delivered. + */ + public static final Constructor getConstructor(Class clazz, Class[] cstrArgTypes) { try { - factory = clazz.getDeclaredConstructor( cstrArgTypes ); - } catch(NoSuchMethodException nsme) { - throw new NativeWindowException("Constructor: '" + clazz + "("+cstrArgTypes+")' not found"); + return clazz.getDeclaredConstructor(cstrArgTypes); + } catch (NoSuchMethodException ex) { + String args = ""; + for (int i = 0; i < cstrArgTypes.length; i++) { + args += cstrArgTypes[i].getName(); + if(i != cstrArgTypes.length-1) { + args+= ", "; + } + } + throw new NativeWindowException("Constructor: '" + clazz + "(" + args + ")' not found", ex); } - return factory; - } catch (Throwable e) { - if (DEBUG) { - e.printStackTrace(); - } - throw new NativeWindowException(e); } - } public static final Constructor getConstructor(String clazzName) { return getConstructor(clazzName, new Class[0]); } - public static final Object createInstance(Class clazz, Class[] cstrArgTypes, Object[] cstrArgs) { - Constructor factory = null; - - try { - factory = getConstructor(clazz, cstrArgTypes); - return factory.newInstance( cstrArgs ) ; - } catch (Exception e) { - throw new NativeWindowException(e); + /** + * @throws NativeWindowException if the instance can not be created. + */ + public static final Object createInstance(Class clazz, Class[] cstrArgTypes, Object[] cstrArgs) { + try { + return getConstructor(clazz, cstrArgTypes).newInstance(cstrArgs); + } catch (InstantiationException ex) { + throw new NativeWindowException("can not create instance of class "+clazz, ex); + } catch (InvocationTargetException ex) { + throw new NativeWindowException("can not create instance of class "+clazz, ex); + } catch (IllegalAccessException ex) { + throw new NativeWindowException("can not create instance of class "+clazz, ex); + } } - } public static final Object createInstance(Class clazz, Object[] cstrArgs) { Class[] cstrArgTypes = new Class[cstrArgs.length]; @@ -116,16 +126,13 @@ public final class NWReflection { return createInstance(clazz, cstrArgTypes, cstrArgs); } - public static final Object createInstance(String clazzName, Class[] cstrArgTypes, Object[] cstrArgs) { - Constructor factory = null; - - try { - factory = getConstructor(clazzName, cstrArgTypes); - return factory.newInstance( cstrArgs ) ; - } catch (Exception e) { - throw new NativeWindowException(e); + public static final Object createInstance(String clazzName, Class[] cstrArgTypes, Object[] cstrArgs) { + try { + return createInstance(getClassImpl(clazzName, true), cstrArgTypes, cstrArgs); + } catch (ClassNotFoundException ex) { + throw new NativeWindowException(clazzName + " not available", ex); + } } - } public static final Object createInstance(String clazzName, Object[] cstrArgs) { Class[] cstrArgTypes = new Class[cstrArgs.length]; diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeLibLoaderBase.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeLibLoaderBase.java index 0670234d4..c4f1d7e08 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeLibLoaderBase.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeLibLoaderBase.java @@ -64,8 +64,7 @@ public class NativeLibLoaderBase { } private static class DefaultAction implements LoaderAction { - public void loadLibrary(String libname, String[] preload, - boolean preloadIgnoreError) { + public void loadLibrary(String libname, String[] preload, boolean preloadIgnoreError) { if (null!=preload) { for (int i=0; i Date: Tue, 20 Apr 2010 11:46:26 +0200 Subject: JOGL GL4 preperation (cont): - All available OpenGL versions (native/platform) are verified at GLProfile initialization and can be queried .. A mapping of major,compat -> major,minor,options is created. - Removal of temp context creation, when creating a context. This was necessary to query general availability of ARB_create_context. Due to the shared context of X11GLXDrawableFactory and WindowsWGLDrawableFactory, this is no more necessary. Due to the version mapping, the ARB_create_context paramters are known. - NativeWindow X11Lib: Added X11ErrorHandler, throwing a RuntimeException. Necessary to catch BadMatch .. etc X11 errors, eg for glXCreateContextAttribsARB Hence all X11 calls are covered now. - X11DummyGLXDrawable needs to use an own Window, otherwise GLn n>2 fails - Flattening the desktop GL* implementation, all use GL4bcImpl, which reduces the footprint dramatically. - GL*Impl.isGL*() (desktop) utilizes the GLContext.isGL*(), hence the results reflect the actual native context version. - GLContextImpl makeCurrent/create: Added workflow documentation, clarified code, defined abstract methods to have a protocol. - Removed moved files (from here to gluegen), see gluegen a01cb3d59715a41153380f1977ec75263b762dc6 - NativeLibLoader -> JNILibLoader - Fixed Exception Handling (as in gluegen bce53b52c8638729750c4286dbc04cb14329fd34), ie removed empty catch Throwable .. - GLContext.setSwapInterval(): Nop in offscreen case, otherwise X11IOError (NVIDIA Bug) Test: Tests - Junit - demos.gears.Gears - demos.jrefract.JRefract Platforms - Linux 64/32 ATI/NVidia - MacOsX - Windows (virtualbox 3.1.6, offscreen failed) TODO/BUGS: - FIXME ATI GLn n>2 with AWT, can't make context current, works well on NVIDIA though - FIXME GL3GL4: Due to GL3 and GL4 implementation bugs, we still choose GL2 first, if available! - Add GL 3.3 to GL3/gl3ext.h - Add GL 4.0 to GL3/gl3ext.h and fix the GL3/GL4 seperation - Rename jogl.gl2.jar -> jogl.gldesktop.jar (as done with it's native lib already) --- make/build-jogl.xml | 133 +++-- make/build-junit.xml | 18 + make/build-nativewindow.xml | 14 +- make/config/jogl/cg-common-CustomJavaCode.java | 2 +- make/config/jogl/gl-gl2.cfg | 48 +- make/config/jogl/gl-gl2es12.cfg | 90 ---- make/config/jogl/gl-gl3.cfg | 43 +- make/config/jogl/gl-gl3bc.cfg | 64 +-- make/config/jogl/gl-gl4.cfg | 37 ++ make/config/jogl/gl-gl4bc.cfg | 110 +++++ make/config/jogl/gl-impl-CustomCCode-gl2.c | 24 - make/config/jogl/gl-impl-CustomCCode-gl2es12.c | 24 - make/config/jogl/gl-impl-CustomCCode-gl3.c | 24 - make/config/jogl/gl-impl-CustomCCode-gl3bc.c | 24 - make/config/jogl/gl-impl-CustomCCode-gl4bc.c | 24 + .../config/jogl/gl-impl-CustomJavaCode-common.java | 74 ++- .../jogl/gl-impl-CustomJavaCode-desktop.java | 250 +++++++--- make/config/jogl/gl-impl-CustomJavaCode-gl2.java | 514 -------------------- .../jogl/gl-impl-CustomJavaCode-gl2es12.java | 455 ------------------ make/config/jogl/gl-impl-CustomJavaCode-gl3.java | 468 ------------------ make/config/jogl/gl-impl-CustomJavaCode-gl3bc.java | 514 -------------------- make/config/jogl/gl-impl-CustomJavaCode-gl4.java | 339 +++++++++++++ make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java | 385 +++++++++++++++ make/config/jogl/gl-impl-CustomJavaCode-gles1.java | 41 -- make/config/jogl/gl-impl-CustomJavaCode-gles2.java | 41 -- make/config/jogl/gl3-common.cfg | 3 + make/config/jogl/gl3-desktop-tracker.cfg | 38 -- make/config/jogl/gl4-common.cfg | 5 + make/config/jogl/gl4-desktop-tracker.cfg | 38 ++ make/config/jogl/glu-CustomJavaCode-base.java | 4 +- make/config/jogl/glu-CustomJavaCode-gl2es1.java | 2 +- make/config/jogl/glu-common.cfg | 2 +- make/config/jogl/obsolete/gl-gl2es12.cfg | 90 ++++ .../config/jogl/obsolete/gl-impl-CustomCCode-gl2.c | 24 + .../jogl/obsolete/gl-impl-CustomCCode-gl2es12.c | 24 + .../config/jogl/obsolete/gl-impl-CustomCCode-gl3.c | 24 + .../jogl/obsolete/gl-impl-CustomJavaCode-gl2.java | 385 +++++++++++++++ .../obsolete/gl-impl-CustomJavaCode-gl2es12.java | 353 ++++++++++++++ make/config/nativewindow/x11-CustomJavaCode.java | 3 +- make/stub_includes/opengl/gl4.c | 10 +- make/stub_includes/opengl/gl4bc.c | 18 + .../opengl/impl/ExtensionAvailabilityCache.java | 4 +- .../com/jogamp/opengl/impl/GLContextImpl.java | 489 ++++++++++++------- .../jogamp/opengl/impl/GLDrawableFactoryImpl.java | 5 +- .../com/jogamp/opengl/impl/GLDrawableImpl.java | 2 +- .../com/jogamp/opengl/impl/GLJNILibLoader.java | 100 ++++ .../com/jogamp/opengl/impl/NativeLibLoader.java | 109 ----- .../com/jogamp/opengl/impl/ThreadingImpl.java | 11 +- .../com/jogamp/opengl/impl/egl/EGLContext.java | 10 +- .../jogamp/opengl/impl/egl/EGLDrawableFactory.java | 12 +- .../opengl/impl/egl/EGLDynamicLookupHelper.java | 12 +- .../jogamp/opengl/impl/egl/EGLExternalContext.java | 2 +- .../opengl/impl/macosx/cgl/MacOSXCGLContext.java | 19 +- .../impl/macosx/cgl/MacOSXCGLDrawableFactory.java | 11 +- .../impl/macosx/cgl/MacOSXExternalCGLContext.java | 5 +- .../impl/macosx/cgl/MacOSXOnscreenCGLContext.java | 4 +- .../impl/macosx/cgl/MacOSXPbufferCGLContext.java | 13 +- .../macosx/cgl/awt/MacOSXJava2DCGLContext.java | 11 +- .../windows/wgl/WindowsExternalWGLContext.java | 2 +- .../opengl/impl/windows/wgl/WindowsWGLContext.java | 16 +- .../windows/wgl/WindowsWGLDrawableFactory.java | 52 +- .../WindowsWGLGraphicsConfigurationFactory.java | 1 - .../opengl/impl/x11/glx/X11DummyGLXDrawable.java | 13 +- .../opengl/impl/x11/glx/X11ExternalGLXContext.java | 2 +- .../jogamp/opengl/impl/x11/glx/X11GLXContext.java | 121 +++-- .../opengl/impl/x11/glx/X11GLXDrawableFactory.java | 52 +- .../opengl/impl/x11/glx/X11PbufferGLXContext.java | 29 +- .../com/jogamp/opengl/util/ImmModeSink.java | 6 +- .../opengl/util/glsl/fixedfunc/FixedFuncUtil.java | 2 +- src/jogl/classes/javax/media/opengl/GL4.java | 5 - src/jogl/classes/javax/media/opengl/GL4bc.java | 5 - src/jogl/classes/javax/media/opengl/GLContext.java | 187 +++++++- .../javax/media/opengl/GLDrawableFactory.java | 62 +-- src/jogl/classes/javax/media/opengl/GLProfile.java | 534 ++++++++++++--------- .../test/junit/jogl/acore/TestGLProfile01CORE.java | 95 ++++ .../jogamp/test/junit/jogl/awt/TestAWT01GLn.java | 106 ++++ .../junit/jogl/offscreen/TestOffscreen01NEWT.java | 39 +- .../test/junit/jogl/texture/TestTexture01AWT.java | 2 +- .../jogamp/nativewindow/impl/NWJNILibLoader.java | 50 ++ .../com/jogamp/nativewindow/impl/NWReflection.java | 188 -------- .../nativewindow/impl/NativeLibLoaderBase.java | 210 -------- .../nativewindow/impl/NativeWindowFactoryImpl.java | 5 +- .../nativewindow/impl/jawt/JAWTJNILibLoader.java | 78 +++ .../impl/jawt/JAWTNativeLibLoader.java | 78 --- .../jogamp/nativewindow/impl/jawt/JAWTUtil.java | 4 +- .../com/jogamp/nativewindow/impl/jvm/JVMUtil.java | 72 --- .../com/jogamp/nativewindow/impl/x11/X11Util.java | 2 +- .../nativewindow/GraphicsConfigurationFactory.java | 3 +- .../media/nativewindow/NativeWindowFactory.java | 13 +- src/nativewindow/native/JVM_Tool.c | 51 -- src/nativewindow/native/x11/Xmisc.c | 50 +- src/newt/classes/com/jogamp/newt/NewtFactory.java | 2 +- src/newt/classes/com/jogamp/newt/Window.java | 5 +- .../com/jogamp/newt/impl/NEWTJNILibLoader.java | 62 +++ .../com/jogamp/newt/impl/NativeLibLoader.java | 62 --- .../classes/com/jogamp/newt/intel/gdl/Display.java | 2 +- .../classes/com/jogamp/newt/macosx/MacDisplay.java | 2 +- .../jogamp/newt/opengl/broadcom/egl/Display.java | 2 +- .../com/jogamp/newt/opengl/kd/KDDisplay.java | 2 +- .../classes/com/jogamp/newt/util/MainThread.java | 6 +- .../com/jogamp/newt/windows/WindowsDisplay.java | 2 +- .../classes/com/jogamp/newt/x11/X11Display.java | 2 +- src/newt/native/X11Window.c | 34 +- 103 files changed, 3850 insertions(+), 4070 deletions(-) delete mode 100644 make/config/jogl/gl-gl2es12.cfg create mode 100644 make/config/jogl/gl-gl4.cfg create mode 100644 make/config/jogl/gl-gl4bc.cfg delete mode 100644 make/config/jogl/gl-impl-CustomCCode-gl2.c delete mode 100644 make/config/jogl/gl-impl-CustomCCode-gl2es12.c delete mode 100644 make/config/jogl/gl-impl-CustomCCode-gl3.c delete mode 100644 make/config/jogl/gl-impl-CustomCCode-gl3bc.c create mode 100644 make/config/jogl/gl-impl-CustomCCode-gl4bc.c delete mode 100644 make/config/jogl/gl-impl-CustomJavaCode-gl2.java delete mode 100644 make/config/jogl/gl-impl-CustomJavaCode-gl2es12.java delete mode 100644 make/config/jogl/gl-impl-CustomJavaCode-gl3.java delete mode 100644 make/config/jogl/gl-impl-CustomJavaCode-gl3bc.java create mode 100644 make/config/jogl/gl-impl-CustomJavaCode-gl4.java create mode 100644 make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java delete mode 100644 make/config/jogl/gl3-desktop-tracker.cfg create mode 100644 make/config/jogl/gl4-common.cfg create mode 100644 make/config/jogl/gl4-desktop-tracker.cfg create mode 100644 make/config/jogl/obsolete/gl-gl2es12.cfg create mode 100644 make/config/jogl/obsolete/gl-impl-CustomCCode-gl2.c create mode 100644 make/config/jogl/obsolete/gl-impl-CustomCCode-gl2es12.c create mode 100644 make/config/jogl/obsolete/gl-impl-CustomCCode-gl3.c create mode 100644 make/config/jogl/obsolete/gl-impl-CustomJavaCode-gl2.java create mode 100644 make/config/jogl/obsolete/gl-impl-CustomJavaCode-gl2es12.java create mode 100644 make/stub_includes/opengl/gl4bc.c create mode 100644 src/jogl/classes/com/jogamp/opengl/impl/GLJNILibLoader.java delete mode 100644 src/jogl/classes/com/jogamp/opengl/impl/NativeLibLoader.java delete mode 100644 src/jogl/classes/javax/media/opengl/GL4.java delete mode 100644 src/jogl/classes/javax/media/opengl/GL4bc.java create mode 100755 src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01CORE.java create mode 100755 src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/NWJNILibLoader.java delete mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/NWReflection.java delete mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeLibLoaderBase.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTJNILibLoader.java delete mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTNativeLibLoader.java delete mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/jvm/JVMUtil.java delete mode 100644 src/nativewindow/native/JVM_Tool.c create mode 100644 src/newt/classes/com/jogamp/newt/impl/NEWTJNILibLoader.java delete mode 100644 src/newt/classes/com/jogamp/newt/impl/NativeLibLoader.java (limited to 'src/nativewindow/classes') diff --git a/make/build-jogl.xml b/make/build-jogl.xml index d42b859bd..6d95ebea8 100644 --- a/make/build-jogl.xml +++ b/make/build-jogl.xml @@ -104,9 +104,6 @@ - - @@ -508,12 +505,24 @@
- - + + + + + + + + + + - @@ -544,7 +553,7 @@ - + - - - - - - - - - @@ -826,6 +820,21 @@ targetfile="${src.generated.java}/javax/media/opengl/DebugGL3.java" /> + + + + + + + + + + + @@ -899,7 +908,29 @@ - + + + + + + + + + + + + + + + + + + + + + @@ -1259,9 +1290,7 @@ - - - + @@ -1269,24 +1298,6 @@
- - - - - - - - - - - - - - - - - - @@ -1393,13 +1404,6 @@ linker.cfg.id="${linker.cfg.id.gl2}"/> - - - - - - + @@ -1450,7 +1453,6 @@ - @@ -1528,14 +1530,7 @@ - - - - - - - + - - - - - - - + diff --git a/make/build-junit.xml b/make/build-junit.xml index 887060084..ebf3f683e 100644 --- a/make/build-junit.xml +++ b/make/build-junit.xml @@ -81,6 +81,24 @@ + + + + + + + + + + + + + + + + + + - - + diff --git a/make/config/jogl/cg-common-CustomJavaCode.java b/make/config/jogl/cg-common-CustomJavaCode.java index 974e24bf4..d1e4f8bf5 100755 --- a/make/config/jogl/cg-common-CustomJavaCode.java +++ b/make/config/jogl/cg-common-CustomJavaCode.java @@ -1,5 +1,5 @@ static { - com.jogamp.opengl.impl.NativeLibLoader.loadCgImpl(); + com.jogamp.opengl.impl.GLJNILibLoader.loadCgImpl(); } /** A convenience method which reads all available data from the InputStream and then calls cgCreateProgram. */ diff --git a/make/config/jogl/gl-gl2.cfg b/make/config/jogl/gl-gl2.cfg index 37452d159..48dd8eda6 100644 --- a/make/config/jogl/gl-gl2.cfg +++ b/make/config/jogl/gl-gl2.cfg @@ -12,72 +12,32 @@ ExtendedInterfaceSymbolsIgnore ../src/jogl/classes/javax/media/opengl/fixedfunc/ ExtendedInterfaceSymbolsIgnore ../src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java Package javax.media.opengl -Style InterfaceAndImpl +Style InterfaceOnly JavaClass GL2 Extends GL2 GLBase Extends GL2 GL Extends GL2 GL2ES1 Extends GL2 GL2ES2 Extends GL2 GL2GL3 -ImplPackage com.jogamp.opengl.impl.gl2 -ImplJavaClass GL2Impl -Implements GL2Impl GLBase -Implements GL2Impl GL -Implements GL2Impl GL2ES1 -Implements GL2Impl GL2ES2 -Implements GL2Impl GL2GL3 Include gl-common.cfg Include gl-common-extensions.cfg Include gl-desktop.cfg -EmitProcAddressTable true -ProcAddressTableClassName GL2ProcAddressTable -GetProcAddressTableExpr ((GL2ProcAddressTable)_context.getGLProcAddressTable()) - # Pick up on-line OpenGL javadoc thanks to user cylab on javagaming.org forums TagNativeBinding true # Ignore extensions that are already picked up via the GL2ES1 interface IgnoreExtension GL_EXT_point_parameters -# Add PixelStorei StateTracker -# -CustomJavaCode GL2Impl private static final int params_offset = 0; // just a helper for JavaPrologue .. - -JavaPrologue glPixelStorei glStateTracker.setInt(pname, param); - -JavaPrologue glGetIntegerv if ( glStateTracker.getInt(pname, params, params_offset) ) { return; } - CustomJavaCode GL2 public boolean glIsPBOPackEnabled(); CustomJavaCode GL2 public boolean glIsPBOUnpackEnabled(); IncludeAs CustomJavaCode GL2 gl-if-CustomJavaCode-gl2.java -CustomJavaCode GL2Impl public void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) { -CustomJavaCode GL2Impl glFrustum((double)left, (double)right, (double)bottom, (double)top, (double)zNear, (double)zFar); } - -CustomJavaCode GL2Impl public void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) { -CustomJavaCode GL2Impl glOrtho((double)left, (double)right, (double)bottom, (double)top, (double)zNear, (double)zFar); } - -CustomJavaCode GL2Impl public void glClearDepthf(float depth) { -CustomJavaCode GL2Impl glClearDepth((double)depth); } - -CustomJavaCode GL2Impl public void glDepthRangef(float zNear, float zFar) { -CustomJavaCode GL2Impl glDepthRange((double)zNear, (double)zFar); } - Include gl-headers.cfg Include ../intptr.cfg -IncludeAs CustomJavaCode GL2Impl gl-impl-CustomJavaCode-common.java -IncludeAs CustomJavaCode GL2Impl gl-impl-CustomJavaCode-gl2.java -IncludeAs CustomJavaCode GL2Impl gl-impl-CustomJavaCode-desktop.java -IncludeAs CustomJavaCode GL2Impl gl-impl-CustomJavaCode-gl2_es2.java -IncludeAs CustomCCode gl-impl-CustomCCode-gl2.c +EmitProcAddressTable false +ProcAddressTableClassName DontGenerateProcAddressTableStuff +GetProcAddressTableExpr DontGenerateProcAddressTableStuff -Import javax.media.opengl.GLES1 -Import javax.media.opengl.GLES2 -Import javax.media.opengl.GL2 -Import javax.media.opengl.GLArrayData -Import javax.media.opengl.GLUniformData -Import com.jogamp.opengl.impl.InternalBufferUtil -Import java.io.PrintStream diff --git a/make/config/jogl/gl-gl2es12.cfg b/make/config/jogl/gl-gl2es12.cfg deleted file mode 100644 index 3942b1419..000000000 --- a/make/config/jogl/gl-gl2es12.cfg +++ /dev/null @@ -1,90 +0,0 @@ -# This .cfg file is used to generate the GL interface and implementing class. -JavaOutputDir gensrc/classes -NativeOutputDir gensrc/native/jogl/gl2es12 - -ExtendedInterfaceSymbolsOnly ../build-temp/gensrc/classes/javax/media/opengl/GL.java -ExtendedInterfaceSymbolsOnly ../build-temp/gensrc/classes/javax/media/opengl/GL2ES1.java -ExtendedInterfaceSymbolsOnly ../build-temp/gensrc/classes/javax/media/opengl/GL2ES2.java -ExtendedInterfaceSymbolsOnly ../src/jogl/classes/javax/media/opengl/GLBase.java -ExtendedInterfaceSymbolsOnly ../src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java -ExtendedInterfaceSymbolsOnly ../src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFunc.java -ExtendedInterfaceSymbolsOnly ../src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java - -Style ImplOnly -ImplPackage com.jogamp.opengl.impl.gl2es12 -ImplJavaClass GL2ES12Impl -Implements GL2ES12Impl GLBase -Implements GL2ES12Impl GL -Implements GL2ES12Impl GL2ES1 -Implements GL2ES12Impl GL2ES2 - -Include gl-common.cfg -Include gl-common-extensions.cfg -Include gl-desktop.cfg - -# Because we're manually implementing glMapBuffer but only producing -# the implementing class, GlueGen doesn't notice that it has to emit a -# proc address table entry for it. Force it to here. -ForceProcAddressGen glMapBuffer - -# Force all of the methods to be emitted using dynamic linking so we -# don't need to link against any emulation library on the desktop or -# depend on the presence of an import library for a particular device -ForceProcAddressGen __ALL__ - -# Also force the calling conventions of the locally generated function -# pointer typedefs for these routines to APIENTRY -LocalProcAddressCallingConvention __ALL__ APIENTRY - -EmitProcAddressTable true -ProcAddressTableClassName GL2ES12ProcAddressTable -GetProcAddressTableExpr ((GL2ES12ProcAddressTable)_context.getGLProcAddressTable()) - -# Pick up on-line OpenGL javadoc thanks to user cylab on javagaming.org forums -TagNativeBinding true - -# There seem to be some errors in the glue code generation where we are not ignoring -# enough routines from desktop GL in GL2ES12Impl. For now manually ignore those which -# we know shouldn't be in there -Ignore glGetTexImage -Ignore glPixelStoref - -# Add PixelStorei StateTracker -# -# Add input validation to glPixelStorei to make sure that, even if we -# are running on top of desktop OpenGL, parameters not exposed in -# OpenGL ES can not be changed -CustomJavaCode GL2ES12Impl private static final int params_offset = 0; // just a helper for JavaPrologue .. - -JavaPrologue glPixelStorei if (pname != GL_PACK_ALIGNMENT && pname != GL_UNPACK_ALIGNMENT) { -JavaPrologue glPixelStorei throw new GLException("Unsupported pixel store parameter name 0x" + Integer.toHexString(pname)); -JavaPrologue glPixelStorei } -JavaPrologue glPixelStorei glStateTracker.setInt(pname, param); - -JavaPrologue glGetIntegerv if ( glStateTracker.getInt(pname, params, params_offset) ) { return; } - -CustomJavaCode GL2ES12Impl public void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) { -CustomJavaCode GL2ES12Impl glFrustum((double)left, (double)right, (double)bottom, (double)top, (double)zNear, (double)zFar); } - -CustomJavaCode GL2ES12Impl public void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) { -CustomJavaCode GL2ES12Impl glOrtho((double)left, (double)right, (double)bottom, (double)top, (double)zNear, (double)zFar); } - -CustomJavaCode GL2ES12Impl public void glClearDepthf(float depth) { -CustomJavaCode GL2ES12Impl glClearDepth((double)depth); } - -CustomJavaCode GL2ES12Impl public void glDepthRangef(float zNear, float zFar) { -CustomJavaCode GL2ES12Impl glDepthRange((double)zNear, (double)zFar); } - -Include gl-headers.cfg -Include ../intptr.cfg - -IncludeAs CustomJavaCode GL2ES12Impl gl-impl-CustomJavaCode-common.java -IncludeAs CustomJavaCode GL2ES12Impl gl-impl-CustomJavaCode-gl2es12.java -IncludeAs CustomJavaCode GL2ES12Impl gl-impl-CustomJavaCode-embedded.java -IncludeAs CustomJavaCode GL2ES12Impl gl-impl-CustomJavaCode-gl2_es2.java -IncludeAs CustomCCode gl-impl-CustomCCode-gl2es12.c - -Import javax.media.opengl.GLES1 -Import javax.media.opengl.GLES2 -Import com.jogamp.opengl.impl.InternalBufferUtil -Import java.io.PrintStream diff --git a/make/config/jogl/gl-gl3.cfg b/make/config/jogl/gl-gl3.cfg index 0bfe2cc38..d5e0003d4 100644 --- a/make/config/jogl/gl-gl3.cfg +++ b/make/config/jogl/gl-gl3.cfg @@ -8,7 +8,7 @@ ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/G ExtendedInterfaceSymbolsIgnore ../src/jogl/classes/javax/media/opengl/GLBase.java Package javax.media.opengl -Style InterfaceAndImpl +Style InterfaceOnly JavaClass GL3 Extends GL3 GLBase Extends GL3 GL @@ -27,48 +27,15 @@ Include gl3-desktop.cfg IncludeAs CustomJavaCode GL3 gl-if-CustomJavaCode-gl3.java -EmitProcAddressTable true -ProcAddressTableClassName GL3ProcAddressTable -GetProcAddressTableExpr ((GL3ProcAddressTable)_context.getGLProcAddressTable()) - -# Force all of the methods to be emitted using dynamic linking so we -# don't need to link against any emulation library on the desktop or -# depend on the presence of an import library for a particular device -ForceProcAddressGen __ALL__ - -# Also force the calling conventions of the locally generated function -# pointer typedefs for these routines to APIENTRY -LocalProcAddressCallingConvention __ALL__ APIENTRY +EmitProcAddressTable false # Pick up on-line OpenGL javadoc thanks to user cylab on javagaming.org forums TagNativeBinding true -# Add PixelStorei StateTracker -# -CustomJavaCode GL3Impl private static final int params_offset = 0; // just a helper for JavaPrologue .. - -JavaPrologue glPixelStorei glStateTracker.setInt(pname, param); - -JavaPrologue glGetIntegerv if ( glStateTracker.getInt(pname, params, params_offset) ) { return; } - -CustomJavaCode GL3Impl public void glClearDepthf(float depth) { -CustomJavaCode GL3Impl glClearDepth((double)depth); } - -CustomJavaCode GL3Impl public void glDepthRangef(float zNear, float zFar) { -CustomJavaCode GL3Impl glDepthRange((double)zNear, (double)zFar); } - Include gl3-headers.cfg Include ../intptr.cfg -IncludeAs CustomJavaCode GL3Impl gl-impl-CustomJavaCode-common.java -IncludeAs CustomJavaCode GL3Impl gl-impl-CustomJavaCode-gl3.java -IncludeAs CustomJavaCode GL3Impl gl-impl-CustomJavaCode-desktop.java -IncludeAs CustomJavaCode GL3Impl gl-impl-CustomJavaCode-gl2_es2.java -IncludeAs CustomCCode gl-impl-CustomCCode-gl3.c +EmitProcAddressTable false +ProcAddressTableClassName DontGenerateProcAddressTableStuff +GetProcAddressTableExpr DontGenerateProcAddressTableStuff -Import javax.media.opengl.GLES2 -Import javax.media.opengl.GL3 -Import javax.media.opengl.GLArrayData -Import javax.media.opengl.GLUniformData -Import com.jogamp.opengl.impl.InternalBufferUtil -Import java.io.PrintStream diff --git a/make/config/jogl/gl-gl3bc.cfg b/make/config/jogl/gl-gl3bc.cfg index 7bba2f635..7c53ea8d6 100644 --- a/make/config/jogl/gl-gl3bc.cfg +++ b/make/config/jogl/gl-gl3bc.cfg @@ -14,7 +14,7 @@ ExtendedInterfaceSymbolsIgnore ../src/jogl/classes/javax/media/opengl/fixedfunc/ ExtendedInterfaceSymbolsIgnore ../src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java Package javax.media.opengl -Style InterfaceAndImpl +Style InterfaceOnly JavaClass GL3bc Extends GL3bc GLBase Extends GL3bc GL @@ -23,15 +23,6 @@ Extends GL3bc GL2ES2 Extends GL3bc GL2GL3 Extends GL3bc GL2 Extends GL3bc GL3 -ImplPackage com.jogamp.opengl.impl.gl3 -ImplJavaClass GL3bcImpl -Implements GL3bcImpl GLBase -Implements GL3bcImpl GL -Implements GL3bcImpl GL2ES1 -Implements GL3bcImpl GL2ES2 -Implements GL3bcImpl GL2GL3 -Implements GL3bcImpl GL2 -Implements GL3bcImpl GL3 Include gl-common.cfg Include gl-common-extensions.cfg @@ -39,64 +30,17 @@ Include gl-desktop.cfg Include gl3-common.cfg Include gl3-desktop.cfg -# Because we're manually implementing glMapBuffer but only producing -# the implementing class, GlueGen doesn't notice that it has to emit a -# proc address table entry for it. Force it to here. -ForceProcAddressGen glMapBuffer - -# Force all of the methods to be emitted using dynamic linking so we -# don't need to link against any emulation library on the desktop or -# depend on the presence of an import library for a particular device -ForceProcAddressGen __ALL__ - -# Also force the calling conventions of the locally generated function -# pointer typedefs for these routines to APIENTRY -LocalProcAddressCallingConvention __ALL__ APIENTRY - -EmitProcAddressTable true -ProcAddressTableClassName GL3bcProcAddressTable -GetProcAddressTableExpr ((GL3bcProcAddressTable)_context.getGLProcAddressTable()) - # Pick up on-line OpenGL javadoc thanks to user cylab on javagaming.org forums TagNativeBinding true # Ignore extensions that are already picked up via the GL2ES1 interface IgnoreExtension GL_EXT_point_parameters -# Add PixelStorei StateTracker -CustomJavaCode GL3bcImpl private static final int params_offset = 0; // just a helper for JavaPrologue .. - -JavaPrologue glPixelStorei glStateTracker.setInt(pname, param); - -JavaPrologue glGetIntegerv if ( glStateTracker.getInt(pname, params, params_offset) ) { return; } - -CustomJavaCode GL3bcImpl public void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) { -CustomJavaCode GL3bcImpl glFrustum((double)left, (double)right, (double)bottom, (double)top, (double)zNear, (double)zFar); } - -CustomJavaCode GL3bcImpl public void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) { -CustomJavaCode GL3bcImpl glOrtho((double)left, (double)right, (double)bottom, (double)top, (double)zNear, (double)zFar); } - -CustomJavaCode GL3bcImpl public void glClearDepthf(float depth) { -CustomJavaCode GL3bcImpl glClearDepth((double)depth); } - -CustomJavaCode GL3bcImpl public void glDepthRangef(float zNear, float zFar) { -CustomJavaCode GL3bcImpl glDepthRange((double)zNear, (double)zFar); } - Include gl-headers.cfg Include gl3ext-headers.cfg Include ../intptr.cfg -IncludeAs CustomJavaCode GL3bcImpl gl-impl-CustomJavaCode-common.java -IncludeAs CustomJavaCode GL3bcImpl gl-impl-CustomJavaCode-gl3bc.java -IncludeAs CustomJavaCode GL3bcImpl gl-impl-CustomJavaCode-desktop.java -IncludeAs CustomJavaCode GL3bcImpl gl-impl-CustomJavaCode-gl2_es2.java -IncludeAs CustomCCode gl-impl-CustomCCode-gl3bc.c +EmitProcAddressTable false +ProcAddressTableClassName DontGenerateProcAddressTableStuff +GetProcAddressTableExpr DontGenerateProcAddressTableStuff -Import javax.media.opengl.GLES1 -Import javax.media.opengl.GLES2 -Import javax.media.opengl.GL2GL3 -Import javax.media.opengl.GL2 -Import javax.media.opengl.GL3 -Import javax.media.opengl.GL3bc -Import com.jogamp.opengl.impl.InternalBufferUtil -Import java.io.PrintStream diff --git a/make/config/jogl/gl-gl4.cfg b/make/config/jogl/gl-gl4.cfg new file mode 100644 index 000000000..1d4392899 --- /dev/null +++ b/make/config/jogl/gl-gl4.cfg @@ -0,0 +1,37 @@ +# This .cfg file is used to generate the GL interface and implementing class. +JavaOutputDir gensrc/classes +NativeOutputDir gensrc/native/jogl/gl4 + +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL2ES2.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL2GL3.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL3.java +ExtendedInterfaceSymbolsIgnore ../src/jogl/classes/javax/media/opengl/GLBase.java + +Package javax.media.opengl +Style InterfaceOnly +JavaClass GL4 +Extends GL4 GLBase +Extends GL4 GL +Extends GL4 GL2ES2 +Extends GL4 GL2GL3 +Extends GL4 GL3 +Include gl-common.cfg +Include gl-common-extensions.cfg +Include gl3-common.cfg +Include gl4-common.cfg +Include gl3-desktop.cfg + +IncludeAs CustomJavaCode GL4 gl-if-CustomJavaCode-gl3.java + +EmitProcAddressTable false +ProcAddressTableClassName DontGenerateProcAddressTableStuff +GetProcAddressTableExpr DontGenerateProcAddressTableStuff + + +# Pick up on-line OpenGL javadoc thanks to user cylab on javagaming.org forums +TagNativeBinding true + +Include gl3-headers.cfg +Include ../intptr.cfg + diff --git a/make/config/jogl/gl-gl4bc.cfg b/make/config/jogl/gl-gl4bc.cfg new file mode 100644 index 000000000..3a3e02041 --- /dev/null +++ b/make/config/jogl/gl-gl4bc.cfg @@ -0,0 +1,110 @@ +# This .cfg file is used to generate the GL interface and implementing class. +JavaOutputDir gensrc/classes +NativeOutputDir gensrc/native/jogl/gl4 + +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL2ES1.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL2ES2.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL2GL3.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL2.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL3.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL4.java +ExtendedInterfaceSymbolsIgnore ../build-temp/gensrc/classes/javax/media/opengl/GL3bc.java +ExtendedInterfaceSymbolsIgnore ../src/jogl/classes/javax/media/opengl/GLBase.java +ExtendedInterfaceSymbolsIgnore ../src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java +ExtendedInterfaceSymbolsIgnore ../src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFunc.java +ExtendedInterfaceSymbolsIgnore ../src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java + +Package javax.media.opengl +Style InterfaceAndImpl +JavaClass GL4bc +Extends GL4bc GLBase +Extends GL4bc GL +Extends GL4bc GL2ES1 +Extends GL4bc GL2ES2 +Extends GL4bc GL2GL3 +Extends GL4bc GL2 +Extends GL4bc GL3 +Extends GL4bc GL3bc +Extends GL4bc GL4 +ImplPackage com.jogamp.opengl.impl.gl4 +ImplJavaClass GL4bcImpl +Implements GL4bcImpl GLBase +Implements GL4bcImpl GL +Implements GL4bcImpl GL2ES1 +Implements GL4bcImpl GL2ES2 +Implements GL4bcImpl GL2GL3 +Implements GL4bcImpl GL2 +Implements GL4bcImpl GL3 +Implements GL4bcImpl GL3bc +Implements GL4bcImpl GL4 + +Include gl-common.cfg +Include gl-common-extensions.cfg +Include gl-desktop.cfg +Include gl3-common.cfg +Include gl4-common.cfg +Include gl3-desktop.cfg + +# Because we're manually implementing glMapBuffer but only producing +# the implementing class, GlueGen doesn't notice that it has to emit a +# proc address table entry for it. Force it to here. +ForceProcAddressGen glMapBuffer + +# Force all of the methods to be emitted using dynamic linking so we +# don't need to link against any emulation library on the desktop or +# depend on the presence of an import library for a particular device +ForceProcAddressGen __ALL__ + +# Also force the calling conventions of the locally generated function +# pointer typedefs for these routines to APIENTRY +LocalProcAddressCallingConvention __ALL__ APIENTRY + +EmitProcAddressTable true +ProcAddressTableClassName GL4bcProcAddressTable +GetProcAddressTableExpr ((GL4bcProcAddressTable)_context.getGLProcAddressTable()) + +# Pick up on-line OpenGL javadoc thanks to user cylab on javagaming.org forums +TagNativeBinding true + +# Ignore extensions that are already picked up via the GL2ES1 interface +IgnoreExtension GL_EXT_point_parameters + +# Add PixelStorei StateTracker +CustomJavaCode GL4bcImpl private static final int params_offset = 0; // just a helper for JavaPrologue .. + +JavaPrologue glPixelStorei glStateTracker.setInt(pname, param); + +JavaPrologue glGetIntegerv if ( glStateTracker.getInt(pname, params, params_offset) ) { return; } + +CustomJavaCode GL4bcImpl public void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) { +CustomJavaCode GL4bcImpl glFrustum((double)left, (double)right, (double)bottom, (double)top, (double)zNear, (double)zFar); } + +CustomJavaCode GL4bcImpl public void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) { +CustomJavaCode GL4bcImpl glOrtho((double)left, (double)right, (double)bottom, (double)top, (double)zNear, (double)zFar); } + +CustomJavaCode GL4bcImpl public void glClearDepthf(float depth) { +CustomJavaCode GL4bcImpl glClearDepth((double)depth); } + +CustomJavaCode GL4bcImpl public void glDepthRangef(float zNear, float zFar) { +CustomJavaCode GL4bcImpl glDepthRange((double)zNear, (double)zFar); } + +Include gl-headers.cfg +Include gl3ext-headers.cfg +Include ../intptr.cfg + +IncludeAs CustomJavaCode GL4bcImpl gl-impl-CustomJavaCode-common.java +IncludeAs CustomJavaCode GL4bcImpl gl-impl-CustomJavaCode-gl4bc.java +IncludeAs CustomJavaCode GL4bcImpl gl-impl-CustomJavaCode-desktop.java +IncludeAs CustomJavaCode GL4bcImpl gl-impl-CustomJavaCode-gl2_es2.java +IncludeAs CustomCCode gl-impl-CustomCCode-gl4bc.c + +Import javax.media.opengl.GLES1 +Import javax.media.opengl.GLES2 +Import javax.media.opengl.GL2GL3 +Import javax.media.opengl.GL2 +Import javax.media.opengl.GL3 +Import javax.media.opengl.GL3bc +Import javax.media.opengl.GL4 +Import com.jogamp.opengl.impl.InternalBufferUtil +Import java.io.PrintStream diff --git a/make/config/jogl/gl-impl-CustomCCode-gl2.c b/make/config/jogl/gl-impl-CustomCCode-gl2.c deleted file mode 100644 index 91fd0078b..000000000 --- a/make/config/jogl/gl-impl-CustomCCode-gl2.c +++ /dev/null @@ -1,24 +0,0 @@ -/* Java->C glue code: - * Java package: com.jogamp.opengl.impl.gl2.GL2Impl - * Java method: long dispatch_glMapBuffer(int target, int access) - * C function: void * glMapBuffer(GLenum target, GLenum access); - */ -JNIEXPORT jlong JNICALL -Java_com_jogamp_opengl_impl_gl2_GL2Impl_dispatch_1glMapBuffer(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { - PFNGLMAPBUFFERPROC ptr_glMapBuffer; - void * _res; - ptr_glMapBuffer = (PFNGLMAPBUFFERPROC) (intptr_t) glProcAddress; - assert(ptr_glMapBuffer != NULL); - _res = (* ptr_glMapBuffer) ((GLenum) target, (GLenum) access); - return (jlong) (intptr_t) _res; -} - -/* Java->C glue code: - * Java package: com.jogamp.opengl.impl.gl2.GL2Impl - * Java method: ByteBuffer newDirectByteBuffer(long addr, int capacity); - * C function: jobject newDirectByteBuffer(jlong addr, jint capacity); - */ -JNIEXPORT jobject JNICALL -Java_com_jogamp_opengl_impl_gl2_GL2Impl_newDirectByteBuffer(JNIEnv *env, jobject _unused, jlong addr, jint capacity) { - return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) addr, capacity); -} diff --git a/make/config/jogl/gl-impl-CustomCCode-gl2es12.c b/make/config/jogl/gl-impl-CustomCCode-gl2es12.c deleted file mode 100644 index 07b821802..000000000 --- a/make/config/jogl/gl-impl-CustomCCode-gl2es12.c +++ /dev/null @@ -1,24 +0,0 @@ -/* Java->C glue code: - * Java package: com.jogamp.opengl.impl.gl2es12.GL2ES12Impl - * Java method: long dispatch_glMapBuffer(int target, int access) - * C function: void * glMapBuffer(GLenum target, GLenum access); - */ -JNIEXPORT jlong JNICALL -Java_com_jogamp_opengl_impl_gl2es12_GL2ES12Impl_dispatch_1glMapBuffer(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { - PFNGLMAPBUFFERPROC ptr_glMapBuffer; - void * _res; - ptr_glMapBuffer = (PFNGLMAPBUFFERPROC) (intptr_t) glProcAddress; - assert(ptr_glMapBuffer != NULL); - _res = (* ptr_glMapBuffer) ((GLenum) target, (GLenum) access); - return (jlong) (intptr_t) _res; -} - -/* Java->C glue code: - * Java package: com.jogamp.opengl.impl.gl2es12.GL2ES12Impl - * Java method: ByteBuffer newDirectByteBuffer(long addr, int capacity); - * C function: jobject newDirectByteBuffer(jlong addr, jint capacity); - */ -JNIEXPORT jobject JNICALL -Java_com_jogamp_opengl_impl_gl2es12_GL2ES12Impl_newDirectByteBuffer(JNIEnv *env, jobject _unused, jlong addr, jint capacity) { - return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) addr, capacity); -} diff --git a/make/config/jogl/gl-impl-CustomCCode-gl3.c b/make/config/jogl/gl-impl-CustomCCode-gl3.c deleted file mode 100644 index f540a7d4a..000000000 --- a/make/config/jogl/gl-impl-CustomCCode-gl3.c +++ /dev/null @@ -1,24 +0,0 @@ -/* Java->C glue code: - * Java package: com.jogamp.opengl.impl.gl3.GL3Impl - * Java method: long dispatch_glMapBuffer(int target, int access) - * C function: void * glMapBuffer(GLenum target, GLenum access); - */ -JNIEXPORT jlong JNICALL -Java_com_jogamp_opengl_impl_gl3_GL3Impl_dispatch_1glMapBuffer(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { - PFNGLMAPBUFFERPROC ptr_glMapBuffer; - void * _res; - ptr_glMapBuffer = (PFNGLMAPBUFFERPROC) (intptr_t) glProcAddress; - assert(ptr_glMapBuffer != NULL); - _res = (* ptr_glMapBuffer) ((GLenum) target, (GLenum) access); - return (jlong) (intptr_t) _res; -} - -/* Java->C glue code: - * Java package: com.jogamp.opengl.impl.gl3.GL3Impl - * Java method: ByteBuffer newDirectByteBuffer(long addr, int capacity); - * C function: jobject newDirectByteBuffer(jlong addr, jint capacity); - */ -JNIEXPORT jobject JNICALL -Java_com_jogamp_opengl_impl_gl3_GL3Impl_newDirectByteBuffer(JNIEnv *env, jobject _unused, jlong addr, jint capacity) { - return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) addr, capacity); -} diff --git a/make/config/jogl/gl-impl-CustomCCode-gl3bc.c b/make/config/jogl/gl-impl-CustomCCode-gl3bc.c deleted file mode 100644 index 21de8c925..000000000 --- a/make/config/jogl/gl-impl-CustomCCode-gl3bc.c +++ /dev/null @@ -1,24 +0,0 @@ -/* Java->C glue code: - * Java package: com.jogamp.opengl.impl.gl3.GL3bcImpl - * Java method: long dispatch_glMapBuffer(int target, int access) - * C function: void * glMapBuffer(GLenum target, GLenum access); - */ -JNIEXPORT jlong JNICALL -Java_com_jogamp_opengl_impl_gl3_GL3bcImpl_dispatch_1glMapBuffer(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { - PFNGLMAPBUFFERPROC ptr_glMapBuffer; - void * _res; - ptr_glMapBuffer = (PFNGLMAPBUFFERPROC) (intptr_t) glProcAddress; - assert(ptr_glMapBuffer != NULL); - _res = (* ptr_glMapBuffer) ((GLenum) target, (GLenum) access); - return (jlong) (intptr_t) _res; -} - -/* Java->C glue code: - * Java package: com.jogamp.opengl.impl.gl3.GL3bcImpl - * Java method: ByteBuffer newDirectByteBuffer(long addr, int capacity); - * C function: jobject newDirectByteBuffer(jlong addr, jint capacity); - */ -JNIEXPORT jobject JNICALL -Java_com_jogamp_opengl_impl_gl3_GL3bcImpl_newDirectByteBuffer(JNIEnv *env, jobject _unused, jlong addr, jint capacity) { - return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) addr, capacity); -} diff --git a/make/config/jogl/gl-impl-CustomCCode-gl4bc.c b/make/config/jogl/gl-impl-CustomCCode-gl4bc.c new file mode 100644 index 000000000..bcda20fa4 --- /dev/null +++ b/make/config/jogl/gl-impl-CustomCCode-gl4bc.c @@ -0,0 +1,24 @@ +/* Java->C glue code: + * Java package: com.jogamp.opengl.impl.gl4.GL4bcImpl + * Java method: long dispatch_glMapBuffer(int target, int access) + * C function: void * glMapBuffer(GLenum target, GLenum access); + */ +JNIEXPORT jlong JNICALL +Java_com_jogamp_opengl_impl_gl4_GL4bcImpl_dispatch_1glMapBuffer(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { + PFNGLMAPBUFFERPROC ptr_glMapBuffer; + void * _res; + ptr_glMapBuffer = (PFNGLMAPBUFFERPROC) (intptr_t) glProcAddress; + assert(ptr_glMapBuffer != NULL); + _res = (* ptr_glMapBuffer) ((GLenum) target, (GLenum) access); + return (jlong) (intptr_t) _res; +} + +/* Java->C glue code: + * Java package: com.jogamp.opengl.impl.gl4.GL4bcImpl + * Java method: ByteBuffer newDirectByteBuffer(long addr, int capacity); + * C function: jobject newDirectByteBuffer(jlong addr, jint capacity); + */ +JNIEXPORT jobject JNICALL +Java_com_jogamp_opengl_impl_gl4_GL4bcImpl_newDirectByteBuffer(JNIEnv *env, jobject _unused, jlong addr, jint capacity) { + return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) addr, capacity); +} diff --git a/make/config/jogl/gl-impl-CustomJavaCode-common.java b/make/config/jogl/gl-impl-CustomJavaCode-common.java index 564606799..4872490b0 100644 --- a/make/config/jogl/gl-impl-CustomJavaCode-common.java +++ b/make/config/jogl/gl-impl-CustomJavaCode-common.java @@ -1,16 +1,58 @@ - public GLProfile getGLProfile() { - return this.glProfile; - } - private GLProfile glProfile; - - public int glGetBoundBuffer(int target) { - return bufferStateTracker.getBoundBufferObject(target, this); - } - - public boolean glIsVBOArrayEnabled() { - return checkArrayVBOEnabled(false); - } - - public boolean glIsVBOElementEnabled() { - return checkElementVBOEnabled(false); - } + public GLProfile getGLProfile() { + return this.glProfile; + } + private GLProfile glProfile; + + public int glGetBoundBuffer(int target) { + return bufferStateTracker.getBoundBufferObject(target, this); + } + + public boolean glIsVBOArrayEnabled() { + return checkArrayVBOEnabled(false); + } + + public boolean glIsVBOElementEnabled() { + return checkElementVBOEnabled(false); + } + + public final boolean isGL() { + return true; + } + + public final GL getGL() throws GLException { + return this; + } + + public boolean isFunctionAvailable(String glFunctionName) { + return _context.isFunctionAvailable(glFunctionName); + } + + public boolean isExtensionAvailable(String glExtensionName) { + return _context.isExtensionAvailable(glExtensionName); + } + + public Object getExtension(String extensionName) { + // At this point we don't expose any extensions using this mechanism + return null; + } + + /** Returns the context this GL object is associated with for better + error checking by DebugGL. */ + public GLContext getContext() { + return _context; + } + + private GLContextImpl _context; + + public void setSwapInterval(int interval) { + _context.setSwapInterval(interval); + } + + public int getSwapInterval() { + return _context.getSwapInterval(); + } + + public Object getPlatformGLExtensions() { + return _context.getPlatformGLExtensions(); + } + diff --git a/make/config/jogl/gl-impl-CustomJavaCode-desktop.java b/make/config/jogl/gl-impl-CustomJavaCode-desktop.java index 04ba39c3d..93a275269 100644 --- a/make/config/jogl/gl-impl-CustomJavaCode-desktop.java +++ b/make/config/jogl/gl-impl-CustomJavaCode-desktop.java @@ -1,79 +1,191 @@ -private int[] imageSizeTemp = new int[1]; - -/** Helper for more precise computation of number of bytes that will - be touched by a pixel pack or unpack operation. */ -private int imageSizeInBytes(int bytesPerElement, - int width, int height, int depth, boolean pack) { - int rowLength = 0; - int skipRows = 0; - int skipPixels = 0; - int alignment = 1; - int imageHeight = 0; - int skipImages = 0; - - if (pack) { - glGetIntegerv(GL_PACK_ROW_LENGTH, imageSizeTemp, 0); - rowLength = imageSizeTemp[0]; - glGetIntegerv(GL_PACK_SKIP_ROWS, imageSizeTemp, 0); - skipRows = imageSizeTemp[0]; - glGetIntegerv(GL_PACK_SKIP_PIXELS, imageSizeTemp, 0); - skipPixels = imageSizeTemp[0]; - glGetIntegerv(GL_PACK_ALIGNMENT, imageSizeTemp, 0); - alignment = imageSizeTemp[0]; - if (depth > 1) { - glGetIntegerv(GL_PACK_IMAGE_HEIGHT, imageSizeTemp, 0); - imageHeight = imageSizeTemp[0]; - glGetIntegerv(GL_PACK_SKIP_IMAGES, imageSizeTemp, 0); - skipImages = imageSizeTemp[0]; + private int[] imageSizeTemp = new int[1]; + + /** Helper for more precise computation of number of bytes that will + be touched by a pixel pack or unpack operation. */ + private int imageSizeInBytes(int bytesPerElement, + int width, int height, int depth, boolean pack) { + int rowLength = 0; + int skipRows = 0; + int skipPixels = 0; + int alignment = 1; + int imageHeight = 0; + int skipImages = 0; + + if (pack) { + glGetIntegerv(GL_PACK_ROW_LENGTH, imageSizeTemp, 0); + rowLength = imageSizeTemp[0]; + glGetIntegerv(GL_PACK_SKIP_ROWS, imageSizeTemp, 0); + skipRows = imageSizeTemp[0]; + glGetIntegerv(GL_PACK_SKIP_PIXELS, imageSizeTemp, 0); + skipPixels = imageSizeTemp[0]; + glGetIntegerv(GL_PACK_ALIGNMENT, imageSizeTemp, 0); + alignment = imageSizeTemp[0]; + if (depth > 1) { + glGetIntegerv(GL_PACK_IMAGE_HEIGHT, imageSizeTemp, 0); + imageHeight = imageSizeTemp[0]; + glGetIntegerv(GL_PACK_SKIP_IMAGES, imageSizeTemp, 0); + skipImages = imageSizeTemp[0]; + } + } else { + glGetIntegerv(GL_UNPACK_ROW_LENGTH, imageSizeTemp, 0); + rowLength = imageSizeTemp[0]; + glGetIntegerv(GL_UNPACK_SKIP_ROWS, imageSizeTemp, 0); + skipRows = imageSizeTemp[0]; + glGetIntegerv(GL_UNPACK_SKIP_PIXELS, imageSizeTemp, 0); + skipPixels = imageSizeTemp[0]; + glGetIntegerv(GL_UNPACK_ALIGNMENT, imageSizeTemp, 0); + alignment = imageSizeTemp[0]; + if (depth > 1) { + glGetIntegerv(GL_UNPACK_IMAGE_HEIGHT, imageSizeTemp, 0); + imageHeight = imageSizeTemp[0]; + glGetIntegerv(GL_UNPACK_SKIP_IMAGES, imageSizeTemp, 0); + skipImages = imageSizeTemp[0]; + } } - } else { - glGetIntegerv(GL_UNPACK_ROW_LENGTH, imageSizeTemp, 0); - rowLength = imageSizeTemp[0]; - glGetIntegerv(GL_UNPACK_SKIP_ROWS, imageSizeTemp, 0); - skipRows = imageSizeTemp[0]; - glGetIntegerv(GL_UNPACK_SKIP_PIXELS, imageSizeTemp, 0); - skipPixels = imageSizeTemp[0]; - glGetIntegerv(GL_UNPACK_ALIGNMENT, imageSizeTemp, 0); - alignment = imageSizeTemp[0]; - if (depth > 1) { - glGetIntegerv(GL_UNPACK_IMAGE_HEIGHT, imageSizeTemp, 0); - imageHeight = imageSizeTemp[0]; - glGetIntegerv(GL_UNPACK_SKIP_IMAGES, imageSizeTemp, 0); - skipImages = imageSizeTemp[0]; + // Try to deal somewhat correctly with potentially invalid values + width = Math.max(0, width ); + height = Math.max(1, height); // min 1D + depth = Math.max(1, depth ); // min 1 * imageSize + skipRows = Math.max(0, skipRows); + skipPixels = Math.max(0, skipPixels); + alignment = Math.max(1, alignment); + skipImages = Math.max(0, skipImages); + + imageHeight = ( imageHeight > 0 ) ? imageHeight : height; + rowLength = ( rowLength > 0 ) ? rowLength : width; + + int rowLengthInBytes = rowLength * bytesPerElement; + + if (alignment > 1) { + int padding = rowLengthInBytes % alignment; + if (padding > 0) { + rowLengthInBytes += alignment - padding; + } } + + /** + * skipPixels and skipRows is a static one time offset. + * + * skipImages and depth are in multiples of image size. + * + * rowlenght is the actual repeating offset + * to go from line n to line n+1 at the same x-axis position. + */ + return + ( skipImages + depth - 1 ) * imageHeight * rowLengthInBytes + // whole images + ( skipRows + height - 1 ) * rowLengthInBytes + // lines with padding + ( skipPixels + width ) * bytesPerElement; // last line + } + + public final boolean isGL4bc() { + return _context.isGL4bc(); + } + + public final boolean isGL4() { + return _context.isGL4(); + } + + public final boolean isGL3bc() { + return _context.isGL3bc(); + } + + public final boolean isGL3() { + return _context.isGL3(); } - // Try to deal somewhat correctly with potentially invalid values - width = Math.max(0, width ); - height = Math.max(1, height); // min 1D - depth = Math.max(1, depth ); // min 1 * imageSize - skipRows = Math.max(0, skipRows); - skipPixels = Math.max(0, skipPixels); - alignment = Math.max(1, alignment); - skipImages = Math.max(0, skipImages); - imageHeight = ( imageHeight > 0 ) ? imageHeight : height; - rowLength = ( rowLength > 0 ) ? rowLength : width; + public final boolean isGL2() { + return _context.isGL2(); + } + + public final boolean isGL2ES1() { + return _context.isGL2ES1(); + } - int rowLengthInBytes = rowLength * bytesPerElement; + public final boolean isGL2ES2() { + return _context.isGL2ES2(); + } - if (alignment > 1) { - int padding = rowLengthInBytes % alignment; - if (padding > 0) { - rowLengthInBytes += alignment - padding; + public final boolean isGL2GL3() { + return _context.isGL2GL3(); + } + + public final boolean hasGLSL() { + return _context.hasGLSL(); + } + + public final GL4bc getGL4bc() throws GLException { + if(!isGL4bc()) { + throw new GLException("Not a GL4bc implementation"); + } + return this; + } + + public final GL4 getGL4() throws GLException { + if(!isGL4bc()) { + throw new GLException("Not a GL4 implementation"); } + return this; } - /** - * skipPixels and skipRows is a static one time offset. - * - * skipImages and depth are in multiples of image size. - * - * rowlenght is the actual repeating offset - * to go from line n to line n+1 at the same x-axis position. - */ - return - ( skipImages + depth - 1 ) * imageHeight * rowLengthInBytes + // whole images - ( skipRows + height - 1 ) * rowLengthInBytes + // lines with padding - ( skipPixels + width ) * bytesPerElement; // last line -} + public final GL3bc getGL3bc() throws GLException { + if(!isGL3bc()) { + throw new GLException("Not a GL3bc implementation"); + } + return this; + } + + public final GL3 getGL3() throws GLException { + if(!isGL3()) { + throw new GLException("Not a GL3 implementation"); + } + return this; + } + + public final GL2 getGL2() throws GLException { + if(!isGL2()) { + throw new GLException("Not a GL2 implementation"); + } + return this; + } + + public final GL2ES1 getGL2ES1() throws GLException { + if(!isGL2ES1()) { + throw new GLException("Not a GL2ES1 implementation"); + } + return this; + } + + public final GL2ES2 getGL2ES2() throws GLException { + if(!isGL2ES2()) { + throw new GLException("Not a GL2ES2 implementation"); + } + return this; + } + + public final GL2GL3 getGL2GL3() throws GLException { + if(!isGL2GL3()) { + throw new GLException("Not a GL2GL3 implementation"); + } + return this; + } + + public final boolean isGLES1() { + return false; + } + + public final boolean isGLES2() { + return false; + } + + public final boolean isGLES() { + return false; + } + + public final GLES1 getGLES1() throws GLException { + throw new GLException("Not a GLES1 implementation"); + } + + public final GLES2 getGLES2() throws GLException { + throw new GLException("Not a GLES2 implementation"); + } diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gl2.java b/make/config/jogl/gl-impl-CustomJavaCode-gl2.java deleted file mode 100644 index 0658b8a01..000000000 --- a/make/config/jogl/gl-impl-CustomJavaCode-gl2.java +++ /dev/null @@ -1,514 +0,0 @@ -// Tracks glBegin/glEnd calls to determine whether it is legal to -// query Vertex Buffer Object state -private boolean inBeginEndPair; - -/* FIXME: refactor dependence on Java 2D / JOGL bridge - -// Tracks creation and destruction of server-side OpenGL objects when -// the Java2D/OpenGL pipeline is enabled and it is using frame buffer -// objects (FBOs) to do its rendering -private GLObjectTracker tracker; - -public void setObjectTracker(GLObjectTracker tracker) { - this.tracker = tracker; -} - -*/ - - -public GL2Impl(GLProfile glp, GLContextImpl context) { - this._context = context; - this.bufferSizeTracker = context.getBufferSizeTracker(); - this.bufferStateTracker = context.getBufferStateTracker(); - this.glStateTracker = context.getGLStateTracker(); - this.glProfile = glp; -} - -public final boolean isGL() { - return true; -} - -public final boolean isGL4bc() { - return false; -} - -public final boolean isGL4() { - return false; -} - -public final boolean isGL3bc() { - return false; -} - -public final boolean isGL3() { - return false; -} - -public final boolean isGL2() { - return true; -} - -public final boolean isGLES1() { - return false; -} - -public final boolean isGLES2() { - return false; -} - -public final boolean isGLES() { - return false; -} - -public final boolean isGL2ES1() { - return true; -} - -public final boolean isGL2ES2() { - return true; -} - -public final boolean isGL2GL3() { - return true; -} - -public final boolean hasGLSL() { - return true; -} - -public final GL getGL() throws GLException { - return this; -} - -public final GL4bc getGL4bc() throws GLException { - throw new GLException("Not a GL4bc implementation"); -} - -public final GL4 getGL4() throws GLException { - throw new GLException("Not a GL4 implementation"); -} - -public final GL3bc getGL3bc() throws GLException { - throw new GLException("Not a GL3bc implementation"); -} - -public final GL3 getGL3() throws GLException { - throw new GLException("Not a GL3 implementation"); -} - -public final GL2 getGL2() throws GLException { - return this; -} - -public final GLES1 getGLES1() throws GLException { - throw new GLException("Not a GLES1 implementation"); -} - -public final GLES2 getGLES2() throws GLException { - throw new GLException("Not a GLES2 implementation"); -} - -public final GL2ES1 getGL2ES1() throws GLException { - return this; -} - -public final GL2ES2 getGL2ES2() throws GLException { - return this; -} - -public final GL2GL3 getGL2GL3() throws GLException { - return this; -} - -public boolean isFunctionAvailable(String glFunctionName) { - return _context.isFunctionAvailable(glFunctionName); -} - -public boolean isExtensionAvailable(String glExtensionName) { - return _context.isExtensionAvailable(glExtensionName); -} - -public Object getExtension(String extensionName) { - // At this point we don't expose any extensions using this mechanism - return null; -} - -/** Returns the context this GL object is associated with for better - error checking by DebugGL. */ -public GLContext getContext() { - return _context; -} - -private GLContextImpl _context; - -/** - * Provides platform-independent access to the wglAllocateMemoryNV / - * glXAllocateMemoryNV extension. - */ -public java.nio.ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { - return _context.glAllocateMemoryNV(arg0, arg1, arg2, arg3); -} - -public void setSwapInterval(int interval) { - _context.setSwapInterval(interval); -} - -public int getSwapInterval() { - return _context.getSwapInterval(); -} - -public Object getPlatformGLExtensions() { - return _context.getPlatformGLExtensions(); -} - -// -// Helpers for ensuring the correct amount of texture data -// - -/** Returns the number of bytes required to fill in the appropriate - texture. This is computed as closely as possible based on the - pixel pack or unpack parameters. The logic in this routine is - based on code in the SGI OpenGL sample implementation. */ - -private int imageSizeInBytes(int format, int type, int w, int h, int d, - boolean pack) { - int elements = 0; - int esize = 0; - - if (w < 0) return 0; - if (h < 0) return 0; - if (d < 0) return 0; - switch (format) { - case GL_COLOR_INDEX: - case GL_STENCIL_INDEX: - elements = 1; - break; - case GL_RED: - case GL_GREEN: - case GL_BLUE: - case GL_ALPHA: - case GL_LUMINANCE: - case GL_DEPTH_COMPONENT: - elements = 1; - break; - case GL_LUMINANCE_ALPHA: - elements = 2; - break; - case GL_RGB: - case GL_BGR: - elements = 3; - break; - case GL_RGBA: - case GL_BGRA: - case GL_ABGR_EXT: - elements = 4; - break; - /* FIXME ?? - case GL_HILO_NV: - elements = 2; - break; */ - default: - return 0; - } - switch (type) { - case GL_BITMAP: - if (format == GL_COLOR_INDEX) { - return (d * (h * ((w+7)/8))); - } else { - return 0; - } - case GL_BYTE: - case GL_UNSIGNED_BYTE: - esize = 1; - break; - case GL_UNSIGNED_BYTE_3_3_2: - case GL_UNSIGNED_BYTE_2_3_3_REV: - esize = 1; - elements = 1; - break; - case GL_SHORT: - case GL_UNSIGNED_SHORT: - esize = 2; - break; - case GL_UNSIGNED_SHORT_5_6_5: - case GL_UNSIGNED_SHORT_5_6_5_REV: - case GL_UNSIGNED_SHORT_4_4_4_4: - case GL_UNSIGNED_SHORT_4_4_4_4_REV: - case GL_UNSIGNED_SHORT_5_5_5_1: - case GL_UNSIGNED_SHORT_1_5_5_5_REV: - esize = 2; - elements = 1; - break; - case GL_INT: - case GL_UNSIGNED_INT: - case GL_FLOAT: - esize = 4; - break; - case GL_UNSIGNED_INT_8_8_8_8: - case GL_UNSIGNED_INT_8_8_8_8_REV: - case GL_UNSIGNED_INT_10_10_10_2: - case GL_UNSIGNED_INT_2_10_10_10_REV: - esize = 4; - elements = 1; - break; - default: - return 0; - } - return imageSizeInBytes(elements * esize, w, h, d, pack); -} - -private GLBufferSizeTracker bufferSizeTracker; -private GLBufferStateTracker bufferStateTracker; -private GLStateTracker glStateTracker; - -private boolean bufferObjectExtensionsInitialized = false; -private boolean haveARBPixelBufferObject; -private boolean haveEXTPixelBufferObject; -private boolean haveGL15; -private boolean haveGL21; -private boolean haveARBVertexBufferObject; - -private void initBufferObjectExtensionChecks() { - if (bufferObjectExtensionsInitialized) - return; - bufferObjectExtensionsInitialized = true; - haveARBPixelBufferObject = isExtensionAvailable("GL_ARB_pixel_buffer_object"); - haveEXTPixelBufferObject = isExtensionAvailable("GL_EXT_pixel_buffer_object"); - haveGL15 = isExtensionAvailable("GL_VERSION_1_5"); - haveGL21 = isExtensionAvailable("GL_VERSION_2_1"); - haveARBVertexBufferObject = isExtensionAvailable("GL_ARB_vertex_buffer_object"); -} - -private boolean checkBufferObject(boolean extension1, - boolean extension2, - boolean extension3, - boolean enabled, - int state, - String kind, boolean throwException) { - if (inBeginEndPair) { - throw new GLException("May not call this between glBegin and glEnd"); - } - boolean avail = (extension1 || extension2 || extension3); - if (!avail) { - if (!enabled) - return true; - if(throwException) { - throw new GLException("Required extensions not available to call this function"); - } - return false; - } - int buffer = bufferStateTracker.getBoundBufferObject(state, this); - if (enabled) { - if (buffer == 0) { - if(throwException) { - throw new GLException(kind + " must be enabled to call this method"); - } - return false; - } - } else { - if (buffer != 0) { - if(throwException) { - throw new GLException(kind + " must be disabled to call this method"); - } - return false; - } - } - return true; -} - -private boolean checkArrayVBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - false, - GL.GL_ARRAY_BUFFER, - "array vertex_buffer_object", throwException); -} - -private boolean checkArrayVBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - true, - GL.GL_ARRAY_BUFFER, - "array vertex_buffer_object", throwException); -} - -private boolean checkElementVBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - false, - GL.GL_ELEMENT_ARRAY_BUFFER, - "element vertex_buffer_object", throwException); -} - -private boolean checkElementVBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - true, - GL.GL_ELEMENT_ARRAY_BUFFER, - "element vertex_buffer_object", throwException); -} - -private boolean checkUnpackPBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - false, - GL2.GL_PIXEL_UNPACK_BUFFER, - "unpack pixel_buffer_object", throwException); -} - -private boolean checkUnpackPBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - true, - GL2.GL_PIXEL_UNPACK_BUFFER, - "unpack pixel_buffer_object", throwException); -} - -private boolean checkPackPBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - false, - GL2.GL_PIXEL_PACK_BUFFER, - "pack pixel_buffer_object", throwException); -} - -private boolean checkPackPBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - true, - GL2.GL_PIXEL_PACK_BUFFER, - "pack pixel_buffer_object", throwException); -} - -public boolean glIsPBOPackEnabled() { - return checkPackPBOEnabled(false); -} - -public boolean glIsPBOUnpackEnabled() { - return checkUnpackPBOEnabled(false); -} - -// Attempt to return the same ByteBuffer object from glMapBuffer if -// the vertex buffer object's base address and size haven't changed -private static class ARBVBOKey { - private long addr; - private int capacity; - - ARBVBOKey(long addr, int capacity) { - this.addr = addr; - this.capacity = capacity; - } - - public int hashCode() { - return (int) addr; - } - - public boolean equals(Object o) { - if ((o == null) || (!(o instanceof ARBVBOKey))) { - return false; - } - - ARBVBOKey other = (ARBVBOKey) o; - return ((addr == other.addr) && (capacity == other.capacity)); - } -} - -private Map/**/ arbVBOCache = new HashMap(); - -/** Entry point to C language function:
LPVOID glMapBuffer(GLenum target, GLenum access); */ -public java.nio.ByteBuffer glMapBuffer(int target, int access) { - final long __addr_ = ((GL2ProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer; - if (__addr_ == 0) { - throw new GLException("Method \"glMapBuffer\" not available"); - } - int sz = bufferSizeTracker.getBufferSize(bufferStateTracker, - target, - this); - long addr; - addr = dispatch_glMapBuffer(target, access, __addr_); - if (addr == 0 || sz == 0) { - return null; - } - ARBVBOKey key = new ARBVBOKey(addr, sz); - ByteBuffer _res = (ByteBuffer) arbVBOCache.get(key); - if (_res == null) { - _res = newDirectByteBuffer(addr, sz); - InternalBufferUtil.nativeOrder(_res); - arbVBOCache.put(key, _res); - } - _res.position(0); - return _res; -} - -/** Encapsulates function pointer for OpenGL function
: LPVOID glMapBuffer(GLenum target, GLenum access); */ -native private long dispatch_glMapBuffer(int target, int access, long glProcAddress); - -native private ByteBuffer newDirectByteBuffer(long addr, int capacity); - - /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ - public void glShaderBinary(int n, java.nio.IntBuffer shaders, int binaryformat, java.nio.Buffer binary, int length) { - throw new GLException("Method \"glShaderBinary\" not available"); - } - - /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ - public void glShaderBinary(int n, int[] shaders, int shaders_offset, int binaryformat, java.nio.Buffer binary, int length) { - throw new GLException("Method \"glShaderBinary\" not available"); - } - - public void glReleaseShaderCompiler() { - // nothing to do - } - - public void glVertexPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.isVBO()) { - glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); - } - } - public void glColorPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.isVBO()) { - glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); - } - - } - public void glNormalPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.getComponentNumber()!=3) { - throw new GLException("Only 3 components per normal allowed"); - } - if(array.isVBO()) { - glNormalPointer(array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glNormalPointer(array.getComponentType(), array.getStride(), array.getBuffer()); - } - } - public void glTexCoordPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.isVBO()) { - glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); - } - } - diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gl2es12.java b/make/config/jogl/gl-impl-CustomJavaCode-gl2es12.java deleted file mode 100644 index 54c7bd92b..000000000 --- a/make/config/jogl/gl-impl-CustomJavaCode-gl2es12.java +++ /dev/null @@ -1,455 +0,0 @@ -// Tracks glBegin/glEnd calls to determine whether it is legal to -// query Vertex Buffer Object state -private boolean inBeginEndPair; - -/* FIXME: refactor dependence on Java 2D / JOGL bridge - -// Tracks creation and destruction of server-side OpenGL objects when -// the Java2D/OpenGL pipeline is enabled and it is using frame buffer -// objects (FBOs) to do its rendering -private GLObjectTracker tracker; - -public void setObjectTracker(GLObjectTracker tracker) { - this.tracker = tracker; -} - -*/ - -public GL2ES12Impl(GLProfile glp, GLContextImpl context) { - this._context = context; - this.bufferSizeTracker = context.getBufferSizeTracker(); - this.bufferStateTracker = context.getBufferStateTracker(); - this.glStateTracker = context.getGLStateTracker(); - this.isGL2ES2 = glp.isGL2ES2(); - this.glProfile = glp; -} - -private boolean isGL2ES2; - -public final boolean isGL() { - return true; -} - -public final boolean isGL4bc() { - return false; -} - -public final boolean isGL4() { - return false; -} - -public final boolean isGL3bc() { - return false; -} - -public final boolean isGL3() { - return false; -} - -public final boolean isGL2() { - return false; -} - -public final boolean isGLES1() { - return false; -} - -public final boolean isGLES2() { - return false; -} - -public final boolean isGLES() { - return false; -} - -public final boolean isGL2ES1() { - return !isGL2ES2; -} - -public final boolean isGL2ES2() { - return isGL2ES2; -} - -public final boolean isGL2GL3() { - return false; -} - -public final boolean hasGLSL() { - return isGL2ES2; -} - -public final GL getGL() throws GLException { - return this; -} - -public final GL4bc getGL4bc() throws GLException { - throw new GLException("Not a GL4bc implementation"); -} - -public final GL4 getGL4() throws GLException { - throw new GLException("Not a GL4 implementation"); -} - -public final GL3bc getGL3bc() throws GLException { - throw new GLException("Not a GL3bc implementation"); -} - -public final GL3 getGL3() throws GLException { - throw new GLException("Not a GL3 implementation"); -} - -public final GL2 getGL2() throws GLException { - throw new GLException("Not a GL2 implementation"); -} - -public final GLES1 getGLES1() throws GLException { - throw new GLException("Not a GLES1 implementation"); -} - -public final GLES2 getGLES2() throws GLException { - throw new GLException("Not a GLES2 implementation"); -} - -public final GL2ES1 getGL2ES1() throws GLException { - if (isGL2ES1()) { - return this; - } - throw new GLException("Not a GL2ES1 implementation"); -} - -public final GL2ES2 getGL2ES2() throws GLException { - if (isGL2ES2()) { - return this; - } - throw new GLException("Not a GL2ES2 implementation"); -} - -public final GL2GL3 getGL2GL3() throws GLException { - throw new GLException("Not a GL2GL3 implementation"); -} - -public boolean isFunctionAvailable(String glFunctionName) { - return _context.isFunctionAvailable(glFunctionName); -} - -public boolean isExtensionAvailable(String glExtensionName) { - return _context.isExtensionAvailable(glExtensionName); -} - -public Object getExtension(String extensionName) { - // At this point we don't expose any extensions using this mechanism - return null; -} - -/** Returns the context this GL object is associated with for better - error checking by DebugGL. */ -public GLContext getContext() { - return _context; -} - -private GLContextImpl _context; - -public void setSwapInterval(int interval) { - _context.setSwapInterval(interval); -} - -public int getSwapInterval() { - return _context.getSwapInterval(); -} - -public Object getPlatformGLExtensions() { - return _context.getPlatformGLExtensions(); -} - -// -// Helpers for ensuring the correct amount of texture data -// - -/** Returns the number of bytes required to fill in the appropriate - texture. This is computed as closely as possible based on the - pixel pack or unpack parameters. The logic in this routine is - based on code in the SGI OpenGL sample implementation. */ - -private int imageSizeInBytes(int format, int type, int w, int h, int d, - boolean pack) { - int elements = 0; - int esize = 0; - - if (w < 0) return 0; - if (h < 0) return 0; - if (d < 0) return 0; - switch (format) { - case GL_STENCIL_INDEX: - elements = 1; - break; - case GL_ALPHA: - case GL_LUMINANCE: - case GL_DEPTH_COMPONENT: - elements = 1; - break; - case GL_LUMINANCE_ALPHA: - elements = 2; - break; - case GL_RGB: - elements = 3; - break; - case GL_RGBA: - elements = 4; - break; - /* FIXME ?? - case GL_HILO_NV: - elements = 2; - break; */ - default: - return 0; - } - switch (type) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - esize = 1; - break; - case GL_SHORT: - case GL_UNSIGNED_SHORT: - esize = 2; - break; - case GL_UNSIGNED_SHORT_5_6_5: - case GL_UNSIGNED_SHORT_4_4_4_4: - case GL_UNSIGNED_SHORT_5_5_5_1: - esize = 2; - elements = 1; - break; - case GL_INT: - case GL_UNSIGNED_INT: - case GL_FLOAT: - esize = 4; - break; - default: - return 0; - } - return imageSizeInBytes(elements * esize, w, h, d, pack); -} - -private GLBufferSizeTracker bufferSizeTracker; -private GLBufferStateTracker bufferStateTracker; -private GLStateTracker glStateTracker; - -private boolean bufferObjectExtensionsInitialized = false; -private boolean haveGL15; -private boolean haveGL21; -private boolean haveARBVertexBufferObject; - -private void initBufferObjectExtensionChecks() { - if (bufferObjectExtensionsInitialized) - return; - bufferObjectExtensionsInitialized = true; - haveGL15 = isExtensionAvailable("GL_VERSION_1_5"); - haveGL21 = isExtensionAvailable("GL_VERSION_2_1"); - haveARBVertexBufferObject = isExtensionAvailable("GL_ARB_vertex_buffer_object"); -} - -private boolean checkBufferObject(boolean extension1, - boolean extension2, - boolean extension3, - boolean enabled, - int state, - String kind, boolean throwException) { - if (inBeginEndPair) { - throw new GLException("May not call this between glBegin and glEnd"); - } - boolean avail = (extension1 || extension2 || extension3); - if (!avail) { - if (!enabled) - return true; - if(throwException) { - throw new GLException("Required extensions not available to call this function"); - } - return false; - } - int buffer = bufferStateTracker.getBoundBufferObject(state, this); - if (enabled) { - if (buffer == 0) { - if(throwException) { - throw new GLException(kind + " must be enabled to call this method"); - } - return false; - } - } else { - if (buffer != 0) { - if(throwException) { - throw new GLException(kind + " must be disabled to call this method"); - } - return false; - } - } - return true; -} - -private boolean checkArrayVBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - false, - GL.GL_ARRAY_BUFFER, - "array vertex_buffer_object", throwException); -} - -private boolean checkArrayVBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - true, - GL.GL_ARRAY_BUFFER, - "array vertex_buffer_object", throwException); -} - -private boolean checkElementVBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - false, - GL.GL_ELEMENT_ARRAY_BUFFER, - "element vertex_buffer_object", throwException); -} - -private boolean checkElementVBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - true, - GL.GL_ELEMENT_ARRAY_BUFFER, - "element vertex_buffer_object", throwException); -} - -private boolean checkUnpackPBODisabled(boolean throwException) { - // PBO n/a for ES 1.1 or ES 2.0 - return true; -} - -private boolean checkUnpackPBOEnabled(boolean throwException) { - // PBO n/a for ES 1.1 or ES 2.0 - return false; -} - -private boolean checkPackPBODisabled(boolean throwException) { - // PBO n/a for ES 1.1 or ES 2.0 - return true; -} - -private boolean checkPackPBOEnabled(boolean throwException) { - // PBO n/a for ES 1.1 or ES 2.0 - return false; -} - -// Attempt to return the same ByteBuffer object from glMapBuffer if -// the vertex buffer object's base address and size haven't changed -private static class ARBVBOKey { - private long addr; - private int capacity; - - ARBVBOKey(long addr, int capacity) { - this.addr = addr; - this.capacity = capacity; - } - - public int hashCode() { - return (int) addr; - } - - public boolean equals(Object o) { - if ((o == null) || (!(o instanceof ARBVBOKey))) { - return false; - } - - ARBVBOKey other = (ARBVBOKey) o; - return ((addr == other.addr) && (capacity == other.capacity)); - } -} - -private Map/**/ arbVBOCache = new HashMap(); - -/** Entry point to C language function:
LPVOID glMapBuffer(GLenum target, GLenum access); */ -public java.nio.ByteBuffer glMapBuffer(int target, int access) { - final long __addr_ = ((GL2ES12ProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer; - if (__addr_ == 0) { - throw new GLException("Method \"glMapBuffer\" not available"); - } - int sz = bufferSizeTracker.getBufferSize(bufferStateTracker, - target, - this); - long addr; - addr = dispatch_glMapBuffer(target, access, __addr_); - if (addr == 0 || sz == 0) { - return null; - } - ARBVBOKey key = new ARBVBOKey(addr, sz); - ByteBuffer _res = (ByteBuffer) arbVBOCache.get(key); - if (_res == null) { - _res = newDirectByteBuffer(addr, sz); - InternalBufferUtil.nativeOrder(_res); - arbVBOCache.put(key, _res); - } - _res.position(0); - return _res; -} - -/** Encapsulates function pointer for OpenGL function
: LPVOID glMapBuffer(GLenum target, GLenum access); */ -native private long dispatch_glMapBuffer(int target, int access, long glProcAddress); - -native private ByteBuffer newDirectByteBuffer(long addr, int capacity); - - /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ - public void glShaderBinary(int n, java.nio.IntBuffer shaders, int binaryformat, java.nio.Buffer binary, int length) { - throw new GLException("Method \"glShaderBinary\" not available"); - } - - /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ - public void glShaderBinary(int n, int[] shaders, int shaders_offset, int binaryformat, java.nio.Buffer binary, int length) { - throw new GLException("Method \"glShaderBinary\" not available"); - } - - public void glReleaseShaderCompiler() { - // nothing to do - } - - public void glVertexPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.isVBO()) { - glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); - } - } - public void glColorPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.isVBO()) { - glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); - } - - } - public void glNormalPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.getComponentNumber()!=3) { - throw new GLException("Only 3 components per normal allowed"); - } - if(array.isVBO()) { - glNormalPointer(array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glNormalPointer(array.getComponentType(), array.getStride(), array.getBuffer()); - } - } - public void glTexCoordPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.isVBO()) { - glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); - } - } - - diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gl3.java b/make/config/jogl/gl-impl-CustomJavaCode-gl3.java deleted file mode 100644 index cff0b0f94..000000000 --- a/make/config/jogl/gl-impl-CustomJavaCode-gl3.java +++ /dev/null @@ -1,468 +0,0 @@ -// Tracks glBegin/glEnd calls to determine whether it is legal to -// query Vertex Buffer Object state -private boolean inBeginEndPair; - -/* FIXME: refactor dependence on Java 2D / JOGL bridge - -// Tracks creation and destruction of server-side OpenGL objects when -// the Java2D/OpenGL pipeline is enabled and it is using frame buffer -// objects (FBOs) to do its rendering -private GLObjectTracker tracker; - -public void setObjectTracker(GLObjectTracker tracker) { - this.tracker = tracker; -} - -*/ - -public GL3Impl(GLProfile glp, GLContextImpl context) { - this._context = context; - this.bufferSizeTracker = context.getBufferSizeTracker(); - this.bufferStateTracker = context.getBufferStateTracker(); - this.glStateTracker = context.getGLStateTracker(); - this.glProfile = glp; -} - -public final boolean isGL() { - return true; -} - -public final boolean isGL4bc() { - return false; -} - -public final boolean isGL4() { - return false; -} - -public final boolean isGL3bc() { - return false; -} - -public final boolean isGL3() { - return true; -} - -public final boolean isGL2() { - return false; -} - -public final boolean isGLES1() { - return false; -} - -public final boolean isGLES2() { - return false; -} - -public final boolean isGLES() { - return false; -} - -public final boolean isGL2ES1() { - return false; -} - -public final boolean isGL2ES2() { - return true; -} - -public final boolean isGL2GL3() { - return true; -} - -public final boolean hasGLSL() { - return true; -} - -public final GL getGL() throws GLException { - return this; -} - -public final GL4bc getGL4bc() throws GLException { - throw new GLException("Not a GL4bc implementation"); -} - -public final GL4 getGL4() throws GLException { - throw new GLException("Not a GL4 implementation"); -} - -public final GL3bc getGL3bc() throws GLException { - throw new GLException("Not a GL3bc implementation"); -} - -public final GL3 getGL3() throws GLException { - return this; -} - -public final GL2 getGL2() throws GLException { - throw new GLException("Not a GL2 implementation"); -} - -public final GLES1 getGLES1() throws GLException { - throw new GLException("Not a GLES1 implementation"); -} - -public final GLES2 getGLES2() throws GLException { - throw new GLException("Not a GLES2 implementation"); -} - -public final GL2ES1 getGL2ES1() throws GLException { - throw new GLException("Not a GLES2ES1 implementation"); -} - -public final GL2ES2 getGL2ES2() throws GLException { - return this; -} - -public final GL2GL3 getGL2GL3() throws GLException { - return this; -} - -public boolean isFunctionAvailable(String glFunctionName) { - return _context.isFunctionAvailable(glFunctionName); -} - -public boolean isExtensionAvailable(String glExtensionName) { - return _context.isExtensionAvailable(glExtensionName); -} - -public Object getExtension(String extensionName) { - // At this point we don't expose any extensions using this mechanism - return null; -} - -/** Returns the context this GL object is associated with for better - error checking by DebugGL. */ -public GLContext getContext() { - return _context; -} - -private GLContextImpl _context; - -/** - * Provides platform-independent access to the wglAllocateMemoryNV / - * glXAllocateMemoryNV extension. - */ -public java.nio.ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { - return _context.glAllocateMemoryNV(arg0, arg1, arg2, arg3); -} - -public void setSwapInterval(int interval) { - _context.setSwapInterval(interval); -} - -public int getSwapInterval() { - return _context.getSwapInterval(); -} - -public Object getPlatformGLExtensions() { - return _context.getPlatformGLExtensions(); -} - -// -// Helpers for ensuring the correct amount of texture data -// - -/** Returns the number of bytes required to fill in the appropriate - texture. This is computed as closely as possible based on the - pixel pack or unpack parameters. The logic in this routine is - based on code in the SGI OpenGL sample implementation. */ - -private int imageSizeInBytes(int format, int type, int w, int h, int d, - boolean pack) { - int elements = 0; - int esize = 0; - - if (w < 0) return 0; - if (h < 0) return 0; - if (d < 0) return 0; - switch (format) { - case GL_STENCIL_INDEX: - elements = 1; - break; - case GL_RED: - case GL_GREEN: - case GL_BLUE: - case GL_ALPHA: - case GL_LUMINANCE: - case GL_DEPTH_COMPONENT: - elements = 1; - break; - case GL_LUMINANCE_ALPHA: - elements = 2; - break; - case GL_RGB: - case GL_BGR: - elements = 3; - break; - case GL_RGBA: - case GL_BGRA: - elements = 4; - break; - /* FIXME ?? - case GL_HILO_NV: - elements = 2; - break; */ - default: - return 0; - } - switch (type) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - esize = 1; - break; - case GL_UNSIGNED_BYTE_3_3_2: - case GL_UNSIGNED_BYTE_2_3_3_REV: - esize = 1; - elements = 1; - break; - case GL_SHORT: - case GL_UNSIGNED_SHORT: - esize = 2; - break; - case GL_UNSIGNED_SHORT_5_6_5: - case GL_UNSIGNED_SHORT_5_6_5_REV: - case GL_UNSIGNED_SHORT_4_4_4_4: - case GL_UNSIGNED_SHORT_4_4_4_4_REV: - case GL_UNSIGNED_SHORT_5_5_5_1: - case GL_UNSIGNED_SHORT_1_5_5_5_REV: - esize = 2; - elements = 1; - break; - case GL_INT: - case GL_UNSIGNED_INT: - case GL_FLOAT: - esize = 4; - break; - case GL_UNSIGNED_INT_8_8_8_8: - case GL_UNSIGNED_INT_8_8_8_8_REV: - case GL_UNSIGNED_INT_10_10_10_2: - case GL_UNSIGNED_INT_2_10_10_10_REV: - esize = 4; - elements = 1; - break; - default: - return 0; - } - return imageSizeInBytes(elements * esize, w, h, d, pack); -} - -private GLBufferSizeTracker bufferSizeTracker; -private GLBufferStateTracker bufferStateTracker; -private GLStateTracker glStateTracker; - -private boolean bufferObjectExtensionsInitialized = false; -private boolean haveARBPixelBufferObject; -private boolean haveEXTPixelBufferObject; -private boolean haveGL15; -private boolean haveGL21; -private boolean haveARBVertexBufferObject; - -private void initBufferObjectExtensionChecks() { - if (bufferObjectExtensionsInitialized) - return; - bufferObjectExtensionsInitialized = true; - haveARBPixelBufferObject = isExtensionAvailable("GL_ARB_pixel_buffer_object"); - haveEXTPixelBufferObject = isExtensionAvailable("GL_EXT_pixel_buffer_object"); - haveGL15 = isExtensionAvailable("GL_VERSION_1_5"); - haveGL21 = isExtensionAvailable("GL_VERSION_2_1"); - haveARBVertexBufferObject = isExtensionAvailable("GL_ARB_vertex_buffer_object"); -} - -private boolean checkBufferObject(boolean extension1, - boolean extension2, - boolean extension3, - boolean enabled, - int state, - String kind, boolean throwException) { - if (inBeginEndPair) { - throw new GLException("May not call this between glBegin and glEnd"); - } - boolean avail = (extension1 || extension2 || extension3); - if (!avail) { - if (!enabled) - return true; - if(throwException) { - throw new GLException("Required extensions not available to call this function"); - } - return false; - } - int buffer = bufferStateTracker.getBoundBufferObject(state, this); - if (enabled) { - if (buffer == 0) { - if(throwException) { - throw new GLException(kind + " must be enabled to call this method"); - } - return false; - } - } else { - if (buffer != 0) { - if(throwException) { - throw new GLException(kind + " must be disabled to call this method"); - } - return false; - } - } - return true; -} - -private boolean checkArrayVBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - false, - GL.GL_ARRAY_BUFFER, - "array vertex_buffer_object", throwException); -} - -private boolean checkArrayVBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - true, - GL.GL_ARRAY_BUFFER, - "array vertex_buffer_object", throwException); -} - -private boolean checkElementVBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - false, - GL.GL_ELEMENT_ARRAY_BUFFER, - "element vertex_buffer_object", throwException); -} - -private boolean checkElementVBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - true, - GL.GL_ELEMENT_ARRAY_BUFFER, - "element vertex_buffer_object", throwException); -} - -private boolean checkUnpackPBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - false, - GL2.GL_PIXEL_UNPACK_BUFFER, - "unpack pixel_buffer_object", throwException); -} - -private boolean checkUnpackPBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - true, - GL2.GL_PIXEL_UNPACK_BUFFER, - "unpack pixel_buffer_object", throwException); -} - -private boolean checkPackPBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - false, - GL2.GL_PIXEL_PACK_BUFFER, - "pack pixel_buffer_object", throwException); -} - -private boolean checkPackPBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - true, - GL2.GL_PIXEL_PACK_BUFFER, - "pack pixel_buffer_object", throwException); -} - -public boolean glIsPBOPackEnabled() { - return checkPackPBOEnabled(false); -} - -public boolean glIsPBOUnpackEnabled() { - return checkUnpackPBOEnabled(false); -} - -// Attempt to return the same ByteBuffer object from glMapBuffer if -// the vertex buffer object's base address and size haven't changed -private static class ARBVBOKey { - private long addr; - private int capacity; - - ARBVBOKey(long addr, int capacity) { - this.addr = addr; - this.capacity = capacity; - } - - public int hashCode() { - return (int) addr; - } - - public boolean equals(Object o) { - if ((o == null) || (!(o instanceof ARBVBOKey))) { - return false; - } - - ARBVBOKey other = (ARBVBOKey) o; - return ((addr == other.addr) && (capacity == other.capacity)); - } -} - -private Map/**/ arbVBOCache = new HashMap(); - -/** Entry point to C language function:
LPVOID glMapBuffer(GLenum target, GLenum access); */ -public java.nio.ByteBuffer glMapBuffer(int target, int access) { - final long __addr_ = ((GL3ProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer; - if (__addr_ == 0) { - throw new GLException("Method \"glMapBuffer\" not available"); - } - int sz = bufferSizeTracker.getBufferSize(bufferStateTracker, - target, - this); - long addr; - addr = dispatch_glMapBuffer(target, access, __addr_); - if (addr == 0 || sz == 0) { - return null; - } - ARBVBOKey key = new ARBVBOKey(addr, sz); - ByteBuffer _res = (ByteBuffer) arbVBOCache.get(key); - if (_res == null) { - _res = newDirectByteBuffer(addr, sz); - InternalBufferUtil.nativeOrder(_res); - arbVBOCache.put(key, _res); - } - _res.position(0); - return _res; -} - -/** Encapsulates function pointer for OpenGL function
: LPVOID glMapBuffer(GLenum target, GLenum access); */ -native private long dispatch_glMapBuffer(int target, int access, long glProcAddress); - -native private ByteBuffer newDirectByteBuffer(long addr, int capacity); - - /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ - public void glShaderBinary(int n, java.nio.IntBuffer shaders, int binaryformat, java.nio.Buffer binary, int length) { - throw new GLException("Method \"glShaderBinary\" not available"); - } - - /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ - public void glShaderBinary(int n, int[] shaders, int shaders_offset, int binaryformat, java.nio.Buffer binary, int length) { - throw new GLException("Method \"glShaderBinary\" not available"); - } - - public void glReleaseShaderCompiler() { - // nothing to do - } - diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gl3bc.java b/make/config/jogl/gl-impl-CustomJavaCode-gl3bc.java deleted file mode 100644 index 2f804a218..000000000 --- a/make/config/jogl/gl-impl-CustomJavaCode-gl3bc.java +++ /dev/null @@ -1,514 +0,0 @@ -// Tracks glBegin/glEnd calls to determine whether it is legal to -// query Vertex Buffer Object state -private boolean inBeginEndPair; - -/* FIXME: refactor dependence on Java 2D / JOGL bridge - -// Tracks creation and destruction of server-side OpenGL objects when -// the Java2D/OpenGL pipeline is enabled and it is using frame buffer -// objects (FBOs) to do its rendering -private GLObjectTracker tracker; - -public void setObjectTracker(GLObjectTracker tracker) { - this.tracker = tracker; -} - -*/ - - -public GL3bcImpl(GLProfile glp, GLContextImpl context) { - this._context = context; - this.bufferSizeTracker = context.getBufferSizeTracker(); - this.bufferStateTracker = context.getBufferStateTracker(); - this.glStateTracker = context.getGLStateTracker(); - this.glProfile = glp; -} - -public final boolean isGL() { - return true; -} - -public final boolean isGL4bc() { - return false; -} - -public final boolean isGL4() { - return false; -} - -public final boolean isGL3bc() { - return true; -} - -public final boolean isGL3() { - return true; -} - -public final boolean isGL2() { - return true; -} - -public final boolean isGLES1() { - return false; -} - -public final boolean isGLES2() { - return false; -} - -public final boolean isGLES() { - return false; -} - -public final boolean isGL2ES1() { - return true; -} - -public final boolean isGL2ES2() { - return true; -} - -public final boolean isGL2GL3() { - return true; -} - -public final boolean hasGLSL() { - return true; -} - -public final GL getGL() throws GLException { - return this; -} - -public final GL4bc getGL4bc() throws GLException { - throw new GLException("Not a GL4bc implementation"); -} - -public final GL4 getGL4() throws GLException { - throw new GLException("Not a GL4 implementation"); -} - -public final GL3bc getGL3bc() throws GLException { - return this; -} - -public final GL3 getGL3() throws GLException { - return this; -} - -public final GL2 getGL2() throws GLException { - return this; -} - -public final GLES1 getGLES1() throws GLException { - throw new GLException("Not a GLES1 implementation"); -} - -public final GLES2 getGLES2() throws GLException { - throw new GLException("Not a GLES2 implementation"); -} - -public final GL2ES1 getGL2ES1() throws GLException { - return this; -} - -public final GL2ES2 getGL2ES2() throws GLException { - return this; -} - -public final GL2GL3 getGL2GL3() throws GLException { - return this; -} - -public boolean isFunctionAvailable(String glFunctionName) { - return _context.isFunctionAvailable(glFunctionName); -} - -public boolean isExtensionAvailable(String glExtensionName) { - return _context.isExtensionAvailable(glExtensionName); -} - -public Object getExtension(String extensionName) { - // At this point we don't expose any extensions using this mechanism - return null; -} - -/** Returns the context this GL object is associated with for better - error checking by DebugGL. */ -public GLContext getContext() { - return _context; -} - -private GLContextImpl _context; - -/** - * Provides platform-independent access to the wglAllocateMemoryNV / - * glXAllocateMemoryNV extension. - */ -public java.nio.ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { - return _context.glAllocateMemoryNV(arg0, arg1, arg2, arg3); -} - -public void setSwapInterval(int interval) { - _context.setSwapInterval(interval); -} - -public int getSwapInterval() { - return _context.getSwapInterval(); -} - -public Object getPlatformGLExtensions() { - return _context.getPlatformGLExtensions(); -} - -// -// Helpers for ensuring the correct amount of texture data -// - -/** Returns the number of bytes required to fill in the appropriate - texture. This is computed as closely as possible based on the - pixel pack or unpack parameters. The logic in this routine is - based on code in the SGI OpenGL sample implementation. */ - -private int imageSizeInBytes(int format, int type, int w, int h, int d, - boolean pack) { - int elements = 0; - int esize = 0; - - if (w < 0) return 0; - if (h < 0) return 0; - if (d < 0) return 0; - switch (format) { - case GL_COLOR_INDEX: - case GL_STENCIL_INDEX: - elements = 1; - break; - case GL_RED: - case GL_GREEN: - case GL_BLUE: - case GL_ALPHA: - case GL_LUMINANCE: - case GL_DEPTH_COMPONENT: - elements = 1; - break; - case GL_LUMINANCE_ALPHA: - elements = 2; - break; - case GL_RGB: - case GL_BGR: - elements = 3; - break; - case GL_RGBA: - case GL_BGRA: - case GL_ABGR_EXT: - elements = 4; - break; - /* FIXME ?? - case GL_HILO_NV: - elements = 2; - break; */ - default: - return 0; - } - switch (type) { - case GL_BITMAP: - if (format == GL_COLOR_INDEX) { - return (d * (h * ((w+7)/8))); - } else { - return 0; - } - case GL_BYTE: - case GL_UNSIGNED_BYTE: - esize = 1; - break; - case GL_UNSIGNED_BYTE_3_3_2: - case GL_UNSIGNED_BYTE_2_3_3_REV: - esize = 1; - elements = 1; - break; - case GL_SHORT: - case GL_UNSIGNED_SHORT: - esize = 2; - break; - case GL_UNSIGNED_SHORT_5_6_5: - case GL_UNSIGNED_SHORT_5_6_5_REV: - case GL_UNSIGNED_SHORT_4_4_4_4: - case GL_UNSIGNED_SHORT_4_4_4_4_REV: - case GL_UNSIGNED_SHORT_5_5_5_1: - case GL_UNSIGNED_SHORT_1_5_5_5_REV: - esize = 2; - elements = 1; - break; - case GL_INT: - case GL_UNSIGNED_INT: - case GL_FLOAT: - esize = 4; - break; - case GL_UNSIGNED_INT_8_8_8_8: - case GL_UNSIGNED_INT_8_8_8_8_REV: - case GL_UNSIGNED_INT_10_10_10_2: - case GL_UNSIGNED_INT_2_10_10_10_REV: - esize = 4; - elements = 1; - break; - default: - return 0; - } - return imageSizeInBytes(elements * esize, w, h, d, pack); -} - -private GLBufferSizeTracker bufferSizeTracker; -private GLBufferStateTracker bufferStateTracker; -private GLStateTracker glStateTracker; - -private boolean bufferObjectExtensionsInitialized = false; -private boolean haveARBPixelBufferObject; -private boolean haveEXTPixelBufferObject; -private boolean haveGL15; -private boolean haveGL21; -private boolean haveARBVertexBufferObject; - -private void initBufferObjectExtensionChecks() { - if (bufferObjectExtensionsInitialized) - return; - bufferObjectExtensionsInitialized = true; - haveARBPixelBufferObject = isExtensionAvailable("GL_ARB_pixel_buffer_object"); - haveEXTPixelBufferObject = isExtensionAvailable("GL_EXT_pixel_buffer_object"); - haveGL15 = isExtensionAvailable("GL_VERSION_1_5"); - haveGL21 = isExtensionAvailable("GL_VERSION_2_1"); - haveARBVertexBufferObject = isExtensionAvailable("GL_ARB_vertex_buffer_object"); -} - -private boolean checkBufferObject(boolean extension1, - boolean extension2, - boolean extension3, - boolean enabled, - int state, - String kind, boolean throwException) { - if (inBeginEndPair) { - throw new GLException("May not call this between glBegin and glEnd"); - } - boolean avail = (extension1 || extension2 || extension3); - if (!avail) { - if (!enabled) - return true; - if(throwException) { - throw new GLException("Required extensions not available to call this function"); - } - return false; - } - int buffer = bufferStateTracker.getBoundBufferObject(state, this); - if (enabled) { - if (buffer == 0) { - if(throwException) { - throw new GLException(kind + " must be enabled to call this method"); - } - return false; - } - } else { - if (buffer != 0) { - if(throwException) { - throw new GLException(kind + " must be disabled to call this method"); - } - return false; - } - } - return true; -} - -private boolean checkArrayVBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - false, - GL.GL_ARRAY_BUFFER, - "array vertex_buffer_object", throwException); -} - -private boolean checkArrayVBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - true, - GL.GL_ARRAY_BUFFER, - "array vertex_buffer_object", throwException); -} - -private boolean checkElementVBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - false, - GL.GL_ELEMENT_ARRAY_BUFFER, - "element vertex_buffer_object", throwException); -} - -private boolean checkElementVBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveGL15, - haveARBVertexBufferObject, - false, - true, - GL.GL_ELEMENT_ARRAY_BUFFER, - "element vertex_buffer_object", throwException); -} - -private boolean checkUnpackPBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - false, - GL2.GL_PIXEL_UNPACK_BUFFER, - "unpack pixel_buffer_object", throwException); -} - -private boolean checkUnpackPBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - true, - GL2.GL_PIXEL_UNPACK_BUFFER, - "unpack pixel_buffer_object", throwException); -} - -private boolean checkPackPBODisabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - false, - GL2.GL_PIXEL_PACK_BUFFER, - "pack pixel_buffer_object", throwException); -} - -private boolean checkPackPBOEnabled(boolean throwException) { - initBufferObjectExtensionChecks(); - return checkBufferObject(haveARBPixelBufferObject, - haveEXTPixelBufferObject, - haveGL21, - true, - GL2.GL_PIXEL_PACK_BUFFER, - "pack pixel_buffer_object", throwException); -} - -public boolean glIsPBOPackEnabled() { - return checkPackPBOEnabled(false); -} - -public boolean glIsPBOUnpackEnabled() { - return checkUnpackPBOEnabled(false); -} - -// Attempt to return the same ByteBuffer object from glMapBuffer if -// the vertex buffer object's base address and size haven't changed -private static class ARBVBOKey { - private long addr; - private int capacity; - - ARBVBOKey(long addr, int capacity) { - this.addr = addr; - this.capacity = capacity; - } - - public int hashCode() { - return (int) addr; - } - - public boolean equals(Object o) { - if ((o == null) || (!(o instanceof ARBVBOKey))) { - return false; - } - - ARBVBOKey other = (ARBVBOKey) o; - return ((addr == other.addr) && (capacity == other.capacity)); - } -} - -private Map/**/ arbVBOCache = new HashMap(); - -/** Entry point to C language function:
LPVOID glMapBuffer(GLenum target, GLenum access); */ -public java.nio.ByteBuffer glMapBuffer(int target, int access) { - final long __addr_ = ((GL3bcProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer; - if (__addr_ == 0) { - throw new GLException("Method \"glMapBuffer\" not available"); - } - int sz = bufferSizeTracker.getBufferSize(bufferStateTracker, - target, - this); - long addr; - addr = dispatch_glMapBuffer(target, access, __addr_); - if (addr == 0 || sz == 0) { - return null; - } - ARBVBOKey key = new ARBVBOKey(addr, sz); - ByteBuffer _res = (ByteBuffer) arbVBOCache.get(key); - if (_res == null) { - _res = newDirectByteBuffer(addr, sz); - InternalBufferUtil.nativeOrder(_res); - arbVBOCache.put(key, _res); - } - _res.position(0); - return _res; -} - -/** Encapsulates function pointer for OpenGL function
: LPVOID glMapBuffer(GLenum target, GLenum access); */ -native private long dispatch_glMapBuffer(int target, int access, long glProcAddress); - -native private ByteBuffer newDirectByteBuffer(long addr, int capacity); - - /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ - public void glShaderBinary(int n, java.nio.IntBuffer shaders, int binaryformat, java.nio.Buffer binary, int length) { - throw new GLException("Method \"glShaderBinary\" not available"); - } - - /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ - public void glShaderBinary(int n, int[] shaders, int shaders_offset, int binaryformat, java.nio.Buffer binary, int length) { - throw new GLException("Method \"glShaderBinary\" not available"); - } - - public void glReleaseShaderCompiler() { - // nothing to do - } - - public void glVertexPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.isVBO()) { - glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); - } - } - public void glColorPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.isVBO()) { - glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); - } - - } - public void glNormalPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.getComponentNumber()!=3) { - throw new GLException("Only 3 components per normal allowed"); - } - if(array.isVBO()) { - glNormalPointer(array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glNormalPointer(array.getComponentType(), array.getStride(), array.getBuffer()); - } - } - public void glTexCoordPointer(GLArrayData array) { - if(array.getComponentNumber()==0) return; - if(array.isVBO()) { - glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); - } else { - glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); - } - } - diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gl4.java b/make/config/jogl/gl-impl-CustomJavaCode-gl4.java new file mode 100644 index 000000000..a2c70eeee --- /dev/null +++ b/make/config/jogl/gl-impl-CustomJavaCode-gl4.java @@ -0,0 +1,339 @@ +// Tracks glBegin/glEnd calls to determine whether it is legal to +// query Vertex Buffer Object state +private boolean inBeginEndPair; + +/* FIXME: refactor dependence on Java 2D / JOGL bridge + +// Tracks creation and destruction of server-side OpenGL objects when +// the Java2D/OpenGL pipeline is enabled and it is using frame buffer +// objects (FBOs) to do its rendering +private GLObjectTracker tracker; + +public void setObjectTracker(GLObjectTracker tracker) { + this.tracker = tracker; +} + +*/ + +public GL3Impl(GLProfile glp, GLContextImpl context) { + this._context = context; + this.bufferSizeTracker = context.getBufferSizeTracker(); + this.bufferStateTracker = context.getBufferStateTracker(); + this.glStateTracker = context.getGLStateTracker(); + this.glProfile = glp; +} + +/** + * Provides platform-independent access to the wglAllocateMemoryNV / + * glXAllocateMemoryNV extension. + */ +public java.nio.ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { + return _context.glAllocateMemoryNV(arg0, arg1, arg2, arg3); +} + +// +// Helpers for ensuring the correct amount of texture data +// + +/** Returns the number of bytes required to fill in the appropriate + texture. This is computed as closely as possible based on the + pixel pack or unpack parameters. The logic in this routine is + based on code in the SGI OpenGL sample implementation. */ + +private int imageSizeInBytes(int format, int type, int w, int h, int d, + boolean pack) { + int elements = 0; + int esize = 0; + + if (w < 0) return 0; + if (h < 0) return 0; + if (d < 0) return 0; + switch (format) { + case GL_STENCIL_INDEX: + elements = 1; + break; + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: + case GL_LUMINANCE: + case GL_DEPTH_COMPONENT: + elements = 1; + break; + case GL_LUMINANCE_ALPHA: + elements = 2; + break; + case GL_RGB: + case GL_BGR: + elements = 3; + break; + case GL_RGBA: + case GL_BGRA: + elements = 4; + break; + /* FIXME ?? + case GL_HILO_NV: + elements = 2; + break; */ + default: + return 0; + } + switch (type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + esize = 1; + break; + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + esize = 1; + elements = 1; + break; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + esize = 2; + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + esize = 2; + elements = 1; + break; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + esize = 4; + break; + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + esize = 4; + elements = 1; + break; + default: + return 0; + } + return imageSizeInBytes(elements * esize, w, h, d, pack); +} + +private GLBufferSizeTracker bufferSizeTracker; +private GLBufferStateTracker bufferStateTracker; +private GLStateTracker glStateTracker; + +private boolean bufferObjectExtensionsInitialized = false; +private boolean haveARBPixelBufferObject; +private boolean haveEXTPixelBufferObject; +private boolean haveGL15; +private boolean haveGL21; +private boolean haveARBVertexBufferObject; + +private void initBufferObjectExtensionChecks() { + if (bufferObjectExtensionsInitialized) + return; + bufferObjectExtensionsInitialized = true; + haveARBPixelBufferObject = isExtensionAvailable("GL_ARB_pixel_buffer_object"); + haveEXTPixelBufferObject = isExtensionAvailable("GL_EXT_pixel_buffer_object"); + haveGL15 = isExtensionAvailable("GL_VERSION_1_5"); + haveGL21 = isExtensionAvailable("GL_VERSION_2_1"); + haveARBVertexBufferObject = isExtensionAvailable("GL_ARB_vertex_buffer_object"); +} + +private boolean checkBufferObject(boolean extension1, + boolean extension2, + boolean extension3, + boolean enabled, + int state, + String kind, boolean throwException) { + if (inBeginEndPair) { + throw new GLException("May not call this between glBegin and glEnd"); + } + boolean avail = (extension1 || extension2 || extension3); + if (!avail) { + if (!enabled) + return true; + if(throwException) { + throw new GLException("Required extensions not available to call this function"); + } + return false; + } + int buffer = bufferStateTracker.getBoundBufferObject(state, this); + if (enabled) { + if (buffer == 0) { + if(throwException) { + throw new GLException(kind + " must be enabled to call this method"); + } + return false; + } + } else { + if (buffer != 0) { + if(throwException) { + throw new GLException(kind + " must be disabled to call this method"); + } + return false; + } + } + return true; +} + +private boolean checkArrayVBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + false, + GL.GL_ARRAY_BUFFER, + "array vertex_buffer_object", throwException); +} + +private boolean checkArrayVBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + true, + GL.GL_ARRAY_BUFFER, + "array vertex_buffer_object", throwException); +} + +private boolean checkElementVBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + false, + GL.GL_ELEMENT_ARRAY_BUFFER, + "element vertex_buffer_object", throwException); +} + +private boolean checkElementVBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + true, + GL.GL_ELEMENT_ARRAY_BUFFER, + "element vertex_buffer_object", throwException); +} + +private boolean checkUnpackPBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + false, + GL2.GL_PIXEL_UNPACK_BUFFER, + "unpack pixel_buffer_object", throwException); +} + +private boolean checkUnpackPBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + true, + GL2.GL_PIXEL_UNPACK_BUFFER, + "unpack pixel_buffer_object", throwException); +} + +private boolean checkPackPBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + false, + GL2.GL_PIXEL_PACK_BUFFER, + "pack pixel_buffer_object", throwException); +} + +private boolean checkPackPBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + true, + GL2.GL_PIXEL_PACK_BUFFER, + "pack pixel_buffer_object", throwException); +} + +public boolean glIsPBOPackEnabled() { + return checkPackPBOEnabled(false); +} + +public boolean glIsPBOUnpackEnabled() { + return checkUnpackPBOEnabled(false); +} + +// Attempt to return the same ByteBuffer object from glMapBuffer if +// the vertex buffer object's base address and size haven't changed +private static class ARBVBOKey { + private long addr; + private int capacity; + + ARBVBOKey(long addr, int capacity) { + this.addr = addr; + this.capacity = capacity; + } + + public int hashCode() { + return (int) addr; + } + + public boolean equals(Object o) { + if ((o == null) || (!(o instanceof ARBVBOKey))) { + return false; + } + + ARBVBOKey other = (ARBVBOKey) o; + return ((addr == other.addr) && (capacity == other.capacity)); + } +} + +private Map/**/ arbVBOCache = new HashMap(); + +/** Entry point to C language function:
LPVOID glMapBuffer(GLenum target, GLenum access); */ +public java.nio.ByteBuffer glMapBuffer(int target, int access) { + final long __addr_ = ((GL3ProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer; + if (__addr_ == 0) { + throw new GLException("Method \"glMapBuffer\" not available"); + } + int sz = bufferSizeTracker.getBufferSize(bufferStateTracker, + target, + this); + long addr; + addr = dispatch_glMapBuffer(target, access, __addr_); + if (addr == 0 || sz == 0) { + return null; + } + ARBVBOKey key = new ARBVBOKey(addr, sz); + ByteBuffer _res = (ByteBuffer) arbVBOCache.get(key); + if (_res == null) { + _res = newDirectByteBuffer(addr, sz); + InternalBufferUtil.nativeOrder(_res); + arbVBOCache.put(key, _res); + } + _res.position(0); + return _res; +} + +/** Encapsulates function pointer for OpenGL function
: LPVOID glMapBuffer(GLenum target, GLenum access); */ +native private long dispatch_glMapBuffer(int target, int access, long glProcAddress); + +native private ByteBuffer newDirectByteBuffer(long addr, int capacity); + + /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ + public void glShaderBinary(int n, java.nio.IntBuffer shaders, int binaryformat, java.nio.Buffer binary, int length) { + throw new GLException("Method \"glShaderBinary\" not available"); + } + + /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ + public void glShaderBinary(int n, int[] shaders, int shaders_offset, int binaryformat, java.nio.Buffer binary, int length) { + throw new GLException("Method \"glShaderBinary\" not available"); + } + + public void glReleaseShaderCompiler() { + // nothing to do + } + diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java b/make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java new file mode 100644 index 000000000..bceb12fe5 --- /dev/null +++ b/make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java @@ -0,0 +1,385 @@ +// Tracks glBegin/glEnd calls to determine whether it is legal to +// query Vertex Buffer Object state +private boolean inBeginEndPair; + +/* FIXME: refactor dependence on Java 2D / JOGL bridge + +// Tracks creation and destruction of server-side OpenGL objects when +// the Java2D/OpenGL pipeline is enabled and it is using frame buffer +// objects (FBOs) to do its rendering +private GLObjectTracker tracker; + +public void setObjectTracker(GLObjectTracker tracker) { + this.tracker = tracker; +} + +*/ + + +public GL4bcImpl(GLProfile glp, GLContextImpl context) { + this._context = context; + this.bufferSizeTracker = context.getBufferSizeTracker(); + this.bufferStateTracker = context.getBufferStateTracker(); + this.glStateTracker = context.getGLStateTracker(); + this.glProfile = glp; +} + +/** + * Provides platform-independent access to the wglAllocateMemoryNV / + * glXAllocateMemoryNV extension. + */ +public java.nio.ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { + return _context.glAllocateMemoryNV(arg0, arg1, arg2, arg3); +} + +// +// Helpers for ensuring the correct amount of texture data +// + +/** Returns the number of bytes required to fill in the appropriate + texture. This is computed as closely as possible based on the + pixel pack or unpack parameters. The logic in this routine is + based on code in the SGI OpenGL sample implementation. */ + +private int imageSizeInBytes(int format, int type, int w, int h, int d, + boolean pack) { + int elements = 0; + int esize = 0; + + if (w < 0) return 0; + if (h < 0) return 0; + if (d < 0) return 0; + switch (format) { + case GL_COLOR_INDEX: + case GL_STENCIL_INDEX: + elements = 1; + break; + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: + case GL_LUMINANCE: + case GL_DEPTH_COMPONENT: + elements = 1; + break; + case GL_LUMINANCE_ALPHA: + elements = 2; + break; + case GL_RGB: + case GL_BGR: + elements = 3; + break; + case GL_RGBA: + case GL_BGRA: + case GL_ABGR_EXT: + elements = 4; + break; + /* FIXME ?? + case GL_HILO_NV: + elements = 2; + break; */ + default: + return 0; + } + switch (type) { + case GL_BITMAP: + if (format == GL_COLOR_INDEX) { + return (d * (h * ((w+7)/8))); + } else { + return 0; + } + case GL_BYTE: + case GL_UNSIGNED_BYTE: + esize = 1; + break; + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + esize = 1; + elements = 1; + break; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + esize = 2; + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + esize = 2; + elements = 1; + break; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + esize = 4; + break; + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + esize = 4; + elements = 1; + break; + default: + return 0; + } + return imageSizeInBytes(elements * esize, w, h, d, pack); +} + +private GLBufferSizeTracker bufferSizeTracker; +private GLBufferStateTracker bufferStateTracker; +private GLStateTracker glStateTracker; + +private boolean bufferObjectExtensionsInitialized = false; +private boolean haveARBPixelBufferObject; +private boolean haveEXTPixelBufferObject; +private boolean haveGL15; +private boolean haveGL21; +private boolean haveARBVertexBufferObject; + +private void initBufferObjectExtensionChecks() { + if (bufferObjectExtensionsInitialized) + return; + bufferObjectExtensionsInitialized = true; + haveARBPixelBufferObject = isExtensionAvailable("GL_ARB_pixel_buffer_object"); + haveEXTPixelBufferObject = isExtensionAvailable("GL_EXT_pixel_buffer_object"); + haveGL15 = isExtensionAvailable("GL_VERSION_1_5"); + haveGL21 = isExtensionAvailable("GL_VERSION_2_1"); + haveARBVertexBufferObject = isExtensionAvailable("GL_ARB_vertex_buffer_object"); +} + +private boolean checkBufferObject(boolean extension1, + boolean extension2, + boolean extension3, + boolean enabled, + int state, + String kind, boolean throwException) { + if (inBeginEndPair) { + throw new GLException("May not call this between glBegin and glEnd"); + } + boolean avail = (extension1 || extension2 || extension3); + if (!avail) { + if (!enabled) + return true; + if(throwException) { + throw new GLException("Required extensions not available to call this function"); + } + return false; + } + int buffer = bufferStateTracker.getBoundBufferObject(state, this); + if (enabled) { + if (buffer == 0) { + if(throwException) { + throw new GLException(kind + " must be enabled to call this method"); + } + return false; + } + } else { + if (buffer != 0) { + if(throwException) { + throw new GLException(kind + " must be disabled to call this method"); + } + return false; + } + } + return true; +} + +private boolean checkArrayVBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + false, + GL.GL_ARRAY_BUFFER, + "array vertex_buffer_object", throwException); +} + +private boolean checkArrayVBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + true, + GL.GL_ARRAY_BUFFER, + "array vertex_buffer_object", throwException); +} + +private boolean checkElementVBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + false, + GL.GL_ELEMENT_ARRAY_BUFFER, + "element vertex_buffer_object", throwException); +} + +private boolean checkElementVBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + true, + GL.GL_ELEMENT_ARRAY_BUFFER, + "element vertex_buffer_object", throwException); +} + +private boolean checkUnpackPBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + false, + GL2.GL_PIXEL_UNPACK_BUFFER, + "unpack pixel_buffer_object", throwException); +} + +private boolean checkUnpackPBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + true, + GL2.GL_PIXEL_UNPACK_BUFFER, + "unpack pixel_buffer_object", throwException); +} + +private boolean checkPackPBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + false, + GL2.GL_PIXEL_PACK_BUFFER, + "pack pixel_buffer_object", throwException); +} + +private boolean checkPackPBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + true, + GL2.GL_PIXEL_PACK_BUFFER, + "pack pixel_buffer_object", throwException); +} + +public boolean glIsPBOPackEnabled() { + return checkPackPBOEnabled(false); +} + +public boolean glIsPBOUnpackEnabled() { + return checkUnpackPBOEnabled(false); +} + +// Attempt to return the same ByteBuffer object from glMapBuffer if +// the vertex buffer object's base address and size haven't changed +private static class ARBVBOKey { + private long addr; + private int capacity; + + ARBVBOKey(long addr, int capacity) { + this.addr = addr; + this.capacity = capacity; + } + + public int hashCode() { + return (int) addr; + } + + public boolean equals(Object o) { + if ((o == null) || (!(o instanceof ARBVBOKey))) { + return false; + } + + ARBVBOKey other = (ARBVBOKey) o; + return ((addr == other.addr) && (capacity == other.capacity)); + } +} + +private Map/**/ arbVBOCache = new HashMap(); + +/** Entry point to C language function:
LPVOID glMapBuffer(GLenum target, GLenum access); */ +public java.nio.ByteBuffer glMapBuffer(int target, int access) { + final long __addr_ = ((GL4bcProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer; + if (__addr_ == 0) { + throw new GLException("Method \"glMapBuffer\" not available"); + } + int sz = bufferSizeTracker.getBufferSize(bufferStateTracker, + target, + this); + long addr; + addr = dispatch_glMapBuffer(target, access, __addr_); + if (addr == 0 || sz == 0) { + return null; + } + ARBVBOKey key = new ARBVBOKey(addr, sz); + ByteBuffer _res = (ByteBuffer) arbVBOCache.get(key); + if (_res == null) { + _res = newDirectByteBuffer(addr, sz); + InternalBufferUtil.nativeOrder(_res); + arbVBOCache.put(key, _res); + } + _res.position(0); + return _res; +} + +/** Encapsulates function pointer for OpenGL function
: LPVOID glMapBuffer(GLenum target, GLenum access); */ +native private long dispatch_glMapBuffer(int target, int access, long glProcAddress); + +native private ByteBuffer newDirectByteBuffer(long addr, int capacity); + + /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ + public void glShaderBinary(int n, java.nio.IntBuffer shaders, int binaryformat, java.nio.Buffer binary, int length) { + throw new GLException("Method \"glShaderBinary\" not available"); + } + + /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ + public void glShaderBinary(int n, int[] shaders, int shaders_offset, int binaryformat, java.nio.Buffer binary, int length) { + throw new GLException("Method \"glShaderBinary\" not available"); + } + + public void glReleaseShaderCompiler() { + // nothing to do + } + + public void glVertexPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.isVBO()) { + glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); + } + } + public void glColorPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.isVBO()) { + glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); + } + + } + public void glNormalPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.getComponentNumber()!=3) { + throw new GLException("Only 3 components per normal allowed"); + } + if(array.isVBO()) { + glNormalPointer(array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glNormalPointer(array.getComponentType(), array.getStride(), array.getBuffer()); + } + } + public void glTexCoordPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.isVBO()) { + glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); + } + } + diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gles1.java b/make/config/jogl/gl-impl-CustomJavaCode-gles1.java index 6fb8a32ef..b4efac8a1 100755 --- a/make/config/jogl/gl-impl-CustomJavaCode-gles1.java +++ b/make/config/jogl/gl-impl-CustomJavaCode-gles1.java @@ -6,10 +6,6 @@ public GLES1Impl(GLProfile glp, GLContextImpl context) { this.glProfile = glp; } -public final boolean isGL() { - return true; -} - public final boolean isGL4bc() { return false; } @@ -58,10 +54,6 @@ public final boolean hasGLSL() { return false; } -public final GL getGL() throws GLException { - return this; -} - public final GL4bc getGL4bc() throws GLException { throw new GLException("Not a GL4bc implementation"); } @@ -102,39 +94,6 @@ public final GL2GL3 getGL2GL3() throws GLException { throw new GLException("Not a GL2GL3 implementation"); } -public boolean isFunctionAvailable(String glFunctionName) { - return _context.isFunctionAvailable(glFunctionName); -} - -public boolean isExtensionAvailable(String glExtensionName) { - return _context.isExtensionAvailable(glExtensionName); -} - -public Object getExtension(String extensionName) { - // At this point we don't expose any extensions using this mechanism - return null; -} - -/** Returns the context this GL object is associated with for better - error checking by DebugGL. */ -public GLContext getContext() { - return _context; -} - -private GLContextImpl _context; - -public void setSwapInterval(int interval) { - _context.setSwapInterval(interval); -} - -public int getSwapInterval() { - return _context.getSwapInterval(); -} - -public Object getPlatformGLExtensions() { - return _context.getPlatformGLExtensions(); -} - // // Helpers for ensuring the correct amount of texture data // diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gles2.java b/make/config/jogl/gl-impl-CustomJavaCode-gles2.java index 8204bd1ae..bb8ddb7ef 100755 --- a/make/config/jogl/gl-impl-CustomJavaCode-gles2.java +++ b/make/config/jogl/gl-impl-CustomJavaCode-gles2.java @@ -10,10 +10,6 @@ public GLES2Impl(GLProfile glp, GLContextImpl context) { this.glProfile = glp; } -public final boolean isGL() { - return true; -} - public final boolean isGL4bc() { return false; } @@ -62,10 +58,6 @@ public final boolean hasGLSL() { return true; } -public final GL getGL() throws GLException { - return this; -} - public final GL4bc getGL4bc() throws GLException { throw new GLException("Not a GL4bc implementation"); } @@ -106,39 +98,6 @@ public final GL2GL3 getGL2GL3() throws GLException { throw new GLException("Not a GL2GL3 implementation"); } -public boolean isFunctionAvailable(String glFunctionName) { - return _context.isFunctionAvailable(glFunctionName); -} - -public boolean isExtensionAvailable(String glExtensionName) { - return _context.isExtensionAvailable(glExtensionName); -} - -public Object getExtension(String extensionName) { - // At this point we don't expose any extensions using this mechanism - return null; -} - -/** Returns the context this GL object is associated with for better - error checking by DebugGL. */ -public GLContext getContext() { - return _context; -} - -private GLContextImpl _context; - -public void setSwapInterval(int interval) { - _context.setSwapInterval(interval); -} - -public int getSwapInterval() { - return _context.getSwapInterval(); -} - -public Object getPlatformGLExtensions() { - return _context.getPlatformGLExtensions(); -} - // // Helpers for ensuring the correct amount of texture data // diff --git a/make/config/jogl/gl3-common.cfg b/make/config/jogl/gl3-common.cfg index fac8323bb..c2cc2968e 100644 --- a/make/config/jogl/gl3-common.cfg +++ b/make/config/jogl/gl3-common.cfg @@ -16,6 +16,9 @@ RenameExtensionIntoCore GL_ARB_geometry_shader4 RenameExtensionIntoCore GL_ARB_sync # <<< OpenGL 3.2 +# >>> OpenGL 3.3 +# <<< OpenGL 3.3 + # Ignore GL functions that deal with explicit pointer values in such a # way that we cannot implement the functionality in Java Ignore glMultiDrawElementsBaseVertex diff --git a/make/config/jogl/gl3-desktop-tracker.cfg b/make/config/jogl/gl3-desktop-tracker.cfg deleted file mode 100644 index 4b9a7edb7..000000000 --- a/make/config/jogl/gl3-desktop-tracker.cfg +++ /dev/null @@ -1,38 +0,0 @@ - -# Track server-side object creation and deletion when necessary -# Note that this is only necessary when the Java 2D / JOGL bridge is active, -# so will never be needed for the embedded OpenGL variants -JavaEpilogue glGenBuffers if (tracker != null) tracker.addBuffers({0}, {1}); -JavaEpilogue glGenFencesAPPLE if (tracker != null) tracker.addFencesAPPLE({0}, {1}); -JavaEpilogue glGenFencesNV if (tracker != null) tracker.addFencesNV({0}, {1}); -JavaEpilogue glGenFragmentShadersATI if (tracker != null) tracker.addFragmentShadersATI(_res, {0}); -JavaEpilogue glGenFramebuffersEXT if (tracker != null) tracker.addFramebuffersEXT({0}, {1}); -JavaEpilogue glGenLists if (tracker != null) tracker.addLists(_res, {0}); -JavaEpilogue glGenOcclusionQueriesNV if (tracker != null) tracker.addOcclusionQueriesNV({0}, {1}); -JavaEpilogue glCreateProgram if (tracker != null) tracker.addProgramObject(_res); -JavaEpilogue glGenPrograms if (tracker != null) tracker.addPrograms({0}, {1}); -JavaEpilogue glGenQueries if (tracker != null) tracker.addQueries({0}, {1}); -JavaEpilogue glGenRenderbuffersEXT if (tracker != null) tracker.addRenderbuffersEXT({0}, {1}); -JavaEpilogue glCreateShader if (tracker != null) tracker.addShaderObject(_res); -JavaEpilogue glGenTextures if (tracker != null) tracker.addTextures({0}, {1}); -JavaEpilogue glGenVertexArraysAPPLE if (tracker != null) tracker.addVertexArraysAPPLE({0}, {1}); -JavaEpilogue glGenVertexShadersEXT if (tracker != null) tracker.addVertexShadersEXT(_res, {0}); - -JavaEpilogue glDeleteBuffers if (tracker != null) tracker.removeBuffers({0}, {1}); -JavaEpilogue glDeleteFencesAPPLE if (tracker != null) tracker.removeFencesAPPLE({0}, {1}); -JavaEpilogue glDeleteFencesNV if (tracker != null) tracker.removeFencesNV({0}, {1}); -JavaEpilogue glDeleteFragmentShaderATI if (tracker != null) tracker.removeFragmentShaderATI({0}); -JavaEpilogue glDeleteFramebuffersEXT if (tracker != null) tracker.removeFramebuffersEXT({0}, {1}); -JavaEpilogue glDeleteLists if (tracker != null) tracker.removeLists({0}, {1}); -JavaEpilogue glDeleteOcclusionQueriesNV if (tracker != null) tracker.removeOcclusionQueriesNV({0}, {1}); -JavaEpilogue glDeleteProgram if (tracker != null) tracker.removeProgramObject({0}); -JavaEpilogue glDeleteObject if (tracker != null) tracker.removeProgramOrShaderObject({0}); -JavaEpilogue glDeletePrograms if (tracker != null) tracker.removePrograms({0}, {1}); -JavaEpilogue glDeleteProgramsNV if (tracker != null) tracker.removeProgramsNV({0}, {1}); -JavaEpilogue glDeleteQueries if (tracker != null) tracker.removeQueries({0}, {1}); -JavaEpilogue glDeleteRenderbuffersEXT if (tracker != null) tracker.removeRenderbuffersEXT({0}, {1}); -JavaEpilogue glDeleteShader if (tracker != null) tracker.removeShaderObject({0}); -JavaEpilogue glDeleteTextures if (tracker != null) tracker.removeTextures({0}, {1}); -JavaEpilogue glDeleteVertexArraysAPPLE if (tracker != null) tracker.removeVertexArraysAPPLE({0}, {1}); -JavaEpilogue glDeleteVertexShaderEXT if (tracker != null) tracker.removeVertexShaderEXT({0}); - diff --git a/make/config/jogl/gl4-common.cfg b/make/config/jogl/gl4-common.cfg new file mode 100644 index 000000000..2c119da30 --- /dev/null +++ b/make/config/jogl/gl4-common.cfg @@ -0,0 +1,5 @@ + +# >>> OpenGL 4.0 +# <<< OpenGL 4.0 + + diff --git a/make/config/jogl/gl4-desktop-tracker.cfg b/make/config/jogl/gl4-desktop-tracker.cfg new file mode 100644 index 000000000..4b9a7edb7 --- /dev/null +++ b/make/config/jogl/gl4-desktop-tracker.cfg @@ -0,0 +1,38 @@ + +# Track server-side object creation and deletion when necessary +# Note that this is only necessary when the Java 2D / JOGL bridge is active, +# so will never be needed for the embedded OpenGL variants +JavaEpilogue glGenBuffers if (tracker != null) tracker.addBuffers({0}, {1}); +JavaEpilogue glGenFencesAPPLE if (tracker != null) tracker.addFencesAPPLE({0}, {1}); +JavaEpilogue glGenFencesNV if (tracker != null) tracker.addFencesNV({0}, {1}); +JavaEpilogue glGenFragmentShadersATI if (tracker != null) tracker.addFragmentShadersATI(_res, {0}); +JavaEpilogue glGenFramebuffersEXT if (tracker != null) tracker.addFramebuffersEXT({0}, {1}); +JavaEpilogue glGenLists if (tracker != null) tracker.addLists(_res, {0}); +JavaEpilogue glGenOcclusionQueriesNV if (tracker != null) tracker.addOcclusionQueriesNV({0}, {1}); +JavaEpilogue glCreateProgram if (tracker != null) tracker.addProgramObject(_res); +JavaEpilogue glGenPrograms if (tracker != null) tracker.addPrograms({0}, {1}); +JavaEpilogue glGenQueries if (tracker != null) tracker.addQueries({0}, {1}); +JavaEpilogue glGenRenderbuffersEXT if (tracker != null) tracker.addRenderbuffersEXT({0}, {1}); +JavaEpilogue glCreateShader if (tracker != null) tracker.addShaderObject(_res); +JavaEpilogue glGenTextures if (tracker != null) tracker.addTextures({0}, {1}); +JavaEpilogue glGenVertexArraysAPPLE if (tracker != null) tracker.addVertexArraysAPPLE({0}, {1}); +JavaEpilogue glGenVertexShadersEXT if (tracker != null) tracker.addVertexShadersEXT(_res, {0}); + +JavaEpilogue glDeleteBuffers if (tracker != null) tracker.removeBuffers({0}, {1}); +JavaEpilogue glDeleteFencesAPPLE if (tracker != null) tracker.removeFencesAPPLE({0}, {1}); +JavaEpilogue glDeleteFencesNV if (tracker != null) tracker.removeFencesNV({0}, {1}); +JavaEpilogue glDeleteFragmentShaderATI if (tracker != null) tracker.removeFragmentShaderATI({0}); +JavaEpilogue glDeleteFramebuffersEXT if (tracker != null) tracker.removeFramebuffersEXT({0}, {1}); +JavaEpilogue glDeleteLists if (tracker != null) tracker.removeLists({0}, {1}); +JavaEpilogue glDeleteOcclusionQueriesNV if (tracker != null) tracker.removeOcclusionQueriesNV({0}, {1}); +JavaEpilogue glDeleteProgram if (tracker != null) tracker.removeProgramObject({0}); +JavaEpilogue glDeleteObject if (tracker != null) tracker.removeProgramOrShaderObject({0}); +JavaEpilogue glDeletePrograms if (tracker != null) tracker.removePrograms({0}, {1}); +JavaEpilogue glDeleteProgramsNV if (tracker != null) tracker.removeProgramsNV({0}, {1}); +JavaEpilogue glDeleteQueries if (tracker != null) tracker.removeQueries({0}, {1}); +JavaEpilogue glDeleteRenderbuffersEXT if (tracker != null) tracker.removeRenderbuffersEXT({0}, {1}); +JavaEpilogue glDeleteShader if (tracker != null) tracker.removeShaderObject({0}); +JavaEpilogue glDeleteTextures if (tracker != null) tracker.removeTextures({0}, {1}); +JavaEpilogue glDeleteVertexArraysAPPLE if (tracker != null) tracker.removeVertexArraysAPPLE({0}, {1}); +JavaEpilogue glDeleteVertexShaderEXT if (tracker != null) tracker.removeVertexShaderEXT({0}); + diff --git a/make/config/jogl/glu-CustomJavaCode-base.java b/make/config/jogl/glu-CustomJavaCode-base.java index aeb4f2ef9..480f5d117 100755 --- a/make/config/jogl/glu-CustomJavaCode-base.java +++ b/make/config/jogl/glu-CustomJavaCode-base.java @@ -169,7 +169,7 @@ protected static boolean checkedGLUtessellatorImpl = false; protected static final void validateGLUtessellatorImpl() { if(!checkedGLUtessellatorImpl) { - availableGLUtessellatorImpl = NWReflection.isClassAvailable("com.jogamp.opengl.impl.glu.tessellator.GLUtessellatorImpl"); + availableGLUtessellatorImpl = ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.glu.tessellator.GLUtessellatorImpl"); checkedGLUtessellatorImpl = true; } if(!availableGLUtessellatorImpl) { @@ -1220,7 +1220,7 @@ protected static final void validateGLUquadricImpl() { if(!checkedGLUquadricImpl) { synchronized (syncObject) { if(!checkedGLUquadricImpl) { - availableGLUquadricImpl = NWReflection.isClassAvailable("com.jogamp.opengl.impl.glu.GLUquadricImpl"); + availableGLUquadricImpl = ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.glu.GLUquadricImpl"); checkedGLUquadricImpl = true; } } diff --git a/make/config/jogl/glu-CustomJavaCode-gl2es1.java b/make/config/jogl/glu-CustomJavaCode-gl2es1.java index b5cb3b2f8..f3b4322d9 100755 --- a/make/config/jogl/glu-CustomJavaCode-gl2es1.java +++ b/make/config/jogl/glu-CustomJavaCode-gl2es1.java @@ -86,7 +86,7 @@ protected static boolean checkedMipmap = false; protected static final void validateMipmap() { if(!checkedMipmap) { - availableMipmap = NWReflection.isClassAvailable("com.jogamp.opengl.impl.glu.mipmap.Mipmap"); + availableMipmap = ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.glu.mipmap.Mipmap"); checkedMipmap = true; } if(!availableMipmap) { diff --git a/make/config/jogl/glu-common.cfg b/make/config/jogl/glu-common.cfg index 937ca0348..f5fc7c1b3 100644 --- a/make/config/jogl/glu-common.cfg +++ b/make/config/jogl/glu-common.cfg @@ -14,7 +14,7 @@ Import javax.media.opengl.glu.* Import com.jogamp.opengl.impl.* Import com.jogamp.opengl.impl.glu.* Import com.jogamp.opengl.impl.glu.tessellator.GLUtessellatorImpl -Import com.jogamp.nativewindow.impl.NWReflection +Import com.jogamp.common.util.ReflectionUtil # Raise GLException instead of RuntimeException in glue code RuntimeExceptionType GLException diff --git a/make/config/jogl/obsolete/gl-gl2es12.cfg b/make/config/jogl/obsolete/gl-gl2es12.cfg new file mode 100644 index 000000000..3942b1419 --- /dev/null +++ b/make/config/jogl/obsolete/gl-gl2es12.cfg @@ -0,0 +1,90 @@ +# This .cfg file is used to generate the GL interface and implementing class. +JavaOutputDir gensrc/classes +NativeOutputDir gensrc/native/jogl/gl2es12 + +ExtendedInterfaceSymbolsOnly ../build-temp/gensrc/classes/javax/media/opengl/GL.java +ExtendedInterfaceSymbolsOnly ../build-temp/gensrc/classes/javax/media/opengl/GL2ES1.java +ExtendedInterfaceSymbolsOnly ../build-temp/gensrc/classes/javax/media/opengl/GL2ES2.java +ExtendedInterfaceSymbolsOnly ../src/jogl/classes/javax/media/opengl/GLBase.java +ExtendedInterfaceSymbolsOnly ../src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java +ExtendedInterfaceSymbolsOnly ../src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFunc.java +ExtendedInterfaceSymbolsOnly ../src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java + +Style ImplOnly +ImplPackage com.jogamp.opengl.impl.gl2es12 +ImplJavaClass GL2ES12Impl +Implements GL2ES12Impl GLBase +Implements GL2ES12Impl GL +Implements GL2ES12Impl GL2ES1 +Implements GL2ES12Impl GL2ES2 + +Include gl-common.cfg +Include gl-common-extensions.cfg +Include gl-desktop.cfg + +# Because we're manually implementing glMapBuffer but only producing +# the implementing class, GlueGen doesn't notice that it has to emit a +# proc address table entry for it. Force it to here. +ForceProcAddressGen glMapBuffer + +# Force all of the methods to be emitted using dynamic linking so we +# don't need to link against any emulation library on the desktop or +# depend on the presence of an import library for a particular device +ForceProcAddressGen __ALL__ + +# Also force the calling conventions of the locally generated function +# pointer typedefs for these routines to APIENTRY +LocalProcAddressCallingConvention __ALL__ APIENTRY + +EmitProcAddressTable true +ProcAddressTableClassName GL2ES12ProcAddressTable +GetProcAddressTableExpr ((GL2ES12ProcAddressTable)_context.getGLProcAddressTable()) + +# Pick up on-line OpenGL javadoc thanks to user cylab on javagaming.org forums +TagNativeBinding true + +# There seem to be some errors in the glue code generation where we are not ignoring +# enough routines from desktop GL in GL2ES12Impl. For now manually ignore those which +# we know shouldn't be in there +Ignore glGetTexImage +Ignore glPixelStoref + +# Add PixelStorei StateTracker +# +# Add input validation to glPixelStorei to make sure that, even if we +# are running on top of desktop OpenGL, parameters not exposed in +# OpenGL ES can not be changed +CustomJavaCode GL2ES12Impl private static final int params_offset = 0; // just a helper for JavaPrologue .. + +JavaPrologue glPixelStorei if (pname != GL_PACK_ALIGNMENT && pname != GL_UNPACK_ALIGNMENT) { +JavaPrologue glPixelStorei throw new GLException("Unsupported pixel store parameter name 0x" + Integer.toHexString(pname)); +JavaPrologue glPixelStorei } +JavaPrologue glPixelStorei glStateTracker.setInt(pname, param); + +JavaPrologue glGetIntegerv if ( glStateTracker.getInt(pname, params, params_offset) ) { return; } + +CustomJavaCode GL2ES12Impl public void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) { +CustomJavaCode GL2ES12Impl glFrustum((double)left, (double)right, (double)bottom, (double)top, (double)zNear, (double)zFar); } + +CustomJavaCode GL2ES12Impl public void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) { +CustomJavaCode GL2ES12Impl glOrtho((double)left, (double)right, (double)bottom, (double)top, (double)zNear, (double)zFar); } + +CustomJavaCode GL2ES12Impl public void glClearDepthf(float depth) { +CustomJavaCode GL2ES12Impl glClearDepth((double)depth); } + +CustomJavaCode GL2ES12Impl public void glDepthRangef(float zNear, float zFar) { +CustomJavaCode GL2ES12Impl glDepthRange((double)zNear, (double)zFar); } + +Include gl-headers.cfg +Include ../intptr.cfg + +IncludeAs CustomJavaCode GL2ES12Impl gl-impl-CustomJavaCode-common.java +IncludeAs CustomJavaCode GL2ES12Impl gl-impl-CustomJavaCode-gl2es12.java +IncludeAs CustomJavaCode GL2ES12Impl gl-impl-CustomJavaCode-embedded.java +IncludeAs CustomJavaCode GL2ES12Impl gl-impl-CustomJavaCode-gl2_es2.java +IncludeAs CustomCCode gl-impl-CustomCCode-gl2es12.c + +Import javax.media.opengl.GLES1 +Import javax.media.opengl.GLES2 +Import com.jogamp.opengl.impl.InternalBufferUtil +Import java.io.PrintStream diff --git a/make/config/jogl/obsolete/gl-impl-CustomCCode-gl2.c b/make/config/jogl/obsolete/gl-impl-CustomCCode-gl2.c new file mode 100644 index 000000000..91fd0078b --- /dev/null +++ b/make/config/jogl/obsolete/gl-impl-CustomCCode-gl2.c @@ -0,0 +1,24 @@ +/* Java->C glue code: + * Java package: com.jogamp.opengl.impl.gl2.GL2Impl + * Java method: long dispatch_glMapBuffer(int target, int access) + * C function: void * glMapBuffer(GLenum target, GLenum access); + */ +JNIEXPORT jlong JNICALL +Java_com_jogamp_opengl_impl_gl2_GL2Impl_dispatch_1glMapBuffer(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { + PFNGLMAPBUFFERPROC ptr_glMapBuffer; + void * _res; + ptr_glMapBuffer = (PFNGLMAPBUFFERPROC) (intptr_t) glProcAddress; + assert(ptr_glMapBuffer != NULL); + _res = (* ptr_glMapBuffer) ((GLenum) target, (GLenum) access); + return (jlong) (intptr_t) _res; +} + +/* Java->C glue code: + * Java package: com.jogamp.opengl.impl.gl2.GL2Impl + * Java method: ByteBuffer newDirectByteBuffer(long addr, int capacity); + * C function: jobject newDirectByteBuffer(jlong addr, jint capacity); + */ +JNIEXPORT jobject JNICALL +Java_com_jogamp_opengl_impl_gl2_GL2Impl_newDirectByteBuffer(JNIEnv *env, jobject _unused, jlong addr, jint capacity) { + return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) addr, capacity); +} diff --git a/make/config/jogl/obsolete/gl-impl-CustomCCode-gl2es12.c b/make/config/jogl/obsolete/gl-impl-CustomCCode-gl2es12.c new file mode 100644 index 000000000..07b821802 --- /dev/null +++ b/make/config/jogl/obsolete/gl-impl-CustomCCode-gl2es12.c @@ -0,0 +1,24 @@ +/* Java->C glue code: + * Java package: com.jogamp.opengl.impl.gl2es12.GL2ES12Impl + * Java method: long dispatch_glMapBuffer(int target, int access) + * C function: void * glMapBuffer(GLenum target, GLenum access); + */ +JNIEXPORT jlong JNICALL +Java_com_jogamp_opengl_impl_gl2es12_GL2ES12Impl_dispatch_1glMapBuffer(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { + PFNGLMAPBUFFERPROC ptr_glMapBuffer; + void * _res; + ptr_glMapBuffer = (PFNGLMAPBUFFERPROC) (intptr_t) glProcAddress; + assert(ptr_glMapBuffer != NULL); + _res = (* ptr_glMapBuffer) ((GLenum) target, (GLenum) access); + return (jlong) (intptr_t) _res; +} + +/* Java->C glue code: + * Java package: com.jogamp.opengl.impl.gl2es12.GL2ES12Impl + * Java method: ByteBuffer newDirectByteBuffer(long addr, int capacity); + * C function: jobject newDirectByteBuffer(jlong addr, jint capacity); + */ +JNIEXPORT jobject JNICALL +Java_com_jogamp_opengl_impl_gl2es12_GL2ES12Impl_newDirectByteBuffer(JNIEnv *env, jobject _unused, jlong addr, jint capacity) { + return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) addr, capacity); +} diff --git a/make/config/jogl/obsolete/gl-impl-CustomCCode-gl3.c b/make/config/jogl/obsolete/gl-impl-CustomCCode-gl3.c new file mode 100644 index 000000000..f540a7d4a --- /dev/null +++ b/make/config/jogl/obsolete/gl-impl-CustomCCode-gl3.c @@ -0,0 +1,24 @@ +/* Java->C glue code: + * Java package: com.jogamp.opengl.impl.gl3.GL3Impl + * Java method: long dispatch_glMapBuffer(int target, int access) + * C function: void * glMapBuffer(GLenum target, GLenum access); + */ +JNIEXPORT jlong JNICALL +Java_com_jogamp_opengl_impl_gl3_GL3Impl_dispatch_1glMapBuffer(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { + PFNGLMAPBUFFERPROC ptr_glMapBuffer; + void * _res; + ptr_glMapBuffer = (PFNGLMAPBUFFERPROC) (intptr_t) glProcAddress; + assert(ptr_glMapBuffer != NULL); + _res = (* ptr_glMapBuffer) ((GLenum) target, (GLenum) access); + return (jlong) (intptr_t) _res; +} + +/* Java->C glue code: + * Java package: com.jogamp.opengl.impl.gl3.GL3Impl + * Java method: ByteBuffer newDirectByteBuffer(long addr, int capacity); + * C function: jobject newDirectByteBuffer(jlong addr, jint capacity); + */ +JNIEXPORT jobject JNICALL +Java_com_jogamp_opengl_impl_gl3_GL3Impl_newDirectByteBuffer(JNIEnv *env, jobject _unused, jlong addr, jint capacity) { + return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) addr, capacity); +} diff --git a/make/config/jogl/obsolete/gl-impl-CustomJavaCode-gl2.java b/make/config/jogl/obsolete/gl-impl-CustomJavaCode-gl2.java new file mode 100644 index 000000000..a1a6917df --- /dev/null +++ b/make/config/jogl/obsolete/gl-impl-CustomJavaCode-gl2.java @@ -0,0 +1,385 @@ +// Tracks glBegin/glEnd calls to determine whether it is legal to +// query Vertex Buffer Object state +private boolean inBeginEndPair; + +/* FIXME: refactor dependence on Java 2D / JOGL bridge + +// Tracks creation and destruction of server-side OpenGL objects when +// the Java2D/OpenGL pipeline is enabled and it is using frame buffer +// objects (FBOs) to do its rendering +private GLObjectTracker tracker; + +public void setObjectTracker(GLObjectTracker tracker) { + this.tracker = tracker; +} + +*/ + + +public GL2Impl(GLProfile glp, GLContextImpl context) { + this._context = context; + this.bufferSizeTracker = context.getBufferSizeTracker(); + this.bufferStateTracker = context.getBufferStateTracker(); + this.glStateTracker = context.getGLStateTracker(); + this.glProfile = glp; +} + +/** + * Provides platform-independent access to the wglAllocateMemoryNV / + * glXAllocateMemoryNV extension. + */ +public java.nio.ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { + return _context.glAllocateMemoryNV(arg0, arg1, arg2, arg3); +} + +// +// Helpers for ensuring the correct amount of texture data +// + +/** Returns the number of bytes required to fill in the appropriate + texture. This is computed as closely as possible based on the + pixel pack or unpack parameters. The logic in this routine is + based on code in the SGI OpenGL sample implementation. */ + +private int imageSizeInBytes(int format, int type, int w, int h, int d, + boolean pack) { + int elements = 0; + int esize = 0; + + if (w < 0) return 0; + if (h < 0) return 0; + if (d < 0) return 0; + switch (format) { + case GL_COLOR_INDEX: + case GL_STENCIL_INDEX: + elements = 1; + break; + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: + case GL_LUMINANCE: + case GL_DEPTH_COMPONENT: + elements = 1; + break; + case GL_LUMINANCE_ALPHA: + elements = 2; + break; + case GL_RGB: + case GL_BGR: + elements = 3; + break; + case GL_RGBA: + case GL_BGRA: + case GL_ABGR_EXT: + elements = 4; + break; + /* FIXME ?? + case GL_HILO_NV: + elements = 2; + break; */ + default: + return 0; + } + switch (type) { + case GL_BITMAP: + if (format == GL_COLOR_INDEX) { + return (d * (h * ((w+7)/8))); + } else { + return 0; + } + case GL_BYTE: + case GL_UNSIGNED_BYTE: + esize = 1; + break; + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + esize = 1; + elements = 1; + break; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + esize = 2; + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + esize = 2; + elements = 1; + break; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + esize = 4; + break; + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + esize = 4; + elements = 1; + break; + default: + return 0; + } + return imageSizeInBytes(elements * esize, w, h, d, pack); +} + +private GLBufferSizeTracker bufferSizeTracker; +private GLBufferStateTracker bufferStateTracker; +private GLStateTracker glStateTracker; + +private boolean bufferObjectExtensionsInitialized = false; +private boolean haveARBPixelBufferObject; +private boolean haveEXTPixelBufferObject; +private boolean haveGL15; +private boolean haveGL21; +private boolean haveARBVertexBufferObject; + +private void initBufferObjectExtensionChecks() { + if (bufferObjectExtensionsInitialized) + return; + bufferObjectExtensionsInitialized = true; + haveARBPixelBufferObject = isExtensionAvailable("GL_ARB_pixel_buffer_object"); + haveEXTPixelBufferObject = isExtensionAvailable("GL_EXT_pixel_buffer_object"); + haveGL15 = isExtensionAvailable("GL_VERSION_1_5"); + haveGL21 = isExtensionAvailable("GL_VERSION_2_1"); + haveARBVertexBufferObject = isExtensionAvailable("GL_ARB_vertex_buffer_object"); +} + +private boolean checkBufferObject(boolean extension1, + boolean extension2, + boolean extension3, + boolean enabled, + int state, + String kind, boolean throwException) { + if (inBeginEndPair) { + throw new GLException("May not call this between glBegin and glEnd"); + } + boolean avail = (extension1 || extension2 || extension3); + if (!avail) { + if (!enabled) + return true; + if(throwException) { + throw new GLException("Required extensions not available to call this function"); + } + return false; + } + int buffer = bufferStateTracker.getBoundBufferObject(state, this); + if (enabled) { + if (buffer == 0) { + if(throwException) { + throw new GLException(kind + " must be enabled to call this method"); + } + return false; + } + } else { + if (buffer != 0) { + if(throwException) { + throw new GLException(kind + " must be disabled to call this method"); + } + return false; + } + } + return true; +} + +private boolean checkArrayVBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + false, + GL.GL_ARRAY_BUFFER, + "array vertex_buffer_object", throwException); +} + +private boolean checkArrayVBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + true, + GL.GL_ARRAY_BUFFER, + "array vertex_buffer_object", throwException); +} + +private boolean checkElementVBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + false, + GL.GL_ELEMENT_ARRAY_BUFFER, + "element vertex_buffer_object", throwException); +} + +private boolean checkElementVBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + true, + GL.GL_ELEMENT_ARRAY_BUFFER, + "element vertex_buffer_object", throwException); +} + +private boolean checkUnpackPBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + false, + GL2.GL_PIXEL_UNPACK_BUFFER, + "unpack pixel_buffer_object", throwException); +} + +private boolean checkUnpackPBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + true, + GL2.GL_PIXEL_UNPACK_BUFFER, + "unpack pixel_buffer_object", throwException); +} + +private boolean checkPackPBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + false, + GL2.GL_PIXEL_PACK_BUFFER, + "pack pixel_buffer_object", throwException); +} + +private boolean checkPackPBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveARBPixelBufferObject, + haveEXTPixelBufferObject, + haveGL21, + true, + GL2.GL_PIXEL_PACK_BUFFER, + "pack pixel_buffer_object", throwException); +} + +public boolean glIsPBOPackEnabled() { + return checkPackPBOEnabled(false); +} + +public boolean glIsPBOUnpackEnabled() { + return checkUnpackPBOEnabled(false); +} + +// Attempt to return the same ByteBuffer object from glMapBuffer if +// the vertex buffer object's base address and size haven't changed +private static class ARBVBOKey { + private long addr; + private int capacity; + + ARBVBOKey(long addr, int capacity) { + this.addr = addr; + this.capacity = capacity; + } + + public int hashCode() { + return (int) addr; + } + + public boolean equals(Object o) { + if ((o == null) || (!(o instanceof ARBVBOKey))) { + return false; + } + + ARBVBOKey other = (ARBVBOKey) o; + return ((addr == other.addr) && (capacity == other.capacity)); + } +} + +private Map/**/ arbVBOCache = new HashMap(); + +/** Entry point to C language function:
LPVOID glMapBuffer(GLenum target, GLenum access); */ +public java.nio.ByteBuffer glMapBuffer(int target, int access) { + final long __addr_ = ((GL2ProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer; + if (__addr_ == 0) { + throw new GLException("Method \"glMapBuffer\" not available"); + } + int sz = bufferSizeTracker.getBufferSize(bufferStateTracker, + target, + this); + long addr; + addr = dispatch_glMapBuffer(target, access, __addr_); + if (addr == 0 || sz == 0) { + return null; + } + ARBVBOKey key = new ARBVBOKey(addr, sz); + ByteBuffer _res = (ByteBuffer) arbVBOCache.get(key); + if (_res == null) { + _res = newDirectByteBuffer(addr, sz); + InternalBufferUtil.nativeOrder(_res); + arbVBOCache.put(key, _res); + } + _res.position(0); + return _res; +} + +/** Encapsulates function pointer for OpenGL function
: LPVOID glMapBuffer(GLenum target, GLenum access); */ +native private long dispatch_glMapBuffer(int target, int access, long glProcAddress); + +native private ByteBuffer newDirectByteBuffer(long addr, int capacity); + + /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ + public void glShaderBinary(int n, java.nio.IntBuffer shaders, int binaryformat, java.nio.Buffer binary, int length) { + throw new GLException("Method \"glShaderBinary\" not available"); + } + + /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ + public void glShaderBinary(int n, int[] shaders, int shaders_offset, int binaryformat, java.nio.Buffer binary, int length) { + throw new GLException("Method \"glShaderBinary\" not available"); + } + + public void glReleaseShaderCompiler() { + // nothing to do + } + + public void glVertexPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.isVBO()) { + glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); + } + } + public void glColorPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.isVBO()) { + glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); + } + + } + public void glNormalPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.getComponentNumber()!=3) { + throw new GLException("Only 3 components per normal allowed"); + } + if(array.isVBO()) { + glNormalPointer(array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glNormalPointer(array.getComponentType(), array.getStride(), array.getBuffer()); + } + } + public void glTexCoordPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.isVBO()) { + glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); + } + } + diff --git a/make/config/jogl/obsolete/gl-impl-CustomJavaCode-gl2es12.java b/make/config/jogl/obsolete/gl-impl-CustomJavaCode-gl2es12.java new file mode 100644 index 000000000..aed442da3 --- /dev/null +++ b/make/config/jogl/obsolete/gl-impl-CustomJavaCode-gl2es12.java @@ -0,0 +1,353 @@ +// Tracks glBegin/glEnd calls to determine whether it is legal to +// query Vertex Buffer Object state +private boolean inBeginEndPair; + +/* FIXME: refactor dependence on Java 2D / JOGL bridge + +// Tracks creation and destruction of server-side OpenGL objects when +// the Java2D/OpenGL pipeline is enabled and it is using frame buffer +// objects (FBOs) to do its rendering +private GLObjectTracker tracker; + +public void setObjectTracker(GLObjectTracker tracker) { + this.tracker = tracker; +} + +*/ + +public GL2ES12Impl(GLProfile glp, GLContextImpl context) { + this._context = context; + this.bufferSizeTracker = context.getBufferSizeTracker(); + this.bufferStateTracker = context.getBufferStateTracker(); + this.glStateTracker = context.getGLStateTracker(); + this.isGL2ES2 = glp.isGL2ES2(); + this.glProfile = glp; +} + +private boolean isGL2ES2; + +public boolean isFunctionAvailable(String glFunctionName) { + return _context.isFunctionAvailable(glFunctionName); +} + +public boolean isExtensionAvailable(String glExtensionName) { + return _context.isExtensionAvailable(glExtensionName); +} + +public Object getExtension(String extensionName) { + // At this point we don't expose any extensions using this mechanism + return null; +} + +/** Returns the context this GL object is associated with for better + error checking by DebugGL. */ +public GLContext getContext() { + return _context; +} + +private GLContextImpl _context; + +public void setSwapInterval(int interval) { + _context.setSwapInterval(interval); +} + +public int getSwapInterval() { + return _context.getSwapInterval(); +} + +public Object getPlatformGLExtensions() { + return _context.getPlatformGLExtensions(); +} + +// +// Helpers for ensuring the correct amount of texture data +// + +/** Returns the number of bytes required to fill in the appropriate + texture. This is computed as closely as possible based on the + pixel pack or unpack parameters. The logic in this routine is + based on code in the SGI OpenGL sample implementation. */ + +private int imageSizeInBytes(int format, int type, int w, int h, int d, + boolean pack) { + int elements = 0; + int esize = 0; + + if (w < 0) return 0; + if (h < 0) return 0; + if (d < 0) return 0; + switch (format) { + case GL_STENCIL_INDEX: + elements = 1; + break; + case GL_ALPHA: + case GL_LUMINANCE: + case GL_DEPTH_COMPONENT: + elements = 1; + break; + case GL_LUMINANCE_ALPHA: + elements = 2; + break; + case GL_RGB: + elements = 3; + break; + case GL_RGBA: + elements = 4; + break; + /* FIXME ?? + case GL_HILO_NV: + elements = 2; + break; */ + default: + return 0; + } + switch (type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + esize = 1; + break; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + esize = 2; + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_5_5_5_1: + esize = 2; + elements = 1; + break; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + esize = 4; + break; + default: + return 0; + } + return imageSizeInBytes(elements * esize, w, h, d, pack); +} + +private GLBufferSizeTracker bufferSizeTracker; +private GLBufferStateTracker bufferStateTracker; +private GLStateTracker glStateTracker; + +private boolean bufferObjectExtensionsInitialized = false; +private boolean haveGL15; +private boolean haveGL21; +private boolean haveARBVertexBufferObject; + +private void initBufferObjectExtensionChecks() { + if (bufferObjectExtensionsInitialized) + return; + bufferObjectExtensionsInitialized = true; + haveGL15 = isExtensionAvailable("GL_VERSION_1_5"); + haveGL21 = isExtensionAvailable("GL_VERSION_2_1"); + haveARBVertexBufferObject = isExtensionAvailable("GL_ARB_vertex_buffer_object"); +} + +private boolean checkBufferObject(boolean extension1, + boolean extension2, + boolean extension3, + boolean enabled, + int state, + String kind, boolean throwException) { + if (inBeginEndPair) { + throw new GLException("May not call this between glBegin and glEnd"); + } + boolean avail = (extension1 || extension2 || extension3); + if (!avail) { + if (!enabled) + return true; + if(throwException) { + throw new GLException("Required extensions not available to call this function"); + } + return false; + } + int buffer = bufferStateTracker.getBoundBufferObject(state, this); + if (enabled) { + if (buffer == 0) { + if(throwException) { + throw new GLException(kind + " must be enabled to call this method"); + } + return false; + } + } else { + if (buffer != 0) { + if(throwException) { + throw new GLException(kind + " must be disabled to call this method"); + } + return false; + } + } + return true; +} + +private boolean checkArrayVBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + false, + GL.GL_ARRAY_BUFFER, + "array vertex_buffer_object", throwException); +} + +private boolean checkArrayVBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + true, + GL.GL_ARRAY_BUFFER, + "array vertex_buffer_object", throwException); +} + +private boolean checkElementVBODisabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + false, + GL.GL_ELEMENT_ARRAY_BUFFER, + "element vertex_buffer_object", throwException); +} + +private boolean checkElementVBOEnabled(boolean throwException) { + initBufferObjectExtensionChecks(); + return checkBufferObject(haveGL15, + haveARBVertexBufferObject, + false, + true, + GL.GL_ELEMENT_ARRAY_BUFFER, + "element vertex_buffer_object", throwException); +} + +private boolean checkUnpackPBODisabled(boolean throwException) { + // PBO n/a for ES 1.1 or ES 2.0 + return true; +} + +private boolean checkUnpackPBOEnabled(boolean throwException) { + // PBO n/a for ES 1.1 or ES 2.0 + return false; +} + +private boolean checkPackPBODisabled(boolean throwException) { + // PBO n/a for ES 1.1 or ES 2.0 + return true; +} + +private boolean checkPackPBOEnabled(boolean throwException) { + // PBO n/a for ES 1.1 or ES 2.0 + return false; +} + +// Attempt to return the same ByteBuffer object from glMapBuffer if +// the vertex buffer object's base address and size haven't changed +private static class ARBVBOKey { + private long addr; + private int capacity; + + ARBVBOKey(long addr, int capacity) { + this.addr = addr; + this.capacity = capacity; + } + + public int hashCode() { + return (int) addr; + } + + public boolean equals(Object o) { + if ((o == null) || (!(o instanceof ARBVBOKey))) { + return false; + } + + ARBVBOKey other = (ARBVBOKey) o; + return ((addr == other.addr) && (capacity == other.capacity)); + } +} + +private Map/**/ arbVBOCache = new HashMap(); + +/** Entry point to C language function:
LPVOID glMapBuffer(GLenum target, GLenum access); */ +public java.nio.ByteBuffer glMapBuffer(int target, int access) { + final long __addr_ = ((GL2ES12ProcAddressTable)_context.getGLProcAddressTable())._addressof_glMapBuffer; + if (__addr_ == 0) { + throw new GLException("Method \"glMapBuffer\" not available"); + } + int sz = bufferSizeTracker.getBufferSize(bufferStateTracker, + target, + this); + long addr; + addr = dispatch_glMapBuffer(target, access, __addr_); + if (addr == 0 || sz == 0) { + return null; + } + ARBVBOKey key = new ARBVBOKey(addr, sz); + ByteBuffer _res = (ByteBuffer) arbVBOCache.get(key); + if (_res == null) { + _res = newDirectByteBuffer(addr, sz); + InternalBufferUtil.nativeOrder(_res); + arbVBOCache.put(key, _res); + } + _res.position(0); + return _res; +} + +/** Encapsulates function pointer for OpenGL function
: LPVOID glMapBuffer(GLenum target, GLenum access); */ +native private long dispatch_glMapBuffer(int target, int access, long glProcAddress); + +native private ByteBuffer newDirectByteBuffer(long addr, int capacity); + + /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ + public void glShaderBinary(int n, java.nio.IntBuffer shaders, int binaryformat, java.nio.Buffer binary, int length) { + throw new GLException("Method \"glShaderBinary\" not available"); + } + + /** Dummy implementation for the ES 2.0 function:
void {@native glShaderBinary}(GLint n, const GLuint * shaders, GLenum binaryformat, const void * binary, GLint length);
Always throws a GLException! */ + public void glShaderBinary(int n, int[] shaders, int shaders_offset, int binaryformat, java.nio.Buffer binary, int length) { + throw new GLException("Method \"glShaderBinary\" not available"); + } + + public void glReleaseShaderCompiler() { + // nothing to do + } + + public void glVertexPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.isVBO()) { + glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); + } + } + public void glColorPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.isVBO()) { + glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); + } + + } + public void glNormalPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.getComponentNumber()!=3) { + throw new GLException("Only 3 components per normal allowed"); + } + if(array.isVBO()) { + glNormalPointer(array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glNormalPointer(array.getComponentType(), array.getStride(), array.getBuffer()); + } + } + public void glTexCoordPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; + if(array.isVBO()) { + glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); + } else { + glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); + } + } + + diff --git a/make/config/nativewindow/x11-CustomJavaCode.java b/make/config/nativewindow/x11-CustomJavaCode.java index 57f37bee7..44bb1e8d0 100644 --- a/make/config/nativewindow/x11-CustomJavaCode.java +++ b/make/config/nativewindow/x11-CustomJavaCode.java @@ -26,9 +26,8 @@ public static native long DefaultVisualID(long display, int screen); - /** public static native long CreateDummyWindow(long display, int screen_index, long visualID); - public static native void DestroyDummyWindow(long display, long window); */ + public static native void DestroyDummyWindow(long display, long window); public static native long dlopen(String name); public static native long dlsym(String name); diff --git a/make/stub_includes/opengl/gl4.c b/make/stub_includes/opengl/gl4.c index cf8a709f7..5e9d87ccd 100644 --- a/make/stub_includes/opengl/gl4.c +++ b/make/stub_includes/opengl/gl4.c @@ -1,11 +1,11 @@ #define GLAPI -// Define GL4_PROTOTYPES so that the OpenGL prototypes in +// Define GL3_PROTOTYPES so that the OpenGL prototypes in // "gl3.h" are parsed. -#define GL4_PROTOTYPES +#define GL3_PROTOTYPES -// Define GL_GL4EXT_PROTOTYPES so that the OpenGL extension prototypes in +// Define GL_GL3EXT_PROTOTYPES so that the OpenGL extension prototypes in // "gl3ext.h" are parsed. -#define GL_GL4EXT_PROTOTYPES +#define GL_GL3EXT_PROTOTYPES -#include +#include diff --git a/make/stub_includes/opengl/gl4bc.c b/make/stub_includes/opengl/gl4bc.c new file mode 100644 index 000000000..262e005f7 --- /dev/null +++ b/make/stub_includes/opengl/gl4bc.c @@ -0,0 +1,18 @@ +#define GLAPI + +// Define GL_GLEXT_PROTOTYPES so that the OpenGL extension prototypes in +// "glext.h" are parsed. +#define GL_GLEXT_PROTOTYPES + +#include + +// Define GL3_PROTOTYPES so that the OpenGL prototypes in +// "gl3.h" are parsed. +#define GL3_PROTOTYPES + +// Define GL_GL3EXT_PROTOTYPES so that the OpenGL extension prototypes in +// "gl3ext.h" are parsed. +#define GL_GL3EXT_PROTOTYPES + +#include + diff --git a/src/jogl/classes/com/jogamp/opengl/impl/ExtensionAvailabilityCache.java b/src/jogl/classes/com/jogamp/opengl/impl/ExtensionAvailabilityCache.java index 082f006e8..1ed0396a9 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/ExtensionAvailabilityCache.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/ExtensionAvailabilityCache.java @@ -174,12 +174,12 @@ public final class ExtensionAvailabilityCache { major[0] = 3; minor[0] = 0; } - while (GLProfile.isValidGLVersion(major[0], minor[0])) { + while (GLContext.isValidGLVersion(major[0], minor[0])) { availableExtensionCache.add("GL_VERSION_" + major[0] + "_" + minor[0]); if (DEBUG) { System.err.println("ExtensionAvailabilityCache: Added GL_VERSION_" + major[0] + "_" + minor[0] + " to known extensions"); } - if(!GLProfile.decrementGLVersion(major, minor)) break; + if(!GLContext.decrementGLVersion(major, minor)) break; } // put a dummy var in here so that the cache is no longer empty even if diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java index 8c5890d1e..3abb69a7f 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java @@ -45,9 +45,10 @@ import java.util.*; import javax.media.opengl.*; import javax.media.nativewindow.*; -import com.jogamp.nativewindow.impl.NWReflection; import com.jogamp.gluegen.runtime.*; import com.jogamp.gluegen.runtime.opengl.*; +import com.jogamp.common.JogampRuntimeException; +import com.jogamp.common.util.ReflectionUtil; public abstract class GLContextImpl extends GLContext { protected GLContextLock lock = new GLContextLock(); @@ -123,108 +124,137 @@ public abstract class GLContextImpl extends GLContext { return (GLDrawableImpl) getGLDrawable(); } - /** - * Platform dependent but harmonized implementation of the ARB_create_context - * mechanism to create a context.
- * The implementation shall verify this context, ie issue a - * MakeCurrent call if necessary.
- * - * @param share the shared context or null - * @param direct flag if direct is requested - * @param ctxOptionFlags ARB_create_context related, see references below - * @param major major number - * @param minor minor number - * @return the valid context if successfull, or null - * - * @see #CTX_PROFILE_COMPAT - * @see #CTX_OPTION_FORWARD - * @see #CTX_OPTION_DEBUG - */ - protected abstract long createContextARBImpl(long share, boolean direct, int ctxOptionFlags, - int major, int minor); + public final GL getGL() { + return gl; + } - private long createContextARB(long share, boolean direct, int ctxOptionFlags, - int majorMax, int minorMax, - int majorMin, int minorMin, - int major[], int minor[]) { - major[0]=majorMax; - minor[0]=minorMax; - long _context=0; + public GL setGL(GL gl) { + if(DEBUG) { + String sgl1 = (null!=this.gl)?this.gl.getClass().toString()+", "+this.gl.toString():new String(""); + String sgl2 = (null!=gl)?gl.getClass().toString()+", "+gl.toString():new String(""); + Exception e = new Exception("setGL (OpenGL "+getGLVersion()+"): "+Thread.currentThread()+", "+sgl1+" -> "+sgl2); + e.printStackTrace(); + } + this.gl = gl; + return gl; + } - while ( 0==_context && - GLProfile.isValidGLVersion(major[0], minor[0]) && - ( major[0]>majorMin || major[0]==majorMin && minor[0] >=minorMin ) ) { + // This is only needed for Mac OS X on-screen contexts + protected void update() throws GLException { } - _context = createContextARBImpl(share, direct, ctxOptionFlags, major[0], minor[0]); + public boolean isSynchronized() { + return !lock.getFailFastMode(); + } - if(0==_context) { - if(!GLProfile.decrementGLVersion(major, minor)) break; - } + public void setSynchronized(boolean isSynchronized) { + lock.setFailFastMode(!isSynchronized); + } + + public abstract Object getPlatformGLExtensions(); + + public void release() throws GLException { + if (!lock.isHeld()) { + throw new GLException("Context not current on current thread"); + } + setCurrent(null); + try { + releaseImpl(); + } finally { + lock.unlock(); } - return _context; } - /** - * Platform independent part of using the ARB_create_context - * mechanism to create a context.
- */ - protected long createContextARB(long share, boolean direct, - int major[], int minor[], int ctp[]) - { - AbstractGraphicsConfiguration config = drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); - GLCapabilities glCaps = (GLCapabilities) config.getChosenCapabilities(); - GLProfile glp = glCaps.getGLProfile(); - long _context = 0; + protected abstract void releaseImpl() throws GLException; - ctp[0] = CTX_IS_ARB_CREATED | CTX_PROFILE_CORE | CTX_OPTION_ANY; // default - boolean isBackwardCompatibility = glp.isGL2() || glp.isGL3bc() || glp.isGL4bc() ; - int majorMin, minorMin; - int majorMax, minorMax; - if( glp.isGL4() ) { - // ?? majorMax=GLProfile.getMaxMajor(); minorMax=GLProfile.getMaxMinor(majorMax); - majorMax=4; minorMax=GLProfile.getMaxMinor(majorMax); - majorMin=4; minorMin=0; - } else if( glp.isGL3() ) { - majorMax=3; minorMax=GLProfile.getMaxMinor(majorMax); - majorMin=3; minorMin=1; - } else /* if( glp.isGL2() ) */ { - majorMax=3; minorMax=0; - majorMin=1; minorMin=1; // our minimum desktop OpenGL runtime requirements + public void destroy() { + if (lock.isHeld()) { + // release current context + release(); } - // Try the requested .. - if(isBackwardCompatibility) { - ctp[0] &= ~CTX_PROFILE_CORE ; - ctp[0] |= CTX_PROFILE_COMPAT ; - } - _context = createContextARB(share, direct, ctp[0], - /* max */ majorMax, minorMax, - /* min */ majorMin, minorMin, - /* res */ major, minor); - - if(0==_context && !isBackwardCompatibility) { - ctp[0] &= ~CTX_PROFILE_COMPAT ; - ctp[0] |= CTX_PROFILE_CORE ; - ctp[0] &= ~CTX_OPTION_ANY ; - ctp[0] |= CTX_OPTION_FORWARD ; - _context = createContextARB(share, direct, ctp[0], - /* max */ majorMax, minorMax, - /* min */ majorMin, minorMin, - /* res */ major, minor); - if(0==_context) { - // Try a compatible one .. even though not requested .. last resort - ctp[0] &= ~CTX_PROFILE_CORE ; - ctp[0] |= CTX_PROFILE_COMPAT ; - ctp[0] &= ~CTX_OPTION_FORWARD ; - ctp[0] |= CTX_OPTION_ANY ; - _context = createContextARB(share, direct, ctp[0], - /* max */ majorMax, minorMax, - /* min */ majorMin, minorMin, - /* res */ major, minor); - } + + // Must hold the lock around the destroy operation to make sure we + // don't destroy the context out from under another thread rendering to it + lock.lock(); + try { + /* FIXME: refactor dependence on Java 2D / JOGL bridge + if (tracker != null) { + // Don't need to do anything for contexts that haven't been + // created yet + if (isCreated()) { + // If we are tracking creation and destruction of server-side + // OpenGL objects, we must decrement the reference count of the + // GLObjectTracker upon context destruction. + // + // Note that we can only eagerly delete these server-side + // objects if there is another context currrent right now + // which shares textures and display lists with this one. + tracker.unref(deletedObjectTracker); + } + } + */ + + // Because we don't know how many other contexts we might be + // sharing with (and it seems too complicated to implement the + // GLObjectTracker's ref/unref scheme for the buffer-related + // optimizations), simply clear the cache of known buffers' sizes + // when we destroy contexts + if (bufferSizeTracker != null) { + bufferSizeTracker.clearCachedBufferSizes(); + } + + if (bufferStateTracker != null) { + bufferStateTracker.clearBufferObjectState(); + } + + if (glStateTracker != null) { + glStateTracker.clearStates(false); + } + + destroyImpl(); + } finally { + lock.unlock(); } - return _context; } + protected abstract void destroyImpl() throws GLException; + + //---------------------------------------------------------------------- + // + + /** + * MakeCurrent functionality, which also issues the creation of the actual OpenGL context.
+ * The complete callgraph for general OpenGL context creation is:
+ *

    + *
  • {@link #makeCurrent} GLContextImpl + *
  • {@link #makeCurrentImpl} Platform Implementation + *
  • {@link #create} Platform Implementation + *
  • If ARB_create_context is supported: + *
      + *
    • {@link #createContextARB} GLContextImpl + *
    • {@link #createContextARBImpl} Platform Implementation + *
    + *

+ * + * Once at startup, ie triggered by the singleton {@link GLDrawableImpl} constructor, + * calling {@link #createContextARB} will query all available OpenGL versions:
+ *
    + *
  • FOR ALL GL* DO: + *
      + *
    • {@link #createContextARBMapVersionsAvailable} + *
        + *
      • {@link #createContextARBVersions} + *
      + *
    • {@link #mapVersionAvailable} + *
    + *

+ * + * @see #makeCurrentImpl + * @see #create + * @see #createContextARB + * @see #createContextARBImpl + * @see #mapVersionAvailable + * @see #destroyContextARBImpl + */ public int makeCurrent() throws GLException { // Support calls to makeCurrent() over and over again with // different contexts without releasing them @@ -287,103 +317,206 @@ public abstract class GLContextImpl extends GLContext { return res; } + /** + * @see #makeCurrent + */ protected abstract int makeCurrentImpl() throws GLException; - public void release() throws GLException { - if (!lock.isHeld()) { - throw new GLException("Context not current on current thread"); - } - setCurrent(null); - try { - releaseImpl(); - } finally { - lock.unlock(); - } - } + /** + * @see #makeCurrent + */ + protected abstract void create() throws GLException ; - protected abstract void releaseImpl() throws GLException; + /** + * Platform dependent but harmonized implementation of the ARB_create_context + * mechanism to create a context.
+ * + * This method is called from {@link #createContextARB}.
+ * + * The implementation shall verify this context with a + * MakeContextCurrent call.
+ * + * @param share the shared context or null + * @param direct flag if direct is requested + * @param ctxOptionFlags ARB_create_context related, see references below + * @param major major number + * @param minor minor number + * @return the valid context if successfull, or null + * + * @see #makeCurrent + * @see #CTX_PROFILE_COMPAT + * @see #CTX_OPTION_FORWARD + * @see #CTX_OPTION_DEBUG + * @see #makeCurrentImpl + * @see #create + * @see #createContextARB + * @see #createContextARBImpl + * @see #destroyContextARBImpl + */ + protected abstract long createContextARBImpl(long share, boolean direct, int ctxOptionFlags, + int major, int minor); - public void destroy() { - if (lock.isHeld()) { - // release current context - release(); - } + /** + * Destroy the context created by {@link #createContextARBImpl}. + * + * @see #makeCurrent + * @see #makeCurrentImpl + * @see #create + * @see #createContextARB + * @see #createContextARBImpl + * @see #destroyContextARBImpl + */ + protected abstract void destroyContextARBImpl(long context); - // Must hold the lock around the destroy operation to make sure we - // don't destroy the context out from under another thread rendering to it - lock.lock(); - try { - /* FIXME: refactor dependence on Java 2D / JOGL bridge - if (tracker != null) { - // Don't need to do anything for contexts that haven't been - // created yet - if (isCreated()) { - // If we are tracking creation and destruction of server-side - // OpenGL objects, we must decrement the reference count of the - // GLObjectTracker upon context destruction. - // - // Note that we can only eagerly delete these server-side - // objects if there is another context currrent right now - // which shares textures and display lists with this one. - tracker.unref(deletedObjectTracker); + /** + * Platform independent part of using the ARB_create_context + * mechanism to create a context.
+ * + * The implementation of {@link #create} shall use this protocol in case the platform supports ARB_create_context.
+ * + * This method may call {@link #createContextARBImpl} and {@link #destroyContextARBImpl}.
+ * + * This method will also query all available native OpenGL context when first called,
+ * usually the first call should happen with the shared GLContext of the DrawableFactory.
+ * + * @see #makeCurrentImpl + * @see #create + * @see #createContextARB + * @see #createContextARBImpl + * @see #destroyContextARBImpl + */ + protected long createContextARB(long share, boolean direct, + int major[], int minor[], int ctp[]) + { + AbstractGraphicsConfiguration config = drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilities glCaps = (GLCapabilities) config.getChosenCapabilities(); + GLProfile glp = glCaps.getGLProfile(); + long _context = 0; + + if( !mappedVersionsAvailableSet ) { + synchronized(mappedVersionsAvailableLock) { + if( !mappedVersionsAvailableSet ) { + createContextARBMapVersionsAvailable(4, false /* compat */); // GL4 + createContextARBMapVersionsAvailable(4, true /* compat */); // GL4bc + createContextARBMapVersionsAvailable(3, false /* compat */); // GL3 + createContextARBMapVersionsAvailable(3, true /* compat */); // GL3bc + createContextARBMapVersionsAvailable(2, true /* compat */); // GL2 + mappedVersionsAvailableSet=true; + } } - } - */ - - // Because we don't know how many other contexts we might be - // sharing with (and it seems too complicated to implement the - // GLObjectTracker's ref/unref scheme for the buffer-related - // optimizations), simply clear the cache of known buffers' sizes - // when we destroy contexts - if (bufferSizeTracker != null) { - bufferSizeTracker.clearCachedBufferSizes(); - } + } - if (bufferStateTracker != null) { - bufferStateTracker.clearBufferObjectState(); - } - - if (glStateTracker != null) { - glStateTracker.clearStates(false); - } - - destroyImpl(); - } finally { - lock.unlock(); + int reqMajor; + if(glp.isGL4()) { + reqMajor=4; + } else if (glp.isGL3()) { + reqMajor=3; + } else /* if (glp.isGL2()) */ { + reqMajor=2; } + boolean compat = glp.isGL2(); // incl GL3bc and GL4bc + + int key = compose8bit(reqMajor, compat?CTX_PROFILE_COMPAT:CTX_PROFILE_CORE, 0, 0); + int val = mappedVersionsAvailable.get( key ); + long _ctx = 0; + if(val>0) { + int _major = getComposed8bit(val, 1); + int _minor = getComposed8bit(val, 2); + int _ctp = getComposed8bit(val, 3); + + _ctx = createContextARBImpl(share, direct, _ctp, _major, _minor); + if(0!=_ctx) { + setGLFunctionAvailability(true, _major, _minor, _ctp); + } + } + return _ctx; } - protected abstract void destroyImpl() throws GLException; + private void createContextARBMapVersionsAvailable(int reqMajor, boolean compat) + { + long _context; + int ctp = CTX_IS_ARB_CREATED | CTX_PROFILE_CORE | CTX_OPTION_ANY; // default + if(compat) { + ctp &= ~CTX_PROFILE_CORE ; + ctp |= CTX_PROFILE_COMPAT ; + } - // This is only needed for Mac OS X on-screen contexts - protected void update() throws GLException { + // FIXME GL3GL4: + // To avoid OpenGL implementation bugs and raise compatibility + // within JOGL, we map to the proper GL version. + // This may change later when GL3 and GL4 drivers become more mature! + // Bug: To ensure GL profile compatibility within the JOGL application + // Bug: we always try to map against the highest GL version, + // Bug: so the use can always cast to a higher one + // Bug: int majorMax=GLContext.getMaxMajor(); + // Bug: int minorMax=GLContext.getMaxMinor(majorMax); + int majorMax, minorMax; + int majorMin, minorMin; + int major[] = new int[1]; + int minor[] = new int[1]; + if( 4 == reqMajor ) { + majorMax=4; minorMax=GLContext.getMaxMinor(majorMax); + majorMin=4; minorMin=0; + } else if( 3 == reqMajor ) { + majorMax=3; minorMax=GLContext.getMaxMinor(majorMax); + majorMin=3; minorMin=1; + } else /* if( glp.isGL2() ) */ { + majorMax=3; minorMax=0; + majorMin=1; minorMin=1; // our minimum desktop OpenGL runtime requirements + } + _context = createContextARBVersions(0, true, ctp, + /* max */ majorMax, minorMax, + /* min */ majorMin, minorMin, + /* res */ major, minor); + + if(0==_context && !compat) { + ctp &= ~CTX_PROFILE_COMPAT ; + ctp |= CTX_PROFILE_CORE ; + ctp &= ~CTX_OPTION_ANY ; + ctp |= CTX_OPTION_FORWARD ; + _context = createContextARBVersions(0, true, ctp, + /* max */ majorMax, minorMax, + /* min */ majorMin, minorMin, + /* res */ major, minor); + if(0==_context) { + // Try a compatible one .. even though not requested .. last resort + ctp &= ~CTX_PROFILE_CORE ; + ctp |= CTX_PROFILE_COMPAT ; + ctp &= ~CTX_OPTION_FORWARD ; + ctp |= CTX_OPTION_ANY ; + _context = createContextARBVersions(0, true, ctp, + /* max */ majorMax, minorMax, + /* min */ majorMin, minorMin, + /* res */ major, minor); + } + } + if(0!=_context) { + destroyContextARBImpl(_context); + mapVersionAvailable(reqMajor, compat, major[0], minor[0], ctp); + } } - public boolean isSynchronized() { - return !lock.getFailFastMode(); - } + private long createContextARBVersions(long share, boolean direct, int ctxOptionFlags, + int majorMax, int minorMax, + int majorMin, int minorMin, + int major[], int minor[]) { + major[0]=majorMax; + minor[0]=minorMax; + long _context=0; - public void setSynchronized(boolean isSynchronized) { - lock.setFailFastMode(!isSynchronized); - } + while ( 0==_context && + GLContext.isValidGLVersion(major[0], minor[0]) && + ( major[0]>majorMin || major[0]==majorMin && minor[0] >=minorMin ) ) { - public final GL getGL() { - return gl; - } + _context = createContextARBImpl(share, direct, ctxOptionFlags, major[0], minor[0]); - public GL setGL(GL gl) { - if(DEBUG) { - String sgl1 = (null!=this.gl)?this.gl.getClass().toString()+", "+this.gl.toString():new String(""); - String sgl2 = (null!=gl)?gl.getClass().toString()+", "+gl.toString():new String(""); - Exception e = new Exception("setGL (OpenGL "+getGLVersion()+"): "+Thread.currentThread()+", "+sgl1+" -> "+sgl2); - e.printStackTrace(); + if(0==_context) { + if(!GLContext.decrementGLVersion(major, minor)) break; + } } - this.gl = gl; - return gl; + return _context; } - public abstract Object getPlatformGLExtensions(); - //---------------------------------------------------------------------- // Managing the actual OpenGL version, usually figured at creation time. // As a last resort, the GL_VERSION string may be used .. @@ -395,7 +528,15 @@ public abstract class GLContextImpl extends GLContext { * Otherwise .. don't touch .. */ protected void setContextVersion(int major, int minor, int ctp) { + if (0==ctp) { + GLException e = new GLException("Invalid GL Version "+major+"."+minor+", ctp "+toHexString(ctp)); + throw e; + } if(major>0 || minor>0) { + if (!GLContext.isValidGLVersion(major, minor)) { + GLException e = new GLException("Invalid GL Version "+major+"."+minor+", ctp "+toHexString(ctp)); + throw e; + } ctxMajorVersion = major; ctxMinorVersion = minor; ctxOptions = ctp; @@ -408,6 +549,7 @@ public abstract class GLContextImpl extends GLContext { if(null==versionStr) { throw new GLException("GL_VERSION is NULL: "+this); } + ctxOptions = ctp; // Set version Version version = new Version(versionStr); @@ -460,7 +602,10 @@ public abstract class GLContextImpl extends GLContext { // private Object createInstance(GLProfile glp, String suffix, Class[] cstrArgTypes, Object[] cstrArgs) { - return NWReflection.createInstance(glp.getGLImplBaseClassName()+suffix, cstrArgTypes, cstrArgs); + try { + return ReflectionUtil.createInstance(glp.getGLImplBaseClassName()+suffix, cstrArgTypes, cstrArgs); + } catch (JogampRuntimeException jre) { /* n/a .. */ } + return null; } /** Create the GL for this context. */ @@ -697,10 +842,6 @@ public abstract class GLContextImpl extends GLContext { return Thread.currentThread().getName(); } - public static String toHexString(long hex) { - return "0x" + Long.toHexString(hex); - } - //---------------------------------------------------------------------- // Helpers for buffer object optimizations diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java index 0cc10b35e..cdf5beb24 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java @@ -42,8 +42,8 @@ package com.jogamp.opengl.impl; import java.nio.*; import javax.media.nativewindow.*; import javax.media.opengl.*; +import com.jogamp.common.util.*; import com.jogamp.gluegen.runtime.*; -import com.jogamp.nativewindow.impl.NWReflection; import java.lang.reflect.*; /** Extends GLDrawableFactory with a few methods for handling @@ -183,6 +183,9 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { protected abstract NativeWindow createOffscreenWindow(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height); + protected abstract GLDrawableImpl getSharedDrawable(); + protected abstract GLContextImpl getSharedContext(); + protected GLDrawableFactoryImpl() { super(); isValid = true; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableImpl.java index 04114a445..2fef8fd80 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableImpl.java @@ -88,7 +88,7 @@ public abstract class GLDrawableImpl implements GLDrawable { protected abstract void swapBuffersImpl(); public static String toHexString(long hex) { - return GLContextImpl.toHexString(hex); + return "0x" + Long.toHexString(hex); } public GLProfile getGLProfile() { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLJNILibLoader.java b/src/jogl/classes/com/jogamp/opengl/impl/GLJNILibLoader.java new file mode 100644 index 000000000..7747b014b --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLJNILibLoader.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. 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. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.opengl.impl; + +// FIXME: refactor Java SE dependencies +//import java.awt.Toolkit; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.HashSet; +import com.jogamp.common.jvm.JNILibLoaderBase; + +public class GLJNILibLoader extends JNILibLoaderBase { + public static void loadNEWT() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + loadLibrary("newt", nativeOSPreload, true); + return null; + } + }); + } + + public static void loadGLDesktop() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + loadLibrary("jogl_desktop", nativeOSPreload, true); + return null; + } + }); + } + + public static void loadES2() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + loadLibrary("jogl_es2", nativeOSPreload, true); + return null; + } + }); + } + + public static void loadES1() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + loadLibrary("jogl_es1", nativeOSPreload, true); + return null; + } + }); + } + + public static void loadCgImpl() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String[] preload = { "nativewindow", "cg", "cgGL" }; + loadLibrary("jogl_cg", preload, true); + return null; + } + }); + } + + private static final String[] nativeOSPreload = { "nativewindow_x11" }; +} + diff --git a/src/jogl/classes/com/jogamp/opengl/impl/NativeLibLoader.java b/src/jogl/classes/com/jogamp/opengl/impl/NativeLibLoader.java deleted file mode 100644 index b6024f240..000000000 --- a/src/jogl/classes/com/jogamp/opengl/impl/NativeLibLoader.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. 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. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.opengl.impl; - -// FIXME: refactor Java SE dependencies -//import java.awt.Toolkit; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.HashSet; -import com.jogamp.nativewindow.impl.NativeLibLoaderBase; - -public class NativeLibLoader extends NativeLibLoaderBase { - public static void loadNEWT() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - loadLibrary("newt", nativeOSPreload, true); - return null; - } - }); - } - - public static void loadGLDesktop() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - loadLibrary("jogl_desktop", nativeOSPreload, true); - return null; - } - }); - } - - public static void loadGLDesktopES12() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - loadLibrary("jogl_gl2es12", nativeOSPreload, true); - return null; - } - }); - } - - public static void loadES2() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - loadLibrary("jogl_es2", nativeOSPreload, true); - return null; - } - }); - } - - public static void loadES1() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - loadLibrary("jogl_es1", nativeOSPreload, true); - return null; - } - }); - } - - public static void loadCgImpl() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - String[] preload = { "nativewindow", "cg", "cgGL" }; - loadLibrary("jogl_cg", preload, true); - return null; - } - }); - } - - private static final String[] nativeOSPreload = { "nativewindow_x11" }; -} - diff --git a/src/jogl/classes/com/jogamp/opengl/impl/ThreadingImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/ThreadingImpl.java index b32ed51b6..1a68f38d4 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/ThreadingImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/ThreadingImpl.java @@ -37,8 +37,9 @@ import java.lang.reflect.InvocationTargetException; import java.security.AccessController; import java.security.PrivilegedAction; +import com.jogamp.common.JogampRuntimeException; +import com.jogamp.common.util.*; import javax.media.nativewindow.NativeWindowFactory; -import com.jogamp.nativewindow.impl.NWReflection; import javax.media.opengl.GLException; /** Implementation of the {@link javax.media.opengl.Threading} class. */ @@ -71,8 +72,8 @@ public class ThreadingImpl { // while holding the AWT lock. The optimization of // makeCurrent / release calls isn't worth these stability // problems. - hasAWT = NWReflection.isClassAvailable("java.awt.Canvas") && - NWReflection.isClassAvailable("javax.media.opengl.awt.GLCanvas"); + hasAWT = ReflectionUtil.isClassAvailable("java.awt.Canvas") && + ReflectionUtil.isClassAvailable("javax.media.opengl.awt.GLCanvas"); String osType = NativeWindowFactory.getNativeWindowType(false); _isX11 = NativeWindowFactory.TYPE_X11.equals(osType); @@ -102,8 +103,8 @@ public class ThreadingImpl { Object threadingPluginObj=null; // try to fetch the AWTThreadingPlugin try { - threadingPluginObj = NWReflection.createInstance("com.jogamp.opengl.impl.awt.AWTThreadingPlugin"); - } catch (Throwable t) { } + threadingPluginObj = ReflectionUtil.createInstance("com.jogamp.opengl.impl.awt.AWTThreadingPlugin"); + } catch (JogampRuntimeException jre) { /* n/a .. */ } return threadingPluginObj; } }); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java index 8c3e9a1c4..48f80977c 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java @@ -95,11 +95,11 @@ public abstract class EGLContext extends GLContextImpl { boolean created = false; if (eglContext == 0) { create(); + created = true; if (DEBUG) { System.err.println(getThreadName() + ": !!! Created GL context 0x" + Long.toHexString(eglContext) + " for " + getClass().getName()); } - created = true; } if (EGL.eglGetCurrentContext() != eglContext) { if (!EGL.eglMakeCurrent(((EGLDrawable)drawable).getDisplay(), @@ -112,7 +112,7 @@ public abstract class EGLContext extends GLContextImpl { } if (created) { - setGLFunctionAvailability(false, -1, -1, -1); + setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_ES|CTX_PROFILE_CORE|CTX_OPTION_ANY); return CONTEXT_CURRENT_NEW; } return CONTEXT_CURRENT; @@ -153,6 +153,10 @@ public abstract class EGLContext extends GLContextImpl { return 0; // FIXME } + protected void destroyContextARBImpl(long _context) { + // FIXME + } + protected void create() throws GLException { long eglDisplay = ((EGLDrawable)drawable).getDisplay(); EGLGraphicsConfiguration config = ((EGLDrawable)drawable).getGraphicsConfiguration(); @@ -218,7 +222,7 @@ public abstract class EGLContext extends GLContextImpl { throw new GLException("Error making context 0x" + Long.toHexString(eglContext) + " current: error code " + EGL.eglGetError()); } - setGLFunctionAvailability(true, contextAttrs[1], 0, CTX_IS_ARB_CREATED|CTX_PROFILE_CORE|CTX_OPTION_ANY); + setGLFunctionAvailability(true, glProfile.usesNativeGLES2()?2:1, 0, CTX_PROFILE_ES|CTX_PROFILE_CORE|CTX_OPTION_ANY); } public boolean isCreated() { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java index 5a193b2ff..4fccf22f8 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java @@ -37,8 +37,10 @@ package com.jogamp.opengl.impl.egl; import javax.media.nativewindow.*; import javax.media.opengl.*; +import com.jogamp.common.JogampRuntimeException; +import com.jogamp.common.util.*; import com.jogamp.opengl.impl.*; -import com.jogamp.nativewindow.impl.*; +import com.jogamp.nativewindow.impl.NullWindow; public class EGLDrawableFactory extends GLDrawableFactoryImpl { @@ -50,8 +52,8 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { // Check for other underlying stuff .. if(NativeWindowFactory.TYPE_X11.equals(NativeWindowFactory.getNativeWindowType(true))) { try { - NWReflection.createInstance("com.jogamp.opengl.impl.x11.glx.X11GLXGraphicsConfigurationFactory"); - } catch (Throwable t) {} + ReflectionUtil.createInstance("com.jogamp.opengl.impl.x11.glx.X11GLXGraphicsConfigurationFactory"); + } catch (JogampRuntimeException jre) { /* n/a .. */ } } } @@ -59,6 +61,10 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { super(); } + + protected final GLDrawableImpl getSharedDrawable() { return null; } + protected final GLContextImpl getSharedContext() { return null; } + public GLDrawableImpl createOnscreenDrawable(NativeWindow target) { if (target == null) { throw new IllegalArgumentException("Null target"); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDynamicLookupHelper.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDynamicLookupHelper.java index 70f0540bf..9e34dc9e9 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDynamicLookupHelper.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDynamicLookupHelper.java @@ -64,9 +64,9 @@ public abstract class EGLDynamicLookupHelper implements DynamicLookupHelper { EGLDynamicLookupHelper tmp=null; try { tmp = new EGLES1DynamicLookupHelper(); - } catch (Throwable t) { + } catch (GLException gle) { if(DEBUG) { - t.printStackTrace(); + gle.printStackTrace(); } } eglES1DynamicLookupHelper = tmp; @@ -74,9 +74,9 @@ public abstract class EGLDynamicLookupHelper implements DynamicLookupHelper { tmp=null; try { tmp = new EGLES2DynamicLookupHelper(); - } catch (Throwable t) { + } catch (GLException gle) { if(DEBUG) { - t.printStackTrace(); + gle.printStackTrace(); } } eglES2DynamicLookupHelper = tmp; @@ -191,9 +191,9 @@ public abstract class EGLDynamicLookupHelper implements DynamicLookupHelper { } if (esProfile==2) { - NativeLibLoader.loadES2(); + GLJNILibLoader.loadES2(); } else if (esProfile==1) { - NativeLibLoader.loadES1(); + GLJNILibLoader.loadES1(); } else { throw new GLException("Unsupported: ES"+esProfile); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLExternalContext.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLExternalContext.java index 0adede4ea..5a8454ea7 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLExternalContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLExternalContext.java @@ -47,7 +47,7 @@ public class EGLExternalContext extends EGLContext { public EGLExternalContext(AbstractGraphicsScreen screen) { super(null, null); GLContextShareSet.contextCreated(this); - setGLFunctionAvailability(false, 0, 0, 0); + setGLFunctionAvailability(false, 0, 0, CTX_IS_ARB_CREATED|CTX_PROFILE_ES|CTX_PROFILE_CORE|CTX_OPTION_ANY); getGLStateTracker().setEnabled(false); // external context usage can't track state in Java } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java index 9182a71de..ebefaf466 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java @@ -88,11 +88,13 @@ public abstract class MacOSXCGLContext extends GLContextImpl protected Map/**/ getExtensionNameMap() { return null; } - protected abstract boolean create(); + protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { + return 0; // FIXME + } - protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { - return 0; // FIXME - } + protected void destroyContextARBImpl(long _context) { + // FIXME + } /** * Creates and initializes an appropriate OpenGl nsContext. Should only be @@ -154,7 +156,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl if (!CGL.makeCurrentContext(nsContext)) { throw new GLException("Error making nsContext current"); } - setGLFunctionAvailability(true, 0, 0, 0); + setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); GLContextShareSet.contextCreated(this); return true; } @@ -165,13 +167,14 @@ public abstract class MacOSXCGLContext extends GLContextImpl } boolean created = false; if ( 0 == cglContext && 0 == nsContext) { - if (!create()) { + create(); + created = 0 != cglContext || 0 != nsContext ; + if(!created) { return CONTEXT_NOT_CURRENT; } if (DEBUG) { System.err.println("!!! Created OpenGL context " + toHexString(nsContext) + " for " + getClass().getName()); } - created = true; } if ( 0 != cglContext ) { @@ -185,7 +188,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl } if (created) { - setGLFunctionAvailability(false, -1, -1, -1); + setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); return CONTEXT_CURRENT_NEW; } return CONTEXT_CURRENT; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java index 906088642..d10434252 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java @@ -43,8 +43,10 @@ import com.jogamp.common.os.DynamicLookupHelper; import java.nio.*; import javax.media.nativewindow.*; import javax.media.opengl.*; +import com.jogamp.common.JogampRuntimeException; +import com.jogamp.common.util.*; import com.jogamp.opengl.impl.*; -import com.jogamp.nativewindow.impl.*; +import com.jogamp.nativewindow.impl.NullWindow; public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl implements DynamicLookupHelper { public MacOSXCGLDrawableFactory() { @@ -55,11 +57,14 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl implements D new MacOSXCGLGraphicsConfigurationFactory(); try { - NWReflection.createInstance("com.jogamp.opengl.impl.macosx.cgl.awt.MacOSXAWTCGLGraphicsConfigurationFactory", + ReflectionUtil.createInstance("com.jogamp.opengl.impl.macosx.cgl.awt.MacOSXAWTCGLGraphicsConfigurationFactory", new Object[] {}); - } catch (Throwable t) { } + } catch (JogampRuntimeException jre) { /* n/a .. */ } } + protected final GLDrawableImpl getSharedDrawable() { return null; } + protected final GLContextImpl getSharedContext() { return null; } + public GLDrawableImpl createOnscreenDrawable(NativeWindow target) { if (target == null) { throw new IllegalArgumentException("Null target"); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java index 248bbb4d6..eba3cf50e 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java @@ -56,7 +56,7 @@ public class MacOSXExternalCGLContext extends MacOSXCGLContext { this.cglContext = cglContext; this.nsContext = nsContext; GLContextShareSet.contextCreated(this); - setGLFunctionAvailability(false, 0, 0, 0); + setGLFunctionAvailability(false, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); getGLStateTracker().setEnabled(false); // external context usage can't track state in Java } @@ -110,8 +110,7 @@ public class MacOSXExternalCGLContext extends MacOSXCGLContext { } } - protected boolean create() { - return true; + protected void create() { } public int makeCurrent() throws GLException { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXOnscreenCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXOnscreenCGLContext.java index 4c64864fa..c4eaee489 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXOnscreenCGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXOnscreenCGLContext.java @@ -115,8 +115,8 @@ public class MacOSXOnscreenCGLContext extends MacOSXCGLContext { CGL.updateContext(nsContext); } - protected boolean create() { - return create(false, false); + protected void create() { + create(false, false); } public void setOpenGLMode(int mode) { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java index 5844b8edd..e90672a1d 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java @@ -59,13 +59,14 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext { boolean created = false; if (nsContext == 0) { - if (!create()) { + create(); + created = 0 != nsContext ; + if(!created) { return CONTEXT_NOT_CURRENT; } if (DEBUG) { System.err.println("!!! Created OpenGL context " + toHexString(nsContext) + " for " + getClass().getName()); } - created = true; } if (!impl.makeCurrent(nsContext)) { @@ -73,7 +74,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext { } if (created) { - setGLFunctionAvailability(false, -1, -1, -1); + setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // Initialize render-to-texture support if requested DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); @@ -134,7 +135,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext { return GLPbuffer.APPLE_FLOAT; } - protected boolean create() { + protected void create() { DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); GLCapabilities capabilities = (GLCapabilities)config.getChosenCapabilities(); if (capabilities.getPbufferFloatingPointBuffers() && @@ -152,9 +153,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext { if (!impl.makeCurrent(nsContext)) { throw new GLException("Error making nsContext current"); } - setGLFunctionAvailability(true, 0, 0, 0); - - return true; + setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); } //--------------------------------------------------------------------------- diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java index 9189b41f3..97a1435bc 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java @@ -73,7 +73,9 @@ public class MacOSXJava2DCGLContext extends MacOSXCGLContext implements Java2DGL protected int makeCurrentImpl() throws GLException { boolean created = false; if (nsContext == 0) { - if (!create()) { + create(); + created = 0 != nsContext ; + if(!created) { return CONTEXT_NOT_CURRENT; } if (DEBUG) { @@ -87,13 +89,13 @@ public class MacOSXJava2DCGLContext extends MacOSXCGLContext implements Java2DGL } if (created) { - setGLFunctionAvailability(false, -1, -1, -1); + setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); return CONTEXT_CURRENT_NEW; } return CONTEXT_CURRENT; } - protected boolean create() { + protected void create() { // Find and configure share context MacOSXCGLContext other = (MacOSXCGLContext) GLContextShareSet.getShareContext(this); long share = 0; @@ -119,11 +121,10 @@ public class MacOSXJava2DCGLContext extends MacOSXCGLContext implements Java2DGL long ctx = Java2D.createOGLContextOnSurface(graphics, share); if (ctx == 0) { - return false; + return; } // FIXME: think about GLContext sharing nsContext = ctx; - return true; } protected void releaseImpl() throws GLException { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java index aae376a6c..e712d8568 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java @@ -56,7 +56,7 @@ public class WindowsExternalWGLContext extends WindowsWGLContext { System.err.println(getThreadName() + ": !!! Created external OpenGL context " + toHexString(hglrc) + " for " + this); } GLContextShareSet.contextCreated(this); - setGLFunctionAvailability(false, 0, 0, 0); + setGLFunctionAvailability(false, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); cfg.updateCapabilitiesByWGL(this); getGLStateTracker().setEnabled(false); // external context usage can't track state in Java } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java index 95706a7a1..0f1f9813f 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java @@ -122,13 +122,18 @@ public class WindowsWGLContext extends GLContextImpl { protected Map/**/ getExtensionNameMap() { return extensionNameMap; } + protected void destroyContextARBImpl(long context) { + WGL.wglMakeCurrent(0, 0); + WGL.wglDeleteContext(context); + } + protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { WindowsWGLDrawableFactory factory = (WindowsWGLDrawableFactory)drawable.getFactoryImpl(); WGLExt wglExt; if(null==factory.getSharedContext()) { wglExt = getWGLExt(); } else { - wglExt = factory.getSharedContext().getWGLExt(); + wglExt = ((WindowsWGLContext)factory.getSharedContext()).getWGLExt(); } boolean ctBwdCompat = 0 != ( CTX_PROFILE_COMPAT & ctp ) ; @@ -235,7 +240,7 @@ public class WindowsWGLContext extends GLContextImpl { if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), temp_hglrc)) { throw new GLException("Error making temp context current: 0x" + Integer.toHexString(WGL.GetLastError())); } - setGLFunctionAvailability(true, 0, 0, 0); + setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); if( createContextARBTried || !isFunctionAvailable("wglCreateContextAttribsARB") || @@ -257,9 +262,6 @@ public class WindowsWGLContext extends GLContextImpl { if(0!=hglrc) { share = 0; // mark as shared .. - // need to update the GL func table .. - setGLFunctionAvailability(true, major[0], minor[0], ctp[0]); - WGL.wglMakeCurrent(0, 0); WGL.wglDeleteContext(temp_hglrc); @@ -302,10 +304,10 @@ public class WindowsWGLContext extends GLContextImpl { boolean created = false; if (hglrc == 0) { create(); + created = true; if (DEBUG) { System.err.println(getThreadName() + ": !!! Created GL context for " + getClass().getName()); } - created = true; } if (WGL.wglGetCurrentContext() != hglrc) { @@ -320,7 +322,7 @@ public class WindowsWGLContext extends GLContextImpl { } if (created) { - setGLFunctionAvailability(false, -1, -1, -1); + setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); WindowsWGLGraphicsConfiguration config = (WindowsWGLGraphicsConfiguration)drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java index bc99338ab..a4bf89b81 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java @@ -45,8 +45,9 @@ import java.util.*; import javax.media.nativewindow.*; import javax.media.nativewindow.windows.*; import javax.media.opengl.*; +import com.jogamp.common.JogampRuntimeException; +import com.jogamp.common.util.*; import com.jogamp.opengl.impl.*; -import com.jogamp.nativewindow.impl.NWReflection; import com.jogamp.nativewindow.impl.NullWindow; public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements DynamicLookupHelper { @@ -66,40 +67,38 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements // The act of constructing them causes them to be registered new WindowsWGLGraphicsConfigurationFactory(); try { - NWReflection.createInstance("com.jogamp.opengl.impl.windows.wgl.awt.WindowsAWTWGLGraphicsConfigurationFactory", + ReflectionUtil.createInstance("com.jogamp.opengl.impl.windows.wgl.awt.WindowsAWTWGLGraphicsConfigurationFactory", new Object[] {}); - } catch (Throwable t) { } + } catch (JogampRuntimeException jre) { /* n/a .. */ } loadOpenGL32Library(); + + sharedDrawable = new WindowsDummyWGLDrawable(this, null); + WindowsWGLContext ctx = (WindowsWGLContext) sharedDrawable.createContext(null); + ctx.makeCurrent(); + canCreateGLPbuffer = ctx.getGL().isExtensionAvailable("GL_ARB_pbuffer"); + ctx.release(); + sharedContext = ctx; + if(null==sharedContext) { + throw new GLException("Couldn't init shared resources"); + } + if (DEBUG) { + System.err.println("!!! SharedContext: "+sharedContext+", pbuffer supported "+canCreateGLPbuffer); + } } WindowsDummyWGLDrawable sharedDrawable=null; WindowsWGLContext sharedContext=null; boolean canCreateGLPbuffer = false; - // package private .. - final WindowsWGLContext getSharedContext() { + protected final GLDrawableImpl getSharedDrawable() { validate(); - return sharedContext; + return sharedDrawable; } - void initShared() { - if(null==sharedDrawable) { - sharedDrawable = new WindowsDummyWGLDrawable(this, null); - WindowsWGLContext _sharedContext = (WindowsWGLContext) sharedDrawable.createContext(null); - { - _sharedContext.makeCurrent(); - canCreateGLPbuffer = _sharedContext.getGL().isExtensionAvailable("GL_ARB_pbuffer"); - _sharedContext.release(); - } - _sharedContext = _sharedContext; - if (DEBUG) { - System.err.println("!!! SharedContext: "+sharedContext+", pbuffer supported "+canCreateGLPbuffer); - } - if(null==sharedContext) { - throw new GLException("Couldn't init shared resources"); - } - } + protected final GLContextImpl getSharedContext() { + validate(); + return sharedContext; } public void shutdown() { @@ -124,7 +123,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements if (target == null) { throw new IllegalArgumentException("Null target"); } - initShared(); return new WindowsOnscreenWGLDrawable(this, target); } @@ -133,13 +131,11 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements if (target == null) { throw new IllegalArgumentException("Null target"); } - initShared(); return new WindowsOffscreenWGLDrawable(this, target); } public boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { validate(); - initShared(); // setup canCreateGLPBuffer return canCreateGLPbuffer; } @@ -148,7 +144,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements if (target == null) { throw new IllegalArgumentException("Null target"); } - initShared(); final List returnList = new ArrayList(); final GLDrawableFactory factory = this; final WindowsWGLContext _sharedContext = sharedContext; @@ -180,7 +175,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements protected NativeWindow createOffscreenWindow(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { validate(); - initShared(); AbstractGraphicsScreen screen = DefaultGraphicsScreen.createDefault(); NullWindow nw = new NullWindow(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( capabilities, chooser, screen) ); @@ -190,7 +184,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements public GLContext createExternalGLContext() { validate(); - initShared(); return WindowsExternalWGLContext.create(this, null); } @@ -201,7 +194,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements public GLDrawable createExternalGLDrawable() { validate(); - initShared(); return WindowsExternalWGLDrawable.create(this, null); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java index c9805fef1..ab3227257 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java @@ -135,7 +135,6 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio pfd = WindowsWGLGraphicsConfiguration.createPixelFormatDescriptor(); // Produce a recommended pixel format selection for the GLCapabilitiesChooser. // Use wglChoosePixelFormatARB if user requested multisampling and if we have it available - factory.initShared(); factory.sharedContext.makeCurrent(); WGLExt wglExt = factory.sharedContext.getWGLExt(); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java index a865e91e8..1f148bead 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java @@ -42,7 +42,7 @@ import com.jogamp.nativewindow.impl.x11.*; public class X11DummyGLXDrawable extends X11OnscreenGLXDrawable { - // private long dummyWindow = 0; + private long dummyWindow = 0; /** * Due to the ATI Bug https://bugzilla.mozilla.org/show_bug.cgi?id=486277, @@ -62,17 +62,15 @@ public class X11DummyGLXDrawable extends X11OnscreenGLXDrawable { X11GraphicsDevice device = (X11GraphicsDevice) screen.getDevice(); long dpy = device.getHandle(); int scrn = screen.getIndex(); - // long visualID = config.getVisualID(); - // System.out.println("X11DummyGLXDrawable: dpy "+toHexString(dpy)+", scrn "+scrn+", visualID "+toHexString(visualID)); + long visualID = config.getVisualID(); X11Lib.XLockDisplay(dpy); try{ - nw.setSurfaceHandle( X11Lib.RootWindow(dpy, scrn) ); - // dummyWindow = X11Lib.CreateDummyWindow(dpy, scrn, visualID); - // nw.setSurfaceHandle( dummyWindow ); + dummyWindow = X11Lib.CreateDummyWindow(dpy, scrn, visualID); } finally { X11Lib.XUnlockDisplay(dpy); } + nw.setSurfaceHandle( dummyWindow ); } public void setSize(int width, int height) { @@ -87,11 +85,10 @@ public class X11DummyGLXDrawable extends X11OnscreenGLXDrawable { } public void destroy() { - /** if(0!=dummyWindow) { X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); long dpy = config.getScreen().getDevice().getHandle(); X11Lib.DestroyDummyWindow(dpy, dummyWindow); - } */ + } } } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java index b8f25aad7..139c0deed 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java @@ -55,7 +55,7 @@ public class X11ExternalGLXContext extends X11GLXContext { super(drawable, null); this.context = context; GLContextShareSet.contextCreated(this); - setGLFunctionAvailability(false, 0, 0, 0); + setGLFunctionAvailability(false, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); getGLStateTracker().setEnabled(false); // external context usage can't track state in Java } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java index f5e291c5f..7d907bf28 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java @@ -103,12 +103,31 @@ public abstract class X11GLXContext extends GLContextImpl { protected Map/**/ getExtensionNameMap() { return extensionNameMap; } - /** Helper routine which usually just turns around and calls - * createContext (except for pbuffers, which use a different context - * creation mechanism). Should only be called by {@link - * makeCurrentImpl()}. - */ - protected abstract void create(); + protected boolean glXMakeContextCurrent(long dpy, long writeDrawable, long readDrawable, long ctx) { + boolean res = false; + + try { + res = GLX.glXMakeContextCurrent(dpy, writeDrawable, readDrawable, ctx); + } catch (RuntimeException re) { + if(DEBUG) { + System.err.println("X11GLXContext.glXMakeContextCurrent failed: "+re+", with "+ + "dpy "+toHexString(dpy)+ + ", write "+toHexString(writeDrawable)+ + ", read "+toHexString(readDrawable)+ + ", ctx "+toHexString(ctx)); + re.printStackTrace(); + } + } + return res; + } + + protected void destroyContextARBImpl(long _context) { + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + long display = config.getScreen().getDevice().getHandle(); + + glXMakeContextCurrent(display, 0, 0, 0); + GLX.glXDestroyContext(display, _context); + } protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { X11GLXDrawableFactory factory = (X11GLXDrawableFactory)drawable.getFactoryImpl(); @@ -119,7 +138,7 @@ public abstract class X11GLXContext extends GLContextImpl { if(null==factory.getSharedContext()) { glXExt = getGLXExt(); } else { - glXExt = factory.getSharedContext().getGLXExt(); + glXExt = ((X11GLXContext)factory.getSharedContext()).getGLXExt(); } boolean ctBwdCompat = 0 != ( CTX_PROFILE_COMPAT & ctp ) ; @@ -156,20 +175,27 @@ public abstract class X11GLXContext extends GLContextImpl { } } - _context = glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0); + try { + _context = glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0); + } catch (RuntimeException re) { + if(DEBUG) { + System.err.println("X11GLXContext.createContextARB glXCreateContextAttribsARB failed: "+re+", with "+getGLVersion(null, major, minor, ctp, "@creation")); + re.printStackTrace(); + } + } if(0==_context) { if(DEBUG) { System.err.println("X11GLXContext.createContextARB couldn't create "+getGLVersion(null, major, minor, ctp, "@creation")); } } else { - if (!GLX.glXMakeContextCurrent(display, - drawable.getNativeWindow().getSurfaceHandle(), - drawableRead.getNativeWindow().getSurfaceHandle(), - _context)) { + if (!glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawableRead.getNativeWindow().getSurfaceHandle(), + _context)) { if(DEBUG) { System.err.println("X11GLXContext.createContextARB couldn't make current "+getGLVersion(null, major, minor, ctp, "@creation")); } - GLX.glXMakeContextCurrent(display, 0, 0, 0); + glXMakeContextCurrent(display, 0, 0, 0); GLX.glXDestroyContext(display, _context); _context = 0; } @@ -179,7 +205,7 @@ public abstract class X11GLXContext extends GLContextImpl { /** * Creates and initializes an appropriate OpenGL context. Should only be - * called by {@link create()}. + * called by {@link #create()}. * Note: The direct parameter may be overwritten by the direct state of a shared context. */ protected void createContext(boolean direct) { @@ -213,13 +239,13 @@ public abstract class X11GLXContext extends GLContextImpl { if (context == 0) { throw new GLException("Unable to create context(0)"); } - if (!GLX.glXMakeContextCurrent(display, - drawable.getNativeWindow().getSurfaceHandle(), - drawableRead.getNativeWindow().getSurfaceHandle(), - context)) { + if (!glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawableRead.getNativeWindow().getSurfaceHandle(), + context)) { throw new GLException("Error making temp context(0) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); } - setGLFunctionAvailability(true, 0, 0, 0); // use GL_VERSION + setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // use GL_VERSION return; } @@ -245,21 +271,21 @@ public abstract class X11GLXContext extends GLContextImpl { if (temp_context == 0) { throw new GLException("Unable to create temp OpenGL context(1)"); } - if (!GLX.glXMakeContextCurrent(display, - drawable.getNativeWindow().getSurfaceHandle(), - drawableRead.getNativeWindow().getSurfaceHandle(), - temp_context)) { + if (!glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawableRead.getNativeWindow().getSurfaceHandle(), + temp_context)) { throw new GLException("Error making temp context(1) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); } - setGLFunctionAvailability(true, 0, 0, 0); // use GL_VERSION + setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // use GL_VERSION if( createContextARBTried || !isFunctionAvailable("glXCreateContextAttribsARB") || !isExtensionAvailable("GLX_ARB_create_context") ) { if(glp.isGL3()) { - GLX.glXMakeContextCurrent(display, 0, 0, 0); + glXMakeContextCurrent(display, 0, 0, 0); GLX.glXDestroyContext(display, temp_context); - throw new GLException("Unable to create OpenGL >= 3.1 context (no GLX_ARB_create_context)"); + throw new GLException("Unable to create OpenGL >= 3.1 context (failed GLX_ARB_create_context), GLProfile "+glp+", Drawable "+drawable); } // continue with temp context for GL < 3.0 @@ -271,22 +297,19 @@ public abstract class X11GLXContext extends GLContextImpl { } if(0!=context) { - // need to update the GL func table .. - setGLFunctionAvailability(true, major[0], minor[0], ctp[0]); - if(0!=temp_context) { - GLX.glXMakeContextCurrent(display, 0, 0, 0); + glXMakeContextCurrent(display, 0, 0, 0); GLX.glXDestroyContext(display, temp_context); - if (!GLX.glXMakeContextCurrent(display, - drawable.getNativeWindow().getSurfaceHandle(), - drawableRead.getNativeWindow().getSurfaceHandle(), - context)) { + if (!glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawableRead.getNativeWindow().getSurfaceHandle(), + context)) { throw new GLException("Cannot make previous verified context current"); } } } else { if(!glp.isGL2()) { - GLX.glXMakeContextCurrent(display, 0, 0, 0); + glXMakeContextCurrent(display, 0, 0, 0); GLX.glXDestroyContext(display, temp_context); throw new GLException("X11GLXContext.createContext failed, but context > GL2 requested "+getGLVersion(null, major[0], minor[0], ctp[0], "@creation")+", "); } @@ -296,11 +319,11 @@ public abstract class X11GLXContext extends GLContextImpl { // continue with temp context for GL <= 3.0 context = temp_context; - if (!GLX.glXMakeContextCurrent(display, - drawable.getNativeWindow().getSurfaceHandle(), - drawableRead.getNativeWindow().getSurfaceHandle(), - context)) { - GLX.glXMakeContextCurrent(display, 0, 0, 0); + if (!glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawableRead.getNativeWindow().getSurfaceHandle(), + context)) { + glXMakeContextCurrent(display, 0, 0, 0); GLX.glXDestroyContext(display, temp_context); throw new GLException("Error making context(1) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); } @@ -349,19 +372,19 @@ public abstract class X11GLXContext extends GLContextImpl { boolean created = false; if (context == 0) { create(); + created = true; GLContextShareSet.contextCreated(this); if (DEBUG) { System.err.println(getThreadName() + ": !!! Created GL context for " + getClass().getName()); } - created = true; } if (GLX.glXGetCurrentContext() != context) { - if (!GLX.glXMakeContextCurrent(dpy, - drawable.getNativeWindow().getSurfaceHandle(), - drawableRead.getNativeWindow().getSurfaceHandle(), - context)) { + if (!glXMakeContextCurrent(dpy, + drawable.getNativeWindow().getSurfaceHandle(), + drawableRead.getNativeWindow().getSurfaceHandle(), + context)) { throw new GLException("Error making context current: "+this); } if (DEBUG && (VERBOSE || created)) { @@ -374,7 +397,7 @@ public abstract class X11GLXContext extends GLContextImpl { } if (created) { - setGLFunctionAvailability(false, -1, -1, -1); + setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); return CONTEXT_CURRENT_NEW; } return CONTEXT_CURRENT; @@ -386,7 +409,7 @@ public abstract class X11GLXContext extends GLContextImpl { protected void releaseImplAfterLock() throws GLException { getDrawableImpl().getFactoryImpl().lockToolkit(); try { - if (!GLX.glXMakeContextCurrent(drawable.getNativeWindow().getDisplayHandle(), 0, 0, 0)) { + if (!glXMakeContextCurrent(drawable.getNativeWindow().getDisplayHandle(), 0, 0, 0)) { throw new GLException("Error freeing OpenGL context"); } } finally { @@ -494,6 +517,10 @@ public abstract class X11GLXContext extends GLContextImpl { private int hasSwapIntervalSGI = 0; protected void setSwapIntervalImpl(int interval) { + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilities glCaps = (GLCapabilities) config.getChosenCapabilities(); + if(!glCaps.isOnscreen()) return; + getDrawableImpl().getFactoryImpl().lockToolkit(); try { GLXExt glXExt = getGLXExt(); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java index 0d74bb791..f331ad2a2 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java @@ -43,8 +43,9 @@ import javax.media.nativewindow.x11.*; import javax.media.opengl.*; import com.jogamp.gluegen.runtime.opengl.*; import com.jogamp.opengl.impl.*; +import com.jogamp.common.JogampRuntimeException; +import com.jogamp.common.util.*; import com.jogamp.nativewindow.impl.NullWindow; -import com.jogamp.nativewindow.impl.NWReflection; import com.jogamp.nativewindow.impl.x11.*; public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements DynamicLookupHelper { @@ -58,9 +59,9 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna // The act of constructing them causes them to be registered new X11GLXGraphicsConfigurationFactory(); try { - NWReflection.createInstance("com.jogamp.opengl.impl.x11.glx.awt.X11AWTGLXGraphicsConfigurationFactory", + ReflectionUtil.createInstance("com.jogamp.opengl.impl.x11.glx.awt.X11AWTGLXGraphicsConfigurationFactory", new Object[] {}); - } catch (Throwable t) { } + } catch (JogampRuntimeException jre) { /* n/a .. */ } X11GraphicsDevice sharedDevice = new X11GraphicsDevice(X11Util.createThreadLocalDisplay(null)); vendorName = GLXUtil.getVendorName(sharedDevice.getHandle()); @@ -70,9 +71,20 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna X11Util.markGlobalDisplayUndeletable(sharedDevice.getHandle()); // ATI hack .. } sharedScreen = new X11GraphicsScreen(sharedDevice, 0); + X11Lib.XLockDisplay(sharedScreen.getDevice().getHandle()); + sharedDrawable = new X11DummyGLXDrawable(sharedScreen, this, null); + X11GLXContext ctx = (X11GLXContext) sharedDrawable.createContext(null); + ctx.makeCurrent(); + ctx.release(); + sharedContext = ctx; + X11Lib.XUnlockDisplay(sharedScreen.getDevice().getHandle()); + if(null==sharedContext) { + throw new GLException("Couldn't init shared resources"); + } if (DEBUG) { System.err.println("!!! Vendor: "+vendorName+", ATI: "+isVendorATI+", NV: "+isVendorNVIDIA); System.err.println("!!! SharedScreen: "+sharedScreen); + System.err.println("!!! SharedContext: "+sharedContext); } } @@ -88,30 +100,14 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna private X11DummyGLXDrawable sharedDrawable=null; private X11GLXContext sharedContext=null; - // package private .. - final X11GLXContext getSharedContext() { + protected final GLDrawableImpl getSharedDrawable() { validate(); - return sharedContext; + return sharedDrawable; } - private void initShared() { - if(null==sharedDrawable) { - X11Lib.XLockDisplay(sharedScreen.getDevice().getHandle()); - sharedDrawable = new X11DummyGLXDrawable(sharedScreen, this, null); - X11GLXContext _sharedContext = (X11GLXContext) sharedDrawable.createContext(null); - { - _sharedContext.makeCurrent(); - _sharedContext.release(); - } - sharedContext = _sharedContext; - X11Lib.XUnlockDisplay(sharedScreen.getDevice().getHandle()); - if (DEBUG) { - System.err.println("!!! SharedContext: "+sharedContext); - } - if(null==sharedContext) { - throw new GLException("Couldn't init shared resources"); - } - } + protected final GLContextImpl getSharedContext() { + validate(); + return sharedContext; } public void shutdown() { @@ -145,7 +141,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna if (target == null) { throw new IllegalArgumentException("Null target"); } - initShared(); if( isVendorATI() ) { X11Util.markGlobalDisplayUndeletable(target.getDisplayHandle()); // ATI hack .. } @@ -157,11 +152,9 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna if (target == null) { throw new IllegalArgumentException("Null target"); } - initShared(); if( isVendorATI() ) { X11Util.markGlobalDisplayUndeletable(target.getDisplayHandle()); // ATI hack .. } - initShared(); return new X11OffscreenGLXDrawable(this, target); } @@ -203,7 +196,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna if (target == null) { throw new IllegalArgumentException("Null target"); } - initShared(); GLDrawableImpl pbufferDrawable; @@ -234,7 +226,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna protected NativeWindow createOffscreenWindow(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { validate(); - initShared(); X11Lib.XLockDisplay(sharedScreen.getDevice().getHandle()); NullWindow nw = new NullWindow(X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capabilities, chooser, sharedScreen)); X11Lib.XUnlockDisplay(sharedScreen.getDevice().getHandle()); @@ -244,19 +235,16 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna public GLContext createExternalGLContext() { validate(); - initShared(); return X11ExternalGLXContext.create(this, null); } public boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device) { validate(); - initShared(); return canCreateGLPbuffer(device); } public GLDrawable createExternalGLDrawable() { validate(); - initShared(); return X11ExternalGLXDrawable.create(this, null); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11PbufferGLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11PbufferGLXContext.java index e0993abc3..1b70adf6b 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11PbufferGLXContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11PbufferGLXContext.java @@ -68,33 +68,6 @@ public class X11PbufferGLXContext extends X11GLXContext { } protected void create() { - if (DEBUG) { - System.err.println("Creating context for pbuffer " + drawable.getWidth() + - " x " + drawable.getHeight()); - } - - // Create a gl context for the p-buffer. - X11GLXContext other = (X11GLXContext) GLContextShareSet.getShareContext(this); - long share = 0; - if (other != null) { - share = other.getContext(); - if (share == 0) { - throw new GLException("GLContextShareSet returned an invalid OpenGL context"); - } - } - X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration) - getGLDrawable().getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); - - context = GLX.glXCreateNewContext(drawable.getNativeWindow().getDisplayHandle(), - config.getFBConfig(), GLX.GLX_RGBA_TYPE, share, true); - if (context == 0) { - throw new GLException("pbuffer creation error: glXCreateNewContext() failed"); - } - GLContextShareSet.contextCreated(this); - - if (DEBUG) { - System.err.println("Created context for pbuffer " + drawable.getWidth() + - " x " + drawable.getHeight()); - } + createContext(true); } } diff --git a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java index ad230a415..04b994198 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java +++ b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java @@ -1,9 +1,9 @@ package com.jogamp.opengl.util; +import com.jogamp.common.util.*; import javax.media.opengl.*; import javax.media.opengl.fixedfunc.*; -import com.jogamp.nativewindow.impl.NWReflection; import java.nio.*; import java.util.Iterator; import java.util.ArrayList; @@ -341,9 +341,9 @@ public class ImmModeSink { } else { Class clazz = indices.getClass(); int type=-1; - if(NWReflection.instanceOf(clazz, ByteBuffer.class.getName())) { + if(ReflectionUtil.instanceOf(clazz, ByteBuffer.class.getName())) { type = GL.GL_UNSIGNED_BYTE; - } else if(NWReflection.instanceOf(clazz, ShortBuffer.class.getName())) { + } else if(ReflectionUtil.instanceOf(clazz, ShortBuffer.class.getName())) { type = GL.GL_UNSIGNED_SHORT; } if(0>type) { diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/FixedFuncUtil.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/FixedFuncUtil.java index f00357bfb..7ec4ac50e 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/FixedFuncUtil.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/FixedFuncUtil.java @@ -28,7 +28,7 @@ public class FixedFuncUtil { gl.getContext().setGL(impl); return impl; } - throw new GLException("GL Object is neither GL2ES1 nor GL2ES2"); + throw new GLException("GL Object is neither GL2ES1 nor GL2ES2: "+gl.getContext()); } /** diff --git a/src/jogl/classes/javax/media/opengl/GL4.java b/src/jogl/classes/javax/media/opengl/GL4.java deleted file mode 100644 index 29a316333..000000000 --- a/src/jogl/classes/javax/media/opengl/GL4.java +++ /dev/null @@ -1,5 +0,0 @@ -package javax.media.opengl; - -public interface GL4 extends GLBase { -} - diff --git a/src/jogl/classes/javax/media/opengl/GL4bc.java b/src/jogl/classes/javax/media/opengl/GL4bc.java deleted file mode 100644 index be1131e91..000000000 --- a/src/jogl/classes/javax/media/opengl/GL4bc.java +++ /dev/null @@ -1,5 +0,0 @@ -package javax.media.opengl; - -public interface GL4bc extends GL4 { -} - diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index 833ebf192..e5b499af9 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -40,6 +40,7 @@ package javax.media.opengl; import java.util.HashMap; +import com.jogamp.common.util.IntIntHashMap; /** Abstraction for an OpenGL rendering context. In order to perform OpenGL rendering, a context must be "made current" on the current @@ -261,6 +262,12 @@ public abstract class GLContext { StringBuffer sb = new StringBuffer(); sb.append(getClass().getName()); sb.append(" [OpenGL "); + sb.append(getGLVersionMajor()); + sb.append("."); + sb.append(getGLVersionMinor()); + sb.append(", options 0x"); + sb.append(Integer.toHexString(ctxOptions)); + sb.append(", "); sb.append(getGLVersion()); sb.append(", "); sb.append(getGL()); @@ -284,7 +291,7 @@ public abstract class GLContext { public abstract String getPlatformExtensionsString(); public final int getGLVersionMajor() { return ctxMajorVersion; } - public final int getGLVersionMinor() { return ctxMajorVersion; } + public final int getGLVersionMinor() { return ctxMinorVersion; } public final boolean isGLCompatibilityProfile() { return ( 0 != ( CTX_PROFILE_COMPAT & ctxOptions ) ); } public final boolean isGLForwardCompatible() { return ( 0 != ( CTX_OPTION_FORWARD & ctxOptions ) ); } public final boolean isCreatedWithARBMethod() { return ( 0 != ( CTX_IS_ARB_CREATED & ctxOptions ) ); } @@ -342,9 +349,181 @@ public abstract class GLContext { /** ARB_create_context related: core profile */ protected static final int CTX_PROFILE_CORE = 1 << 2; /** ARB_create_context related: flag forward compatible */ - protected static final int CTX_OPTION_FORWARD = 1 << 3; + protected static final int CTX_PROFILE_ES = 1 << 3; + /** ARB_create_context related: flag forward compatible */ + protected static final int CTX_OPTION_FORWARD = 1 << 4; /** ARB_create_context related: not flag forward compatible */ - protected static final int CTX_OPTION_ANY = 1 << 4; + protected static final int CTX_OPTION_ANY = 1 << 5; /** ARB_create_context related: flag debug */ - protected static final int CTX_OPTION_DEBUG = 1 << 5; + protected static final int CTX_OPTION_DEBUG = 1 << 6; + + + public final boolean isGL4bc() { + return ctxMajorVersion>=4 && CTX_PROFILE_COMPAT==(ctxOptions & (CTX_PROFILE_COMPAT|CTX_PROFILE_ES)); + } + + public final boolean isGL4() { + return ctxMajorVersion>=4 && 0==(ctxOptions & (CTX_PROFILE_ES)); + } + + public final boolean isGL3bc() { + return ctxMajorVersion>=3 && CTX_PROFILE_COMPAT==(ctxOptions & (CTX_PROFILE_COMPAT|CTX_PROFILE_ES)); + } + + public final boolean isGL3() { + return ctxMajorVersion>=3 && 0==(ctxOptions & (CTX_PROFILE_ES)); + } + + public final boolean isGL2() { + return ctxMajorVersion>=1 && CTX_PROFILE_COMPAT==(ctxOptions & (CTX_PROFILE_COMPAT|CTX_PROFILE_ES)); + } + + public final boolean isGLES1() { + return ctxMajorVersion==1 && CTX_PROFILE_ES==(ctxOptions & CTX_PROFILE_ES); + } + + public final boolean isGLES2() { + return ctxMajorVersion==2 && CTX_PROFILE_ES==(ctxOptions & CTX_PROFILE_ES); + } + + public final boolean isGLES() { + return CTX_PROFILE_ES==(ctxOptions & CTX_PROFILE_ES); + } + + public final boolean isGL2ES1() { + return isGL2() || isGLES1() ; + } + + public final boolean isGL2ES2() { + return isGL2() || isGL3() || isGLES2() ; + } + + public final boolean isGL2GL3() { + return isGL2() || isGL3(); + } + + public final boolean hasGLSL() { + return isGL2ES2() ; + } + + public static final int GL_VERSIONS[][] = { + /* 0.*/ { -1 }, + /* 1.*/ { 0, 1, 2, 3, 4, 5 }, + /* 2.*/ { 0, 1 }, + /* 3.*/ { 0, 1, 2, 3 }, + /* 4.*/ { 0 } }; + + public static final int getMaxMajor() { + return GL_VERSIONS.length-1; + } + + public static final int getMaxMinor(int major) { + if(1>major || major>=GL_VERSIONS.length) return -1; + return GL_VERSIONS[major].length-1; + } + + public static final boolean isValidGLVersion(int major, int minor) { + if(1>major || major>=GL_VERSIONS.length) return false; + if(0>minor || minor>=GL_VERSIONS[major].length) return false; + return true; + } + + public static final boolean decrementGLVersion(int major[], int minor[]) { + if(null==major || major.length<1 ||null==minor || minor.length<1) { + throw new GLException("invalid array arguments"); + } + int m = major[0]; + int n = minor[0]; + if(!isValidGLVersion(m, n)) return false; + + // decrement .. + n -= 1; + if(n < 0) { + m -= 1; + n = GL_VERSIONS[m].length-1; + } + if(!isValidGLVersion(m, n)) return false; + major[0]=m; + minor[0]=n; + + return true; + } + + public static final boolean isGLVersionAvailable(int major, boolean compatibility) { + int key = compose8bit(major, compatibility?CTX_PROFILE_COMPAT:CTX_PROFILE_CORE, 0, 0); + int val = mappedVersionsAvailable.get( key ); + return val>0; + } + public static final boolean isGL4bcAvailable() { return isGLVersionAvailable(4, true); } + public static final boolean isGL4Available() { return isGLVersionAvailable(4, false); } + public static final boolean isGL3bcAvailable() { return isGLVersionAvailable(3, true); } + public static final boolean isGL3Available() { return isGLVersionAvailable(3, false); } + public static final boolean isGL2Available() { return isGLVersionAvailable(2, true); } + + protected static final IntIntHashMap mappedVersionsAvailable; + protected static volatile boolean mappedVersionsAvailableSet; + protected static Object mappedVersionsAvailableLock; + + static { + mappedVersionsAvailableLock = new Object(); + mappedVersionsAvailableSet = false; + mappedVersionsAvailable = new IntIntHashMap(); + mappedVersionsAvailable.setKeyNotFoundValue(-1); + } + + /** + * Called by {@link GLContextImpl#createContextARBMapVersionsAvailable} not intendet to be used by + * implementations. However, if {@link #createContextARB} is not being used within the + * {@link GLDrawableImpl} constructor, GLProfile has to map the available versions. + * + * @see #createContextARBMapVersionsAvailable + */ + protected static void mapVersionAvailable(int reqMajor, boolean reqCompat, int resMajor, int resMinor, int resCtp) + { + int key = compose8bit(reqMajor, reqCompat?CTX_PROFILE_COMPAT:CTX_PROFILE_CORE, 0, 0); + int val = compose8bit(resMajor, resMinor, resCtp, 0); + mappedVersionsAvailable.put( key, val ); + } + + protected static int compose8bit(int one, int two, int three, int four) { + return ( ( one & 0x000000FF ) << 24 ) | + ( ( two & 0x000000FF ) << 16 ) | + ( ( three & 0x000000FF ) << 8 ) | + ( ( four & 0x000000FF ) ) ; + } + + protected static int getComposed8bit(int bits32, int which ) { + switch (which) { + case 1: return ( bits32 & 0xFF000000 ) >> 24 ; + case 2: return ( bits32 & 0x00FF0000 ) >> 16 ; + case 3: return ( bits32 & 0x0000FF00 ) >> 8 ; + case 4: return ( bits32 & 0xFF0000FF ) ; + } + throw new GLException("argument which out of range: "+which); + } + + protected static String composed8BitToString(int bits32, boolean hex1, boolean hex2, boolean hex3, boolean hex4) { + int a = getComposed8bit(bits32, 1); + int b = getComposed8bit(bits32, 2); + int c = getComposed8bit(bits32, 3); + int d = getComposed8bit(bits32, 4); + return "["+toString(a, hex1)+", "+toString(b, hex2)+", "+toString(c, hex3)+", "+toString(d, hex4)+"]"; + } + + protected static String toString(int val, boolean hex) { + if(hex) { + return "0x" + Integer.toHexString(val); + } + return String.valueOf(val); + } + + protected static String toHexString(int hex) { + return "0x" + Integer.toHexString(hex); + } + + protected static String toHexString(long hex) { + return "0x" + Long.toHexString(hex); + } + } + diff --git a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java index 80c2c10e2..b02bffb61 100644 --- a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java +++ b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java @@ -42,8 +42,9 @@ package javax.media.opengl; import javax.media.nativewindow.*; import java.security.*; +import com.jogamp.common.JogampRuntimeException; +import com.jogamp.common.util.*; import com.jogamp.opengl.impl.*; -import com.jogamp.nativewindow.impl.NWReflection; /**

Provides a virtual machine- and operating system-independent mechanism for creating {@link GLDrawable}s.

@@ -96,51 +97,50 @@ public abstract class GLDrawableFactory { static { GLDrawableFactory tmp = null; try { - tmp = (GLDrawableFactory) NWReflection.createInstance("com.jogamp.opengl.impl.egl.EGLDrawableFactory"); - } catch (Throwable t) { + tmp = (GLDrawableFactory) ReflectionUtil.createInstance("com.jogamp.opengl.impl.egl.EGLDrawableFactory"); + } catch (JogampRuntimeException jre) { if (GLProfile.DEBUG) { System.err.println("GLDrawableFactory.static - EGLDrawableFactory - not available"); - t.printStackTrace(); + jre.printStackTrace(); } } eglFactory = tmp; nativeOSType = NativeWindowFactory.getNativeWindowType(true); - String factoryClassName = null; tmp = null; - try { - factoryClassName = Debug.getProperty("jogl.gldrawablefactory.class.name", true, AccessController.getContext()); - if (null == factoryClassName) { - if ( nativeOSType.equals(NativeWindowFactory.TYPE_X11) ) { - factoryClassName = "com.jogamp.opengl.impl.x11.glx.X11GLXDrawableFactory"; - } else if ( nativeOSType.equals(NativeWindowFactory.TYPE_WINDOWS) ) { - factoryClassName = "com.jogamp.opengl.impl.windows.wgl.WindowsWGLDrawableFactory"; - } else if ( nativeOSType.equals(NativeWindowFactory.TYPE_MACOSX) ) { - if(NWReflection.isClassAvailable(macosxFactoryClassNameAWTCGL)) { - factoryClassName = macosxFactoryClassNameAWTCGL; - } else { - factoryClassName = macosxFactoryClassNameCGL; - } + String factoryClassName = Debug.getProperty("jogl.gldrawablefactory.class.name", true, AccessController.getContext()); + if (null == factoryClassName) { + if ( nativeOSType.equals(NativeWindowFactory.TYPE_X11) ) { + factoryClassName = "com.jogamp.opengl.impl.x11.glx.X11GLXDrawableFactory"; + } else if ( nativeOSType.equals(NativeWindowFactory.TYPE_WINDOWS) ) { + factoryClassName = "com.jogamp.opengl.impl.windows.wgl.WindowsWGLDrawableFactory"; + } else if ( nativeOSType.equals(NativeWindowFactory.TYPE_MACOSX) ) { + if(ReflectionUtil.isClassAvailable(macosxFactoryClassNameAWTCGL)) { + factoryClassName = macosxFactoryClassNameAWTCGL; } else { - // may use egl*Factory .. - if (GLProfile.DEBUG) { - System.err.println("GLDrawableFactory.static - No native OS Factory for: "+nativeOSType+"; May use EGLDrawableFactory, if available." ); - } + factoryClassName = macosxFactoryClassNameCGL; } - } - if (null != factoryClassName) { + } else { + // may use egl*Factory .. if (GLProfile.DEBUG) { - System.err.println("GLDrawableFactory.static - Native OS Factory for: "+nativeOSType+": "+factoryClassName); + System.err.println("GLDrawableFactory.static - No native OS Factory for: "+nativeOSType+"; May use EGLDrawableFactory, if available." ); } - tmp = (GLDrawableFactory) NWReflection.createInstance(factoryClassName); - } - } catch (Throwable t) { - if (GLProfile.DEBUG) { - System.err.println("GLDrawableFactory.static - Native Platform: "+nativeOSType+" - not available: "+factoryClassName); - t.printStackTrace(); } } + if (null != factoryClassName) { + if (GLProfile.DEBUG) { + System.err.println("GLDrawableFactory.static - Native OS Factory for: "+nativeOSType+": "+factoryClassName); + } + try { + tmp = (GLDrawableFactory) ReflectionUtil.createInstance(factoryClassName); + } catch (JogampRuntimeException jre) { + if (GLProfile.DEBUG) { + System.err.println("GLDrawableFactory.static - Native Platform: "+nativeOSType+" - not available: "+factoryClassName); + jre.printStackTrace(); + } + } + } nativeOSFactory = tmp; } diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java index e1fc9f53f..9e3a532e6 100644 --- a/src/jogl/classes/javax/media/opengl/GLProfile.java +++ b/src/jogl/classes/javax/media/opengl/GLProfile.java @@ -36,12 +36,13 @@ package javax.media.opengl; +import com.jogamp.common.util.*; import com.jogamp.opengl.impl.DRIHack; import com.jogamp.opengl.impl.Debug; -import com.jogamp.opengl.impl.NativeLibLoader; -import com.jogamp.nativewindow.impl.NWReflection; -import com.jogamp.nativewindow.impl.jvm.JVMUtil; +import com.jogamp.opengl.impl.GLJNILibLoader; +import com.jogamp.common.jvm.JVMUtil; import java.util.HashMap; +import java.util.Iterator; import java.security.AccessControlContext; import java.security.AccessController; import javax.media.opengl.fixedfunc.GLPointerFunc; @@ -58,6 +59,45 @@ import javax.media.opengl.fixedfunc.GLPointerFunc; public class GLProfile implements Cloneable { public static final boolean DEBUG = Debug.debug("GLProfile"); + // + // Query platform available OpenGL implementation + // + + public static final boolean isGL4bcAvailable() { return hasGL4bcImpl; } + public static final boolean isGL4Available() { return hasGL4Impl; } + public static final boolean isGL3bcAvailable() { return hasGL3bcImpl; } + public static final boolean isGL3Available() { return hasGL3Impl; } + public static final boolean isGL2Available() { return hasGL2Impl; } + public static final boolean isGLES2Available() { return hasGLES2Impl; } + public static final boolean isGLES1Available() { return hasGLES1Impl; } + public static final String glAvailabilityToString() { + StringBuffer sb = new StringBuffer(); + sb.append("GLAvailability[Native[GL4bc "); + sb.append(hasGL4bcImpl); + sb.append(", GL4 "); + sb.append(hasGL4Impl); + sb.append(", GL3bc "); + sb.append(hasGL3bcImpl); + sb.append(", GL3 "); + sb.append(hasGL3Impl); + sb.append(", GL2 "); + sb.append(hasGL2Impl); + sb.append(", GLES1 "); + sb.append(hasGLES1Impl); + sb.append(", GLES2 "); + sb.append(hasGLES2Impl); + sb.append("], Profiles["); + for(Iterator i=mappedProfiles.values().iterator(); i.hasNext(); ) { + sb.append(((GLProfile)i.next()).toString()); + sb.append(", "); + } + sb.append(", default "); + sb.append(defaultGLProfile); + sb.append("]]"); + + return sb.toString(); + } + // // Public (user-visible) profiles // @@ -95,22 +135,92 @@ public class GLProfile implements Cloneable { public static final String GL2GL3 = "GL2GL3"; /** - * All GL Profiles in the order of default detection: GL2, GL2ES2, GL2ES1, GLES2, GLES1, GL2GL3, GL3 + * All GL Profiles in the order of default detection. + * Desktop compatibility profiles (the one with fixed function pipeline) comes first. + * + * FIXME GL3GL4: Due to GL3 and GL4 implementation bugs, we still choose GL2 first, if available! + * + *
    + *
  • GL2 + *
  • GL3bc + *
  • GL4bc + *
  • GL2GL3 + *
  • GL3 + *
  • GL4 + *
  • GL2ES2 + *
  • GLES2 + *
  • GL2ES1 + *
  • GLES1 + *
+ * */ - public static final String[] GL_PROFILE_LIST_ALL = new String[] { GL2, GL2ES2, GL2ES1, GLES2, GLES1, GL2GL3, GL4bc, GL3bc, GL4, GL3 }; + public static final String[] GL_PROFILE_LIST_ALL = new String[] { GL2, GL3bc, GL4bc, GL2GL3, GL3, GL4, GL2ES2, GLES2, GL2ES1, GLES1 }; /** - * All GL2ES2 Profiles in the order of default detection: GL2ES2, GL2, GLES2, GL3 + * Order of maximum fixed function profiles + * + *
    + *
  • GL4bc + *
  • GL3bc + *
  • GL2 + *
  • GL2ES1 + *
  • GLES1 + *
+ * + */ + public static final String[] GL_PROFILE_LIST_MAX_FIXEDFUNC = new String[] { GL4bc, GL3bc, GL2, GL2ES1, GLES1 }; + + /** + * Order of maximum programmable shader profiles + * + *
    + *
  • GL4 + *
  • GL4bc + *
  • GL3 + *
  • GL3bc + *
  • GL2 + *
  • GL2ES2 + *
  • GLES2 + *
+ * + */ + public static final String[] GL_PROFILE_LIST_MAX_PROGSHADER = new String[] { GL4, GL4bc, GL3, GL3bc, GL2, GL2ES2, GLES2 }; + + /** + * All GL2ES2 Profiles in the order of default detection. + * + * FIXME GL3GL4: Due to GL3 and GL4 implementation bugs, we still choose GL2 first, if available! + * + *
    + *
  • GL2ES2 + *
  • GL2 + *
  • GL3 + *
  • GL4 + *
  • GLES2 + *
+ * */ - public static final String[] GL_PROFILE_LIST_GL2ES2 = new String[] { GL2ES2, GL2, GLES2, GL4bc, GL3bc, GL4, GL3 }; + public static final String[] GL_PROFILE_LIST_GL2ES2 = new String[] { GL2ES2, GL2, GL3, GL4, GLES2 }; /** - * All GL2ES1 Profiles in the order of default detection: GL2ES1, GL2, GLES1 + * All GL2ES1 Profiles in the order of default detection. + * + * FIXME GL3GL4: Due to GL3 and GL4 implementation bugs, we still choose GL2 first, if available! + * + *
    + *
  • GL2ES1 + *
  • GL2 + *
  • GL3bc + *
  • GL4bc + *
  • GLES1 + *
+ * */ - public static final String[] GL_PROFILE_LIST_GL2ES1 = new String[] { GL2ES1, GL2, GLES1 }; + public static final String[] GL_PROFILE_LIST_GL2ES1 = new String[] { GL2ES1, GL2, GL3bc, GL4bc, GLES1 }; /** Returns a default GLProfile object, reflecting the best for the running platform. * It selects the first of the set {@link GLProfile#GL_PROFILE_LIST_ALL} + * @see #GL_PROFILE_LIST_ALL */ public static final GLProfile getDefault() { if(null==defaultGLProfile) { @@ -119,22 +229,30 @@ public class GLProfile implements Cloneable { return defaultGLProfile; } - /** Returns a GLProfile object. - * Verfifies the given profile and chooses an apropriate implementation. - * A generic value of null or GL will result in - * the default profile. + /** + * Returns the highest profile, implementing the fixed function pipeline + * It selects the first of the set: {@link GLProfile#GL_PROFILE_LIST_MAX_FIXEDFUNC} * * @throws GLException if no implementation for the given profile is found. + * @see #GL_PROFILE_LIST_MAX_FIXEDFUNC */ - public static final GLProfile get(String profile) + public static final GLProfile getMaxFixedFunc() throws GLException { - if(null==profile || profile.equals("GL")) return getDefault(); - GLProfile glProfile = (GLProfile) mappedProfiles.get(profile); - if(null==glProfile) { - throw new GLException("No implementation for profile "+profile+" available"); - } - return glProfile; + return get(GL_PROFILE_LIST_MAX_FIXEDFUNC); + } + + /** + * Returns the highest profile, implementing the programmable shader pipeline. + * It selects the first of the set: {@link GLProfile#GL_PROFILE_LIST_MAX_PROGSHADER} + * + * @throws GLException if no implementation for the given profile is found. + * @see #GL_PROFILE_LIST_MAX_PROGSHADER + */ + public static final GLProfile getMaxProgrammable() + throws GLException + { + return get(GL_PROFILE_LIST_MAX_PROGSHADER); } /** @@ -142,6 +260,7 @@ public class GLProfile implements Cloneable { * It selects the first of the set: {@link GLProfile#GL_PROFILE_LIST_GL2ES1} * * @throws GLException if no implementation for the given profile is found. + * @see #GL_PROFILE_LIST_GL2ES1 */ public static final GLProfile getGL2ES1() throws GLException @@ -154,6 +273,7 @@ public class GLProfile implements Cloneable { * It selects the first of the set: {@link GLProfile#GL_PROFILE_LIST_GL2ES2} * * @throws GLException if no implementation for the given profile is found. + * @see #GL_PROFILE_LIST_GL2ES2 */ public static final GLProfile getGL2ES2() throws GLException @@ -161,6 +281,24 @@ public class GLProfile implements Cloneable { return get(GL_PROFILE_LIST_GL2ES2); } + /** Returns a GLProfile object. + * Verfifies the given profile and chooses an apropriate implementation. + * A generic value of null or GL will result in + * the default profile. + * + * @throws GLException if no implementation for the given profile is found. + */ + public static final GLProfile get(String profile) + throws GLException + { + if(null==profile || profile.equals("GL")) return getDefault(); + GLProfile glProfile = (GLProfile) mappedProfiles.get(profile); + if(null==glProfile) { + throw new GLException("No implementation for profile "+profile+" available"); + } + return glProfile; + } + /** * Returns the first profile from the given list, * where an implementation is available. @@ -200,18 +338,12 @@ public class GLProfile implements Cloneable { } private static final String getGLImplBaseClassName(String profileImpl) { - if(GL4bc.equals(profileImpl)) { + if ( GL4bc.equals(profileImpl) || + GL4.equals(profileImpl) || + GL3bc.equals(profileImpl) || + GL3.equals(profileImpl) || + GL2.equals(profileImpl) ) { return "com.jogamp.opengl.impl.gl4.GL4bc"; - } else if(GL4.equals(profileImpl)) { - return "com.jogamp.opengl.impl.gl4.GL4"; - } else if(GL3bc.equals(profileImpl)) { - return "com.jogamp.opengl.impl.gl3.GL3bc"; - } else if(GL3.equals(profileImpl)) { - return "com.jogamp.opengl.impl.gl3.GL3"; - } else if(GL2.equals(profileImpl)) { - return "com.jogamp.opengl.impl.gl2.GL2"; - } else if(GL2ES12.equals(profileImpl)) { - return "com.jogamp.opengl.impl.gl2es12.GL2ES12"; } else if(GLES1.equals(profileImpl) || GL2ES1.equals(profileImpl)) { return "com.jogamp.opengl.impl.es1.GLES1"; } else if(GLES2.equals(profileImpl) || GL2ES2.equals(profileImpl)) { @@ -285,7 +417,7 @@ public class GLProfile implements Cloneable { return isGL4() || isGL3bc() || GL3.equals(profile); } - /** Indicates whether this profile is capable of GL2. */ + /** Indicates whether this context is a GL2 context */ public final boolean isGL2() { return isGL3bc() || GL2.equals(profile); } @@ -315,34 +447,9 @@ public class GLProfile implements Cloneable { return GL2GL3.equals(profile) || isGL2() || isGL3() ; } - /** Indicates whether this profile uses the native desktop OpenGL GL4bc implementations. */ - public final boolean usesNativeGL4bc() { - return GL4bc.equals(profileImpl); - } - - /** Indicates whether this profile uses the native desktop OpenGL GL4 implementations. */ - public final boolean usesNativeGL4() { - return usesNativeGL4bc() || GL4.equals(profileImpl); - } - - /** Indicates whether this profile uses the native desktop OpenGL GL3bc implementations. */ - public final boolean usesNativeGL3bc() { - return GL3bc.equals(profileImpl); - } - - /** Indicates whether this profile uses the native desktop OpenGL GL3 implementations. */ - public final boolean usesNativeGL3() { - return usesNativeGL3bc() || GL3.equals(profileImpl); - } - - /** Indicates whether this profile uses the native desktop OpenGL GL2 implementations. */ - public final boolean usesNativeGL2() { - return GL2.equals(profileImpl) || GL2ES12.equals(profileImpl) ; - } - - /** Indicates whether this profile uses the native desktop OpenGL GL2 or GL3 implementations. */ - public final boolean usesNativeGL2GL3() { - return usesNativeGL2() || usesNativeGL3() || usesNativeGL4(); + /** Indicates whether this profile supports GLSL. */ + public final boolean hasGLSL() { + return isGL2ES2() ; } /** Indicates whether this profile uses the native OpenGL ES1 implementations. */ @@ -360,11 +467,6 @@ public class GLProfile implements Cloneable { return usesNativeGLES2() || usesNativeGLES1(); } - /** Indicates whether this profile supports GLSL. */ - public final boolean hasGLSL() { - return isGL2ES2() ; - } - /** * General validation if type is a valid GL data type * for the current profile @@ -665,70 +767,23 @@ public class GLProfile implements Cloneable { return "GLProfile[" + profile + "/" + profileImpl + "]"; } - public static final int GL_VERSIONS[][] = { - /* 0.*/ { -1 }, - /* 1.*/ { 0, 1, 2, 3, 4, 5 }, - /* 2.*/ { 0, 1 }, - /* 3.*/ { 0, 1, 2, 3 }, - /* 4.*/ { 0 } }; - - public static final int getMaxMajor() { - return GL_VERSIONS.length-1; - } - - public static final int getMaxMinor(int major) { - if(1>major || major>=GL_VERSIONS.length) return -1; - return GL_VERSIONS[major].length-1; - } - - public static final boolean isValidGLVersion(int major, int minor) { - if(1>major || major>=GL_VERSIONS.length) return false; - if(0>minor || minor>=GL_VERSIONS[major].length) return false; - return true; - } - - public static final boolean decrementGLVersion(int major[], int minor[]) { - if(null==major || major.length<1 ||null==minor || minor.length<1) { - throw new GLException("invalid array arguments"); - } - int m = major[0]; - int n = minor[0]; - if(!isValidGLVersion(m, n)) return false; - - // decrement .. - n -= 1; - if(n < 0) { - m -= 1; - n = GL_VERSIONS[m].length-1; - } - if(!isValidGLVersion(m, n)) return false; - major[0]=m; - minor[0]=n; - - return true; - } - - // The intersection between desktop OpenGL and the union of the OpenGL ES profiles - // This is here only to avoid having separate GL2ES1Impl and GL2ES2Impl classes - private static final String GL2ES12 = "GL2ES12"; - private static final boolean isAWTAvailable; private static final boolean isAWTJOGLAvailable; - private static final boolean hasGL4bcImpl; - private static final boolean hasGL4Impl; - private static final boolean hasGL3bcImpl; - private static final boolean hasGL3Impl; - private static final boolean hasGL2Impl; - private static final boolean hasGL2ES12Impl; - private static final boolean hasGLES2Impl; - private static final boolean hasGLES1Impl; + private static /*final*/ boolean hasGL234Impl; + private static /*final*/ boolean hasGL4bcImpl; + private static /*final*/ boolean hasGL4Impl; + private static /*final*/ boolean hasGL3bcImpl; + private static /*final*/ boolean hasGL3Impl; + private static /*final*/ boolean hasGL2Impl; + private static /*final*/ boolean hasGLES2Impl; + private static /*final*/ boolean hasGLES1Impl; /** The JVM/process wide default GL profile **/ - private static GLProfile defaultGLProfile; + private static /*final*/ GLProfile defaultGLProfile; /** All GLProfiles */ - private static final HashMap/**/ mappedProfiles; + private static /*final*/ HashMap/**/ mappedProfiles; /** * Tries the profiles implementation and native libraries. @@ -740,119 +795,174 @@ public class GLProfile implements Cloneable { AccessControlContext acc = AccessController.getContext(); isAWTAvailable = !Debug.getBooleanProperty("java.awt.headless", true, acc) && - NWReflection.isClassAvailable("java.awt.Component") ; + ReflectionUtil.isClassAvailable("java.awt.Component") ; isAWTJOGLAvailable = isAWTAvailable && - NWReflection.isClassAvailable("javax.media.nativewindow.awt.AWTGraphicsDevice") && // NativeWindow - NWReflection.isClassAvailable("javax.media.opengl.awt.GLCanvas") ; // JOGL + ReflectionUtil.isClassAvailable("javax.media.nativewindow.awt.AWTGraphicsDevice") && // NativeWindow + ReflectionUtil.isClassAvailable("javax.media.opengl.awt.GLCanvas") ; // JOGL boolean hasDesktopGL = false; - boolean hasDesktopGLES12 = false; boolean hasNativeOSFactory = false; - + Throwable t; + + // + // First iteration of desktop GL availability detection + // - native libs exist + // - class exists + // + t=null; try { // See DRIHack.java for an explanation of why this is necessary DRIHack.begin(); - NativeLibLoader.loadGLDesktop(); + GLJNILibLoader.loadGLDesktop(); DRIHack.end(); hasDesktopGL = true; - } catch (Throwable t) { + } catch (UnsatisfiedLinkError ule) { + t=ule; + } catch (SecurityException se) { + t=se; + } catch (NullPointerException npe) { + t=npe; + } catch (RuntimeException re) { + t=re; + } + if(null!=t) { if (DEBUG) { System.err.println("GLProfile.static Desktop GL Library not available"); t.printStackTrace(); } } - try { - // See DRIHack.java for an explanation of why this is necessary - DRIHack.begin(); - NativeLibLoader.loadGLDesktopES12(); - DRIHack.end(); - hasDesktopGLES12 = true; - } catch (Throwable t) { - if (DEBUG) { - System.err.println("GLProfile.static Desktop GL ES12 Library not available"); - t.printStackTrace(); + hasGL234Impl = hasDesktopGL && ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.gl4.GL4bcImpl"); + hasGL4bcImpl = hasGL234Impl; + hasGL4Impl = hasGL234Impl; + hasGL3bcImpl = hasGL234Impl; + hasGL3Impl = hasGL234Impl; + hasGL2Impl = hasGL234Impl; + mappedProfiles = computeProfileMap(); + + // + // Second iteration of desktop GL availability detection + // utilizing the detected GL version in the shared context. + // + // - Instantiate GLDrawableFactory incl its shared dummy drawable/context, + // which will register at GLContext .. + // + + if(hasDesktopGL) { + // if successfull it has a shared dummy drawable and context created + try { + hasNativeOSFactory = null != GLDrawableFactory.getFactoryImpl(GL2); + } catch (RuntimeException re) { + System.err.println("GLProfile.static - Native platform GLDrawable factory not available"); + re.printStackTrace(); } } - if(hasDesktopGL||hasDesktopGLES12) { - try { - hasNativeOSFactory = null!=GLDrawableFactory.getFactoryImpl(GL2); - } catch (Throwable t) { - if (DEBUG) { - System.err.println("GLProfile.static - Native platform GLDrawable factory not available"); - t.printStackTrace(); - } - } + if(hasNativeOSFactory && !GLContext.mappedVersionsAvailableSet) { + // nobody yet set the available desktop versions, see {@link GLContextImpl#makeCurrent}, + // so we have to add the usual suspect + GLContext.mapVersionAvailable(2, true, 1, 5, GLContext.CTX_PROFILE_COMPAT|GLContext.CTX_OPTION_ANY); } if(!hasNativeOSFactory) { - hasDesktopGLES12=false; - hasDesktopGL=false; + hasDesktopGL = false; + hasGL234Impl = false; + hasGL4bcImpl = false; + hasGL4Impl = false; + hasGL3bcImpl = false; + hasGL3Impl = false; + hasGL2Impl = false; + } else { + hasGL4bcImpl = GLContext.isGL4bcAvailable(); + hasGL4Impl = GLContext.isGL4Available(); + hasGL3bcImpl = GLContext.isGL3bcAvailable(); + hasGL3Impl = GLContext.isGL3Available(); + hasGL2Impl = GLContext.isGL2Available(); } - // FIXME: check for real GL3 availability .. ? - hasGL4bcImpl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl4.GL4bcImpl"); - hasGL4Impl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl4.GL4Impl"); - hasGL3bcImpl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl3.GL3bcImpl"); - hasGL3Impl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl3.GL3Impl"); - hasGL2Impl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl2.GL2Impl"); - - hasGL2ES12Impl = hasDesktopGLES12 && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl2es12.GL2ES12Impl"); - boolean btest = false; - boolean hasEGLDynLookup = NWReflection.isClassAvailable("com.jogamp.opengl.impl.egl.EGLDynamicLookupHelper"); + boolean hasEGLDynLookup = ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.egl.EGLDynamicLookupHelper"); boolean hasEGLDrawableFactory = false; + t=null; try { if(hasEGLDynLookup) { hasEGLDrawableFactory = null!=GLDrawableFactory.getFactoryImpl(GLES2); - btest = hasEGLDrawableFactory && - NWReflection.isClassAvailable("com.jogamp.opengl.impl.es2.GLES2Impl") && - null!=com.jogamp.opengl.impl.egl.EGLDynamicLookupHelper.getDynamicLookupHelper(2); + try { + btest = hasEGLDrawableFactory && + ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.es2.GLES2Impl") && + null!=com.jogamp.opengl.impl.egl.EGLDynamicLookupHelper.getDynamicLookupHelper(2); + } catch (GLException gle) { + // n/a .. + } } - } catch (Throwable t) { + } catch (UnsatisfiedLinkError ule) { + t=ule; + } catch (SecurityException se) { + t=se; + } catch (NullPointerException npe) { + t=npe; + } catch (RuntimeException re) { + t=re; + } + if(null!=t) { if (DEBUG) { System.err.println("GLProfile.static - GL ES2 Factory/Library not available"); t.printStackTrace(); } } hasGLES2Impl = btest; + if(hasGLES2Impl) { + GLContext.mapVersionAvailable(2, false, 2, 0, GLContext.CTX_PROFILE_ES|GLContext.CTX_PROFILE_CORE|GLContext.CTX_OPTION_ANY); + } btest = false; - try { - if(hasEGLDynLookup) { + if(hasEGLDynLookup) { + try { btest = hasEGLDrawableFactory && - NWReflection.isClassAvailable("com.jogamp.opengl.impl.es1.GLES1Impl") && + ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.es1.GLES1Impl") && null!=com.jogamp.opengl.impl.egl.EGLDynamicLookupHelper.getDynamicLookupHelper(1); - } - } catch (Throwable t) { - if (DEBUG) { - System.err.println("GLProfile.static - GL ES1 Factory/Library not available"); - t.printStackTrace(); + } catch (GLException jre) { + /* just not available .. */ } } hasGLES1Impl = btest; + if(hasGLES1Impl) { + GLContext.mapVersionAvailable(1, false, 1, 0, GLContext.CTX_PROFILE_ES|GLContext.CTX_PROFILE_CORE|GLContext.CTX_OPTION_ANY); + } + + mappedProfiles = computeProfileMap(); + if(null==defaultGLProfile) { + throw new GLException("No profile available: "+list2String(GL_PROFILE_LIST_ALL)); + } if (DEBUG) { System.err.println("GLProfile.static isAWTAvailable "+isAWTAvailable); System.err.println("GLProfile.static isAWTJOGLAvailable "+isAWTJOGLAvailable); System.err.println("GLProfile.static hasNativeOSFactory "+hasNativeOSFactory); - System.err.println("GLProfile.static hasDesktopGLES12 "+hasDesktopGLES12); System.err.println("GLProfile.static hasDesktopGL "+hasDesktopGL); - System.err.println("GLProfile.static hasGL4bcImpl "+hasGL4bcImpl); - System.err.println("GLProfile.static hasGL4Impl "+hasGL4Impl); - System.err.println("GLProfile.static hasGL3bcImpl "+hasGL3bcImpl); - System.err.println("GLProfile.static hasGL3Impl "+hasGL3Impl); - System.err.println("GLProfile.static hasGL2Impl "+hasGL2Impl); - System.err.println("GLProfile.static hasGL2ES12Impl "+hasGL2ES12Impl); System.err.println("GLProfile.static hasEGLDynLookup "+hasEGLDynLookup); System.err.println("GLProfile.static hasEGLDrawableFactory "+hasEGLDrawableFactory); - System.err.println("GLProfile.static hasGLES2Impl "+hasGLES2Impl); - System.err.println("GLProfile.static hasGLES1Impl "+hasGLES1Impl); + System.err.println("GLProfile.static hasGL234Impl "+hasGL234Impl); + System.err.println("GLProfile.static "+glAvailabilityToString()); + } + } + + private static final String list2String(String[] list) { + StringBuffer msg = new StringBuffer(); + msg.append("["); + for (int i = 0; i < list.length; i++) { + if (i > 0) + msg.append(", "); + msg.append(list[i]); } + msg.append("]"); + return msg.toString(); + } + private static HashMap computeProfileMap() { + defaultGLProfile=null; HashMap/**/ _mappedProfiles = new HashMap(GL_PROFILE_LIST_ALL.length); for(int i=0; i 0) - msg.append(", "); - msg.append(list[i]); - } - msg.append("]"); - return msg.toString(); + return _mappedProfiles; } /** * Returns the profile implementation */ private static String computeProfileImpl(String profile) { - // FIXME Order of return profiles, after we can test their availability if (GL2ES1.equals(profile)) { - if(hasGL2ES12Impl) { - return GL2ES12; - } else if(hasGL2Impl) { + if(hasGL2Impl) { return GL2; + } else if(hasGL3bcImpl) { + return GL3bc; + } else if(hasGL4bcImpl) { + return GL4bc; } else if(hasGLES1Impl) { return GLES1; } } else if (GL2ES2.equals(profile)) { - if(hasGL2ES12Impl) { - return GL2ES12; - } else if(hasGL2Impl) { + if(hasGL2Impl) { return GL2; } else if(hasGL3Impl) { return GL3; - } else if(hasGL3bcImpl) { - return GL3bc; } else if(hasGL4Impl) { return GL4; - } else if(hasGL4bcImpl) { - return GL4bc; } else if(hasGLES2Impl) { return GLES2; } - } else if(GL4bc.equals(profile) && hasGL4bcImpl) { - return GL4bc; - } else if(GL4.equals(profile)) { - if(hasGL4Impl) { - return GL4; + } else if(GL2GL3.equals(profile)) { + if(hasGL2Impl) { + return GL2; + } else if(hasGL3bcImpl) { + return GL3bc; } else if(hasGL4bcImpl) { return GL4bc; + } else if(hasGL3Impl) { + return GL3; + } else if(hasGL4Impl) { + return GL4; } + } else if(GL4bc.equals(profile) && hasGL4bcImpl) { + return GL4bc; + } else if(GL4.equals(profile) && hasGL4Impl) { + return GL4; } else if(GL3bc.equals(profile) && hasGL3bcImpl) { return GL3bc; - } else if(GL3.equals(profile)) { - if(hasGL3Impl) { - return GL3; - } else if(hasGL3bcImpl) { - return GL3bc; - } + } else if(GL3.equals(profile) && hasGL3Impl) { + return GL3; } else if(GL2.equals(profile) && hasGL2Impl) { return GL2; - } else if(GL2GL3.equals(profile) && hasGL2Impl) { - return GL2; } else if(GLES2.equals(profile) && hasGLES2Impl) { return GLES2; } else if(GLES1.equals(profile) && hasGLES1Impl) { diff --git a/src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01CORE.java b/src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01CORE.java new file mode 100755 index 000000000..a1ff0d860 --- /dev/null +++ b/src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01CORE.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2010 Sven Gothel. 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 Sven Gothel 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 + * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.jogamp.test.junit.jogl.acore; + + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Test; + +import javax.media.opengl.*; + +import com.jogamp.newt.*; +import java.io.IOException; + +public class TestGLProfile01CORE { + static GLProfile glp; + static GLDrawableFactory factory; + + @BeforeClass + public static void initClass() { + glp = GLProfile.getDefault(); + Assert.assertNotNull(glp); + factory = GLDrawableFactory.getFactory(glp); + Assert.assertNotNull(factory); + } + + @AfterClass + public static void releaseClass() { + factory.shutdown(); + factory=null; + } + + @Test + public void test01GLProfileDefault() { + System.out.println("GLProfile "+GLProfile.glAvailabilityToString()); + } + + @Test + public void test02GLProfileMaxFixedFunc() { + System.out.println("GLProfile getMaxFixedFunc(): "+GLProfile.getMaxFixedFunc()); + } + + @Test + public void test02GLProfileMaxProgrammable() { + System.out.println("GLProfile getMaxProgrammable(): "+GLProfile.getMaxProgrammable()); + } + + public static void main(String args[]) throws IOException { + String tstname = TestGLProfile01CORE.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } + +} diff --git a/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java b/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java new file mode 100755 index 000000000..ac34b46b5 --- /dev/null +++ b/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2010 Sven Gothel. 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 Sven Gothel 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 + * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.jogamp.test.junit.jogl.awt; + +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.opengl.util.Animator; + +import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears; +import java.awt.Frame; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.After; +import org.junit.Test; + +public class TestAWT01GLn { + Frame frame=null; + GLCanvas glCanvas=null; + + @Before + public void init() { + frame = new Frame("Texture Test"); + Assert.assertNotNull(frame); + } + + @After + public void release() { + Assert.assertNotNull(frame); + Assert.assertNotNull(glCanvas); + frame.setVisible(false); + frame.remove(glCanvas); + frame.dispose(); + frame=null; + glCanvas=null; + } + + protected void runTestGL(GLCapabilities caps) throws InterruptedException { + glCanvas = new GLCanvas(caps); + Assert.assertNotNull(glCanvas); + frame.add(glCanvas); + frame.setSize(512, 512); + + glCanvas.addGLEventListener(new Gears()); + + Animator animator = new Animator(glCanvas); + frame.setVisible(true); + animator.start(); + + Thread.sleep(500); // 500 ms + + animator.stop(); + } + + @Test + public void test01GLDefault() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(GLProfile.getDefault()); + runTestGL(caps); + } + + /** Both fail on ATI .. if GLn n>2 + public void test02GL3bc() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL3bc)); + runTestGL(caps); + } + + public void test03GLMaxFixed() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(GLProfile.getMaxFixedFunc()); + runTestGL(caps); + } */ + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestAWT01GLn.class.getName()); + } +} diff --git a/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java b/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java index ec03bec95..459b41f16 100755 --- a/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java +++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java @@ -55,16 +55,16 @@ import com.jogamp.test.junit.jogl.demos.es1.RedSquare; import java.io.IOException; public class TestOffscreen01NEWT { - static GLProfile glp; + static GLProfile glpDefault; static GLDrawableFactory factory; static int width, height; - GLCapabilities caps; + GLCapabilities capsDefault; @BeforeClass public static void initClass() { - glp = GLProfile.getDefault(); - Assert.assertNotNull(glp); - factory = GLDrawableFactory.getFactory(glp); + glpDefault = GLProfile.getDefault(); + Assert.assertNotNull(glpDefault); + factory = GLDrawableFactory.getFactory(glpDefault); Assert.assertNotNull(factory); width = 640; height = 480; @@ -78,7 +78,8 @@ public class TestOffscreen01NEWT { @Before public void init() { - caps = new GLCapabilities(glp); + capsDefault = new GLCapabilities(glpDefault); + Assert.assertNotNull(capsDefault); } private void do01OffscreenWindowPBuffer(GLCapabilities caps) { @@ -115,20 +116,20 @@ public class TestOffscreen01NEWT { @Test public void test01aOffscreenWindowPBuffer() { - GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); do01OffscreenWindowPBuffer(caps2); } @Test public void test01bOffscreenWindowPBufferStencil() { - GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); caps2.setStencilBits(8); do01OffscreenWindowPBuffer(caps2); } @Test public void test01cOffscreenWindowPBufferStencilAlpha() { - GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); caps2.setStencilBits(8); caps2.setAlphaBits(8); do01OffscreenWindowPBuffer(caps2); @@ -136,7 +137,7 @@ public class TestOffscreen01NEWT { @Test public void test01cOffscreenWindowPBuffer555() { - GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); caps2.setRedBits(5); caps2.setGreenBits(5); caps2.setBlueBits(5); @@ -145,7 +146,7 @@ public class TestOffscreen01NEWT { @Test public void test02Offscreen3Windows1DisplayPBuffer() { - GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); int winnum = 3, i; Window windows[] = new Window[winnum]; GLWindow glWindows[] = new GLWindow[winnum]; @@ -192,7 +193,7 @@ public class TestOffscreen01NEWT { @Test public void test03Offscreen3Windows3DisplaysPBuffer() { - GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); int winnum = 3, i; Display displays[] = new Display[winnum]; Screen screens[] = new Screen[winnum]; @@ -240,7 +241,7 @@ public class TestOffscreen01NEWT { @Test public void test04OffscreenSnapshotWithDemoPBuffer() { - GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false); System.out.println("Create Window 1"); Display display = NewtFactory.createDisplay(null); // local display @@ -283,6 +284,12 @@ public class TestOffscreen01NEWT { @Test public void test11OffscreenWindowPixmap() { + // Offscreen doesn't work on >= GL3 (ATI) + GLProfile glp = GLProfile.get(GLProfile.GL2); + Assert.assertNotNull(glp); + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, false, false); Display display = NewtFactory.createDisplay(null); // local display @@ -318,6 +325,12 @@ public class TestOffscreen01NEWT { @Test public void test14OffscreenSnapshotWithDemoPixmap() { + // Offscreen doesn't work on >= GL3 (ATI) + GLProfile glp = GLProfile.get(GLProfile.GL2); + Assert.assertNotNull(glp); + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, false, false); System.out.println("Create Window 1"); diff --git a/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java b/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java index 563c7f88e..4bbbaa271 100755 --- a/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java +++ b/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java @@ -93,7 +93,7 @@ public class TestTexture01AWT { frame.setVisible(true); animator.start(); - Thread.sleep(1000); // 1000 ms + Thread.sleep(500); // 500 ms animator.stop(); frame.setVisible(false); diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWJNILibLoader.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWJNILibLoader.java new file mode 100644 index 000000000..c3c04287a --- /dev/null +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWJNILibLoader.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2010, Sven Gothel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of Sven Gothel nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 Sven Gothel 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. + */ + +package com.jogamp.nativewindow.impl; + +// FIXME: refactor Java SE dependencies +//import java.awt.Toolkit; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.HashSet; +import com.jogamp.common.jvm.JNILibLoaderBase; + +public class NWJNILibLoader extends JNILibLoaderBase { + + public static void loadNativeWindow(final String ossuffix) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + loadLibrary("nativewindow_"+ossuffix, null, false); + return null; + } + }); + } + +} diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWReflection.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWReflection.java deleted file mode 100644 index 9bac9477a..000000000 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWReflection.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. 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 com.jogamp.nativewindow.impl; - -import java.lang.reflect.*; -import javax.media.nativewindow.*; - -public final class NWReflection { - - public static final boolean DEBUG = Debug.debug("NWReflection"); - - /** - * Returns true only if the class could be loaded. - */ - public static final boolean isClassAvailable(String clazzName) { - try { - return null != Class.forName(clazzName, false, NWReflection.class.getClassLoader()); - } catch (ClassNotFoundException e) { - return false; - } - } - - /** - * Loads and returns the class or null. - * @see Class#forName(java.lang.String, boolean, java.lang.ClassLoader) - */ - public static final Class getClass(String clazzName, boolean initialize) { - try { - return getClassImpl(clazzName, initialize); - } catch (ClassNotFoundException e) { - return null; - } - } - - private static Class getClassImpl(String clazzName, boolean initialize) throws ClassNotFoundException { - return Class.forName(clazzName, initialize, NWReflection.class.getClassLoader()); - } - - /** - * @throws NativeWindowException if the constructor can not be delivered. - */ - public static final Constructor getConstructor(String clazzName, Class[] cstrArgTypes) { - try { - return getConstructor(getClassImpl(clazzName, true), cstrArgTypes); - } catch (ClassNotFoundException ex) { - throw new NativeWindowException(clazzName + " not available", ex); - } - } - - /** - * @throws NativeWindowException if the constructor can not be delivered. - */ - public static final Constructor getConstructor(Class clazz, Class[] cstrArgTypes) { - try { - return clazz.getDeclaredConstructor(cstrArgTypes); - } catch (NoSuchMethodException ex) { - String args = ""; - for (int i = 0; i < cstrArgTypes.length; i++) { - args += cstrArgTypes[i].getName(); - if(i != cstrArgTypes.length-1) { - args+= ", "; - } - } - throw new NativeWindowException("Constructor: '" + clazz + "(" + args + ")' not found", ex); - } - } - - public static final Constructor getConstructor(String clazzName) { - return getConstructor(clazzName, new Class[0]); - } - - /** - * @throws NativeWindowException if the instance can not be created. - */ - public static final Object createInstance(Class clazz, Class[] cstrArgTypes, Object[] cstrArgs) { - try { - return getConstructor(clazz, cstrArgTypes).newInstance(cstrArgs); - } catch (InstantiationException ex) { - throw new NativeWindowException("can not create instance of class "+clazz, ex); - } catch (InvocationTargetException ex) { - throw new NativeWindowException("can not create instance of class "+clazz, ex); - } catch (IllegalAccessException ex) { - throw new NativeWindowException("can not create instance of class "+clazz, ex); - } - } - - public static final Object createInstance(Class clazz, Object[] cstrArgs) { - Class[] cstrArgTypes = new Class[cstrArgs.length]; - for(int i=0; i=0; i--) { - Class face = clazzes[i]; - if(face.getName().equals(faceName)) { - return true; - } - } - clazz = clazz.getSuperclass(); - } while (clazz!=null); - return false; - } - - public static boolean isAWTComponent(Object target) { - return instanceOf(target, "java.awt.Component"); - } - - public static boolean isAWTComponent(Class clazz) { - return instanceOf(clazz, "java.awt.Component"); - } - -} - diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeLibLoaderBase.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeLibLoaderBase.java deleted file mode 100644 index c4f1d7e08..000000000 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeLibLoaderBase.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. 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. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.nativewindow.impl; - -// FIXME: refactor Java SE dependencies -//import java.awt.Toolkit; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.HashSet; - -public class NativeLibLoaderBase { - public static final boolean DEBUG = Debug.debug("NativeLibLoader"); - - public interface LoaderAction { - /** - * Loads the library specified by libname. Optionally preloads the libraries specified by - * preload. The implementation should ignore, if the preload-libraries have already been - * loaded. - * @param libname the library to load - * @param preload the libraries to load before loading the main library if not null - * @param preloadIgnoreError true, if errors during loading the preload-libraries should be ignored - */ - void loadLibrary(String libname, String[] preload, - boolean preloadIgnoreError); - } - - private static class DefaultAction implements LoaderAction { - public void loadLibrary(String libname, String[] preload, boolean preloadIgnoreError) { - if (null!=preload) { - for (int i=0; i - 4395095 JNI access to java.nio DirectBuffer constructor/accessor - 6852404 Race condition in JNI Direct Buffer access and creation routines - - * - * Make sure to initialize this class as soon as possible, - * before doing any multithreading work. - * - */ -public class JVMUtil { - private static final boolean DEBUG = Debug.debug("JVMUtil"); - - static { - NativeLibLoaderBase.loadNativeWindow("jvm"); - - ByteBuffer buffer = InternalBufferUtil.newByteBuffer(64); - if( ! initialize(buffer) ) { - throw new RuntimeException("Failed to initialize the JVMUtil "+Thread.currentThread().getName()); - } - if(DEBUG) { - Exception e = new Exception("JVMUtil.initSingleton() .. initialized "+Thread.currentThread().getName()); - e.printStackTrace(); - } - } - - public static void initSingleton() { - } - - private JVMUtil() {} - - private static native boolean initialize(java.nio.ByteBuffer buffer); -} - diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java index 41ffccc42..5f5c10885 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java @@ -53,7 +53,7 @@ public class X11Util { private static final boolean DEBUG = Debug.debug("X11Util"); static { - NativeLibLoaderBase.loadNativeWindow("x11"); + NWJNILibLoader.loadNativeWindow("x11"); installIOErrorHandler(); } diff --git a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java index a8b67fddc..c692e51c4 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java +++ b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java @@ -35,6 +35,7 @@ package javax.media.nativewindow; import java.lang.reflect.*; import java.util.*; +import com.jogamp.common.util.*; import com.jogamp.nativewindow.impl.*; /** @@ -77,7 +78,7 @@ public abstract class GraphicsConfigurationFactory { if (NativeWindowFactory.TYPE_X11.equals(NativeWindowFactory.getNativeWindowType(true))) { try { GraphicsConfigurationFactory factory = (GraphicsConfigurationFactory) - NWReflection.createInstance("com.jogamp.nativewindow.impl.x11.X11GraphicsConfigurationFactory", new Object[] {}); + ReflectionUtil.createInstance("com.jogamp.nativewindow.impl.x11.X11GraphicsConfigurationFactory", new Object[] {}); registerFactory(javax.media.nativewindow.x11.X11GraphicsDevice.class, factory); } catch (Exception e) { throw new RuntimeException(e); diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java index 5b1bf54bb..944fdee74 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java @@ -36,8 +36,9 @@ import java.lang.reflect.*; import java.security.*; import java.util.*; +import com.jogamp.common.util.*; +import com.jogamp.common.jvm.JVMUtil; import com.jogamp.nativewindow.impl.*; -import com.jogamp.nativewindow.impl.jvm.JVMUtil; /** Provides a pluggable mechanism for arbitrary window toolkits to adapt their components to the {@link NativeWindow} interface, @@ -123,10 +124,10 @@ public abstract class NativeWindowFactory { // make it easier to run this code on mobile devices Class componentClass = null; - if ( NWReflection.isClassAvailable("java.awt.Component") && - NWReflection.isClassAvailable("javax.media.nativewindow.awt.AWTGraphicsDevice") ) { + if ( ReflectionUtil.isClassAvailable("java.awt.Component") && + ReflectionUtil.isClassAvailable("javax.media.nativewindow.awt.AWTGraphicsDevice") ) { try { - componentClass = NWReflection.getClass("java.awt.Component", false); + componentClass = ReflectionUtil.getClass("java.awt.Component", false); } catch (Exception e) { } } @@ -177,7 +178,7 @@ public abstract class NativeWindowFactory { try { Constructor factoryConstructor = - NWReflection.getConstructor("com.jogamp.nativewindow.impl.x11.awt.X11AWTNativeWindowFactory", new Class[] {}); + ReflectionUtil.getConstructor("com.jogamp.nativewindow.impl.x11.awt.X11AWTNativeWindowFactory", new Class[] {}); _factory = (NativeWindowFactory) factoryConstructor.newInstance(null); } catch (Exception e) { } } @@ -185,7 +186,7 @@ public abstract class NativeWindowFactory { if (toolkitLockForced && null==_factory) { try { Constructor factoryConstructor = - NWReflection.getConstructor("com.jogamp.nativewindow.impl.LockingNativeWindowFactory", new Class[] {}); + ReflectionUtil.getConstructor("com.jogamp.nativewindow.impl.LockingNativeWindowFactory", new Class[] {}); _factory = (NativeWindowFactory) factoryConstructor.newInstance(null); } catch (Exception e) { } } diff --git a/src/nativewindow/native/JVM_Tool.c b/src/nativewindow/native/JVM_Tool.c deleted file mode 100644 index ce827129c..000000000 --- a/src/nativewindow/native/JVM_Tool.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. 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 - * MIDROSYSTEMS, 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. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -#include - -JNIEXPORT jboolean JNICALL -Java_com_jogamp_nativewindow_impl_jvm_JVMUtil_initialize(JNIEnv *env, jclass _unused, jobject nioBuffer) { - int res; - void * ptr = NULL; - if (nioBuffer != NULL) { - ptr = (void *) (*env)->GetDirectBufferAddress(env, nioBuffer); - } - return ( NULL==ptr ) ? JNI_FALSE : JNI_TRUE ; -} - diff --git a/src/nativewindow/native/x11/Xmisc.c b/src/nativewindow/native/x11/Xmisc.c index 4320a8f12..52449ae84 100644 --- a/src/nativewindow/native/x11/Xmisc.c +++ b/src/nativewindow/native/x11/Xmisc.c @@ -128,6 +128,7 @@ static void _FatalError(JNIEnv *env, const char* msg, ...) va_end(ap); fprintf(stderr, buffer); + fprintf(stderr, "\n"); (*env)->FatalError(env, buffer); } @@ -201,32 +202,54 @@ static void _throwNewRuntimeException(Display * unlockDisplay, JNIEnv *env, cons (*env)->ThrowNew(env, clazzRuntimeException, buffer); } +static JNIEnv * x11ErrorHandlerJNIEnv = NULL; +static XErrorHandler origErrorHandler = NULL ; + +static int x11ErrorHandler(Display *dpy, XErrorEvent *e) +{ + _throwNewRuntimeException(NULL, x11ErrorHandlerJNIEnv, "Nativewindow X11 Error: Display %p, Code 0x%X", dpy, e->error_code); + + return 0; +} + +static void x11ErrorHandlerEnable(int onoff, JNIEnv * env) { + if(onoff) { + if(NULL==origErrorHandler) { + x11ErrorHandlerJNIEnv = env; + origErrorHandler = XSetErrorHandler(x11ErrorHandler); + } + } else { + XSetErrorHandler(origErrorHandler); + origErrorHandler = NULL; + } +} + + static XIOErrorHandler origIOErrorHandler = NULL; -static JNIEnv * displayIOErrorHandlerJNIEnv = NULL; -static int displayIOErrorHandler(Display *dpy) +static int x11IOErrorHandler(Display *dpy) { - _FatalError(displayIOErrorHandlerJNIEnv, "Nativewindow X11 IOError: Display %p not available", dpy); + _FatalError(x11ErrorHandlerJNIEnv, "Nativewindow X11 IOError: Display %p not available", dpy); origIOErrorHandler(dpy); return 0; } -static void displayIOErrorHandlerEnable(int onoff, JNIEnv * env) { +static void x11IOErrorHandlerEnable(int onoff, JNIEnv * env) { if(onoff) { if(NULL==origIOErrorHandler) { - displayIOErrorHandlerJNIEnv = env; - origIOErrorHandler = XSetIOErrorHandler(displayIOErrorHandler); + x11ErrorHandlerJNIEnv = env; + origIOErrorHandler = XSetIOErrorHandler(x11IOErrorHandler); } } else { XSetIOErrorHandler(origIOErrorHandler); origIOErrorHandler = NULL; - displayIOErrorHandlerJNIEnv = NULL; } } JNIEXPORT void JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Util_installIOErrorHandler(JNIEnv *env, jclass _unused) { - displayIOErrorHandlerEnable(1, env); + x11ErrorHandlerEnable(1, env); + x11IOErrorHandlerEnable(1, env); } JNIEXPORT jlong JNICALL @@ -345,6 +368,7 @@ Java_com_jogamp_nativewindow_impl_x11_X11Lib_XCloseDisplay__J(JNIEnv *env, jclas * Class: com_jogamp_nativewindow_impl_x11_X11Lib * Method: CreateDummyWindow * Signature: (JIJ)J + */ JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_CreateDummyWindow (JNIEnv *env, jobject obj, jlong display, jint screen_index, jlong visualID) { @@ -370,7 +394,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_CreateDummy } if(visualID<0) { - _throwNewRuntimeException(NULL, env, "invalid VisualID ..\n"); + _throwNewRuntimeException(NULL, env, "invalid VisualID .."); return 0; } @@ -396,7 +420,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_CreateDummy if (visual==NULL) { - _throwNewRuntimeException(dpy, env, "could not query Visual by given VisualID, bail out!\n"); + _throwNewRuntimeException(dpy, env, "could not query Visual by given VisualID, bail out!"); return 0; } @@ -440,13 +464,13 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_CreateDummy return (jlong) window; } - */ /* * Class: com_jogamp_nativewindow_impl_x11_X11Lib * Method: DestroyDummyWindow * Signature: (JJ)V + */ JNIEXPORT void JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_DestroyDummyWindow (JNIEnv *env, jobject obj, jlong display, jlong window) { @@ -454,7 +478,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_DestroyDummy Window w = (Window) window; if(NULL==dpy) { - _throwNewRuntimeException(NULL, env, "invalid display connection..\n"); + _throwNewRuntimeException(NULL, env, "invalid display connection.."); return; } XLockDisplay(dpy) ; @@ -467,5 +491,3 @@ JNIEXPORT void JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_DestroyDummy XUnlockDisplay(dpy) ; } - */ - diff --git a/src/newt/classes/com/jogamp/newt/NewtFactory.java b/src/newt/classes/com/jogamp/newt/NewtFactory.java index 2a696aa07..2d5c10c52 100755 --- a/src/newt/classes/com/jogamp/newt/NewtFactory.java +++ b/src/newt/classes/com/jogamp/newt/NewtFactory.java @@ -36,7 +36,7 @@ package com.jogamp.newt; import javax.media.nativewindow.*; import java.util.ArrayList; import java.util.Iterator; -import com.jogamp.nativewindow.impl.jvm.JVMUtil; +import com.jogamp.common.jvm.JVMUtil; public abstract class NewtFactory { // Work-around for initialization order problems on Mac OS X diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java index 8f09ae364..5123ab19f 100755 --- a/src/newt/classes/com/jogamp/newt/Window.java +++ b/src/newt/classes/com/jogamp/newt/Window.java @@ -36,8 +36,8 @@ package com.jogamp.newt; import com.jogamp.newt.impl.Debug; import com.jogamp.newt.util.EDTUtil; +import com.jogamp.common.util.*; import javax.media.nativewindow.*; -import com.jogamp.nativewindow.impl.NWReflection; import java.util.ArrayList; import java.util.Iterator; @@ -127,7 +127,7 @@ public abstract class Window implements NativeWindow if ( argsChecked < cstrArguments.length ) { throw new NativeWindowException("WindowClass "+windowClass+" constructor mismatch at argument #"+argsChecked+"; Constructor: "+getTypeStrList(cstrArgumentTypes)+", arguments: "+getArgsStrList(cstrArguments)); } - Window window = (Window) NWReflection.createInstance( windowClass, cstrArgumentTypes, cstrArguments ) ; + Window window = (Window) ReflectionUtil.createInstance( windowClass, cstrArgumentTypes, cstrArguments ) ; window.invalidate(); window.screen = screen; window.setUndecorated(undecorated); @@ -144,7 +144,6 @@ public abstract class Window implements NativeWindow } return window; } catch (Throwable t) { - t.printStackTrace(); throw new NativeWindowException(t); } } diff --git a/src/newt/classes/com/jogamp/newt/impl/NEWTJNILibLoader.java b/src/newt/classes/com/jogamp/newt/impl/NEWTJNILibLoader.java new file mode 100644 index 000000000..a4d234fd5 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/impl/NEWTJNILibLoader.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. 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. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.newt.impl; + +// FIXME: refactor Java SE dependencies +//import java.awt.Toolkit; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.HashSet; +import com.jogamp.common.jvm.JNILibLoaderBase; + +public class NEWTJNILibLoader extends JNILibLoaderBase { + + public static void loadNEWT() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + loadLibrary("newt", null, true); + return null; + } + }); + } + +} diff --git a/src/newt/classes/com/jogamp/newt/impl/NativeLibLoader.java b/src/newt/classes/com/jogamp/newt/impl/NativeLibLoader.java deleted file mode 100644 index 52e4c0dc3..000000000 --- a/src/newt/classes/com/jogamp/newt/impl/NativeLibLoader.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. 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. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.newt.impl; - -// FIXME: refactor Java SE dependencies -//import java.awt.Toolkit; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.HashSet; -import com.jogamp.nativewindow.impl.NativeLibLoaderBase; - -public class NativeLibLoader extends NativeLibLoaderBase { - - public static void loadNEWT() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - loadLibrary("newt", null, true); - return null; - } - }); - } - -} diff --git a/src/newt/classes/com/jogamp/newt/intel/gdl/Display.java b/src/newt/classes/com/jogamp/newt/intel/gdl/Display.java index eb93943ee..a3e5501c4 100644 --- a/src/newt/classes/com/jogamp/newt/intel/gdl/Display.java +++ b/src/newt/classes/com/jogamp/newt/intel/gdl/Display.java @@ -40,7 +40,7 @@ public class Display extends com.jogamp.newt.Display { static int initCounter = 0; static { - NativeLibLoader.loadNEWT(); + NEWTJNILibLoader.loadNEWT(); if (!Screen.initIDs()) { throw new NativeWindowException("Failed to initialize GDL Screen jmethodIDs"); diff --git a/src/newt/classes/com/jogamp/newt/macosx/MacDisplay.java b/src/newt/classes/com/jogamp/newt/macosx/MacDisplay.java index 2f86125f8..0b5297685 100755 --- a/src/newt/classes/com/jogamp/newt/macosx/MacDisplay.java +++ b/src/newt/classes/com/jogamp/newt/macosx/MacDisplay.java @@ -41,7 +41,7 @@ import com.jogamp.newt.util.MainThread; public class MacDisplay extends Display { static { - NativeLibLoader.loadNEWT(); + NEWTJNILibLoader.loadNEWT(); if(!initNSApplication()) { throw new NativeWindowException("Failed to initialize native Application hook"); diff --git a/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Display.java b/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Display.java index a375181ac..999a407ec 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Display.java +++ b/src/newt/classes/com/jogamp/newt/opengl/broadcom/egl/Display.java @@ -41,7 +41,7 @@ import javax.media.nativewindow.egl.*; public class Display extends com.jogamp.newt.Display { static { - NativeLibLoader.loadNEWT(); + NEWTJNILibLoader.loadNEWT(); if (!Window.initIDs()) { throw new NativeWindowException("Failed to initialize BCEGL Window jmethodIDs"); diff --git a/src/newt/classes/com/jogamp/newt/opengl/kd/KDDisplay.java b/src/newt/classes/com/jogamp/newt/opengl/kd/KDDisplay.java index b09568237..6a28f992b 100755 --- a/src/newt/classes/com/jogamp/newt/opengl/kd/KDDisplay.java +++ b/src/newt/classes/com/jogamp/newt/opengl/kd/KDDisplay.java @@ -42,7 +42,7 @@ import javax.media.nativewindow.egl.*; public class KDDisplay extends Display { static { - NativeLibLoader.loadNEWT(); + NEWTJNILibLoader.loadNEWT(); if (!KDWindow.initIDs()) { throw new NativeWindowException("Failed to initialize KDWindow jmethodIDs"); diff --git a/src/newt/classes/com/jogamp/newt/util/MainThread.java b/src/newt/classes/com/jogamp/newt/util/MainThread.java index 6cd4f8c69..daa09edce 100644 --- a/src/newt/classes/com/jogamp/newt/util/MainThread.java +++ b/src/newt/classes/com/jogamp/newt/util/MainThread.java @@ -43,10 +43,10 @@ import java.security.*; import javax.media.nativewindow.*; +import com.jogamp.common.util.*; import com.jogamp.newt.*; import com.jogamp.newt.impl.*; import com.jogamp.newt.macosx.MacDisplay; -import com.jogamp.nativewindow.impl.NWReflection; /** * NEWT Utility class MainThread

@@ -116,7 +116,7 @@ public class MainThread { // start user app .. try { - Class mainClass = NWReflection.getClass(mainClassName, true); + Class mainClass = ReflectionUtil.getClass(mainClassName, true); if(null==mainClass) { throw new RuntimeException(new ClassNotFoundException("MainThread couldn't find main class "+mainClassName)); } @@ -159,7 +159,7 @@ public class MainThread { System.arraycopy(args, 1, mainClassArgs, 0, args.length-1); } - NativeLibLoader.loadNEWT(); + NEWTJNILibLoader.loadNEWT(); shouldStop = false; tasks = new ArrayList(); diff --git a/src/newt/classes/com/jogamp/newt/windows/WindowsDisplay.java b/src/newt/classes/com/jogamp/newt/windows/WindowsDisplay.java index 05cab1a0a..281022901 100755 --- a/src/newt/classes/com/jogamp/newt/windows/WindowsDisplay.java +++ b/src/newt/classes/com/jogamp/newt/windows/WindowsDisplay.java @@ -45,7 +45,7 @@ public class WindowsDisplay extends Display { private static long hInstance; static { - NativeLibLoader.loadNEWT(); + NEWTJNILibLoader.loadNEWT(); if (!WindowsWindow.initIDs()) { throw new NativeWindowException("Failed to initialize WindowsWindow jmethodIDs"); diff --git a/src/newt/classes/com/jogamp/newt/x11/X11Display.java b/src/newt/classes/com/jogamp/newt/x11/X11Display.java index 5fd6d9640..c8faefbf1 100755 --- a/src/newt/classes/com/jogamp/newt/x11/X11Display.java +++ b/src/newt/classes/com/jogamp/newt/x11/X11Display.java @@ -41,7 +41,7 @@ import com.jogamp.nativewindow.impl.x11.X11Util; public class X11Display extends Display { static { - NativeLibLoader.loadNEWT(); + NEWTJNILibLoader.loadNEWT(); if (!initIDs()) { throw new NativeWindowException("Failed to initialize X11Display jmethodIDs"); diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index 33c5324e2..296172f6e 100755 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -159,11 +159,11 @@ static void _FatalError(JNIEnv *env, const char* msg, ...) va_end(ap); fprintf(stderr, buffer); + fprintf(stderr, "\n"); (*env)->FatalError(env, buffer); } -static const char * const ClazzNameRuntimeException = - "java/lang/RuntimeException"; +static const char * const ClazzNameRuntimeException = "java/lang/RuntimeException"; static jclass runtimeExceptionClz=NULL; static const char * const ClazzNameNewtWindow = @@ -200,6 +200,7 @@ static void _throwNewRuntimeException(Display * unlockDisplay, JNIEnv *env, cons */ +static JNIEnv * x11ErrorHandlerJNIEnv = NULL; static XErrorHandler origErrorHandler = NULL ; static int displayDispatchErrorHandler(Display *dpy, XErrorEvent *e) @@ -213,15 +214,16 @@ static int displayDispatchErrorHandler(Display *dpy, XErrorEvent *e) { fprintf(stderr, " BadWindow (%p): Window probably already removed\n", e->resourceid); } else { - return origErrorHandler(dpy, e); + _throwNewRuntimeException(NULL, x11ErrorHandlerJNIEnv, "NEWT X11 Error: Display %p, Code 0x%X", dpy, e->error_code); } return 0; } -static void displayDispatchErrorHandlerEnable(int onoff) { +static void displayDispatchErrorHandlerEnable(int onoff, JNIEnv * env) { if(onoff) { if(NULL==origErrorHandler) { + x11ErrorHandlerJNIEnv = env; origErrorHandler = XSetErrorHandler(displayDispatchErrorHandler); } } else { @@ -329,13 +331,13 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Display_CompleteDisplay javaObjectAtom = (jlong) XInternAtom(dpy, "JOGL_JAVA_OBJECT", False); if(None==javaObjectAtom) { - _throwNewRuntimeException(dpy, env, "could not create Atom JOGL_JAVA_OBJECT, bail out!\n"); + _throwNewRuntimeException(dpy, env, "could not create Atom JOGL_JAVA_OBJECT, bail out!"); return; } windowDeleteAtom = (jlong) XInternAtom(dpy, "WM_DELETE_WINDOW", False); if(None==windowDeleteAtom) { - _throwNewRuntimeException(dpy, env, "could not create Atom WM_DELETE_WINDOW, bail out!\n"); + _throwNewRuntimeException(dpy, env, "could not create Atom WM_DELETE_WINDOW, bail out!"); return; } @@ -371,7 +373,7 @@ static void setJavaWindowProperty(JNIEnv *env, Display *dpy, Window window, jlon { jobject test = (jobject) getPtrOut32Long(jogl_java_object_data); if( ! (jwindow==test) ) { - _throwNewRuntimeException(dpy, env, "Internal Error .. Encoded Window ref not the same %p != %p !\n", jwindow, test); + _throwNewRuntimeException(dpy, env, "Internal Error .. Encoded Window ref not the same %p != %p !", jwindow, test); return; } } @@ -415,7 +417,7 @@ static jobject getJavaWindowProperty(JNIEnv *env, Display *dpy, Window window, j #ifdef VERBOSE_ON if(JNI_FALSE == (*env)->IsInstanceOf(env, jwindow, newtWindowClz)) { - _throwNewRuntimeException(dpy, env, "fetched Atom JOGL_JAVA_OBJECT window is not a NEWT Window: javaWindow 0x%X !\n", jwindow); + _throwNewRuntimeException(dpy, env, "fetched Atom JOGL_JAVA_OBJECT window is not a NEWT Window: javaWindow 0x%X !", jwindow); } #endif return jwindow; @@ -457,20 +459,20 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Display_DispatchMessages num_events--; if( 0==evt.xany.window ) { - _throwNewRuntimeException(dpy, env, "event window NULL, bail out!\n"); + _throwNewRuntimeException(dpy, env, "event window NULL, bail out!"); return ; } if(dpy!=evt.xany.display) { - _throwNewRuntimeException(dpy, env, "wrong display, bail out!\n"); + _throwNewRuntimeException(dpy, env, "wrong display, bail out!"); return ; } - displayDispatchErrorHandlerEnable(1); + displayDispatchErrorHandlerEnable(1, env); jwindow = getJavaWindowProperty(env, dpy, evt.xany.window, javaObjectAtom); - displayDispatchErrorHandlerEnable(0); + displayDispatchErrorHandlerEnable(0, env); if(NULL==jwindow) { fprintf(stderr, "Warning: NEWT X11 DisplayDispatch %p, Couldn't handle event %d for invalid X11 window %p\n", @@ -685,7 +687,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_x11_X11Window_CreateWindow } if(visualID<0) { - _throwNewRuntimeException(NULL, env, "invalid VisualID ..\n"); + _throwNewRuntimeException(NULL, env, "invalid VisualID .."); return 0; } @@ -712,7 +714,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_x11_X11Window_CreateWindow if (visual==NULL) { - _throwNewRuntimeException(dpy, env, "could not query Visual by given VisualID, bail out!\n"); + _throwNewRuntimeException(dpy, env, "could not query Visual by given VisualID, bail out!"); return 0; } @@ -797,11 +799,11 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_x11_X11Window_CloseWindow jwindow = getJavaWindowProperty(env, dpy, w, javaObjectAtom); if(NULL==jwindow) { - _throwNewRuntimeException(dpy, env, "could not fetch Java Window object, bail out!\n"); + _throwNewRuntimeException(dpy, env, "could not fetch Java Window object, bail out!"); return; } if ( JNI_FALSE == (*env)->IsSameObject(env, jwindow, obj) ) { - _throwNewRuntimeException(dpy, env, "Internal Error .. Window global ref not the same!\n"); + _throwNewRuntimeException(dpy, env, "Internal Error .. Window global ref not the same!"); return; } (*env)->DeleteGlobalRef(env, jwindow); -- cgit v1.2.3 From ca6818d87ee86b2cc9961e47ad9f899e1fd90f78 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Thu, 22 Apr 2010 23:24:18 +0200 Subject: reviewed X11Lib.XLock/UnlockDisplay() usage: - added lock(); try{foo();}finally{unlock();} where missing - made sure lock is called outside the try block - fixed nesting in situations with two independent locks --- .../com/jogamp/opengl/impl/x11/glx/GLXUtil.java | 6 +- .../opengl/impl/x11/glx/X11GLXDrawableFactory.java | 27 ++- .../glx/X11GLXGraphicsConfigurationFactory.java | 270 +++++++++++---------- .../impl/x11/glx/X11OffscreenGLXDrawable.java | 103 ++++---- .../impl/x11/X11GraphicsConfigurationFactory.java | 4 +- .../media/nativewindow/x11/X11GraphicsScreen.java | 33 ++- 6 files changed, 236 insertions(+), 207 deletions(-) (limited to 'src/nativewindow/classes') diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/GLXUtil.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/GLXUtil.java index e3c1381f8..ec0eaf94f 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/GLXUtil.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/GLXUtil.java @@ -34,14 +34,12 @@ package com.jogamp.opengl.impl.x11.glx; import javax.media.opengl.*; -import com.jogamp.opengl.impl.*; -import javax.media.nativewindow.NativeWindowFactory; import com.jogamp.nativewindow.impl.x11.*; public class GLXUtil { public static boolean isMultisampleAvailable(long display) { + X11Lib.XLockDisplay(display); try { - X11Lib.XLockDisplay(display); String exts = GLX.glXGetClientString(display, GLX.GLX_EXTENSIONS); if (exts != null) { return (exts.indexOf("GLX_ARB_multisample") >= 0); @@ -55,8 +53,8 @@ public class GLXUtil { /** Workaround for apparent issue with ATI's proprietary drivers where direct contexts still send GLX tokens for GL calls */ public static String getVendorName(long display) { + X11Lib.XLockDisplay(display); try { - X11Lib.XLockDisplay(display); return GLX.glXGetClientString(display, GLX.GLX_VENDOR); } finally { X11Lib.XUnlockDisplay(display); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java index f331ad2a2..d8e5f7646 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java @@ -72,12 +72,15 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna } sharedScreen = new X11GraphicsScreen(sharedDevice, 0); X11Lib.XLockDisplay(sharedScreen.getDevice().getHandle()); - sharedDrawable = new X11DummyGLXDrawable(sharedScreen, this, null); - X11GLXContext ctx = (X11GLXContext) sharedDrawable.createContext(null); - ctx.makeCurrent(); - ctx.release(); - sharedContext = ctx; - X11Lib.XUnlockDisplay(sharedScreen.getDevice().getHandle()); + try{ + sharedDrawable = new X11DummyGLXDrawable(sharedScreen, this, null); + X11GLXContext ctx = (X11GLXContext) sharedDrawable.createContext(null); + ctx.makeCurrent(); + ctx.release(); + sharedContext = ctx; + }finally{ + X11Lib.XUnlockDisplay(sharedScreen.getDevice().getHandle()); + } if(null==sharedContext) { throw new GLException("Couldn't init shared resources"); } @@ -226,10 +229,16 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna protected NativeWindow createOffscreenWindow(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { validate(); + NullWindow nw = null; X11Lib.XLockDisplay(sharedScreen.getDevice().getHandle()); - NullWindow nw = new NullWindow(X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capabilities, chooser, sharedScreen)); - X11Lib.XUnlockDisplay(sharedScreen.getDevice().getHandle()); - nw.setSize(width, height); + try{ + nw = new NullWindow(X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capabilities, chooser, sharedScreen)); + }finally{ + X11Lib.XUnlockDisplay(sharedScreen.getDevice().getHandle()); + } + if(nw != null) { + nw.setSize(width, height); + } return nw; } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java index 477f2473c..e65fb5e90 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java @@ -190,108 +190,111 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac long display = absDevice.getHandle(); NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); - X11Lib.XLockDisplay(display); try { - int screen = x11Screen.getIndex(); - boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); - int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList(capabilities, true, isMultisampleAvailable, display, screen); - int[] count = { -1 }; - - // determine the recommended FBConfig .. - fbcfgsL = GLX.glXChooseFBConfigCopied(display, screen, attribs, 0, count, 0); - if (fbcfgsL == null || fbcfgsL.limit()<1) { - if(DEBUG) { - System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXChooseFBConfig ("+x11Screen+","+capabilities+"): "+fbcfgsL+", "+count[0]); - } - } else if( !X11GLXGraphicsConfiguration.GLXFBConfigValid( display, fbcfgsL.get(0) ) ) { - if(DEBUG) { - System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed - GLX FBConfig invalid: ("+x11Screen+","+capabilities+"): "+fbcfgsL+", fbcfg: "+toHexString(fbcfgsL.get(0))); - } - } else { - recommendedFBConfig = fbcfgsL.get(0); - } - - // get all, glXChooseFBConfig(.. attribs==null ..) == glXGetFBConfig(..) - fbcfgsL = GLX.glXChooseFBConfigCopied(display, screen, null, 0, count, 0); - if (fbcfgsL == null || fbcfgsL.limit()<1) { - if(DEBUG) { - System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXGetFBConfig ("+x11Screen+"): "+fbcfgsL+", "+count[0]); + X11Lib.XLockDisplay(display); + try{ + int screen = x11Screen.getIndex(); + boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); + int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList(capabilities, true, isMultisampleAvailable, display, screen); + int[] count = { -1 }; + + // determine the recommended FBConfig .. + fbcfgsL = GLX.glXChooseFBConfigCopied(display, screen, attribs, 0, count, 0); + if (fbcfgsL == null || fbcfgsL.limit()<1) { + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXChooseFBConfig ("+x11Screen+","+capabilities+"): "+fbcfgsL+", "+count[0]); + } + } else if( !X11GLXGraphicsConfiguration.GLXFBConfigValid( display, fbcfgsL.get(0) ) ) { + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed - GLX FBConfig invalid: ("+x11Screen+","+capabilities+"): "+fbcfgsL+", fbcfg: "+toHexString(fbcfgsL.get(0))); + } + } else { + recommendedFBConfig = fbcfgsL.get(0); } - return null; - } - // make GLCapabilities and seek the recommendedIndex - caps = new GLCapabilities[fbcfgsL.limit()]; - for (int i = 0; i < fbcfgsL.limit(); i++) { - if( !X11GLXGraphicsConfiguration.GLXFBConfigValid( display, fbcfgsL.get(i) ) ) { + // get all, glXChooseFBConfig(.. attribs==null ..) == glXGetFBConfig(..) + fbcfgsL = GLX.glXChooseFBConfigCopied(display, screen, null, 0, count, 0); + if (fbcfgsL == null || fbcfgsL.limit()<1) { if(DEBUG) { - System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: FBConfig invalid: ("+x11Screen+","+capabilities+"): fbcfg: "+toHexString(fbcfgsL.get(i))); + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXGetFBConfig ("+x11Screen+"): "+fbcfgsL+", "+count[0]); } - } else { - caps[i] = X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(glProfile, display, fbcfgsL.get(i), - false, onscreen, usePBuffer, isMultisampleAvailable); - if(caps[i]!=null && recommendedFBConfig==fbcfgsL.get(i)) { - recommendedIndex=i; - if (DEBUG) { - System.err.println("!!! glXChooseFBConfig recommended "+i+", "+caps[i]); + return null; + } + + // make GLCapabilities and seek the recommendedIndex + caps = new GLCapabilities[fbcfgsL.limit()]; + for (int i = 0; i < fbcfgsL.limit(); i++) { + if( !X11GLXGraphicsConfiguration.GLXFBConfigValid( display, fbcfgsL.get(i) ) ) { + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: FBConfig invalid: ("+x11Screen+","+capabilities+"): fbcfg: "+toHexString(fbcfgsL.get(i))); + } + } else { + caps[i] = X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(glProfile, display, fbcfgsL.get(i), + false, onscreen, usePBuffer, isMultisampleAvailable); + if(caps[i]!=null && recommendedFBConfig==fbcfgsL.get(i)) { + recommendedIndex=i; + if (DEBUG) { + System.err.println("!!! glXChooseFBConfig recommended "+i+", "+caps[i]); + } } } } - } - if(null==chooser) { - chosen = recommendedIndex; // may still be -1 in case nothing was recommended (-1) - } - - if (chosen < 0) { if(null==chooser) { - // nothing recommended .. so use our default implementation - chooser = new DefaultGLCapabilitiesChooser(); + chosen = recommendedIndex; // may still be -1 in case nothing was recommended (-1) } - try { - chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex); - } catch (NativeWindowException e) { + + if (chosen < 0) { + if(null==chooser) { + // nothing recommended .. so use our default implementation + chooser = new DefaultGLCapabilitiesChooser(); + } + try { + chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex); + } catch (NativeWindowException e) { + if(DEBUG) { + e.printStackTrace(); + } + chosen = -1; + } + } + if (chosen < 0) { + // keep on going .. if(DEBUG) { - e.printStackTrace(); + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig Failed .. unable to choose config, using first"); } - chosen = -1; - } - } - if (chosen < 0) { - // keep on going .. - if(DEBUG) { - System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig Failed .. unable to choose config, using first"); - } - // seek first available one .. - for(chosen = 0; chosen < caps.length && caps[chosen]==null; chosen++) ; - if(chosen==caps.length) { - // give up .. - if(DEBUG) { - System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig Failed .. nothing available, bail out"); - } - return null; - } - } else if (chosen >= caps.length) { - if(DEBUG) { - System.err.println("GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ", got "+chosen+")"); + // seek first available one .. + for(chosen = 0; chosen < caps.length && caps[chosen]==null; chosen++) ; + if(chosen==caps.length) { + // give up .. + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig Failed .. nothing available, bail out"); + } + return null; + } + } else if (chosen >= caps.length) { + if(DEBUG) { + System.err.println("GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ", got "+chosen+")"); + } + return null; } - return null; - } - retFBID = X11GLXGraphicsConfiguration.glXFBConfig2FBConfigID(display, fbcfgsL.get(chosen)); + retFBID = X11GLXGraphicsConfiguration.glXFBConfig2FBConfigID(display, fbcfgsL.get(chosen)); - retXVisualInfo = GLX.glXGetVisualFromFBConfigCopied(display, fbcfgsL.get(chosen)); - if (retXVisualInfo==null) { - if(DEBUG) { - System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXGetVisualFromFBConfig ("+x11Screen+", "+fbcfgsL.get(chosen) +" (Continue: "+(false==caps[chosen].isOnscreen())+"):\n\t"+caps[chosen]); - } - if(caps[chosen].isOnscreen()) { - // Onscreen drawables shall have a XVisual .. - return null; + retXVisualInfo = GLX.glXGetVisualFromFBConfigCopied(display, fbcfgsL.get(chosen)); + if (retXVisualInfo==null) { + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXGetVisualFromFBConfig ("+x11Screen+", "+fbcfgsL.get(chosen) +" (Continue: "+(false==caps[chosen].isOnscreen())+"):\n\t"+caps[chosen]); + } + if(caps[chosen].isOnscreen()) { + // Onscreen drawables shall have a XVisual .. + return null; + } } + }finally{ + X11Lib.XUnlockDisplay(display); } } finally { - X11Lib.XUnlockDisplay(display); NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); } @@ -320,60 +323,63 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac long display = absDevice.getHandle(); NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); - X11Lib.XLockDisplay(display); try { - int screen = x11Screen.getIndex(); - boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); - int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList(capabilities, false, isMultisampleAvailable, display, screen); - XVisualInfo[] infos = null; - - XVisualInfo recommendedVis = GLX.glXChooseVisualCopied(display, screen, attribs, 0); - if (DEBUG) { - System.err.print("!!! glXChooseVisual recommended "); - if (recommendedVis == null) { - System.err.println("null visual"); - } else { - System.err.println("visual id " + toHexString(recommendedVis.getVisualid())); + X11Lib.XLockDisplay(display); + try{ + int screen = x11Screen.getIndex(); + boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); + int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList(capabilities, false, isMultisampleAvailable, display, screen); + XVisualInfo[] infos = null; + + XVisualInfo recommendedVis = GLX.glXChooseVisualCopied(display, screen, attribs, 0); + if (DEBUG) { + System.err.print("!!! glXChooseVisual recommended "); + if (recommendedVis == null) { + System.err.println("null visual"); + } else { + System.err.println("visual id " + toHexString(recommendedVis.getVisualid())); + } } - } - int[] count = new int[1]; - XVisualInfo template = XVisualInfo.create(); - template.setScreen(screen); - infos = X11Lib.XGetVisualInfoCopied(display, X11Lib.VisualScreenMask, template, count, 0); - if (infos == null || infos.length<1) { - throw new GLException("Error while enumerating available XVisualInfos"); - } - caps = new GLCapabilities[infos.length]; - for (int i = 0; i < infos.length; i++) { - caps[i] = X11GLXGraphicsConfiguration.XVisualInfo2GLCapabilities(glProfile, display, infos[i], onscreen, false, isMultisampleAvailable); - // Attempt to find the visual chosen by glXChooseVisual - if (recommendedVis != null && recommendedVis.getVisualid() == infos[i].getVisualid()) { - recommendedIndex = i; + int[] count = new int[1]; + XVisualInfo template = XVisualInfo.create(); + template.setScreen(screen); + infos = X11Lib.XGetVisualInfoCopied(display, X11Lib.VisualScreenMask, template, count, 0); + if (infos == null || infos.length<1) { + throw new GLException("Error while enumerating available XVisualInfos"); } + caps = new GLCapabilities[infos.length]; + for (int i = 0; i < infos.length; i++) { + caps[i] = X11GLXGraphicsConfiguration.XVisualInfo2GLCapabilities(glProfile, display, infos[i], onscreen, false, isMultisampleAvailable); + // Attempt to find the visual chosen by glXChooseVisual + if (recommendedVis != null && recommendedVis.getVisualid() == infos[i].getVisualid()) { + recommendedIndex = i; + } + } + try { + chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex); + } catch (NativeWindowException e) { + if(DEBUG) { + e.printStackTrace(); + } + chosen = -1; + } + if (chosen < 0) { + // keep on going .. + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationXVisual Failed .. unable to choose config, using first"); + } + chosen = 0; // default .. + } else if (chosen >= caps.length) { + throw new GLException("GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); + } + if (infos[chosen] == null) { + throw new GLException("GLCapabilitiesChooser chose an invalid visual for "+caps[chosen]); + } + retXVisualInfo = XVisualInfo.create(infos[chosen]); + }finally{ + X11Lib.XUnlockDisplay(display); } - try { - chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex); - } catch (NativeWindowException e) { - if(DEBUG) { - e.printStackTrace(); - } - chosen = -1; - } - if (chosen < 0) { - // keep on going .. - if(DEBUG) { - System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationXVisual Failed .. unable to choose config, using first"); - } - chosen = 0; // default .. - } else if (chosen >= caps.length) { - throw new GLException("GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); - } - if (infos[chosen] == null) { - throw new GLException("GLCapabilitiesChooser chose an invalid visual for "+caps[chosen]); - } - retXVisualInfo = XVisualInfo.create(infos[chosen]); } finally { - X11Lib.XUnlockDisplay(display); NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); } return new X11GLXGraphicsConfiguration(x11Screen, caps[chosen], capabilities, chooser, retXVisualInfo, 0, -1); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java index 41f012122..14d07e74f 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java @@ -41,7 +41,6 @@ package com.jogamp.opengl.impl.x11.glx; import javax.media.nativewindow.*; import javax.media.opengl.*; -import com.jogamp.opengl.impl.*; import com.jogamp.nativewindow.impl.x11.*; public class X11OffscreenGLXDrawable extends X11GLXDrawable { @@ -75,27 +74,31 @@ public class X11OffscreenGLXDrawable extends X11GLXDrawable { int screen = aScreen.getIndex(); getFactoryImpl().lockToolkit(); - X11Lib.XLockDisplay(dpy); try { - pixmap = X11Lib.XCreatePixmap(dpy, X11Lib.RootWindow(dpy, screen), - component.getWidth(), component.getHeight(), bitsPerPixel); - if (pixmap == 0) { - throw new GLException("XCreatePixmap failed"); - } - long drawable = GLX.glXCreateGLXPixmap(dpy, vis, pixmap); - if (drawable == 0) { - X11Lib.XFreePixmap(dpy, pixmap); - pixmap = 0; - throw new GLException("glXCreateGLXPixmap failed"); - } - ((SurfaceChangeable)nw).setSurfaceHandle(drawable); - if (DEBUG) { - System.err.println("Created pixmap " + toHexString(pixmap) + - ", GLXPixmap " + toHexString(drawable) + - ", display " + toHexString(dpy)); - } + X11Lib.XLockDisplay(dpy); + try{ + + pixmap = X11Lib.XCreatePixmap(dpy, X11Lib.RootWindow(dpy, screen), + component.getWidth(), component.getHeight(), bitsPerPixel); + if (pixmap == 0) { + throw new GLException("XCreatePixmap failed"); + } + long drawable = GLX.glXCreateGLXPixmap(dpy, vis, pixmap); + if (drawable == 0) { + X11Lib.XFreePixmap(dpy, pixmap); + pixmap = 0; + throw new GLException("glXCreateGLXPixmap failed"); + } + ((SurfaceChangeable)nw).setSurfaceHandle(drawable); + if (DEBUG) { + System.err.println("Created pixmap " + toHexString(pixmap) + + ", GLXPixmap " + toHexString(drawable) + + ", display " + toHexString(dpy)); + } + }finally{ + X11Lib.XUnlockDisplay(dpy); + } } finally { - X11Lib.XUnlockDisplay(dpy); getFactoryImpl().unlockToolkit(); } } @@ -107,37 +110,41 @@ public class X11OffscreenGLXDrawable extends X11GLXDrawable { long display = nw.getDisplayHandle(); getFactoryImpl().lockToolkit(); - X11Lib.XLockDisplay(display); try { - long drawable = nw.getSurfaceHandle(); - if (DEBUG) { - System.err.println("Destroying pixmap " + toHexString(pixmap) + - ", GLXPixmap " + toHexString(drawable) + - ", display " + toHexString(display)); - } - - // Must destroy pixmap and GLXPixmap - - if (DEBUG) { - long cur = GLX.glXGetCurrentContext(); - if (cur != 0) { - System.err.println("WARNING: found context " + toHexString(cur) + " current during pixmap destruction"); + X11Lib.XLockDisplay(display); + try{ + long drawable = nw.getSurfaceHandle(); + if (DEBUG) { + System.err.println("Destroying pixmap " + toHexString(pixmap) + + ", GLXPixmap " + toHexString(drawable) + + ", display " + toHexString(display)); + } + + // Must destroy pixmap and GLXPixmap + + if (DEBUG) { + long cur = GLX.glXGetCurrentContext(); + if (cur != 0) { + System.err.println("WARNING: found context " + toHexString(cur) + " current during pixmap destruction"); + } + } + + // FIXME: workaround for crashes on NVidia hardware when + // destroying pixmap (no context is current at the point of the + // crash, at least from the point of view of + // glXGetCurrentContext) + GLX.glXMakeCurrent(display, 0, 0); + + GLX.glXDestroyGLXPixmap(display, drawable); + X11Lib.XFreePixmap(display, pixmap); + drawable = 0; + pixmap = 0; + ((SurfaceChangeable)nw).setSurfaceHandle(0); + + }finally{ + X11Lib.XUnlockDisplay(display); } - } - - // FIXME: workaround for crashes on NVidia hardware when - // destroying pixmap (no context is current at the point of the - // crash, at least from the point of view of - // glXGetCurrentContext) - GLX.glXMakeCurrent(display, 0, 0); - - GLX.glXDestroyGLXPixmap(display, drawable); - X11Lib.XFreePixmap(display, pixmap); - drawable = 0; - pixmap = 0; - ((SurfaceChangeable)nw).setSurfaceHandle(0); } finally { - X11Lib.XUnlockDisplay(display); getFactoryImpl().unlockToolkit(); display = 0; } diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java index 4ffda2fae..a6f52f3c0 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java @@ -58,8 +58,8 @@ public class X11GraphicsConfigurationFactory extends GraphicsConfigurationFactor int num[] = { -1 }; long display = screen.getDevice().getHandle(); + X11Lib.XLockDisplay(display); try { - X11Lib.XLockDisplay(display); XVisualInfo[] xvis = X11Lib.XGetVisualInfoCopied(display, X11Lib.VisualIDMask|X11Lib.VisualScreenMask, xvi_temp, num, 0); if(xvis==null || num[0]<1) { @@ -90,8 +90,8 @@ public class X11GraphicsConfigurationFactory extends GraphicsConfigurationFactor vinfo_template.setC_class(c_class); long display = screen.getDevice().getHandle(); + X11Lib.XLockDisplay(display); try { - X11Lib.XLockDisplay(display); XVisualInfo[] vinfos = X11Lib.XGetVisualInfoCopied(display, X11Lib.VisualScreenMask, vinfo_template, num, 0); XVisualInfo best=null; int rdepth = capabilities.getRedBits() + capabilities.getGreenBits() + capabilities.getBlueBits() + capabilities.getAlphaBits(); diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java index 69ace3c52..58b40efe0 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java +++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java @@ -57,13 +57,16 @@ public class X11GraphicsScreen extends DefaultGraphicsScreen implements Cloneabl /** Creates a new X11GraphicsScreen using a thread local display connection */ public static AbstractGraphicsScreen createDefault() { NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); - long display = X11Util.createThreadLocalDefaultDisplay(); try { + long display = X11Util.createThreadLocalDefaultDisplay(); X11Lib.XLockDisplay(display); - int scrnIdx = X11Lib.DefaultScreen(display); - return createScreenDevice(display, scrnIdx); + try{ + int scrnIdx = X11Lib.DefaultScreen(display); + return createScreenDevice(display, scrnIdx); + }finally{ + X11Lib.XUnlockDisplay(display); + } } finally { - X11Lib.XUnlockDisplay(display); NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); } } @@ -71,13 +74,16 @@ public class X11GraphicsScreen extends DefaultGraphicsScreen implements Cloneabl public long getDefaultVisualID() { // It still could be an AWT hold handle .. NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); - long display = getDevice().getHandle(); try { + long display = getDevice().getHandle(); X11Lib.XLockDisplay(display); - int scrnIdx = X11Lib.DefaultScreen(display); - return X11Lib.DefaultVisualID(display, scrnIdx); + try{ + int scrnIdx = X11Lib.DefaultScreen(display); + return X11Lib.DefaultVisualID(display, scrnIdx); + }finally{ + X11Lib.XUnlockDisplay(display); + } } finally { - X11Lib.XUnlockDisplay(display); NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); } } @@ -85,14 +91,17 @@ public class X11GraphicsScreen extends DefaultGraphicsScreen implements Cloneabl private static int fetchScreen(X11GraphicsDevice device, int screen) { // It still could be an AWT hold handle .. NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); - long display = device.getHandle(); try { + long display = device.getHandle(); X11Lib.XLockDisplay(display); - if(X11Lib.XineramaEnabled(display)) { - screen = 0; // Xinerama -> 1 screen + try{ + if(X11Lib.XineramaEnabled(display)) { + screen = 0; // Xinerama -> 1 screen + } + }finally{ + X11Lib.XUnlockDisplay(display); } } finally { - X11Lib.XUnlockDisplay(display); NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); } return screen; -- cgit v1.2.3