diff options
13 files changed, 427 insertions, 175 deletions
diff --git a/make/scripts/tests-win.bat b/make/scripts/tests-win.bat index 06e0c512d..8c6970f33 100755 --- a/make/scripts/tests-win.bat +++ b/make/scripts/tests-win.bat @@ -30,6 +30,7 @@ REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGea REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.acore.anim.TestAnimatorGLWindow01NEWT %* REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.acore.anim.TestAnimatorGLJPanel01AWT %* REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.awt.TestGLJPanelResize01AWT %* +REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.awt.TestGLCanvasResize01AWT %* REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2AWT %* REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NewtCanvasAWT %* REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.swt.TestGLCanvasSWTNewtCanvasSWTPosInTabs %* diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index 8f1d2a656..dd90647e6 100644 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -198,7 +198,7 @@ function jrun() { #D_ARGS="-Djogl.debug.GLSLCode -Djogl.debug.DebugGL" #D_ARGS="-Djogl.debug.TraceGL -Djogl.debug.DebugGL -Djogl.debug.GLSLCode" #D_ARGS="-Djogl.debug.GLContext -Dnativewindow.debug.JAWT -Dnewt.debug.Window" - #D_ARGS="-Dnativewindow.debug.JAWT -Djogl.debug.GLCanvas" + #D_ARGS="-Dnativewindow.debug.JAWT -Djogl.debug.GLCanvas -Djogl.debug.GLJPanel -Dnewt.debug.Window" #D_ARGS="-Dnativewindow.debug.JAWT -Djogamp.debug.TaskBase.TraceSource" #D_ARGS="-Dnativewindow.debug.JAWT" #D_ARGS="-Djogl.debug.GLContext.TraceSwitch" @@ -298,7 +298,6 @@ function jrun() { #D_ARGS="-Dnewt.debug.EDT" #D_ARGS="-Dnewt.debug.Window -Dnewt.debug.Display -Dnewt.debug.EDT -Djogl.debug.GLContext" #D_ARGS="-Dnewt.debug.Window -Djogl.debug.Animator -Dnewt.debug.Screen" - #D_ARGS="-Dnativewindow.debug.JAWT -Dnewt.debug.Window -Djogl.debug.GLJPanel -Djogl.debug.GLCanvas -Djogamp.debug.TempJarCache" #D_ARGS="-Dnewt.debug.Window.KeyEvent" #D_ARGS="-Dnewt.debug.Window.MouseEvent" #D_ARGS="-Dnewt.debug.Window.MouseEvent -Dnewt.debug.Window.KeyEvent" @@ -308,7 +307,6 @@ function jrun() { #D_ARGS="-Dnewt.debug.Window -Dnewt.debug.Window.KeyEvent" #D_ARGS="-Dnewt.debug.Window -Dnewt.debug.Window.MouseEvent -Dnewt.debug.Window.KeyEvent" #D_ARGS="-Dnewt.debug.Window" - #D_ARGS="-Dnewt.debug.Window -Dnativewindow.debug.JAWT" #D_ARGS="-Dnewt.debug.Window.visibility.failure.freeze" #D_ARGS="-Xprof" #D_ARGS="-Dnativewindow.debug=all -Djogl.debug=all -Dnewt.debug=all" @@ -503,9 +501,11 @@ function testawtswt() { # #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2SimpleNEWT $* +#testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2GLJPanelAWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.anim.TestAnimatorGLWindow01NEWT $* #testawt com.jogamp.opengl.test.junit.jogl.acore.anim.TestAnimatorGLJPanel01AWT $* -#testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2GLJPanelAWT $* +#testawt com.jogamp.opengl.test.junit.jogl.awt.TestGLJPanelResize01AWT $* +#testawt com.jogamp.opengl.test.junit.jogl.awt.TestGLCanvasResize01AWT $* #testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2AWT $* #testawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NewtCanvasAWT $* #testswt com.jogamp.opengl.test.junit.jogl.swt.TestGLCanvasSWTNewtCanvasSWTPosInTabs $* diff --git a/src/jogl/classes/com/jogamp/opengl/awt/GLCanvas.java b/src/jogl/classes/com/jogamp/opengl/awt/GLCanvas.java index 602671f6e..735a2a21c 100644 --- a/src/jogl/classes/com/jogamp/opengl/awt/GLCanvas.java +++ b/src/jogl/classes/com/jogamp/opengl/awt/GLCanvas.java @@ -1,6 +1,6 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2010 JogAmp Community. All rights reserved. + * Copyright (c) 2010-2023 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -175,10 +175,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing private volatile JAWTWindow jawtWindow; // the JAWTWindow presentation of this AWT Canvas, bound to the 'drawable' lifecycle private volatile GLContextImpl context; // volatile: avoid locking for read-only access private volatile boolean sendReshape = false; // volatile: maybe written by EDT w/o locking - private final float[] minPixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; - private final float[] maxPixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; private final float[] hasPixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; - final float[] reqPixelScale = new float[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE }; // copy of the cstr args, mainly for recreation private final GLCapabilitiesImmutable capsReqUser; @@ -564,9 +561,10 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing function properly. <P> <B>Overrides:</B> - <DL><DD><CODE>addNotify</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> */ - @SuppressWarnings("deprecation") - @Override + <DL><DD><CODE>addNotify</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> + */ + @SuppressWarnings("deprecation") + @Override public void addNotify() { final RecursiveLock _lock = lock; _lock.lock(); @@ -634,62 +632,51 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing } } + /** + * {@inheritDoc} + * <p> + * This implementation returns false, i.e. not supporting manual change of pixel-scale. + * </p> + */ @Override - public final boolean setSurfaceScale(final float[] pixelScale) { - System.arraycopy(pixelScale, 0, reqPixelScale, 0, 2); - if( isRealized() && isShowing ) { - Threading.invoke(true, setSurfaceScaleOnEDTAction, getTreeLock()); - return true; - } else { - return false; - } - } - private final Runnable setSurfaceScaleOnEDTAction = new Runnable() { - @Override - public void run() { - final RecursiveLock _lock = lock; - _lock.lock(); - try { - if( null != drawable && drawable.isRealized() ) { - if( setSurfaceScaleImpl(jawtWindow) ) { - reshapeImpl(getWidth(), getHeight()); - if( !helper.isAnimatorAnimatingOnOtherThread() ) { - helper.invokeGL(drawable, context, displayAction, initAction); // display - } - } - } - } finally { - _lock.unlock(); - } - } }; + public final boolean canSetSurfaceScale() { return false; } - private final boolean setSurfaceScaleImpl(final ScalableSurface ns) { - if(DEBUG) { - System.err.printf("GLCanvas.setSurfaceScaleImpl reqPixelScale %.2f %.2f, hasPixelScale %.2f %.2f\n", - reqPixelScale[0], reqPixelScale[1], hasPixelScale[0], hasPixelScale[1]); - } - - if( ns.setSurfaceScale(hasPixelScale) ) { - ns.getCurrentSurfaceScale(hasPixelScale); - return true; - } else { - return false; - } + /** + * {@inheritDoc} + * <p> + * Ignored for an AWT widget since pixelScale is dictated by AWT mechanisms. + * </p> + */ + @Override + public final boolean setSurfaceScale(final float[] pixelScale) { + return false; } private final boolean updatePixelScale() { if( jawtWindow.hasPixelScaleChanged() ) { - jawtWindow.getMaximumSurfaceScale(maxPixelScale); - jawtWindow.getMinimumSurfaceScale(minPixelScale); - return setSurfaceScaleImpl(jawtWindow); + if(DEBUG) { + final float[] old = { hasPixelScale[0], hasPixelScale[1] }; + jawtWindow.getCurrentSurfaceScale(hasPixelScale); + System.err.printf("GLCanvas.updatePixelScale hasPixelScale %.2f %.2f -> %.2f %.2f\n", old[0], old[1], hasPixelScale[0], hasPixelScale[1]); + } else { + jawtWindow.getCurrentSurfaceScale(hasPixelScale); + } + return true; } else { return false; } } + /** + * {@inheritDoc} + * <p> + * Returns {@link ScalableSurface#AUTOMAX_PIXELSCALE}, always. + * </p> + */ @Override public final float[] getRequestedSurfaceScale(final float[] result) { - System.arraycopy(reqPixelScale, 0, result, 0, 2); + result[0] = ScalableSurface.AUTOMAX_PIXELSCALE; + result[1] = ScalableSurface.AUTOMAX_PIXELSCALE; return result; } @@ -699,15 +686,28 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing return result; } + /** + * {@inheritDoc} + * <p> + * Returns 1.0, always. + * </p> + */ @Override public float[] getMinimumSurfaceScale(final float[] result) { - System.arraycopy(minPixelScale, 0, result, 0, 2); + result[0] = 1f; + result[1] = 1f; return result; } + /** + * {@inheritDoc} + * <p> + * Returns {@link #getCurrentSurfaceScale(float[])}. + * </p> + */ @Override public float[] getMaximumSurfaceScale(final float[] result) { - System.arraycopy(maxPixelScale, 0, result, 0, 2); + System.arraycopy(hasPixelScale, 0, result, 0, 2); return result; } @@ -723,12 +723,9 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing jawtWindow.setShallUseOffscreenLayer(shallUseOffscreenLayer); jawtWindow.lockSurface(); try { - jawtWindow.setSurfaceScale(reqPixelScale); drawable = (GLDrawableImpl) GLDrawableFactory.getFactory(capsReqUser.getGLProfile()).createGLDrawable(jawtWindow); createContextImpl(drawable); jawtWindow.getCurrentSurfaceScale(hasPixelScale); - jawtWindow.getMinimumSurfaceScale(minPixelScale); - jawtWindow.getMaximumSurfaceScale(maxPixelScale); } finally { jawtWindow.unlockSurface(); } @@ -1388,10 +1385,6 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing } hasPixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE; hasPixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE; - minPixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE; - minPixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE; - maxPixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE; - maxPixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE; if(null != awtConfig) { final AbstractGraphicsConfiguration aconfig = awtConfig.getNativeGraphicsConfiguration(); diff --git a/src/jogl/classes/com/jogamp/opengl/awt/GLJPanel.java b/src/jogl/classes/com/jogamp/opengl/awt/GLJPanel.java index 20dc71958..fb0df6aaf 100644 --- a/src/jogl/classes/com/jogamp/opengl/awt/GLJPanel.java +++ b/src/jogl/classes/com/jogamp/opengl/awt/GLJPanel.java @@ -1,6 +1,6 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2010 JogAmp Community. All rights reserved. + * Copyright (c) 2010-2023 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -263,10 +263,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing private boolean handleReshape = false; private boolean sendReshape = true; - private final float[] minPixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; - private final float[] maxPixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; private final float[] hasPixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; - private final float[] reqPixelScale = new float[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE }; /** For handling reshape events lazily: reshapeWidth -> panelWidth -> backend.width in pixel units (scaled) */ private int reshapeWidth; @@ -397,6 +394,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing public final boolean initializeBackend(final boolean offthread) { if( offthread ) { new InterruptSource.Thread(null, null, getThreadName()+"-GLJPanel_Init") { + @Override public void run() { if( !isInitialized ) { initializeBackendImpl(); @@ -581,59 +579,52 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing } } + /** + * {@inheritDoc} + * <p> + * This implementation returns false, i.e. not supporting manual change of pixel-scale. + * </p> + */ @Override - public final boolean setSurfaceScale(final float[] pixelScale) { // HiDPI support - System.arraycopy(pixelScale, 0, reqPixelScale, 0, 2); - final Backend b = backend; - if ( isInitialized && null != b && isShowing ) { - if( isShowing || ( printActive && isVisible() ) ) { - if (EventQueue.isDispatchThread()) { - setSurfaceScaleAction.run(); - } else { - try { - EventQueue.invokeAndWait(setSurfaceScaleAction); - } catch (final Exception e) { - throw new GLException(e); - } - } - } - return true; - } else { - return false; - } - } - private final Runnable setSurfaceScaleAction = new Runnable() { - @Override - public void run() { - final Backend b = backend; - if( null != b && setSurfaceScaleImpl(b) ) { - if( !helper.isAnimatorAnimatingOnOtherThread() ) { - paintImmediatelyAction.run(); // display - } - } - } - }; + public final boolean canSetSurfaceScale() { return false; } - private final boolean setSurfaceScaleImpl(final Backend b) { - if( SurfaceScaleUtils.setNewPixelScale(hasPixelScale, hasPixelScale, reqPixelScale, minPixelScale, maxPixelScale, DEBUG ? getClass().getSimpleName() : null) ) { - reshapeImpl(getWidth(), getHeight()); - updateWrappedSurfaceScale(b.getDrawable()); - return true; - } + /** + * {@inheritDoc} + * <p> + * Ignored for an AWT widget since pixelScale is dictated by AWT mechanisms. + * </p> + */ + @Override + public final boolean setSurfaceScale(final float[] pixelScale) { // HiDPI support return false; } private final boolean updatePixelScale(final Backend b) { - if( JAWTUtil.getPixelScale(getGraphicsConfiguration(), minPixelScale, maxPixelScale) ) { - return setSurfaceScaleImpl(b); - } else { - return false; - } + final float[] min = { 1, 1 }; + final float[] max = { hasPixelScale[0], hasPixelScale[1] }; + if( JAWTUtil.getPixelScale(getGraphicsConfiguration(), min, max) ) { + if( DEBUG ) { + System.err.printf("GLJPanel.updatePixelScale %.2f %.2f -> %.2f %.2f\n", hasPixelScale[0], hasPixelScale[1], max[0], max[1]); + } + System.arraycopy(max, 0, hasPixelScale, 0, 2); + reshapeImpl(getWidth(), getHeight()); + updateWrappedSurfaceScale(b.getDrawable()); + return true; + } else { + return false; + } } + /** + * {@inheritDoc} + * <p> + * Returns {@link ScalableSurface#AUTOMAX_PIXELSCALE}, always. + * </p> + */ @Override public final float[] getRequestedSurfaceScale(final float[] result) { - System.arraycopy(reqPixelScale, 0, result, 0, 2); + result[0] = ScalableSurface.AUTOMAX_PIXELSCALE; + result[1] = ScalableSurface.AUTOMAX_PIXELSCALE; return result; } @@ -643,15 +634,28 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing return result; } + /** + * {@inheritDoc} + * <p> + * Returns 1.0, always. + * </p> + */ @Override public float[] getMinimumSurfaceScale(final float[] result) { - System.arraycopy(minPixelScale, 0, result, 0, 2); + result[0] = 1f; + result[1] = 1f; return result; } + /** + * {@inheritDoc} + * <p> + * Returns {@link #getCurrentSurfaceScale(float[])}. + * </p> + */ @Override public float[] getMaximumSurfaceScale(final float[] result) { - System.arraycopy(maxPixelScale, 0, result, 0, 2); + System.arraycopy(hasPixelScale, 0, result, 0, 2); return result; } @@ -667,8 +671,17 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing awtWindowClosingProtocol.addClosingListener(); // HiDPI support - JAWTUtil.getPixelScale(getGraphicsConfiguration(), minPixelScale, maxPixelScale); - SurfaceScaleUtils.setNewPixelScale(hasPixelScale, hasPixelScale, reqPixelScale, minPixelScale, maxPixelScale, DEBUG ? getClass().getSimpleName() : null); + { + final float[] min = { 1, 1 }; + final float[] max = { hasPixelScale[0], hasPixelScale[1] }; + if( JAWTUtil.getPixelScale(getGraphicsConfiguration(), min, max) ) { + if( DEBUG ) { + System.err.printf("GLJPanel.addNotify: pixelScale %.2f %.2f -> %.2f %.2f\n", hasPixelScale[0], hasPixelScale[1], max[0], max[1]); + } + System.arraycopy(max, 0, hasPixelScale, 0, 2); + reshapeImpl(getWidth(), getHeight()); + } + } if (DEBUG) { System.err.println(getThreadName()+": GLJPanel.addNotify()"); @@ -688,10 +701,6 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing dispose(null); hasPixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE; hasPixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE; - minPixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE; - minPixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE; - maxPixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE; - maxPixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE; super.removeNotify(); } @@ -1345,7 +1354,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing if( !isInitialized ) { if( handleReshape ) { if (DEBUG) { - System.err.println(getThreadName()+": GLJPanel.createAndInitializeBackend.1: ["+(printActive?"printing":"paint")+"] "+ + System.err.println(getThreadName()+": GLJPanel.initializeBackendImpl.1: ["+(printActive?"printing":"paint")+"] "+ panelWidth+"x"+panelHeight+" @ scale "+getPixelScaleStr() + " -> " + reshapeWidth+"x"+reshapeHeight+" @ scale "+getPixelScaleStr()); } @@ -1354,7 +1363,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing handleReshape = false; } else { if (DEBUG) { - System.err.println(getThreadName()+": GLJPanel.createAndInitializeBackend.0: ["+(printActive?"printing":"paint")+"] "+ + System.err.println(getThreadName()+": GLJPanel.initializeBackendImpl.0: ["+(printActive?"printing":"paint")+"] "+ panelWidth+"x"+panelHeight+" @ scale "+getPixelScaleStr()); } } diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/ScalableSurface.java b/src/nativewindow/classes/com/jogamp/nativewindow/ScalableSurface.java index eea9e4bed..ec584f3be 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/ScalableSurface.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/ScalableSurface.java @@ -1,5 +1,5 @@ /** - * Copyright 2014 JogAmp Community. All rights reserved. + * Copyright 2014-2023 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: @@ -39,12 +39,25 @@ public interface ScalableSurface { public static final float AUTOMAX_PIXELSCALE = 0f; /** + * Returns true if {@link #setSurfaceScale(float[])} is supported, otherwise false. + * <p> + * For pure downstream scalable surfaces like AWT widgets, + * setting the picel scale is not supported since the pixel scale is set by the underlying toolkit. + * </p> + */ + public boolean canSetSurfaceScale(); + + /** * Request a pixel scale in x- and y-direction for the associated {@link NativeSurface}, * where {@code size_in_pixel_units = pixel_scale * size_in_window_units}. * <p> * Default pixel scale request for both directions is {@link #AUTOMAX_PIXELSCALE}. * </p> * <p> + * If {@link #canSetSurfaceScale()} returns false, requested pixel scale is {@link #AUTOMAX_PIXELSCALE}, + * immutable and method returns false. + * </p> + * <p> * In case platform only supports uniform pixel scale, i.e. one scale for both directions, * either {@link #AUTOMAX_PIXELSCALE} or the maximum requested pixel scale component is used. * </p> @@ -61,15 +74,20 @@ public interface ScalableSurface { * @param pixelScale <i>requested</i> surface pixel scale float[2] values for x- and y-direction. * @return {@code true} if the {@link #getCurrentSurfaceScale(float[]) current pixel scale} has changed, otherwise {@code false}. * @see #getRequestedSurfaceScale(float[]) + * @see #canSetSurfaceScale() */ public boolean setSurfaceScale(final float[] pixelScale); /** * Returns the {@link #setSurfaceScale(float[]) requested} pixel scale of the associated {@link NativeSurface}. + * <p> + * If {@link #canSetSurfaceScale()} returns false, requested pixel scale is {@link #AUTOMAX_PIXELSCALE} and immutable. + * </p> * * @param result float[2] storage for the result * @return the passed storage containing the current pixelScale for chaining * @see #setSurfaceScale(float[]) + * @see #canSetSurfaceScale() */ public float[] getRequestedSurfaceScale(final float[] result); diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java index 78cb58b8d..f7d4761fe 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java @@ -1,6 +1,6 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2010 JogAmp Community. All rights reserved. + * Copyright (c) 2010-2023 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -102,10 +102,7 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, protected Insets insets; private volatile long offscreenSurfaceLayer; - private final float[] minPixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; - private final float[] maxPixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; private final float[] hasPixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; - private final float[] reqPixelScale = new float[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE }; private volatile boolean hasPixelScaleChanged = false; private long drawable_old; @@ -283,10 +280,6 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, insets = new Insets(); hasPixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE; hasPixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE; - minPixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE; - minPixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE; - maxPixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE; - maxPixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE; hasPixelScaleChanged = false; } protected abstract void invalidateNative(final long _offscreenSurfaceLayer); @@ -322,15 +315,36 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, return awtConfig; } + /** + * {@inheritDoc} + * <p> + * This implementation returns false, i.e. not supporting manual change of pixel-scale. + * </p> + */ + @Override + public final boolean canSetSurfaceScale() { return false; } + + /** + * {@inheritDoc} + * <p> + * Ignored for an AWT widget since pixelScale is dictated by AWT mechanisms. + * </p> + */ @Override public boolean setSurfaceScale(final float[] pixelScale) { - System.arraycopy(pixelScale, 0, reqPixelScale, 0, 2); return false; } + /** + * {@inheritDoc} + * <p> + * Returns {@link ScalableSurface#AUTOMAX_PIXELSCALE}, always. + * </p> + */ @Override public final float[] getRequestedSurfaceScale(final float[] result) { - System.arraycopy(reqPixelScale, 0, result, 0, 2); + result[0] = ScalableSurface.AUTOMAX_PIXELSCALE; + result[1] = ScalableSurface.AUTOMAX_PIXELSCALE; return result; } @@ -340,15 +354,28 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, return result; } + /** + * {@inheritDoc} + * <p> + * Returns 1.0, always. + * </p> + */ @Override public float[] getMinimumSurfaceScale(final float[] result) { - System.arraycopy(minPixelScale, 0, result, 0, 2); + result[0] = 1f; + result[1] = 1f; return result; } + /** + * {@inheritDoc} + * <p> + * Returns {@link #getCurrentSurfaceScale(float[])}. + * </p> + */ @Override public final float[] getMaximumSurfaceScale(final float[] result) { - System.arraycopy(maxPixelScale, 0, result, 0, 2); + System.arraycopy(hasPixelScale, 0, result, 0, 2); return result; } @@ -390,17 +417,15 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, * @see Component#getGraphicsConfiguration() */ public final boolean updatePixelScale(final GraphicsConfiguration gc, final boolean clearFlag) { - if( JAWTUtil.getPixelScale(gc, minPixelScale, maxPixelScale) ) { + final float[] min = { 1, 1 }; + final float[] max = { hasPixelScale[0], hasPixelScale[1] }; + if( JAWTUtil.getPixelScale(gc, min, max) ) { // Enforce maxPixelScale as used by AWT - hasPixelScaleChanged = true; - System.arraycopy(maxPixelScale, 0, hasPixelScale, 0, 2); if( DEBUG ) { - System.err.println("JAWTWindow.updatePixelScale: updated req["+ - reqPixelScale[0]+", "+reqPixelScale[1]+"], min["+ - minPixelScale[0]+", "+minPixelScale[1]+"], max["+ - maxPixelScale[0]+", "+maxPixelScale[1]+"], has["+ - hasPixelScale[0]+", "+hasPixelScale[1]+"]"); + System.err.println("JAWTWindow.updatePixelScale: ["+hasPixelScale[0]+", "+hasPixelScale[1]+"] -> ["+max[0]+", "+max[1]+"]"); } + hasPixelScaleChanged = true; + System.arraycopy(max, 0, hasPixelScale, 0, 2); } if( clearFlag ) { final boolean r = hasPixelScaleChanged; @@ -428,15 +453,6 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, return v; } - /** - * set requested pixelScale - * @return true if pixelScale has changed, otherwise false - */ - protected final boolean setReqPixelScale() { - updatePixelScale(awtConfig.getAWTGraphicsConfiguration(), true); - return SurfaceScaleUtils.setNewPixelScale(hasPixelScale, hasPixelScale, reqPixelScale, minPixelScale, maxPixelScale, DEBUG ? getClass().getSimpleName() : null); - } - /** @return the JAWT_DrawingSurfaceInfo's (JAWT_Rectangle) bounds in pixel units, updated with lock */ public final RectangleImmutable getJAWTSurfaceBounds() { return jawt_surface_bounds; } diff --git a/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java b/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java index 769041f10..093625cb3 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java +++ b/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java @@ -1,5 +1,5 @@ /** - * Copyright 2010 JogAmp Community. All rights reserved. + * Copyright 2010-2023 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: @@ -132,6 +132,15 @@ public class WrappedSurface extends ProxySurfaceImpl implements ScalableSurface /** * {@inheritDoc} * <p> + * This implementation returns false, i.e. not supporting manual change of pixel-scale. + * </p> + */ + @Override + public final boolean canSetSurfaceScale() { return false; } + + /** + * {@inheritDoc} + * <p> * {@link WrappedSurface}'s implementation is to simply pass the given pixelScale * from the caller <i>down</i> to this instance without validation to be applied in the {@link #convertToPixelUnits(int[]) conversion} {@link #convertToWindowUnits(int[]) methods} <b>only</b>.<br/> * This allows the caller to pass down knowledge about window- and pixel-unit conversion and utilize mentioned conversion methods. diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java index 40fb48f33..ffd75f038 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java @@ -125,27 +125,6 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface { } @Override - public boolean setSurfaceScale(final float[] pixelScale) { - super.setSurfaceScale(pixelScale); - if( 0 != getWindowHandle() && setReqPixelScale() ) { // locked at least once _and_ updated pixel-scale - if( 0 != getAttachedSurfaceLayer() ) { - OSXUtil.RunOnMainThread(false /* wait */, false, new Runnable() { - @Override - public void run() { - final long osl = getAttachedSurfaceLayer(); - if( 0 != rootSurfaceLayer && 0 != osl ) { - OSXUtil.SetCALayerPixelScale(rootSurfaceLayer, osl, getPixelScaleX()); - } - } - }); - } - return true; - } else { - return false; - } - } - - @Override protected void attachSurfaceLayerImpl(final long _offscreenSurfaceLayer) { OSXUtil.RunOnMainThread(false /* wait */, false /* kickNSApp */, new Runnable() { @Override diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java index 60ed53c9f..47c03557e 100644 --- a/src/newt/classes/com/jogamp/newt/Window.java +++ b/src/newt/classes/com/jogamp/newt/Window.java @@ -1,5 +1,5 @@ /** - * Copyright 2010 JogAmp Community. All rights reserved. + * Copyright 2010-2023 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index 1435aa20a..cbac22e26 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -482,6 +482,15 @@ public class GLWindow extends GLAutoDrawableBase implements GLAutoDrawable, Wind return window.convertToPixelUnits(windowUnitsAndResult); } + /** + * {@inheritDoc} + * <p> + * This implementation returns true, i.e. supporting manual change of pixel-scale. + * </p> + */ + @Override + public final boolean canSetSurfaceScale() { return true; } + @Override public final boolean setSurfaceScale(final float[] pixelScale) { return window.setSurfaceScale(pixelScale); diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index 0a8bc0e63..a19218ead 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -2696,6 +2696,15 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer /** * {@inheritDoc} + * <p> + * This implementation returns true, i.e. supporting manual change of pixel-scale. + * </p> + */ + @Override + public final boolean canSetSurfaceScale() { return true; } + + /** + * {@inheritDoc} */ @Override public boolean setSurfaceScale(final float[] pixelScale) { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestGLCanvasResize01AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestGLCanvasResize01AWT.java new file mode 100644 index 000000000..349d985c8 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestGLCanvasResize01AWT.java @@ -0,0 +1,207 @@ +/** + * Copyright 2013-2023 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package com.jogamp.opengl.test.junit.jogl.awt; + +import java.awt.Dimension; +import java.lang.reflect.InvocationTargetException; + +import com.jogamp.opengl.GLCapabilities; +import com.jogamp.opengl.GLCapabilitiesImmutable; +import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.awt.GLCanvas; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; + +import org.junit.Assume; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.util.UITestCase; + +/** + * Multiple GLCanvas in a JFrame + */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestGLCanvasResize01AWT extends UITestCase { + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(); + } + + static Dimension[] esize00 = { + new Dimension(281, 151), + new Dimension(282, 151), + new Dimension(283, 151), + new Dimension(284, 151), + + new Dimension(284, 152), + new Dimension(283, 152), + new Dimension(282, 152), + new Dimension(281, 152), + + new Dimension(291, 153), + new Dimension(292, 153), + new Dimension(293, 153), + new Dimension(294, 153), + + new Dimension(281, 154), + new Dimension(282, 154), + new Dimension(283, 154), + new Dimension(284, 154) + }; + static Dimension[] esize01 = { + new Dimension(283, 154), // #3: new sub-aligned image in pixelBuffer-1 + new Dimension(291, 154), // #2: new pixelBuffer-1 + new Dimension(282, 154), // #1: new pixelBuffer-0 + }; + static Dimension[] esize02 = { + new Dimension(291, 154), // #2: new pixelBuffer-1 + new Dimension(282, 154), // #1: new pixelBuffer-0 + }; + + public void test(final GLCapabilitiesImmutable caps, final Dimension[] dims) { + final int cols = 4; + final int rows = dims.length / cols + ( dims.length % cols > 0 ? 1 : 0 ); + final JFrame[] frame = new JFrame[] { null }; + + System.err.println("Frame size: cols x rows "+cols+"x"+rows); + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + frame[0] = new JFrame(); + frame[0].setLocation(64, 64); + final JPanel panel = new JPanel(); + panel.setLayout(null); // new BorderLayout()); + panel.setDoubleBuffered(false); + frame[0].getContentPane().add(panel); + + final int x0 = 4; + int x = x0, y = 4; + int maxRowWidth = 0; + for(int i=0; i<rows; i++) { + int maxColHeight = 0; + for(int j=0; j<cols; j++) { + final int idx = i*cols+j; + if( idx >= dims.length ) { break; } + final Dimension d = dims[idx]; + if( d.height > maxColHeight ) { + maxColHeight = d.height; + } + final GLCanvas glad = createGLJPanel(caps, d, "[r "+i+", c "+j+"]"); + panel.add(glad); + glad.setLocation(x, y); + x+=d.width+4; + } + if( x > maxRowWidth ) { + maxRowWidth = x; + } + x = x0; + y += maxColHeight+4; + } + frame[0].setSize(maxRowWidth+4+64, y+4+64); + // frame[0].pack(); + frame[0].setVisible(true); + } } ); + } catch( final Throwable throwable ) { + throwable.printStackTrace(); + Assume.assumeNoException( throwable ); + } + try { + Thread.sleep(duration); + } catch (final InterruptedException e1) { + e1.printStackTrace(); + } + try { + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + frame[0].dispose(); + } } ); + } catch (final Exception e1) { + e1.printStackTrace(); + } + } + + private GLCanvas createGLJPanel(final GLCapabilitiesImmutable caps, final Dimension size, final String name) { + final GLCanvas canvas = new GLCanvas(caps); + canvas.setName(name); + canvas.setSize(size); + canvas.setPreferredSize(size); + canvas.setMinimumSize(size); + final GearsES2 g = new GearsES2(0); + canvas.addGLEventListener(g); + return canvas; + } + + static GLCapabilitiesImmutable caps = null; + + // @Test + public void test00() throws InterruptedException, InvocationTargetException { + test(new GLCapabilities(null), esize00); + } + + @Test + public void test01() throws InterruptedException, InvocationTargetException { + test(new GLCapabilities(null), esize01); + } + + @Test + public void test02() throws InterruptedException, InvocationTargetException { + test(new GLCapabilities(null), esize02); + } + + static long duration = 600; // ms + + public static void main(final String[] args) { + boolean manual=false; + + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + duration = MiscUtils.atol(args[i], duration); + } else if(args[i].equals("-manual")) { + manual = true; + } + } + if( manual ) { + GLProfile.initSingleton(); + final TestGLCanvasResize01AWT demo = new TestGLCanvasResize01AWT(); + demo.test(new GLCapabilities(null), esize01); + } else { + org.junit.runner.JUnitCore.main(TestGLCanvasResize01AWT.class.getName()); + } + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestGLJPanelResize01AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestGLJPanelResize01AWT.java index 00960d4dd..ea25891f5 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestGLJPanelResize01AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestGLJPanelResize01AWT.java @@ -1,5 +1,5 @@ /** - * Copyright 2013 JogAmp Community. All rights reserved. + * Copyright 2013-2023 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: @@ -98,6 +98,7 @@ public class TestGLJPanelResize01AWT extends UITestCase { System.err.println("Frame size: cols x rows "+cols+"x"+rows); try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { frame[0] = new JFrame(); frame[0].setLocation(64, 64); @@ -144,6 +145,7 @@ public class TestGLJPanelResize01AWT extends UITestCase { } try { SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { frame[0].dispose(); } } ); @@ -160,7 +162,7 @@ public class TestGLJPanelResize01AWT extends UITestCase { canvas.setMinimumSize(size); canvas.setDoubleBuffered(useSwingDoubleBuffer); final GearsES2 g = new GearsES2(0); - g.setVerbose(false); + // g.setVerbose(false); canvas.addGLEventListener(g); return canvas; } |