summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/javax/media
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-05-20 21:01:21 +0200
committerSven Gothel <[email protected]>2014-05-20 21:01:21 +0200
commit0ffba122ea5c4b8cc247234ca9f48ccfcce833cd (patch)
treedce8b10163710522cd73da8975e63fbb8a189e98 /src/jogl/classes/javax/media
parent83be0fa0ffe96c1acbc232965c2c03f40768184d (diff)
Bug 742 HiDPI: Add prelim HiDPI support to GLJPanel w/o API change and w/o fixing AWTPrintLifecycle DPI evaluation
We also have to re-validating AWTPrintLifecycle's DPI semantics, since we currently are based on pixel dimension w/ 72 dpi!
Diffstat (limited to 'src/jogl/classes/javax/media')
-rw-r--r--src/jogl/classes/javax/media/opengl/awt/GLJPanel.java66
1 files changed, 49 insertions, 17 deletions
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
index fbd923a3b..8bcf97ba1 100644
--- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
+++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
@@ -83,6 +83,7 @@ import javax.media.opengl.GLSharedContextSetter;
import javax.media.opengl.Threading;
import javax.swing.JPanel;
+import jogamp.nativewindow.jawt.JAWTUtil;
import jogamp.opengl.Debug;
import jogamp.opengl.GLContextImpl;
import jogamp.opengl.GLDrawableFactoryImpl;
@@ -174,6 +175,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
private static final boolean USE_GLSL_TEXTURE_RASTERIZER;
private static final boolean SKIP_VERTICAL_FLIP_DEFAULT;
+ private static final boolean SKIP_HIDPI;
+
/** Indicates whether the Java 2D OpenGL pipeline is requested by user. */
private static final boolean java2dOGLEnabledByProp;
@@ -189,6 +192,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
DEBUG_VIEWPORT = Debug.isPropertyDefined("jogl.debug.GLJPanel.Viewport", true);
USE_GLSL_TEXTURE_RASTERIZER = !Debug.isPropertyDefined("jogl.gljpanel.noglsl", true);
SKIP_VERTICAL_FLIP_DEFAULT = Debug.isPropertyDefined("jogl.gljpanel.noverticalflip", true);
+ SKIP_HIDPI = Debug.isPropertyDefined("jogl.gljpanel.nohidpi", true);
boolean enabled = Debug.getBooleanProperty("sun.java2d.opengl", false);
java2dOGLEnabledByProp = enabled && !Debug.isPropertyDefined("jogl.gljpanel.noogl", true);
@@ -246,10 +250,12 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
// For handling reshape events lazily: reshapeWidth -> panelWidth -> backend.width
private int reshapeWidth;
private int reshapeHeight;
+ private int reshapeScale;
// Width of the actual GLJPanel: reshapeWidth -> panelWidth -> backend.width
private int panelWidth = 0;
private int panelHeight = 0;
+ private int panelScale = 0;
// These are always set to (0, 0) except when the Java2D / OpenGL
// pipeline is active
@@ -588,15 +594,20 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
public void reshape(int x, int y, int width, int height) {
super.reshape(x, y, width, height);
+ final int scale = getPixelScale();
+ final int scaledWidth = scale * width;
+ final int scaledHeight = scale * height;
if( DEBUG ) {
- System.err.println(getThreadName()+": GLJPanel.reshape.0 "+this.getName()+" resize"+(printActive?"WithinPrint":"")+" [ this "+getWidth()+"x"+getHeight()+", panel "+
- panelWidth+"x"+panelHeight +
+ System.err.println(getThreadName()+": GLJPanel.reshape.0 "+this.getName()+" resize"+(printActive?"WithinPrint":"")+
+ " [ this "+getWidth()+"x"+getHeight()+", pixelScale "+scale+
+ ", panel "+panelWidth+"x"+panelHeight +
", reshape: " +reshapeWidth+"x"+reshapeHeight +
- "] -> "+(printActive?"skipped":"") + width+"x"+height);
+ "] -> "+(printActive?"[skipped] ":"") + width+"x"+height+" * "+scale+" -> "+scaledWidth+"x"+scaledHeight);
}
if( !printActive ) {
- reshapeWidth = width;
- reshapeHeight = height;
+ reshapeWidth = scaledWidth;
+ reshapeHeight = scaledHeight;
+ reshapeScale = scale;
handleReshape = true;
}
}
@@ -711,17 +722,21 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
// trigger reshape, i.e. gl-viewport and -listener - this component might got resized!
final int awtWidth = GLJPanel.this.getWidth();
final int awtHeight= GLJPanel.this.getHeight();
+ final int scale = getPixelScale();
+ final int scaledAWTWidth = scale * awtWidth;
+ final int scaledAWTHeight= scale * awtHeight;
final GLDrawable drawable = GLJPanel.this.getDelegatedDrawable();
- if( awtWidth != panelWidth || awtHeight != panelHeight ||
+ if( scaledAWTWidth != panelWidth || scaledAWTHeight != panelHeight ||
drawable.getWidth() != panelWidth || drawable.getHeight() != panelHeight ) {
// -> !( awtSize == panelSize == drawableSize )
if ( DEBUG ) {
- System.err.println(getThreadName()+": GLJPanel.releasePrintOnEDT.0: resizeWithinPrint panel " +panelWidth+"x"+panelHeight +
+ System.err.println(getThreadName()+": GLJPanel.releasePrintOnEDT.0: resizeWithinPrint panel " +panelWidth+"x"+panelHeight + " @ scale "+panelScale+
", draw "+drawable.getWidth()+"x"+drawable.getHeight()+
- " -> " + awtWidth+"x"+awtHeight);
+ " -> " + awtWidth+"x"+awtHeight+" * "+scale+" -> "+scaledAWTWidth+"x"+scaledAWTHeight);
}
- reshapeWidth = awtWidth;
- reshapeHeight = awtHeight;
+ reshapeWidth = scaledAWTWidth;
+ reshapeHeight = scaledAWTHeight;
+ reshapeScale = scale;
sendReshape = handleReshape(); // reshapeSize -> panelSize, backend reshape w/ GL reshape
} else {
sendReshape = true; // only GL reshape
@@ -1126,13 +1141,16 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
}
if (DEBUG) {
- System.err.println(getThreadName()+": GLJPanel.createAndInitializeBackend: " +panelWidth+"x"+panelHeight + " -> " + reshapeWidth+"x"+reshapeHeight);
+ System.err.println(getThreadName()+": GLJPanel.createAndInitializeBackend: " +
+ panelWidth+"x"+panelHeight+" @ scale "+panelScale + " -> " +
+ reshapeWidth+"x"+reshapeHeight+" @ scale "+reshapeScale);
}
// Pull down reshapeWidth and reshapeHeight into panelWidth and
// panelHeight eagerly in order to complete initialization, and
// force a reshape later
panelWidth = reshapeWidth;
panelHeight = reshapeHeight;
+ panelScale = reshapeScale;
}
if ( null == backend ) {
@@ -1154,6 +1172,15 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
}
}
+ protected final int getPixelScale() {
+ if( SKIP_HIDPI ) {
+ return 1;
+ } else {
+ final int s = JAWTUtil.getPixelScale(this);
+ return 0 < s ? s : 1;
+ }
+ }
+
@Override
public WindowClosingMode getDefaultCloseOperation() {
return awtWindowClosingProtocol.getDefaultCloseOperation();
@@ -1166,10 +1193,13 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
private boolean handleReshape() {
if (DEBUG) {
- System.err.println(getThreadName()+": GLJPanel.handleReshape: " +panelWidth+"x"+panelHeight + " -> " + reshapeWidth+"x"+reshapeHeight);
+ System.err.println(getThreadName()+": GLJPanel.handleReshape: "+
+ panelWidth+"x"+panelHeight+" @ scale "+panelScale + " -> " +
+ reshapeWidth+"x"+reshapeHeight+" @ scale "+reshapeScale);
}
panelWidth = reshapeWidth;
panelHeight = reshapeHeight;
+ panelScale = reshapeScale;
return backend.handleReshape();
}
@@ -1204,7 +1234,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
}
if (sendReshape) {
if (DEBUG) {
- System.err.println(getThreadName()+": GLJPanel.display: reshape(" + viewportX + "," + viewportY + " " + panelWidth + "x" + panelHeight + ")");
+ System.err.println(getThreadName()+": GLJPanel.display: reshape(" + viewportX + "," + viewportY + " " + panelWidth + "x" + panelHeight + " @ scale "+panelScale+")");
}
helper.reshape(GLJPanel.this, viewportX, viewportY, panelWidth, panelHeight);
sendReshape = false;
@@ -1403,6 +1433,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
private final boolean useSingletonBuffer;
private AWTGLPixelBuffer pixelBuffer;
private BufferedImage alignedImage;
+ private int alignedImageScale;
// One of these is used to store the read back pixels before storing
// in the BufferedImage
@@ -1643,7 +1674,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.postGL.0: "+GLJPanel.this.getName()+" pixelBufferProvider isSingletonBufferProvider "+useSingletonBuffer+", 0x"+Integer.toHexString(pixelBufferProvider.hashCode())+", "+pixelBufferProvider.getClass().getSimpleName());
System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.postGL.0: "+GLJPanel.this.getName()+" pixelBuffer 0x"+Integer.toHexString(pixelBuffer.hashCode())+", "+pixelBuffer+", alignment "+alignment);
System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.postGL.0: "+GLJPanel.this.getName()+" flippedVertical "+flipVertical+", glslTextureRaster "+(null!=glslTextureRaster));
- System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.postGL.0: "+GLJPanel.this.getName()+" panelSize "+panelWidth+"x"+panelHeight);
+ System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.postGL.0: "+GLJPanel.this.getName()+" panelSize "+panelWidth+"x"+panelHeight+" @ scale "+panelScale);
}
}
if( offscreenDrawable.getWidth() != panelWidth || offscreenDrawable.getHeight() != panelHeight ) {
@@ -1653,8 +1684,9 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
panelWidth != alignedImage.getWidth() || panelHeight != alignedImage.getHeight() ||
!pixelBuffer.isDataBufferSource(alignedImage) ) {
alignedImage = pixelBuffer.getAlignedImage(panelWidth, panelHeight);
+ alignedImageScale = panelScale;
if(DEBUG) {
- System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.postGL.0: "+GLJPanel.this.getName()+" new alignedImage "+alignedImage.getWidth()+"x"+alignedImage.getHeight()+", "+alignedImage+", pixelBuffer "+pixelBuffer.width+"x"+pixelBuffer.height+", "+pixelBuffer);
+ System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.postGL.0: "+GLJPanel.this.getName()+" new alignedImage "+alignedImage.getWidth()+"x"+alignedImage.getHeight()+" @ scale "+alignedImageScale+", "+alignedImage+", pixelBuffer "+pixelBuffer.width+"x"+pixelBuffer.height+", "+pixelBuffer);
}
}
final IntBuffer readBackInts;
@@ -1781,7 +1813,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.doPaintComponent.drawImage: - frameCount "+frameCount);
}
// Draw resulting image in one shot
- g.drawImage(alignedImage, 0, 0, alignedImage.getWidth(), alignedImage.getHeight(), null); // Null ImageObserver since image data is ready.
+ g.drawImage(alignedImage, 0, 0, alignedImage.getWidth()/alignedImageScale, alignedImage.getHeight()/alignedImageScale, null); // Null ImageObserver since image data is ready.
}
frameCount++;
}
@@ -1803,7 +1835,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
}
}
if (DEBUG) {
- System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.handleReshape: " +panelWidth+"x"+panelHeight + " -> " + _drawable.getWidth()+"x"+_drawable.getHeight());
+ System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.handleReshape: " +panelWidth+"x"+panelHeight + " @ scale "+panelScale + " -> " + _drawable.getWidth()+"x"+_drawable.getHeight());
}
panelWidth = _drawable.getWidth();
panelHeight = _drawable.getHeight();