diff options
author | Egor Tsinko <[email protected]> | 2020-01-27 14:20:11 -0700 |
---|---|---|
committer | Egor Tsinko <[email protected]> | 2020-01-27 14:20:11 -0700 |
commit | ce5a0e13d536dc67f121d39117db6f1b47d29525 (patch) | |
tree | e6aff9a196f5242ea545707171444644fd77822f | |
parent | a50f5639aa38bbcfcb47069e6baf8d0079047f83 (diff) |
improved the 2D graphics overlay in Canvas3D.
Now actual pixel sizes are used instead of canvas sizes for creating an overlay image.
-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 1edb33e..91b42ae 100644 --- a/src/main/java/org/jogamp/java3d/CanvasViewCache.java +++ b/src/main/java/org/jogamp/java3d/CanvasViewCache.java @@ -1803,6 +1803,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) { |