diff options
author | Sven Gothel <[email protected]> | 2014-05-21 08:53:54 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-05-21 08:53:54 +0200 |
commit | f9a00b91dcd146c72a50237b62270f33bd0da98e (patch) | |
tree | f4387da868608cea5066ce3a8cb9039a16b529de /src/nativewindow | |
parent | 0ffba122ea5c4b8cc247234ca9f48ccfcce833cd (diff) |
Bug 742 HiDPI: [Core API Change] Distinguish window-units and pixel-units; Add HiDPI for AWT GLCanvas w/ OSX CALayer
Core API Change:
To support HiDPI thoroughly in JOGL (NativeWindow, JOGL, NEWT)
we need to separate window- and pixel units.
NativeWindow and NativeSurface now have distinguished
access methods for window units and pixel units.
NativeWindow: Using window units
- getWindowWidth() * NEW Method *
- getWindowHeight() * NEW Method *
- getX(), getY(), ...
NativeSurface: Using pixel units
- getWidth() -> getSurfaceWidth() * RENAMED *
- getHeight() -> getSurfaceHeight() * RENAMED *
GLDrawable: Using pixel units
- getWidth() -> getSurfaceWidth() * RENAMED, aligned w/ NativeSurface *
- getHeight() -> getSurfaceHeight() * RENAMED, aligned w/ NativeSurface *
Above changes also removes API collision w/ other windowing TK,
e.g. AWT's getWidth()/getHeight() in GLCanvas
and the same method names in GLDrawable before this change.
+++
Now preliminary 'working':
- AWT GLCanvas
- AWT GLJPanel
Tested manually on OSX w/ and w/o HiDPI Retina:
java com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2AWT -manual -noanim -time 1000000
java com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2GLJPanelAWT -manual -noanim -time 1000000
+++
TODO:
- NEWT
- Change Window.setSize(..) to use pixel units ?
- OSX HiDPI support
- Testing ..
- API refinement
Diffstat (limited to 'src/nativewindow')
25 files changed, 397 insertions, 187 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/DelegatedUpstreamSurfaceHookMutableSize.java b/src/nativewindow/classes/com/jogamp/nativewindow/DelegatedUpstreamSurfaceHookMutableSize.java index c98bf5436..7ae614158 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/DelegatedUpstreamSurfaceHookMutableSize.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/DelegatedUpstreamSurfaceHookMutableSize.java @@ -32,7 +32,7 @@ public class DelegatedUpstreamSurfaceHookMutableSize extends UpstreamSurfaceHook @Override public String toString() { - return getClass().getSimpleName()+"[ "+ width + "x" + height + ", " + upstream + "]"; + return getClass().getSimpleName()+"[ "+ pixWidth + "x" + pixHeight + ", " + upstream + "]"; } } diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/DelegatedUpstreamSurfaceHookWithSurfaceSize.java b/src/nativewindow/classes/com/jogamp/nativewindow/DelegatedUpstreamSurfaceHookWithSurfaceSize.java index 1557f4e51..db4a979d1 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/DelegatedUpstreamSurfaceHookWithSurfaceSize.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/DelegatedUpstreamSurfaceHookWithSurfaceSize.java @@ -10,7 +10,7 @@ public class DelegatedUpstreamSurfaceHookWithSurfaceSize implements UpstreamSurf /** * @param upstream optional upstream UpstreamSurfaceHook used for {@link #create(ProxySurface)} and {@link #destroy(ProxySurface)}. - * @param surface mandatory {@link NativeSurface} used for {@link #getWidth(ProxySurface)} and {@link #getHeight(ProxySurface)} + * @param surface mandatory {@link NativeSurface} used for {@link #getPixelWidth(ProxySurface)} and {@link #getPixelHeight(ProxySurface)} */ public DelegatedUpstreamSurfaceHookWithSurfaceSize(UpstreamSurfaceHook upstream, NativeSurface surface) { this.upstream = upstream; @@ -35,18 +35,18 @@ public class DelegatedUpstreamSurfaceHookWithSurfaceSize implements UpstreamSurf } @Override - public final int getWidth(ProxySurface s) { - return surface.getWidth(); + public final int getPixelWidth(ProxySurface s) { + return surface.getSurfaceWidth(); } @Override - public final int getHeight(ProxySurface s) { - return surface.getHeight(); + public final int getPixelHeight(ProxySurface s) { + return surface.getSurfaceHeight(); } @Override public String toString() { - final String us_s = null != surface ? ( surface.getClass().getName() + ": 0x" + Long.toHexString(surface.getSurfaceHandle()) + " " +surface.getWidth() + "x" + surface.getHeight() ) : "nil"; + final String us_s = null != surface ? ( surface.getClass().getName() + ": 0x" + Long.toHexString(surface.getSurfaceHandle()) + " " +surface.getSurfaceWidth() + "x" + surface.getSurfaceHeight() ) : "nil"; return getClass().getSimpleName()+"["+upstream+", "+us_s+"]"; } diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/UpstreamSurfaceHookMutableSize.java b/src/nativewindow/classes/com/jogamp/nativewindow/UpstreamSurfaceHookMutableSize.java index 5838c7a56..5910f5fea 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/UpstreamSurfaceHookMutableSize.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/UpstreamSurfaceHookMutableSize.java @@ -4,31 +4,31 @@ import javax.media.nativewindow.ProxySurface; import javax.media.nativewindow.UpstreamSurfaceHook; public class UpstreamSurfaceHookMutableSize implements UpstreamSurfaceHook.MutableSize { - int width, height; + int pixWidth, pixHeight; /** * @param width initial width * @param height initial height */ public UpstreamSurfaceHookMutableSize(int width, int height) { - this.width = width; - this.height = height; + this.pixWidth = width; + this.pixHeight = height; } @Override - public final void setSize(int width, int height) { - this.width = width; - this.height = height; + public final void setPixelSize(int width, int height) { + this.pixWidth = width; + this.pixHeight = height; } @Override - public final int getWidth(ProxySurface s) { - return width; + public final int getPixelWidth(ProxySurface s) { + return pixWidth; } @Override - public final int getHeight(ProxySurface s) { - return height; + public final int getPixelHeight(ProxySurface s) { + return pixHeight; } @Override public void create(ProxySurface s) { /* nop */ } @@ -38,7 +38,7 @@ public class UpstreamSurfaceHookMutableSize implements UpstreamSurfaceHook.Mutab @Override public String toString() { - return getClass().getSimpleName()+"[ "+ width + "x" + height + "]"; + return getClass().getSimpleName()+"[pixel "+ pixWidth + "x" + pixHeight + "]"; } } diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/UpstreamSurfaceHookMutableSizePos.java b/src/nativewindow/classes/com/jogamp/nativewindow/UpstreamSurfaceHookMutableSizePos.java deleted file mode 100644 index e6fcc049c..000000000 --- a/src/nativewindow/classes/com/jogamp/nativewindow/UpstreamSurfaceHookMutableSizePos.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.jogamp.nativewindow; - -public class UpstreamSurfaceHookMutableSizePos extends UpstreamSurfaceHookMutableSize { - int x, y; - - /** - * @param width initial width - * @param height initial height - */ - public UpstreamSurfaceHookMutableSizePos(int x, int y, int width, int height) { - super(width, height); - this.x= x; - this.y= y; - } - - // @Override - public final void setPos(int x, int y) { - this.x= x; - this.y= y; - } - - public final int getX() { - return x; - } - - public final int getY() { - return y; - } - - @Override - public String toString() { - return getClass().getSimpleName()+"[ "+ x + "/" + y + " " + width + "x" + height + "]"; - } - -} - diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/UpstreamWindowHookMutableSizePos.java b/src/nativewindow/classes/com/jogamp/nativewindow/UpstreamWindowHookMutableSizePos.java new file mode 100644 index 000000000..f761b522a --- /dev/null +++ b/src/nativewindow/classes/com/jogamp/nativewindow/UpstreamWindowHookMutableSizePos.java @@ -0,0 +1,53 @@ +package com.jogamp.nativewindow; + +public class UpstreamWindowHookMutableSizePos extends UpstreamSurfaceHookMutableSize { + int winX, winY, winWidth, winHeight; + + /** + * @param winX initial window x-pos + * @param winY initial window y-pos + * @param winWidth initial window width + * @param winHeight initial window height + * @param pixWidth initial surface pixel width, FIXME: pixel-dim == window-dim 'for now' ? + * @param pixHeight initial surface pixel height, FIXME: pixel-dim == window-dim 'for now' ? + */ + public UpstreamWindowHookMutableSizePos(int winX, int winY, int winWidth, int winHeight, int pixWidth, int pixHeight) { + super(pixWidth, pixHeight); + this.winX= winX; + this.winY= winY; + this.winWidth = winWidth; + this.winHeight = winHeight; + } + + // @Override + public final void setWinPos(int winX, int winY) { + this.winX= winX; + this.winY= winY; + } + // @Override + public final void setWinSize(int winWidth, int winHeight) { + this.winWidth= winWidth; + this.winHeight= winHeight; + } + + public final int getX() { + return winX; + } + + public final int getY() { + return winY; + } + public final int getWindowWidth() { + return winWidth; + } + public final int getWindowHeight() { + return winHeight; + } + + @Override + public String toString() { + return getClass().getSimpleName()+"[window "+ winX + "/" + winY + " " + winWidth + "x" + winHeight + ", pixel " + pixWidth + "x" + pixHeight + "]"; + } + +} + diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java index 8d7c382ee..e35716c49 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java @@ -46,7 +46,6 @@ import com.jogamp.nativewindow.MutableGraphicsConfiguration; import java.awt.Component; import java.awt.Container; import java.awt.Cursor; -import java.awt.GraphicsDevice; import java.awt.Window; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; @@ -99,7 +98,7 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, protected Rectangle bounds; protected Insets insets; private volatile long offscreenSurfaceLayer; - + private volatile int pixelScale; private long drawable_old; /** @@ -123,6 +122,7 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, invalidate(); this.isApplet = false; this.offscreenSurfaceLayer = 0; + this.pixelScale = 1; } private static String id(Object obj) { return ( null!=obj ? toHexString(obj.hashCode()) : "nil" ); } private String jawtStr() { return "JAWTWindow["+id(JAWTWindow.this)+"]"; } @@ -260,17 +260,26 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, drawable_old = 0; bounds = new Rectangle(); insets = new Insets(); + pixelScale = 1; } protected abstract void invalidateNative(); - protected final boolean updateBounds(JAWT_Rectangle jawtBounds) { + /** + * Updates bounds and pixelScale + */ + protected final boolean updateLockedData(JAWT_Rectangle jawtBounds) { final Rectangle jb = new Rectangle(jawtBounds.getX(), jawtBounds.getY(), jawtBounds.getWidth(), jawtBounds.getHeight()); - final boolean changed = !bounds.equals(jb); + final int newPixelScale; + { + final int s = JAWTUtil.getPixelScale(component); + newPixelScale = 0 < s ? s : 1; + } + final boolean changedBounds = !bounds.equals(jb); + final boolean changedPixelScale = newPixelScale != pixelScale; - if(changed) { - if(DEBUG) { + if( changedBounds ) { + if( DEBUG ) { System.err.println("JAWTWindow.updateBounds: "+bounds+" -> "+jb); - // Thread.dumpStack(); } bounds.set(jawtBounds.getX(), jawtBounds.getY(), jawtBounds.getWidth(), jawtBounds.getHeight()); @@ -279,12 +288,21 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, insets.set(contInsets.left, contInsets.right, contInsets.top, contInsets.bottom); } } - return changed; + if( changedPixelScale ) { + if( DEBUG ) { + System.err.println("JAWTWindow.updatePixelScale: "+pixelScale+" -> "+newPixelScale); + } + pixelScale = newPixelScale; + } + return changedBounds || changedPixelScale; } /** @return the JAWT_DrawingSurfaceInfo's (JAWT_Rectangle) bounds, updated with lock */ public final RectangleImmutable getBounds() { return bounds; } + /** @return the safe pixelScale value, i.e. never negative or zero. Updated with lock. */ + public final int getPixelScale() { return pixelScale; } + @Override public final InsetsImmutable getInsets() { return insets; } @@ -606,13 +624,13 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, } @Override - public final int getWidth() { - return component.getWidth(); + public final int getSurfaceWidth() { + return getWindowWidth() * getPixelScale(); } @Override - public final int getHeight() { - return component.getHeight(); + public final int getSurfaceHeight() { + return getWindowHeight() * getPixelScale(); } // @@ -620,6 +638,32 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, // @Override + public final int getWindowWidth() { + return component.getWidth(); + } + + @Override + public final int getWindowHeight() { + return component.getHeight(); + } + + @Override + public final int[] getWindowUnitXY(int[] result, final int[] pixelUnitXY) { + final int scale = getPixelScale(); + result[0] = pixelUnitXY[0] / scale; + result[1] = pixelUnitXY[1] / scale; + return result; + } + + @Override + public final int[] getPixelUnitXY(int[] result, final int[] windowUnitXY) { + final int scale = getPixelScale(); + result[0] = windowUnitXY[0] * scale; + result[1] = windowUnitXY[1] * scale; + return result; + } + + @Override public void destroy() { surfaceLock.lock(); try { @@ -751,25 +795,6 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, return component.hasFocus(); } - /** - * Returns the pixel scale factor of this {@link Component}'s {@link GraphicsDevice}, if supported. - * <p> - * If the component is not yet {@link Component#isDisplayable() displayable}, - * <code>zero</code> is returned. - * </p> - * <p> - * If the component does not support pixel scaling the default - * <code>one</code> is returned. - * </p> - * <p> - * Note: Currently only supported on OSX since 1.7.0_40 for HiDPI retina displays - * </p> - * @return the pixel scale factor - */ - protected final int getPixelScale() { - return JAWTUtil.getPixelScale(component); - } - protected StringBuilder jawt2String(StringBuilder sb) { if( null == sb ) { sb = new StringBuilder(); @@ -801,7 +826,8 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, ", surfaceHandle "+toHexString(getSurfaceHandle())+ ", bounds "+bounds+", insets "+insets ); - sb.append(", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+ + sb.append(", window ["+getX()+"/"+getY()+" "+getWindowWidth()+"x"+getWindowHeight()+ + "], pixels[x"+getPixelScale()+" -> "+getSurfaceWidth()+"x"+getSurfaceHeight()+"]"+ ", visible "+component.isVisible()); sb.append(", lockedExt "+isSurfaceLockedByOtherThread()+ ",\n\tconfig "+config+ diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java b/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java index a755b1812..d5cc048a1 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java @@ -28,14 +28,20 @@ package javax.media.nativewindow; -/** Provides low-level information required for - hardware-accelerated rendering using a surface in a platform-independent manner.<P> - - A NativeSurface created for a particular on- or offscreen component is - expected to have the same lifetime as that component. As long as - the component is alive and realized/visible, NativeSurface must be able - provide information such as the surface handle while it is locked.<P> -*/ +/** + * Provides low-level information required for + * hardware-accelerated rendering using a surface in a platform-independent manner. + * <p> + * All values of this interface are represented in pixel units, + * see {@link NativeWindow}. + * </p> + * <p> + * A NativeSurface created for a particular on- or offscreen component is + * expected to have the same lifetime as that component. As long as + * the component is alive and realized/visible, NativeSurface must be able + * provide information such as the surface handle while it is locked. + * </p> + */ public interface NativeSurface extends SurfaceUpdatedListener { /** Unlocked state */ public static final int LOCK_SURFACE_UNLOCKED = 0; @@ -172,16 +178,36 @@ public interface NativeSurface extends SurfaceUpdatedListener { public long getSurfaceHandle(); /** - * Returns the width of the client area excluding insets (window decorations). - * @return width of the client area + * Returns the width of the client area excluding insets (window decorations) in pixel units. + * @return width of the client area in pixel units + * @see NativeWindow#getWindowWidth() + * @see #getWindowUnitXY(int[], int[]) + */ + public int getSurfaceWidth(); + + /** + * Returns the height of the client area excluding insets (window decorations) in pixel units. + * @return height of the client area in pixel units + * @see NativeWindow#getWindowHeight() + * @see #getWindowUnitXY(int[], int[]) + */ + public int getSurfaceHeight(); + + /** + * Converts the given pixel units into window units. + * @param result int[2] storage for the result, may be equal to pixelUnitXY (in-place) + * @param pixelUnitXY int[2] x- and y-coord values in pixel units + * @return result int[2] storage for chaining holding the converted values */ - public int getWidth(); + public int[] getWindowUnitXY(int[] result, final int[] pixelUnitXY); /** - * Returns the height of the client area excluding insets (window decorations). - * @return height of the client area + * Converts the given window units into pixel units. + * @param result int[2] storage for the result, may be equal to windowUnitXY (in-place) + * @param windowUnitXY int[2] x- and y-coord values in window units + * @return result int[2] storage for chaining holding the converted values */ - public int getHeight(); + public int[] getPixelUnitXY(int[] result, final int[] windowUnitXY); /** * Returns the graphics configuration corresponding to this window. diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java index a740ebbe0..242f25d43 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java @@ -43,14 +43,21 @@ package javax.media.nativewindow; import javax.media.nativewindow.util.InsetsImmutable; import javax.media.nativewindow.util.Point; -/** Extend the {@link NativeSurface} interface with windowing - information such as window handle and position.<P> - - A window toolkit such as the AWT may either implement this interface - directly with one of its components, or provide and register an - implementation of {@link NativeWindowFactory NativeWindowFactory} - which can create NativeWindow objects for its components. <P> -*/ +/** + * Extend the {@link NativeSurface} interface with windowing + * information such as {@link #getWindowHandle() window-handle}, + * {@link #getWindowWidth() window-size} and {@link #getX() window-position}. + * <p> + * All values of this interface are represented in window units. + * see {@link NativeSurface}. + * </p> + * <p> + * A window toolkit such as the AWT may either implement this interface + * directly with one of its components, or provide and register an + * implementation of {@link NativeWindowFactory NativeWindowFactory} + * which can create NativeWindow objects for its components. + * </p> + */ public interface NativeWindow extends NativeSurface { /** @@ -76,8 +83,10 @@ public interface NativeWindow extends NativeSurface { /** * Returns the insets defined as the width and height of the window decoration - * on the left, right, top and bottom.<br> + * on the left, right, top and bottom in window units. + * <p> * Insets are zero if the window is undecorated, including child windows. + * </p> * * <p> * Insets are available only after the native window has been created, @@ -85,14 +94,14 @@ public interface NativeWindow extends NativeSurface { * * The top-level window area's top-left corner is located at * <pre> - * getX() - getInsets().{@link InsetsImmutable#getLeftWidth() getLeftWidth()} - * getY() - getInsets().{@link InsetsImmutable#getTopHeight() getTopHeight()} + * {@link #getX()} - getInsets().{@link InsetsImmutable#getLeftWidth() getLeftWidth()} + * {@link #getY()} - getInsets().{@link InsetsImmutable#getTopHeight() getTopHeight()} * </pre> * * The top-level window size is * <pre> - * getWidth() + getInsets().{@link InsetsImmutable#getTotalWidth() getTotalWidth()} - * getHeight() + getInsets().{@link InsetsImmutable#getTotalHeight() getTotalHeight()} + * {@link #getWindowWidth()} + getInsets().{@link InsetsImmutable#getTotalWidth() getTotalWidth()} + * {@link #getWindowHeight()} + getInsets().{@link InsetsImmutable#getTotalHeight() getTotalHeight()} * </pre> * * @return insets @@ -103,7 +112,7 @@ public interface NativeWindow extends NativeSurface { /** * @return the current x position of the top-left corner - * of the client area relative to it's parent. + * of the client area relative to it's parent in window units. * Since the position reflects the client area, it does not include the insets. * @see #getInsets() */ @@ -111,15 +120,29 @@ public interface NativeWindow extends NativeSurface { /** * @return the current y position of the top-left corner - * of the client area relative to it's parent. + * of the client area relative to it's parent in window units. * Since the position reflects the client area, it does not include the insets. * @see #getInsets() */ public int getY(); /** + * Returns the width of the client area excluding insets (window decorations) in window units. + * @return width of the client area in window units + * @see NativeSurface#getSurfaceWidth() + */ + public int getWindowWidth(); + + /** + * Returns the height of the client area excluding insets (window decorations) in window units. + * @return height of the client area in window units + * @see NativeSurface#getSurfaceHeight() + */ + public int getWindowHeight(); + + /** * Returns the current position of the top-left corner - * of the client area in screen coordinates. + * of the client area in window units. * <p> * Since the position reflects the client area, it does not include the insets. * </p> diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java index 034bf2456..1546bd909 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java @@ -56,7 +56,7 @@ import jogamp.nativewindow.x11.X11Lib; import com.jogamp.common.os.Platform; import com.jogamp.common.util.ReflectionUtil; -import com.jogamp.nativewindow.UpstreamSurfaceHookMutableSizePos; +import com.jogamp.nativewindow.UpstreamWindowHookMutableSizePos; import com.jogamp.nativewindow.awt.AWTGraphicsDevice; import com.jogamp.nativewindow.awt.AWTGraphicsScreen; import com.jogamp.nativewindow.macosx.MacOSXGraphicsDevice; @@ -669,7 +669,7 @@ public abstract class NativeWindowFactory { /** * Creates a wrapped {@link NativeWindow} with given native handles and {@link AbstractGraphicsScreen}. * <p> - * The given {@link UpstreamSurfaceHookMutableSizePos} maybe used to reflect resizes and repositioning of the native window. + * The given {@link UpstreamWindowHookMutableSizePos} maybe used to reflect resizes and repositioning of the native window. * </p> * <p> * The {@link AbstractGraphicsScreen} may be created via {@link #createScreen(AbstractGraphicsDevice, int)}. @@ -680,7 +680,7 @@ public abstract class NativeWindowFactory { * </p> */ public static NativeWindow createWrappedWindow(AbstractGraphicsScreen aScreen, long surfaceHandle, long windowHandle, - UpstreamSurfaceHookMutableSizePos hook) { + UpstreamWindowHookMutableSizePos hook) { final CapabilitiesImmutable caps = new Capabilities(); final AbstractGraphicsConfiguration config = new DefaultGraphicsConfiguration(aScreen, caps, caps); return new WrappedWindow(config, surfaceHandle, hook, true, windowHandle); diff --git a/src/nativewindow/classes/javax/media/nativewindow/UpstreamSurfaceHook.java b/src/nativewindow/classes/javax/media/nativewindow/UpstreamSurfaceHook.java index f08a6c938..39e316856 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/UpstreamSurfaceHook.java +++ b/src/nativewindow/classes/javax/media/nativewindow/UpstreamSurfaceHook.java @@ -38,15 +38,15 @@ public interface UpstreamSurfaceHook { /** called within {@link ProxySurface#destroyNotify()} within lock, before clearing fields. */ public void destroy(ProxySurface s); - /** Returns the width of the upstream surface, used if {@link ProxySurface#UPSTREAM_PROVIDES_SIZE} is set. */ - public int getWidth(ProxySurface s); - /** Returns the height of the upstream surface, used if {@link ProxySurface#UPSTREAM_PROVIDES_SIZE} is set. */ - public int getHeight(ProxySurface s); + /** Returns the width of the upstream surface in pixels, used if {@link ProxySurface#UPSTREAM_PROVIDES_SIZE} is set. */ + public int getPixelWidth(ProxySurface s); + /** Returns the height of the upstream surface in pixels, used if {@link ProxySurface#UPSTREAM_PROVIDES_SIZE} is set. */ + public int getPixelHeight(ProxySurface s); /** * {@link UpstreamSurfaceHook} w/ mutable size, allowing it's {@link ProxySurface} user to resize. */ public interface MutableSize extends UpstreamSurfaceHook { - public void setSize(int width, int height); + public void setPixelSize(int width, int height); } } diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/Insets.java b/src/nativewindow/classes/javax/media/nativewindow/util/Insets.java index 3644916fe..dfe78b06f 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/util/Insets.java +++ b/src/nativewindow/classes/javax/media/nativewindow/util/Insets.java @@ -28,11 +28,15 @@ package javax.media.nativewindow.util; +/** + * Mutable insets representing rectangular window decoration insets on all four edges + * in window units. + */ public class Insets implements Cloneable, InsetsImmutable { static final InsetsImmutable zeroInsets = new Insets(); public static final InsetsImmutable getZero() { return zeroInsets; } - int l, r, t, b; + private int l, r, t, b; public Insets() { this(0, 0, 0, 0); @@ -72,12 +76,35 @@ public class Insets implements Cloneable, InsetsImmutable { @Override public final int getTotalHeight() { return t + b; } + /** + * Set the inset values of this instance in window units. + * @param left left inset width in window units. + * @param right right inset width in window units. + * @param top top inset width in window units. + * @param bottom bottom inset width in window units. + */ public final void set(int left, int right, int top, int bottom) { l = left; r = right; t = top; b = bottom; } + /** + * Set the left inset value of this instance in window units. + * @param left left inset width in window units. + */ public final void setLeftWidth(int left) { l = left; } + /** + * Set the right inset value of this instance in window units. + * @param right right inset width in window units. + */ public final void setRightWidth(int right) { r = right; } + /** + * Set the top inset value of this instance in window units. + * @param top top inset width in window units. + */ public final void setTopHeight(int top) { t = top; } + /** + * Set the bottom inset value of this instance in window units. + * @param bottom bottom inset width in window units. + */ public final void setBottomHeight(int bottom) { b = bottom; } @Override diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/InsetsImmutable.java b/src/nativewindow/classes/javax/media/nativewindow/util/InsetsImmutable.java index 8256068cd..0f8ba0158 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/util/InsetsImmutable.java +++ b/src/nativewindow/classes/javax/media/nativewindow/util/InsetsImmutable.java @@ -30,25 +30,28 @@ package javax.media.nativewindow.util; import com.jogamp.common.type.WriteCloneable; -/** Immutable Rectangle interface */ +/** + * Immutable insets representing rectangular window decoration insets on all four edges + * in window units. + */ public interface InsetsImmutable extends WriteCloneable { - /** @return left inset width */ + /** @return left inset width in window units. */ int getLeftWidth(); - /** @return right inset width */ + /** @return right inset width in window units. */ int getRightWidth(); - /** @return total width, ie. <code>left_width + right_width</code> */ + /** @return total width in window units, ie. <code>left_width + right_width</code> */ int getTotalWidth(); - /** @return top inset height */ + /** @return top inset height in window units. */ int getTopHeight(); - /** @return bottom inset height */ + /** @return bottom inset height in window units. */ int getBottomHeight(); - /** @return total height, ie. <code>top_height + bottom_height</code> */ + /** @return total height in window units, ie. <code>top_height + bottom_height</code> */ int getTotalHeight(); /** diff --git a/src/nativewindow/classes/jogamp/nativewindow/ProxySurfaceImpl.java b/src/nativewindow/classes/jogamp/nativewindow/ProxySurfaceImpl.java index fbff7128e..dd1b6f185 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/ProxySurfaceImpl.java +++ b/src/nativewindow/classes/jogamp/nativewindow/ProxySurfaceImpl.java @@ -149,13 +149,13 @@ public abstract class ProxySurfaceImpl implements ProxySurface { public abstract void setSurfaceHandle(long surfaceHandle); @Override - public final int getWidth() { - return upstream.getWidth(this); + public final int getSurfaceWidth() { + return upstream.getPixelWidth(this); } @Override - public final int getHeight() { - return upstream.getHeight(this); + public final int getSurfaceHeight() { + return upstream.getPixelHeight(this); } @Override @@ -303,7 +303,7 @@ public abstract class ProxySurfaceImpl implements ProxySurface { } sink.append("displayHandle 0x" + Long.toHexString(getDisplayHandle())). append("\n, surfaceHandle 0x" + Long.toHexString(getSurfaceHandle())). - append("\n, size " + getWidth() + "x" + getHeight()).append("\n, "); + append("\n, size " + getSurfaceWidth() + "x" + getSurfaceHeight()).append("\n, "); getUpstreamOptionBits(sink); sink.append("\n, "+config). append("\n, surfaceLock "+surfaceLock+"\n, "). diff --git a/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java b/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java index f622db8cc..5601dac02 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java +++ b/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java @@ -97,4 +97,21 @@ public class WrappedSurface extends ProxySurfaceImpl { protected final void unlockSurfaceImpl() { } + @Override + public final int[] getWindowUnitXY(int[] result, final int[] pixelUnitXY) { + final int scale = 1; // FIXME: Use 'scale' .. + result[0] = pixelUnitXY[0] / scale; + result[1] = pixelUnitXY[1] / scale; + return result; + } + + @Override + public final int[] getPixelUnitXY(int[] result, final int[] windowUnitXY) { + final int scale = 1; // FIXME: Use 'scale' .. + result[0] = windowUnitXY[0] * scale; + result[1] = windowUnitXY[1] * scale; + return result; + } + + } diff --git a/src/nativewindow/classes/jogamp/nativewindow/WrappedWindow.java b/src/nativewindow/classes/jogamp/nativewindow/WrappedWindow.java index edb65eb06..3cbfcd4d9 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/WrappedWindow.java +++ b/src/nativewindow/classes/jogamp/nativewindow/WrappedWindow.java @@ -9,28 +9,36 @@ import javax.media.nativewindow.util.Insets; import javax.media.nativewindow.util.InsetsImmutable; import javax.media.nativewindow.util.Point; -import com.jogamp.nativewindow.UpstreamSurfaceHookMutableSizePos; +import com.jogamp.nativewindow.UpstreamWindowHookMutableSizePos; public class WrappedWindow extends WrappedSurface implements NativeWindow { private final InsetsImmutable insets = new Insets(0, 0, 0, 0); private long windowHandle; /** - * Utilizes a {@link UpstreamSurfaceHookMutableSizePos} to hold the size and postion information, + * Utilizes a {@link UpstreamWindowHookMutableSizePos} to hold the size and postion information, * which is being passed to the {@link ProxySurface} instance. * * @param cfg the {@link AbstractGraphicsConfiguration} to be used * @param surfaceHandle the wrapped pre-existing native surface handle, maybe 0 if not yet determined - * @param initialX - * @param initialY - * @param initialWidth - * @param initialHeight + * @param initialWinX + * @param initialWinY + * @param initialWinWidth + * @param initialWinHeight + * @param initialPixelWidth FIXME: pixel-dim == window-dim 'for now' ? + * @param initialPixelHeight FIXME: pixel-dim == window-dim 'for now' ? * @param ownsDevice <code>true</code> if this {@link ProxySurface} instance * owns the {@link AbstractGraphicsConfiguration}'s {@link AbstractGraphicsDevice}, * otherwise <code>false</code>. Owning the device implies closing it at {@link #destroyNotify()}. */ - public WrappedWindow(AbstractGraphicsConfiguration cfg, long surfaceHandle, int initialX, int initialY, int initialWidth, int initialHeight, boolean ownsDevice, long windowHandle) { - this(cfg, surfaceHandle, new UpstreamSurfaceHookMutableSizePos(initialX, initialY, initialWidth, initialHeight), ownsDevice, windowHandle); + public WrappedWindow(AbstractGraphicsConfiguration cfg, long surfaceHandle, + int initialWinX, int initialWinY, int initialWinWidth, int initialWinHeight, + int initialPixelWidth, int initialPixelHeight, + boolean ownsDevice, long windowHandle) { + this(cfg, surfaceHandle, + new UpstreamWindowHookMutableSizePos(initialWinX, initialWinY, initialWinWidth, initialWinHeight, + initialPixelWidth, initialPixelHeight), + ownsDevice, windowHandle); } /** @@ -41,7 +49,7 @@ public class WrappedWindow extends WrappedSurface implements NativeWindow { * owns the {@link AbstractGraphicsConfiguration}'s {@link AbstractGraphicsDevice}, * otherwise <code>false</code>. */ - public WrappedWindow(AbstractGraphicsConfiguration cfg, long surfaceHandle, UpstreamSurfaceHookMutableSizePos upstream, boolean ownsDevice, long windowHandle) { + public WrappedWindow(AbstractGraphicsConfiguration cfg, long surfaceHandle, UpstreamWindowHookMutableSizePos upstream, boolean ownsDevice, long windowHandle) { super(cfg, surfaceHandle, upstream, ownsDevice); this.windowHandle = windowHandle; } @@ -74,12 +82,22 @@ public class WrappedWindow extends WrappedSurface implements NativeWindow { @Override public int getX() { - return ((UpstreamSurfaceHookMutableSizePos)getUpstreamSurfaceHook()).getX(); + return ((UpstreamWindowHookMutableSizePos)getUpstreamSurfaceHook()).getX(); } @Override public int getY() { - return ((UpstreamSurfaceHookMutableSizePos)getUpstreamSurfaceHook()).getY(); + return ((UpstreamWindowHookMutableSizePos)getUpstreamSurfaceHook()).getY(); + } + + @Override + public int getWindowWidth() { + return ((UpstreamWindowHookMutableSizePos)getUpstreamSurfaceHook()).getWindowWidth(); + } + + @Override + public int getWindowHeight() { + return ((UpstreamWindowHookMutableSizePos)getUpstreamSurfaceHook()).getWindowHeight(); } @Override diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java index fb979d440..387f40f89 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java @@ -64,6 +64,8 @@ import com.jogamp.common.util.locks.RecursiveLock; public class JAWTUtil { public static final boolean DEBUG = Debug.debug("JAWT"); + private static final boolean SKIP_AWT_HIDPI; + /** OSX JAWT version option to use CALayer */ public static final int JAWT_MACOSX_USE_CALAYER = 0x80000000; @@ -298,8 +300,10 @@ public class JAWTUtil { } static { + SKIP_AWT_HIDPI = Debug.isPropertyDefined("nativewindow.awt.nohidpi", true); + if(DEBUG) { - System.err.println("JAWTUtil initialization (JAWT/JNI/..."); + System.err.println("JAWTUtil initialization (JAWT/JNI/...); SKIP_AWT_HIDPI "+SKIP_AWT_HIDPI); // Thread.dumpStack(); } @@ -542,13 +546,15 @@ public class JAWTUtil { * @return the pixel scale factor */ public static final int getPixelScale(final GraphicsDevice device) { - if( null != getScaleFactorMethod ) { - try { - final Object res = getScaleFactorMethod.invoke(device); - if (res instanceof Integer) { - return ((Integer)res).intValue(); - } - } catch (Throwable t) {} + if( !SKIP_AWT_HIDPI ) { + if( null != getScaleFactorMethod ) { + try { + final Object res = getScaleFactorMethod.invoke(device); + if (res instanceof Integer) { + return ((Integer)res).intValue(); + } + } catch (Throwable t) {} + } } return 1; } diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java index 8d46d805a..58dc7e47e 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java @@ -143,7 +143,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface { } else if( DEBUG ) { System.err.println("JAWTWindow.attachSurfaceLayerImpl: "+toHexString(layerHandle) + ", [ins "+outterInsets+"], p0 "+p0+" -> "+p1+", bounds "+bounds); } - OSXUtil.AddCASublayer(rootSurfaceLayer, layerHandle, p1.getX(), p1.getY(), getWidth(), getHeight(), JAWTUtil.getOSXCALayerQuirks()); + OSXUtil.AddCASublayer(rootSurfaceLayer, layerHandle, p1.getX(), p1.getY(), getWindowWidth(), getWindowHeight(), getPixelScale(), JAWTUtil.getOSXCALayerQuirks()); } } ); } @@ -177,7 +177,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface { System.err.println("JAWTWindow.layoutSurfaceLayerImpl: "+toHexString(layerHandle) + ", quirks "+caLayerQuirks+", visible "+visible+ ", [ins "+outterInsets+"], p0 "+p0+" -> "+p1+", bounds "+bounds); } - OSXUtil.FixCALayerLayout(rootSurfaceLayer, layerHandle, visible, p1.getX(), p1.getY(), getWidth(), getHeight(), caLayerQuirks); + OSXUtil.FixCALayerLayout(rootSurfaceLayer, layerHandle, visible, p1.getX(), p1.getY(), getWindowWidth(), getWindowHeight(), caLayerQuirks); } @Override @@ -256,7 +256,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface { unlockSurfaceImpl(); return NativeWindow.LOCK_SURFACE_NOT_READY; } - updateBounds(dsi.getBounds()); + updateLockedData(dsi.getBounds()); if (DEBUG && firstLock ) { dumpInfo(); } @@ -309,7 +309,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface { public void run() { String errMsg = null; if(0 == rootSurfaceLayer && 0 != jawtSurfaceLayersHandle) { - rootSurfaceLayer = OSXUtil.CreateCALayer(bounds.getWidth(), bounds.getHeight()); + rootSurfaceLayer = OSXUtil.CreateCALayer(bounds.getWidth(), bounds.getHeight(), getPixelScale()); if(0 == rootSurfaceLayer) { errMsg = "Could not create root CALayer"; } else { diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/windows/WindowsJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/windows/WindowsJAWTWindow.java index 54bdb34f6..90688258d 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/windows/WindowsJAWTWindow.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/windows/WindowsJAWTWindow.java @@ -98,7 +98,7 @@ public class WindowsJAWTWindow extends JAWTWindow { unlockSurfaceImpl(); return LOCK_SURFACE_NOT_READY; } - updateBounds(dsi.getBounds()); + updateLockedData(dsi.getBounds()); win32dsi = (JAWT_Win32DrawingSurfaceInfo) dsi.platformInfo(getJAWT()); if (win32dsi == null) { unlockSurfaceImpl(); diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTWindow.java index 4599b9021..b5a519fcc 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTWindow.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTWindow.java @@ -93,7 +93,7 @@ public class X11JAWTWindow extends JAWTWindow { unlockSurfaceImpl(); return LOCK_SURFACE_NOT_READY; } - updateBounds(dsi.getBounds()); + updateLockedData(dsi.getBounds()); x11dsi = (JAWT_X11DrawingSurfaceInfo) dsi.platformInfo(getJAWT()); if (x11dsi == null) { unlockSurfaceImpl(); diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXDummyUpstreamSurfaceHook.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXDummyUpstreamSurfaceHook.java index b71af1042..5a51aca3e 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXDummyUpstreamSurfaceHook.java +++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXDummyUpstreamSurfaceHook.java @@ -11,10 +11,10 @@ public class OSXDummyUpstreamSurfaceHook extends UpstreamSurfaceHookMutableSize long nsWindow; /** - * @param width the initial width as returned by {@link NativeSurface#getWidth()} via {@link UpstreamSurfaceHook#getWidth(ProxySurface)}, + * @param width the initial width as returned by {@link NativeSurface#getSurfaceWidth()} via {@link UpstreamSurfaceHook#getPixelWidth(ProxySurface)}, * not the actual dummy surface width. * The latter is platform specific and small - * @param height the initial height as returned by {@link NativeSurface#getHeight()} via {@link UpstreamSurfaceHook#getHeight(ProxySurface)}, + * @param height the initial height as returned by {@link NativeSurface#getSurfaceHeight()} via {@link UpstreamSurfaceHook#getPixelHeight(ProxySurface)}, * not the actual dummy surface height, * The latter is platform specific and small */ diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java index bac07b85a..88ba531d1 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java @@ -137,11 +137,15 @@ public class OSXUtil implements ToolkitProperties { /** * Create a CALayer suitable to act as a root CALayer. + * @param width width of the CALayer in window units (points) + * @param height height of the CALayer in window units (points) + * @param contentsScale scale for HiDPI support: pixel-dim = window-dim x scale + * @return the new CALayer object * @see #DestroyCALayer(long) * @see #AddCASublayer(long, long) */ - public static long CreateCALayer(final int width, final int height) { - final long l = CreateCALayer0(width, height); + public static long CreateCALayer(final int width, final int height, final float contentsScale) { + final long l = CreateCALayer0(width, height, contentsScale); if(DEBUG) { System.err.println("OSXUtil.CreateCALayer: 0x"+Long.toHexString(l)+" - "+Thread.currentThread().getName()); } @@ -158,18 +162,27 @@ public class OSXUtil implements ToolkitProperties { * Hence it is important that related resources are not locked <i>if</i> * they will be used for creation. * </p> - * @param caLayerQuirks TODO - * @see #CreateCALayer(int, int) + * @param rootCALayer + * @param subCALayer + * @param x x-coord of the sub-CALayer in window units (points) + * @param y y-coord of the sub-CALayer in window units (points) + * @param width width of the sub-CALayer in window units (points) + * @param height height of the sub-CALayer in window units (points) + * @param contentsScale scale for HiDPI support: pixel-dim = window-dim x scale + * @param caLayerQuirks + * @see #CreateCALayer(int, int, float) * @see #RemoveCASublayer(long, long, boolean) */ - public static void AddCASublayer(final long rootCALayer, final long subCALayer, final int x, final int y, final int width, final int height, final int caLayerQuirks) { + public static void AddCASublayer(final long rootCALayer, final long subCALayer, + final int x, final int y, final int width, final int height, + final float contentsScale, final int caLayerQuirks) { if(0==rootCALayer || 0==subCALayer) { throw new IllegalArgumentException("rootCALayer 0x"+Long.toHexString(rootCALayer)+", subCALayer 0x"+Long.toHexString(subCALayer)); } if(DEBUG) { System.err.println("OSXUtil.AttachCALayer: caLayerQuirks "+caLayerQuirks+", 0x"+Long.toHexString(subCALayer)+" - "+Thread.currentThread().getName()); } - AddCASublayer0(rootCALayer, subCALayer, x, y, width, height, caLayerQuirks); + AddCASublayer0(rootCALayer, subCALayer, x, y, width, height, contentsScale, caLayerQuirks); } /** @@ -186,8 +199,8 @@ public class OSXUtil implements ToolkitProperties { * @param rootCALayer the root surface layer, maybe null. * @param subCALayer the client surface layer, maybe null. * @param visible TODO - * @param width the expected width - * @param height the expected height + * @param width the expected width in window units (points) + * @param height the expected height in window units (points) * @param caLayerQuirks TODO */ public static void FixCALayerLayout(final long rootCALayer, final long subCALayer, final boolean visible, final int x, final int y, final int width, final int height, final int caLayerQuirks) { @@ -212,7 +225,7 @@ public class OSXUtil implements ToolkitProperties { /** * Destroy a CALayer. - * @see #CreateCALayer(int, int) + * @see #CreateCALayer(int, int, float) */ public static void DestroyCALayer(final long caLayer) { if(0==caLayer) { @@ -356,8 +369,8 @@ public class OSXUtil implements ToolkitProperties { private static native void DestroyNSWindow0(long nsWindow); private static native long GetNSView0(long nsWindow); private static native long GetNSWindow0(long nsView); - private static native long CreateCALayer0(int width, int height); - private static native void AddCASublayer0(long rootCALayer, long subCALayer, int x, int y, int width, int height, int caLayerQuirks); + private static native long CreateCALayer0(int width, int height, float contentsScale); + private static native void AddCASublayer0(long rootCALayer, long subCALayer, int x, int y, int width, int height, float contentsScale, int caLayerQuirks); private static native void FixCALayerLayout0(long rootCALayer, long subCALayer, boolean visible, int x, int y, int width, int height, int caLayerQuirks); private static native void RemoveCASublayer0(long rootCALayer, long subCALayer); private static native void DestroyCALayer0(long caLayer); diff --git a/src/nativewindow/classes/jogamp/nativewindow/windows/GDIDummyUpstreamSurfaceHook.java b/src/nativewindow/classes/jogamp/nativewindow/windows/GDIDummyUpstreamSurfaceHook.java index e5de43c0a..9c74950e0 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/windows/GDIDummyUpstreamSurfaceHook.java +++ b/src/nativewindow/classes/jogamp/nativewindow/windows/GDIDummyUpstreamSurfaceHook.java @@ -9,10 +9,10 @@ import com.jogamp.nativewindow.UpstreamSurfaceHookMutableSize; public class GDIDummyUpstreamSurfaceHook extends UpstreamSurfaceHookMutableSize { /** - * @param width the initial width as returned by {@link NativeSurface#getWidth()} via {@link UpstreamSurfaceHook#getWidth(ProxySurface)}, + * @param width the initial width as returned by {@link NativeSurface#getSurfaceWidth()} via {@link UpstreamSurfaceHook#getPixelWidth(ProxySurface)}, * not the actual dummy surface width. * The latter is platform specific and small - * @param height the initial height as returned by {@link NativeSurface#getHeight()} via {@link UpstreamSurfaceHook#getHeight(ProxySurface)}, + * @param height the initial height as returned by {@link NativeSurface#getSurfaceHeight()} via {@link UpstreamSurfaceHook#getPixelHeight(ProxySurface)}, * not the actual dummy surface height, * The latter is platform specific and small */ diff --git a/src/nativewindow/classes/jogamp/nativewindow/windows/GDISurface.java b/src/nativewindow/classes/jogamp/nativewindow/windows/GDISurface.java index 3e07b2a9e..c4ec0f653 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/windows/GDISurface.java +++ b/src/nativewindow/classes/jogamp/nativewindow/windows/GDISurface.java @@ -128,4 +128,21 @@ public class GDISurface extends ProxySurfaceImpl { final public long getSurfaceHandle() { return surfaceHandle; } + + @Override + public final int[] getWindowUnitXY(int[] result, final int[] pixelUnitXY) { + if( pixelUnitXY != result ) { // no scale factor, window units == pixel units + System.arraycopy(pixelUnitXY, 0, result, 0, 2); + } + return result; + } + + @Override + public final int[] getPixelUnitXY(int[] result, final int[] windowUnitXY) { + if( windowUnitXY != result ) { // no scale factor, window units == pixel units + System.arraycopy(windowUnitXY, 0, result, 0, 2); + } + return result; + } + } diff --git a/src/nativewindow/classes/jogamp/nativewindow/x11/X11DummyUpstreamSurfaceHook.java b/src/nativewindow/classes/jogamp/nativewindow/x11/X11DummyUpstreamSurfaceHook.java index 2c8ef642c..31d168fea 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/x11/X11DummyUpstreamSurfaceHook.java +++ b/src/nativewindow/classes/jogamp/nativewindow/x11/X11DummyUpstreamSurfaceHook.java @@ -14,10 +14,10 @@ import com.jogamp.nativewindow.x11.X11GraphicsScreen; public class X11DummyUpstreamSurfaceHook extends UpstreamSurfaceHookMutableSize { /** - * @param width the initial width as returned by {@link NativeSurface#getWidth()} via {@link UpstreamSurfaceHook#getWidth(ProxySurface)}, + * @param width the initial width as returned by {@link NativeSurface#getSurfaceWidth()} via {@link UpstreamSurfaceHook#getPixelWidth(ProxySurface)}, * not the actual dummy surface width. * The latter is platform specific and small - * @param height the initial height as returned by {@link NativeSurface#getHeight()} via {@link UpstreamSurfaceHook#getHeight(ProxySurface)}, + * @param height the initial height as returned by {@link NativeSurface#getSurfaceHeight()} via {@link UpstreamSurfaceHook#getPixelHeight(ProxySurface)}, * not the actual dummy surface height, * The latter is platform specific and small */ diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m index d95d1cdbf..15547ffee 100644 --- a/src/nativewindow/native/macosx/OSXmisc.m +++ b/src/nativewindow/native/macosx/OSXmisc.m @@ -41,7 +41,7 @@ #include <jawt_md.h> -// #define VERBOSE 1 +#define VERBOSE 1 // #ifdef VERBOSE // #define DBG_PRINT(...) NSLog(@ ## __VA_ARGS__) @@ -544,19 +544,27 @@ JNIEXPORT jlong JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetNSWindow0 /* * Class: Java_jogamp_nativewindow_macosx_OSXUtil * Method: CreateCALayer0 - * Signature: (II)J + * Signature: (IIF)J */ JNIEXPORT jlong JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_CreateCALayer0 - (JNIEnv *env, jclass unused, jint width, jint height) + (JNIEnv *env, jclass unused, jint width, jint height, jfloat contentsScale) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; MyCALayer* layer = [[MyCALayer alloc] init]; - DBG_PRINT("CALayer::CreateCALayer.0: root %p 0/0 %dx%d (refcnt %d)\n", layer, (int)width, (int)height, (int)[layer retainCount]); + DBG_PRINT("CALayer::CreateCALayer.0: root %p 0/0 %dx%d @ scale %lf (refcnt %d)\n", layer, (int)width, (int)height, (double)contentsScale, (int)[layer retainCount]); // avoid zero size if(0 == width) { width = 32; } if(0 == height) { height = 32; } + if( 1.0 != contentsScale ) { +NS_DURING + // Available >= 10.7 + [layer setContentsScale: (CGFloat)contentsScale]; +NS_HANDLER +NS_ENDHANDLER + } + // initial dummy size ! CGRect lFrame = [layer frame]; lFrame.origin.x = 0; @@ -580,10 +588,10 @@ JNIEXPORT jlong JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_CreateCALayer0 /* * Class: Java_jogamp_nativewindow_macosx_OSXUtil * Method: AddCASublayer0 - * Signature: (JJIIIII)V + * Signature: (JJIIIIIF)V */ JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_AddCASublayer0 - (JNIEnv *env, jclass unused, jlong rootCALayer, jlong subCALayer, jint x, jint y, jint width, jint height, jint caLayerQuirks) + (JNIEnv *env, jclass unused, jlong rootCALayer, jlong subCALayer, jint x, jint y, jint width, jint height, jfloat contentsScale, jint caLayerQuirks) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; MyCALayer* rootLayer = (MyCALayer*) ((intptr_t) rootCALayer); @@ -596,9 +604,18 @@ JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_AddCASublayer0 [subLayer retain]; // Pairs w/ RemoveCASublayer CGRect lRectRoot = [rootLayer frame]; - DBG_PRINT("CALayer::AddCASublayer0.0: Quirks %d, Root %p (refcnt %d), Sub %p (refcnt %d), frame0: %lf/%lf %lfx%lf\n", + + // Available >= 10.7 + DBG_PRINT("CALayer::AddCASublayer0.0: Quirks %d, Root %p (refcnt %d), Sub %p (refcnt %d), frame0: %lf/%lf %lfx%lf scale %lf\n", caLayerQuirks, rootLayer, (int)[rootLayer retainCount], subLayer, (int)[subLayer retainCount], - lRectRoot.origin.x, lRectRoot.origin.y, lRectRoot.size.width, lRectRoot.size.height); + lRectRoot.origin.x, lRectRoot.origin.y, lRectRoot.size.width, lRectRoot.size.height, (float)contentsScale); + + if( 1.0 != contentsScale ) { +NS_DURING + [subLayer setContentsScale: (CGFloat)contentsScale]; +NS_HANDLER +NS_ENDHANDLER + } [subLayer setFrame:lRectRoot]; [rootLayer addSublayer:subLayer]; |