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