Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 1 | // Copyright 2012 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | package com.android.server.wm; |
| 4 | |
| 5 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 6 | |
| 7 | import android.content.Context; |
| 8 | import android.os.SystemClock; |
| 9 | import android.util.Log; |
| 10 | import android.util.Slog; |
| 11 | import android.view.Surface; |
| 12 | import android.view.WindowManager; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 13 | import android.view.WindowManagerPolicy; |
| 14 | import android.view.animation.Animation; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 15 | |
| 16 | import com.android.internal.policy.impl.PhoneWindowManager; |
| 17 | |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 18 | import java.io.PrintWriter; |
| 19 | |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 20 | /** |
| 21 | * @author cmautner@google.com (Craig Mautner) |
| 22 | * Singleton class that carries out the animations and Surface operations in a separate task |
| 23 | * on behalf of WindowManagerService. |
| 24 | */ |
| 25 | public class WindowAnimator { |
Craig Mautner | bb1449b3 | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 26 | private static final String TAG = "WindowAnimator"; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 27 | |
| 28 | final WindowManagerService mService; |
| 29 | final Context mContext; |
| 30 | final WindowManagerPolicy mPolicy; |
| 31 | |
| 32 | boolean mAnimating; |
| 33 | boolean mUpdateRotation; |
| 34 | boolean mTokenMayBeDrawn; |
| 35 | boolean mForceHiding; |
| 36 | WindowState mWindowAnimationBackground; |
| 37 | int mWindowAnimationBackgroundColor; |
| 38 | int mAdjResult; |
| 39 | |
| 40 | int mPendingLayoutChanges; |
| 41 | |
| 42 | /** Overall window dimensions */ |
| 43 | int mDw, mDh; |
| 44 | |
| 45 | /** Interior window dimensions */ |
| 46 | int mInnerDw, mInnerDh; |
| 47 | |
| 48 | /** Time of current animation step. Reset on each iteration */ |
| 49 | long mCurrentTime; |
| 50 | |
| 51 | /** Skip repeated AppWindowTokens initialization. Note that AppWindowsToken's version of this |
| 52 | * is a long initialized to Long.MIN_VALUE so that it doesn't match this value on startup. */ |
| 53 | private int mTransactionSequence; |
| 54 | |
| 55 | /** The one and only screen rotation if one is happening */ |
| 56 | ScreenRotationAnimation mScreenRotationAnimation = null; |
| 57 | |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 58 | // Window currently running an animation that has requested it be detached |
| 59 | // from the wallpaper. This means we need to ensure the wallpaper is |
| 60 | // visible behind it in case it animates in a way that would allow it to be |
| 61 | // seen. |
| 62 | WindowState mWindowDetachedWallpaper = null; |
| 63 | WindowState mDetachedWallpaper = null; |
| 64 | boolean mWallpaperMayChange; |
| 65 | DimSurface mWindowAnimationBackgroundSurface = null; |
| 66 | |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 67 | WindowAnimator(final WindowManagerService service, final Context context, |
| 68 | final WindowManagerPolicy policy) { |
| 69 | mService = service; |
| 70 | mContext = context; |
| 71 | mPolicy = policy; |
| 72 | } |
| 73 | |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 74 | private void testWallpaperAndBackgroundLocked() { |
| 75 | if (mWindowDetachedWallpaper != mDetachedWallpaper) { |
| 76 | if (WindowManagerService.DEBUG_WALLPAPER) Slog.v(TAG, |
| 77 | "Detached wallpaper changed from " + mWindowDetachedWallpaper |
| 78 | + " to " + mDetachedWallpaper); |
| 79 | mWindowDetachedWallpaper = mDetachedWallpaper; |
| 80 | mWallpaperMayChange = true; |
| 81 | } |
| 82 | |
| 83 | if (mWindowAnimationBackgroundColor != 0) { |
| 84 | // If the window that wants black is the current wallpaper |
| 85 | // target, then the black goes *below* the wallpaper so we |
| 86 | // don't cause the wallpaper to suddenly disappear. |
| 87 | WindowState target = mWindowAnimationBackground; |
| 88 | if (mService.mWallpaperTarget == target |
| 89 | || mService.mLowerWallpaperTarget == target |
| 90 | || mService.mUpperWallpaperTarget == target) { |
| 91 | for (int i=0; i<mService.mWindows.size(); i++) { |
| 92 | WindowState w = mService.mWindows.get(i); |
| 93 | if (w.mIsWallpaper) { |
| 94 | target = w; |
| 95 | break; |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | if (mWindowAnimationBackgroundSurface == null) { |
| 100 | mWindowAnimationBackgroundSurface = new DimSurface(mService.mFxSession); |
| 101 | } |
| 102 | final int dw = mDw; |
| 103 | final int dh = mDh; |
| 104 | mWindowAnimationBackgroundSurface.show(dw, dh, |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame^] | 105 | target.mWinAnimator.mAnimLayer - WindowManagerService.LAYER_OFFSET_DIM, |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 106 | mWindowAnimationBackgroundColor); |
| 107 | } else if (mWindowAnimationBackgroundSurface != null) { |
| 108 | mWindowAnimationBackgroundSurface.hide(); |
| 109 | } |
| 110 | } |
| 111 | |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 112 | private void updateWindowsAppsAndRotationAnimationsLocked() { |
| 113 | int i; |
| 114 | final int NAT = mService.mAppTokens.size(); |
| 115 | for (i=0; i<NAT; i++) { |
| 116 | final AppWindowToken appToken = mService.mAppTokens.get(i); |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 117 | final boolean wasAnimating = appToken.animation != null |
| 118 | && appToken.animation != WindowManagerService.sDummyAnimation; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 119 | if (appToken.stepAnimationLocked(mCurrentTime, mInnerDw, mInnerDh)) { |
| 120 | mAnimating = true; |
Craig Mautner | bb1449b3 | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 121 | } else if (wasAnimating) { |
| 122 | // stopped animating, do one more pass through the layout |
| 123 | mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 124 | if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { |
| 125 | mService.debugLayoutRepeats("appToken " + appToken + " done"); |
| 126 | } |
Craig Mautner | bb1449b3 | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 127 | } |
| 128 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 129 | |
Craig Mautner | bb1449b3 | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 130 | final int NEAT = mService.mExitingAppTokens.size(); |
| 131 | for (i=0; i<NEAT; i++) { |
| 132 | final AppWindowToken appToken = mService.mExitingAppTokens.get(i); |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 133 | final boolean wasAnimating = appToken.animation != null |
| 134 | && appToken.animation != WindowManagerService.sDummyAnimation; |
Craig Mautner | bb1449b3 | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 135 | if (appToken.stepAnimationLocked(mCurrentTime, mInnerDw, mInnerDh)) { |
| 136 | mAnimating = true; |
| 137 | } else if (wasAnimating) { |
| 138 | // stopped animating, do one more pass through the layout |
| 139 | mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 140 | if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { |
| 141 | mService.debugLayoutRepeats("exiting appToken " + appToken + " done"); |
| 142 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
| 146 | if (mScreenRotationAnimation != null && |
| 147 | (mScreenRotationAnimation.isAnimating() || |
| 148 | mScreenRotationAnimation.mFinishAnimReady)) { |
| 149 | if (mScreenRotationAnimation.stepAnimationLocked(mCurrentTime)) { |
| 150 | mUpdateRotation = false; |
| 151 | mAnimating = true; |
| 152 | } else { |
| 153 | mUpdateRotation = true; |
| 154 | mScreenRotationAnimation.kill(); |
| 155 | mScreenRotationAnimation = null; |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | private void updateWindowsAndWallpaperLocked() { |
| 161 | ++mTransactionSequence; |
| 162 | |
| 163 | for (int i = mService.mWindows.size() - 1; i >= 0; i--) { |
| 164 | WindowState w = mService.mWindows.get(i); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 165 | WindowStateAnimator winAnimator = w.mWinAnimator; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 166 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 167 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame^] | 168 | if (winAnimator.mSurface != null) { |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 169 | final boolean wasAnimating = winAnimator.mWasAnimating; |
| 170 | final boolean nowAnimating = winAnimator.stepAnimationLocked(mCurrentTime); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 171 | |
| 172 | if (WindowManagerService.DEBUG_WALLPAPER) { |
| 173 | Slog.v(TAG, w + ": wasAnimating=" + wasAnimating + |
| 174 | ", nowAnimating=" + nowAnimating); |
| 175 | } |
| 176 | |
| 177 | // If this window is animating, make a note that we have |
| 178 | // an animating window and take care of a request to run |
| 179 | // a detached wallpaper animation. |
| 180 | if (nowAnimating) { |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 181 | if (winAnimator.mAnimation != null) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame^] | 182 | if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0 |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 183 | && winAnimator.mAnimation.getDetachWallpaper()) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame^] | 184 | mDetachedWallpaper = w; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 185 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 186 | if (winAnimator.mAnimation.getBackgroundColor() != 0) { |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 187 | if (mWindowAnimationBackground == null |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame^] | 188 | || (winAnimator.mAnimLayer < |
| 189 | mWindowAnimationBackground.mWinAnimator.mAnimLayer)) { |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 190 | mWindowAnimationBackground = w; |
| 191 | mWindowAnimationBackgroundColor = |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 192 | winAnimator.mAnimation.getBackgroundColor(); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | } |
| 196 | mAnimating = true; |
| 197 | } |
| 198 | |
| 199 | // If this window's app token is running a detached wallpaper |
| 200 | // animation, make a note so we can ensure the wallpaper is |
| 201 | // displayed behind it. |
| 202 | if (w.mAppToken != null && w.mAppToken.animation != null |
| 203 | && w.mAppToken.animating) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame^] | 204 | if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0 |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 205 | && w.mAppToken.animation.getDetachWallpaper()) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame^] | 206 | mDetachedWallpaper = w; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 207 | } |
| 208 | if (w.mAppToken.animation.getBackgroundColor() != 0) { |
| 209 | if (mWindowAnimationBackground == null |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame^] | 210 | || (winAnimator.mAnimLayer < |
| 211 | mWindowAnimationBackground.mWinAnimator.mAnimLayer)) { |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 212 | mWindowAnimationBackground = w; |
| 213 | mWindowAnimationBackgroundColor = |
| 214 | w.mAppToken.animation.getBackgroundColor(); |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 219 | if (wasAnimating && !winAnimator.mAnimating && mService.mWallpaperTarget == w) { |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 220 | mWallpaperMayChange = true; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 221 | mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 222 | if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { |
| 223 | mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 2"); |
| 224 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | if (mPolicy.doesForceHide(w, attrs)) { |
| 228 | if (!wasAnimating && nowAnimating) { |
| 229 | if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, |
| 230 | "Animation started that could impact force hide: " |
| 231 | + w); |
| 232 | mService.mInnerFields.mWallpaperForceHidingChanged = true; |
| 233 | mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 234 | if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { |
| 235 | mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 3"); |
| 236 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 237 | mService.mFocusMayChange = true; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 238 | } else if (w.isReadyForDisplay() && winAnimator.mAnimation == null) { |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 239 | mForceHiding = true; |
| 240 | } |
| 241 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 242 | boolean changed; |
| 243 | if (mForceHiding) { |
| 244 | changed = w.hideLw(false, false); |
| 245 | if (WindowManagerService.DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 246 | "Now policy hidden: " + w); |
| 247 | } else { |
| 248 | changed = w.showLw(false, false); |
| 249 | if (WindowManagerService.DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 250 | "Now policy shown: " + w); |
| 251 | if (changed) { |
| 252 | if (mService.mInnerFields.mWallpaperForceHidingChanged |
| 253 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
| 254 | // Assume we will need to animate. If |
| 255 | // we don't (because the wallpaper will |
| 256 | // stay with the lock screen), then we will |
| 257 | // clean up later. |
| 258 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 259 | if (a != null) { |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 260 | winAnimator.setAnimation(a); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | if (mCurrentFocus == null || mCurrentFocus.mLayer < w.mLayer) { |
| 264 | // We are showing on to of the current |
| 265 | // focus, so re-evaluate focus to make |
| 266 | // sure it is correct. |
| 267 | mService.mFocusMayChange = true; |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | if (changed && (attrs.flags |
| 272 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 273 | mWallpaperMayChange = true; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 274 | mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 275 | if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { |
| 276 | mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 4"); |
| 277 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | final AppWindowToken atoken = w.mAppToken; |
| 283 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 284 | if (atoken.lastTransactionSequence != mTransactionSequence) { |
| 285 | atoken.lastTransactionSequence = mTransactionSequence; |
| 286 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 287 | atoken.startingDisplayed = false; |
| 288 | } |
| 289 | if ((w.isOnScreen() || w.mAttrs.type |
| 290 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 291 | && !w.mExiting && !w.mDestroying) { |
| 292 | if (WindowManagerService.DEBUG_VISIBILITY || |
| 293 | WindowManagerService.DEBUG_ORIENTATION) { |
| 294 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
| 295 | + w.isDrawnLw() |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 296 | + ", isAnimating=" + winAnimator.isAnimating()); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 297 | if (!w.isDrawnLw()) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame^] | 298 | Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurface |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 299 | + " pv=" + w.mPolicyVisibility |
| 300 | + " dp=" + w.mDrawPending |
| 301 | + " cdp=" + w.mCommitDrawPending |
| 302 | + " ah=" + w.mAttachedHidden |
| 303 | + " th=" + atoken.hiddenRequested |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 304 | + " a=" + winAnimator.mAnimating); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | if (w != atoken.startingWindow) { |
| 308 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 309 | atoken.numInterestingWindows++; |
| 310 | if (w.isDrawnLw()) { |
| 311 | atoken.numDrawnWindows++; |
| 312 | if (WindowManagerService.DEBUG_VISIBILITY || |
| 313 | WindowManagerService.DEBUG_ORIENTATION) Slog.v(TAG, |
| 314 | "tokenMayBeDrawn: " + atoken |
| 315 | + " freezingScreen=" + atoken.freezingScreen |
| 316 | + " mAppFreezing=" + w.mAppFreezing); |
| 317 | mTokenMayBeDrawn = true; |
| 318 | } |
| 319 | } |
| 320 | } else if (w.isDrawnLw()) { |
| 321 | atoken.startingDisplayed = true; |
| 322 | } |
| 323 | } |
| 324 | } else if (w.mReadyToShow) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame^] | 325 | if (winAnimator.performShowLocked()) { |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 326 | mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; |
| 327 | if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { |
| 328 | mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 5"); |
| 329 | } |
| 330 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 331 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 332 | if (atoken != null && atoken.thumbnail != null) { |
| 333 | if (atoken.thumbnailTransactionSeq != mTransactionSequence) { |
| 334 | atoken.thumbnailTransactionSeq = mTransactionSequence; |
| 335 | atoken.thumbnailLayer = 0; |
| 336 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame^] | 337 | if (atoken.thumbnailLayer < winAnimator.mAnimLayer) { |
| 338 | atoken.thumbnailLayer = winAnimator.mAnimLayer; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 339 | } |
| 340 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 341 | } // end forall windows |
| 342 | } |
| 343 | |
| 344 | private void testTokenMayBeDrawnLocked() { |
| 345 | // See if any windows have been drawn, so they (and others |
| 346 | // associated with them) can now be shown. |
| 347 | final int NT = mService.mAppTokens.size(); |
| 348 | for (int i=0; i<NT; i++) { |
| 349 | AppWindowToken wtoken = mService.mAppTokens.get(i); |
| 350 | if (wtoken.freezingScreen) { |
| 351 | int numInteresting = wtoken.numInterestingWindows; |
| 352 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 353 | if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, |
| 354 | "allDrawn: " + wtoken |
| 355 | + " interesting=" + numInteresting |
| 356 | + " drawn=" + wtoken.numDrawnWindows); |
| 357 | wtoken.showAllWindowsLocked(); |
| 358 | mService.unsetAppFreezingScreenLocked(wtoken, false, true); |
| 359 | if (WindowManagerService.DEBUG_ORIENTATION) Slog.i(TAG, |
| 360 | "Setting mOrientationChangeComplete=true because wtoken " |
| 361 | + wtoken + " numInteresting=" + numInteresting |
| 362 | + " numDrawn=" + wtoken.numDrawnWindows); |
| 363 | mService.mInnerFields.mOrientationChangeComplete = true; |
| 364 | } |
| 365 | } else if (!wtoken.allDrawn) { |
| 366 | int numInteresting = wtoken.numInterestingWindows; |
| 367 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 368 | if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, |
| 369 | "allDrawn: " + wtoken |
| 370 | + " interesting=" + numInteresting |
| 371 | + " drawn=" + wtoken.numDrawnWindows); |
| 372 | wtoken.allDrawn = true; |
| 373 | mPendingLayoutChanges |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 374 | if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { |
| 375 | mService.debugLayoutRepeats("testTokenMayBeDrawnLocked"); |
| 376 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 377 | |
| 378 | // We can now show all of the drawn windows! |
| 379 | if (!mService.mOpeningApps.contains(wtoken)) { |
| 380 | mAnimating |= wtoken.showAllWindowsLocked(); |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | private void performAnimationsLocked() { |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 388 | mTokenMayBeDrawn = false; |
| 389 | mService.mInnerFields.mWallpaperMayChange = false; |
| 390 | mForceHiding = false; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame^] | 391 | mDetachedWallpaper = null; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 392 | mWindowAnimationBackground = null; |
| 393 | mWindowAnimationBackgroundColor = 0; |
| 394 | |
| 395 | updateWindowsAndWallpaperLocked(); |
| 396 | |
| 397 | if (mTokenMayBeDrawn) { |
| 398 | testTokenMayBeDrawnLocked(); |
| 399 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 402 | |
| 403 | void animate() { |
Craig Mautner | bb1449b3 | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 404 | mPendingLayoutChanges = 0; |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 405 | mWallpaperMayChange = false; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 406 | mCurrentTime = SystemClock.uptimeMillis(); |
| 407 | |
| 408 | // Update animations of all applications, including those |
| 409 | // associated with exiting/removed apps |
| 410 | Surface.openTransaction(); |
| 411 | |
| 412 | try { |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 413 | testWallpaperAndBackgroundLocked(); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 414 | updateWindowsAppsAndRotationAnimationsLocked(); |
| 415 | performAnimationsLocked(); |
| 416 | |
| 417 | // THIRD LOOP: Update the surfaces of all windows. |
| 418 | |
| 419 | if (mScreenRotationAnimation != null) { |
| 420 | mScreenRotationAnimation.updateSurfaces(); |
| 421 | } |
| 422 | |
| 423 | final int N = mService.mWindows.size(); |
| 424 | for (int i=N-1; i>=0; i--) { |
| 425 | WindowState w = mService.mWindows.get(i); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame^] | 426 | w.mWinAnimator.prepareSurfaceLocked(true); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | if (mService.mDimAnimator != null && mService.mDimAnimator.mDimShown) { |
| 430 | mAnimating |= mService.mDimAnimator.updateSurface(mService.mInnerFields.mDimming, |
| 431 | mCurrentTime, !mService.okToDisplay()); |
| 432 | } |
| 433 | |
| 434 | if (mService.mBlackFrame != null) { |
| 435 | if (mScreenRotationAnimation != null) { |
| 436 | mService.mBlackFrame.setMatrix( |
| 437 | mScreenRotationAnimation.getEnterTransformation().getMatrix()); |
| 438 | } else { |
| 439 | mService.mBlackFrame.clearMatrix(); |
| 440 | } |
| 441 | } |
| 442 | } catch (RuntimeException e) { |
| 443 | Log.wtf(TAG, "Unhandled exception in Window Manager", e); |
| 444 | } finally { |
| 445 | Surface.closeTransaction(); |
| 446 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame^] | 447 | |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 448 | if (mWallpaperMayChange) { |
| 449 | mService.notifyWallpaperMayChange(); |
| 450 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | WindowState mCurrentFocus; |
| 454 | void setCurrentFocus(WindowState currentFocus) { |
| 455 | mCurrentFocus = currentFocus; |
| 456 | } |
| 457 | |
| 458 | void setDisplayDimensions(final int curWidth, final int curHeight, |
| 459 | final int appWidth, final int appHeight) { |
| 460 | mDw = curWidth; |
| 461 | mDh = curHeight; |
| 462 | mInnerDw = appWidth; |
| 463 | mInnerDh = appHeight; |
| 464 | } |
| 465 | |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 466 | public void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
| 467 | if (mWindowDetachedWallpaper != null) { |
| 468 | pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper); |
| 469 | } |
| 470 | if (mWindowAnimationBackgroundSurface != null) { |
| 471 | pw.println(" mWindowAnimationBackgroundSurface:"); |
| 472 | mWindowAnimationBackgroundSurface.printTo(" ", pw); |
| 473 | } |
| 474 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 475 | } |