aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/javax/media/opengl/awt
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-11-25 03:01:27 +0100
committerSven Gothel <[email protected]>2010-11-25 03:01:27 +0100
commit16bb638603c01e3d3ed94c63550b7c2b18ad23a2 (patch)
tree0be8cb4e669e3bc6ea6f5fd272f3564b382a8bd5 /src/jogl/classes/javax/media/opengl/awt
parentce3508aa66b9a40974cce2988094d0edc68b30f4 (diff)
Fix GLCanvas Recreation - Regression 96af6c9bf2d683115996
96af6c9bf2d683115996 moved the creation of the AWTGraphicsConfiguration, GLDrawable and GLContext to the GLCanvas constructor. This disabled recreation, removeNotify()/addNotify() after 1st addNotify(), since the drawable/context were already set to null. Smart recreation, ie not destroying the resources completly: 1 - drawable 2 - context 3 - AWTGraphicsConfiguration's Device (X11: Display) is not possible, since removeNotify() is the only destroy notification we have from AWT, which would leave the above resources open -> leak. This is especially true for (3), since the device is created 'on the fly'. In NEWT we use lazy creation/destroy and are able to keep the references alive. A remodelling of AbstractGraphicsConfiguration would be required, which indeed would be overkill. Simple solution is to move the creation block back to addNotify() but before 'super.addNotify()', since it needs our chosen AWTGraphicsConfiguration. Also flagging sendReshape in addNotify(). Added test case com.jogamp.test.junit.jogl.awt.TestAWT03GLCanvasRecreate01.
Diffstat (limited to 'src/jogl/classes/javax/media/opengl/awt')
-rw-r--r--src/jogl/classes/javax/media/opengl/awt/GLCanvas.java73
1 files changed, 41 insertions, 32 deletions
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
index b2d919eaf..aeb698c81 100644
--- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
+++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
@@ -86,17 +86,17 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
defaultGLProfile = GLProfile.getDefault(GLProfile.getDefaultDesktopDevice());
}
- private GLProfile glProfile;
private GLDrawableHelper drawableHelper = new GLDrawableHelper();
- private GraphicsConfiguration chosen;
private AWTGraphicsConfiguration awtConfig;
private GLDrawable drawable;
private GLContextImpl context;
private boolean sendReshape = false;
- // copy of the cstr args ..
+ // copy of the cstr args, mainly for recreation
+ private GLCapabilitiesImmutable capsReqUser;
private GLCapabilitiesChooser chooser;
- private GLContext shareWith;
+ private GLContext shareWith;
+ private GraphicsDevice device;
/** Creates a new GLCanvas component with a default set of OpenGL
capabilities, using the default OpenGL capabilities selection
@@ -154,25 +154,11 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
}
}
- this.glProfile = capsReqUser.getGLProfile();
+ // instantiation will be issued in addNotify()
+ this.capsReqUser = capsReqUser;
this.chooser = chooser;
this.shareWith = shareWith;
-
- /*
- * Save the 'chosen' GraphicsConfiguration for use in getGraphicsConfiguration().
- */
- awtConfig = chooseGraphicsConfiguration(capsReqUser, capsReqUser, chooser, device);
- if(null==awtConfig) {
- throw new GLException("Error: NULL AWTGraphicsConfiguration");
- }
- chosen = awtConfig.getGraphicsConfiguration();
-
- if (!Beans.isDesignTime()) {
- // no lock required, since this resource ain't available yet
- drawable = GLDrawableFactory.getFactory(glProfile).createGLDrawable(NativeWindowFactory.getNativeWindow(this, awtConfig));
- context = (GLContextImpl) drawable.createContext(shareWith);
- context.setSynchronized(true);
- }
+ this.device = device;
}
protected interface DestroyMethod {
@@ -230,6 +216,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
* otherwise it is from an ancestor component that this Canvas is being
* added to, and we go into this block.
*/
+ GraphicsConfiguration chosen = awtConfig.getGraphicsConfiguration();
+
if (gc != null && chosen != null && !chosen.equals(gc)) {
/*
* Check for compatibility with gc. If they differ by only the
@@ -350,11 +338,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
boolean animatorPaused = false;
GLAnimatorControl animator = getAnimator();
if(null!=animator) {
- if(regenerate) {
- animatorPaused = animator.pause();
- } else {
- animator.remove(this);
- }
+ // can't remove us from animator for recreational addNotify()
+ animatorPaused = animator.pause();
}
disposeRegenerate=regenerate;
@@ -445,16 +430,36 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
Exception ex1 = new Exception(Thread.currentThread().getName()+" - Info: addNotify - start");
ex1.printStackTrace();
}
- // 'super.addNotify()' determines the GraphicsConfiguration,
- // while calling this class's overriden 'getGraphicsConfiguration()' method.
- // Then it creates the native peer.
- // Hence we chose the proper GraphicsConfiguration beforehand (see constructor).
+
+ /**
+ * 'super.addNotify()' determines the GraphicsConfiguration,
+ * while calling this class's overriden 'getGraphicsConfiguration()' method
+ * after which it creates the native peer.
+ * Hence we have to set the 'awtConfig' before since it's GraphicsConfiguration
+ * is being used in getGraphicsConfiguration().
+ * This code order also allows recreation, ie re-adding the GLCanvas.
+ */
+ awtConfig = chooseGraphicsConfiguration(capsReqUser, capsReqUser, chooser, device);
+ if(null==awtConfig) {
+ throw new GLException("Error: NULL AWTGraphicsConfiguration");
+ }
+
+ if (!Beans.isDesignTime()) {
+ // no lock required, since this resource ain't available yet
+ drawable = GLDrawableFactory.getFactory(capsReqUser.getGLProfile())
+ .createGLDrawable(NativeWindowFactory.getNativeWindow(this, awtConfig));
+ context = (GLContextImpl) drawable.createContext(shareWith);
+ context.setSynchronized(true);
+ }
+
+ // issues getGraphicsConfiguration() and creates the native peer
super.addNotify();
if (!Beans.isDesignTime()) {
// no lock required, since this resource ain't available yet
disableBackgroundErase();
drawable.setRealized(true);
+ sendReshape=true; // ensure a reshape is being send ..
if(DEBUG) {
System.err.println(Thread.currentThread().getName()+" - Realized Drawable: "+drawable);
}
@@ -576,7 +581,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
}
public GLProfile getGLProfile() {
- return glProfile;
+ return capsReqUser.getGLProfile();
}
public GLCapabilitiesImmutable getChosenGLCapabilities() {
@@ -641,7 +646,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
if(disposeRegenerate) {
// recreate GLDrawable to reflect it's new graphics configuration
- drawable = GLDrawableFactory.getFactory(glProfile).createGLDrawable(NativeWindowFactory.getNativeWindow(GLCanvas.this, awtConfig));
+ drawable = GLDrawableFactory.getFactory(capsReqUser.getGLProfile())
+ .createGLDrawable(NativeWindowFactory.getNativeWindow(GLCanvas.this, awtConfig));
if(DEBUG) {
System.err.println("GLCanvas.dispose(true): new drawable: "+drawable);
}
@@ -693,6 +699,9 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
class DisplayAction implements Runnable {
public void run() {
if (sendReshape) {
+ if(DEBUG) {
+ System.err.println(Thread.currentThread().getName()+" - reshape: "+getWidth()+"x"+getHeight());
+ }
// Note: we ignore the given x and y within the parent component
// since we are drawing directly into this heavyweight component.
drawableHelper.reshape(GLCanvas.this, 0, 0, getWidth(), getHeight());