@@ -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