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; |
| 13 | import android.view.WindowManager.LayoutParams; |
| 14 | import android.view.WindowManagerPolicy; |
| 15 | import android.view.animation.Animation; |
| 16 | import android.view.animation.AnimationUtils; |
| 17 | |
| 18 | import com.android.internal.policy.impl.PhoneWindowManager; |
| 19 | |
| 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 | bb1449b | 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 | |
| 58 | WindowAnimator(final WindowManagerService service, final Context context, |
| 59 | final WindowManagerPolicy policy) { |
| 60 | mService = service; |
| 61 | mContext = context; |
| 62 | mPolicy = policy; |
| 63 | } |
| 64 | |
| 65 | private void updateWindowsAppsAndRotationAnimationsLocked() { |
| 66 | int i; |
| 67 | final int NAT = mService.mAppTokens.size(); |
| 68 | for (i=0; i<NAT; i++) { |
| 69 | final AppWindowToken appToken = mService.mAppTokens.get(i); |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 70 | final boolean wasAnimating = appToken.animation != null |
| 71 | && appToken.animation != WindowManagerService.sDummyAnimation; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 72 | if (appToken.stepAnimationLocked(mCurrentTime, mInnerDw, mInnerDh)) { |
| 73 | mAnimating = true; |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 74 | } else if (wasAnimating) { |
| 75 | // stopped animating, do one more pass through the layout |
| 76 | mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 77 | if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { |
| 78 | mService.debugLayoutRepeats("appToken " + appToken + " done"); |
| 79 | } |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 80 | } |
| 81 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame^] | 82 | |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 83 | final int NEAT = mService.mExitingAppTokens.size(); |
| 84 | for (i=0; i<NEAT; i++) { |
| 85 | final AppWindowToken appToken = mService.mExitingAppTokens.get(i); |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 86 | final boolean wasAnimating = appToken.animation != null |
| 87 | && appToken.animation != WindowManagerService.sDummyAnimation; |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 88 | if (appToken.stepAnimationLocked(mCurrentTime, mInnerDw, mInnerDh)) { |
| 89 | mAnimating = true; |
| 90 | } else if (wasAnimating) { |
| 91 | // stopped animating, do one more pass through the layout |
| 92 | mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 93 | if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { |
| 94 | mService.debugLayoutRepeats("exiting appToken " + appToken + " done"); |
| 95 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
| 99 | if (mScreenRotationAnimation != null && |
| 100 | (mScreenRotationAnimation.isAnimating() || |
| 101 | mScreenRotationAnimation.mFinishAnimReady)) { |
| 102 | if (mScreenRotationAnimation.stepAnimationLocked(mCurrentTime)) { |
| 103 | mUpdateRotation = false; |
| 104 | mAnimating = true; |
| 105 | } else { |
| 106 | mUpdateRotation = true; |
| 107 | mScreenRotationAnimation.kill(); |
| 108 | mScreenRotationAnimation = null; |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | private void updateWindowsAndWallpaperLocked() { |
| 114 | ++mTransactionSequence; |
| 115 | |
| 116 | for (int i = mService.mWindows.size() - 1; i >= 0; i--) { |
| 117 | WindowState w = mService.mWindows.get(i); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame^] | 118 | WindowStateAnimator winAnimator = w.mWinAnimator; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 119 | |
| 120 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 121 | |
| 122 | if (w.mSurface != null) { |
| 123 | // Take care of the window being ready to display. |
| 124 | if (w.commitFinishDrawingLocked(mCurrentTime)) { |
| 125 | if ((w.mAttrs.flags |
| 126 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 127 | if (WindowManagerService.DEBUG_WALLPAPER) Slog.v(TAG, |
| 128 | "First draw done in potential wallpaper target " + w); |
| 129 | mService.mInnerFields.mWallpaperMayChange = true; |
| 130 | mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 131 | if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { |
| 132 | mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 1"); |
| 133 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | |
| 137 | // If the window has moved due to its containing |
| 138 | // content frame changing, then we'd like to animate |
| 139 | // it. The checks here are ordered by what is least |
| 140 | // likely to be true first. |
| 141 | if (w.shouldAnimateMove()) { |
| 142 | // Frame has moved, containing content frame |
| 143 | // has also moved, and we're not currently animating... |
| 144 | // let's do something. |
| 145 | Animation a = AnimationUtils.loadAnimation(mContext, |
| 146 | com.android.internal.R.anim.window_move_from_decor); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame^] | 147 | winAnimator.setAnimation(a); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 148 | w.mAnimDw = w.mLastFrame.left - w.mFrame.left; |
| 149 | w.mAnimDh = w.mLastFrame.top - w.mFrame.top; |
| 150 | } else { |
| 151 | w.mAnimDw = mInnerDw; |
| 152 | w.mAnimDh = mInnerDh; |
| 153 | } |
| 154 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame^] | 155 | final boolean wasAnimating = winAnimator.mWasAnimating; |
| 156 | final boolean nowAnimating = winAnimator.stepAnimationLocked(mCurrentTime); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 157 | |
| 158 | if (WindowManagerService.DEBUG_WALLPAPER) { |
| 159 | Slog.v(TAG, w + ": wasAnimating=" + wasAnimating + |
| 160 | ", nowAnimating=" + nowAnimating); |
| 161 | } |
| 162 | |
| 163 | // If this window is animating, make a note that we have |
| 164 | // an animating window and take care of a request to run |
| 165 | // a detached wallpaper animation. |
| 166 | if (nowAnimating) { |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame^] | 167 | if (winAnimator.mAnimation != null) { |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 168 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame^] | 169 | && winAnimator.mAnimation.getDetachWallpaper()) { |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 170 | mService.mInnerFields.mDetachedWallpaper = w; |
| 171 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame^] | 172 | if (winAnimator.mAnimation.getBackgroundColor() != 0) { |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 173 | if (mWindowAnimationBackground == null |
| 174 | || (w.mAnimLayer < mWindowAnimationBackground.mAnimLayer)) { |
| 175 | mWindowAnimationBackground = w; |
| 176 | mWindowAnimationBackgroundColor = |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame^] | 177 | winAnimator.mAnimation.getBackgroundColor(); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | } |
| 181 | mAnimating = true; |
| 182 | } |
| 183 | |
| 184 | // If this window's app token is running a detached wallpaper |
| 185 | // animation, make a note so we can ensure the wallpaper is |
| 186 | // displayed behind it. |
| 187 | if (w.mAppToken != null && w.mAppToken.animation != null |
| 188 | && w.mAppToken.animating) { |
| 189 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 |
| 190 | && w.mAppToken.animation.getDetachWallpaper()) { |
| 191 | mService.mInnerFields.mDetachedWallpaper = w; |
| 192 | } |
| 193 | if (w.mAppToken.animation.getBackgroundColor() != 0) { |
| 194 | if (mWindowAnimationBackground == null |
| 195 | || (w.mAnimLayer < |
| 196 | mWindowAnimationBackground.mAnimLayer)) { |
| 197 | mWindowAnimationBackground = w; |
| 198 | mWindowAnimationBackgroundColor = |
| 199 | w.mAppToken.animation.getBackgroundColor(); |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame^] | 204 | if (wasAnimating && !winAnimator.mAnimating && mService.mWallpaperTarget == w) { |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 205 | mService.mInnerFields.mWallpaperMayChange = true; |
| 206 | mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 207 | if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { |
| 208 | mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 2"); |
| 209 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | if (mPolicy.doesForceHide(w, attrs)) { |
| 213 | if (!wasAnimating && nowAnimating) { |
| 214 | if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, |
| 215 | "Animation started that could impact force hide: " |
| 216 | + w); |
| 217 | mService.mInnerFields.mWallpaperForceHidingChanged = true; |
| 218 | mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 219 | if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { |
| 220 | mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 3"); |
| 221 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 222 | mService.mFocusMayChange = true; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame^] | 223 | } else if (w.isReadyForDisplay() && winAnimator.mAnimation == null) { |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 224 | mForceHiding = true; |
| 225 | } |
| 226 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 227 | boolean changed; |
| 228 | if (mForceHiding) { |
| 229 | changed = w.hideLw(false, false); |
| 230 | if (WindowManagerService.DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 231 | "Now policy hidden: " + w); |
| 232 | } else { |
| 233 | changed = w.showLw(false, false); |
| 234 | if (WindowManagerService.DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 235 | "Now policy shown: " + w); |
| 236 | if (changed) { |
| 237 | if (mService.mInnerFields.mWallpaperForceHidingChanged |
| 238 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
| 239 | // Assume we will need to animate. If |
| 240 | // we don't (because the wallpaper will |
| 241 | // stay with the lock screen), then we will |
| 242 | // clean up later. |
| 243 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 244 | if (a != null) { |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame^] | 245 | winAnimator.setAnimation(a); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | if (mCurrentFocus == null || mCurrentFocus.mLayer < w.mLayer) { |
| 249 | // We are showing on to of the current |
| 250 | // focus, so re-evaluate focus to make |
| 251 | // sure it is correct. |
| 252 | mService.mFocusMayChange = true; |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | if (changed && (attrs.flags |
| 257 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 258 | mService.mInnerFields.mWallpaperMayChange = true; |
| 259 | mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 260 | if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { |
| 261 | mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 4"); |
| 262 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | final AppWindowToken atoken = w.mAppToken; |
| 268 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 269 | if (atoken.lastTransactionSequence != mTransactionSequence) { |
| 270 | atoken.lastTransactionSequence = mTransactionSequence; |
| 271 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 272 | atoken.startingDisplayed = false; |
| 273 | } |
| 274 | if ((w.isOnScreen() || w.mAttrs.type |
| 275 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 276 | && !w.mExiting && !w.mDestroying) { |
| 277 | if (WindowManagerService.DEBUG_VISIBILITY || |
| 278 | WindowManagerService.DEBUG_ORIENTATION) { |
| 279 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
| 280 | + w.isDrawnLw() |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame^] | 281 | + ", isAnimating=" + winAnimator.isAnimating()); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 282 | if (!w.isDrawnLw()) { |
| 283 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
| 284 | + " pv=" + w.mPolicyVisibility |
| 285 | + " dp=" + w.mDrawPending |
| 286 | + " cdp=" + w.mCommitDrawPending |
| 287 | + " ah=" + w.mAttachedHidden |
| 288 | + " th=" + atoken.hiddenRequested |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame^] | 289 | + " a=" + winAnimator.mAnimating); |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | if (w != atoken.startingWindow) { |
| 293 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 294 | atoken.numInterestingWindows++; |
| 295 | if (w.isDrawnLw()) { |
| 296 | atoken.numDrawnWindows++; |
| 297 | if (WindowManagerService.DEBUG_VISIBILITY || |
| 298 | WindowManagerService.DEBUG_ORIENTATION) Slog.v(TAG, |
| 299 | "tokenMayBeDrawn: " + atoken |
| 300 | + " freezingScreen=" + atoken.freezingScreen |
| 301 | + " mAppFreezing=" + w.mAppFreezing); |
| 302 | mTokenMayBeDrawn = true; |
| 303 | } |
| 304 | } |
| 305 | } else if (w.isDrawnLw()) { |
| 306 | atoken.startingDisplayed = true; |
| 307 | } |
| 308 | } |
| 309 | } else if (w.mReadyToShow) { |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 310 | if (w.performShowLocked()) { |
| 311 | mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; |
| 312 | if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { |
| 313 | mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 5"); |
| 314 | } |
| 315 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 316 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 317 | if (atoken != null && atoken.thumbnail != null) { |
| 318 | if (atoken.thumbnailTransactionSeq != mTransactionSequence) { |
| 319 | atoken.thumbnailTransactionSeq = mTransactionSequence; |
| 320 | atoken.thumbnailLayer = 0; |
| 321 | } |
| 322 | if (atoken.thumbnailLayer < w.mAnimLayer) { |
| 323 | atoken.thumbnailLayer = w.mAnimLayer; |
| 324 | } |
| 325 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 326 | } // end forall windows |
| 327 | } |
| 328 | |
| 329 | private void testTokenMayBeDrawnLocked() { |
| 330 | // See if any windows have been drawn, so they (and others |
| 331 | // associated with them) can now be shown. |
| 332 | final int NT = mService.mAppTokens.size(); |
| 333 | for (int i=0; i<NT; i++) { |
| 334 | AppWindowToken wtoken = mService.mAppTokens.get(i); |
| 335 | if (wtoken.freezingScreen) { |
| 336 | int numInteresting = wtoken.numInterestingWindows; |
| 337 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| 338 | if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, |
| 339 | "allDrawn: " + wtoken |
| 340 | + " interesting=" + numInteresting |
| 341 | + " drawn=" + wtoken.numDrawnWindows); |
| 342 | wtoken.showAllWindowsLocked(); |
| 343 | mService.unsetAppFreezingScreenLocked(wtoken, false, true); |
| 344 | if (WindowManagerService.DEBUG_ORIENTATION) Slog.i(TAG, |
| 345 | "Setting mOrientationChangeComplete=true because wtoken " |
| 346 | + wtoken + " numInteresting=" + numInteresting |
| 347 | + " numDrawn=" + wtoken.numDrawnWindows); |
| 348 | mService.mInnerFields.mOrientationChangeComplete = true; |
| 349 | } |
| 350 | } else if (!wtoken.allDrawn) { |
| 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.allDrawn = true; |
| 358 | mPendingLayoutChanges |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Craig Mautner | cf8cbbe | 2012-03-25 21:54:36 -0700 | [diff] [blame] | 359 | if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { |
| 360 | mService.debugLayoutRepeats("testTokenMayBeDrawnLocked"); |
| 361 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 362 | |
| 363 | // We can now show all of the drawn windows! |
| 364 | if (!mService.mOpeningApps.contains(wtoken)) { |
| 365 | mAnimating |= wtoken.showAllWindowsLocked(); |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | private void performAnimationsLocked() { |
| 373 | if (WindowManagerService.DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
| 374 | + mTransactionSequence + " mAnimating=" |
| 375 | + mAnimating); |
| 376 | |
| 377 | mTokenMayBeDrawn = false; |
| 378 | mService.mInnerFields.mWallpaperMayChange = false; |
| 379 | mForceHiding = false; |
| 380 | mService.mInnerFields.mDetachedWallpaper = null; |
| 381 | mWindowAnimationBackground = null; |
| 382 | mWindowAnimationBackgroundColor = 0; |
| 383 | |
| 384 | updateWindowsAndWallpaperLocked(); |
| 385 | |
| 386 | if (mTokenMayBeDrawn) { |
| 387 | testTokenMayBeDrawnLocked(); |
| 388 | } |
| 389 | |
| 390 | if (WindowManagerService.DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 391 | + Integer.toHexString(mPendingLayoutChanges)); |
| 392 | } |
| 393 | |
| 394 | public void prepareSurfaceLocked(final WindowState w, final boolean recoveringMemory) { |
| 395 | if (w.mSurface == null) { |
| 396 | if (w.mOrientationChanging) { |
| 397 | if (WindowManagerService.DEBUG_ORIENTATION) { |
| 398 | Slog.v(TAG, "Orientation change skips hidden " + w); |
| 399 | } |
| 400 | w.mOrientationChanging = false; |
| 401 | } |
| 402 | return; |
| 403 | } |
| 404 | |
| 405 | boolean displayed = false; |
| 406 | |
| 407 | w.computeShownFrameLocked(); |
| 408 | |
| 409 | int width, height; |
| 410 | if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 411 | // for a scaled surface, we just want to use |
| 412 | // the requested size. |
| 413 | width = w.mRequestedWidth; |
| 414 | height = w.mRequestedHeight; |
| 415 | } else { |
| 416 | width = w.mCompatFrame.width(); |
| 417 | height = w.mCompatFrame.height(); |
| 418 | } |
| 419 | |
| 420 | if (width < 1) { |
| 421 | width = 1; |
| 422 | } |
| 423 | if (height < 1) { |
| 424 | height = 1; |
| 425 | } |
| 426 | final boolean surfaceResized = w.mSurfaceW != width || w.mSurfaceH != height; |
| 427 | if (surfaceResized) { |
| 428 | w.mSurfaceW = width; |
| 429 | w.mSurfaceH = height; |
| 430 | } |
| 431 | |
| 432 | if (w.mSurfaceX != w.mShownFrame.left |
| 433 | || w.mSurfaceY != w.mShownFrame.top) { |
| 434 | try { |
| 435 | if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w, |
| 436 | "POS " + w.mShownFrame.left |
| 437 | + ", " + w.mShownFrame.top, null); |
| 438 | w.mSurfaceX = w.mShownFrame.left; |
| 439 | w.mSurfaceY = w.mShownFrame.top; |
| 440 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 441 | } catch (RuntimeException e) { |
| 442 | Slog.w(TAG, "Error positioning surface of " + w |
| 443 | + " pos=(" + w.mShownFrame.left |
| 444 | + "," + w.mShownFrame.top + ")", e); |
| 445 | if (!recoveringMemory) { |
| 446 | mService.reclaimSomeSurfaceMemoryLocked(w, "position", true); |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | if (surfaceResized) { |
| 452 | try { |
| 453 | if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w, |
| 454 | "SIZE " + width + "x" + height, null); |
| 455 | w.mSurfaceResized = true; |
| 456 | w.mSurface.setSize(width, height); |
| 457 | } catch (RuntimeException e) { |
| 458 | // If something goes wrong with the surface (such |
| 459 | // as running out of memory), don't take down the |
| 460 | // entire system. |
| 461 | Slog.e(TAG, "Error resizing surface of " + w |
| 462 | + " size=(" + width + "x" + height + ")", e); |
| 463 | if (!recoveringMemory) { |
| 464 | mService.reclaimSomeSurfaceMemoryLocked(w, "size", true); |
| 465 | } |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
| 470 | if (!w.mLastHidden) { |
| 471 | //dump(); |
| 472 | w.mLastHidden = true; |
| 473 | if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w, |
| 474 | "HIDE (performLayout)", null); |
| 475 | if (w.mSurface != null) { |
| 476 | w.mSurfaceShown = false; |
| 477 | try { |
| 478 | w.mSurface.hide(); |
| 479 | } catch (RuntimeException e) { |
| 480 | Slog.w(TAG, "Exception hiding surface in " + w); |
| 481 | } |
| 482 | } |
| 483 | } |
| 484 | // If we are waiting for this window to handle an |
| 485 | // orientation change, well, it is hidden, so |
| 486 | // doesn't really matter. Note that this does |
| 487 | // introduce a potential glitch if the window |
| 488 | // becomes unhidden before it has drawn for the |
| 489 | // new orientation. |
| 490 | if (w.mOrientationChanging) { |
| 491 | w.mOrientationChanging = false; |
| 492 | if (WindowManagerService.DEBUG_ORIENTATION) Slog.v(TAG, |
| 493 | "Orientation change skips hidden " + w); |
| 494 | } |
| 495 | } else if (w.mLastLayer != w.mAnimLayer |
| 496 | || w.mLastAlpha != w.mShownAlpha |
| 497 | || w.mLastDsDx != w.mDsDx |
| 498 | || w.mLastDtDx != w.mDtDx |
| 499 | || w.mLastDsDy != w.mDsDy |
| 500 | || w.mLastDtDy != w.mDtDy |
| 501 | || w.mLastHScale != w.mHScale |
| 502 | || w.mLastVScale != w.mVScale |
| 503 | || w.mLastHidden) { |
| 504 | displayed = true; |
| 505 | w.mLastAlpha = w.mShownAlpha; |
| 506 | w.mLastLayer = w.mAnimLayer; |
| 507 | w.mLastDsDx = w.mDsDx; |
| 508 | w.mLastDtDx = w.mDtDx; |
| 509 | w.mLastDsDy = w.mDsDy; |
| 510 | w.mLastDtDy = w.mDtDy; |
| 511 | w.mLastHScale = w.mHScale; |
| 512 | w.mLastVScale = w.mVScale; |
| 513 | if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w, |
| 514 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
| 515 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 516 | + "," + (w.mDtDx*w.mVScale) |
| 517 | + "][" + (w.mDsDy*w.mHScale) |
| 518 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
| 519 | if (w.mSurface != null) { |
| 520 | try { |
| 521 | w.mSurfaceAlpha = w.mShownAlpha; |
| 522 | w.mSurface.setAlpha(w.mShownAlpha); |
| 523 | w.mSurfaceLayer = w.mAnimLayer; |
| 524 | w.mSurface.setLayer(w.mAnimLayer); |
| 525 | w.mSurface.setMatrix( |
| 526 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 527 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 528 | } catch (RuntimeException e) { |
| 529 | Slog.w(TAG, "Error updating surface in " + w, e); |
| 530 | if (!recoveringMemory) { |
| 531 | mService.reclaimSomeSurfaceMemoryLocked(w, "update", true); |
| 532 | } |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | if (w.mLastHidden && w.isDrawnLw() |
| 537 | && !w.mReadyToShow) { |
| 538 | if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w, |
| 539 | "SHOW (performLayout)", null); |
| 540 | if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
| 541 | + " during relayout"); |
| 542 | if (mService.showSurfaceRobustlyLocked(w)) { |
| 543 | w.mHasDrawn = true; |
| 544 | w.mLastHidden = false; |
| 545 | } else { |
| 546 | w.mOrientationChanging = false; |
| 547 | } |
| 548 | } |
| 549 | if (w.mSurface != null) { |
| 550 | w.mToken.hasVisible = true; |
| 551 | } |
| 552 | } else { |
| 553 | displayed = true; |
| 554 | } |
| 555 | |
| 556 | if (displayed) { |
| 557 | if (w.mOrientationChanging) { |
| 558 | if (!w.isDrawnLw()) { |
| 559 | mService.mInnerFields.mOrientationChangeComplete = false; |
| 560 | if (WindowManagerService.DEBUG_ORIENTATION) Slog.v(TAG, |
| 561 | "Orientation continue waiting for draw in " + w); |
| 562 | } else { |
| 563 | w.mOrientationChanging = false; |
| 564 | if (WindowManagerService.DEBUG_ORIENTATION) Slog.v(TAG, |
| 565 | "Orientation change complete in " + w); |
| 566 | } |
| 567 | } |
| 568 | w.mToken.hasVisible = true; |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | void animate() { |
Craig Mautner | bb1449b | 2012-03-23 16:11:14 -0700 | [diff] [blame] | 573 | mPendingLayoutChanges = 0; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 574 | mCurrentTime = SystemClock.uptimeMillis(); |
| 575 | |
| 576 | // Update animations of all applications, including those |
| 577 | // associated with exiting/removed apps |
| 578 | Surface.openTransaction(); |
| 579 | |
| 580 | try { |
| 581 | updateWindowsAppsAndRotationAnimationsLocked(); |
| 582 | performAnimationsLocked(); |
| 583 | |
| 584 | // THIRD LOOP: Update the surfaces of all windows. |
| 585 | |
| 586 | if (mScreenRotationAnimation != null) { |
| 587 | mScreenRotationAnimation.updateSurfaces(); |
| 588 | } |
| 589 | |
| 590 | final int N = mService.mWindows.size(); |
| 591 | for (int i=N-1; i>=0; i--) { |
| 592 | WindowState w = mService.mWindows.get(i); |
| 593 | prepareSurfaceLocked(w, true); |
| 594 | } |
| 595 | |
| 596 | if (mService.mDimAnimator != null && mService.mDimAnimator.mDimShown) { |
| 597 | mAnimating |= mService.mDimAnimator.updateSurface(mService.mInnerFields.mDimming, |
| 598 | mCurrentTime, !mService.okToDisplay()); |
| 599 | } |
| 600 | |
| 601 | if (mService.mBlackFrame != null) { |
| 602 | if (mScreenRotationAnimation != null) { |
| 603 | mService.mBlackFrame.setMatrix( |
| 604 | mScreenRotationAnimation.getEnterTransformation().getMatrix()); |
| 605 | } else { |
| 606 | mService.mBlackFrame.clearMatrix(); |
| 607 | } |
| 608 | } |
| 609 | } catch (RuntimeException e) { |
| 610 | Log.wtf(TAG, "Unhandled exception in Window Manager", e); |
| 611 | } finally { |
| 612 | Surface.closeTransaction(); |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | WindowState mCurrentFocus; |
| 617 | void setCurrentFocus(WindowState currentFocus) { |
| 618 | mCurrentFocus = currentFocus; |
| 619 | } |
| 620 | |
| 621 | void setDisplayDimensions(final int curWidth, final int curHeight, |
| 622 | final int appWidth, final int appHeight) { |
| 623 | mDw = curWidth; |
| 624 | mDh = curHeight; |
| 625 | mInnerDw = appWidth; |
| 626 | mInnerDh = appHeight; |
| 627 | } |
| 628 | |
| 629 | } |