diff options
-rw-r--r-- | src/main/java/org/jogamp/java3d/Canvas3D.java | 32 | ||||
-rw-r--r-- | src/main/java/org/jogamp/java3d/CanvasViewCache.java | 8 | ||||
-rw-r--r-- | src/main/java/org/jogamp/java3d/J3DGraphics2DImpl.java | 8 |
3 files changed, 46 insertions, 2 deletions
diff --git a/src/main/java/org/jogamp/java3d/Canvas3D.java b/src/main/java/org/jogamp/java3d/Canvas3D.java index c678631..55dbab9 100644 --- a/src/main/java/org/jogamp/java3d/Canvas3D.java +++ b/src/main/java/org/jogamp/java3d/Canvas3D.java @@ -38,6 +38,7 @@ import java.awt.GraphicsEnvironment; import java.awt.IllegalComponentStateException; import java.awt.Point; import java.awt.Window; +import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.Hashtable; @@ -1577,6 +1578,13 @@ ArrayList<TextureRetained> textureIDResourceTable = new ArrayList<TextureRetaine if (graphics2D == null) graphics2D = new J3DGraphics2DImpl(this); } + // Set graphics transform to the current HiDPI scale + if (canvasViewCache != null) { + synchronized (canvasViewCache) { + graphics2D.setTransform(new AffineTransform(canvasViewCache.getHiDPIXScale(), 0, 0, + canvasViewCache.getHiDPIYScale(), 0, 0)); + } + } return graphics2D; } @@ -2838,6 +2846,30 @@ ArrayList<TextureRetained> textureIDResourceTable = new ArrayList<TextureRetaine } /** + * Retreives the width of the canvas in device pixels (regardless of HIDPI scale) + */ + int getPixelWidth() { + if (canvasViewCache != null) { + synchronized (canvasViewCache) { + return canvasViewCache.getCanvasWidth(); + } + } + return getWidth(); + } + + /** + * Retreives the height of the canvas in device pixels (regardless of HIDPI scale) + */ + int getPixelHeight() { + if (canvasViewCache != null) { + synchronized (canvasViewCache) { + return canvasViewCache.getCanvasHeight(); + } + } + return getHeight(); + } + + /** * Sets view that points to this Canvas3D. * @param view view object that points to this Canvas3D */ diff --git a/src/main/java/org/jogamp/java3d/CanvasViewCache.java b/src/main/java/org/jogamp/java3d/CanvasViewCache.java index 8a131fa..a6b4e2c 100644 --- a/src/main/java/org/jogamp/java3d/CanvasViewCache.java +++ b/src/main/java/org/jogamp/java3d/CanvasViewCache.java @@ -1805,6 +1805,14 @@ class CanvasViewCache extends Object { return canvasHeight; } + double getHiDPIXScale() { + return hiDPIXScale; + } + + double getHiDPIYScale() { + return hiDPIYScale; + } + double getPhysicalWindowWidth() { return physicalWindowWidth; } diff --git a/src/main/java/org/jogamp/java3d/J3DGraphics2DImpl.java b/src/main/java/org/jogamp/java3d/J3DGraphics2DImpl.java index d774ede..124fb74 100644 --- a/src/main/java/org/jogamp/java3d/J3DGraphics2DImpl.java +++ b/src/main/java/org/jogamp/java3d/J3DGraphics2DImpl.java @@ -115,8 +115,10 @@ final class J3DGraphics2DImpl extends J3DGraphics2D { if (!initCtx) { abgr = ((canvas3d.extensionsSupported & Canvas3D.EXT_ABGR) != 0); - width = canvas3d.getWidth(); - height = canvas3d.getHeight(); + // We use actual pixel sizes that depend + // on the current HiDPI setting + width = canvas3d.getPixelWidth(); + height = canvas3d.getPixelHeight(); initTexMap = false; if (width <= 0) { @@ -135,6 +137,8 @@ final class J3DGraphics2DImpl extends J3DGraphics2D { g3dImage = new BufferedImage(width, height, (abgr ? BufferedImage.TYPE_4BYTE_ABGR: BufferedImage.TYPE_INT_ARGB)); + // No need to set graphics affine transform to HiDPI scaling + // as it will be reset in Canvas3D.getGraphics2D() offScreenGraphics2D = g3dImage.createGraphics(); clearOffScreen(); if (!abgr) { |