diff options
author | Steve Vaughan <[email protected]> | 2010-11-17 01:11:09 -0500 |
---|---|---|
committer | Steve Vaughan <[email protected]> | 2010-11-17 01:11:09 -0500 |
commit | e491306690f5c1e281bb4f673481dc890fef5217 (patch) | |
tree | 79204e5f039f02cc433736715d15d998ef7dcb91 /src | |
parent | 483d47795fd1b4bd4cf892960ced8e961f7a8a3c (diff) |
Implement CapabilitiesImmutable to indicate that getRequestedCapabilities() and getChosenCapabilities() return immutable instances. Add cloneCapabilities() to create a mutable clone of an immutable set of capabilities.
Diffstat (limited to 'src')
16 files changed, 143 insertions, 50 deletions
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 2d5154442..2e4b06d94 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfiguration.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfiguration.java @@ -83,7 +83,7 @@ public class EGLGraphicsConfiguration extends DefaultGraphicsConfiguration imple protected void updateGraphicsConfiguration() { EGLGraphicsConfiguration newConfig = (EGLGraphicsConfiguration) - GraphicsConfigurationFactory.getFactory(getScreen().getDevice()).chooseGraphicsConfiguration(getRequestedCapabilities(), + GraphicsConfigurationFactory.getFactory(getScreen().getDevice()).chooseGraphicsConfiguration(getRequestedCapabilities().cloneCapabilites(), chooser, getScreen()); if(null!=newConfig) { 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 8661fba5e..b2bc59578 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 @@ -89,7 +89,7 @@ public class X11GLXGraphicsConfiguration extends X11GraphicsConfiguration implem protected void updateGraphicsConfiguration() { X11GLXGraphicsConfiguration newConfig = (X11GLXGraphicsConfiguration) - GraphicsConfigurationFactory.getFactory(getScreen().getDevice()).chooseGraphicsConfiguration(getRequestedCapabilities(), + GraphicsConfigurationFactory.getFactory(getScreen().getDevice()).chooseGraphicsConfiguration(getRequestedCapabilities().cloneCapabilites(), chooser, getScreen()); if(null!=newConfig) { diff --git a/src/junit/com/jogamp/test/junit/newt/TestRemoteWindow01NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestRemoteWindow01NEWT.java index 2a43c3ac5..b384145b6 100644 --- a/src/junit/com/jogamp/test/junit/newt/TestRemoteWindow01NEWT.java +++ b/src/junit/com/jogamp/test/junit/newt/TestRemoteWindow01NEWT.java @@ -83,12 +83,12 @@ public class TestRemoteWindow01NEWT extends UITestCase { // Create native OpenGL resources .. XGL/WGL/CGL .. // equivalent to GLAutoDrawable methods: setVisible(true) // - caps = window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); - Assert.assertNotNull(caps); - Assert.assertTrue(caps.getGreenBits()>5); - Assert.assertTrue(caps.getBlueBits()>5); - Assert.assertTrue(caps.getRedBits()>5); - Assert.assertEquals(caps.isOnscreen(),onscreen); + CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + Assert.assertNotNull(chosenCapabilities); + Assert.assertTrue(chosenCapabilities.getGreenBits()>5); + Assert.assertTrue(chosenCapabilities.getBlueBits()>5); + Assert.assertTrue(chosenCapabilities.getRedBits()>5); + Assert.assertEquals(chosenCapabilities.isOnscreen(),onscreen); return window; } diff --git a/src/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java index 706ad5192..033542bea 100644 --- a/src/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java +++ b/src/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java @@ -82,12 +82,12 @@ public class TestWindows01NEWT extends UITestCase { // Create native OpenGL resources .. XGL/WGL/CGL .. // equivalent to GLAutoDrawable methods: setVisible(true) // - caps = window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); - Assert.assertNotNull(caps); - Assert.assertTrue(caps.getGreenBits()>5); - Assert.assertTrue(caps.getBlueBits()>5); - Assert.assertTrue(caps.getRedBits()>5); - Assert.assertEquals(caps.isOnscreen(),onscreen); + CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + Assert.assertNotNull(chosenCapabilities); + Assert.assertTrue(chosenCapabilities.getGreenBits()>5); + Assert.assertTrue(chosenCapabilities.getBlueBits()>5); + Assert.assertTrue(chosenCapabilities.getRedBits()>5); + Assert.assertEquals(chosenCapabilities.isOnscreen(),onscreen); return window; } diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting02NEWT.java b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting02NEWT.java index 3d9efcf82..23e3e1c44 100644 --- a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting02NEWT.java +++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting02NEWT.java @@ -127,7 +127,7 @@ public class TestParenting02NEWT extends UITestCase { // glWindow1.addGLEventListener(demo1); glWindow1.setVisible(true); - Capabilities capsChosen = glWindow1.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + CapabilitiesImmutable capsChosen = glWindow1.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); Assert.assertNotNull(capsChosen); Assert.assertTrue(capsChosen.isOnscreen()==true); diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java index 87324a57c..ff07fab44 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java @@ -65,14 +65,14 @@ public class X11GraphicsConfigurationFactory extends GraphicsConfigurationFactor return XVisualInfo.create(xvis[0]); } - public static XVisualInfo getXVisualInfo(AbstractGraphicsScreen screen, Capabilities capabilities) + public static XVisualInfo getXVisualInfo(AbstractGraphicsScreen screen, CapabilitiesImmutable 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) + private static XVisualInfo getXVisualInfoImpl(AbstractGraphicsScreen screen, CapabilitiesImmutable capabilities, int c_class) { XVisualInfo ret = null; int[] num = { -1 }; diff --git a/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsConfiguration.java index e53f75251..784343c5a 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsConfiguration.java +++ b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsConfiguration.java @@ -52,9 +52,10 @@ public interface AbstractGraphicsConfiguration extends Cloneable { * Return the capabilities reflecting this graphics configuration, * which may differ from the capabilites used to choose this configuration. * - * @return A copy of the Capabilities to avoid mutation by the user. + * @return An immutable instance of the Capabilities to avoid mutation by + * the user. */ - public Capabilities getChosenCapabilities(); + public CapabilitiesImmutable getChosenCapabilities(); /** * Return the capabilities used to choose this graphics configuration. @@ -62,9 +63,10 @@ public interface AbstractGraphicsConfiguration extends Cloneable { * These may be used to reconfigure the NativeWindow in case * the device changes in a multi screen environment. * - * @return A copy of the Capabilities to avoid mutation by the user. + * @return An immutable instance of the Capabilities to avoid mutation by + * the user. */ - public Capabilities getRequestedCapabilities(); + public CapabilitiesImmutable getRequestedCapabilities(); /** * In case this instance already reflects a native configuration, diff --git a/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java b/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java index 6c875ab40..ff6e077ee 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java +++ b/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java @@ -44,7 +44,7 @@ package javax.media.nativewindow; contains the minimal number of routines which allow configuration on all supported window systems. */ -public class Capabilities implements Cloneable { +public class Capabilities implements CapabilitiesImmutable, Cloneable { private int redBits = 8; private int greenBits = 8; private int blueBits = 8; @@ -65,6 +65,10 @@ public class Capabilities implements Cloneable { */ public Capabilities() {} + public Capabilities cloneCapabilites() { + return (Capabilities) clone(); + } + public Object clone() { try { return super.clone(); diff --git a/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesImmutable.java b/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesImmutable.java new file mode 100644 index 000000000..9369221cb --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesImmutable.java @@ -0,0 +1,81 @@ +package javax.media.nativewindow; + +/** + * Specifies an immutable set of capabilities that a window's rendering context + * must support, such as color depth per channel. + * + * @see javax.media.nativewindow.Capabilities + */ +public interface CapabilitiesImmutable extends Cloneable { + + /** + * Returns the number of bits requested for the color buffer's red + * component. On some systems only the color depth, which is the sum of the + * red, green, and blue bits, is considered. + */ + int getRedBits(); + + /** + * Returns the number of bits requested for the color buffer's green + * component. On some systems only the color depth, which is the sum of the + * red, green, and blue bits, is considered. + */ + int getGreenBits(); + + /** + * Returns the number of bits requested for the color buffer's blue + * component. On some systems only the color depth, which is the sum of the + * red, green, and blue bits, is considered. + */ + int getBlueBits(); + + /** + * Returns the number of bits requested for the color buffer's alpha + * component. On some systems only the color depth, which is the sum of the + * red, green, and blue bits, is considered. + */ + int getAlphaBits(); + + /** + * Indicates whether the background of this OpenGL context should be + * considered opaque. Defaults to true. + */ + boolean isBackgroundOpaque(); + + /** + * Indicates whether the drawable surface is onscreen. Defaults to true. + */ + boolean isOnscreen(); + + /** + * Gets the transparent red value for the frame buffer configuration. This + * value is undefined if; equals true. + */ + int getTransparentRedValue(); + + /** + * Gets the transparent green value for the frame buffer configuration. This + * value is undefined if; equals true. + */ + int getTransparentGreenValue(); + + /** + * Gets the transparent blue value for the frame buffer configuration. This + * value is undefined if; equals true. + */ + int getTransparentBlueValue(); + + /** + * Gets the transparent alpha value for the frame buffer configuration. This + * value is undefined if; equals true. + */ + int getTransparentAlphaValue(); + + /** + * Get a mutable clone of this instance. + * + * @see java.lang.Object#clone() + */ + Capabilities cloneCapabilites(); + +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java index 42350e6c1..3d06388c2 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java +++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java @@ -34,16 +34,16 @@ package javax.media.nativewindow; public class DefaultGraphicsConfiguration implements Cloneable, AbstractGraphicsConfiguration { private AbstractGraphicsScreen screen; - protected Capabilities capabilitiesChosen; - protected Capabilities capabilitiesRequested; + protected CapabilitiesImmutable capabilitiesChosen; + protected CapabilitiesImmutable capabilitiesRequested; public DefaultGraphicsConfiguration(AbstractGraphicsScreen screen, - Capabilities capsChosen, Capabilities capsRequested) { + CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested) { this.screen = screen; // Create "immutable" copies of capabilities. - this.capabilitiesChosen = (Capabilities) capsChosen.clone(); - this.capabilitiesRequested = (Capabilities) capsRequested.clone(); + this.capabilitiesChosen = capsChosen.cloneCapabilites(); + this.capabilitiesRequested = capsRequested.cloneCapabilites(); } public Object clone() { @@ -58,13 +58,11 @@ public class DefaultGraphicsConfiguration implements Cloneable, AbstractGraphics return screen; } - // TODO: Return immutable instance. - public Capabilities getChosenCapabilities() { + public CapabilitiesImmutable getChosenCapabilities() { return capabilitiesChosen; } - // TODO: Return immutable instance. - public Capabilities getRequestedCapabilities() { + public CapabilitiesImmutable getRequestedCapabilities() { return capabilitiesRequested; } @@ -82,8 +80,9 @@ public class DefaultGraphicsConfiguration implements Cloneable, AbstractGraphics * * @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen) */ - protected void setChosenCapabilities(Capabilities capsChosen) { - capabilitiesChosen = (Capabilities) capsChosen.clone(); + protected void setChosenCapabilities(CapabilitiesImmutable capsChosen) { + // Create "immutable" copy of capabilities. + capabilitiesChosen = (CapabilitiesImmutable) capsChosen.cloneCapabilites(); } /** diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java index 6aafc8549..bce9b248d 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java +++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java @@ -56,14 +56,14 @@ public class AWTGraphicsConfiguration extends DefaultGraphicsConfiguration imple AbstractGraphicsConfiguration encapsulated; public AWTGraphicsConfiguration(AWTGraphicsScreen screen, - Capabilities capsChosen, Capabilities capsRequested, + CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, GraphicsConfiguration config, AbstractGraphicsConfiguration encapsulated) { super(screen, capsChosen, capsRequested); this.config = config; this.encapsulated=encapsulated; } - public AWTGraphicsConfiguration(AWTGraphicsScreen screen, Capabilities capsChosen, Capabilities capsRequested, GraphicsConfiguration config) { + public AWTGraphicsConfiguration(AWTGraphicsScreen screen, CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, GraphicsConfiguration config) { super(screen, capsChosen, capsRequested); this.config = config; this.encapsulated=null; @@ -74,7 +74,7 @@ public class AWTGraphicsConfiguration extends DefaultGraphicsConfiguration imple * with the graphics capabilties of the AWT Component to produce the chosen Capabilties. * Otherwise the <code>capsChosen</code> is used. */ - public static AWTGraphicsConfiguration create(Component awtComp, Capabilities capsChosen, Capabilities capsRequested) + public static AWTGraphicsConfiguration create(Component awtComp, CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested) { AWTGraphicsScreen awtScreen = null; AWTGraphicsDevice awtDevice = null; @@ -96,9 +96,8 @@ public class AWTGraphicsConfiguration extends DefaultGraphicsConfiguration imple } if(null==capsChosen) { - capsChosen = (Capabilities) capsRequested.clone() ; GraphicsConfiguration gc = awtGraphicsDevice.getDefaultConfiguration(); - setupCapabilitiesRGBABits(capsChosen, gc); + capsChosen = setupCapabilitiesRGBABits(capsRequested.cloneCapabilites(), gc); } return new AWTGraphicsConfiguration(awtScreen, capsChosen, capsRequested, awtGfxConfig); } diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java index 5659dcdcc..07171e141 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java +++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java @@ -45,7 +45,7 @@ public class X11GraphicsConfiguration extends DefaultGraphicsConfiguration imple private XVisualInfo info; public X11GraphicsConfiguration(X11GraphicsScreen screen, - Capabilities capsChosen, Capabilities capsRequested, + CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, XVisualInfo info) { super(screen, capsChosen, capsRequested); this.info = info; diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java index 9307ea7f7..13cc0e098 100644 --- a/src/newt/classes/com/jogamp/newt/Window.java +++ b/src/newt/classes/com/jogamp/newt/Window.java @@ -33,11 +33,10 @@ import com.jogamp.newt.event.KeyListener; import com.jogamp.newt.event.MouseListener; import com.jogamp.newt.event.ScreenModeListener; import com.jogamp.newt.impl.Debug; -import javax.media.nativewindow.Capabilities; +import javax.media.nativewindow.CapabilitiesImmutable; import javax.media.nativewindow.NativeWindow; import javax.media.nativewindow.SurfaceUpdatedListener; import javax.media.nativewindow.util.Insets; -import javax.media.nativewindow.util.Point; /** * Specifying the public Window functionality for the @@ -80,11 +79,18 @@ public interface Window extends NativeWindow, ScreenModeListener { Screen getScreen(); /** - * @return The requested capabilities + * Gets an immutable set of requested capabilities. + * + * @return the requested capabilities */ - Capabilities getRequestedCapabilities(); + CapabilitiesImmutable getRequestedCapabilities(); - Capabilities getChosenCapabilities(); + /** + * Gets an immutable set of chosen capabilities. + * + * @return the chosen capabilities + */ + CapabilitiesImmutable getChosenCapabilities(); /** * Destroy the Window and it's children, incl. native destruction.<br> diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java index a0ab5f9f6..29e8c91b4 100644 --- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java +++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java @@ -168,7 +168,8 @@ public class NewtCanvasAWT extends java.awt.Canvas { newtChild.setFocusAction(null); // no AWT focus traversal .. if(add) { - nativeWindow = NewtFactoryAWT.getNativeWindow(this, newtChild.getRequestedCapabilities()); + nativeWindow = NewtFactoryAWT.getNativeWindow(this, + newtChild.getRequestedCapabilities().cloneCapabilites()); if(null!=nativeWindow) { if(DEBUG) { System.err.println("NewtCanvasAWT.reparentWindow: "+newtChild); diff --git a/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java b/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java index 9f744be82..572ed5bb7 100644 --- a/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java +++ b/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java @@ -57,6 +57,7 @@ import java.lang.reflect.Method; import javax.media.nativewindow.AbstractGraphicsConfiguration; import javax.media.nativewindow.AbstractGraphicsDevice; import javax.media.nativewindow.Capabilities; +import javax.media.nativewindow.CapabilitiesImmutable; import javax.media.nativewindow.NativeSurface; import javax.media.nativewindow.NativeWindow; import javax.media.nativewindow.NativeWindowException; @@ -1145,12 +1146,12 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer, ScreenMod return reparentActionStrategy; } - public final Capabilities getChosenCapabilities() { + public final CapabilitiesImmutable getChosenCapabilities() { return config.getNativeGraphicsConfiguration().getChosenCapabilities(); } - public final Capabilities getRequestedCapabilities() { - return (Capabilities)caps.clone(); + public final CapabilitiesImmutable getRequestedCapabilities() { + return caps; } public String getTitle() { diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index 72963eaa3..54fcfe85e 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -141,7 +141,7 @@ public class GLWindow implements GLAutoDrawable, Window { // Window Access // - public final Capabilities getChosenCapabilities() { + public final CapabilitiesImmutable getChosenCapabilities() { if (drawable == null) { return window.getChosenCapabilities(); } @@ -149,7 +149,7 @@ public class GLWindow implements GLAutoDrawable, Window { return drawable.getChosenGLCapabilities(); } - public final Capabilities getRequestedCapabilities() { + public final CapabilitiesImmutable getRequestedCapabilities() { return window.getRequestedCapabilities(); } |