Skip to content

Commit acaf9cc

Browse files
author
Craig Mautner
committed
Move Surface operations into existing transaction.
Several Surface operations - notably setPosition, setSize, and show - had been moved outside of a Surface.openTransaction/closeTransaction window. This corrects that problem. In addition, before animations were separated from layout the Surface frame was computed prior to returning from relayoutWindow(). After separation the frame was being computed during animation. This checkin restores the frame calculation in layout. Fixes bug 6343291. Change-Id: I4752bdf1fed0f2b46c5eb9508825c9b1b0fd702f
1 parent 3255a28 commit acaf9cc

File tree

2 files changed

+96
-83
lines changed

2 files changed

+96
-83
lines changed

services/java/com/android/server/wm/WindowManagerService.java

Lines changed: 66 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -7959,7 +7959,7 @@ private void updateResizingWindows(final WindowState w) {
79597959
Slog.v(TAG, "Resize reasons: "
79607960
+ " contentInsetsChanged=" + w.mContentInsetsChanged
79617961
+ " visibleInsetsChanged=" + w.mVisibleInsetsChanged
7962-
+ " surfaceResized=" + w.mWinAnimator.mSurfaceResized
7962+
+ " surfaceResized=" + winAnimator.mSurfaceResized
79637963
+ " configChanged=" + configChanged);
79647964
}
79657965

@@ -7974,23 +7974,23 @@ private void updateResizingWindows(final WindowState w) {
79747974
if (w.mOrientationChanging) {
79757975
if (DEBUG_ORIENTATION) Slog.v(TAG,
79767976
"Orientation start waiting for draw in "
7977-
+ w + ", surface " + w.mWinAnimator.mSurface);
7977+
+ w + ", surface " + winAnimator.mSurface);
79787978
winAnimator.mDrawState = WindowStateAnimator.DRAW_PENDING;
79797979
if (w.mAppToken != null) {
79807980
w.mAppToken.allDrawn = false;
79817981
}
79827982
}
79837983
if (!mResizingWindows.contains(w)) {
79847984
if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
7985-
"Resizing window " + w + " to " + w.mWinAnimator.mSurfaceW
7986-
+ "x" + w.mWinAnimator.mSurfaceH);
7985+
"Resizing window " + w + " to " + winAnimator.mSurfaceW
7986+
+ "x" + winAnimator.mSurfaceH);
79877987
mResizingWindows.add(w);
79887988
}
79897989
} else if (w.mOrientationChanging) {
79907990
if (w.isDrawnLw()) {
79917991
if (DEBUG_ORIENTATION) Slog.v(TAG,
79927992
"Orientation not waiting for draw in "
7993-
+ w + ", surface " + w.mWinAnimator.mSurface);
7993+
+ w + ", surface " + winAnimator.mSurface);
79947994
w.mOrientationChanging = false;
79957995
}
79967996
}
@@ -8083,7 +8083,7 @@ private final void performLayoutAndPlaceSurfacesLockedInner(
80838083
updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
80848084
false /*updateInputWindows*/);
80858085
}
8086-
8086+
80878087
// Initialize state of exiting tokens.
80888088
for (i=mExitingTokens.size()-1; i>=0; i--) {
80898089
mExitingTokens.get(i).hasVisible = false;
@@ -8112,7 +8112,7 @@ private final void performLayoutAndPlaceSurfacesLockedInner(
81128112

81138113
try {
81148114
int repeats = 0;
8115-
8115+
81168116
do {
81178117
repeats++;
81188118
if (repeats > 6) {
@@ -8172,7 +8172,7 @@ private final void performLayoutAndPlaceSurfacesLockedInner(
81728172
mInnerFields.mObscured = false;
81738173
mInnerFields.mDimming = false;
81748174
mInnerFields.mSyswin = false;
8175-
8175+
81768176
boolean focusDisplayed = false;
81778177
final int N = mWindows.size();
81788178
for (i=N-1; i>=0; i--) {
@@ -8196,7 +8196,52 @@ private final void performLayoutAndPlaceSurfacesLockedInner(
81968196
// has been updated accordingly.
81978197
updateWallpaperVisibilityLocked();
81988198
}
8199+
8200+
final WindowStateAnimator winAnimator = w.mWinAnimator;
8201+
8202+
// If the window has moved due to its containing
8203+
// content frame changing, then we'd like to animate
8204+
// it.
8205+
if (w.mHasSurface && w.shouldAnimateMove()) {
8206+
// Frame has moved, containing content frame
8207+
// has also moved, and we're not currently animating...
8208+
// let's do something.
8209+
Animation a = AnimationUtils.loadAnimation(mContext,
8210+
com.android.internal.R.anim.window_move_from_decor);
8211+
winAnimator.setAnimation(a);
8212+
winAnimator.mAnimDw = w.mLastFrame.left - w.mFrame.left;
8213+
winAnimator.mAnimDh = w.mLastFrame.top - w.mFrame.top;
8214+
} else {
8215+
winAnimator.mAnimDw = innerDw;
8216+
winAnimator.mAnimDh = innerDh;
8217+
}
8218+
8219+
//Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
8220+
w.mContentChanged = false;
8221+
8222+
// Moved from updateWindowsAndWallpaperLocked().
8223+
if (w.mHasSurface) {
8224+
// Take care of the window being ready to display.
8225+
if (winAnimator.commitFinishDrawingLocked(currentTime)) {
8226+
if ((w.mAttrs.flags
8227+
& WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8228+
if (WindowManagerService.DEBUG_WALLPAPER) Slog.v(TAG,
8229+
"First draw done in potential wallpaper target " + w);
8230+
mInnerFields.mWallpaperMayChange = true;
8231+
mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
8232+
if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
8233+
debugLayoutRepeats("updateWindowsAndWallpaperLocked 1",
8234+
mPendingLayoutChanges);
8235+
}
8236+
}
8237+
}
8238+
8239+
winAnimator.setSurfaceBoundaries(recoveringMemory);
8240+
}
8241+
8242+
updateResizingWindows(w);
81998243
}
8244+
82008245
if (focusDisplayed) {
82018246
mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
82028247
}
@@ -8278,68 +8323,10 @@ private final void performLayoutAndPlaceSurfacesLockedInner(
82788323
if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("mLayoutNeeded", mPendingLayoutChanges);
82798324
}
82808325

8281-
final int N = mWindows.size();
8282-
for (i=N-1; i>=0; i--) {
8283-
final WindowState w = mWindows.get(i);
8284-
final WindowStateAnimator winAnimator = w.mWinAnimator;
8285-
8286-
// If the window has moved due to its containing
8287-
// content frame changing, then we'd like to animate
8288-
// it.
8289-
if (w.mHasSurface && w.shouldAnimateMove()) {
8290-
// Frame has moved, containing content frame
8291-
// has also moved, and we're not currently animating...
8292-
// let's do something.
8293-
Animation a = AnimationUtils.loadAnimation(mContext,
8294-
com.android.internal.R.anim.window_move_from_decor);
8295-
winAnimator.setAnimation(a);
8296-
winAnimator.mAnimDw = w.mLastFrame.left - w.mFrame.left;
8297-
winAnimator.mAnimDh = w.mLastFrame.top - w.mFrame.top;
8298-
} else {
8299-
winAnimator.mAnimDw = innerDw;
8300-
winAnimator.mAnimDh = innerDh;
8301-
}
8302-
8303-
//Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
8304-
w.mContentChanged = false;
8305-
8306-
// TODO(cmautner): Can this move up to the loop at the end of try/catch above?
8307-
updateResizingWindows(w);
8308-
8309-
// Moved from updateWindowsAndWallpaperLocked().
8310-
if (w.mHasSurface) {
8311-
// Take care of the window being ready to display.
8312-
if (winAnimator.commitFinishDrawingLocked(currentTime)) {
8313-
if ((w.mAttrs.flags
8314-
& WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8315-
if (WindowManagerService.DEBUG_WALLPAPER) Slog.v(TAG,
8316-
"First draw done in potential wallpaper target " + w);
8317-
mInnerFields.mWallpaperMayChange = true;
8318-
mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
8319-
if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
8320-
debugLayoutRepeats("updateWindowsAndWallpaperLocked 1",
8321-
mPendingLayoutChanges);
8322-
}
8323-
}
8324-
}
8325-
}
8326-
}
8327-
8328-
if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
8329-
"With display frozen, orientationChangeComplete="
8330-
+ mInnerFields.mOrientationChangeComplete);
8331-
if (mInnerFields.mOrientationChangeComplete) {
8332-
if (mWindowsFreezingScreen) {
8333-
mWindowsFreezingScreen = false;
8334-
mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
8335-
}
8336-
stopFreezingDisplayLocked();
8337-
}
8338-
83398326
if (!mResizingWindows.isEmpty()) {
83408327
for (i = mResizingWindows.size() - 1; i >= 0; i--) {
83418328
WindowState win = mResizingWindows.get(i);
8342-
final WindowStateAnimator winAnimator = win.mWinAnimator;
8329+
final WindowStateAnimator winAnimator = win.mWinAnimator;
83438330
try {
83448331
if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
83458332
"Reporting new frame to " + win + ": " + win.mCompatFrame);
@@ -8358,7 +8345,7 @@ private final void performLayoutAndPlaceSurfacesLockedInner(
83588345
win.mConfiguration = mCurConfiguration;
83598346
if (DEBUG_ORIENTATION &&
83608347
winAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING) Slog.i(
8361-
TAG, "Resizing " + win + " WITH DRAW PENDING");
8348+
TAG, "Resizing " + win + " WITH DRAW PENDING");
83628349
win.mClient.resized((int)winAnimator.mSurfaceW,
83638350
(int)winAnimator.mSurfaceH,
83648351
win.mLastContentInsets, win.mLastVisibleInsets,
@@ -8374,6 +8361,17 @@ private final void performLayoutAndPlaceSurfacesLockedInner(
83748361
mResizingWindows.clear();
83758362
}
83768363

8364+
if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
8365+
"With display frozen, orientationChangeComplete="
8366+
+ mInnerFields.mOrientationChangeComplete);
8367+
if (mInnerFields.mOrientationChangeComplete) {
8368+
if (mWindowsFreezingScreen) {
8369+
mWindowsFreezingScreen = false;
8370+
mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
8371+
}
8372+
stopFreezingDisplayLocked();
8373+
}
8374+
83778375
// Destroy the surface of any windows that are no longer visible.
83788376
boolean wallpaperDestroyed = false;
83798377
i = mDestroySurface.size();

services/java/com/android/server/wm/WindowStateAnimator.java

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,14 @@ public void destroy() {
499499
sSurfaces.remove(this);
500500
}
501501

502+
@Override
503+
public void release() {
504+
super.release();
505+
Slog.v(SURFACE_TAG, "release: " + this + ". Called by "
506+
+ WindowManagerService.getCallers(3));
507+
sSurfaces.remove(this);
508+
}
509+
502510
static void dumpAllSurfaces() {
503511
final int N = sSurfaces.size();
504512
for (int i = 0; i < N; i++) {
@@ -886,22 +894,8 @@ void computeShownFrameLocked() {
886894
mDtDy = mWin.mGlobalScale;
887895
}
888896

889-
public void prepareSurfaceLocked(final boolean recoveringMemory) {
897+
void setSurfaceBoundaries(final boolean recoveringMemory) {
890898
final WindowState w = mWin;
891-
if (mSurface == null) {
892-
if (w.mOrientationChanging) {
893-
if (DEBUG_ORIENTATION) {
894-
Slog.v(TAG, "Orientation change skips hidden " + w);
895-
}
896-
w.mOrientationChanging = false;
897-
}
898-
return;
899-
}
900-
901-
boolean displayed = false;
902-
903-
computeShownFrameLocked();
904-
905899
int width, height;
906900
if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
907901
// for a scaled surface, we just want to use
@@ -950,6 +944,8 @@ public void prepareSurfaceLocked(final boolean recoveringMemory) {
950944
"SIZE " + width + "x" + height, null);
951945
mSurfaceResized = true;
952946
mSurface.setSize(width, height);
947+
mAnimator.mPendingLayoutChanges |=
948+
WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
953949
} catch (RuntimeException e) {
954950
// If something goes wrong with the surface (such
955951
// as running out of memory), don't take down the
@@ -961,6 +957,25 @@ public void prepareSurfaceLocked(final boolean recoveringMemory) {
961957
}
962958
}
963959
}
960+
}
961+
962+
public void prepareSurfaceLocked(final boolean recoveringMemory) {
963+
final WindowState w = mWin;
964+
if (mSurface == null) {
965+
if (w.mOrientationChanging) {
966+
if (DEBUG_ORIENTATION) {
967+
Slog.v(TAG, "Orientation change skips hidden " + w);
968+
}
969+
w.mOrientationChanging = false;
970+
}
971+
return;
972+
}
973+
974+
boolean displayed = false;
975+
976+
computeShownFrameLocked();
977+
978+
setSurfaceBoundaries(recoveringMemory);
964979

965980
if (w.mAttachedHidden || !w.isReadyForDisplay()) {
966981
if (!mLastHidden) {

0 commit comments

Comments
 (0)