blob: 81e0a176e5f761dcea8da0b9740271ffe21adf11 [file] [log] [blame]
Craig Mautner764983d2012-03-22 11:37:36 -07001// Copyright 2012 Google Inc. All Rights Reserved.
2
3package com.android.server.wm;
4
5import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
6
7import android.content.Context;
8import android.os.SystemClock;
9import android.util.Log;
10import android.util.Slog;
11import android.view.Surface;
12import android.view.WindowManager;
13import android.view.WindowManager.LayoutParams;
14import android.view.WindowManagerPolicy;
15import android.view.animation.Animation;
16import android.view.animation.AnimationUtils;
17
18import 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 */
25public class WindowAnimator {
Craig Mautnerbb1449b2012-03-23 16:11:14 -070026 private static final String TAG = "WindowAnimator";
Craig Mautner764983d2012-03-22 11:37:36 -070027
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 Mautnercf8cbbe2012-03-25 21:54:36 -070070 final boolean wasAnimating = appToken.animation != null
71 && appToken.animation != WindowManagerService.sDummyAnimation;
Craig Mautner764983d2012-03-22 11:37:36 -070072 if (appToken.stepAnimationLocked(mCurrentTime, mInnerDw, mInnerDh)) {
73 mAnimating = true;
Craig Mautnerbb1449b2012-03-23 16:11:14 -070074 } else if (wasAnimating) {
75 // stopped animating, do one more pass through the layout
76 mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Craig Mautnercf8cbbe2012-03-25 21:54:36 -070077 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
78 mService.debugLayoutRepeats("appToken " + appToken + " done");
79 }
Craig Mautnerbb1449b2012-03-23 16:11:14 -070080 }
81 }
Craig Mautnera2c77052012-03-26 12:14:43 -070082
Craig Mautnerbb1449b2012-03-23 16:11:14 -070083 final int NEAT = mService.mExitingAppTokens.size();
84 for (i=0; i<NEAT; i++) {
85 final AppWindowToken appToken = mService.mExitingAppTokens.get(i);
Craig Mautnercf8cbbe2012-03-25 21:54:36 -070086 final boolean wasAnimating = appToken.animation != null
87 && appToken.animation != WindowManagerService.sDummyAnimation;
Craig Mautnerbb1449b2012-03-23 16:11:14 -070088 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 Mautnercf8cbbe2012-03-25 21:54:36 -070093 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
94 mService.debugLayoutRepeats("exiting appToken " + appToken + " done");
95 }
Craig Mautner764983d2012-03-22 11:37:36 -070096 }
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 Mautnera2c77052012-03-26 12:14:43 -0700118 WindowStateAnimator winAnimator = w.mWinAnimator;
Craig Mautner764983d2012-03-22 11:37:36 -0700119
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 Mautnercf8cbbe2012-03-25 21:54:36 -0700131 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
132 mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 1");
133 }
Craig Mautner764983d2012-03-22 11:37:36 -0700134 }
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 Mautnera2c77052012-03-26 12:14:43 -0700147 winAnimator.setAnimation(a);
Craig Mautner764983d2012-03-22 11:37:36 -0700148 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 Mautnera2c77052012-03-26 12:14:43 -0700155 final boolean wasAnimating = winAnimator.mWasAnimating;
156 final boolean nowAnimating = winAnimator.stepAnimationLocked(mCurrentTime);
Craig Mautner764983d2012-03-22 11:37:36 -0700157
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 Mautnera2c77052012-03-26 12:14:43 -0700167 if (winAnimator.mAnimation != null) {
Craig Mautner764983d2012-03-22 11:37:36 -0700168 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0
Craig Mautnera2c77052012-03-26 12:14:43 -0700169 && winAnimator.mAnimation.getDetachWallpaper()) {
Craig Mautner764983d2012-03-22 11:37:36 -0700170 mService.mInnerFields.mDetachedWallpaper = w;
171 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700172 if (winAnimator.mAnimation.getBackgroundColor() != 0) {
Craig Mautner764983d2012-03-22 11:37:36 -0700173 if (mWindowAnimationBackground == null
174 || (w.mAnimLayer < mWindowAnimationBackground.mAnimLayer)) {
175 mWindowAnimationBackground = w;
176 mWindowAnimationBackgroundColor =
Craig Mautnera2c77052012-03-26 12:14:43 -0700177 winAnimator.mAnimation.getBackgroundColor();
Craig Mautner764983d2012-03-22 11:37:36 -0700178 }
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 Mautnera2c77052012-03-26 12:14:43 -0700204 if (wasAnimating && !winAnimator.mAnimating && mService.mWallpaperTarget == w) {
Craig Mautner764983d2012-03-22 11:37:36 -0700205 mService.mInnerFields.mWallpaperMayChange = true;
206 mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Craig Mautnercf8cbbe2012-03-25 21:54:36 -0700207 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
208 mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 2");
209 }
Craig Mautner764983d2012-03-22 11:37:36 -0700210 }
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 Mautnercf8cbbe2012-03-25 21:54:36 -0700219 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
220 mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 3");
221 }
Craig Mautner764983d2012-03-22 11:37:36 -0700222 mService.mFocusMayChange = true;
Craig Mautnera2c77052012-03-26 12:14:43 -0700223 } else if (w.isReadyForDisplay() && winAnimator.mAnimation == null) {
Craig Mautner764983d2012-03-22 11:37:36 -0700224 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 Mautnera2c77052012-03-26 12:14:43 -0700245 winAnimator.setAnimation(a);
Craig Mautner764983d2012-03-22 11:37:36 -0700246 }
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 Mautnercf8cbbe2012-03-25 21:54:36 -0700260 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
261 mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 4");
262 }
Craig Mautner764983d2012-03-22 11:37:36 -0700263 }
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 Mautnera2c77052012-03-26 12:14:43 -0700281 + ", isAnimating=" + winAnimator.isAnimating());
Craig Mautner764983d2012-03-22 11:37:36 -0700282 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 Mautnera2c77052012-03-26 12:14:43 -0700289 + " a=" + winAnimator.mAnimating);
Craig Mautner764983d2012-03-22 11:37:36 -0700290 }
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 Mautnercf8cbbe2012-03-25 21:54:36 -0700310 if (w.performShowLocked()) {
311 mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
312 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
313 mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 5");
314 }
315 }
Craig Mautner764983d2012-03-22 11:37:36 -0700316 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700317 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 Mautner764983d2012-03-22 11:37:36 -0700326 } // 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 Mautnercf8cbbe2012-03-25 21:54:36 -0700359 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
360 mService.debugLayoutRepeats("testTokenMayBeDrawnLocked");
361 }
Craig Mautner764983d2012-03-22 11:37:36 -0700362
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 Mautnerbb1449b2012-03-23 16:11:14 -0700573 mPendingLayoutChanges = 0;
Craig Mautner764983d2012-03-22 11:37:36 -0700574 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}