From 4686a652d821efe04045333026be79270bc19bfd Mon Sep 17 00:00:00 2001
From: Sven Gothel
Date: Mon, 9 Jun 2014 03:58:37 +0200
Subject: 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 ..
---
.../classes/com/jogamp/newt/MonitorDevice.java | 22 ++++++++++++++--------
src/newt/classes/com/jogamp/newt/Window.java | 21 +++++++++++++++++++++
.../classes/com/jogamp/newt/opengl/GLWindow.java | 10 ++++++++++
3 files changed, 45 insertions(+), 8 deletions(-)
(limited to 'src/newt/classes/com/jogamp')
diff --git a/src/newt/classes/com/jogamp/newt/MonitorDevice.java b/src/newt/classes/com/jogamp/newt/MonitorDevice.java
index 8e5d305dd..a65675204 100644
--- a/src/newt/classes/com/jogamp/newt/MonitorDevice.java
+++ b/src/newt/classes/com/jogamp/newt/MonitorDevice.java
@@ -34,6 +34,7 @@ import javax.media.nativewindow.util.DimensionImmutable;
import javax.media.nativewindow.util.Rectangle;
import javax.media.nativewindow.util.RectangleImmutable;
import javax.media.nativewindow.util.SurfaceSize;
+
import com.jogamp.common.util.ArrayHashSet;
/**
@@ -124,29 +125,34 @@ public abstract class MonitorDevice {
}
/**
- * Stores the pixels per millimeter value according to current {@link MonitorMode}
- * {@link SurfaceSize#getResolution() SurfaceSize's resolution} in the given storage ppmmStore
.
+ * Returns the pixels per millimeter value according to the current {@link MonitorMode mode}'s
+ * {@link SurfaceSize#getResolution() surface resolution}.
*
* To convert the result to dpi, i.e. dots-per-inch, multiply both components with 25.4f
.
*
+ * @param ppmmStore float[2] storage for the ppmm result
+ * @return the passed storage containing the ppmm for chaining
*/
- public final void getPixelsPerMM(final float[] ppmmStore) {
- final MonitorMode mode = getCurrentMode();
- getPixelsPerMM(mode, ppmmStore);
+ public final float[] getPixelsPerMM(final float[] ppmmStore) {
+ return getPixelsPerMM(getCurrentMode(), ppmmStore);
}
/**
- * Stores the pixels per millimeter value according to the given {@link MonitorMode}
- * {@link SurfaceSize#getResolution() SurfaceSize's resolution} in the given storage ppmmStore
.
+ * Returns the pixels per millimeter value according to the given {@link MonitorMode mode}'s
+ * {@link SurfaceSize#getResolution() surface resolution}.
*
* To convert the result to dpi, i.e. dots-per-inch, multiply both components with 25.4f
.
*
+ * @param mode
+ * @param ppmmStore float[2] storage for the ppmm result
+ * @return the passed storage containing the ppmm for chaining
*/
- public final void getPixelsPerMM(final MonitorMode mode, final float[] ppmmStore) {
+ public final float[] getPixelsPerMM(final MonitorMode mode, final float[] ppmmStore) {
final DimensionImmutable sdim = getSizeMM();
final DimensionImmutable spix = mode.getSurfaceSize().getResolution();
ppmmStore[0] = (float)spix.getWidth() / (float)sdim.getWidth();
ppmmStore[1] = (float)spix.getHeight() / (float)sdim.getHeight();
+ return ppmmStore;
}
/**
diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java
index 08236ae67..600ecee52 100644
--- a/src/newt/classes/com/jogamp/newt/Window.java
+++ b/src/newt/classes/com/jogamp/newt/Window.java
@@ -49,6 +49,7 @@ import javax.media.nativewindow.ScalableSurface;
import javax.media.nativewindow.WindowClosingProtocol;
import javax.media.nativewindow.util.Rectangle;
import javax.media.nativewindow.util.RectangleImmutable;
+import javax.media.nativewindow.util.SurfaceSize;
/**
* Specifying NEWT's Window functionality:
@@ -253,6 +254,26 @@ public interface Window extends NativeWindow, WindowClosingProtocol, ScalableSur
*/
Rectangle getBounds();
+ /**
+ * Returns the pixels per millimeter of this window's {@link NativeSurface}
+ * according to the {@link #getMainMonitor() main monitor}'s current {@link MonitorMode mode}'s
+ * {@link SurfaceSize#getResolution() surface resolution}.
+ *
+ * Method takes the {@link #getCurrentSurfaceScale(int[]) current surface-scale} and {@link #getNativeSurfaceScale(int[]) native surface-scale}
+ * into account, i.e.:
+ *
+ * surfacePpMM = monitorPpMM * currentSurfaceScale / nativeSurfaceScale,
+ * with PpMM == pixel per millimeter
+ *
+ *
+ *
+ * To convert the result to dpi, i.e. dots-per-inch, multiply both components with 25.4f
.
+ *
+ * @param ppmmStore float[2] storage for the ppmm result
+ * @return the passed storage containing the ppmm for chaining
+ */
+ float[] getPixelsPerMM(final float[] ppmmStore);
+
/**
* Sets the size of the window's client area in window units, excluding decorations.
*
diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
index 2991bb98a..cdc4f1217 100644
--- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
+++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
@@ -403,6 +403,16 @@ public class GLWindow extends GLAutoDrawableBase implements GLAutoDrawable, Wind
return window.getCurrentSurfaceScale(result);
}
+ @Override
+ public final int[] getNativeSurfaceScale(final int[] result) {
+ return window.getNativeSurfaceScale(result);
+ }
+
+ @Override
+ public final float[] getPixelsPerMM(final float[] ppmmStore) {
+ return window.getPixelsPerMM(ppmmStore);
+ }
+
@Override
public final void setPosition(int x, int y) {
window.setPosition(x, y);
--
cgit v1.2.3