summaryrefslogtreecommitdiffstats
path: root/src/nativewindow
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-06-09 03:58:37 +0200
committerSven Gothel <[email protected]>2014-06-09 03:58:37 +0200
commit4686a652d821efe04045333026be79270bc19bfd (patch)
tree240ac4df0ae58c7461e7bfdfb3b438917041a3af /src/nativewindow
parent14ff638b63fc7adaa59f351891f6a38806d7fa5d (diff)
Bug 741 HiDPI: Add ScalableSurface.getNativeSurfaceScale(..) to compute surface DPI ; Add NEWT Window.getPixelsPerMM(..) to query surface DPI
With HiDPI and surface scale, we need knowledge of the native surface's pixel-scale matching the monitor's pixel-per-millimeter value. Preserving the queried native pixel-scale and exposing it via ScalableSurface.getNativeSurfaceScale(..) to compute surface DPI. Add NEWT Window.getPixelsPerMM(..) to query surface DPI. Surface DPI is demonstrated in GraphUI's GPUUISceneGLListener0A .. and TestRulerNEWT01, etc ..
Diffstat (limited to 'src/nativewindow')
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java23
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/ScalableSurface.java21
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/util/Dimension.java6
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/SurfaceScaleUtils.java31
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java6
5 files changed, 60 insertions, 27 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
index 1cc8fdb01..62710830f 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
@@ -101,7 +101,8 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
protected Insets insets;
private volatile long offscreenSurfaceLayer;
- private volatile int[] hasPixelScale = new int[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE };
+ private final int[] nativePixelScale = new int[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE };
+ private final int[] hasPixelScale = new int[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE };
protected final int[] reqPixelScale = new int[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE };
private long drawable_old;
@@ -266,6 +267,8 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
insets = new Insets();
hasPixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE;
hasPixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE;
+ nativePixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE;
+ nativePixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE;
}
protected abstract void invalidateNative();
@@ -293,6 +296,12 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
return result;
}
+ @Override
+ public final int[] getNativeSurfaceScale(final int[] result) {
+ System.arraycopy(nativePixelScale, 0, result, 0, 2);
+ return result;
+ }
+
/**
* Updates bounds and pixelScale
* @return true if bounds or pixelScale has changed, otherwise false
@@ -312,6 +321,11 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
insets.set(contInsets.left, contInsets.right, contInsets.top, contInsets.bottom);
}
}
+ {
+ final int ps = JAWTUtil.getPixelScale(config.getAWTGraphicsConfiguration());
+ nativePixelScale[0] = ps;
+ nativePixelScale[1] = ps;
+ }
return updatePixelScale() || changedBounds;
}
@@ -321,12 +335,7 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
* @return true if pixelScale has changed, otherwise false
*/
protected final boolean updatePixelScale() {
- final int[] pixelScaleInt;
- {
- final int ps = JAWTUtil.getPixelScale(config.getAWTGraphicsConfiguration());
- pixelScaleInt = new int[] { ps, ps };
- }
- return SurfaceScaleUtils.computePixelScale(hasPixelScale, hasPixelScale, reqPixelScale, pixelScaleInt, DEBUG ? getClass().getSimpleName() : null);
+ return SurfaceScaleUtils.computePixelScale(hasPixelScale, hasPixelScale, reqPixelScale, nativePixelScale, DEBUG ? getClass().getSimpleName() : null);
}
/** @return the JAWT_DrawingSurfaceInfo's (JAWT_Rectangle) bounds, updated with lock */
diff --git a/src/nativewindow/classes/javax/media/nativewindow/ScalableSurface.java b/src/nativewindow/classes/javax/media/nativewindow/ScalableSurface.java
index de6ba51d7..ffd5c224c 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/ScalableSurface.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/ScalableSurface.java
@@ -65,7 +65,7 @@ public interface ScalableSurface {
* Returns the requested pixel scale of the associated {@link NativeSurface}.
*
* @param result int[2] storage for the result
- * @return the passed storage containing the requested pixelSize for chaining
+ * @return the passed storage containing the requested pixelScale for chaining
*/
int[] getRequestedSurfaceScale(final int[] result);
@@ -73,8 +73,25 @@ public interface ScalableSurface {
* Returns the current pixel scale of the associated {@link NativeSurface}.
*
* @param result int[2] storage for the result
- * @return the passed storage containing the current pixelSize for chaining
+ * @return the passed storage containing the current pixelScale for chaining
*/
public int[] getCurrentSurfaceScale(final int[] result);
+
+ /**
+ * Returns the native pixel scale of the associated {@link NativeSurface}
+ * reflecting it's currently bound <i>monitor surface resolution in pixels</i>.
+ * <p>
+ * The native pixel scale maybe used to determine the proper <i>dpi</i>
+ * value of this {@link NativeSurface}:
+ * <pre>
+ * surfacePpMM = monitorPpMM * currentSurfaceScale / nativeSurfaceScale,
+ * with PpMM == pixel per millimeter
+ * </pre>
+ * </p>
+ *
+ * @param result int[2] storage for the result
+ * @return the passed storage containing the native pixelScale for chaining
+ */
+ public int[] getNativeSurfaceScale(final int[] result);
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/Dimension.java b/src/nativewindow/classes/javax/media/nativewindow/util/Dimension.java
index 24ccc836a..5c9dc279d 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/util/Dimension.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/util/Dimension.java
@@ -37,7 +37,11 @@ public class Dimension implements Cloneable, DimensionImmutable {
this(0, 0);
}
- public Dimension(int width, int height) {
+ public Dimension(final int[] size) {
+ this(size[0], size[1]);
+ }
+
+ public Dimension(final int width, final int height) {
if(width<0 || height<0) {
throw new IllegalArgumentException("width and height must be within: ["+0+".."+Integer.MAX_VALUE+"]");
}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/SurfaceScaleUtils.java b/src/nativewindow/classes/jogamp/nativewindow/SurfaceScaleUtils.java
index 22e67ecff..3aea58852 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/SurfaceScaleUtils.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/SurfaceScaleUtils.java
@@ -58,37 +58,34 @@ public class SurfaceScaleUtils {
* @param result int[2] storage for result, maybe same as <code>prePixelScale</code> for in-place
* @param prePixelScale previous pixelScale
* @param reqPixelScale requested pixelScale, validated via {@link #validateReqPixelScale(int[], int, String)}.
- * @param surfPixelScaleRaw raw surface pixelScale
+ * @param newPixelScaleRaw new raw surface pixelScale
* @param DEBUG_PREFIX if set, dumps debug info on stderr using this prefix
* @return true if pixelScale has changed, otherwise false
*/
- public static boolean computePixelScale(int[] result, final int[] prePixelScale, final int[] reqPixelScale, final int[] surfPixelScaleRaw, final String DEBUG_PREFIX) {
- final int surfPixelScaleSafeX = 0 < surfPixelScaleRaw[0] ? surfPixelScaleRaw[0] : ScalableSurface.IDENTITY_PIXELSCALE;
- final int surfPixelScaleSafeY = 0 < surfPixelScaleRaw[1] ? surfPixelScaleRaw[1] : ScalableSurface.IDENTITY_PIXELSCALE;
+ public static boolean computePixelScale(int[] result, final int[] prePixelScale, final int[] reqPixelScale, final int[] newPixelScaleRaw, final String DEBUG_PREFIX) {
+ final int newPixelScaleSafeX = 0 < newPixelScaleRaw[0] ? newPixelScaleRaw[0] : ScalableSurface.IDENTITY_PIXELSCALE;
+ final int newPixelScaleSafeY = 0 < newPixelScaleRaw[1] ? newPixelScaleRaw[1] : ScalableSurface.IDENTITY_PIXELSCALE;
final boolean useHiDPI = ScalableSurface.IDENTITY_PIXELSCALE != reqPixelScale[0] || ScalableSurface.IDENTITY_PIXELSCALE != reqPixelScale[1];
final int prePixelScaleX = prePixelScale[0];
final int prePixelScaleY = prePixelScale[1];
if( useHiDPI ) {
- result[0] = surfPixelScaleSafeX;
- result[1] = surfPixelScaleSafeY;
+ result[0] = newPixelScaleSafeX;
+ result[1] = newPixelScaleSafeY;
} else {
result[0] = ScalableSurface.IDENTITY_PIXELSCALE;
result[1] = ScalableSurface.IDENTITY_PIXELSCALE;
}
- if( result[0] != prePixelScaleX || result[1] != prePixelScaleY ) {
- if( null != DEBUG_PREFIX ) {
- System.err.println(DEBUG_PREFIX+".computePixelScale: useHiDPI "+useHiDPI+", ["+prePixelScaleX+"x"+prePixelScaleY+" (pre), "+
- reqPixelScale[0]+"x"+reqPixelScale[1]+" (req)] -> "+
- surfPixelScaleRaw[0]+"x"+surfPixelScaleRaw[1]+" (raw) -> "+
- surfPixelScaleSafeX+"x"+surfPixelScaleSafeY+" (safe) -> "+
- result[0]+"x"+result[1]+" (use)");
- }
- return true;
- } else {
- return false;
+ final boolean changed = result[0] != prePixelScaleX || result[1] != prePixelScaleY;
+ if( null != DEBUG_PREFIX ) {
+ System.err.println(DEBUG_PREFIX+".computePixelScale: useHiDPI "+useHiDPI+", ["+prePixelScaleX+"x"+prePixelScaleY+" (pre), "+
+ reqPixelScale[0]+"x"+reqPixelScale[1]+" (req)] -> "+
+ newPixelScaleRaw[0]+"x"+newPixelScaleRaw[1]+" (raw) -> "+
+ newPixelScaleSafeX+"x"+newPixelScaleSafeY+" (safe) -> "+
+ result[0]+"x"+result[1]+" (use), changed "+changed);
}
+ return changed;
}
/**
diff --git a/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java b/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java
index 8f9379130..752057a49 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java
@@ -164,4 +164,10 @@ public class WrappedSurface extends ProxySurfaceImpl implements ScalableSurface
return result;
}
+ @Override
+ public final int[] getNativeSurfaceScale(final int[] result) {
+ System.arraycopy(hasPixelScale, 0, result, 0, 2);
+ return result;
+ }
+
} \ No newline at end of file