From 58153310faa4089417037e67e06c0812908cecd2 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 8 Jun 2014 18:04:51 +0200 Subject: Bug 741 HiDPI: Simplify ScalableSurface (2): Add request pixelScale API entry, fixed NewtCanvasAWT use-case We require the requested pixelScale in NewtCanvasAWT if the NEWT window (child) is not yet realized, so the JAWTWindow can receive the request, since realized/current pixelScale is still 1. Remove return value (requested pixel scale): - public int[] setSurfaceScale(final int[] result, final int[] pixelScale); + public void setSurfaceScale(final int[] pixelScale); Add API hook to query requested pixel scale: + int[] getRequestedSurfaceScale(final int[] result); Unique name for get[Current]*: - public int[] getSurfaceScale(final int[] result); + public int[] getCurrentSurfaceScale(final int[] result); --- src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java | 11 +++++++++-- src/newt/classes/com/jogamp/newt/opengl/GLWindow.java | 13 +++++++++---- src/newt/classes/jogamp/newt/WindowImpl.java | 12 +++++++----- src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java | 4 ++-- .../classes/jogamp/newt/driver/macosx/WindowDriver.java | 10 +++------- 5 files changed, 30 insertions(+), 20 deletions(-) (limited to 'src/newt/classes') diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java index f5e4ff43f..48c7cd5bf 100644 --- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java +++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java @@ -860,12 +860,19 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto } final int w = getWidth(); final int h = getHeight(); + final boolean isNValid = newtChild.isNativeValid(); if(DEBUG) { - System.err.println("NewtCanvasAWT.attachNewtChild.2: size "+w+"x"+h); + System.err.println("NewtCanvasAWT.attachNewtChild.2: size "+w+"x"+h+", isNValid "+isNValid); } newtChild.setVisible(false); newtChild.setSize(w, h); - jawtWindow.setSurfaceScale(null, newtChild.getSurfaceScale(new int[2])); + final int[] reqSurfaceScale = new int[2]; + if( isNValid ) { + newtChild.getCurrentSurfaceScale(reqSurfaceScale); + } else { + newtChild.getRequestedSurfaceScale(reqSurfaceScale); + } + jawtWindow.setSurfaceScale(reqSurfaceScale); newtChild.reparentWindow(jawtWindow, -1, -1, Window.REPARENT_HINT_BECOMES_VISIBLE); newtChild.addSurfaceUpdatedListener(jawtWindow); if( jawtWindow.isOffscreenLayerSurfaceEnabled() && diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index ae99b7465..25297917b 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -404,13 +404,18 @@ public class GLWindow extends GLAutoDrawableBase implements GLAutoDrawable, Wind } @Override - public final int[] setSurfaceScale(final int[] result, final int[] pixelScale) { - return window.setSurfaceScale(result, pixelScale); + public final void setSurfaceScale(final int[] pixelScale) { + window.setSurfaceScale(pixelScale); } @Override - public final int[] getSurfaceScale(final int[] result) { - return window.getSurfaceScale(result); + public final int[] getRequestedSurfaceScale(final int[] result) { + return window.getRequestedSurfaceScale(result); + } + + @Override + public final int[] getCurrentSurfaceScale(final int[] result) { + return window.getCurrentSurfaceScale(result); } @Override diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index d68a1dfd4..0df105ff0 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -1968,16 +1968,18 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } @Override - public int[] setSurfaceScale(final int[] result, final int[] pixelScale) { + public void setSurfaceScale(final int[] pixelScale) { SurfaceScaleUtils.validateReqPixelScale(reqPixelScale, pixelScale, DEBUG_IMPLEMENTATION ? getClass().getSimpleName() : null); - if( null != result ) { - System.arraycopy(reqPixelScale, 0, result, 0, 2); - } + } + + @Override + public final int[] getRequestedSurfaceScale(final int[] result) { + System.arraycopy(reqPixelScale, 0, result, 0, 2); return result; } @Override - public final int[] getSurfaceScale(final int[] result) { + public final int[] getCurrentSurfaceScale(final int[] result) { System.arraycopy(hasPixelScale, 0, result, 0, 2); return result; } diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java b/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java index e3c4e3b87..540d9b7e8 100644 --- a/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java +++ b/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java @@ -146,9 +146,9 @@ public class AWTCanvas extends Canvas { { jawtWindow = (JAWTWindow) NativeWindowFactory.getNativeWindow(this, awtConfig); // trigger initialization cycle - jawtWindow.setSurfaceScale(null, upstreamScale.getReqPixelScale() ); + jawtWindow.setSurfaceScale(upstreamScale.getReqPixelScale() ); jawtWindow.lockSurface(); - upstreamScale.setHasPixelScale(jawtWindow.getSurfaceScale(new int[2])); + upstreamScale.setHasPixelScale(jawtWindow.getCurrentSurfaceScale(new int[2])); jawtWindow.unlockSurface(); } diff --git a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java index 07d31acfd..498556630 100644 --- a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java @@ -135,11 +135,8 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl } @Override - public final int[] setSurfaceScale(final int[] result, final int[] pixelScale) { + public final void setSurfaceScale(final int[] pixelScale) { SurfaceScaleUtils.validateReqPixelScale(reqPixelScale, pixelScale, DEBUG_IMPLEMENTATION ? getClass().getName() : null); - if( null != result ) { - System.arraycopy(reqPixelScale, 0, result, 0, 2); - } final int[] resPixelScale; if( isNativeValid() ) { @@ -147,8 +144,8 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl final NativeWindow pWin = getParent(); if( pWin instanceof ScalableSurface ) { final ScalableSurface sSurf = (ScalableSurface)pWin; - sSurf.setSurfaceScale(result, reqPixelScale); - final int[] pPixelScale = sSurf.getSurfaceScale(new int[2]); + sSurf.setSurfaceScale(reqPixelScale); + final int[] pPixelScale = sSurf.getCurrentSurfaceScale(new int[2]); updatePixelScale(true /* sendEvent */, true /* defer */, pPixelScale[0]); // HiDPI: uniformPixelScale } else { // just notify updated pixelScale if offscreen @@ -175,7 +172,6 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl reqPixelScale[0]+"x"+reqPixelScale[1]+" (validated) -> "+ resPixelScale[0]+"x"+resPixelScale[1]+" (result) - realized "+isNativeValid()); } - return result; } @Override -- cgit v1.2.3