From 3f72e907e869370b98dc7519ae5fc53681376450 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Sat, 27 Mar 2010 23:28:04 +0100 Subject: refactoring part 3 (impl package): renamed com.sun.opengl -> com.jogamp.opengl. --- .../opengl/impl/egl/EGLOnscreenDrawable.java | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/jogl/classes/com/jogamp/opengl/impl/egl/EGLOnscreenDrawable.java (limited to 'src/jogl/classes/com/jogamp/opengl/impl/egl/EGLOnscreenDrawable.java') diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLOnscreenDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLOnscreenDrawable.java new file mode 100644 index 000000000..d37a36fb0 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLOnscreenDrawable.java @@ -0,0 +1,82 @@ +/* + * 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.egl; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; +import javax.media.nativewindow.egl.*; +import com.jogamp.opengl.impl.*; +import com.sun.nativewindow.impl.NullWindow; + +public class EGLOnscreenDrawable extends EGLDrawable { + protected EGLOnscreenDrawable(EGLDrawableFactory factory, NativeWindow component) throws GLException { + super(factory, component); + } + + public GLContext createContext(GLContext shareWith) { + return new EGLOnscreenContext(this, shareWith); + } + + protected long createSurface(long eglDpy, _EGLConfig eglNativeCfg, long surfaceHandle) { + return EGL.eglCreateWindowSurface(eglDpy, eglNativeCfg, surfaceHandle, null); + } + + protected void swapBuffersImpl() { + boolean didLock = false; + try { + if ( !isSurfaceLocked() ) { + // Usually the surface shall be locked within [makeCurrent .. swap .. release] + if (lockSurface() == NativeWindow.LOCK_SURFACE_NOT_READY) { + return; + } + didLock = true; + } + + EGL.eglSwapBuffers(eglDisplay, eglSurface); + + } finally { + if(didLock) { + unlockSurface(); + } + } + } + +} + -- 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/jogl/classes/com/jogamp/opengl/impl/egl/EGLOnscreenDrawable.java') 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 1a2a54a83a9adb95b4bfe9c337751acbef0cb0d3 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 30 Mar 2010 02:01:15 +0200 Subject: Adaptions to http://www.jogamp.org/bugzilla/show_bug.cgi?id=392 7220416bcef3140883d3966d921442feae3107c4 --- make/stub_includes/egl/EGL/egl.h | 8 +-- .../com/jogamp/opengl/impl/egl/EGLContext.java | 4 +- .../com/jogamp/opengl/impl/egl/EGLDrawable.java | 2 +- .../opengl/impl/egl/EGLGraphicsConfiguration.java | 57 +++++++++++----------- .../impl/egl/EGLGraphicsConfigurationFactory.java | 20 ++++---- .../opengl/impl/egl/EGLOnscreenDrawable.java | 2 +- .../jogamp/opengl/impl/egl/EGLPbufferDrawable.java | 2 +- .../impl/macosx/cgl/MacOSXPbufferCGLContext.java | 15 +++--- .../impl/macosx/cgl/MacOSXPbufferCGLDrawable.java | 7 +-- .../windows/wgl/WindowsOffscreenWGLDrawable.java | 2 +- 10 files changed, 59 insertions(+), 60 deletions(-) (limited to 'src/jogl/classes/com/jogamp/opengl/impl/egl/EGLOnscreenDrawable.java') diff --git a/make/stub_includes/egl/EGL/egl.h b/make/stub_includes/egl/EGL/egl.h index fc6cc4c87..a384bab48 100755 --- a/make/stub_includes/egl/EGL/egl.h +++ b/make/stub_includes/egl/EGL/egl.h @@ -20,13 +20,7 @@ extern "C" { typedef int32_t EGLint; typedef unsigned int EGLBoolean; typedef unsigned int EGLenum; -#ifdef USE_GLUEGEN - /* GlueGen currently needs this form of typedef to produce distinct - types for each of these pointer types */ - typedef struct {} _EGLConfig, *EGLConfig; -#else - typedef void *EGLConfig; -#endif +typedef void *EGLConfig; typedef void *EGLContext; typedef void *EGLDisplay; typedef void *EGLSurface; 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 42d4588b5..ec2677559 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java @@ -158,13 +158,13 @@ public abstract class EGLContext extends GLContextImpl { long eglDisplay = ((EGLDrawable)drawable).getDisplay(); EGLGraphicsConfiguration config = ((EGLDrawable)drawable).getGraphicsConfiguration(); GLProfile glProfile = drawable.getGLProfile(); - _EGLConfig eglConfig = config.getNativeConfig(); + long eglConfig = config.getNativeConfig(); long shareWith = EGL.EGL_NO_CONTEXT; if (eglDisplay == 0) { throw new GLException("Error: attempted to create an OpenGL context without a display connection"); } - if (eglConfig == null) { + if (eglConfig == 0) { throw new GLException("Error: attempted to create an OpenGL context without a graphics configuration"); } 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 f3695ed16..db5ee6ac6 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawable.java @@ -75,7 +75,7 @@ public abstract class EGLDrawable extends GLDrawableImpl { public abstract GLContext createContext(GLContext shareWith); - protected abstract long createSurface(long eglDpy, _EGLConfig eglNativeCfg, long surfaceHandle); + protected abstract long createSurface(long eglDpy, long eglNativeCfg, long surfaceHandle); private void recreateSurface() { // create a new EGLSurface .. 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 33f9db140..43c99a422 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfiguration.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfiguration.java @@ -41,12 +41,13 @@ import javax.media.nativewindow.egl.*; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; import com.jogamp.gluegen.runtime.NativeLibrary; +import com.jogamp.gluegen.runtime.PointerBuffer; public class EGLGraphicsConfiguration extends DefaultGraphicsConfiguration implements Cloneable { protected static final boolean DEBUG = Debug.debug("GraphicsConfiguration"); - public _EGLConfig getNativeConfig() { - return _config; + public long getNativeConfig() { + return config; } public int getNativeConfigID() { @@ -55,10 +56,10 @@ public class EGLGraphicsConfiguration extends DefaultGraphicsConfiguration imple public EGLGraphicsConfiguration(AbstractGraphicsScreen absScreen, GLCapabilities capsChosen, GLCapabilities capsRequested, GLCapabilitiesChooser chooser, - _EGLConfig cfg, int cfgID) { + long cfg, int cfgID) { super(absScreen, capsChosen, capsRequested); this.chooser = chooser; - _config = cfg; + config = cfg; configID = cfgID; } @@ -72,9 +73,9 @@ public class EGLGraphicsConfiguration extends DefaultGraphicsConfiguration imple throw new GLException("Invalid EGL display: "+absDevice); } GLProfile glp = capsRequested.getGLProfile(); - _EGLConfig _cfg = EGLConfigId2EGLConfig(glp, dpy, cfgID); - GLCapabilities caps = EGLConfig2Capabilities(glp, dpy, _cfg, false, capsRequested.isOnscreen(), capsRequested.isPBuffer()); - return new EGLGraphicsConfiguration(absScreen, caps, capsRequested, new DefaultGLCapabilitiesChooser(), _cfg, cfgID); + long cfg = EGLConfigId2EGLConfig(glp, dpy, cfgID); + GLCapabilities caps = EGLConfig2Capabilities(glp, dpy, cfg, false, capsRequested.isOnscreen(), capsRequested.isPBuffer()); + return new EGLGraphicsConfiguration(absScreen, caps, capsRequested, new DefaultGLCapabilitiesChooser(), cfg, cfgID); } public Object clone() { @@ -89,7 +90,7 @@ public class EGLGraphicsConfiguration extends DefaultGraphicsConfiguration imple if(null!=newConfig) { // FIXME: setScreen( ... ); setChosenCapabilities(newConfig.getChosenCapabilities()); - _config = newConfig.getNativeConfig(); + config = newConfig.getNativeConfig(); configID = newConfig.getNativeConfigID(); if(DEBUG) { System.err.println("!!! updateGraphicsConfiguration: "+this); @@ -97,23 +98,23 @@ public class EGLGraphicsConfiguration extends DefaultGraphicsConfiguration imple } } - public static _EGLConfig EGLConfigId2EGLConfig(GLProfile glp, long display, int configID) { + public static long EGLConfigId2EGLConfig(GLProfile glp, long display, int configID) { int[] attrs = new int[] { EGL.EGL_CONFIG_ID, configID, EGL.EGL_NONE }; - _EGLConfig[] configs = new _EGLConfig[1]; + PointerBuffer configs = PointerBuffer.allocateDirect(1); int[] numConfigs = new int[1]; if (!EGL.eglChooseConfig(display, attrs, 0, configs, 1, numConfigs, 0)) { - return null; + return 0; } if (numConfigs[0] == 0) { - return null; + return 0; } - return configs[0]; + return configs.get(0); } public static boolean EGLConfigDrawableTypeVerify(int val, boolean onscreen, boolean usePBuffer) { @@ -131,53 +132,53 @@ public class EGLGraphicsConfiguration extends DefaultGraphicsConfiguration imple return res; } - public static GLCapabilities EGLConfig2Capabilities(GLProfile glp, long display, _EGLConfig _config, + public static GLCapabilities EGLConfig2Capabilities(GLProfile glp, long display, long config, boolean relaxed, boolean onscreen, boolean usePBuffer) { GLCapabilities caps = new GLCapabilities(glp); int[] val = new int[1]; // Read the actual configuration into the choosen caps - if(EGL.eglGetConfigAttrib(display, _config, EGL.EGL_RED_SIZE, val, 0)) { + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_RED_SIZE, val, 0)) { caps.setRedBits(val[0]); } - if(EGL.eglGetConfigAttrib(display, _config, EGL.EGL_GREEN_SIZE, val, 0)) { + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_GREEN_SIZE, val, 0)) { caps.setGreenBits(val[0]); } - if(EGL.eglGetConfigAttrib(display, _config, EGL.EGL_BLUE_SIZE, val, 0)) { + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_BLUE_SIZE, val, 0)) { caps.setBlueBits(val[0]); } - if(EGL.eglGetConfigAttrib(display, _config, EGL.EGL_ALPHA_SIZE, val, 0)) { + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_ALPHA_SIZE, val, 0)) { caps.setAlphaBits(val[0]); } - if(EGL.eglGetConfigAttrib(display, _config, EGL.EGL_STENCIL_SIZE, val, 0)) { + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_STENCIL_SIZE, val, 0)) { caps.setStencilBits(val[0]); } - if(EGL.eglGetConfigAttrib(display, _config, EGL.EGL_DEPTH_SIZE, val, 0)) { + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_DEPTH_SIZE, val, 0)) { caps.setDepthBits(val[0]); } - if(EGL.eglGetConfigAttrib(display, _config, EGL.EGL_SAMPLES, val, 0)) { + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_SAMPLES, val, 0)) { caps.setSampleBuffers(val[0]>0?true:false); caps.setNumSamples(val[0]); } - if(EGL.eglGetConfigAttrib(display, _config, EGL.EGL_TRANSPARENT_TYPE, val, 0)) { + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_TRANSPARENT_TYPE, val, 0)) { caps.setBackgroundOpaque(val[0] != EGL.EGL_TRANSPARENT_RGB); } if(!caps.isBackgroundOpaque()) { - if(EGL.eglGetConfigAttrib(display, _config, EGL.EGL_TRANSPARENT_RED_VALUE, val, 0)) { + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_TRANSPARENT_RED_VALUE, val, 0)) { caps.setTransparentRedValue(val[0]==EGL.EGL_DONT_CARE?-1:val[0]); } - if(EGL.eglGetConfigAttrib(display, _config, EGL.EGL_TRANSPARENT_GREEN_VALUE, val, 0)) { + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_TRANSPARENT_GREEN_VALUE, val, 0)) { caps.setTransparentGreenValue(val[0]==EGL.EGL_DONT_CARE?-1:val[0]); } - if(EGL.eglGetConfigAttrib(display, _config, EGL.EGL_TRANSPARENT_BLUE_VALUE, val, 0)) { + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_TRANSPARENT_BLUE_VALUE, val, 0)) { caps.setTransparentBlueValue(val[0]==EGL.EGL_DONT_CARE?-1:val[0]); } /** Not defined in EGL - if(EGL.eglGetConfigAttrib(display, _config, EGL.EGL_TRANSPARENT_ALPHA_VALUE, val, 0)) { + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_TRANSPARENT_ALPHA_VALUE, val, 0)) { caps.setTransparentAlphaValue(val[0]==EGL.EGL_DONT_CARE?-1:val[0]); } */ } - if(EGL.eglGetConfigAttrib(display, _config, EGL.EGL_SURFACE_TYPE, val, 0)) { + if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_SURFACE_TYPE, val, 0)) { if(EGLConfigDrawableTypeVerify(val[0], onscreen, usePBuffer)) { caps.setDoubleBuffered(onscreen); caps.setOnscreen(onscreen); @@ -300,7 +301,7 @@ public class EGLGraphicsConfiguration extends DefaultGraphicsConfiguration imple } private GLCapabilitiesChooser chooser; - private _EGLConfig _config; + private long config; private int configID; } 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 0a9edd239..f315a514c 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfigurationFactory.java @@ -40,6 +40,8 @@ import com.jogamp.nativewindow.impl.*; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; +import com.jogamp.gluegen.runtime.PointerBuffer; + /** Subclass of GraphicsConfigurationFactory used when non-AWT tookits are used on X11 platforms. Toolkits will likely need to delegate to this one to change the accepted and returned types of the @@ -115,10 +117,10 @@ public class EGLGraphicsConfigurationFactory extends GraphicsConfigurationFactor chooser = new DefaultGLCapabilitiesChooser(); } - _EGLConfig[] configs = new _EGLConfig[10]; + PointerBuffer configs = PointerBuffer.allocateDirect(10); int[] numConfigs = new int[1]; - if(!EGL.eglGetConfigs(eglDisplay, configs, configs.length, numConfigs, 0)) { + if(!EGL.eglGetConfigs(eglDisplay, configs, configs.capacity(), numConfigs, 0)) { throw new GLException("Graphics configuration fetch (eglGetConfigs) failed"); } if (numConfigs[0] == 0) { @@ -205,11 +207,11 @@ public class EGLGraphicsConfigurationFactory extends GraphicsConfigurationFactor AbstractGraphicsScreen absScreen) { GLProfile glp = capsChosen0.getGLProfile(); int[] attrs = EGLGraphicsConfiguration.GLCapabilities2AttribList(capsChosen0); - _EGLConfig[] configs = new _EGLConfig[1]; + PointerBuffer configs = PointerBuffer.allocateDirect(1); int[] numConfigs = new int[1]; if (!EGL.eglChooseConfig(eglDisplay, attrs, 0, - configs, configs.length, + configs, configs.capacity(), numConfigs, 0)) { throw new GLException("Graphics configuration selection (eglChooseConfig) failed for "+capsChosen0); } @@ -222,14 +224,14 @@ public class EGLGraphicsConfigurationFactory extends GraphicsConfigurationFactor } int[] val = new int[1]; // get the configID - if(!EGL.eglGetConfigAttrib(eglDisplay, configs[0], EGL.EGL_CONFIG_ID, val, 0)) { + if(!EGL.eglGetConfigAttrib(eglDisplay, configs.get(0), EGL.EGL_CONFIG_ID, val, 0)) { if(DEBUG) { // FIXME: this happens on a ATI PC Emulation .. System.err.println("EGL couldn't retrieve ConfigID for already chosen eglConfig "+capsChosen0+", error 0x"+Integer.toHexString(EGL.eglGetError())); } return null; } - GLCapabilities capsChosen1 = EGLGraphicsConfiguration.EGLConfig2Capabilities(glp, eglDisplay, configs[0], + GLCapabilities capsChosen1 = EGLGraphicsConfiguration.EGLConfig2Capabilities(glp, eglDisplay, configs.get(0), true, capsChosen0.isOnscreen(), capsChosen0.isPBuffer()); if(null!=capsChosen1) { if(DEBUG) { @@ -237,7 +239,7 @@ public class EGLGraphicsConfigurationFactory extends GraphicsConfigurationFactor ", eglConfig ID 0x"+Integer.toHexString(val[0])+ ", "+capsChosen0+" -> "+capsChosen1); } - return new EGLGraphicsConfiguration(absScreen, capsChosen1, capsRequested, chooser, configs[0], val[0]); + return new EGLGraphicsConfiguration(absScreen, capsChosen1, capsRequested, chooser, configs.get(0), val[0]); } if(DEBUG) { System.err.println("eglChooseConfig couldn't verify: eglDisplay 0x"+Long.toHexString(eglDisplay)+ @@ -253,11 +255,11 @@ public class EGLGraphicsConfigurationFactory extends GraphicsConfigurationFactor return null; } - protected static GLCapabilities[] eglConfigs2GLCaps(GLProfile glp, long eglDisplay, _EGLConfig[] configs, int num, + protected static GLCapabilities[] eglConfigs2GLCaps(GLProfile glp, long eglDisplay, PointerBuffer configs, int num, boolean onscreen, boolean usePBuffer) { GLCapabilities[] caps = new GLCapabilities[num]; for(int i=0; i Date: Fri, 23 Apr 2010 02:00:27 +0200 Subject: reviewed calls to lockSurface() and ensured propper unlocking. --- .../opengl/impl/egl/EGLOnscreenDrawable.java | 24 +++++++-------- .../opengl/impl/macosx/cgl/MacOSXCGLDrawable.java | 7 ++--- .../impl/windows/wgl/WindowsWGLDrawable.java | 14 ++++----- .../jogamp/opengl/impl/x11/glx/X11GLXDrawable.java | 34 ++++++++++------------ src/newt/classes/com/jogamp/newt/Window.java | 2 +- 5 files changed, 37 insertions(+), 44 deletions(-) (limited to 'src/jogl/classes/com/jogamp/opengl/impl/egl/EGLOnscreenDrawable.java') 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 3286367e5..3864fc39c 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLOnscreenDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLOnscreenDrawable.java @@ -60,21 +60,19 @@ public class EGLOnscreenDrawable extends EGLDrawable { protected void swapBuffersImpl() { boolean didLock = false; + if (!isSurfaceLocked()) { + // Usually the surface shall be locked within [makeCurrent .. swap .. release] + if (lockSurface() == NativeWindow.LOCK_SURFACE_NOT_READY) { + return; + } + didLock = true; + } try { - if ( !isSurfaceLocked() ) { - // Usually the surface shall be locked within [makeCurrent .. swap .. release] - if (lockSurface() == NativeWindow.LOCK_SURFACE_NOT_READY) { - return; - } - didLock = true; - } - - EGL.eglSwapBuffers(eglDisplay, eglSurface); - + EGL.eglSwapBuffers(eglDisplay, eglSurface); } finally { - if(didLock) { - unlockSurface(); - } + if (didLock) { + unlockSurface(); + } } } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawable.java index 5816b2101..cf29d214b 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawable.java @@ -87,11 +87,8 @@ public abstract class MacOSXCGLDrawable extends GLDrawableImpl { if( NativeWindow.LOCK_SURFACE_NOT_READY == lockSurface() ) { throw new GLException("Couldn't lock surface"); } - try { - // don't remove this block .. locking the surface is essential to update surface data - } finally { - unlockSurface(); - } + // locking the surface is essential to update surface data + unlockSurface(); } } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawable.java index fe0945139..43c1ff5e0 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawable.java @@ -83,14 +83,14 @@ public abstract class WindowsWGLDrawable extends GLDrawableImpl { protected void swapBuffersImpl() { boolean didLock = false; - try { - if ( !isSurfaceLocked() ) { - // Usually the surface shall be locked within [makeCurrent .. swap .. release] - if (lockSurface() == NativeWindow.LOCK_SURFACE_NOT_READY) { - return; - } - didLock = true; + if ( !isSurfaceLocked() ) { + // Usually the surface shall be locked within [makeCurrent .. swap .. release] + if (lockSurface() == NativeWindow.LOCK_SURFACE_NOT_READY) { + return; } + didLock = true; + } + try { long startTime = 0; if (PROFILING) { 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 2dabe774c..95dfc0a1c 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 @@ -73,25 +73,23 @@ public abstract class X11GLXDrawable extends GLDrawableImpl { } } - protected void swapBuffersImpl() { - boolean didLock = false; - try { - if ( !isSurfaceLocked() ) { - // Usually the surface shall be locked within [makeCurrent .. swap .. release] - if (lockSurface() == NativeWindow.LOCK_SURFACE_NOT_READY) { - return; - } - didLock=true; - } - - GLX.glXSwapBuffers(component.getDisplayHandle(), component.getSurfaceHandle()); - - } finally { - if(didLock) { - unlockSurface(); - } + protected void swapBuffersImpl() { + boolean didLock = false; + if (!isSurfaceLocked()) { + // Usually the surface shall be locked within [makeCurrent .. swap .. release] + if (lockSurface() == NativeWindow.LOCK_SURFACE_NOT_READY) { + return; + } + didLock = true; + } + try { + GLX.glXSwapBuffers(component.getDisplayHandle(), component.getSurfaceHandle()); + } finally { + if (didLock) { + unlockSurface(); + } + } } - } //--------------------------------------------------------------------------- // Internals only below this point diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java index 5123ab19f..a3d034792 100755 --- a/src/newt/classes/com/jogamp/newt/Window.java +++ b/src/newt/classes/com/jogamp/newt/Window.java @@ -342,8 +342,8 @@ public abstract class Window implements NativeWindow keyListeners = new ArrayList(); } synchronized(this) { + destructionLock.lock(); try { - destructionLock.lock(); Display dpy = null; if( null != screen && 0 != windowHandle ) { Screen scr = screen; -- cgit v1.2.3