Skip to content

Commit

Permalink
Bug 1176: BCM VC IV: Refine clamping of window position and size at n…
Browse files Browse the repository at this point in the history
…ative creation

- Refines commit a566a1b

- 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.
  • Loading branch information
sgothel committed Jul 17, 2015
1 parent 1584cae commit 51268bc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
42 changes: 29 additions & 13 deletions src/newt/classes/jogamp/newt/driver/bcm/vc/iv/WindowDriver.java
Expand Up @@ -69,52 +69,70 @@ public WindowDriver() {
*
* @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()) {
Expand Down Expand Up @@ -162,10 +180,8 @@ protected void createNativeImpl() {
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);
Expand Down Expand Up @@ -210,7 +226,7 @@ protected void requestFocusImpl(final boolean reparented) {

@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;
Expand Down
2 changes: 0 additions & 2 deletions src/newt/native/bcm_vc_iv.c
Expand Up @@ -402,8 +402,6 @@ 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);
Expand Down

0 comments on commit 51268bc

Please sign in to comment.