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