diff options
author | Sven Gothel <[email protected]> | 2010-11-14 08:50:12 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-11-14 08:50:12 +0100 |
commit | f2de12dd8d20ba7a08d9c97f5ac9f51c94b693cc (patch) | |
tree | 09a5cb79dbd71942721bf26a51f22389b9b14be8 /src/newt | |
parent | 957b02dbaf386ba635146ed702193ff8b9a548d2 (diff) |
NEWT: Add optional eager native initialization ; Proper exception handling
NEWT: Add optional eager native initialization
of Display and Screen to overcome a possible chicken/egg situation.
This is useful to be able to request the AbstractGraphicsDevice, via getGraphicsDevice().
Otherwise the abstract device won't be available before
the dependent components (Screen and Window) are realized.
Throw NativeWindowException in case native creation failed.
Diffstat (limited to 'src/newt')
5 files changed, 60 insertions, 26 deletions
diff --git a/src/newt/classes/com/jogamp/newt/Display.java b/src/newt/classes/com/jogamp/newt/Display.java index bec014c0b..19733723e 100644 --- a/src/newt/classes/com/jogamp/newt/Display.java +++ b/src/newt/classes/com/jogamp/newt/Display.java @@ -35,6 +35,7 @@ import com.jogamp.newt.impl.DisplayImpl; import java.util.*; import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.NativeWindowException; public abstract class Display { public static final boolean DEBUG = Debug.debug("Display"); @@ -53,6 +54,17 @@ public abstract class Display { } /** + * Manual trigger the native creation.<br> + * This is useful to be able to request the {@link javax.media.nativewindow.AbstractGraphicsDevice}, via + * {@link #getGraphicsDevice()}. Otherwise the abstract device won't be available before the dependent components (Screen and Window) + * are realized. + * @throws NativeWindowException if the native creation failed. + */ + public abstract void createNative() throws NativeWindowException; + + public abstract void destroy(); + + /** * @return true if the native display handle is valid and ready to operate, * otherwise false. * @@ -61,13 +73,6 @@ public abstract class Display { public abstract boolean isNativeValid(); /** - * @return number of references by Screen - */ - public abstract int getReferenceCount(); - - public abstract void destroy(); - - /** * @return the value set by {@link #setDestroyWhenUnused(boolean)} * or the default <code>false</code>. * @@ -88,13 +93,19 @@ public abstract class Display { public abstract void setDestroyWhenUnused(boolean v); /** + * @return number of references by Screen + */ + public abstract int getReferenceCount(); + + /** * The 1st call will initiate native creation, * since we follow the lazy creation pattern. * * @return number of references after adding one + * @throws NativeWindowException if the native creation failed. * @see #removeReference() */ - public abstract int addReference(); + public abstract int addReference() throws NativeWindowException ; /** * The last call may destroy this instance, diff --git a/src/newt/classes/com/jogamp/newt/Screen.java b/src/newt/classes/com/jogamp/newt/Screen.java index d7d6baea7..a6d45d789 100644 --- a/src/newt/classes/com/jogamp/newt/Screen.java +++ b/src/newt/classes/com/jogamp/newt/Screen.java @@ -33,6 +33,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.NativeWindowException; public abstract class Screen { @@ -56,17 +57,20 @@ public abstract class Screen { } return false; } - - public abstract boolean isNativeValid(); /** - * - * @return number of references by Window + * Manual trigger the native creation.<br> + * This is useful to be able to request the {@link javax.media.nativewindow.AbstractGraphicsScreen}, via + * {@link #getGraphicsScreen()}. Otherwise the abstract device won't be available before the dependent component (Window) + * is realized. + * @throws NativeWindowException if the native creation failed. */ - public abstract int getReferenceCount(); + public abstract void createNative() throws NativeWindowException; public abstract void destroy(); + public abstract boolean isNativeValid(); + /** * @return {@link Display#getDestroyWhenUnused()} * @@ -86,13 +90,20 @@ public abstract class Screen { public abstract void setDestroyWhenUnused(boolean v); /** + * + * @return number of references by Window + */ + public abstract int getReferenceCount(); + + /** * See {@link Display#addReference()} * + * @throws NativeWindowException if the native creation failed. * @see #removeReference() * @see #setDestroyWhenUnused(boolean) * @see #getDestroyWhenUnused() */ - public abstract int addReference(); + public abstract int addReference() throws NativeWindowException; /** * See {@link Display#removeReference()} diff --git a/src/newt/classes/com/jogamp/newt/impl/DefaultEDTUtil.java b/src/newt/classes/com/jogamp/newt/impl/DefaultEDTUtil.java index d7a22b92c..e2b3b81ef 100644 --- a/src/newt/classes/com/jogamp/newt/impl/DefaultEDTUtil.java +++ b/src/newt/classes/com/jogamp/newt/impl/DefaultEDTUtil.java @@ -38,9 +38,9 @@ package com.jogamp.newt.impl; import com.jogamp.common.util.RunnableTask; -import com.jogamp.newt.Display; import com.jogamp.newt.util.EDTUtil; import java.util.*; +import javax.media.nativewindow.NativeWindowException; public class DefaultEDTUtil implements EDTUtil { public static final boolean DEBUG = Debug.debug("EDT"); @@ -177,6 +177,9 @@ public class DefaultEDTUtil implements EDTUtil { throwable = rTask.getThrowable(); } if(null!=throwable) { + if(throwable instanceof NativeWindowException) { + throw (NativeWindowException)throwable; + } throw new RuntimeException(throwable); } } diff --git a/src/newt/classes/com/jogamp/newt/impl/DisplayImpl.java b/src/newt/classes/com/jogamp/newt/impl/DisplayImpl.java index d22e9c7c4..7983a1118 100644 --- a/src/newt/classes/com/jogamp/newt/impl/DisplayImpl.java +++ b/src/newt/classes/com/jogamp/newt/impl/DisplayImpl.java @@ -43,6 +43,7 @@ import com.jogamp.newt.util.EDTUtil; import com.jogamp.newt.util.MainThread; import java.util.ArrayList; import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.NativeWindowException; import javax.media.nativewindow.NativeWindowFactory; public abstract class DisplayImpl extends Display { @@ -111,18 +112,24 @@ public abstract class DisplayImpl extends Display { return hashCode; } - protected synchronized final void createNative() { + public synchronized final void createNative() + throws NativeWindowException + { if(null==aDevice) { if(DEBUG) { System.err.println("Display.createNative() START ("+getThreadName()+", "+this+")"); } final DisplayImpl f_dpy = this; - runOnEDTIfAvail(true, new Runnable() { - public void run() { - f_dpy.createNativeImpl(); - }}); + try { + runOnEDTIfAvail(true, new Runnable() { + public void run() { + f_dpy.createNativeImpl(); + }}); + } catch (Throwable t) { + throw new NativeWindowException(t); + } if(null==aDevice) { - throw new RuntimeException("Display.createNative() failed to instanciate an AbstractGraphicsDevice"); + throw new NativeWindowException("Display.createNative() failed to instanciate an AbstractGraphicsDevice"); } if(DEBUG) { System.err.println("Display.createNative() END ("+getThreadName()+", "+this+")"); @@ -216,7 +223,7 @@ public abstract class DisplayImpl extends Display { createNative(); } if(null == aDevice) { - throw new RuntimeException("Display.addReference() (refCount "+refCount+") null AbstractGraphicsDevice"); + throw new NativeWindowException ("Display.addReference() (refCount "+refCount+") null AbstractGraphicsDevice"); } return ++refCount; } diff --git a/src/newt/classes/com/jogamp/newt/impl/ScreenImpl.java b/src/newt/classes/com/jogamp/newt/impl/ScreenImpl.java index ebb496988..c9d1a9c32 100644 --- a/src/newt/classes/com/jogamp/newt/impl/ScreenImpl.java +++ b/src/newt/classes/com/jogamp/newt/impl/ScreenImpl.java @@ -129,7 +129,9 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener { return hashCode; } - protected synchronized final void createNative() { + public synchronized final void createNative() + throws NativeWindowException + { if(null == aScreen) { if(DEBUG) { System.err.println("Screen.createNative() START ("+DisplayImpl.getThreadName()+", "+this+")"); @@ -138,7 +140,7 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener { display.addReference(); createNativeImpl(); if(null == aScreen) { - throw new RuntimeException("Screen.createNative() failed to instanciate an AbstractGraphicsScreen"); + throw new NativeWindowException("Screen.createNative() failed to instanciate an AbstractGraphicsScreen"); } if(DEBUG) { System.err.println("Screen.createNative() END ("+DisplayImpl.getThreadName()+", "+this+")"); @@ -166,7 +168,7 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener { display.removeReference(); } - public synchronized final int addReference() { + public synchronized final int addReference() throws NativeWindowException { if(DEBUG) { System.err.println("Screen.addReference() ("+DisplayImpl.getThreadName()+"): "+refCount+" -> "+(refCount+1)); } @@ -174,7 +176,7 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener { createNative(); } if(null == aScreen) { - throw new RuntimeException("Screen.addReference() (refCount "+refCount+") null AbstractGraphicsScreen"); + throw new NativeWindowException("Screen.addReference() (refCount "+refCount+") null AbstractGraphicsScreen"); } return ++refCount; } |