diff options
author | Sven Gothel <[email protected]> | 2011-10-22 12:01:01 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-10-22 12:01:01 +0200 |
commit | d6ecf1d8dd105f2d84e86e94159dc55700d2e0e6 (patch) | |
tree | 433966de01a5a01da91237c05c372f54f6353fc5 | |
parent | 929093c88a8741ee4819291c4494f350695a394c (diff) |
NEWT/ScreenMode: If unimplemented have at least current mode in list. Current mode uses ScreenSize w/ dummy values if unimplemented.
7 files changed, 121 insertions, 119 deletions
diff --git a/src/newt/classes/com/jogamp/newt/Screen.java b/src/newt/classes/com/jogamp/newt/Screen.java index c6943ff22..d25d3e7ac 100644 --- a/src/newt/classes/com/jogamp/newt/Screen.java +++ b/src/newt/classes/com/jogamp/newt/Screen.java @@ -151,24 +151,28 @@ public abstract class Screen { public abstract void removeScreenModeListener(ScreenModeListener sml); /** - * Return a list of available {@link com.jogamp.newt.ScreenMode}s. - * @return a shallow copy of the internal immutable {@link com.jogamp.newt.ScreenMode}s, - * or null if not implemented for this native type {@link com.jogamp.newt.Display#getType()}. + * Return a list of available {@link com.jogamp.newt.ScreenMode ScreenMode}s. + * <p> + * If {@link com.jogamp.newt.ScreenMode ScreenMode}s are not supported for this + * native type {@link com.jogamp.newt.Display#getType()}, it returns a list of size one with the current screen size.</p> + * + * @return a shallow copy of the internal immutable {@link com.jogamp.newt.ScreenMode ScreenMode}s. */ public abstract List<ScreenMode> getScreenModes(); /** * Return the original {@link com.jogamp.newt.ScreenMode}, as used at NEWT initialization. - * @return null if functionality not implemented, - * otherwise the original ScreenMode which is element of the list {@link #getScreenModes()}. - * + * @return original ScreenMode which is element of the list {@link #getScreenModes()}. */ public abstract ScreenMode getOriginalScreenMode(); /** * Return the current {@link com.jogamp.newt.ScreenMode}. - * @return null if functionality not implemented, - * otherwise the current ScreenMode which is element of the list {@link #getScreenModes()}. + * <p> + * If {@link com.jogamp.newt.ScreenMode ScreenMode}s are not supported for this + * native type {@link com.jogamp.newt.Display#getType()}, it returns one with the current screen size. </p> + * + * @return current ScreenMode which is element of the list {@link #getScreenModes()}. */ public abstract ScreenMode getCurrentScreenMode(); diff --git a/src/newt/classes/jogamp/newt/ScreenImpl.java b/src/newt/classes/jogamp/newt/ScreenImpl.java index d79a567db..61764196f 100644 --- a/src/newt/classes/jogamp/newt/ScreenImpl.java +++ b/src/newt/classes/jogamp/newt/ScreenImpl.java @@ -308,22 +308,23 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener { public ScreenMode getCurrentScreenMode() { ScreenMode smU = null; ScreenModeStatus sms = ScreenModeStatus.getScreenModeStatus(this.getFQName()); - if(null != sms) { - ScreenMode sm0 = ( DEBUG_TEST_SCREENMODE_DISABLED ) ? null : getCurrentScreenModeImpl(); - if(null == sm0) { - return null; - } - sms.lock(); - try { - smU = sms.getScreenModes().getOrAdd(sm0); // unified instance, maybe new + if(null == sms) { + throw new InternalError("ScreenModeStatus.getScreenModeStatus("+this.getFQName()+") == null"); + } + ScreenMode sm0 = getCurrentScreenModeImpl(); + if(null == sm0) { + throw new InternalError("getCurrentScreenModeImpl() == null"); + } + sms.lock(); + try { + smU = sms.getScreenModes().getOrAdd(sm0); // unified instance, maybe new - // if mode has changed somehow, update it .. - if( sms.getCurrentScreenMode().hashCode() != smU.hashCode() ) { - sms.fireScreenModeChanged(smU, true); - } - } finally { - sms.unlock(); + // if mode has changed somehow, update it .. + if( sms.getCurrentScreenMode().hashCode() != smU.hashCode() ) { + sms.fireScreenModeChanged(smU, true); } + } finally { + sms.unlock(); } return smU; } @@ -338,46 +339,46 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener { return true; } ScreenModeStatus sms = ScreenModeStatus.getScreenModeStatus(this.getFQName()); - if(null!=sms) { - sms.lock(); - try { - long t0=0, t1=0; - if(DEBUG) { - System.err.println("Screen.setCurrentScreenMode ("+(System.currentTimeMillis()-t0)+"): 0.0 "+screenMode); - t0 = System.currentTimeMillis(); - } + if(null == sms) { + throw new InternalError("ScreenModeStatus.getScreenModeStatus("+this.getFQName()+") == null"); + } + boolean success; + sms.lock(); + try { + long t0=0, t1=0; + if(DEBUG) { + System.err.println("Screen.setCurrentScreenMode ("+(System.currentTimeMillis()-t0)+"): 0.0 "+screenMode); + t0 = System.currentTimeMillis(); + } - sms.fireScreenModeChangeNotify(smU); + sms.fireScreenModeChangeNotify(smU); - if(DEBUG) { - System.err.println("Screen.setCurrentScreenMode ("+(System.currentTimeMillis()-t0)+"): 0.1 "+screenMode); - t1 = System.currentTimeMillis(); - } - - boolean success = setCurrentScreenModeImpl(smU); - if(success) { - setScreenSize(screenMode.getRotatedWidth(), screenMode.getRotatedHeight()); - } - - if(DEBUG) { - t1 = System.currentTimeMillis() - t1; - System.err.println("Screen.setCurrentScreenMode ("+(System.currentTimeMillis()-t0)+"): X.0 "+screenMode+", success: "+success); - } + if(DEBUG) { + System.err.println("Screen.setCurrentScreenMode ("+(System.currentTimeMillis()-t0)+"): 0.1 "+screenMode); + t1 = System.currentTimeMillis(); + } - sms.fireScreenModeChanged(smU, success); - - if(DEBUG) { - t0 = System.currentTimeMillis() - t0; - System.err.println("Screen.setCurrentScreenMode ("+(System.currentTimeMillis()-t0)+"): X.X "+screenMode+", success: "+success+ - " - dt0 "+t0+"ms, dt1 "+t1+"ms"); - } + success = setCurrentScreenModeImpl(smU); + if(success) { + setScreenSize(screenMode.getRotatedWidth(), screenMode.getRotatedHeight()); + } + + if(DEBUG) { + t1 = System.currentTimeMillis() - t1; + System.err.println("Screen.setCurrentScreenMode ("+(System.currentTimeMillis()-t0)+"): X.0 "+screenMode+", success: "+success); + } - return success; - } finally { - sms.unlock(); + sms.fireScreenModeChanged(smU, success); + + if(DEBUG) { + t0 = System.currentTimeMillis() - t0; + System.err.println("Screen.setCurrentScreenMode ("+(System.currentTimeMillis()-t0)+"): X.X "+screenMode+", success: "+success+ + " - dt0 "+t0+"ms, dt1 "+t1+"ms"); } + } finally { + sms.unlock(); } - return false; + return success; } public void screenModeChangeNotify(ScreenMode sm) { @@ -452,9 +453,21 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener { /** * To be implemented by the native specification.<br> * Is called within a thread safe environment.<br> + * Default dummy implementation only set the current screen size, other values are dummy defaults.<br> */ protected ScreenMode getCurrentScreenModeImpl() { - return null; + int[] props = new int[ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL]; + int i = 0; + props[i++] = 0; // set later for verification of iterator + props[i++] = getWidth(); // width + props[i++] = getHeight(); // height + props[i++] = 32; // bpp + props[i++] = 519; // widthmm + props[i++] = 324; // heightmm + props[i++] = 60; // rate + props[i++] = 0; // rot + props[i - ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL] = i; // count + return ScreenModeUtil.streamIn(props, 0); } /** @@ -472,30 +485,25 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener { sms = ScreenModeStatus.getScreenModeStatus(this.getFQName()); if(null==sms) { IntIntHashMap screenModesIdx2NativeIdx = new IntIntHashMap(); + final ScreenMode currentSM = getCurrentScreenModeImpl(); + if(null == currentSM) { + throw new InternalError("getCurrentScreenModeImpl() == null"); + } ArrayHashSet<ScreenMode> screenModes = collectNativeScreenModes(screenModesIdx2NativeIdx); if(screenModes.size()==0) { - ScreenMode sm0 = ( DEBUG_TEST_SCREENMODE_DISABLED ) ? null : getCurrentScreenModeImpl(); - if(null != sm0) { - if(DEBUG) { - System.err.println("ScreenImpl.initScreenModeStatus: added current (last resort, collect failed): "+sm0); - } - screenModes.getOrAdd(sm0); - } else if(DEBUG) { - System.err.println("ScreenImpl.initScreenModeStatus: Warning: No screen modes added!"); + if(DEBUG) { + System.err.println("ScreenImpl.initScreenModeStatus: added current (last resort, collect failed): "+currentSM); } + screenModes.getOrAdd(currentSM); } + sms = new ScreenModeStatus(screenModes, screenModesIdx2NativeIdx); - if(screenModes.size()>0) { - ScreenMode originalScreenMode = ( DEBUG_TEST_SCREENMODE_DISABLED ) ? null : getCurrentScreenModeImpl(); - if(null != originalScreenMode) { - ScreenMode originalScreenMode0 = screenModes.get(originalScreenMode); // unify via value hash - if(null == originalScreenMode0) { - throw new RuntimeException(originalScreenMode+" could not be hashed from ScreenMode list"); - } - sms.setOriginalScreenMode(originalScreenMode0); - } + ScreenMode originalScreenMode0 = screenModes.get(currentSM); // unify via value hash + if(null == originalScreenMode0) { + throw new RuntimeException(currentSM+" could not be hashed from ScreenMode list"); } + sms.setOriginalScreenMode(originalScreenMode0); ScreenModeStatus.mapScreenModeStatus(this.getFQName(), sms); } } finally { diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java index cfb8c7715..985affa92 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java @@ -103,26 +103,21 @@ public class TestScreenMode00NEWT extends UITestCase { Screen screen = window.getScreen(); List<ScreenMode> screenModes = screen.getScreenModes(); - if(null != screenModes) { - Assert.assertTrue(screenModes.size()>0); - int i=0; - for(Iterator<ScreenMode> iter=screenModes.iterator(); iter.hasNext(); i++) { - System.err.println(i+": "+iter.next()); - } - ScreenMode sm_o = screen.getOriginalScreenMode(); - Assert.assertNotNull(sm_o); - ScreenMode sm_c = screen.getCurrentScreenMode(); - Assert.assertNotNull(sm_c); - System.err.println("orig SM: "+sm_o); - System.err.println("curr SM: "+sm_c); - System.err.println("curr sz: "+screen.getWidth()+"x"+screen.getHeight()); - Assert.assertEquals(sm_o, sm_c); - Assert.assertEquals(sm_c.getRotatedWidth(), screen.getWidth()); - Assert.assertEquals(sm_c.getRotatedHeight(), screen.getHeight()); - } else { - // no support .. - System.err.println("Your platform has no ScreenMode change support, sorry"); + Assert.assertTrue(screenModes.size()>0); + int i=0; + for(Iterator<ScreenMode> iter=screenModes.iterator(); iter.hasNext(); i++) { + System.err.println(i+": "+iter.next()); } + ScreenMode sm_o = screen.getOriginalScreenMode(); + Assert.assertNotNull(sm_o); + ScreenMode sm_c = screen.getCurrentScreenMode(); + Assert.assertNotNull(sm_c); + System.err.println("orig SM: "+sm_o); + System.err.println("curr SM: "+sm_c); + System.err.println("curr sz: "+screen.getWidth()+"x"+screen.getHeight()); + Assert.assertEquals(sm_o, sm_c); + Assert.assertEquals(sm_c.getRotatedWidth(), screen.getWidth()); + Assert.assertEquals(sm_c.getRotatedHeight(), screen.getHeight()); window.destroy(); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00bNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00bNEWT.java index 15b3740a2..41bdfdfd7 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00bNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00bNEWT.java @@ -82,30 +82,25 @@ public class TestScreenMode00bNEWT extends UITestCase { Assert.assertEquals(true,display.isNativeValid()); List<ScreenMode> screenModes = screen.getScreenModes(); - if(null != screenModes) { - Assert.assertTrue(screenModes.size()>0); - int i=0; - for(Iterator<ScreenMode> iter=screenModes.iterator(); iter.hasNext(); i++) { - System.err.println(i+": "+iter.next()); - } - ScreenMode sm_o = screen.getOriginalScreenMode(); - - Assert.assertNotNull(sm_o); - ScreenMode sm_c = screen.getCurrentScreenMode(); + Assert.assertTrue(screenModes.size()>0); + int i=0; + for(Iterator<ScreenMode> iter=screenModes.iterator(); iter.hasNext(); i++) { + System.err.println(i+": "+iter.next()); + } + ScreenMode sm_o = screen.getOriginalScreenMode(); + + Assert.assertNotNull(sm_o); + ScreenMode sm_c = screen.getCurrentScreenMode(); + Assert.assertNotNull(sm_c); + System.err.println("orig: "+sm_o); + System.err.println("curr: "+sm_c); + + for(i=0; i<100; i++) { + sm_c = screen.getCurrentScreenMode(); Assert.assertNotNull(sm_c); - System.err.println("orig: "+sm_o); - System.err.println("curr: "+sm_c); - - for(i=0; i<100; i++) { - sm_c = screen.getCurrentScreenMode(); - Assert.assertNotNull(sm_c); - System.err.print("."); - } - System.err.println("!"); - } else { - // no support .. - System.err.println("Your platform has no ScreenMode change support, sorry"); + System.err.print("."); } + System.err.println("!"); // screen.removeReference(); anim.stop(); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java index c53c9a1de..5f14fc466 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java @@ -184,7 +184,7 @@ public class TestScreenMode01NEWT extends UITestCase { Assert.assertNotNull(window); List<ScreenMode> screenModes = screen.getScreenModes(); - if(null==screenModes) { + if(screenModes.size()==1) { // no support .. System.err.println("Your platform has no ScreenMode change support, sorry"); destroyWindow(window); @@ -293,7 +293,7 @@ public class TestScreenMode01NEWT extends UITestCase { Assert.assertEquals(smCurrent.getRotatedHeight(), screen.getHeight()); List<ScreenMode> screenModes = screen.getScreenModes(); - if(null==screenModes) { + if(screenModes.size()==1) { // no support .. destroyWindow(window); return; diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01bNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01bNEWT.java index 6c505d58a..4d7769669 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01bNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01bNEWT.java @@ -110,7 +110,7 @@ public class TestScreenMode01bNEWT extends UITestCase { Assert.assertNotNull(window0); List<ScreenMode> screenModes = screen.getScreenModes(); - if(null==screenModes) { + if(screenModes.size()==1) { // no support .. System.err.println("Your platform has no ScreenMode change support, sorry"); destroyWindow(window0); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java index c5c11682c..8c7f75e2b 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java @@ -104,7 +104,7 @@ public class TestScreenMode02NEWT extends UITestCase { Assert.assertNotNull(window); List<ScreenMode> screenModes = screen.getScreenModes(); - if(null==screenModes) { + if(screenModes.size()==1) { // no support .. System.err.println("Your platform has no ScreenMode change support, sorry"); destroyWindow(window); |