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