2222import com .android .internal .policy .impl .PhoneWindowManager ;
2323
2424import java .io .PrintWriter ;
25+ import java .util .HashSet ;
2526
2627/**
2728 * Singleton class that carries out the animations and Surface operations in a separate task
@@ -34,6 +35,9 @@ public class WindowAnimator {
3435 final Context mContext ;
3536 final WindowManagerPolicy mPolicy ;
3637
38+ HashSet <WindowStateAnimator > mWinAnimators = new HashSet <WindowStateAnimator >();
39+ HashSet <WindowStateAnimator > mFinished = new HashSet <WindowStateAnimator >();
40+
3741 boolean mAnimating ;
3842 boolean mTokenMayBeDrawn ;
3943 boolean mForceHiding ;
@@ -171,16 +175,16 @@ private void updateWindowsAndWallpaperLocked() {
171175 ++mTransactionSequence ;
172176
173177 for (int i = mService .mWindows .size () - 1 ; i >= 0 ; i --) {
174- WindowState w = mService .mWindows .get (i );
175- WindowStateAnimator winAnimator = w .mWinAnimator ;
176- final WindowManager . LayoutParams attrs = w . mAttrs ;
178+ WindowState win = mService .mWindows .get (i );
179+ WindowStateAnimator winAnimator = win .mWinAnimator ;
180+ final int flags = winAnimator . mAttrFlags ;
177181
178182 if (winAnimator .mSurface != null ) {
179183 final boolean wasAnimating = winAnimator .mWasAnimating ;
180184 final boolean nowAnimating = winAnimator .stepAnimationLocked (mCurrentTime );
181185
182186 if (WindowManagerService .DEBUG_WALLPAPER ) {
183- Slog .v (TAG , w + ": wasAnimating=" + wasAnimating +
187+ Slog .v (TAG , win + ": wasAnimating=" + wasAnimating +
184188 ", nowAnimating=" + nowAnimating );
185189 }
186190
@@ -189,16 +193,16 @@ private void updateWindowsAndWallpaperLocked() {
189193 // a detached wallpaper animation.
190194 if (nowAnimating ) {
191195 if (winAnimator .mAnimation != null ) {
192- if ((attrs . flags & FLAG_SHOW_WALLPAPER ) != 0
196+ if ((flags & FLAG_SHOW_WALLPAPER ) != 0
193197 && winAnimator .mAnimation .getDetachWallpaper ()) {
194- mDetachedWallpaper = w ;
198+ mDetachedWallpaper = win ;
195199 }
196200 final int backgroundColor = winAnimator .mAnimation .getBackgroundColor ();
197201 if (backgroundColor != 0 ) {
198202 if (mWindowAnimationBackground == null
199203 || (winAnimator .mAnimLayer <
200204 mWindowAnimationBackground .mWinAnimator .mAnimLayer )) {
201- mWindowAnimationBackground = w ;
205+ mWindowAnimationBackground = win ;
202206 mWindowAnimationBackgroundColor = backgroundColor ;
203207 }
204208 }
@@ -210,25 +214,25 @@ private void updateWindowsAndWallpaperLocked() {
210214 // animation, make a note so we can ensure the wallpaper is
211215 // displayed behind it.
212216 final AppWindowAnimator appAnimator =
213- w .mAppToken == null ? null : w .mAppToken .mAppAnimator ;
217+ win .mAppToken == null ? null : win .mAppToken .mAppAnimator ;
214218 if (appAnimator != null && appAnimator .animation != null
215219 && appAnimator .animating ) {
216- if ((attrs . flags & FLAG_SHOW_WALLPAPER ) != 0
220+ if ((flags & FLAG_SHOW_WALLPAPER ) != 0
217221 && appAnimator .animation .getDetachWallpaper ()) {
218- mDetachedWallpaper = w ;
222+ mDetachedWallpaper = win ;
219223 }
220224 final int backgroundColor = appAnimator .animation .getBackgroundColor ();
221225 if (backgroundColor != 0 ) {
222226 if (mWindowAnimationBackground == null
223227 || (winAnimator .mAnimLayer <
224228 mWindowAnimationBackground .mWinAnimator .mAnimLayer )) {
225- mWindowAnimationBackground = w ;
229+ mWindowAnimationBackground = win ;
226230 mWindowAnimationBackgroundColor = backgroundColor ;
227231 }
228232 }
229233 }
230234
231- if (wasAnimating && !winAnimator .mAnimating && mService .mWallpaperTarget == w ) {
235+ if (wasAnimating && !winAnimator .mAnimating && mService .mWallpaperTarget == win ) {
232236 mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE ;
233237 mPendingLayoutChanges |= WindowManagerPolicy .FINISH_LAYOUT_REDO_WALLPAPER ;
234238 if (WindowManagerService .DEBUG_LAYOUT_REPEATS ) {
@@ -237,34 +241,34 @@ private void updateWindowsAndWallpaperLocked() {
237241 }
238242 }
239243
240- if (mPolicy .doesForceHide (w , attrs )) {
244+ if (mPolicy .doesForceHide (win , win . mAttrs )) {
241245 if (!wasAnimating && nowAnimating ) {
242246 if (WindowManagerService .DEBUG_VISIBILITY ) Slog .v (TAG ,
243247 "Animation started that could impact force hide: "
244- + w );
248+ + win );
245249 mBulkUpdateParams |= SET_FORCE_HIDING_CHANGED ;
246250 mPendingLayoutChanges |= WindowManagerPolicy .FINISH_LAYOUT_REDO_WALLPAPER ;
247251 if (WindowManagerService .DEBUG_LAYOUT_REPEATS ) {
248252 mService .debugLayoutRepeats ("updateWindowsAndWallpaperLocked 3" ,
249253 mPendingLayoutChanges );
250254 }
251255 mService .mFocusMayChange = true ;
252- } else if (w .isReadyForDisplay () && winAnimator .mAnimation == null ) {
256+ } else if (win .isReadyForDisplay () && winAnimator .mAnimation == null ) {
253257 mForceHiding = true ;
254258 }
255- } else if (mPolicy .canBeForceHidden (w , attrs )) {
259+ } else if (mPolicy .canBeForceHidden (win , win . mAttrs )) {
256260 final boolean changed ;
257261 if (mForceHiding ) {
258- changed = w .hideLw (false , false );
262+ changed = win .hideLw (false , false );
259263 if (WindowManagerService .DEBUG_VISIBILITY && changed ) Slog .v (TAG ,
260- "Now policy hidden: " + w );
264+ "Now policy hidden: " + win );
261265 } else {
262- changed = w .showLw (false , false );
266+ changed = win .showLw (false , false );
263267 if (WindowManagerService .DEBUG_VISIBILITY && changed ) Slog .v (TAG ,
264- "Now policy shown: " + w );
268+ "Now policy shown: " + win );
265269 if (changed ) {
266270 if ((mBulkUpdateParams & SET_FORCE_HIDING_CHANGED ) != 0
267- && w .isVisibleNow () /*w.isReadyForDisplay()*/ ) {
271+ && win .isVisibleNow () /*w.isReadyForDisplay()*/ ) {
268272 // Assume we will need to animate. If
269273 // we don't (because the wallpaper will
270274 // stay with the lock screen), then we will
@@ -274,16 +278,15 @@ private void updateWindowsAndWallpaperLocked() {
274278 winAnimator .setAnimation (a );
275279 }
276280 }
277- if (mCurrentFocus == null || mCurrentFocus .mLayer < w .mLayer ) {
281+ if (mCurrentFocus == null || mCurrentFocus .mLayer < win .mLayer ) {
278282 // We are showing on to of the current
279283 // focus, so re-evaluate focus to make
280284 // sure it is correct.
281285 mService .mFocusMayChange = true ;
282286 }
283287 }
284288 }
285- if (changed && (attrs .flags
286- & WindowManager .LayoutParams .FLAG_SHOW_WALLPAPER ) != 0 ) {
289+ if (changed && (flags & WindowManager .LayoutParams .FLAG_SHOW_WALLPAPER ) != 0 ) {
287290 mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE ;
288291 mPendingLayoutChanges |= WindowManagerPolicy .FINISH_LAYOUT_REDO_WALLPAPER ;
289292 if (WindowManagerService .DEBUG_LAYOUT_REPEATS ) {
@@ -294,44 +297,43 @@ private void updateWindowsAndWallpaperLocked() {
294297 }
295298 }
296299
297- final AppWindowToken atoken = w .mAppToken ;
300+ final AppWindowToken atoken = win .mAppToken ;
298301 if (atoken != null && (!atoken .allDrawn || atoken .mAppAnimator .freezingScreen )) {
299302 if (atoken .lastTransactionSequence != mTransactionSequence ) {
300303 atoken .lastTransactionSequence = mTransactionSequence ;
301304 atoken .numInterestingWindows = atoken .numDrawnWindows = 0 ;
302305 atoken .startingDisplayed = false ;
303306 }
304- if ((w .isOnScreen () || w . mAttrs . type
307+ if ((win .isOnScreen () || winAnimator . mAttrType
305308 == WindowManager .LayoutParams .TYPE_BASE_APPLICATION )
306- && !w .mExiting && !w .mDestroying ) {
309+ && !win .mExiting && !win .mDestroying ) {
307310 if (WindowManagerService .DEBUG_VISIBILITY ||
308311 WindowManagerService .DEBUG_ORIENTATION ) {
309- Slog .v (TAG , "Eval win " + w + ": isDrawn="
310- + w .isDrawnLw ()
312+ Slog .v (TAG , "Eval win " + win + ": isDrawn=" + win .isDrawnLw ()
311313 + ", isAnimating=" + winAnimator .isAnimating ());
312- if (!w .isDrawnLw ()) {
314+ if (!win .isDrawnLw ()) {
313315 Slog .v (TAG , "Not displayed: s=" + winAnimator .mSurface
314- + " pv=" + w .mPolicyVisibility
316+ + " pv=" + win .mPolicyVisibility
315317 + " mDrawState=" + winAnimator .mDrawState
316- + " ah=" + w .mAttachedHidden
318+ + " ah=" + win .mAttachedHidden
317319 + " th=" + atoken .hiddenRequested
318320 + " a=" + winAnimator .mAnimating );
319321 }
320322 }
321- if (w != atoken .startingWindow ) {
322- if (!atoken .mAppAnimator .freezingScreen || !w .mAppFreezing ) {
323+ if (win != atoken .startingWindow ) {
324+ if (!atoken .mAppAnimator .freezingScreen || !win .mAppFreezing ) {
323325 atoken .numInterestingWindows ++;
324- if (w .isDrawnLw ()) {
326+ if (win .isDrawnLw ()) {
325327 atoken .numDrawnWindows ++;
326328 if (WindowManagerService .DEBUG_VISIBILITY ||
327329 WindowManagerService .DEBUG_ORIENTATION ) Slog .v (TAG ,
328330 "tokenMayBeDrawn: " + atoken
329331 + " freezingScreen=" + atoken .mAppAnimator .freezingScreen
330- + " mAppFreezing=" + w .mAppFreezing );
332+ + " mAppFreezing=" + win .mAppFreezing );
331333 mTokenMayBeDrawn = true ;
332334 }
333335 }
334- } else if (w .isDrawnLw ()) {
336+ } else if (win .isDrawnLw ()) {
335337 atoken .startingDisplayed = true ;
336338 }
337339 }
@@ -371,7 +373,7 @@ private void testTokenMayBeDrawnLocked() {
371373 "allDrawn: " + wtoken
372374 + " interesting=" + numInteresting
373375 + " drawn=" + wtoken .numDrawnWindows );
374- wtoken .showAllWindowsLocked ();
376+ wtoken .mAppAnimator . showAllWindowsLocked ();
375377 mService .unsetAppFreezingScreenLocked (wtoken , false , true );
376378 if (WindowManagerService .DEBUG_ORIENTATION ) Slog .i (TAG ,
377379 "Setting mOrientationChangeComplete=true because wtoken "
@@ -394,7 +396,7 @@ private void testTokenMayBeDrawnLocked() {
394396
395397 // We can now show all of the drawn windows!
396398 if (!mService .mOpeningApps .contains (wtoken )) {
397- mAnimating |= wtoken .showAllWindowsLocked ();
399+ mAnimating |= wtoken .mAppAnimator . showAllWindowsLocked ();
398400 }
399401 }
400402 }
@@ -435,9 +437,16 @@ void animate() {
435437 mScreenRotationAnimation .updateSurfaces ();
436438 }
437439
438- for (int i = mService .mWindows .size () - 1 ; i >= 0 ; i --) {
439- WindowState w = mService .mWindows .get (i );
440- w .mWinAnimator .prepareSurfaceLocked (true );
440+ mFinished .clear ();
441+ for (final WindowStateAnimator winAnimator : mWinAnimators ) {
442+ if (winAnimator .mSurface == null ) {
443+ mFinished .add (winAnimator );
444+ } else {
445+ winAnimator .prepareSurfaceLocked (true );
446+ }
447+ }
448+ for (final WindowStateAnimator winAnimator : mFinished ) {
449+ mWinAnimators .remove (winAnimator );
441450 }
442451
443452 if (mDimParams != null ) {
@@ -509,4 +518,18 @@ public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
509518 pw .println ( " no DimAnimator " );
510519 }
511520 }
521+
522+ static class SetAnimationParams {
523+ final WindowStateAnimator mWinAnimator ;
524+ final Animation mAnimation ;
525+ final int mAnimDw ;
526+ final int mAnimDh ;
527+ public SetAnimationParams (final WindowStateAnimator winAnimator ,
528+ final Animation animation , final int animDw , final int animDh ) {
529+ mWinAnimator = winAnimator ;
530+ mAnimation = animation ;
531+ mAnimDw = animDw ;
532+ mAnimDh = animDh ;
533+ }
534+ }
512535}
0 commit comments