aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/awt/GLJPanel.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-05-15 06:47:22 +0200
committerSven Gothel <[email protected]>2023-05-15 06:47:22 +0200
commit900c35c6a49e0d53e38dd07da709bf81e28abd3e (patch)
tree97a10ef8c5e0609f66545f19a0b370e183af132f /src/jogl/classes/com/jogamp/opengl/awt/GLJPanel.java
parentcc5e46d8096a9395246518ad413385167f5f8eee (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/classes/com/jogamp/opengl/awt/GLJPanel.java')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/awt/GLJPanel.java123
1 files changed, 66 insertions, 57 deletions
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());
}
}