Skip to content

Commit 1d60133

Browse files
Craig MautnerAndroid (Google) Code Review
authored andcommitted
Merge "Refactor to convert four state booleans to int."
2 parents ea7ff4d + 749a7bb commit 1d60133

File tree

5 files changed

+69
-81
lines changed

5 files changed

+69
-81
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,7 @@ void updateReportedVisibilityLocked() {
394394
if (!win.isDrawnLw()) {
395395
Slog.v(WindowManagerService.TAG, "Not displayed: s=" + win.mWinAnimator.mSurface
396396
+ " pv=" + win.mPolicyVisibility
397-
+ " dp=" + win.mWinAnimator.mDrawPending
398-
+ " cdp=" + win.mWinAnimator.mCommitDrawPending
397+
+ " mDrawState=" + win.mWinAnimator.mDrawState
399398
+ " ah=" + win.mAttachedHidden
400399
+ " th="
401400
+ (win.mAppToken != null

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,7 @@ private void updateWindowsAndWallpaperLocked() {
299299
if (!w.isDrawnLw()) {
300300
Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurface
301301
+ " pv=" + w.mPolicyVisibility
302-
+ " dp=" + winAnimator.mDrawPending
303-
+ " cdp=" + winAnimator.mCommitDrawPending
302+
+ " mDrawState=" + winAnimator.mDrawState
304303
+ " ah=" + w.mAttachedHidden
305304
+ " th=" + atoken.hiddenRequested
306305
+ " a=" + winAnimator.mAnimating);
@@ -323,7 +322,7 @@ private void updateWindowsAndWallpaperLocked() {
323322
atoken.startingDisplayed = true;
324323
}
325324
}
326-
} else if (w.mReadyToShow) {
325+
} else if (winAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW) {
327326
if (winAnimator.performShowLocked()) {
328327
mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
329328
if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,8 +1589,7 @@ int adjustWallpaperWindowsLocked() {
15891589
}
15901590
}
15911591
if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
1592-
+ w.isReadyForDisplay() + " drawpending=" + w.mWinAnimator.mDrawPending
1593-
+ " commitdrawpending=" + w.mWinAnimator.mCommitDrawPending);
1592+
+ w.isReadyForDisplay() + " mDrawState=" + w.mWinAnimator.mDrawState);
15941593
if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
15951594
&& (mWallpaperTarget == w || w.isDrawnLw())) {
15961595
if (DEBUG_WALLPAPER) Slog.v(TAG,
@@ -8111,9 +8110,7 @@ private void updateResizingWindows(final WindowState w) {
81118110
if (DEBUG_ORIENTATION) Slog.v(TAG,
81128111
"Orientation start waiting for draw in "
81138112
+ w + ", surface " + w.mWinAnimator.mSurface);
8114-
winAnimator.mDrawPending = true;
8115-
winAnimator.mCommitDrawPending = false;
8116-
w.mReadyToShow = false;
8113+
winAnimator.mDrawState = WindowStateAnimator.DRAW_PENDING;
81178114
if (w.mAppToken != null) {
81188115
w.mAppToken.allDrawn = false;
81198116
}
@@ -8498,12 +8495,14 @@ private final void performLayoutAndPlaceSurfacesLockedInner(
84988495
+ Integer.toHexString(diff));
84998496
}
85008497
win.mConfiguration = mCurConfiguration;
8501-
if (DEBUG_ORIENTATION && winAnimator.mDrawPending) Slog.i(
8498+
if (DEBUG_ORIENTATION &&
8499+
winAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING) Slog.i(
85028500
TAG, "Resizing " + win + " WITH DRAW PENDING");
85038501
win.mClient.resized((int)winAnimator.mSurfaceW,
85048502
(int)winAnimator.mSurfaceH,
85058503
win.mLastContentInsets, win.mLastVisibleInsets,
8506-
winAnimator.mDrawPending, configChanged ? win.mConfiguration : null);
8504+
winAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING,
8505+
configChanged ? win.mConfiguration : null);
85078506
win.mContentInsetsChanged = false;
85088507
win.mVisibleInsetsChanged = false;
85098508
winAnimator.mSurfaceResized = false;

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

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ final class WindowState implements WindowManagerPolicy.WindowState {
8383
boolean mPolicyVisibilityAfterAnim = true;
8484
boolean mAppFreezing;
8585
boolean mAttachedHidden; // is our parent window hidden?
86-
boolean mLastHidden; // was this window last hidden?
8786
boolean mWallpaperVisible; // for wallpaper, what was last vis report?
8887

8988
/**
@@ -206,15 +205,6 @@ final class WindowState implements WindowManagerPolicy.WindowState {
206205
// when in that case until the layout is done.
207206
boolean mLayoutNeeded;
208207

209-
// This is set during the time after the window's drawing has been
210-
// committed, and before its surface is actually shown. It is used
211-
// to delay showing the surface until all windows in a token are ready
212-
// to be shown.
213-
boolean mReadyToShow;
214-
215-
// Set when the window has been shown in the screen the first time.
216-
boolean mHasDrawn;
217-
218208
// Currently running an exit animation?
219209
boolean mExiting;
220210

@@ -744,7 +734,8 @@ public boolean isGoneForLayoutLw() {
744734
*/
745735
public boolean isDrawnLw() {
746736
return mHasSurface && !mDestroying &&
747-
!mWinAnimator.mDrawPending && !mWinAnimator.mCommitDrawPending;
737+
(mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
738+
|| mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
748739
}
749740

750741
/**
@@ -764,7 +755,7 @@ && isDrawnLw() && mWinAnimator.mAnimation == null
764755
* sense to call from performLayoutAndPlaceSurfacesLockedInner().)
765756
*/
766757
boolean shouldAnimateMove() {
767-
return mContentChanged && !mExiting && !mLastHidden && mService.okToDisplay()
758+
return mContentChanged && !mExiting && !mWinAnimator.mLastHidden && mService.okToDisplay()
768759
&& (mFrame.top != mLastFrame.top
769760
|| mFrame.left != mLastFrame.left)
770761
&& (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove());
@@ -837,10 +828,12 @@ public final boolean canReceiveKeys() {
837828
&& ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
838829
}
839830

831+
@Override
840832
public boolean hasDrawnLw() {
841-
return mHasDrawn;
833+
return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
842834
}
843835

836+
@Override
844837
public boolean showLw(boolean doAnimation) {
845838
return showLw(doAnimation, true);
846839
}
@@ -985,7 +978,6 @@ void dump(PrintWriter pw, String prefix, boolean dumpAll) {
985978
}
986979
pw.print(prefix); pw.print("mViewVisibility=0x");
987980
pw.print(Integer.toHexString(mViewVisibility));
988-
pw.print(" mLastHidden="); pw.print(mLastHidden);
989981
pw.print(" mHaveFrame="); pw.print(mHaveFrame);
990982
pw.print(" mObscured="); pw.println(mObscured);
991983
pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
@@ -1048,12 +1040,6 @@ void dump(PrintWriter pw, String prefix, boolean dumpAll) {
10481040
pw.println();
10491041
}
10501042
mWinAnimator.dump(pw, prefix, dumpAll);
1051-
if (dumpAll) {
1052-
pw.print(prefix); pw.print("mDrawPending="); pw.print(mWinAnimator.mDrawPending);
1053-
pw.print(" mCommitDrawPending="); pw.print(mWinAnimator.mCommitDrawPending);
1054-
pw.print(" mReadyToShow="); pw.print(mReadyToShow);
1055-
pw.print(" mHasDrawn="); pw.println(mHasDrawn);
1056-
}
10571043
if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
10581044
pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
10591045
pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);

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

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,24 @@ class WindowStateAnimator {
100100
// an enter animation.
101101
boolean mEnterAnimationPending;
102102

103-
// This is set after the Surface has been created but before the
104-
// window has been drawn. During this time the surface is hidden.
105-
boolean mDrawPending;
106-
107-
// This is set after the window has finished drawing for the first
108-
// time but before its surface is shown. The surface will be
109-
// displayed when the next layout is run.
110-
boolean mCommitDrawPending;
103+
/** This is set when there is no Surface */
104+
static final int NO_SURFACE = 0;
105+
/** This is set after the Surface has been created but before the window has been drawn. During
106+
* this time the surface is hidden. */
107+
static final int DRAW_PENDING = 1;
108+
/** This is set after the window has finished drawing for the first time but before its surface
109+
* is shown. The surface will be displayed when the next layout is run. */
110+
static final int COMMIT_DRAW_PENDING = 2;
111+
/** This is set during the time after the window's drawing has been committed, and before its
112+
* surface is actually shown. It is used to delay showing the surface until all windows in a
113+
* token are ready to be shown. */
114+
static final int READY_TO_SHOW = 3;
115+
/** Set when the window has been shown in the screen the first time. */
116+
static final int HAS_DRAWN = 4;
117+
int mDrawState;
118+
119+
/** Was this window last hidden? */
120+
boolean mLastHidden;
111121

112122
public WindowStateAnimator(final WindowManagerService service, final WindowState win,
113123
final WindowState attachedWindow) {
@@ -130,7 +140,7 @@ public void setAnimation(Animation anim) {
130140
mAnimation.scaleCurrentDuration(mService.mWindowAnimationScale);
131141
// Start out animation gone if window is gone, or visible if window is visible.
132142
mTransformation.clear();
133-
mTransformation.setAlpha(mWin.mLastHidden ? 0 : 1);
143+
mTransformation.setAlpha(mLastHidden ? 0 : 1);
134144
mHasLocalTransformation = true;
135145
}
136146

@@ -291,7 +301,7 @@ boolean stepAnimationLocked(long currentTime) {
291301
}
292302
}
293303
mTransformation.clear();
294-
if (mWin.mHasDrawn
304+
if (mDrawState == HAS_DRAWN
295305
&& mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
296306
&& mWin.mAppToken != null
297307
&& mWin.mAppToken.firstWindowDrawn
@@ -347,7 +357,7 @@ void finishExit() {
347357
} catch (RuntimeException e) {
348358
Slog.w(TAG, "Error hiding surface in " + this, e);
349359
}
350-
mWin.mLastHidden = true;
360+
mLastHidden = true;
351361
}
352362
mWin.mExiting = false;
353363
if (mWin.mRemoveOnExit) {
@@ -357,11 +367,10 @@ void finishExit() {
357367
}
358368

359369
boolean finishDrawingLocked() {
360-
if (mDrawPending) {
370+
if (mDrawState == DRAW_PENDING) {
361371
if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
362372
TAG, "finishDrawingLocked: " + this + " in " + mSurface);
363-
mCommitDrawPending = true;
364-
mDrawPending = false;
373+
mDrawState = COMMIT_DRAW_PENDING;
365374
return true;
366375
}
367376
return false;
@@ -370,11 +379,10 @@ boolean finishDrawingLocked() {
370379
// This must be called while inside a transaction.
371380
boolean commitFinishDrawingLocked(long currentTime) {
372381
//Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
373-
if (!mCommitDrawPending) {
382+
if (mDrawState != COMMIT_DRAW_PENDING) {
374383
return false;
375384
}
376-
mCommitDrawPending = false;
377-
mWin.mReadyToShow = true;
385+
mDrawState = READY_TO_SHOW;
378386
final boolean starting = mWin.mAttrs.type == TYPE_APPLICATION_STARTING;
379387
final AppWindowToken atoken = mWin.mAppToken;
380388
if (atoken == null || atoken.allDrawn || starting) {
@@ -389,9 +397,7 @@ Surface createSurfaceLocked() {
389397
mSurfacePendingDestroy = false;
390398
if (DEBUG_ORIENTATION) Slog.i(TAG,
391399
"createSurface " + this + ": DRAW NOW PENDING");
392-
mDrawPending = true;
393-
mCommitDrawPending = false;
394-
mWin.mReadyToShow = false;
400+
mDrawState = DRAW_PENDING;
395401
if (mWin.mAppToken != null) {
396402
mWin.mAppToken.allDrawn = false;
397403
}
@@ -456,10 +462,12 @@ Surface createSurfaceLocked() {
456462
mWin.mHasSurface = false;
457463
Slog.w(TAG, "OutOfResourcesException creating surface");
458464
mService.reclaimSomeSurfaceMemoryLocked(this, "create", true);
465+
mDrawState = NO_SURFACE;
459466
return null;
460467
} catch (Exception e) {
461468
mWin.mHasSurface = false;
462469
Slog.e(TAG, "Exception creating surface", e);
470+
mDrawState = NO_SURFACE;
463471
return null;
464472
}
465473

@@ -492,7 +500,7 @@ Surface createSurfaceLocked() {
492500
Slog.w(TAG, "Error creating surface in " + w, e);
493501
mService.reclaimSomeSurfaceMemoryLocked(this, "create-init", true);
494502
}
495-
mWin.mLastHidden = true;
503+
mLastHidden = true;
496504
} finally {
497505
Surface.closeTransaction();
498506
if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
@@ -509,10 +517,8 @@ void destroySurfaceLocked() {
509517
mWin.mAppToken.startingDisplayed = false;
510518
}
511519

520+
mDrawState = NO_SURFACE;
512521
if (mSurface != null) {
513-
mDrawPending = false;
514-
mCommitDrawPending = false;
515-
mWin.mReadyToShow = false;
516522

517523
int i = mWin.mChildWindows.size();
518524
while (i > 0) {
@@ -823,9 +829,9 @@ public void prepareSurfaceLocked(final boolean recoveringMemory) {
823829
}
824830

825831
if (w.mAttachedHidden || !w.isReadyForDisplay()) {
826-
if (!w.mLastHidden) {
832+
if (!mLastHidden) {
827833
//dump();
828-
w.mLastHidden = true;
834+
mLastHidden = true;
829835
if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
830836
"HIDE (performLayout)", null);
831837
if (mSurface != null) {
@@ -856,7 +862,7 @@ public void prepareSurfaceLocked(final boolean recoveringMemory) {
856862
|| mLastDtDy != mDtDy
857863
|| w.mLastHScale != w.mHScale
858864
|| w.mLastVScale != w.mVScale
859-
|| w.mLastHidden) {
865+
|| mLastHidden) {
860866
displayed = true;
861867
mLastAlpha = mShownAlpha;
862868
mLastLayer = mAnimLayer;
@@ -881,30 +887,28 @@ public void prepareSurfaceLocked(final boolean recoveringMemory) {
881887
mSurface.setMatrix(
882888
mDsDx*w.mHScale, mDtDx*w.mVScale,
883889
mDsDy*w.mHScale, mDtDy*w.mVScale);
890+
891+
if (mLastHidden && mDrawState == HAS_DRAWN) {
892+
if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
893+
"SHOW (performLayout)", null);
894+
if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
895+
+ " during relayout");
896+
if (showSurfaceRobustlyLocked()) {
897+
mLastHidden = false;
898+
} else {
899+
w.mOrientationChanging = false;
900+
}
901+
}
902+
if (mSurface != null) {
903+
w.mToken.hasVisible = true;
904+
}
884905
} catch (RuntimeException e) {
885906
Slog.w(TAG, "Error updating surface in " + w, e);
886907
if (!recoveringMemory) {
887908
mService.reclaimSomeSurfaceMemoryLocked(this, "update", true);
888909
}
889910
}
890911
}
891-
892-
if (w.mLastHidden && w.isDrawnLw()
893-
&& !w.mReadyToShow) {
894-
if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
895-
"SHOW (performLayout)", null);
896-
if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
897-
+ " during relayout");
898-
if (showSurfaceRobustlyLocked()) {
899-
w.mHasDrawn = true;
900-
w.mLastHidden = false;
901-
} else {
902-
w.mOrientationChanging = false;
903-
}
904-
}
905-
if (mSurface != null) {
906-
w.mToken.hasVisible = true;
907-
}
908912
} else {
909913
displayed = true;
910914
}
@@ -961,11 +965,11 @@ boolean performShowLocked() {
961965
e.fillInStackTrace();
962966
}
963967
Slog.v(TAG, "performShow on " + this
964-
+ ": readyToShow=" + mWin.mReadyToShow + " readyForDisplay="
968+
+ ": mDrawState=" + mDrawState + " readyForDisplay="
965969
+ mWin.isReadyForDisplay()
966970
+ " starting=" + (mWin.mAttrs.type == TYPE_APPLICATION_STARTING), e);
967971
}
968-
if (mWin.mReadyToShow && mWin.isReadyForDisplay()) {
972+
if (mDrawState == READY_TO_SHOW && mWin.isReadyForDisplay()) {
969973
if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
970974
WindowManagerService.logSurface(mWin, "SHOW (performShowLocked)", null);
971975
if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
@@ -987,9 +991,8 @@ boolean performShowLocked() {
987991
applyEnterAnimationLocked();
988992

989993
mLastAlpha = -1;
990-
mWin.mHasDrawn = true;
991-
mWin.mLastHidden = false;
992-
mWin.mReadyToShow = false;
994+
mLastHidden = false;
995+
mDrawState = HAS_DRAWN;
993996

994997
int i = mWin.mChildWindows.size();
995998
while (i > 0) {
@@ -1170,6 +1173,8 @@ public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
11701173
if (mSurface != null) {
11711174
if (dumpAll) {
11721175
pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
1176+
pw.print(prefix); pw.print("mDrawState="); pw.print(mDrawState);
1177+
pw.print(" mLastHidden="); pw.println(mLastHidden);
11731178
}
11741179
pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
11751180
pw.print(" layer="); pw.print(mSurfaceLayer);

0 commit comments

Comments
 (0)