diff options
author | Dan Krisher <[email protected]> | 2012-01-11 10:37:47 -0500 |
---|---|---|
committer | Dan Krisher <[email protected]> | 2012-01-11 10:37:47 -0500 |
commit | 6fecbcd14c069193aefa2e580aaa53de5265fce3 (patch) | |
tree | 6448d3d08b9c9bb58f1798ebcb882af448bd4939 /src/jogl | |
parent | 1a79d4f87d750b3146b80bd861230022e66108d6 (diff) |
Fix for use of SWT GLCanvas in headless mode (or with threading in worker mode). See discussion in Bugzilla #484
Diffstat (limited to 'src/jogl')
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java b/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java index ef1c3fbeb..c982ce16d 100644 --- a/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java +++ b/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java @@ -57,6 +57,7 @@ import org.eclipse.swt.events.ControlAdapter; import org.eclipse.swt.events.ControlEvent; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; @@ -186,6 +187,11 @@ public class GLCanvas extends Canvas implements GLAutoDrawable { }; /** + * Storage for the client area rectangle so that it may be accessed from outside of the SWT thread. + */ + private volatile Rectangle clientArea; + + /** * Creates a new SWT GLCanvas. * * @param parent @@ -212,6 +218,8 @@ public class GLCanvas extends Canvas implements GLAutoDrawable { SWTAccessor.setRealized(this, true); + clientArea = GLCanvas.this.getClientArea(); + /* Get the nativewindow-Graphics Device associated with this control (which is determined by the parent Composite) */ device = SWTAccessor.getDevice(this); /* Native handle for the control, used to associate with GLContext */ @@ -247,6 +255,7 @@ public class GLCanvas extends Canvas implements GLAutoDrawable { addControlListener(new ControlAdapter() { @Override public void controlResized(final ControlEvent arg0) { + clientArea = GLCanvas.this.getClientArea(); /* Mark for OpenGL reshape next time the control is painted */ sendReshape = true; } @@ -381,7 +390,9 @@ public class GLCanvas extends Canvas implements GLAutoDrawable { } public int getHeight() { - return getClientArea().height; + final Rectangle clientArea = this.clientArea; + if (clientArea == null) return 0; + return clientArea.height; } public NativeSurface getNativeSurface() { @@ -395,7 +406,9 @@ public class GLCanvas extends Canvas implements GLAutoDrawable { } public int getWidth() { - return getClientArea().width; + final Rectangle clientArea = this.clientArea; + if (clientArea == null) return 0; + return clientArea.width; } public boolean isRealized() { |