aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/classes/com/jogamp
diff options
context:
space:
mode:
Diffstat (limited to 'src/newt/classes/com/jogamp')
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/WindowImpl.java71
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java64
-rw-r--r--src/newt/classes/com/jogamp/newt/opengl/GLWindow.java5
3 files changed, 60 insertions, 80 deletions
diff --git a/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java b/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java
index 7d80712e6..dfa768147 100644
--- a/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java
+++ b/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java
@@ -163,11 +163,21 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer, ScreenMod
*/
void destroyActionInLock(boolean unrecoverable);
- /** Only informal, when starting reparenting */
- void reparentActionPre();
+ /**
+ * Invoked for expensive modifications, ie while reparenting and ScreenMode change.<br>
+ * No lock is hold when invoked.<br>
+ *
+ * @see #resumeRenderingAction()
+ */
+ void pauseRenderingAction();
- /** Only informal, when finishing reparenting */
- void reparentActionPost(int reparentActionType);
+ /**
+ * Invoked for expensive modifications, ie while reparenting and ScreenMode change.
+ * No lock is hold when invoked.<br>
+ *
+ * @see #pauseRenderingAction()
+ */
+ void resumeRenderingAction();
}
private LifecycleHook lifecycleHook = null;
@@ -475,13 +485,11 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer, ScreenMod
class VisibleAction implements Runnable {
boolean visible;
- long timeOut;
boolean nativeWindowCreated;
boolean madeVisible;
- public VisibleAction (boolean visible, long timeOut) {
+ public VisibleAction (boolean visible) {
this.visible = visible;
- this.timeOut = timeOut;
this.nativeWindowCreated = false;
this.madeVisible = false;
}
@@ -510,13 +518,13 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer, ScreenMod
if(0==windowHandle && visible) {
if( 0<width*height ) {
nativeWindowCreated = createNative();
- WindowImpl.this.waitForVisible(visible, true, timeOut);
+ WindowImpl.this.waitForVisible(visible, true);
madeVisible = visible;
}
} else if(WindowImpl.this.visible != visible) {
if(0 != windowHandle) {
setVisibleImpl(visible, x, y, width, height);
- WindowImpl.this.waitForVisible(visible, true, timeOut);
+ WindowImpl.this.waitForVisible(visible, true);
madeVisible = visible;
}
}
@@ -545,17 +553,12 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer, ScreenMod
}
public void setVisible(boolean visible) {
- setVisible(visible, TIMEOUT_NATIVEWINDOW);
-
- }
-
- protected final void setVisible(boolean visible, long timeOut) {
if(isValid()) {
if( 0==windowHandle && visible && 0>=width*height ) {
// fast-path: not realized yet, make visible, but zero size
return;
}
- VisibleAction visibleAction = new VisibleAction(visible, timeOut);
+ VisibleAction visibleAction = new VisibleAction(visible);
runOnEDTIfAvail(true, visibleAction);
if( visibleAction.getChanged() ) {
sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout and repaint to listener
@@ -1034,20 +1037,20 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer, ScreenMod
int reparentActionStrategy = ReparentAction.ACTION_INVALID;
if(isValid()) {
if(null!=lifecycleHook) {
- lifecycleHook.reparentActionPre();
+ // pause animation
+ lifecycleHook.pauseRenderingAction();
}
try {
ReparentActionImpl reparentAction = new ReparentActionImpl(newParent, forceDestroyCreate);
runOnEDTIfAvail(true, reparentAction);
reparentActionStrategy = reparentAction.getStrategy();
- if( isVisible() ) {
- sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout and repaint to listener
- }
} finally {
if(null!=lifecycleHook) {
- lifecycleHook.reparentActionPost(reparentActionStrategy);
+ // resume animation
+ lifecycleHook.resumeRenderingAction();
}
}
+ sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout and repaint to listener
}
return reparentActionStrategy;
}
@@ -1379,7 +1382,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer, ScreenMod
display.dispatchMessagesNative(); // status up2date
boolean wasVisible = isVisible();
setVisibleImpl(false, x, y, width, height);
- WindowImpl.this.waitForVisible(false, true, Screen.SCREEN_MODE_CHANGE_TIMEOUT);
+ WindowImpl.this.waitForVisible(false, true);
display.dispatchMessagesNative(); // status up2date
// write back mirrored values, to be able to detect satisfaction
@@ -1429,29 +1432,21 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer, ScreenMod
return this.fullscreen;
}
- boolean screenModeChangeVisible;
- boolean screenModeChangeFullscreen;
-
public void screenModeChangeNotify(ScreenMode sm) {
if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) {
System.err.println("Window.screenModeChangeNotify: "+sm);
}
- screenModeChangeFullscreen = isFullscreen();
- if(screenModeChangeFullscreen) {
- setFullscreen(false);
- }
- screenModeChangeVisible = isVisible();
- if(screenModeChangeVisible) {
- setVisible(false);
+
+ if(null!=lifecycleHook) {
+ // pause animation
+ lifecycleHook.pauseRenderingAction();
}
- windowLock.lock();
}
public void screenModeChanged(ScreenMode sm, boolean success) {
if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) {
System.err.println("Window.screenModeChanged: "+sm+", success: "+success);
}
- windowLock.unlock();
if(success) {
DimensionReadOnly screenSize = sm.getMonitorMode().getSurfaceSize().getResolution();
@@ -1460,11 +1455,11 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer, ScreenMod
setSize(screenSize.getWidth(), screenSize.getHeight());
}
}
- if(screenModeChangeFullscreen) {
- setFullscreen(true);
- }
- if(screenModeChangeVisible) {
- setVisible(true, Screen.SCREEN_MODE_CHANGE_TIMEOUT);
+
+ if(null!=lifecycleHook) {
+ // resume animation
+ lifecycleHook.resumeRenderingAction();
+ sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout and repaint to listener
}
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java
index 3f49b5e79..5e89a9972 100644
--- a/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java
+++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java
@@ -211,51 +211,34 @@ public class X11Screen extends ScreenImpl {
if(0>resIdx || resIdx>=resNumber) {
throw new RuntimeException("Invalid resolution index: ! 0 < "+resIdx+" < "+resNumber+", screenMode["+screenModeIdx+"] "+screenMode);
}
- String tname = Thread.currentThread()+"-X11Screen.setCurrentScreenModeImpl()";
- SetScreenModeAction setScreenModeAction = new SetScreenModeAction(screenMode, resIdx);
- Thread randrTask = new Thread(setScreenModeAction, tname);
- randrTask.start();
- int to = SCREEN_MODE_CHANGE_TIMEOUT / 100 ;
- while(to>0 && randrTask.isAlive()) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException ex) { }
- to--;
- }
- if(0==to && DEBUG) {
- System.err.println("X11Screen.setCurrentScreenModeImpl: TO ("+SCREEN_MODE_CHANGE_TIMEOUT+") reached: "+
- randrTask+", alive "+randrTask.isAlive());
- }
- return setScreenModeAction.getResult();
- }
-
- class SetScreenModeAction implements Runnable {
- boolean res;
- ScreenMode screenMode;
- int resIdx;
- public SetScreenModeAction(ScreenMode screenMode, int resIdx) {
- this.screenMode = screenMode;
- this.resIdx = resIdx;
- this.res = false;
+ long dpy = X11Util.createDisplay(display.getName());
+ if( 0 == dpy ) {
+ throw new RuntimeException("Error creating display: "+display.getName());
}
- public boolean getResult() {
- return res;
+ boolean done = false;
+ long t0 = System.currentTimeMillis();
+ try {
+ int f = screenMode.getMonitorMode().getRefreshRate();
+ int r = screenMode.getRotation();
+ if( setCurrentScreenModeStart0(dpy, screen_idx, resIdx, f, r) ) {
+ while(!done && System.currentTimeMillis()-t0 < SCREEN_MODE_CHANGE_TIMEOUT) {
+ done = setCurrentScreenModePollEnd0(dpy, screen_idx, resIdx, f, r);
+ if(!done) {
+ Thread.yield();
+ }
+ }
+ }
+ } finally {
+ X11Util.closeDisplay(dpy);
}
- public void run() {
- long dpy = X11Util.createDisplay(display.getName());
- if( 0 == dpy ) {
- throw new RuntimeException("Error creating display: "+display.getName());
- }
- try {
- res = setCurrentScreenMode0(dpy, screen_idx, resIdx,
- screenMode.getMonitorMode().getRefreshRate(), screenMode.getRotation());
- } finally {
- X11Util.closeDisplay(dpy);
- }
+ if(!done) {
+ System.err.println("X11Screen.setCurrentScreenModeImpl: TO ("+SCREEN_MODE_CHANGE_TIMEOUT+") reached: "+
+ (System.currentTimeMillis()-t0)+"ms");
}
+ return done;
}
//----------------------------------------------------------------------
@@ -282,5 +265,6 @@ public class X11Screen extends ScreenImpl {
private static native int getCurrentScreenRotation0(long display, int screen_index);
/** needs own Display connection for XRANDR event handling */
- private static native boolean setCurrentScreenMode0(long display, int screen_index, int mode_index, int freq, int rot);
+ private static native boolean setCurrentScreenModeStart0(long display, int screen_index, int mode_index, int freq, int rot);
+ private static native boolean setCurrentScreenModePollEnd0(long display, int screen_index, int mode_index, int freq, int rot);
}
diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
index 7836bec68..36302c55a 100644
--- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
+++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
@@ -367,7 +367,7 @@ public class GLWindow implements GLAutoDrawable, Window {
boolean animatorPaused = false;
- public synchronized void reparentActionPre() {
+ public synchronized void pauseRenderingAction() {
GLAnimatorControl ctrl = GLWindow.this.getAnimator();
if ( null!=ctrl && ctrl.isAnimating() && ctrl.getThread() != Thread.currentThread() ) {
animatorPaused = true;
@@ -375,7 +375,7 @@ public class GLWindow implements GLAutoDrawable, Window {
}
}
- public synchronized void reparentActionPost(int reparentActionType) {
+ public synchronized void resumeRenderingAction() {
resetCounter();
GLAnimatorControl ctrl = GLWindow.this.getAnimator();
if ( null!=ctrl && animatorPaused ) {
@@ -384,6 +384,7 @@ public class GLWindow implements GLAutoDrawable, Window {
}
}
}
+
//----------------------------------------------------------------------
// OpenGL-related methods and state
//