diff options
author | Sven Gothel <[email protected]> | 2015-07-17 03:23:36 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2015-07-17 03:23:36 +0200 |
commit | a566a1b5a2828b38f1a5c4dfb215ab9b03e7acaa (patch) | |
tree | 3aa3082f9855762aedb58952e1dbf72a0554ce8b | |
parent | 0b62f343f5c2ca74d10d86c435099ce0e0ab89db (diff) |
Bug 1176: Clamp window position and size to 0/0 and screen-size, avoiding out-of screen window positions on BCM VC IV hardware
Out of screen window positions on BCM VC IV hardware cause:
- Misalignment of self-rendered mouse-pointer / window
due to window-offset.
- Artifacts when moving the mouse pointer partially
out of screen.
We still need to add the window position to rel. mouse-pointer position.
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/bcm/vc/iv/WindowDriver.java | 63 | ||||
-rw-r--r-- | src/newt/native/bcm_vc_iv.c | 4 |
2 files changed, 63 insertions, 4 deletions
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 29c7f9898..1ee60f4da 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 @@ -37,7 +37,8 @@ import com.jogamp.nativewindow.NativeWindowException; import com.jogamp.nativewindow.VisualIDHolder; import com.jogamp.nativewindow.util.Insets; import com.jogamp.nativewindow.util.Point; - +import com.jogamp.nativewindow.util.Rectangle; +import com.jogamp.nativewindow.util.RectangleImmutable; import com.jogamp.common.util.IntBitfield; import com.jogamp.nativewindow.egl.EGLGraphicsDevice; import com.jogamp.newt.event.MouseEvent; @@ -63,6 +64,57 @@ public class WindowDriver extends WindowImpl { windowHandleClose = 0; } + /** + * Clamp given rectangle to given screen bounds. + * + * @param screen + * @param rect the {@link RectangleImmutable} in pixel units + * @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) { + 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; + if( 0 > x ) { + x = 0; + mod = true; + } + if( 0 > y ) { + y = 0; + mod = true; + } + if( s_w < x + w ) { + if( 0 < x ) { + x = 0; + mod = true; + } + if( s_w < w ) { + w = s_w; + mod = true; + } + } + if( s_h < y + h ) { + if( 0 < y ) { + y = 0; + mod = true; + } + if( s_h < h ) { + h = s_h; + mod = true; + } + } + if( mod ) { + return new Rectangle(x, y, w, h); + } else { + return rect; + } + } + @Override protected void createNativeImpl() { if(0!=getParentWindowHandle()) { @@ -110,7 +162,10 @@ public class WindowDriver extends WindowImpl { chosenCaps.setBackgroundOpaque(capsRequested.isBackgroundOpaque()); } setGraphicsConfiguration(cfg); - nativeWindowHandle = CreateWindow0(display.getBCMHandle(), layer, getX(), getY(), getWidth(), getHeight(), + // 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(), chosenCaps.isBackgroundOpaque(), chosenCaps.getAlphaBits()); if (nativeWindowHandle == 0) { throw new NativeWindowException("Error creating egl window: "+cfg); @@ -155,7 +210,9 @@ public class WindowDriver extends WindowImpl { @Override protected boolean reconfigureWindowImpl(final int x, final int y, final int width, final int height, final int flags) { - reconfigure0(nativeWindowHandle, x, y, width, height, flags); + final RectangleImmutable rect = clampRect((ScreenDriver) getScreen(), new Rectangle(x, y, width, height)); + // reconfigure0 will issue position/size changed events if required + reconfigure0(nativeWindowHandle, rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight(), flags); return true; } diff --git a/src/newt/native/bcm_vc_iv.c b/src/newt/native/bcm_vc_iv.c index 6b1ee3aaf..487941e38 100644 --- a/src/newt/native/bcm_vc_iv.c +++ b/src/newt/native/bcm_vc_iv.c @@ -402,6 +402,8 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_bcm_vc_iv_WindowDriver_CreateWin vc_dispmanx_update_submit_sync( dispman_update ); (*env)->CallVoidMethod(env, obj, visibleChangedID, JNI_FALSE, JNI_TRUE); // FIXME: or defer=true ? + (*env)->CallVoidMethod(env, obj, positionChangedID, JNI_FALSE, x, y); // always report pos-change (clamping) + (*env)->CallVoidMethod(env, obj, sizeChangedID, JNI_FALSE, width, height, JNI_FALSE); // always report size-change (clamping) DBG_PRINT( "BCM.Display Window.Create.X %p, element %p\n", (void*)(intptr_t)dispman_display, (void*)(intptr_t)p->handle); @@ -457,7 +459,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_bcm_vc_iv_WindowDriver_reconfigur (*env)->CallVoidMethod(env, obj, positionChangedID, JNI_FALSE, x, y); } if( sizeChanged ) { - (*env)->CallVoidMethod(env, obj, sizeChangedID, JNI_FALSE, (jint) width, (jint) height, JNI_FALSE); + (*env)->CallVoidMethod(env, obj, sizeChangedID, JNI_FALSE, width, height, JNI_FALSE); } } |