diff options
author | Sven Gothel <[email protected]> | 2023-01-22 09:17:41 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-01-22 09:17:41 +0100 |
commit | bd2004b140f12afeb2e2337a1b426a212b1ba492 (patch) | |
tree | 799a2df613fda22709ab229c50e654947022d943 /src | |
parent | be4fa1f3fc1a97ad712b8d907e611a99c2bd4c83 (diff) |
Execute AWT's Frame.setTitle() on AWT-EDT if already visible (avoid rare deadlock)
Diffstat (limited to 'src')
4 files changed, 41 insertions, 14 deletions
diff --git a/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java index 860ee9188..8cd2a1f32 100644 --- a/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java @@ -49,6 +49,7 @@ import jogamp.nativewindow.awt.AWTMisc; import jogamp.newt.WindowImpl; import com.jogamp.common.os.Platform; +import com.jogamp.common.util.awt.AWTEDTExecutor; import com.jogamp.nativewindow.awt.AWTGraphicsConfiguration; import com.jogamp.nativewindow.awt.AWTGraphicsDevice; import com.jogamp.nativewindow.awt.AWTGraphicsScreen; @@ -97,7 +98,11 @@ public class WindowDriver extends WindowImpl { @Override protected void setTitleImpl(final String title) { if (awtFrame != null) { - awtFrame.setTitle(title); + AWTEDTExecutor.singleton.invoke(false, new Runnable() { + @Override + public void run() { + awtFrame.setTitle(title); + } } ); } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java index 83826bacc..aa2789e4e 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java @@ -36,6 +36,7 @@ import com.jogamp.opengl.util.Animator; import com.jogamp.opengl.awt.GLCanvas; import com.jogamp.common.os.Platform; +import com.jogamp.common.util.awt.AWTEDTExecutor; import com.jogamp.newt.event.awt.AWTKeyAdapter; import com.jogamp.newt.event.awt.AWTWindowAdapter; import com.jogamp.newt.event.KeyEvent; @@ -100,6 +101,7 @@ public class TestGearsES2AWT extends UITestCase { public static void initClass() { try { EventQueue.invokeAndWait(new Runnable() { + @Override public void run() { awtEDT = Thread.currentThread(); } } ); @@ -116,6 +118,7 @@ public class TestGearsES2AWT extends UITestCase { static void setComponentSize(final Frame frame, final Component comp, final java.awt.Dimension new_sz) { try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { comp.setMinimumSize(new_sz); comp.setPreferredSize(new_sz); @@ -132,6 +135,7 @@ public class TestGearsES2AWT extends UITestCase { static void setFrameSize(final Frame frame, final boolean frameLayout, final java.awt.Dimension new_sz) { try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { frame.setSize(new_sz); if( frameLayout ) { @@ -162,11 +166,15 @@ public class TestGearsES2AWT extends UITestCase { final float[] maxSurfacePixelScale = glc.getMaximumSurfaceScale(new float[2]); final float[] reqSurfacePixelScale = glc.getRequestedSurfaceScale(new float[2]); final float[] hasSurfacePixelScale = glc.getCurrentSurfaceScale(new float[2]); - frame.setTitle("GLCanvas["+capsA+"], swapI "+swapInterval+", win: ["+b.x+"/"+b.y+" "+b.width+"x"+b.height+"], pix: "+glc.getSurfaceWidth()+"x"+glc.getSurfaceHeight()+ - ", scale[min "+minSurfacePixelScale[0]+"x"+minSurfacePixelScale[1]+", max "+ - maxSurfacePixelScale[0]+"x"+maxSurfacePixelScale[1]+", req "+ - reqSurfacePixelScale[0]+"x"+reqSurfacePixelScale[1]+" -> has "+ - hasSurfacePixelScale[0]+"x"+hasSurfacePixelScale[1]+"]"); + AWTEDTExecutor.singleton.invoke(false, new Runnable() { + @Override + public void run() { + frame.setTitle("GLCanvas["+capsA+"], swapI "+swapInterval+", win: ["+b.x+"/"+b.y+" "+b.width+"x"+b.height+"], pix: "+glc.getSurfaceWidth()+"x"+glc.getSurfaceHeight()+ + ", scale[min "+minSurfacePixelScale[0]+"x"+minSurfacePixelScale[1]+", max "+ + maxSurfacePixelScale[0]+"x"+maxSurfacePixelScale[1]+", req "+ + reqSurfacePixelScale[0]+"x"+reqSurfacePixelScale[1]+" -> has "+ + hasSurfacePixelScale[0]+"x"+hasSurfacePixelScale[1]+"]"); + } } ); } protected void runTestGL(final GLCapabilities caps, final ResizeBy resizeBy, final FrameLayout frameLayout) throws InterruptedException, InvocationTargetException { @@ -275,6 +283,7 @@ public class TestGearsES2AWT extends UITestCase { new AWTKeyAdapter(kl, glCanvas).addTo(glCanvas); javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { if( ResizeBy.Frame == resizeBy ) { frame.validate(); @@ -332,11 +341,13 @@ public class TestGearsES2AWT extends UITestCase { } javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { frame.setVisible(false); }}); Assert.assertEquals(false, frame.isVisible()); javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { if(shutdownRemoveGLCanvas) { frame.remove(glCanvas); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java index bbcb936f3..1d1644e9b 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java @@ -35,6 +35,7 @@ import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.lang.reflect.InvocationTargetException; +import com.jogamp.common.util.awt.AWTEDTExecutor; import com.jogamp.nativewindow.ScalableSurface; import com.jogamp.nativewindow.util.Rectangle; import com.jogamp.nativewindow.util.RectangleImmutable; @@ -107,6 +108,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { static void setFrameSize(final JFrame frame, final boolean frameLayout, final java.awt.Dimension new_sz) { try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { frame.setSize(new_sz); if( frameLayout ) { @@ -127,11 +129,15 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { final float[] maxSurfacePixelScale = glc.getMaximumSurfaceScale(new float[2]); final float[] reqSurfacePixelScale = glc.getRequestedSurfaceScale(new float[2]); final float[] hasSurfacePixelScale = glc.getCurrentSurfaceScale(new float[2]); - frame.setTitle("GLJPanel["+capsA+"], swapI "+swapInterval+", win: ["+b.x+"/"+b.y+" "+b.width+"x"+b.height+"], pix: "+glc.getSurfaceWidth()+"x"+glc.getSurfaceHeight()+ - ", scale[min "+minSurfacePixelScale[0]+"x"+minSurfacePixelScale[1]+", max "+ - maxSurfacePixelScale[0]+"x"+maxSurfacePixelScale[1]+", req "+ - reqSurfacePixelScale[0]+"x"+reqSurfacePixelScale[1]+" -> has "+ - hasSurfacePixelScale[0]+"x"+hasSurfacePixelScale[1]+"]"); + AWTEDTExecutor.singleton.invoke(false, new Runnable() { + @Override + public void run() { + frame.setTitle("GLJPanel["+capsA+"], swapI "+swapInterval+", win: ["+b.x+"/"+b.y+" "+b.width+"x"+b.height+"], pix: "+glc.getSurfaceWidth()+"x"+glc.getSurfaceHeight()+ + ", scale[min "+minSurfacePixelScale[0]+"x"+minSurfacePixelScale[1]+", max "+ + maxSurfacePixelScale[0]+"x"+maxSurfacePixelScale[1]+", req "+ + reqSurfacePixelScale[0]+"x"+reqSurfacePixelScale[1]+" -> has "+ + hasSurfacePixelScale[0]+"x"+hasSurfacePixelScale[1]+"]"); + } } ); } protected GLEventListener createDemo(final GLCapabilities caps) { @@ -213,6 +219,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { frame.setVisible(true); } else { SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { frame.getContentPane().add(glJPanel, BorderLayout.CENTER); frame.getContentPane().validate(); @@ -260,6 +267,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { } } else { SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { if( null != frame ) { frame.setVisible(false); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java index 7e92c8438..439d9fa99 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java @@ -29,12 +29,11 @@ package com.jogamp.opengl.test.junit.newt.parenting; import java.awt.Frame; +import com.jogamp.common.util.awt.AWTEDTExecutor; import com.jogamp.nativewindow.CapabilitiesImmutable; import com.jogamp.nativewindow.NativeWindow; import com.jogamp.nativewindow.NativeWindowHolder; -import com.jogamp.nativewindow.util.InsetsImmutable; import com.jogamp.newt.Window; -import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.newt.opengl.util.NEWTDemoListener; @@ -59,7 +58,11 @@ public class NewtAWTReparentingKeyAdapter extends NewtReparentingKeyAdapter { final CapabilitiesImmutable caps = null != chosenCaps ? chosenCaps : reqCaps; final String capsA = caps.isBackgroundOpaque() ? "opaque" : "transl"; { - frame.setTitle("Frame["+capsA+"], win: "+getNativeWinTitle(nw)); + AWTEDTExecutor.singleton.invoke(false, new Runnable() { + @Override + public void run() { + frame.setTitle("Frame["+capsA+"], win: "+getNativeWinTitle(nw)); + } } ); } super.setTitle(nw, win); } |