From 2571ed0b5ef14155d204540d38b564a7d4cd47b6 Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Sun, 8 Jun 2014 08:11:57 +0200
Subject: Bug 741 HiDPI: Add ScalableSurface interface to get/set pixelScale w/
 full OSX impl.

Add ScalableSurface interface
  - To set pixelScale before and after realization
  - To get pixelScale

  - Implemented on:
    - NEWT Window
      - Generic impl. in WindowImpl
      - OSX WindowDriver impl.
        - Also propagetes pixelScale to parent JAWTWindow if offscreen (NewtCanvasAWT)
      - AWT WindowDriver impl.

    - JAWTWindow / OSXCalayer
      - AWT GLCanvas
      - AWT GLJPanel
      - NEWTCanvasAWT:
        - Propagates NEWT Window's pixelScale to underlying JAWTWindow

    - WrappedSurface for pixelScale propagation
      using offscreen drawables, i.e. GLJPanel

    - Generic helper in SurfaceScaleUtils (nativewindow package)

  - Fully implemented on OSX

  - Capable to switch pixelScale before realization,
    i.e. native-creation, as well as on-the-fly.

  - Impl. uses int[2] for pixelScale to support
    non-uniform scale.

Test cases:
  - com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT
  - com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2AWT
  - com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2GLJPanelAWT
  - com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NewtCanvasAWT

  - Press 'x' to toggle HiDPI
  - Commandline '-pixelScale <value>'
  - Added basic auto unit test (setting pre-realization)
---
 src/newt/classes/com/jogamp/newt/Window.java            |  3 ++-
 src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java |  1 +
 src/newt/classes/com/jogamp/newt/opengl/GLWindow.java   | 10 ++++++++++
 3 files changed, 13 insertions(+), 1 deletion(-)

(limited to 'src/newt/classes/com')

diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java
index 82199e9b5..88134f3ef 100644
--- a/src/newt/classes/com/jogamp/newt/Window.java
+++ b/src/newt/classes/com/jogamp/newt/Window.java
@@ -45,6 +45,7 @@ import jogamp.newt.WindowImpl;
 import javax.media.nativewindow.CapabilitiesChooser;
 import javax.media.nativewindow.CapabilitiesImmutable;
 import javax.media.nativewindow.NativeWindow;
+import javax.media.nativewindow.ScalableSurface;
 import javax.media.nativewindow.WindowClosingProtocol;
 import javax.media.nativewindow.util.Rectangle;
 import javax.media.nativewindow.util.RectangleImmutable;
@@ -94,7 +95,7 @@ import javax.media.nativewindow.util.RectangleImmutable;
  * </pre>
  * </p>
  */
-public interface Window extends NativeWindow, WindowClosingProtocol {
+public interface Window extends NativeWindow, WindowClosingProtocol, ScalableSurface {
     public static final boolean DEBUG_MOUSE_EVENT = Debug.debug("Window.MouseEvent");
     public static final boolean DEBUG_KEY_EVENT = Debug.debug("Window.KeyEvent");
     public static final boolean DEBUG_IMPLEMENTATION = Debug.debug("Window");
diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
index 37e9f9813..baaa69e8e 100644
--- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
+++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
@@ -865,6 +865,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
       }
       newtChild.setVisible(false);
       newtChild.setSize(w, h);
+      jawtWindow.setSurfaceScale(newtChild.getSurfaceScale(new int[2]));
       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 a61085fb0..6610bd74f 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.convertToPixelUnits(windowUnitsAndResult);
     }
 
+    @Override
+    public final void setSurfaceScale(final int[] pixelScale) {
+        window.setSurfaceScale(pixelScale);
+    }
+
+    @Override
+    public final int[] getSurfaceScale(final int[] result) {
+        return window.getSurfaceScale(result);
+    }
+
     @Override
     public final void setPosition(int x, int y) {
         window.setPosition(x, y);
-- 
cgit v1.2.3