diff options
author | Sven Gothel <[email protected]> | 2023-05-15 06:47:22 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-05-15 06:47:22 +0200 |
commit | 900c35c6a49e0d53e38dd07da709bf81e28abd3e (patch) | |
tree | 97a10ef8c5e0609f66545f19a0b370e183af132f /src/jogl | |
parent | cc5e46d8096a9395246518ad413385167f5f8eee (diff) |
HiDPI: Revise AWT GLCanvas/GLJPanel ScalableSurface: No setSurfaceScale(), have AWT toolkit define pixelScale only (simplification)
This aligns with Glenn's initial AWT patch commit e5e7514d649cd7dd28bbb8e04b72338dc09c2c83, i.e. removing redundancies...
Tested on Linux, Windows and MacOS w/ GLCanvas, GLJPanel and GLWindow using pixelScale values:
- Linux: 1, 2
- Windows: 1, 1.25, 2
- MacOS: 1, 2
Diffstat (limited to 'src/jogl')
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/awt/GLCanvas.java | 111 | ||||
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/awt/GLJPanel.java | 123 |
2 files changed, 118 insertions, 116 deletions
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()); } } |