aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/classes/com
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-09-15 07:50:50 +0200
committerSven Gothel <[email protected]>2015-09-15 07:50:50 +0200
commit68c8e39fa8d6e700f0a99241c1a01a435b7f6284 (patch)
treed02cf789a06514da205f6da8a45f55538b019a0b /src/newt/classes/com
parentcf9b31c30de3768447b20d6aa31ec1df00595871 (diff)
Bug 1211: Hardening Condition-Wait from Spurious-Wakeups and unintended InterruptedException(s)
Below is an updated list of Condition-Wait classifications as described in Bug 1211. This list includes recent changes on GlueGen regarding this Bug 1211. A followup commit will address the unit tests. - Noncancelable + Persistent-Wait - GLMediaPlayerImpl.StreamWorker thread (changed) - pauses thread in case of intr - Cancelable + Persistent-Wait: - LFRingbuffer.getImpl(..) - LFRingbuffer.waitForFreeSlots(int) - SyncedRingbuffer.getImpl(..) - SyncedRingbuffer.waitForFreeSlots(int) - FunctionTask.invokeOnNewThread(..) (changed) - RunnableTask.invokeOnNewThread(..) (changed) - SharedResourceRunner.run() - SharedResourceRunner.doAndWait() (changed) - SharedResourceRunner.start() (changed) - SharedResourceRunner.stop() (changed) - GLMediaPlayerImpl.StreamWorker ctor (changed) - GLMediaPlayerImpl caller thread actions do*() (changed) - AndroidGLMediaPlayerAPI14.getNextTextureImpl(..) (changed) - DisplayImpl.enqueueEvent(..) (changed) -> Persistent-Wait -> Cancels wait and NEWTEvent -> dispatchMessage(NEWTEventTask): always notifyCaller! - GLDrawableHelper.invoke(..) (changed) - DefaultEDTUtil.waitUntilIdle() (changed) - DefaultEDTUtil.waitUntilStopped() (changed) - DefaultEDTUtil.invokeImpl(..) (changed) - DefaultEDTUtil.NEDT.run(..) (changed) - AWTEDTUtil.waitUntilStopped(..) (changed) - AWTEDTUtil.invokeImpl(..) (changed) - AWTEDTUtil.NEDT.run(..) (changed) - SWTEDTUtil.invokeImpl(..) (changed) - SWTEDTUtil.waitUntilStopped(..) (changed) - SWTEDTUtil.NEDT.run(..) (changed) - GLWorkerThread.invokeAndWait(..) - GLWorkerThread.start() (changed) - GLWorkerThread.WorkerRunnable.run() (changed) - Animator.run() (changed) - AnimatorBase.finishLifecycleAction() (changed) - OSXUtil.RunOnMainThread(..) (changed) - SingletonInstanceServerSocket.Server.shutdown() (changed) - SingletonInstanceServerSocket.Server.start() (changed) - com.jogamp.audio.windows.waveout.Mixer.shutdown() (changed) - Extending/Using InterruptSource.Thread (changed) - DefaultEDTUtil.NEDT - AWTEDTUtil.NEDT - SWTEDTUtil.NEDT - GLWorkerThread.thread - Mixer.FillerThread - Mixer.MixerThread - Using InterruptSource.Thread (changed) - TempFileCache - LauncherTempFileCache - Animator.thread - SingletonInstanceServerSocket.Server.serverThread Deprecated: - FunctionTask.invoke(..) (changed) -> on current thread, no wait -> deprecated - RunnableTask.invoke(..) (changed) -> on current thread, no wait -> deprecated
Diffstat (limited to 'src/newt/classes/com')
-rw-r--r--src/newt/classes/com/jogamp/newt/opengl/util/NEWTDemoListener.java499
-rw-r--r--src/newt/classes/com/jogamp/newt/util/MainThread.java20
-rw-r--r--src/newt/classes/com/jogamp/newt/util/applet/JOGLNewtAppletBase.java93
3 files changed, 516 insertions, 96 deletions
diff --git a/src/newt/classes/com/jogamp/newt/opengl/util/NEWTDemoListener.java b/src/newt/classes/com/jogamp/newt/opengl/util/NEWTDemoListener.java
new file mode 100644
index 000000000..ca4b51192
--- /dev/null
+++ b/src/newt/classes/com/jogamp/newt/opengl/util/NEWTDemoListener.java
@@ -0,0 +1,499 @@
+/**
+ * Copyright 2015 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.newt.opengl.util;
+
+import java.net.URLConnection;
+
+import com.jogamp.common.util.IOUtil;
+import com.jogamp.nativewindow.CapabilitiesImmutable;
+import com.jogamp.nativewindow.ScalableSurface;
+import com.jogamp.newt.Display;
+import com.jogamp.newt.Display.PointerIcon;
+import com.jogamp.newt.event.KeyEvent;
+import com.jogamp.newt.event.KeyListener;
+import com.jogamp.newt.event.MouseEvent;
+import com.jogamp.newt.event.MouseListener;
+import com.jogamp.newt.event.WindowAdapter;
+import com.jogamp.newt.event.WindowEvent;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.FPSCounter;
+import com.jogamp.opengl.GL;
+import com.jogamp.opengl.GLAnimatorControl;
+import com.jogamp.opengl.GLAutoDrawable;
+import com.jogamp.opengl.GLRunnable;
+import com.jogamp.opengl.util.Gamma;
+import com.jogamp.opengl.util.PNGPixelRect;
+
+import jogamp.newt.driver.PNGIcon;
+
+public class NEWTDemoListener extends WindowAdapter implements KeyListener, MouseListener {
+ protected final GLWindow glWindow;
+ final PointerIcon[] pointerIcons;
+ int pointerIconIdx = 0;
+ float gamma = 1f;
+ float brightness = 0f;
+ float contrast = 1f;
+ boolean confinedFixedCenter = false;
+
+ public NEWTDemoListener(final GLWindow glWin, final PointerIcon[] pointerIcons) {
+ this.glWindow = glWin;
+ if( null != pointerIcons ) {
+ this.pointerIcons = pointerIcons;
+ } else {
+ this.pointerIcons = createPointerIcons(glWindow);
+ }
+ }
+ public NEWTDemoListener(final GLWindow glWin) {
+ this(glWin, null);
+ }
+
+ protected void printlnState(final String prelude) {
+ System.err.println(prelude+": "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets()+", state "+glWindow.getStateMaskString());
+ }
+ protected void printlnState(final String prelude, final String post) {
+ System.err.println(prelude+": "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets()+", state "+glWindow.getStateMaskString()+", "+post);
+ }
+
+ @Override
+ public void keyPressed(final KeyEvent e) {
+ if( e.isAutoRepeat() || e.isConsumed() ) {
+ return;
+ }
+ final int keySymbol = e.getKeySymbol();
+ switch(keySymbol) {
+ case KeyEvent.VK_SPACE:
+ e.setConsumed(true);
+ glWindow.invokeOnCurrentThread(new Runnable() {
+ public void run() {
+ if(glWindow.getAnimator().isPaused()) {
+ glWindow.getAnimator().resume();
+ } else {
+ glWindow.getAnimator().pause();
+ }
+ } } );
+ break;
+ case KeyEvent.VK_A:
+ e.setConsumed(true);
+ glWindow.invokeOnNewThread(null, false, new Runnable() {
+ public void run() {
+ printlnState("[set alwaysontop pre]");
+ glWindow.setAlwaysOnTop(!glWindow.isAlwaysOnTop());
+ printlnState("[set alwaysontop post]");
+ } } );
+ break;
+ case KeyEvent.VK_B:
+ e.setConsumed(true);
+ glWindow.invokeOnNewThread(null, false, new Runnable() {
+ public void run() {
+ printlnState("[set alwaysonbottom pre]");
+ glWindow.setAlwaysOnBottom(!glWindow.isAlwaysOnBottom());
+ printlnState("[set alwaysonbottom post]");
+ } } );
+ break;
+ case KeyEvent.VK_C:
+ e.setConsumed(true);
+ glWindow.invokeOnNewThread(null, false, new Runnable() {
+ public void run() {
+ if( null != pointerIcons ) {
+ printlnState("[set pointer-icon pre]");
+ final PointerIcon currentPI = glWindow.getPointerIcon();
+ final PointerIcon newPI;
+ if( pointerIconIdx >= pointerIcons.length ) {
+ newPI=null;
+ pointerIconIdx=0;
+ } else {
+ newPI=pointerIcons[pointerIconIdx++];
+ }
+ glWindow.setPointerIcon( newPI );
+ printlnState("[set pointer-icon post]", currentPI+" -> "+glWindow.getPointerIcon());
+ }
+ } } );
+ break;
+ case KeyEvent.VK_D:
+ e.setConsumed(true);
+ glWindow.invokeOnNewThread(null, false, new Runnable() {
+ public void run() {
+ printlnState("[set undecorated pre]");
+ glWindow.setUndecorated(!glWindow.isUndecorated());
+ printlnState("[set undecorated post]");
+ } } );
+ break;
+ case KeyEvent.VK_F:
+ e.setConsumed(true);
+ quitAdapterOff();
+ glWindow.invokeOnNewThread(null, false, new Runnable() {
+ public void run() {
+ printlnState("[set fullscreen pre]");
+ if( glWindow.isFullscreen() ) {
+ glWindow.setFullscreen( false );
+ } else {
+ if( e.isAltDown() ) {
+ glWindow.setFullscreen( null );
+ } else {
+ glWindow.setFullscreen( true );
+ }
+ }
+ printlnState("[set fullscreen post]");
+ quitAdapterOn();
+ } } );
+ break;
+ case KeyEvent.VK_G:
+ e.setConsumed(true);
+ glWindow.invokeOnNewThread(null, false, new Runnable() {
+ public void run() {
+ final float newGamma = gamma + ( e.isShiftDown() ? -0.1f : 0.1f );
+ System.err.println("[set gamma]: "+gamma+" -> "+newGamma);
+ if( Gamma.setDisplayGamma(glWindow, newGamma, brightness, contrast) ) {
+ gamma = newGamma;
+ }
+ } } );
+ break;
+ case KeyEvent.VK_I:
+ e.setConsumed(true);
+ glWindow.invokeOnNewThread(null, false, new Runnable() {
+ public void run() {
+ printlnState("[set pointer-visible pre]");
+ glWindow.setPointerVisible(!glWindow.isPointerVisible());
+ printlnState("[set pointer-visible post]");
+ } } );
+ break;
+ case KeyEvent.VK_J:
+ e.setConsumed(true);
+ glWindow.invokeOnNewThread(null, false, new Runnable() {
+ public void run() {
+ printlnState("[set pointer-confined pre]", "warp-center: "+e.isShiftDown());
+ final boolean confine = !glWindow.isPointerConfined();
+ glWindow.confinePointer(confine);
+ printlnState("[set pointer-confined post]", "warp-center: "+e.isShiftDown());
+ if( e.isShiftDown() ) {
+ setConfinedFixedCenter(confine);
+ } else if( !confine ) {
+ setConfinedFixedCenter(false);
+ }
+ } } );
+ break;
+ case KeyEvent.VK_M:
+ e.setConsumed(true);
+ glWindow.invokeOnNewThread(null, false, new Runnable() {
+ public void run() {
+ // none: max-v
+ // alt: max-h
+ // shift: max-hv
+ // ctrl: max-off
+ final boolean horz, vert;
+ if( e.isControlDown() ) {
+ horz = false;
+ vert = false;
+ } else if( e.isShiftDown() ) {
+ final boolean bothMax = glWindow.isMaximizedHorz() && glWindow.isMaximizedVert();
+ horz = !bothMax;
+ vert = !bothMax;
+ } else if( !e.isAltDown() ) {
+ horz = glWindow.isMaximizedHorz();
+ vert = !glWindow.isMaximizedVert();
+ } else if( e.isAltDown() ) {
+ horz = !glWindow.isMaximizedHorz();
+ vert = glWindow.isMaximizedVert();
+ } else {
+ vert = glWindow.isMaximizedVert();
+ horz = glWindow.isMaximizedHorz();
+ }
+ printlnState("[set maximize pre]", "max[vert "+vert+", horz "+horz+"]");
+ glWindow.setMaximized(horz, vert);
+ printlnState("[set maximize post]", "max[vert "+vert+", horz "+horz+"]");
+ } } );
+ break;
+ case KeyEvent.VK_Q:
+ if( quitAdapterEnabled && 0 == e.getModifiers() ) {
+ System.err.println("QUIT Key "+Thread.currentThread());
+ quitAdapterShouldQuit = true;
+ }
+ break;
+ case KeyEvent.VK_P:
+ e.setConsumed(true);
+ glWindow.invokeOnNewThread(null, false, new Runnable() {
+ public void run() {
+ printlnState("[set position pre]");
+ glWindow.setPosition(100, 100);
+ printlnState("[set position post]");
+ } } );
+ break;
+ case KeyEvent.VK_R:
+ e.setConsumed(true);
+ glWindow.invokeOnNewThread(null, false, new Runnable() {
+ public void run() {
+ printlnState("[set resizable pre]");
+ glWindow.setResizable(!glWindow.isResizable());
+ printlnState("[set resizable post]");
+ } } );
+ break;
+ case KeyEvent.VK_S:
+ e.setConsumed(true);
+ glWindow.invokeOnNewThread(null, false, new Runnable() {
+ public void run() {
+ printlnState("[set sticky pre]");
+ glWindow.setSticky(!glWindow.isSticky());
+ printlnState("[set sticky post]");
+ } } );
+ break;
+ case KeyEvent.VK_V:
+ e.setConsumed(true);
+ if( e.isControlDown() ) {
+ glWindow.invoke(false, new GLRunnable() {
+ @Override
+ public boolean run(final GLAutoDrawable drawable) {
+ final GL gl = drawable.getGL();
+ final int _i = gl.getSwapInterval();
+ final int i;
+ switch(_i) {
+ case 0: i = -1; break;
+ case -1: i = 1; break;
+ case 1: i = 0; break;
+ default: i = 1; break;
+ }
+ gl.setSwapInterval(i);
+
+ final GLAnimatorControl a = drawable.getAnimator();
+ if( null != a ) {
+ a.resetFPSCounter();
+ }
+ if(drawable instanceof FPSCounter) {
+ ((FPSCounter)drawable).resetFPSCounter();
+ }
+ System.err.println("Swap Interval: "+_i+" -> "+i+" -> "+gl.getSwapInterval());
+ return true;
+ }
+ });
+ } else {
+ glWindow.invokeOnNewThread(null, false, new Runnable() {
+ public void run() {
+ final boolean wasVisible = glWindow.isVisible();
+ {
+ printlnState("[set visible pre]");
+ glWindow.setVisible(!wasVisible);
+ printlnState("[set visible post]");
+ }
+ if( wasVisible && !e.isControlDown() ) {
+ try {
+ java.lang.Thread.sleep(5000);
+ } catch (final InterruptedException e) {
+ e.printStackTrace();
+ }
+ printlnState("[reset visible pre]");
+ glWindow.setVisible(true);
+ printlnState("[reset visible post]");
+ }
+ } } );
+ }
+ break;
+ case KeyEvent.VK_W:
+ e.setConsumed(true);
+ glWindow.invokeOnNewThread(null, false, new Runnable() {
+ public void run() {
+ printlnState("[set pointer-pos pre]");
+ glWindow.warpPointer(glWindow.getSurfaceWidth()/2, glWindow.getSurfaceHeight()/2);
+ printlnState("[set pointer-pos post]");
+ } } );
+ break;
+ case KeyEvent.VK_X:
+ e.setConsumed(true);
+ final float[] hadSurfacePixelScale = glWindow.getCurrentSurfaceScale(new float[2]);
+ final float[] reqSurfacePixelScale;
+ if( hadSurfacePixelScale[0] == ScalableSurface.IDENTITY_PIXELSCALE ) {
+ reqSurfacePixelScale = new float[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE };
+ } else {
+ reqSurfacePixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE };
+ }
+ System.err.println("[set PixelScale pre]: had "+hadSurfacePixelScale[0]+"x"+hadSurfacePixelScale[1]+" -> req "+reqSurfacePixelScale[0]+"x"+reqSurfacePixelScale[1]);
+ glWindow.setSurfaceScale(reqSurfacePixelScale);
+ final float[] valReqSurfacePixelScale = glWindow.getRequestedSurfaceScale(new float[2]);
+ final float[] hasSurfacePixelScale1 = glWindow.getCurrentSurfaceScale(new float[2]);
+ System.err.println("[set PixelScale post]: "+hadSurfacePixelScale[0]+"x"+hadSurfacePixelScale[1]+" (had) -> "+
+ reqSurfacePixelScale[0]+"x"+reqSurfacePixelScale[1]+" (req) -> "+
+ valReqSurfacePixelScale[0]+"x"+valReqSurfacePixelScale[1]+" (val) -> "+
+ hasSurfacePixelScale1[0]+"x"+hasSurfacePixelScale1[1]+" (has)");
+ setTitle();
+ }
+ }
+ @Override
+ public void keyReleased(final KeyEvent e) { }
+
+ public void setConfinedFixedCenter(final boolean v) {
+ confinedFixedCenter = v;
+ }
+ @Override
+ public void mouseMoved(final MouseEvent e) {
+ if( e.isConfined() ) {
+ mouseCenterWarp(e);
+ }
+ }
+ @Override
+ public void mouseDragged(final MouseEvent e) {
+ if( e.isConfined() ) {
+ mouseCenterWarp(e);
+ }
+ }
+ @Override
+ public void mouseClicked(final MouseEvent e) {
+ if(e.getClickCount() == 2 && e.getPointerCount() == 1) {
+ glWindow.setFullscreen(!glWindow.isFullscreen());
+ System.err.println("setFullscreen: "+glWindow.isFullscreen());
+ }
+ }
+ private void mouseCenterWarp(final MouseEvent e) {
+ if(e.isConfined() && confinedFixedCenter ) {
+ final int x=glWindow.getSurfaceWidth()/2;
+ final int y=glWindow.getSurfaceHeight()/2;
+ glWindow.warpPointer(x, y);
+ }
+ }
+ @Override
+ public void mouseEntered(final MouseEvent e) {}
+ @Override
+ public void mouseExited(final MouseEvent e) {}
+ @Override
+ public void mousePressed(final MouseEvent e) {}
+ @Override
+ public void mouseReleased(final MouseEvent e) {}
+ @Override
+ public void mouseWheelMoved(final MouseEvent e) {}
+
+ /////////////////////////////////////////////////////////////
+
+ private boolean quitAdapterShouldQuit = false;
+ private boolean quitAdapterEnabled = false;
+ private boolean quitAdapterEnabled2 = true;
+
+ protected void quitAdapterOff() {
+ quitAdapterEnabled2 = false;
+ }
+ protected void quitAdapterOn() {
+ clearQuitAdapter();
+ quitAdapterEnabled2 = true;
+ }
+ public void quitAdapterEnable(final boolean v) { quitAdapterEnabled = v; }
+ public void clearQuitAdapter() { quitAdapterShouldQuit = false; }
+ public boolean shouldQuit() { return quitAdapterShouldQuit; }
+ public void doQuit() { quitAdapterShouldQuit=true; }
+
+ public void windowDestroyNotify(final WindowEvent e) {
+ if( quitAdapterEnabled && quitAdapterEnabled2 ) {
+ System.err.println("QUIT Window "+Thread.currentThread());
+ quitAdapterShouldQuit = true;
+ }
+ }
+
+ /////////////////////////////////////////////////////////////
+
+ public void setTitle() {
+ setTitle(glWindow);
+ }
+ public static void setTitle(final GLWindow win) {
+ final CapabilitiesImmutable chosenCaps = win.getChosenCapabilities();
+ final CapabilitiesImmutable reqCaps = win.getRequestedCapabilities();
+ final CapabilitiesImmutable caps = null != chosenCaps ? chosenCaps : reqCaps;
+ final String capsA = caps.isBackgroundOpaque() ? "opaque" : "transl";
+ final float[] sDPI = win.getPixelsPerMM(new float[2]);
+ sDPI[0] *= 25.4f;
+ sDPI[1] *= 25.4f;
+ win.setTitle("GLWindow["+capsA+"], win: "+win.getBounds()+", pix: "+win.getSurfaceWidth()+"x"+win.getSurfaceHeight()+", sDPI "+sDPI[0]+" x "+sDPI[1]);
+ }
+
+ public static PointerIcon[] createPointerIcons(final GLWindow glWindow) {
+ final PointerIcon[] pointerIcons = { null, null, null, null, null };
+ {
+ final Display disp = glWindow.getScreen().getDisplay();
+ disp.createNative();
+ int idx = 0;
+ {
+ PointerIcon _pointerIcon = null;
+ final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "newt/data/cross-grey-alpha-16x16.png" } );
+ try {
+ _pointerIcon = disp.createPointerIcon(res, 8, 8);
+ System.err.printf("Create PointerIcon #%02d: %s%n", idx, _pointerIcon.toString());
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ pointerIcons[idx] = _pointerIcon;
+ }
+ idx++;
+ {
+ PointerIcon _pointerIcon = null;
+ final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "newt/data/pointer-grey-alpha-16x24.png" } );
+ try {
+ _pointerIcon = disp.createPointerIcon(res, 0, 0);
+ System.err.printf("Create PointerIcon #%02d: %s%n", idx, _pointerIcon.toString());
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ pointerIcons[idx] = _pointerIcon;
+ }
+ idx++;
+ {
+ PointerIcon _pointerIcon = null;
+ final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "arrow-red-alpha-64x64.png" } );
+ try {
+ _pointerIcon = disp.createPointerIcon(res, 0, 0);
+ System.err.printf("Create PointerIcon #%02d: %s%n", idx, _pointerIcon.toString());
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ pointerIcons[idx] = _pointerIcon;
+ }
+ idx++;
+ {
+ PointerIcon _pointerIcon = null;
+ final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "arrow-blue-alpha-64x64.png" } );
+ try {
+ _pointerIcon = disp.createPointerIcon(res, 0, 0);
+ System.err.printf("Create PointerIcon #%02d: %s%n", idx, _pointerIcon.toString());
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ pointerIcons[idx] = _pointerIcon;
+ }
+ idx++;
+ if( PNGIcon.isAvailable() ) {
+ PointerIcon _pointerIcon = null;
+ final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "jogamp-pointer-64x64.png" } );
+ try {
+ final URLConnection urlConn = res.resolve(0);
+ final PNGPixelRect image = PNGPixelRect.read(urlConn.getInputStream(), null, false /* directBuffer */, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */);
+ System.err.printf("Create PointerIcon #%02d: %s%n", idx, image.toString());
+ _pointerIcon = disp.createPointerIcon(image, 32, 0);
+ System.err.printf("Create PointerIcon #%02d: %s%n", idx, _pointerIcon.toString());
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ pointerIcons[idx] = _pointerIcon;
+ }
+ idx++;
+ }
+ return pointerIcons;
+ }
+} \ No newline at end of file
diff --git a/src/newt/classes/com/jogamp/newt/util/MainThread.java b/src/newt/classes/com/jogamp/newt/util/MainThread.java
index 8bf4bc20f..05df63794 100644
--- a/src/newt/classes/com/jogamp/newt/util/MainThread.java
+++ b/src/newt/classes/com/jogamp/newt/util/MainThread.java
@@ -45,6 +45,7 @@ import java.util.List;
import com.jogamp.nativewindow.NativeWindowFactory;
import com.jogamp.common.os.Platform;
+import com.jogamp.common.util.InterruptSource;
import com.jogamp.common.util.PropertyAccess;
import com.jogamp.common.util.ReflectionUtil;
@@ -171,15 +172,14 @@ public class MainThread {
return res;
}
- static class UserApp extends Thread {
+ static class UserApp extends InterruptSource.Thread {
private final String mainClassNameShort;
private final String mainClassName;
private final String[] mainClassArgs;
private final Method mainClassMain;
- private List<Thread> nonDaemonThreadsAtStart;
+ private List<java.lang.Thread> nonDaemonThreadsAtStart;
public UserApp(final String mainClassName, final String[] mainClassArgs) throws SecurityException, NoSuchMethodException, ClassNotFoundException {
- super();
this.mainClassName=mainClassName;
this.mainClassArgs=mainClassArgs;
@@ -200,10 +200,10 @@ public class MainThread {
@Override
public void run() {
nonDaemonThreadsAtStart = getNonDaemonThreads();
- if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" start, nonDaemonThreadsAtStart "+nonDaemonThreadsAtStart);
+ if(DEBUG) System.err.println("MainAction.run(): "+java.lang.Thread.currentThread().getName()+" start, nonDaemonThreadsAtStart "+nonDaemonThreadsAtStart);
// start user app ..
try {
- if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" invoke "+mainClassName);
+ if(DEBUG) System.err.println("MainAction.run(): "+java.lang.Thread.currentThread().getName()+" invoke "+mainClassName);
mainClassMain.invoke(null, new Object[] { mainClassArgs } );
} catch (final InvocationTargetException ite) {
ite.getTargetException().printStackTrace();
@@ -219,30 +219,30 @@ public class MainThread {
while( 0 < ( ndtr = getNonDaemonThreadCount(nonDaemonThreadsAtStart) ) ) {
if(DEBUG) System.err.println("MainAction.run(): post user app, non daemon threads alive: "+ndtr);
try {
- Thread.sleep(1000);
+ java.lang.Thread.sleep(1000);
} catch (final InterruptedException e) {
e.printStackTrace();
}
}
- if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" user app fin: "+ndtr);
+ if(DEBUG) System.err.println("MainAction.run(): "+java.lang.Thread.currentThread().getName()+" user app fin: "+ndtr);
}
if ( useMainThread ) {
if(isMacOSX) {
try {
if(DEBUG) {
- System.err.println("MainAction.main(): "+Thread.currentThread()+" MainAction fin - stopNSApp.0");
+ System.err.println("MainAction.main(): "+java.lang.Thread.currentThread()+" MainAction fin - stopNSApp.0");
}
ReflectionUtil.callStaticMethod(MACOSXDisplayClassName, "stopNSApplication",
null, null, MainThread.class.getClassLoader());
if(DEBUG) {
- System.err.println("MainAction.main(): "+Thread.currentThread()+" MainAction fin - stopNSApp.X");
+ System.err.println("MainAction.main(): "+java.lang.Thread.currentThread()+" MainAction fin - stopNSApp.X");
}
} catch (final Exception e) {
e.printStackTrace();
}
} else {
- if(DEBUG) System.err.println("MainAction.run(): "+Thread.currentThread().getName()+" MainAction fin - System.exit(0)");
+ if(DEBUG) System.err.println("MainAction.run(): "+java.lang.Thread.currentThread().getName()+" MainAction fin - System.exit(0)");
System.exit(0);
}
}
diff --git a/src/newt/classes/com/jogamp/newt/util/applet/JOGLNewtAppletBase.java b/src/newt/classes/com/jogamp/newt/util/applet/JOGLNewtAppletBase.java
index c2cf64da2..e02e02013 100644
--- a/src/newt/classes/com/jogamp/newt/util/applet/JOGLNewtAppletBase.java
+++ b/src/newt/classes/com/jogamp/newt/util/applet/JOGLNewtAppletBase.java
@@ -33,7 +33,6 @@ import java.security.PrivilegedAction;
import com.jogamp.nativewindow.NativeWindow;
import com.jogamp.nativewindow.WindowClosingProtocol.WindowClosingMode;
-import com.jogamp.nativewindow.util.InsetsImmutable;
import com.jogamp.opengl.FPSCounter;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GLAutoDrawable;
@@ -43,16 +42,17 @@ import com.jogamp.opengl.GLPipelineFactory;
import jogamp.newt.Debug;
import com.jogamp.common.util.IOUtil;
+import com.jogamp.common.util.InterruptSource;
import com.jogamp.newt.Display;
import com.jogamp.newt.Window;
import com.jogamp.newt.Display.PointerIcon;
-import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.KeyListener;
import com.jogamp.newt.event.MouseListener;
import com.jogamp.newt.event.WindowAdapter;
import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.event.WindowListener;
import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.newt.opengl.util.NEWTDemoListener;
import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.util.AnimatorBase;
@@ -60,7 +60,7 @@ import com.jogamp.opengl.util.AnimatorBase;
/** Shows how to deploy an applet using JOGL. This demo must be
referenced from a web page via an &lt;applet&gt; tag. */
-public class JOGLNewtAppletBase implements KeyListener, GLEventListener {
+public class JOGLNewtAppletBase implements GLEventListener {
public static final boolean DEBUG = Debug.debug("Applet");
String glEventListenerClazzName;
@@ -194,7 +194,9 @@ public class JOGLNewtAppletBase implements KeyListener, GLEventListener {
}
if(!noDefaultKeyListener) {
- glWindow.addKeyListener(this);
+ final NEWTDemoListener newtDemoListener = new NEWTDemoListener(glWindow);
+ glWindow.addKeyListener(newtDemoListener);
+ glWindow.addMouseListener(newtDemoListener);
}
glWindow.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err);
@@ -220,7 +222,7 @@ public class JOGLNewtAppletBase implements KeyListener, GLEventListener {
null == glWindow.getParent() && null != parentWin && 0 != parentWin.getWindowHandle() )
{
// we may be called directly by the native EDT
- new Thread(new Runnable() {
+ new InterruptSource.Thread(null, new Runnable() {
@Override
public void run() {
if( glWindow.isNativeValid() && null != parentWin && 0 != parentWin.getWindowHandle() ) {
@@ -303,86 +305,5 @@ public class JOGLNewtAppletBase implements KeyListener, GLEventListener {
public void dispose(final GLAutoDrawable drawable) {
}
- // ***********************************************************************************
- // ***********************************************************************************
- // ***********************************************************************************
-
- @Override
- public void keyPressed(final KeyEvent e) {
- if( !e.isPrintableKey() || e.isAutoRepeat() ) {
- return;
- }
- if(e.getKeyChar()=='d') {
- new Thread() {
- public void run() {
- glWindow.setUndecorated(!glWindow.isUndecorated());
- } }.start();
- } if(e.getKeyChar()=='f') {
- new Thread() {
- public void run() {
- glWindow.setFullscreen(!glWindow.isFullscreen());
- } }.start();
- } else if(e.getKeyChar()=='a') {
- new Thread() {
- public void run() {
- glWindow.setAlwaysOnTop(!glWindow.isAlwaysOnTop());
- } }.start();
- } else if(e.getKeyChar()=='r' && null!=parentWin) {
- new Thread() {
- public void run() {
- if(null == glWindow.getParent()) {
- glWindow.reparentWindow(parentWin, -1, -1, 0 /* hints */);
- } else {
- final InsetsImmutable insets = glWindow.getInsets();
- final int x, y;
- if ( 0 >= insets.getTopHeight() ) {
- // fail safe ..
- x = 32;
- y = 32;
- } else {
- x = insets.getLeftWidth();
- y = insets.getTopHeight();
- }
- glWindow.reparentWindow(null, x, y, 0 /* hints */);
- glWindow.setDefaultCloseOperation( glClosable ? WindowClosingMode.DISPOSE_ON_CLOSE : WindowClosingMode.DO_NOTHING_ON_CLOSE );
- }
- } }.start();
- } else if(e.getKeyChar()=='c') {
- new Thread() {
- public void run() {
- System.err.println("[set pointer-icon pre]");
- final PointerIcon currentPI = glWindow.getPointerIcon();
- glWindow.setPointerIcon( currentPI == pointerIconTest ? null : pointerIconTest);
- System.err.println("[set pointer-icon post] "+currentPI+" -> "+glWindow.getPointerIcon());
- } }.start();
- } else if(e.getKeyChar()=='i') {
- new Thread() {
- public void run() {
- System.err.println("[set mouse visible pre]: "+glWindow.isPointerVisible());
- glWindow.setPointerVisible(!glWindow.isPointerVisible());
- System.err.println("[set mouse visible post]: "+glWindow.isPointerVisible());
- } }.start();
- } else if(e.getKeyChar()=='j') {
- new Thread() {
- public void run() {
- final Thread t = glWindow.setExclusiveContextThread(null);
- System.err.println("[set mouse confined pre]: "+glWindow.isPointerConfined());
- glWindow.confinePointer(!glWindow.isPointerConfined());
- System.err.println("[set mouse confined post]: "+glWindow.isPointerConfined());
- glWindow.setExclusiveContextThread(t);
- } }.start();
- } else if(e.getKeyChar()=='w') {
- new Thread() {
- public void run() {
- System.err.println("[set mouse pos pre]");
- glWindow.warpPointer(glWindow.getSurfaceWidth()/2, glWindow.getSurfaceHeight()/2);
- System.err.println("[set mouse pos post]");
- } }.start();
- }
- }
-
- @Override
- public void keyReleased(final KeyEvent e) {
- }
}