diff options
author | Sven Gothel <[email protected]> | 2012-06-28 18:37:55 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-06-28 18:37:55 +0200 |
commit | bd92af2b6b0ae2d1b1f22c64dcb0ffd0e94fae84 (patch) | |
tree | af392e26356f160e0a5d8237d6358e40892969dc /src/jogl/classes/javax/media/opengl/awt | |
parent | 914b522af26b6d779dc931bf4303be3c7e898eff (diff) |
GLDrawable* cleanup: Add @Override, remove trailing whitespace, ..
Diffstat (limited to 'src/jogl/classes/javax/media/opengl/awt')
3 files changed, 258 insertions, 123 deletions
diff --git a/src/jogl/classes/javax/media/opengl/awt/AWTGLAutoDrawable.java b/src/jogl/classes/javax/media/opengl/awt/AWTGLAutoDrawable.java index d1e725b00..2698678af 100644 --- a/src/jogl/classes/javax/media/opengl/awt/AWTGLAutoDrawable.java +++ b/src/jogl/classes/javax/media/opengl/awt/AWTGLAutoDrawable.java @@ -1,21 +1,21 @@ /* * 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 @@ -28,18 +28,18 @@ * 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 javax.media.opengl.awt; -import javax.media.opengl.*; +import javax.media.opengl.GLAutoDrawable; public interface AWTGLAutoDrawable extends GLAutoDrawable, ComponentEvents { /** Requests a new width and height for this AWTGLAutoDrawable. */ diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java index 0a75865e2..604dea057 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java @@ -1,22 +1,22 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Copyright (c) 2010 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: - * + * * - 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 @@ -29,11 +29,11 @@ * 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. */ @@ -139,22 +139,23 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing private static final boolean DEBUG = Debug.debug("GLCanvas"); - private GLDrawableHelper drawableHelper = new GLDrawableHelper(); + private final GLDrawableHelper drawableHelper = new GLDrawableHelper(); private AWTGraphicsConfiguration awtConfig; private volatile GLDrawable drawable; private GLContextImpl context; private boolean sendReshape = false; - + // copy of the cstr args, mainly for recreation private GLCapabilitiesImmutable capsReqUser; private GLCapabilitiesChooser chooser; private GLContext shareWith; - private int additionalCtxCreationFlags = 0; + private int additionalCtxCreationFlags = 0; private GraphicsDevice device; private boolean shallUseOffscreenLayer = false; private AWTWindowClosingProtocol awtWindowClosingProtocol = new AWTWindowClosingProtocol(this, new Runnable() { + @Override public void run() { GLCanvas.this.destroy(); } @@ -162,7 +163,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing /** Creates a new GLCanvas component with a default set of OpenGL capabilities, using the default OpenGL capabilities selection - mechanism, on the default screen device. + mechanism, on the default screen device. * @throws GLException if no default profile is available for the default desktop device. */ public GLCanvas() throws GLException { @@ -171,7 +172,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing /** Creates a new GLCanvas component with the requested set of OpenGL capabilities, using the default OpenGL capabilities - selection mechanism, on the default screen device. + selection mechanism, on the default screen device. * @throws GLException if no GLCapabilities are given and no default profile is available for the default desktop device. * @see GLCanvas#GLCanvas(javax.media.opengl.GLCapabilitiesImmutable, javax.media.opengl.GLCapabilitiesChooser, javax.media.opengl.GLContext, java.awt.GraphicsDevice) */ @@ -187,8 +188,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing * @throws GLException if no GLCapabilities are given and no default profile is available for the default desktop device. * @see GLCanvas#GLCanvas(javax.media.opengl.GLCapabilitiesImmutable, javax.media.opengl.GLCapabilitiesChooser, javax.media.opengl.GLContext, java.awt.GraphicsDevice) */ - public GLCanvas(GLCapabilitiesImmutable capsReqUser, GLContext shareWith) - throws GLException + public GLCanvas(GLCapabilitiesImmutable capsReqUser, GLContext shareWith) + throws GLException { this(capsReqUser, null, shareWith, null); } @@ -207,14 +208,14 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing sharing</a>. The passed GraphicsDevice indicates the screen on which to create the GLCanvas; the GLDrawableFactory uses the default screen device of the local GraphicsEnvironment if null - is passed for this argument. + is passed for this argument. * @throws GLException if no GLCapabilities are given and no default profile is available for the default desktop device. */ public GLCanvas(GLCapabilitiesImmutable capsReqUser, GLCapabilitiesChooser chooser, GLContext shareWith, - GraphicsDevice device) - throws GLException + GraphicsDevice device) + throws GLException { /* * Determination of the native window is made in 'super.addNotify()', @@ -246,14 +247,17 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing this.device = device; } + @Override public void setShallUseOffscreenLayer(boolean v) { shallUseOffscreenLayer = v; } + @Override public final boolean getShallUseOffscreenLayer() { - return shallUseOffscreenLayer; + return shallUseOffscreenLayer; } + @Override public final boolean isOffscreenLayerSurfaceEnabled() { if(null != drawable) { return ((JAWTWindow)drawable.getNativeSurface()).isOffscreenLayerSurfaceEnabled(); @@ -261,18 +265,18 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing return false; } - + /** * Overridden to choose a GraphicsConfiguration on a parent container's * GraphicsDevice because both devices */ - @Override + @Override public GraphicsConfiguration getGraphicsConfiguration() { /* * Workaround for problems with Xinerama and java.awt.Component.checkGD * when adding to a container on a different graphics device than the * one that this Canvas is associated with. - * + * * GC will be null unless: * - A native peer has assigned it. This means we have a native * peer, and are already comitted to a graphics configuration. @@ -286,7 +290,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing * chosen is only non-null on platforms where the GLDrawableFactory * returns a non-null GraphicsConfiguration (in the GLCanvas * constructor). - * + * * if gc is from this Canvas' native peer then it should equal chosen, * otherwise it is from an ancestor component that this Canvas is being * added to, and we go into this block. @@ -298,21 +302,21 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing * Check for compatibility with gc. If they differ by only the * device then return a new GCconfig with the super-class' GDevice * (and presumably the same visual ID in Xinerama). - * + * */ if (!chosen.getDevice().getIDstring().equals(gc.getDevice().getIDstring())) { /* * Here we select a GraphicsConfiguration on the alternate * device that is presumably identical to the chosen * configuration, but on the other device. - * + * * Should really check to ensure that we select a configuration * with the same X visual ID for Xinerama screens, otherwise the * GLDrawable may have the wrong visual ID (I don't think this * ever gets updated). May need to add a method to * X11GLDrawableFactory to do this in a platform specific * manner. - * + * * However, on platforms where we can actually get into this * block, both devices should have the same visual list, and the * same configuration should be selected here. @@ -353,7 +357,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing * return the GC that was selected in the constructor (and might * cause an exception in Component.checkGD when adding to a * container, but in this case that would be the desired behavior). - * + * */ return chosen; } else if (gc == null) { @@ -372,14 +376,17 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing */ return gc; } - + + @Override public GLContext createContext(GLContext shareWith) { return (null != drawable) ? drawable.createContext(shareWith) : null; } + @Override public void setRealized(boolean realized) { } + @Override public boolean isRealized() { return ( null != drawable ) ? drawable.isRealized() : false; } @@ -387,14 +394,17 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing return ( null != drawable ) ? drawable.isRealized() : false; } + @Override public WindowClosingMode getDefaultCloseOperation() { return awtWindowClosingProtocol.getDefaultCloseOperation(); } + @Override public WindowClosingMode setDefaultCloseOperation(WindowClosingMode op) { return awtWindowClosingProtocol.setDefaultCloseOperation(op); } + @Override public void display() { if( !validateGLDrawable() ) { if(DEBUG) { @@ -402,7 +412,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing } return; // not yet available .. } - Threading.invoke(true, displayOnEventDispatchThreadAction, getTreeLock()); + Threading.invoke(true, displayOnEDTAction, getTreeLock()); awtWindowClosingProtocol.addClosingListenerOneShot(); } @@ -425,14 +435,14 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing disposeRegenerate=regenerate; if(context.isCreated()) { - Threading.invoke(true, disposeOnEventDispatchThreadAction, getTreeLock()); + Threading.invoke(true, disposeOnEDTAction, getTreeLock()); } if(animatorPaused) { animator.resume(); } } - + if(!regenerate) { disposeAbstractGraphicsDevice(); } @@ -443,8 +453,14 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing } /** - * Just an alias for removeNotify + * {@inheritDoc} + * + * <p> + * This impl. calls this class's {@link #removeNotify()} AWT override, + * where the actual implementation resides. + * </p> */ + @Override public void destroy() { removeNotify(); } @@ -546,7 +562,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing jawtWindow.unlockSurface(); } } - + private boolean validateGLDrawable() { boolean realized = false; if (!Beans.isDesignTime()) { @@ -554,7 +570,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing realized = drawable.isRealized(); if ( !realized && 0 < drawable.getWidth() * drawable.getHeight() ) { // make sure drawable realization happens on AWT EDT, due to AWTTree lock - AWTEDTExecutor.singleton.invoke(true, setRealizedOnEventDispatchThreadAction); + AWTEDTExecutor.singleton.invoke(true, setRealizedOnEDTAction); realized = true; sendReshape=true; // ensure a reshape is being send .. if(DEBUG) { @@ -566,8 +582,9 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing } return realized; } - private Runnable setRealizedOnEventDispatchThreadAction = new Runnable() { - public void run() { + private Runnable setRealizedOnEDTAction = new Runnable() { + @Override + public void run() { drawable.setRealized(true); } }; @@ -626,7 +643,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing /** <B>Overrides:</B> <DL><DD><CODE>update</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> */ - /** + /** * Overridden from Canvas to prevent the AWT's clearing of the * canvas from interfering with the OpenGL rendering. */ @@ -634,31 +651,38 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing public void update(Graphics g) { paint(g); } - + + @Override public void addGLEventListener(GLEventListener listener) { drawableHelper.addGLEventListener(listener); } + @Override public void addGLEventListener(int index, GLEventListener listener) { drawableHelper.addGLEventListener(index, listener); } + @Override public void removeGLEventListener(GLEventListener listener) { drawableHelper.removeGLEventListener(listener); } + @Override public void setAnimator(GLAnimatorControl animatorControl) { drawableHelper.setAnimator(animatorControl); } + @Override public GLAnimatorControl getAnimator() { return drawableHelper.getAnimator(); } + @Override public void invoke(boolean wait, GLRunnable glRunnable) { drawableHelper.invoke(this, wait, glRunnable); } + @Override public void setContext(GLContext ctx) { context=(GLContextImpl)ctx; if(null != context) { @@ -666,10 +690,12 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing } } + @Override public GLContext getContext() { return context; } + @Override public GL getGL() { if (Beans.isDesignTime()) { return null; @@ -678,6 +704,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing return (ctx == null) ? null : ctx.getGL(); } + @Override public GL setGL(GL gl) { GLContext ctx = getContext(); if (ctx != null) { @@ -688,30 +715,37 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing } + @Override public void setAutoSwapBufferMode(boolean onOrOff) { drawableHelper.setAutoSwapBufferMode(onOrOff); } + @Override public boolean getAutoSwapBufferMode() { return drawableHelper.getAutoSwapBufferMode(); } + @Override public void swapBuffers() { - Threading.invoke(true, swapBuffersOnEventDispatchThreadAction, getTreeLock()); + Threading.invoke(true, swapBuffersOnEDTAction, getTreeLock()); } + @Override public void setContextCreationFlags(int flags) { additionalCtxCreationFlags = flags; } - + + @Override public int getContextCreationFlags() { - return additionalCtxCreationFlags; + return additionalCtxCreationFlags; } - + + @Override public GLProfile getGLProfile() { return capsReqUser.getGLProfile(); } + @Override public GLCapabilitiesImmutable getChosenGLCapabilities() { if (awtConfig == null) { throw new GLException("No AWTGraphicsConfiguration: "+this); @@ -728,14 +762,17 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing return (GLCapabilitiesImmutable)awtConfig.getRequestedCapabilities(); } + @Override public NativeSurface getNativeSurface() { return (null != drawable) ? drawable.getNativeSurface() : null; } + @Override public long getHandle() { return (null != drawable) ? drawable.getHandle() : 0; } + @Override public GLDrawableFactory getFactory() { return (null != drawable) ? drawable.getFactory() : null; } @@ -744,9 +781,9 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing public String toString() { final int dw = (null!=drawable) ? drawable.getWidth() : -1; final int dh = (null!=drawable) ? drawable.getHeight() : -1; - + return "AWT-GLCanvas[Realized "+isRealized()+ - ",\n\t"+((null!=drawable)?drawable.getClass().getName():"null-drawable")+ + ",\n\t"+((null!=drawable)?drawable.getClass().getName():"null-drawable")+ ",\n\tFactory "+getFactory()+ ",\n\thandle 0x"+Long.toHexString(getHandle())+ ",\n\tDrawable size "+dw+"x"+dh+ @@ -754,13 +791,14 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing ",\n\tvisible "+isVisible()+ ",\n\t"+awtConfig+"]"; } - + //---------------------------------------------------------------------- // Internals only below this point // private boolean disposeRegenerate; private final Runnable postDisposeAction = new Runnable() { + @Override public void run() { context=null; if(null!=drawable) { @@ -769,39 +807,41 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing drawable=null; if(null!=jawtWindow) { jawtWindow.destroy(); - } + } } - + if(disposeRegenerate) { // Similar process as in addNotify()! - + // Recreate GLDrawable/GLContext to reflect it's new graphics configuration createDrawableAndContext(); - + if(DEBUG) { System.err.println(getThreadName()+": GLCanvas.dispose(true): new drawable: "+drawable); } validateGLDrawable(); // immediate attempt to recreate the drawable } } - }; + }; - private final Runnable disposeOnEventDispatchThreadAction = new Runnable() { + private final Runnable disposeOnEDTAction = new Runnable() { + @Override public void run() { - drawableHelper.disposeGL(GLCanvas.this, drawable, context, postDisposeAction); + drawableHelper.disposeGL(GLCanvas.this, drawable, context, postDisposeAction); } }; private final Runnable disposeAbstractGraphicsDeviceAction = new Runnable() { + @Override public void run() { if(null != awtConfig) { - final AbstractGraphicsConfiguration aconfig = awtConfig.getNativeGraphicsConfiguration(); + final AbstractGraphicsConfiguration aconfig = awtConfig.getNativeGraphicsConfiguration(); final AbstractGraphicsDevice adevice = aconfig.getScreen().getDevice(); final String adeviceMsg; if(DEBUG) { adeviceMsg = adevice.toString(); } else { - adeviceMsg = null; + adeviceMsg = null; } boolean closed = adevice.close(); if(DEBUG) { @@ -833,12 +873,14 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing } private final Runnable initAction = new Runnable() { + @Override public void run() { drawableHelper.init(GLCanvas.this); } }; - + private final Runnable displayAction = new Runnable() { + @Override public void run() { if (sendReshape) { if(DEBUG) { @@ -855,6 +897,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing }; private final Runnable swapBuffersAction = new Runnable() { + @Override public void run() { drawable.swapBuffers(); } @@ -863,16 +906,18 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing // Workaround for ATI driver bugs related to multithreading issues // like simultaneous rendering via Animators to canvases that are // being resized on the AWT event dispatch thread - private final Runnable displayOnEventDispatchThreadAction = new Runnable() { + private final Runnable displayOnEDTAction = new Runnable() { + @Override public void run() { drawableHelper.invokeGL(drawable, context, displayAction, initAction); } }; - - private final Runnable swapBuffersOnEventDispatchThreadAction = new Runnable() { + + private final Runnable swapBuffersOnEDTAction = new Runnable() { + @Override public void run() { drawableHelper.invokeGL(drawable, context, swapBuffersAction, initAction); - } + } }; // Disables the AWT's erasing of this Canvas's background on Windows @@ -886,6 +931,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing if (!disableBackgroundEraseInitialized) { try { AccessController.doPrivileged(new PrivilegedAction<Object>() { + @Override public Object run() { try { Class<?> clazz = getToolkit().getClass(); @@ -946,7 +992,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing return null; } - final AbstractGraphicsScreen aScreen = null != device ? + final AbstractGraphicsScreen aScreen = null != device ? AWTGraphicsScreen.createScreenDevice(device, AbstractGraphicsDevice.DEFAULT_UNIT): AWTGraphicsScreen.createDefault(); AWTGraphicsConfiguration config = null; @@ -960,6 +1006,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing try { final ArrayList<AWTGraphicsConfiguration> bucket = new ArrayList<AWTGraphicsConfiguration>(1); EventQueue.invokeAndWait(new Runnable() { + @Override public void run() { AWTGraphicsConfiguration c = (AWTGraphicsConfiguration) GraphicsConfigurationFactory.getFactory(AWTGraphicsDevice.class).chooseGraphicsConfiguration(capsChosen, @@ -982,11 +1029,11 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing return config; } - + protected static String getThreadName() { return Thread.currentThread().getName(); } - + /** * A most simple JOGL AWT test entry */ @@ -1006,17 +1053,22 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing frame.setSize(128, 128); glCanvas.addGLEventListener(new GLEventListener() { + @Override public void init(GLAutoDrawable drawable) { GL gl = drawable.getGL(); System.err.println(JoglVersion.getGLInfo(gl, null)); } + @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { } + @Override public void display(GLAutoDrawable drawable) { } + @Override public void dispose(GLAutoDrawable drawable) { } }); try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { frame.setVisible(true); }}); @@ -1026,6 +1078,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing glCanvas.display(); try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { frame.dispose(); }}); diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java index 167b99374..152326006 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java @@ -1,22 +1,22 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Copyright (c) 2010 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: - * + * * - 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 @@ -29,21 +29,17 @@ * 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 javax.media.opengl.awt; -import java.nio.ByteBuffer; -import java.nio.IntBuffer; -import java.beans.Beans; - import java.awt.Color; import java.awt.EventQueue; import java.awt.FontMetrics; @@ -55,13 +51,13 @@ import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.awt.image.DataBufferByte; import java.awt.image.DataBufferInt; -import javax.swing.JPanel; +import java.beans.Beans; +import java.nio.ByteBuffer; +import java.nio.IntBuffer; -import javax.media.nativewindow.WindowClosingProtocol; import javax.media.nativewindow.AbstractGraphicsDevice; import javax.media.nativewindow.NativeSurface; -import javax.media.nativewindow.WindowClosingProtocol.WindowClosingMode; - +import javax.media.nativewindow.WindowClosingProtocol; import javax.media.opengl.DefaultGLCapabilitiesChooser; import javax.media.opengl.GL; import javax.media.opengl.GL2; @@ -80,10 +76,7 @@ import javax.media.opengl.GLPbuffer; import javax.media.opengl.GLProfile; import javax.media.opengl.GLRunnable; import javax.media.opengl.Threading; - -import com.jogamp.nativewindow.awt.AWTWindowClosingProtocol; -import com.jogamp.opengl.util.FBObject; -import com.jogamp.opengl.util.GLBuffers; +import javax.swing.JPanel; import jogamp.opengl.Debug; import jogamp.opengl.GLContextImpl; @@ -93,6 +86,10 @@ import jogamp.opengl.GLDrawableImpl; import jogamp.opengl.awt.Java2D; import jogamp.opengl.awt.Java2DGLContext; +import com.jogamp.nativewindow.awt.AWTWindowClosingProtocol; +import com.jogamp.opengl.util.FBObject; +import com.jogamp.opengl.util.GLBuffers; + // FIXME: Subclasses need to call resetGLFunctionAvailability() on their // context whenever the displayChanged() function is called on their // GLEventListeners @@ -107,9 +104,9 @@ import jogamp.opengl.awt.Java2DGLContext; #setOpaque}(false). Pixels with resulting OpenGL alpha values less than 1.0 will be overlaid on any underlying Swing rendering. </P> <P> - Notes specific to the Reference Implementation: This component - attempts to use hardware-accelerated rendering via pbuffers and - falls back on to software rendering if problems occur. + Notes specific to the Reference Implementation: This component + attempts to use hardware-accelerated rendering via pbuffers and + falls back on to software rendering if problems occur. Note that because this component attempts to use pbuffers for rendering, and because pbuffers can not be resized, somewhat surprising behavior may occur during resize operations; the {@link @@ -138,7 +135,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing private GLCapabilitiesChooser chooser; private GLContext shareWith; private int additionalCtxCreationFlags = 0; - + // Width of the actual GLJPanel private int panelWidth = 0; private int panelHeight = 0; @@ -180,6 +177,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing private AWTWindowClosingProtocol awtWindowClosingProtocol = new AWTWindowClosingProtocol(this, new Runnable() { + @Override public void run() { GLJPanel.this.destroy(); } @@ -198,7 +196,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing /** Creates a new GLJPanel component with a default set of OpenGL capabilities and using the default OpenGL capabilities selection - mechanism. + mechanism. * @throws GLException if no default profile is available for the default desktop device. */ public GLJPanel() throws GLException { @@ -207,7 +205,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing /** Creates a new GLJPanel component with the requested set of OpenGL capabilities, using the default OpenGL capabilities - selection mechanism. + selection mechanism. * @throws GLException if no GLCapabilities are given and no default profile is available for the default desktop device. */ public GLJPanel(GLCapabilitiesImmutable userCapsRequest) throws GLException { @@ -229,8 +227,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing since J2D GL Context must be shared and we can only share one context. * @throws GLException if no GLCapabilities are given and no default profile is available for the default desktop device. */ - public GLJPanel(GLCapabilitiesImmutable userCapsRequest, GLCapabilitiesChooser chooser, GLContext shareWith) - throws GLException + public GLJPanel(GLCapabilitiesImmutable userCapsRequest, GLCapabilitiesChooser chooser, GLContext shareWith) + throws GLException { super(); @@ -252,6 +250,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing this.shareWith = shareWith; } + @Override public void display() { if (EventQueue.isDispatchThread()) { // Want display() to be synchronous, so call paintImmediately() @@ -280,7 +279,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing animatorPaused = animator.pause(); } - if(backend.getContext().isCreated()) { + if(backend.getContext().isCreated()) { Threading.invoke(true, disposeAction, getTreeLock()); } if(null != backend) { @@ -291,9 +290,9 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing if(animatorPaused) { animator.resume(); - } + } } - + if(DEBUG) { System.err.println(getThreadName()+": GLJPanel.dispose() - stop"); } @@ -302,6 +301,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing /** * Just an alias for removeNotify */ + @Override public void destroy() { removeNotify(); } @@ -352,11 +352,11 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing } updater.setGraphics(g); - + backend.doPaintComponent(g); } - + /** Overridden to track when this component is added to a container. Subclasses which override this method must call super.addNotify() in their addNotify() method in order to @@ -393,7 +393,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing <DL><DD><CODE>reshape</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> */ @SuppressWarnings("deprecation") @Override -public void reshape(int x, int y, int width, int height) { + public void reshape(int x, int y, int width, int height) { super.reshape(x, y, width, height); // reshapeX = x; @@ -411,41 +411,51 @@ public void reshape(int x, int y, int width, int height) { super.setOpaque(opaque); } + @Override public void addGLEventListener(GLEventListener listener) { drawableHelper.addGLEventListener(listener); } + @Override public void addGLEventListener(int index, GLEventListener listener) { drawableHelper.addGLEventListener(index, listener); } + @Override public void removeGLEventListener(GLEventListener listener) { drawableHelper.removeGLEventListener(listener); } + @Override public void setAnimator(GLAnimatorControl animatorControl) { drawableHelper.setAnimator(animatorControl); } + @Override public GLAnimatorControl getAnimator() { return drawableHelper.getAnimator(); } + @Override public void invoke(boolean wait, GLRunnable glRunnable) { drawableHelper.invoke(this, wait, glRunnable); } + @Override public GLContext createContext(GLContext shareWith) { return (null != backend) ? backend.createContext(shareWith) : null; } + @Override public void setRealized(boolean realized) { } + @Override public boolean isRealized() { return isInitialized; } + @Override public void setContext(GLContext ctx) { if (backend == null) { return; @@ -456,6 +466,7 @@ public void reshape(int x, int y, int width, int height) { backend.setContext(ctx); } + @Override public GLContext getContext() { if (backend == null) { return null; @@ -463,6 +474,7 @@ public void reshape(int x, int y, int width, int height) { return backend.getContext(); } + @Override public GL getGL() { if (Beans.isDesignTime()) { return null; @@ -471,6 +483,7 @@ public void reshape(int x, int y, int width, int height) { return (context == null) ? null : context.getGL(); } + @Override public GL setGL(GL gl) { GLContext context = getContext(); if (context != null) { @@ -480,6 +493,7 @@ public void reshape(int x, int y, int width, int height) { return null; } + @Override public void setAutoSwapBufferMode(boolean onOrOff) { // In the current implementation this is a no-op. Both the pbuffer // and pixmap based rendering paths use a single-buffered surface @@ -488,6 +502,7 @@ public void reshape(int x, int y, int width, int height) { // Swing portion of the GLJPanel in any of the rendering paths. } + @Override public boolean getAutoSwapBufferMode() { // In the current implementation this is a no-op. Both the pbuffer // and pixmap based rendering paths use a single-buffered surface @@ -496,7 +511,8 @@ public void reshape(int x, int y, int width, int height) { // Swing portion of the GLJPanel in any of the rendering paths. return true; } - + + @Override public void swapBuffers() { // In the current implementation this is a no-op. Both the pbuffer // and pixmap based rendering paths use a single-buffered surface @@ -505,14 +521,16 @@ public void reshape(int x, int y, int width, int height) { // Swing portion of the GLJPanel in any of the rendering paths. } + @Override public void setContextCreationFlags(int flags) { additionalCtxCreationFlags = flags; } - + + @Override public int getContextCreationFlags() { - return additionalCtxCreationFlags; + return additionalCtxCreationFlags; } - + /** For a translucent GLJPanel (one for which {@link #setOpaque setOpaque}(false) has been called), indicates whether the application should preserve the OpenGL color buffer @@ -529,22 +547,27 @@ public void reshape(int x, int y, int width, int height) { return oglPipelineEnabled; } + @Override public GLCapabilitiesImmutable getChosenGLCapabilities() { return backend.getChosenGLCapabilities(); } + @Override public final GLProfile getGLProfile() { return glProfile; } + @Override public NativeSurface getNativeSurface() { throw new GLException("FIXME"); } + @Override public long getHandle() { throw new GLException("FIXME"); } + @Override public final GLDrawableFactory getFactory() { return factory; } @@ -597,10 +620,12 @@ public void reshape(int x, int y, int width, int height) { awtWindowClosingProtocol.addClosingListenerOneShot(); } + @Override public WindowClosingMode getDefaultCloseOperation() { return awtWindowClosingProtocol.getDefaultCloseOperation(); } + @Override public WindowClosingMode setDefaultCloseOperation(WindowClosingMode op) { return awtWindowClosingProtocol.setDefaultCloseOperation(op); } @@ -618,7 +643,7 @@ public void reshape(int x, int y, int width, int height) { backend.handleReshape(); handleReshape = false; } - + // This is used as the GLEventListener for the pbuffer-based backend // as well as the callback mechanism for the other backends class Updater implements GLEventListener { @@ -628,6 +653,7 @@ public void reshape(int x, int y, int width, int height) { this.g = g; } + @Override public void init(GLAutoDrawable drawable) { if (!backend.preGL(g)) { return; @@ -636,10 +662,12 @@ public void reshape(int x, int y, int width, int height) { backend.postGL(g, false); } + @Override public void dispose(GLAutoDrawable drawable) { drawableHelper.dispose(GLJPanel.this); } + @Override public void display(GLAutoDrawable drawable) { if (!backend.preGL(g)) { return; @@ -656,6 +684,7 @@ public void reshape(int x, int y, int width, int height) { backend.postGL(g, true); } + @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { // This is handled above and dispatched directly to the appropriate context } @@ -664,43 +693,49 @@ public void reshape(int x, int y, int width, int height) { } } + @Override public String toString() { return "AWT-GLJPanel[ "+((null!=backend)?backend.getDrawable().getClass().getName():"null-drawable")+"]"; } private final Runnable postDisposeAction = new Runnable() { + @Override public void run() { if (backend != null && !backend.isUsingOwnThreadManagment()) { backend.destroy(); backend = null; - isInitialized = false; + isInitialized = false; } } - }; + }; private final Runnable disposeAction = new Runnable() { + @Override public void run() { drawableHelper.disposeGL(GLJPanel.this, backend.getDrawable(), backend.getContext(), postDisposeAction); } - }; + }; private final Runnable updaterInitAction = new Runnable() { + @Override public void run() { updater.init(GLJPanel.this); } }; private final Runnable updaterDisplayAction = new Runnable() { + @Override public void run() { updater.display(GLJPanel.this); } }; private final Runnable paintImmediatelyAction = new Runnable() { + @Override public void run() { paintImmediately(0, 0, getWidth(), getHeight()); } - }; + }; private int getNextPowerOf2(int number) { // Workaround for problems where 0 width or height are transiently @@ -720,7 +755,7 @@ public void reshape(int x, int y, int width, int height) { protected static String getThreadName() { return Thread.currentThread().getName(); } - + //---------------------------------------------------------------------- // Implementations of the various backends // @@ -731,7 +766,7 @@ public void reshape(int x, int y, int width, int height) { static interface Backend { // Create, Destroy, .. public boolean isUsingOwnThreadManagment(); - + // Called each time the backend needs to initialize itself public void initialize(); @@ -801,6 +836,7 @@ public void reshape(int x, int y, int width, int height) { private int[] skippixels = new int[1]; private int[] alignment = new int[1]; + @Override public void setOpaque(boolean opaque) { if (opaque != isOpaque()) { if (offscreenImage != null) { @@ -810,11 +846,13 @@ public void reshape(int x, int y, int width, int height) { } } + @Override public boolean preGL(Graphics g) { // Empty in this implementation return true; } + @Override public void postGL(Graphics g, boolean isDisplay) { if (isDisplay) { // Must now copy pixels from offscreen context into surface @@ -938,6 +976,7 @@ public void reshape(int x, int y, int width, int height) { } } + @Override public void doPaintComponent(Graphics g) { doPaintComponentImpl(); if (offscreenImage != null) { @@ -959,8 +998,10 @@ public void reshape(int x, int y, int width, int height) { private GLDrawableImpl offscreenDrawable; private GLContextImpl offscreenContext; + @Override public boolean isUsingOwnThreadManagment() { return false; } - + + @Override public void initialize() { if(DEBUG) { System.err.println(getThreadName()+": SoftwareBackend: initialize()"); @@ -975,10 +1016,11 @@ public void reshape(int x, int y, int width, int height) { offscreenDrawable.setRealized(true); offscreenContext = (GLContextImpl) offscreenDrawable.createContext(shareWith); offscreenContext.setContextCreationFlags(additionalCtxCreationFlags); - + isInitialized = true; } + @Override public void destroy() { if(DEBUG) { System.err.println(getThreadName()+": SoftwareBackend: destroy() - offscreenContext: "+(null!=offscreenContext)+" - offscreenDrawable: "+(null!=offscreenDrawable)); @@ -997,22 +1039,27 @@ public void reshape(int x, int y, int width, int height) { } } + @Override public GLContext createContext(GLContext shareWith) { return (null != offscreenDrawable) ? offscreenDrawable.createContext(shareWith) : null; } + @Override public void setContext(GLContext ctx) { offscreenContext=(GLContextImpl)ctx; } + @Override public GLContext getContext() { return offscreenContext; } + @Override public GLDrawable getDrawable() { return offscreenDrawable; } + @Override public GLCapabilitiesImmutable getChosenGLCapabilities() { if (offscreenDrawable == null) { return null; @@ -1020,6 +1067,7 @@ public void reshape(int x, int y, int width, int height) { return offscreenDrawable.getChosenGLCapabilities(); } + @Override public GLProfile getGLProfile() { if (offscreenDrawable == null) { return null; @@ -1027,6 +1075,7 @@ public void reshape(int x, int y, int width, int height) { return offscreenDrawable.getGLProfile(); } + @Override public void handleReshape() { destroy(); initialize(); @@ -1039,14 +1088,17 @@ public void reshape(int x, int y, int width, int height) { } } + @Override protected void doPaintComponentImpl() { drawableHelper.invokeGL(offscreenDrawable, offscreenContext, updaterDisplayAction, updaterInitAction); } + @Override protected int getGLPixelType() { return offscreenContext.getOffscreenContextPixelDataType(); } + @Override protected boolean flipVertically() { return offscreenContext.offscreenImageNeedsVerticalFlip(); } @@ -1057,8 +1109,10 @@ public void reshape(int x, int y, int width, int height) { private int pbufferWidth = 256; private int pbufferHeight = 256; + @Override public boolean isUsingOwnThreadManagment() { return false; } - + + @Override public void initialize() { if (pbuffer != null) { throw new InternalError("Creating pbuffer twice without destroying it (memory leak / correctness bug)"); @@ -1073,7 +1127,7 @@ public void reshape(int x, int y, int width, int height) { pbufferWidth, pbufferHeight, shareWith); - pbuffer.setContextCreationFlags(additionalCtxCreationFlags); + pbuffer.setContextCreationFlags(additionalCtxCreationFlags); pbuffer.addGLEventListener(updater); isInitialized = true; } catch (GLException e) { @@ -1088,6 +1142,7 @@ public void reshape(int x, int y, int width, int height) { } } + @Override public void destroy() { if(DEBUG) { System.err.println(getThreadName()+": PbufferBackend: destroy() - pbuffer: "+(null!=pbuffer)); @@ -1098,10 +1153,12 @@ public void reshape(int x, int y, int width, int height) { } } + @Override public GLContext createContext(GLContext shareWith) { return (null != pbuffer) ? pbuffer.createContext(shareWith) : null; } + @Override public void setContext(GLContext ctx) { if (pbuffer == null && Beans.isDesignTime()) { return; @@ -1109,6 +1166,7 @@ public void reshape(int x, int y, int width, int height) { pbuffer.setContext(ctx); } + @Override public GLContext getContext() { // Workaround for crashes in NetBeans GUI builder if (pbuffer == null && Beans.isDesignTime()) { @@ -1117,24 +1175,28 @@ public void reshape(int x, int y, int width, int height) { return pbuffer.getContext(); } + @Override public GLDrawable getDrawable() { return pbuffer; } + @Override public GLCapabilitiesImmutable getChosenGLCapabilities() { if (pbuffer == null) { return null; } return pbuffer.getChosenGLCapabilities(); } - + + @Override public GLProfile getGLProfile() { if (pbuffer == null) { return null; } return pbuffer.getGLProfile(); } - + + @Override public void handleReshape() { // Use factor larger than 2 during shrinks for some hysteresis float shrinkFactor = 2.5f; @@ -1192,15 +1254,18 @@ public void reshape(int x, int y, int width, int height) { } } + @Override protected void doPaintComponentImpl() { pbuffer.display(); } + @Override protected int getGLPixelType() { // This seems to be a good choice on all platforms return GL2.GL_UNSIGNED_INT_8_8_8_8_REV; } + @Override protected boolean flipVertically() { return true; } @@ -1255,8 +1320,10 @@ public void reshape(int x, int y, int width, int height) { // comment related to Issue 274 below private GraphicsConfiguration workaroundConfig; + @Override public boolean isUsingOwnThreadManagment() { return true; } - + + @Override public void initialize() { if(DEBUG) { System.err.println(getThreadName()+": J2DOGL: initialize()"); @@ -1265,8 +1332,10 @@ public void reshape(int x, int y, int width, int height) { isInitialized = true; } + @Override public void destroy() { Java2D.invokeWithOGLContextCurrent(null, new Runnable() { + @Override public void run() { if(DEBUG) { System.err.println(getThreadName()+": J2DOGL: destroy() - joglContext: "+(null!=joglContext)+" - joglDrawable: "+(null!=joglDrawable)); @@ -1284,10 +1353,12 @@ public void reshape(int x, int y, int width, int height) { }); } + @Override public void setOpaque(boolean opaque) { // Empty in this implementation } + @Override public GLContext createContext(GLContext shareWith) { if(null != shareWith) { throw new GLException("J2DOGLBackend cannot create context w/ additional shared context, since it already needs to share the context w/ J2D."); @@ -1295,32 +1366,39 @@ public void reshape(int x, int y, int width, int height) { return (null != joglDrawable && null != j2dContext) ? joglDrawable.createContext(j2dContext) : null; } + @Override public void setContext(GLContext ctx) { joglContext=ctx; } + @Override public GLContext getContext() { return joglContext; } + @Override public GLDrawable getDrawable() { return joglDrawable; } + @Override public GLCapabilitiesImmutable getChosenGLCapabilities() { // FIXME: should do better than this; is it possible to using only platform-independent code? return new GLCapabilities(null); } + @Override public GLProfile getGLProfile() { // FIXME: should do better than this; is it possible to using only platform-independent code? return GLProfile.getDefault(GLProfile.getDefaultDevice()); } + @Override public void handleReshape() { // Empty in this implementation } + @Override public boolean preGL(Graphics g) { GL2 gl = joglContext.getGL().getGL2(); // Set up needed state in JOGL context from Java2D context @@ -1403,13 +1481,13 @@ public void reshape(int x, int y, int width, int height) { int[] height = new int[1]; gl.glGetTexLevelParameteriv(fboTextureTarget, 0, GL2.GL_TEXTURE_WIDTH, width, 0); gl.glGetTexLevelParameteriv(fboTextureTarget, 0, GL2.GL_TEXTURE_HEIGHT, height, 0); - + gl.glGenRenderbuffers(1, frameBufferDepthBuffer, 0); if (DEBUG) { System.err.println(getThreadName()+": GLJPanel: Generated frameBufferDepthBuffer " + frameBufferDepthBuffer[0] + " with width " + width[0] + ", height " + height[0]); } - + gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, frameBufferDepthBuffer[0]); // FIXME: may need a loop here like in Java2D gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, GL2GL3.GL_DEPTH_COMPONENT24, width[0], height[0]); @@ -1457,6 +1535,7 @@ public void reshape(int x, int y, int width, int height) { return true; } + @Override public void postGL(Graphics g, boolean isDisplay) { // Cause OpenGL pipeline to flush its results because // otherwise it's possible we will buffer up multiple frames' @@ -1473,6 +1552,7 @@ public void reshape(int x, int y, int width, int height) { } } + @Override public void doPaintComponent(final Graphics g) { // This is a workaround for an issue in the Java 2D / JOGL // bridge (reported by an end user as JOGL Issue 274) where Java @@ -1498,10 +1578,12 @@ public void reshape(int x, int y, int width, int height) { getDefaultScreenDevice(). getDefaultConfiguration(); } - Java2D.invokeWithOGLSharedContextCurrent(workaroundConfig, new Runnable() { public void run() {}}); + Java2D.invokeWithOGLSharedContextCurrent(workaroundConfig, new Runnable() { @Override + public void run() {}}); } Java2D.invokeWithOGLContextCurrent(g, new Runnable() { + @Override public void run() { if (DEBUG) { System.err.println(getThreadName()+": GLJPanel.invokeWithOGLContextCurrent"); |