From 6fecbcd14c069193aefa2e580aaa53de5265fce3 Mon Sep 17 00:00:00 2001 From: Dan Krisher Date: Wed, 11 Jan 2012 10:37:47 -0500 Subject: Fix for use of SWT GLCanvas in headless mode (or with threading in worker mode). See discussion in Bugzilla #484 --- src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java | 17 +++++++++++++++-- 1 file 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; @@ -185,6 +186,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. * @@ -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() { -- cgit v1.2.3