Skip to content

Commit

Permalink
Fix issue #5508024: Rotation jank seen in live wallpapers
Browse files Browse the repository at this point in the history
Fix a few places where we would unfreeze the screen too early.
Now that we are no longer relying on surface flinger freezing, we
can't depend on it keeping the screen frozen until surfaces get
drawn.

Change-Id: Icb03bf30c9599a5e2016817bfa5ca6458adc7249
  • Loading branch information
Dianne Hackborn committed Oct 25, 2011
1 parent a6d2e6b commit 3ec891a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
49 changes: 31 additions & 18 deletions services/java/com/android/server/wm/WindowManagerService.java
Expand Up @@ -3973,6 +3973,7 @@ void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
if (w.mAppFreezing) {
w.mAppFreezing = false;
if (w.mSurface != null && !w.mOrientationChanging) {
if (DEBUG_ORIENTATION) Slog.v(TAG, "set mOrientationChanging of " + w);
w.mOrientationChanging = true;
}
unfrozeWindows = true;
Expand Down Expand Up @@ -5106,7 +5107,7 @@ public Bitmap screenshotApplications(IBinder appToken, int width, int height) {
}

if (rawss == null) {
Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
Slog.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
+ ") to layer " + maxLayer);
return null;
}
Expand Down Expand Up @@ -5312,6 +5313,7 @@ public boolean updateRotationUncheckedLocked(boolean inTransaction) {
for (int i=mWindows.size()-1; i>=0; i--) {
WindowState w = mWindows.get(i);
if (w.mSurface != null) {
if (DEBUG_ORIENTATION) Slog.v(TAG, "Set mOrientationChanging of " + w);
w.mOrientationChanging = true;
}
}
Expand Down Expand Up @@ -7128,7 +7130,7 @@ private final void assignLayersLocked() {
if (DEBUG_LAYERS) {
RuntimeException here = new RuntimeException("here");
here.fillInStackTrace();
Log.v(TAG, "Assigning layers", here);
Slog.v(TAG, "Assigning layers", here);
}

for (i=0; i<N; i++) {
Expand Down Expand Up @@ -7367,6 +7369,25 @@ private final int performLayoutLockedInner(boolean initial, boolean updateInputW
return mPolicy.finishLayoutLw();
}

void makeWindowFreezingScreenIfNeededLocked(WindowState w) {
// If the screen is currently frozen or off, then keep
// it frozen/off until this window draws at its new
// orientation.
if (mDisplayFrozen || !mPolicy.isScreenOnFully()) {
if (DEBUG_ORIENTATION) Slog.v(TAG,
"Changing surface while display frozen: " + w);
w.mOrientationChanging = true;
if (!mWindowsFreezingScreen) {
mWindowsFreezingScreen = true;
// XXX should probably keep timeout from
// when we first froze the display.
mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
mH.sendMessageDelayed(mH.obtainMessage(
H.WINDOW_FREEZE_TIMEOUT), 2000);
}
}
}

// "Something has changed! Let's make it correct now."
private final void performLayoutAndPlaceSurfacesLockedInner(
boolean recoveringMemory) {
Expand Down Expand Up @@ -7718,6 +7739,10 @@ private final void performLayoutAndPlaceSurfacesLockedInner(
+ " drawn=" + wtoken.numDrawnWindows);
wtoken.showAllWindowsLocked();
unsetAppFreezingScreenLocked(wtoken, false, true);
if (DEBUG_ORIENTATION) Slog.i(TAG,
"Setting orientationChangeComplete=true because wtoken "
+ wtoken + " numInteresting=" + numInteresting
+ " numDrawn=" + wtoken.numDrawnWindows);
orientationChangeComplete = true;
}
} else if (!wtoken.allDrawn) {
Expand Down Expand Up @@ -8225,22 +8250,7 @@ private final void performLayoutAndPlaceSurfacesLockedInner(

w.mLastContentInsets.set(w.mContentInsets);
w.mLastVisibleInsets.set(w.mVisibleInsets);
// If the screen is currently frozen or off, then keep
// it frozen/off until this window draws at its new
// orientation.
if (mDisplayFrozen || !mPolicy.isScreenOnFully()) {
if (DEBUG_ORIENTATION) Slog.v(TAG,
"Resizing while display frozen: " + w);
w.mOrientationChanging = true;
if (!mWindowsFreezingScreen) {
mWindowsFreezingScreen = true;
// XXX should probably keep timeout from
// when we first froze the display.
mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
mH.sendMessageDelayed(mH.obtainMessage(
H.WINDOW_FREEZE_TIMEOUT), 2000);
}
}
makeWindowFreezingScreenIfNeededLocked(w);
// If the orientation is changing, then we need to
// hold off on unfreezing the display until this
// window has been redrawn; to do that, we need
Expand Down Expand Up @@ -8563,6 +8573,8 @@ private final void performLayoutAndPlaceSurfacesLockedInner(
+ Integer.toHexString(diff));
}
win.mConfiguration = mCurConfiguration;
if (DEBUG_ORIENTATION && win.mDrawPending) Slog.i(
TAG, "Resizing " + win + " WITH DRAW PENDING");
win.mClient.resized((int)win.mSurfaceW, (int)win.mSurfaceH,
win.mLastContentInsets, win.mLastVisibleInsets, win.mDrawPending,
configChanged ? win.mConfiguration : null);
Expand Down Expand Up @@ -9087,6 +9099,7 @@ private void stopFreezingDisplayLocked() {

if (CUSTOM_SCREEN_ROTATION && mScreenRotationAnimation != null
&& mScreenRotationAnimation.hasScreenshot()) {
if (DEBUG_ORIENTATION) Slog.i(TAG, "**** Dismissing screen rotation animation");
if (mScreenRotationAnimation.dismiss(mFxSession, MAX_ANIMATION_DURATION,
mTransitionAnimationScale, mCurDisplayWidth, mCurDisplayHeight)) {
requestAnimationLocked(0);
Expand Down
5 changes: 4 additions & 1 deletion services/java/com/android/server/wm/WindowState.java
Expand Up @@ -600,13 +600,16 @@ Surface createSurfaceLocked() {
if (mSurface == null) {
mReportDestroySurface = false;
mSurfacePendingDestroy = false;
Slog.i(WindowManagerService.TAG, "createSurface " + this + ": DRAW NOW PENDING");
mDrawPending = true;
mCommitDrawPending = false;
mReadyToShow = false;
if (mAppToken != null) {
mAppToken.allDrawn = false;
}

mService.makeWindowFreezingScreenIfNeededLocked(this);

int flags = 0;

if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
Expand Down Expand Up @@ -771,7 +774,7 @@ void destroySurfaceLocked() {
boolean finishDrawingLocked() {
if (mDrawPending) {
if (SHOW_TRANSACTIONS || WindowManagerService.DEBUG_ORIENTATION) Slog.v(
WindowManagerService.TAG, "finishDrawingLocked: " + mSurface);
WindowManagerService.TAG, "finishDrawingLocked: " + this + " in " + mSurface);
mCommitDrawPending = true;
mDrawPending = false;
return true;
Expand Down

0 comments on commit 3ec891a

Please sign in to comment.