From 51268bc9874de7cc34dfe7741187238f7d46aafc Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Fri, 17 Jul 2015 04:39:53 +0200
Subject: Bug 1176: BCM VC IV: Refine clamping of window position and size at
 native creation

- Refines commit a566a1b5a2828b38f1a5c4dfb215ab9b03e7acaa

- Issue clamping at 'canCreateNativeImpl()' instead of 'createNativeImpl()',
  allowing to define clamped position and size before utilizing these values
  at caller 'createNative()'.
  Otherwise a clamped position would cause to wait for the original position
  after 'createNativeImpl()'.

  This also allows to remove the positionChanged(..) / sizeChanged(..) calls in
  the native CreateWindow0() implementation.
---
 .../jogamp/newt/driver/bcm/vc/iv/WindowDriver.java | 42 +++++++++++++++-------
 1 file changed, 29 insertions(+), 13 deletions(-)

(limited to 'src/newt/classes')

diff --git a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/WindowDriver.java
index 9423949e4..93c28d370 100644
--- a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/WindowDriver.java
@@ -69,52 +69,70 @@ public class WindowDriver extends WindowImpl {
      *
      * @param screen
      * @param rect the {@link RectangleImmutable} in pixel units
+     * @param definePosSize if {@code true} issue {@link #definePosition(int, int)} and {@link #defineSize(int, int)}
+     *                      if either has changed.
      * @return If position or size has been clamped a new {@link RectangleImmutable} instance w/ clamped values
      *         will be returned, otherwise the given {@code rect} is returned.
      */
-    private RectangleImmutable clampRect(final ScreenDriver screen, final RectangleImmutable rect) {
+    private RectangleImmutable clampRect(final ScreenDriver screen, final RectangleImmutable rect, final boolean definePosSize) {
         int x = rect.getX();
         int y = rect.getY();
         int w = rect.getWidth();
         int h = rect.getHeight();
         final int s_w = screen.getWidth();
         final int s_h = screen.getHeight();
-        boolean mod = false;
+        boolean modPos = false;
+        boolean modSize = false;
         if( 0 > x ) {
             x = 0;
-            mod = true;
+            modPos = true;
         }
         if( 0 > y ) {
             y = 0;
-            mod = true;
+            modPos = true;
         }
         if( s_w < x + w ) {
             if( 0 < x ) {
                 x = 0;
-                mod = true;
+                modPos = true;
             }
             if( s_w < w ) {
                 w = s_w;
-                mod = true;
+                modSize = true;
             }
         }
         if( s_h < y + h ) {
             if( 0 < y ) {
                 y = 0;
-                mod = true;
+                modPos = true;
             }
             if( s_h < h ) {
                 h = s_h;
-                mod = true;
+                modSize = true;
             }
         }
-        if( mod ) {
+        if( modPos || modSize ) {
+            if( definePosSize ) {
+                if( modPos ) {
+                    definePosition(x, y);
+                }
+                if( modSize ) {
+                    defineSize(w, h);
+                }
+            }
             return new Rectangle(x, y, w, h);
         } else {
             return rect;
         }
     }
 
+    @Override
+    protected boolean canCreateNativeImpl() {
+        // clamp if required incl. redefinition of position and size
+        clampRect((ScreenDriver) getScreen(), new Rectangle(getX(), getY(), getWidth(), getHeight()), true);
+        return true; // default: always able to be created
+    }
+
     @Override
     protected void createNativeImpl() {
         if(0!=getParentWindowHandle()) {
@@ -162,10 +180,8 @@ public class WindowDriver extends WindowImpl {
             chosenCaps.setBackgroundOpaque(capsRequested.isBackgroundOpaque());
         }
         setGraphicsConfiguration(cfg);
-        // CreateWindow0 will issue position/size changed event if clamped and required
-        final RectangleImmutable rect = clampRect(screen, new Rectangle(getX(), getY(), getWidth(), getHeight()));
         nativeWindowHandle = CreateWindow0(display.getBCMHandle(), layer,
-                                           rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight(),
+                                           getX(), getY(), getWidth(), getHeight(),
                                            chosenCaps.isBackgroundOpaque(), chosenCaps.getAlphaBits());
         if (nativeWindowHandle == 0) {
             throw new NativeWindowException("Error creating egl window: "+cfg);
@@ -210,7 +226,7 @@ public class WindowDriver extends WindowImpl {
 
     @Override
     protected boolean reconfigureWindowImpl(final int x, final int y, final int width, final int height, final int flags) {
-        final RectangleImmutable rect = clampRect((ScreenDriver) getScreen(), new Rectangle(x, y, width, height));
+        final RectangleImmutable rect = clampRect((ScreenDriver) getScreen(), new Rectangle(x, y, width, height), false);
         // reconfigure0 will issue position/size changed events if required
         reconfigure0(nativeWindowHandle, rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight(), flags);
         return true;
-- 
cgit v1.2.3