aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/newt/classes/com/jogamp/newt/opengl/util/NEWTDemoListener.java10
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java10
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java192
3 files changed, 172 insertions, 40 deletions
diff --git a/src/newt/classes/com/jogamp/newt/opengl/util/NEWTDemoListener.java b/src/newt/classes/com/jogamp/newt/opengl/util/NEWTDemoListener.java
index 58484ca57..3e0b4f43c 100644
--- a/src/newt/classes/com/jogamp/newt/opengl/util/NEWTDemoListener.java
+++ b/src/newt/classes/com/jogamp/newt/opengl/util/NEWTDemoListener.java
@@ -423,7 +423,15 @@ public class NEWTDemoListener extends WindowAdapter implements KeyListener, Mous
final float[] sDPI = win.getPixelsPerMM(new float[2]);
sDPI[0] *= 25.4f;
sDPI[1] *= 25.4f;
- win.setTitle("GLWindow["+capsA+"], win: "+win.getBounds()+", pix: "+win.getSurfaceWidth()+"x"+win.getSurfaceHeight()+", sDPI "+sDPI[0]+" x "+sDPI[1]);
+ final float[] minSurfacePixelScale = win.getMinimumSurfaceScale(new float[2]);
+ final float[] maxSurfacePixelScale = win.getMaximumSurfaceScale(new float[2]);
+ final float[] reqSurfacePixelScale = win.getRequestedSurfaceScale(new float[2]);
+ final float[] hasSurfacePixelScale = win.getCurrentSurfaceScale(new float[2]);
+ win.setTitle("GLWindow["+capsA+"], win: "+win.getBounds()+", pix: "+win.getSurfaceWidth()+"x"+win.getSurfaceHeight()+", sDPI "+sDPI[0]+" x "+sDPI[1]+
+ ", 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]+"]");
}
public static PointerIcon[] createPointerIcons(final Display disp) {
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 2e805d8fd..503878c65 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
@@ -158,7 +158,15 @@ public class TestGearsES2AWT extends UITestCase {
private void setTitle(final Frame frame, final GLCanvas glc, final GLCapabilitiesImmutable caps) {
final String capsA = caps.isBackgroundOpaque() ? "opaque" : "transl";
final java.awt.Rectangle b = glc.getBounds();
- frame.setTitle("GLCanvas["+capsA+"], swapI "+swapInterval+", win: ["+b.x+"/"+b.y+" "+b.width+"x"+b.height+"], pix: "+glc.getSurfaceWidth()+"x"+glc.getSurfaceHeight());
+ final float[] minSurfacePixelScale = glc.getMinimumSurfaceScale(new float[2]);
+ 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]+"]");
}
protected void runTestGL(final GLCapabilities caps, final ResizeBy resizeBy, final FrameLayout frameLayout) throws InterruptedException, InvocationTargetException {
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 dfc2d1165..0312604d7 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
@@ -31,6 +31,8 @@ package com.jogamp.opengl.test.junit.jogl.demos.es2.awt;
import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.Dimension;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
import java.lang.reflect.InvocationTargetException;
import com.jogamp.nativewindow.ScalableSurface;
@@ -118,17 +120,21 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
private void setTitle(final JFrame frame, final GLJPanel glc, final GLCapabilitiesImmutable caps) {
final String capsA = caps.isBackgroundOpaque() ? "opaque" : "transl";
final java.awt.Rectangle b = glc.getBounds();
- frame.setTitle("GLJPanel["+capsA+"], swapI "+swapInterval+", win: ["+b.x+"/"+b.y+" "+b.width+"x"+b.height+"], pix: "+glc.getSurfaceWidth()+"x"+glc.getSurfaceHeight());
+
+ final float[] minSurfacePixelScale = glc.getMinimumSurfaceScale(new float[2]);
+ 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]+"]");
}
- protected void runTestGL(final GLCapabilities caps)
+ protected GLJPanel newGLJPanel(final JFrame frame, final GLCapabilities caps, final FPSAnimator animator, final SnapshotGLEventListener snap)
throws AWTException, InterruptedException, InvocationTargetException
{
- System.err.println("Requesting: "+caps);
-
- final JFrame frame = new JFrame("Swing GLJPanel");
- Assert.assertNotNull(frame);
-
final GLJPanel glJPanel = new GLJPanel(caps);
Assert.assertNotNull(glJPanel);
glJPanel.setSkipGLOrientationVerticalFlip(skipGLOrientationVerticalFlip);
@@ -136,7 +142,6 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
glJPanel.setPreferredSize(wsize);
glJPanel.setSize(wsize);
glJPanel.setSurfaceScale(reqSurfacePixelScale);
- final float[] valReqSurfacePixelScale = glJPanel.getRequestedSurfaceScale(new float[2]);
if( caps.isBitmap() || caps.getGLProfile().isGL2() ) {
final Gears gears = new Gears(swapInterval);
gears.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip);
@@ -146,8 +151,9 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
gears.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip);
glJPanel.addGLEventListener(gears);
}
- final SnapshotGLEventListener snap = new SnapshotGLEventListener();
- glJPanel.addGLEventListener(snap);
+ if( null != snap ) {
+ glJPanel.addGLEventListener(snap);
+ }
glJPanel.addGLEventListener(new GLEventListener() {
@Override
public void init(final GLAutoDrawable drawable) { }
@@ -159,42 +165,128 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
setTitle(frame, glJPanel, caps);
}
+
});
setTitle(frame, glJPanel, caps);
- frame.setLocation(xpos, ypos);
- final FPSAnimator animator = useAnimator ? new FPSAnimator(glJPanel, 60) : null;
+ frame.addComponentListener(new ComponentListener() {
+ @Override
+ public void componentResized(final ComponentEvent e) {
+ setTitle(frame, glJPanel, caps);
+ }
- SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
- frame.getContentPane().add(glJPanel, BorderLayout.CENTER);
- frame.getContentPane().validate();
- frame.pack();
- frame.setVisible(true);
- } } ) ;
- Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true));
- Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glJPanel, true));
+ @Override
+ public void componentMoved(final ComponentEvent e) {
+ setTitle(frame, glJPanel, caps);
+ }
- final Screen screen = NewtFactoryAWT.createScreen(glJPanel, true);
- screen.addReference(); // initial native creation - keep alive!
- System.err.println("GetPixelScale: AWT -> Screen: "+screen);
+ @Override
+ public void componentShown(final ComponentEvent e) { }
- final float[] hasSurfacePixelScale1 = glJPanel.getCurrentSurfaceScale(new float[2]);
- System.err.println("HiDPI PixelScale: "+reqSurfacePixelScale[0]+"x"+reqSurfacePixelScale[1]+" (req) -> "+
- valReqSurfacePixelScale[0]+"x"+valReqSurfacePixelScale[1]+" (val) -> "+
- hasSurfacePixelScale1[0]+"x"+hasSurfacePixelScale1[1]+" (has)");
- setTitle(frame, glJPanel, caps);
+ @Override
+ public void componentHidden(final ComponentEvent e) { }
+ });
- if( useAnimator ) {
+ if( SwingUtilities.isEventDispatchThread() ) {
+ frame.getContentPane().add(glJPanel, BorderLayout.CENTER);
+ frame.getContentPane().validate();
+ frame.pack();
+ frame.setVisible(true);
+ } else {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.getContentPane().add(glJPanel, BorderLayout.CENTER);
+ frame.getContentPane().validate();
+ frame.pack();
+ frame.setVisible(true);
+ } } ) ;
+ Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true));
+ Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glJPanel, true));
+
+ final float[] minSurfacePixelScale = glJPanel.getMinimumSurfaceScale(new float[2]);
+ final float[] maxSurfacePixelScale = glJPanel.getMaximumSurfaceScale(new float[2]);
+ final float[] valReqSurfacePixelScale = glJPanel.getRequestedSurfaceScale(new float[2]);
+ final float[] hasSurfacePixelScale = glJPanel.getCurrentSurfaceScale(new float[2]);
+ System.err.println("HiDPI PixelScale: min "+
+ minSurfacePixelScale[0]+"x"+minSurfacePixelScale[1]+", max "+
+ maxSurfacePixelScale[0]+"x"+maxSurfacePixelScale[1]+", req "+
+ reqSurfacePixelScale[0]+"x"+reqSurfacePixelScale[1]+" -> val "+
+ valReqSurfacePixelScale[0]+"x"+valReqSurfacePixelScale[1]+" -> has "+
+ hasSurfacePixelScale[0]+"x"+hasSurfacePixelScale[1]);
+ setTitle(frame, glJPanel, caps);
+ }
+
+ if( null != animator ) {
+ animator.add(glJPanel);
animator.setUpdateFPSFrames(60, System.err);
+ }
+ return glJPanel;
+ }
+
+ protected void destroy(final JFrame frame, final GLJPanel glJPanel) {
+ try {
+ if( SwingUtilities.isEventDispatchThread() ) {
+ if( null != frame ) {
+ frame.setVisible(false);
+ if( null != glJPanel ) {
+ frame.getContentPane().remove(glJPanel);
+ }
+ frame.remove(glJPanel);
+ }
+ if( null != glJPanel ) {
+ glJPanel.destroy();
+ }
+ if( null != frame ) {
+ frame.dispose();
+ }
+ } else {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ if( null != frame ) {
+ frame.setVisible(false);
+ if( null != glJPanel ) {
+ frame.getContentPane().remove(glJPanel);
+ }
+ frame.remove(glJPanel);
+ }
+ if( null != glJPanel ) {
+ glJPanel.destroy();
+ }
+ if( null != frame ) {
+ frame.dispose();
+ }
+ } } );
+ }
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ protected void runTestGL(final GLCapabilities caps)
+ throws AWTException, InterruptedException, InvocationTargetException
+ {
+ final JFrame frame = new JFrame("Swing GLJPanel");
+ frame.setLocation(xpos, ypos);
+ Assert.assertNotNull(frame);
+
+ final FPSAnimator animator = useAnimator ? new FPSAnimator(60) : null;
+ final SnapshotGLEventListener snap = new SnapshotGLEventListener();
+ final GLJPanel glJPanel = newGLJPanel(frame, caps, animator, snap);
+ if( null != animator ) {
animator.start();
Assert.assertEquals(true, animator.isAnimating());
}
+ final Screen screen = NewtFactoryAWT.createScreen(glJPanel, true);
+ screen.addReference(); // initial native creation - keep alive!
+ System.err.println("GetPixelScale: AWT -> Screen: "+screen);
final QuitAdapter quitAdapter = new QuitAdapter();
new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter), glJPanel).addTo(glJPanel);
new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glJPanel).addTo(frame);
+ final JFrame[] frame2 = { null };
+ final GLJPanel[] glJPanel2 = { null };
+
final com.jogamp.newt.event.KeyListener kl = new com.jogamp.newt.event.KeyAdapter() {
@Override
public void keyPressed(final KeyEvent e) {
@@ -262,6 +354,33 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
glJPanel.setRequestedGLCapabilities(capsNew);
System.err.println("XXX-A2: "+animator.toString());
System.err.println("XXX: "+glJPanel.toString());
+ } else if(e.getKeyChar()=='n') {
+ System.err.println("XXX: frame2: "+frame2[0]);
+ if( null != frame2[0] ) {
+ System.err.println("XXX: frame2.isShowing: "+frame2[0].isShowing());
+ }
+ System.err.println("XXX: glJPanel2: "+glJPanel2[0]);
+ if( null != frame2[0] && frame2[0].isShowing() ) {
+ destroy(frame2[0], glJPanel2[0]);
+ frame2[0] = null;
+ glJPanel2[0] = null;
+ } else {
+ frame2[0] = new JFrame("GLJPanel2");
+ frame2[0].setLocation(frame.getX()+frame.getWidth()+64, frame.getY());
+ final FPSAnimator animator2 = useAnimator ? new FPSAnimator(60) : null;
+ if( null != animator2 ) {
+ animator2.start();
+ }
+ final SnapshotGLEventListener snap2 = new SnapshotGLEventListener();
+ try {
+ glJPanel2[0] = newGLJPanel(frame2[0], caps, animator2, snap2);
+ } catch (final Exception e2) {
+ e2.printStackTrace();
+ destroy(frame2[0], glJPanel2[0]);
+ frame2[0] = null;
+ glJPanel2[0] = null;
+ }
+ }
}
} };
new AWTKeyAdapter(kl, glJPanel).addTo(glJPanel);
@@ -300,15 +419,12 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
} else {
Assert.assertNull(animator);
}
- SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
- frame.setVisible(false);
- frame.getContentPane().remove(glJPanel);
- frame.remove(glJPanel);
- glJPanel.destroy();
- frame.dispose();
- } } );
+
screen.removeReference(); // final native destroy
+ destroy(frame, glJPanel);
+ if( null != frame2[0] ) {
+ destroy(frame2[0], glJPanel2[0]);
+ }
}
@Test