blob: e99340c998cb814e9f81e8fe0a06ca7b81551731 [file] [log] [blame]
Craig Mautnera2c77052012-03-26 12:14:43 -07001// Copyright 2012 Google Inc. All Rights Reserved.
2
3package com.android.server.wm;
4
Craig Mautnerc2f9be02012-03-27 17:32:29 -07005import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
6import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
7
8import android.content.Context;
9import android.graphics.Matrix;
10import android.graphics.PixelFormat;
11import android.graphics.Rect;
12import android.os.RemoteException;
Craig Mautnera2c77052012-03-26 12:14:43 -070013import android.util.Slog;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070014import android.view.Surface;
Craig Mautnera2c77052012-03-26 12:14:43 -070015import android.view.WindowManager;
16import android.view.WindowManagerPolicy;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070017import android.view.WindowManager.LayoutParams;
Craig Mautnera2c77052012-03-26 12:14:43 -070018import android.view.animation.Animation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070019import android.view.animation.AnimationUtils;
Craig Mautnera2c77052012-03-26 12:14:43 -070020import android.view.animation.Transformation;
21
22import com.android.server.wm.WindowManagerService.H;
23
24import java.io.PrintWriter;
25
26/**
Craig Mautnerc2f9be02012-03-27 17:32:29 -070027 * Keep track of animations and surface operations for a single WindowState.
28 **/
Craig Mautnera2c77052012-03-26 12:14:43 -070029class WindowStateAnimator {
Craig Mautnerc2f9be02012-03-27 17:32:29 -070030 static final boolean DEBUG_VISIBILITY = WindowManagerService.DEBUG_VISIBILITY;
31 static final boolean DEBUG_ANIM = WindowManagerService.DEBUG_ANIM;
32 static final boolean DEBUG_LAYERS = WindowManagerService.DEBUG_LAYERS;
33 static final boolean DEBUG_STARTING_WINDOW = WindowManagerService.DEBUG_STARTING_WINDOW;
34 static final boolean SHOW_TRANSACTIONS = WindowManagerService.SHOW_TRANSACTIONS;
35 static final boolean SHOW_LIGHT_TRANSACTIONS = WindowManagerService.SHOW_LIGHT_TRANSACTIONS;
36 static final boolean SHOW_SURFACE_ALLOC = WindowManagerService.SHOW_SURFACE_ALLOC;
37 static final boolean localLOGV = WindowManagerService.localLOGV;
38
39 static final String TAG = "WindowStateAnimator";
Craig Mautnera2c77052012-03-26 12:14:43 -070040
41 final WindowManagerService mService;
42 final WindowState mWin;
43 final WindowState mAttachedWindow;
Craig Mautnere7ae2502012-03-26 17:11:19 -070044 final WindowAnimator mAnimator;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070045 final Session mSession;
46 final WindowManagerPolicy mPolicy;
47 final Context mContext;
Craig Mautnera2c77052012-03-26 12:14:43 -070048
49 // Currently running animation.
50 boolean mAnimating;
51 boolean mLocalAnimating;
52 Animation mAnimation;
53 boolean mAnimationIsEntrance;
54 boolean mHasTransformation;
55 boolean mHasLocalTransformation;
56 final Transformation mTransformation = new Transformation();
57 boolean mWasAnimating; // Were we animating going into the most recent animation step?
Craig Mautnerc2f9be02012-03-27 17:32:29 -070058 int mAnimLayer;
59 int mLastLayer;
60
61 Surface mSurface;
62 Surface mPendingDestroySurface;
63 boolean mReportDestroySurface;
64 boolean mSurfacePendingDestroy;
65
66 /**
67 * Set when we have changed the size of the surface, to know that
68 * we must tell them application to resize (and thus redraw itself).
69 */
70 boolean mSurfaceResized;
71
72 /**
73 * Set if the client has asked that the destroy of its surface be delayed
74 * until it explicitly says it is okay.
75 */
76 boolean mSurfaceDestroyDeferred;
77
78 float mShownAlpha = 1;
79 float mAlpha = 1;
80 float mLastAlpha = 1;
81
82 // Used to save animation distances between the time they are calculated and when they are
83 // used.
84 int mAnimDw;
85 int mAnimDh;
86 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
87 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
88
89 boolean mHaveMatrix;
90
91 // For debugging, this is the last information given to the surface flinger.
92 boolean mSurfaceShown;
93 float mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
94 int mSurfaceLayer;
95 float mSurfaceAlpha;
96
97 // Set to true if, when the window gets displayed, it should perform
98 // an enter animation.
99 boolean mEnterAnimationPending;
Craig Mautnera2c77052012-03-26 12:14:43 -0700100
Craig Mautnera608b882012-03-30 13:03:49 -0700101 // This is set after the Surface has been created but before the
102 // window has been drawn. During this time the surface is hidden.
103 boolean mDrawPending;
104
105 // This is set after the window has finished drawing for the first
106 // time but before its surface is shown. The surface will be
107 // displayed when the next layout is run.
108 boolean mCommitDrawPending;
109
Craig Mautnera2c77052012-03-26 12:14:43 -0700110 public WindowStateAnimator(final WindowManagerService service, final WindowState win,
111 final WindowState attachedWindow) {
112 mService = service;
113 mWin = win;
114 mAttachedWindow = attachedWindow;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700115 mAnimator = mService.mAnimator;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700116 mSession = win.mSession;
117 mPolicy = mService.mPolicy;
118 mContext = mService.mContext;
Craig Mautnera2c77052012-03-26 12:14:43 -0700119 }
120
121 public void setAnimation(Animation anim) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700122 if (localLOGV) Slog.v(
123 TAG, "Setting animation in " + this + ": " + anim);
Craig Mautnera2c77052012-03-26 12:14:43 -0700124 mAnimating = false;
125 mLocalAnimating = false;
126 mAnimation = anim;
127 mAnimation.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION);
128 mAnimation.scaleCurrentDuration(mService.mWindowAnimationScale);
129 // Start out animation gone if window is gone, or visible if window is visible.
130 mTransformation.clear();
131 mTransformation.setAlpha(mWin.mLastHidden ? 0 : 1);
132 mHasLocalTransformation = true;
133 }
134
135 public void clearAnimation() {
136 if (mAnimation != null) {
137 mAnimating = true;
138 mLocalAnimating = false;
139 mAnimation.cancel();
140 mAnimation = null;
141 }
142 }
143
144 /** Is the window or its container currently animating? */
145 boolean isAnimating() {
146 final WindowState attached = mAttachedWindow;
147 final AppWindowToken atoken = mWin.mAppToken;
148 return mAnimation != null
149 || (attached != null && attached.mWinAnimator.mAnimation != null)
150 || (atoken != null &&
151 (atoken.animation != null
152 || atoken.inPendingTransaction));
153 }
154
155 /** Is this window currently animating? */
156 boolean isWindowAnimating() {
157 return mAnimation != null;
158 }
159
Craig Mautnera2c77052012-03-26 12:14:43 -0700160 void cancelExitAnimationForNextAnimationLocked() {
161 if (!mWin.mExiting) return;
162 if (mAnimation != null) {
163 mAnimation.cancel();
164 mAnimation = null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700165 destroySurfaceLocked();
Craig Mautnera2c77052012-03-26 12:14:43 -0700166 }
167 mWin.mExiting = false;
168 }
169
170 private boolean stepAnimation(long currentTime) {
171 if ((mAnimation == null) || !mLocalAnimating) {
172 return false;
173 }
174 mTransformation.clear();
175 final boolean more = mAnimation.getTransformation(currentTime, mTransformation);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700176 if (DEBUG_ANIM) Slog.v(
177 TAG, "Stepped animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700178 ": more=" + more + ", xform=" + mTransformation);
179 return more;
180 }
181
182 // This must be called while inside a transaction. Returns true if
183 // there is more animation to run.
184 boolean stepAnimationLocked(long currentTime) {
185 // Save the animation state as it was before this step so WindowManagerService can tell if
186 // we just started or just stopped animating by comparing mWasAnimating with isAnimating().
187 mWasAnimating = mAnimating;
188 if (mService.okToDisplay()) {
189 // We will run animations as long as the display isn't frozen.
190
191 if (mWin.isDrawnLw() && mAnimation != null) {
192 mHasTransformation = true;
193 mHasLocalTransformation = true;
194 if (!mLocalAnimating) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700195 if (DEBUG_ANIM) Slog.v(
196 TAG, "Starting animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700197 " @ " + currentTime + ": ww=" + mWin.mFrame.width() +
198 " wh=" + mWin.mFrame.height() +
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700199 " dw=" + mAnimDw + " dh=" + mAnimDh +
Craig Mautnera2c77052012-03-26 12:14:43 -0700200 " scale=" + mService.mWindowAnimationScale);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700201 mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(),
202 mAnimDw, mAnimDh);
Craig Mautnera2c77052012-03-26 12:14:43 -0700203 mAnimation.setStartTime(currentTime);
204 mLocalAnimating = true;
205 mAnimating = true;
206 }
207 if ((mAnimation != null) && mLocalAnimating) {
208 if (stepAnimation(currentTime)) {
209 return true;
210 }
211 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700212 if (DEBUG_ANIM) Slog.v(
213 TAG, "Finished animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700214 " @ " + currentTime);
215 //WindowManagerService.this.dump();
216 }
217 mHasLocalTransformation = false;
218 if ((!mLocalAnimating || mAnimationIsEntrance) && mWin.mAppToken != null
219 && mWin.mAppToken.animation != null) {
220 // When our app token is animating, we kind-of pretend like
221 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
222 // part of this check means that we will only do this if
223 // our window is not currently exiting, or it is not
224 // locally animating itself. The idea being that one that
225 // is exiting and doing a local animation should be removed
226 // once that animation is done.
227 mAnimating = true;
228 mHasTransformation = true;
229 mTransformation.clear();
230 return false;
231 } else if (mHasTransformation) {
232 // Little trick to get through the path below to act like
233 // we have finished an animation.
234 mAnimating = true;
235 } else if (isAnimating()) {
236 mAnimating = true;
237 }
238 } else if (mAnimation != null) {
239 // If the display is frozen, and there is a pending animation,
240 // clear it and make sure we run the cleanup code.
241 mAnimating = true;
242 mLocalAnimating = true;
243 mAnimation.cancel();
244 mAnimation = null;
245 }
246
247 if (!mAnimating && !mLocalAnimating) {
248 return false;
249 }
250
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700251 // Done animating, clean up.
252 if (DEBUG_ANIM) Slog.v(
253 TAG, "Animation done in " + this + ": exiting=" + mWin.mExiting
Craig Mautnera2c77052012-03-26 12:14:43 -0700254 + ", reportedVisible="
255 + (mWin.mAppToken != null ? mWin.mAppToken.reportedVisible : false));
256
257 mAnimating = false;
258 mLocalAnimating = false;
259 if (mAnimation != null) {
260 mAnimation.cancel();
261 mAnimation = null;
262 }
Craig Mautnere7ae2502012-03-26 17:11:19 -0700263 if (mAnimator.mWindowDetachedWallpaper == mWin) {
264 mAnimator.mWindowDetachedWallpaper = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700265 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700266 mAnimLayer = mWin.mLayer;
Craig Mautnera2c77052012-03-26 12:14:43 -0700267 if (mWin.mIsImWindow) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700268 mAnimLayer += mService.mInputMethodAnimLayerAdjustment;
Craig Mautnera2c77052012-03-26 12:14:43 -0700269 } else if (mWin.mIsWallpaper) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700270 mAnimLayer += mService.mWallpaperAnimLayerAdjustment;
Craig Mautnera2c77052012-03-26 12:14:43 -0700271 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700272 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
273 + " anim layer: " + mAnimLayer);
Craig Mautnera2c77052012-03-26 12:14:43 -0700274 mHasTransformation = false;
275 mHasLocalTransformation = false;
276 if (mWin.mPolicyVisibility != mWin.mPolicyVisibilityAfterAnim) {
277 if (WindowState.DEBUG_VISIBILITY) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700278 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
Craig Mautnera2c77052012-03-26 12:14:43 -0700279 + mWin.mPolicyVisibilityAfterAnim);
280 }
281 mWin.mPolicyVisibility = mWin.mPolicyVisibilityAfterAnim;
282 mService.mLayoutNeeded = true;
283 if (!mWin.mPolicyVisibility) {
284 if (mService.mCurrentFocus == mWin) {
285 mService.mFocusMayChange = true;
286 }
287 // Window is no longer visible -- make sure if we were waiting
288 // for it to be displayed before enabling the display, that
289 // we allow the display to be enabled now.
290 mService.enableScreenIfNeededLocked();
291 }
292 }
293 mTransformation.clear();
294 if (mWin.mHasDrawn
295 && mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
296 && mWin.mAppToken != null
297 && mWin.mAppToken.firstWindowDrawn
298 && mWin.mAppToken.startingData != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700299 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
Craig Mautnera2c77052012-03-26 12:14:43 -0700300 + mWin.mToken + ": first real window done animating");
301 mService.mFinishedStarting.add(mWin.mAppToken);
302 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
303 }
304
305 finishExit();
306 mService.mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
307 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) mService.debugLayoutRepeats("WindowState");
308
309 if (mWin.mAppToken != null) {
310 mWin.mAppToken.updateReportedVisibilityLocked();
311 }
312
313 return false;
314 }
315
316 void finishExit() {
317 if (WindowManagerService.DEBUG_ANIM) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700318 TAG, "finishExit in " + this
Craig Mautnera2c77052012-03-26 12:14:43 -0700319 + ": exiting=" + mWin.mExiting
320 + " remove=" + mWin.mRemoveOnExit
321 + " windowAnimating=" + isWindowAnimating());
322
323 final int N = mWin.mChildWindows.size();
324 for (int i=0; i<N; i++) {
325 mWin.mChildWindows.get(i).mWinAnimator.finishExit();
326 }
327
328 if (!mWin.mExiting) {
329 return;
330 }
331
332 if (isWindowAnimating()) {
333 return;
334 }
335
336 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700337 TAG, "Exit animation finished in " + this
Craig Mautnera2c77052012-03-26 12:14:43 -0700338 + ": remove=" + mWin.mRemoveOnExit);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700339 if (mSurface != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700340 mService.mDestroySurface.add(mWin);
341 mWin.mDestroying = true;
342 if (WindowState.SHOW_TRANSACTIONS) WindowManagerService.logSurface(
343 mWin, "HIDE (finishExit)", null);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700344 mSurfaceShown = false;
Craig Mautnera2c77052012-03-26 12:14:43 -0700345 try {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700346 mSurface.hide();
Craig Mautnera2c77052012-03-26 12:14:43 -0700347 } catch (RuntimeException e) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700348 Slog.w(TAG, "Error hiding surface in " + this, e);
Craig Mautnera2c77052012-03-26 12:14:43 -0700349 }
350 mWin.mLastHidden = true;
351 }
352 mWin.mExiting = false;
353 if (mWin.mRemoveOnExit) {
354 mService.mPendingRemove.add(mWin);
355 mWin.mRemoveOnExit = false;
356 }
357 }
358
Craig Mautnera608b882012-03-30 13:03:49 -0700359 boolean finishDrawingLocked() {
360 if (mDrawPending) {
361 if (SHOW_TRANSACTIONS || WindowManagerService.DEBUG_ORIENTATION) Slog.v(
362 TAG, "finishDrawingLocked: " + this + " in " + mSurface);
363 mCommitDrawPending = true;
364 mDrawPending = false;
365 return true;
366 }
367 return false;
368 }
369
370 // This must be called while inside a transaction.
371 boolean commitFinishDrawingLocked(long currentTime) {
372 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
373 if (!mCommitDrawPending) {
374 return false;
375 }
376 mCommitDrawPending = false;
377 mWin.mReadyToShow = true;
378 final boolean starting = mWin.mAttrs.type == TYPE_APPLICATION_STARTING;
379 final AppWindowToken atoken = mWin.mAppToken;
380 if (atoken == null || atoken.allDrawn || starting) {
381 performShowLocked();
382 }
383 return true;
384 }
385
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700386 Surface createSurfaceLocked() {
387 if (mSurface == null) {
388 mReportDestroySurface = false;
389 mSurfacePendingDestroy = false;
390 if (WindowManagerService.DEBUG_ORIENTATION) Slog.i(TAG,
391 "createSurface " + this + ": DRAW NOW PENDING");
Craig Mautnera608b882012-03-30 13:03:49 -0700392 mDrawPending = true;
393 mCommitDrawPending = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700394 mWin.mReadyToShow = false;
395 if (mWin.mAppToken != null) {
396 mWin.mAppToken.allDrawn = false;
397 }
398
399 mService.makeWindowFreezingScreenIfNeededLocked(mWin);
400
401 int flags = 0;
402 final WindowManager.LayoutParams attrs = mWin.mAttrs;
403
404 if ((attrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
405 flags |= Surface.SECURE;
406 }
407 if (WindowState.DEBUG_VISIBILITY) Slog.v(
408 TAG, "Creating surface in session "
409 + mSession.mSurfaceSession + " window " + this
410 + " w=" + mWin.mCompatFrame.width()
411 + " h=" + mWin.mCompatFrame.height() + " format="
412 + attrs.format + " flags=" + flags);
413
414 int w = mWin.mCompatFrame.width();
415 int h = mWin.mCompatFrame.height();
416 if ((attrs.flags & LayoutParams.FLAG_SCALED) != 0) {
417 // for a scaled surface, we always want the requested
418 // size.
419 w = mWin.mRequestedWidth;
420 h = mWin.mRequestedHeight;
421 }
422
423 // Something is wrong and SurfaceFlinger will not like this,
424 // try to revert to sane values
425 if (w <= 0) w = 1;
426 if (h <= 0) h = 1;
427
428 mSurfaceShown = false;
429 mSurfaceLayer = 0;
430 mSurfaceAlpha = 1;
431 mSurfaceX = 0;
432 mSurfaceY = 0;
433 mSurfaceW = w;
434 mSurfaceH = h;
435 try {
436 final boolean isHwAccelerated = (attrs.flags &
437 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
438 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
439 if (!PixelFormat.formatHasAlpha(attrs.format)) {
440 flags |= Surface.OPAQUE;
441 }
442 mSurface = new Surface(
443 mSession.mSurfaceSession, mSession.mPid,
444 attrs.getTitle().toString(),
445 0, w, h, format, flags);
446 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG,
447 " CREATE SURFACE "
448 + mSurface + " IN SESSION "
449 + mSession.mSurfaceSession
450 + ": pid=" + mSession.mPid + " format="
451 + attrs.format + " flags=0x"
452 + Integer.toHexString(flags)
453 + " / " + this);
454 } catch (Surface.OutOfResourcesException e) {
455 Slog.w(TAG, "OutOfResourcesException creating surface");
456 mService.reclaimSomeSurfaceMemoryLocked(this, "create", true);
457 return null;
458 } catch (Exception e) {
459 Slog.e(TAG, "Exception creating surface", e);
460 return null;
461 }
462
463 if (WindowManagerService.localLOGV) Slog.v(
464 TAG, "Got surface: " + mSurface
465 + ", set left=" + mWin.mFrame.left + " top=" + mWin.mFrame.top
466 + ", animLayer=" + mAnimLayer);
467 if (SHOW_LIGHT_TRANSACTIONS) {
468 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
469 WindowManagerService.logSurface(mWin, "CREATE pos=("
470 + mWin.mFrame.left + "," + mWin.mFrame.top + ") ("
471 + mWin.mCompatFrame.width() + "x" + mWin.mCompatFrame.height()
472 + "), layer=" + mAnimLayer + " HIDE", null);
473 }
474 Surface.openTransaction();
475 try {
476 try {
477 mSurfaceX = mWin.mFrame.left + mWin.mXOffset;
478 mSurfaceY = mWin.mFrame.top + mWin.mYOffset;
479 mSurface.setPosition(mSurfaceX, mSurfaceY);
480 mSurfaceLayer = mAnimLayer;
481 mSurface.setLayer(mAnimLayer);
482 mSurfaceShown = false;
483 mSurface.hide();
484 if ((mWin.mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
485 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, "DITHER", null);
486 mSurface.setFlags(Surface.SURFACE_DITHER, Surface.SURFACE_DITHER);
487 }
488 } catch (RuntimeException e) {
489 Slog.w(TAG, "Error creating surface in " + w, e);
490 mService.reclaimSomeSurfaceMemoryLocked(this, "create-init", true);
491 }
492 mWin.mLastHidden = true;
493 } finally {
494 Surface.closeTransaction();
495 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
496 "<<< CLOSE TRANSACTION createSurfaceLocked");
497 }
498 if (WindowManagerService.localLOGV) Slog.v(
499 TAG, "Created surface " + this);
500 }
501 return mSurface;
502 }
503
504 void destroySurfaceLocked() {
505 if (mWin.mAppToken != null && mWin == mWin.mAppToken.startingWindow) {
506 mWin.mAppToken.startingDisplayed = false;
507 }
508
509 if (mSurface != null) {
Craig Mautnera608b882012-03-30 13:03:49 -0700510 mDrawPending = false;
511 mCommitDrawPending = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700512 mWin.mReadyToShow = false;
513
514 int i = mWin.mChildWindows.size();
515 while (i > 0) {
516 i--;
517 WindowState c = mWin.mChildWindows.get(i);
518 c.mAttachedHidden = true;
519 }
520
521 if (mReportDestroySurface) {
522 mReportDestroySurface = false;
523 mSurfacePendingDestroy = true;
524 try {
525 mWin.mClient.dispatchGetNewSurface();
526 // We'll really destroy on the next time around.
527 return;
528 } catch (RemoteException e) {
529 }
530 }
531
532 try {
533 if (DEBUG_VISIBILITY) {
534 RuntimeException e = null;
535 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
536 e = new RuntimeException();
537 e.fillInStackTrace();
538 }
539 Slog.w(TAG, "Window " + this + " destroying surface "
540 + mSurface + ", session " + mSession, e);
541 }
542 if (mSurfaceDestroyDeferred) {
543 if (mSurface != null && mPendingDestroySurface != mSurface) {
544 if (mPendingDestroySurface != null) {
545 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
546 RuntimeException e = null;
547 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
548 e = new RuntimeException();
549 e.fillInStackTrace();
550 }
551 WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
552 }
553 mPendingDestroySurface.destroy();
554 }
555 mPendingDestroySurface = mSurface;
556 }
557 } else {
558 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
559 RuntimeException e = null;
560 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
561 e = new RuntimeException();
562 e.fillInStackTrace();
563 }
564 WindowManagerService.logSurface(mWin, "DESTROY", e);
565 }
566 mSurface.destroy();
567 }
568 } catch (RuntimeException e) {
569 Slog.w(TAG, "Exception thrown when destroying Window " + this
570 + " surface " + mSurface + " session " + mSession
571 + ": " + e.toString());
572 }
573
574 mSurfaceShown = false;
575 mSurface = null;
576 }
577 }
578
579 void destroyDeferredSurfaceLocked() {
580 try {
581 if (mPendingDestroySurface != null) {
582 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
583 RuntimeException e = null;
584 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
585 e = new RuntimeException();
586 e.fillInStackTrace();
587 }
588 WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
589 }
590 mPendingDestroySurface.destroy();
591 }
592 } catch (RuntimeException e) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700593 Slog.w(TAG, "Exception thrown when destroying Window "
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700594 + this + " surface " + mPendingDestroySurface
595 + " session " + mSession + ": " + e.toString());
596 }
597 mSurfaceDestroyDeferred = false;
598 mPendingDestroySurface = null;
599 }
600
601 void computeShownFrameLocked() {
602 final boolean selfTransformation = mHasLocalTransformation;
603 Transformation attachedTransformation =
604 (mAttachedWindow != null && mAttachedWindow.mWinAnimator.mHasLocalTransformation)
605 ? mAttachedWindow.mWinAnimator.mTransformation : null;
606 Transformation appTransformation =
607 (mWin.mAppToken != null && mWin.mAppToken.hasTransformation)
608 ? mWin.mAppToken.transformation : null;
609
610 // Wallpapers are animated based on the "real" window they
611 // are currently targeting.
612 if (mWin.mAttrs.type == TYPE_WALLPAPER && mService.mLowerWallpaperTarget == null
613 && mService.mWallpaperTarget != null) {
614 if (mService.mWallpaperTarget.mWinAnimator.mHasLocalTransformation &&
615 mService.mWallpaperTarget.mWinAnimator.mAnimation != null &&
616 !mService.mWallpaperTarget.mWinAnimator.mAnimation.getDetachWallpaper()) {
617 attachedTransformation = mService.mWallpaperTarget.mWinAnimator.mTransformation;
618 if (WindowManagerService.DEBUG_WALLPAPER && attachedTransformation != null) {
619 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
620 }
621 }
622 if (mService.mWallpaperTarget.mAppToken != null &&
623 mService.mWallpaperTarget.mAppToken.hasTransformation &&
624 mService.mWallpaperTarget.mAppToken.animation != null &&
625 !mService.mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
626 appTransformation = mService.mWallpaperTarget.mAppToken.transformation;
627 if (WindowManagerService.DEBUG_WALLPAPER && appTransformation != null) {
628 Slog.v(TAG, "WP target app xform: " + appTransformation);
629 }
630 }
631 }
632
633 final boolean screenAnimation = mService.mAnimator.mScreenRotationAnimation != null
634 && mService.mAnimator.mScreenRotationAnimation.isAnimating();
635 if (selfTransformation || attachedTransformation != null
636 || appTransformation != null || screenAnimation) {
637 // cache often used attributes locally
638 final Rect frame = mWin.mFrame;
639 final float tmpFloats[] = mService.mTmpFloats;
640 final Matrix tmpMatrix = mWin.mTmpMatrix;
641
642 // Compute the desired transformation.
643 if (screenAnimation) {
644 // If we are doing a screen animation, the global rotation
645 // applied to windows can result in windows that are carefully
646 // aligned with each other to slightly separate, allowing you
647 // to see what is behind them. An unsightly mess. This...
648 // thing... magically makes it call good: scale each window
649 // slightly (two pixels larger in each dimension, from the
650 // window's center).
651 final float w = frame.width();
652 final float h = frame.height();
653 if (w>=1 && h>=1) {
654 tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2);
655 } else {
656 tmpMatrix.reset();
657 }
658 } else {
659 tmpMatrix.reset();
660 }
661 tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale);
662 if (selfTransformation) {
663 tmpMatrix.postConcat(mTransformation.getMatrix());
664 }
665 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
666 if (attachedTransformation != null) {
667 tmpMatrix.postConcat(attachedTransformation.getMatrix());
668 }
669 if (appTransformation != null) {
670 tmpMatrix.postConcat(appTransformation.getMatrix());
671 }
672 if (screenAnimation) {
673 tmpMatrix.postConcat(
674 mService.mAnimator.mScreenRotationAnimation.getEnterTransformation().getMatrix());
675 }
676
677 // "convert" it into SurfaceFlinger's format
678 // (a 2x2 matrix + an offset)
679 // Here we must not transform the position of the surface
680 // since it is already included in the transformation.
681 //Slog.i(TAG, "Transform: " + matrix);
682
683 mHaveMatrix = true;
684 tmpMatrix.getValues(tmpFloats);
685 mDsDx = tmpFloats[Matrix.MSCALE_X];
686 mDtDx = tmpFloats[Matrix.MSKEW_Y];
687 mDsDy = tmpFloats[Matrix.MSKEW_X];
688 mDtDy = tmpFloats[Matrix.MSCALE_Y];
689 float x = tmpFloats[Matrix.MTRANS_X];
690 float y = tmpFloats[Matrix.MTRANS_Y];
691 int w = frame.width();
692 int h = frame.height();
693 mWin.mShownFrame.set(x, y, x+w, y+h);
694
695 // Now set the alpha... but because our current hardware
696 // can't do alpha transformation on a non-opaque surface,
697 // turn it off if we are running an animation that is also
698 // transforming since it is more important to have that
699 // animation be smooth.
700 mShownAlpha = mAlpha;
701 if (!mService.mLimitedAlphaCompositing
702 || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format)
703 || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
704 && x == frame.left && y == frame.top))) {
705 //Slog.i(TAG, "Applying alpha transform");
706 if (selfTransformation) {
707 mShownAlpha *= mTransformation.getAlpha();
708 }
709 if (attachedTransformation != null) {
710 mShownAlpha *= attachedTransformation.getAlpha();
711 }
712 if (appTransformation != null) {
713 mShownAlpha *= appTransformation.getAlpha();
714 }
715 if (screenAnimation) {
716 mShownAlpha *=
717 mService.mAnimator.mScreenRotationAnimation.getEnterTransformation().getAlpha();
718 }
719 } else {
720 //Slog.i(TAG, "Not applying alpha transform");
721 }
722
723 if (WindowManagerService.localLOGV) Slog.v(
724 TAG, "computeShownFrameLocked: Animating " + this +
725 ": " + mWin.mShownFrame +
726 ", alpha=" + mTransformation.getAlpha() + ", mShownAlpha=" + mShownAlpha);
727 return;
728 }
729
730 if (WindowManagerService.localLOGV) Slog.v(
731 TAG, "computeShownFrameLocked: " + this +
732 " not attached, mAlpha=" + mAlpha);
733 mWin.mShownFrame.set(mWin.mFrame);
734 if (mWin.mXOffset != 0 || mWin.mYOffset != 0) {
735 mWin.mShownFrame.offset(mWin.mXOffset, mWin.mYOffset);
736 }
737 mShownAlpha = mAlpha;
738 mHaveMatrix = false;
739 mDsDx = mWin.mGlobalScale;
740 mDtDx = 0;
741 mDsDy = 0;
742 mDtDy = mWin.mGlobalScale;
743 }
Craig Mautnerd87946b2012-03-29 18:00:19 -0700744
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700745 public void prepareSurfaceLocked(final boolean recoveringMemory) {
746 final WindowState w = mWin;
747 if (mSurface == null) {
748 if (w.mOrientationChanging) {
749 if (WindowManagerService.DEBUG_ORIENTATION) {
750 Slog.v(TAG, "Orientation change skips hidden " + w);
751 }
752 w.mOrientationChanging = false;
753 }
754 return;
755 }
756
757 boolean displayed = false;
758
759 computeShownFrameLocked();
760
761 int width, height;
762 if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
763 // for a scaled surface, we just want to use
764 // the requested size.
765 width = w.mRequestedWidth;
766 height = w.mRequestedHeight;
767 } else {
768 width = w.mCompatFrame.width();
769 height = w.mCompatFrame.height();
770 }
771
772 if (width < 1) {
773 width = 1;
774 }
775 if (height < 1) {
776 height = 1;
777 }
778 final boolean surfaceResized = mSurfaceW != width || mSurfaceH != height;
779 if (surfaceResized) {
780 mSurfaceW = width;
781 mSurfaceH = height;
782 }
783
784 if (mSurfaceX != w.mShownFrame.left
785 || mSurfaceY != w.mShownFrame.top) {
786 try {
787 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
788 "POS " + w.mShownFrame.left
789 + ", " + w.mShownFrame.top, null);
790 mSurfaceX = w.mShownFrame.left;
791 mSurfaceY = w.mShownFrame.top;
792 mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
793 } catch (RuntimeException e) {
794 Slog.w(TAG, "Error positioning surface of " + w
795 + " pos=(" + w.mShownFrame.left
796 + "," + w.mShownFrame.top + ")", e);
797 if (!recoveringMemory) {
798 mService.reclaimSomeSurfaceMemoryLocked(this, "position", true);
799 }
800 }
801 }
802
803 if (surfaceResized) {
804 try {
805 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
806 "SIZE " + width + "x" + height, null);
807 mSurfaceResized = true;
808 mSurface.setSize(width, height);
809 } catch (RuntimeException e) {
810 // If something goes wrong with the surface (such
811 // as running out of memory), don't take down the
812 // entire system.
813 Slog.e(TAG, "Error resizing surface of " + w
814 + " size=(" + width + "x" + height + ")", e);
815 if (!recoveringMemory) {
816 mService.reclaimSomeSurfaceMemoryLocked(this, "size", true);
817 }
818 }
819 }
820
821 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
822 if (!w.mLastHidden) {
823 //dump();
824 w.mLastHidden = true;
825 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
826 "HIDE (performLayout)", null);
827 if (mSurface != null) {
828 mSurfaceShown = false;
829 try {
830 mSurface.hide();
831 } catch (RuntimeException e) {
832 Slog.w(TAG, "Exception hiding surface in " + w);
833 }
834 }
835 }
836 // If we are waiting for this window to handle an
837 // orientation change, well, it is hidden, so
838 // doesn't really matter. Note that this does
839 // introduce a potential glitch if the window
840 // becomes unhidden before it has drawn for the
841 // new orientation.
842 if (w.mOrientationChanging) {
843 w.mOrientationChanging = false;
844 if (WindowManagerService.DEBUG_ORIENTATION) Slog.v(TAG,
845 "Orientation change skips hidden " + w);
846 }
847 } else if (mLastLayer != mAnimLayer
848 || mLastAlpha != mShownAlpha
849 || mLastDsDx != mDsDx
850 || mLastDtDx != mDtDx
851 || mLastDsDy != mDsDy
852 || mLastDtDy != mDtDy
853 || w.mLastHScale != w.mHScale
854 || w.mLastVScale != w.mVScale
855 || w.mLastHidden) {
856 displayed = true;
857 mLastAlpha = mShownAlpha;
858 mLastLayer = mAnimLayer;
859 mLastDsDx = mDsDx;
860 mLastDtDx = mDtDx;
861 mLastDsDy = mDsDy;
862 mLastDtDy = mDtDy;
863 w.mLastHScale = w.mHScale;
864 w.mLastVScale = w.mVScale;
865 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
866 "alpha=" + mShownAlpha + " layer=" + mAnimLayer
867 + " matrix=[" + (mDsDx*w.mHScale)
868 + "," + (mDtDx*w.mVScale)
869 + "][" + (mDsDy*w.mHScale)
870 + "," + (mDtDy*w.mVScale) + "]", null);
871 if (mSurface != null) {
872 try {
873 mSurfaceAlpha = mShownAlpha;
874 mSurface.setAlpha(mShownAlpha);
875 mSurfaceLayer = w.mWinAnimator.mAnimLayer;
876 mSurface.setLayer(w.mWinAnimator.mAnimLayer);
877 mSurface.setMatrix(
878 mDsDx*w.mHScale, mDtDx*w.mVScale,
879 mDsDy*w.mHScale, mDtDy*w.mVScale);
880 } catch (RuntimeException e) {
881 Slog.w(TAG, "Error updating surface in " + w, e);
882 if (!recoveringMemory) {
883 mService.reclaimSomeSurfaceMemoryLocked(this, "update", true);
884 }
885 }
886 }
887
888 if (w.mLastHidden && w.isDrawnLw()
889 && !w.mReadyToShow) {
890 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
891 "SHOW (performLayout)", null);
892 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
893 + " during relayout");
894 if (showSurfaceRobustlyLocked()) {
895 w.mHasDrawn = true;
896 w.mLastHidden = false;
897 } else {
898 w.mOrientationChanging = false;
899 }
900 }
901 if (mSurface != null) {
902 w.mToken.hasVisible = true;
903 }
904 } else {
905 displayed = true;
906 }
907
908 if (displayed) {
909 if (w.mOrientationChanging) {
910 if (!w.isDrawnLw()) {
911 mService.mInnerFields.mOrientationChangeComplete = false;
912 if (WindowManagerService.DEBUG_ORIENTATION) Slog.v(TAG,
913 "Orientation continue waiting for draw in " + w);
914 } else {
915 w.mOrientationChanging = false;
916 if (WindowManagerService.DEBUG_ORIENTATION) Slog.v(TAG,
917 "Orientation change complete in " + w);
918 }
919 }
920 w.mToken.hasVisible = true;
921 }
922 }
923
924 // This must be called while inside a transaction.
925 boolean performShowLocked() {
926 if (DEBUG_VISIBILITY) {
927 RuntimeException e = null;
928 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
929 e = new RuntimeException();
930 e.fillInStackTrace();
931 }
Craig Mautnerd87946b2012-03-29 18:00:19 -0700932 Slog.v(TAG, "performShow on " + this
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700933 + ": readyToShow=" + mWin.mReadyToShow + " readyForDisplay="
934 + mWin.isReadyForDisplay()
935 + " starting=" + (mWin.mAttrs.type == TYPE_APPLICATION_STARTING), e);
936 }
937 if (mWin.mReadyToShow && mWin.isReadyForDisplay()) {
938 if (SHOW_TRANSACTIONS || WindowManagerService.DEBUG_ORIENTATION)
939 WindowManagerService.logSurface(mWin, "SHOW (performShowLocked)", null);
Craig Mautnerd87946b2012-03-29 18:00:19 -0700940 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700941 + " during animation: policyVis=" + mWin.mPolicyVisibility
942 + " attHidden=" + mWin.mAttachedHidden
943 + " tok.hiddenRequested="
944 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
945 + " tok.hidden="
946 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
947 + " animating=" + mAnimating
948 + " tok animating="
949 + (mWin.mAppToken != null ? mWin.mAppToken.animating : false));
950 if (!showSurfaceRobustlyLocked()) {
951 return false;
952 }
953
954 mService.enableScreenIfNeededLocked();
955
956 applyEnterAnimationLocked();
957
958 mLastAlpha = -1;
959 mWin.mHasDrawn = true;
960 mWin.mLastHidden = false;
961 mWin.mReadyToShow = false;
962
963 int i = mWin.mChildWindows.size();
964 while (i > 0) {
965 i--;
966 WindowState c = mWin.mChildWindows.get(i);
967 if (c.mAttachedHidden) {
968 c.mAttachedHidden = false;
969 if (c.mWinAnimator.mSurface != null) {
970 c.mWinAnimator.performShowLocked();
971 // It hadn't been shown, which means layout not
972 // performed on it, so now we want to make sure to
973 // do a layout. If called from within the transaction
974 // loop, this will cause it to restart with a new
975 // layout.
976 mService.mLayoutNeeded = true;
977 }
978 }
979 }
980
981 if (mWin.mAttrs.type != TYPE_APPLICATION_STARTING
982 && mWin.mAppToken != null) {
983 mWin.mAppToken.firstWindowDrawn = true;
984
985 if (mWin.mAppToken.startingData != null) {
986 if (WindowManagerService.DEBUG_STARTING_WINDOW ||
Craig Mautnerd87946b2012-03-29 18:00:19 -0700987 WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700988 "Finish starting " + mWin.mToken
989 + ": first real window is shown, no animation");
990 // If this initial window is animating, stop it -- we
991 // will do an animation to reveal it from behind the
992 // starting window, so there is no need for it to also
993 // be doing its own stuff.
994 if (mAnimation != null) {
995 mAnimation.cancel();
996 mAnimation = null;
997 // Make sure we clean up the animation.
998 mAnimating = true;
999 }
1000 mService.mFinishedStarting.add(mWin.mAppToken);
1001 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
1002 }
1003 mWin.mAppToken.updateReportedVisibilityLocked();
1004 }
1005
1006 return true;
1007 }
1008
1009 return false;
1010 }
1011
1012 /**
1013 * Have the surface flinger show a surface, robustly dealing with
1014 * error conditions. In particular, if there is not enough memory
1015 * to show the surface, then we will try to get rid of other surfaces
1016 * in order to succeed.
1017 *
1018 * @return Returns true if the surface was successfully shown.
1019 */
1020 boolean showSurfaceRobustlyLocked() {
1021 try {
1022 if (mSurface != null) {
1023 mSurfaceShown = true;
1024 mSurface.show();
1025 if (mWin.mTurnOnScreen) {
1026 if (DEBUG_VISIBILITY) Slog.v(TAG,
1027 "Show surface turning screen on: " + mWin);
1028 mWin.mTurnOnScreen = false;
1029 mService.mTurnOnScreen = true;
1030 }
1031 }
1032 return true;
1033 } catch (RuntimeException e) {
1034 Slog.w(TAG, "Failure showing surface " + mSurface + " in " + mWin, e);
1035 }
1036
1037 mService.reclaimSomeSurfaceMemoryLocked(this, "show", true);
1038
1039 return false;
1040 }
1041
1042 void applyEnterAnimationLocked() {
1043 final int transit;
1044 if (mEnterAnimationPending) {
1045 mEnterAnimationPending = false;
1046 transit = WindowManagerPolicy.TRANSIT_ENTER;
1047 } else {
1048 transit = WindowManagerPolicy.TRANSIT_SHOW;
1049 }
1050
1051 applyAnimationLocked(transit, true);
1052 }
1053
1054 /**
1055 * Choose the correct animation and set it to the passed WindowState.
1056 * @param transit If WindowManagerPolicy.TRANSIT_PREVIEW_DONE and the app window has been drawn
1057 * then the animation will be app_starting_exit. Any other value loads the animation from
1058 * the switch statement below.
1059 * @param isEntrance The animation type the last time this was called. Used to keep from
1060 * loading the same animation twice.
1061 * @return true if an animation has been loaded.
1062 */
1063 boolean applyAnimationLocked(int transit, boolean isEntrance) {
1064 if (mLocalAnimating && mAnimationIsEntrance == isEntrance) {
1065 // If we are trying to apply an animation, but already running
1066 // an animation of the same type, then just leave that one alone.
1067 return true;
1068 }
1069
1070 // Only apply an animation if the display isn't frozen. If it is
1071 // frozen, there is no reason to animate and it can cause strange
1072 // artifacts when we unfreeze the display if some different animation
1073 // is running.
1074 if (mService.okToDisplay()) {
1075 int anim = mPolicy.selectAnimationLw(mWin, transit);
1076 int attr = -1;
1077 Animation a = null;
1078 if (anim != 0) {
1079 a = AnimationUtils.loadAnimation(mContext, anim);
1080 } else {
1081 switch (transit) {
1082 case WindowManagerPolicy.TRANSIT_ENTER:
1083 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
1084 break;
1085 case WindowManagerPolicy.TRANSIT_EXIT:
1086 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
1087 break;
1088 case WindowManagerPolicy.TRANSIT_SHOW:
1089 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
1090 break;
1091 case WindowManagerPolicy.TRANSIT_HIDE:
1092 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
1093 break;
1094 }
1095 if (attr >= 0) {
1096 a = mService.loadAnimation(mWin.mAttrs, attr);
1097 }
1098 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001099 if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001100 "applyAnimation: win=" + this
1101 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
1102 + " mAnimation=" + mAnimation
1103 + " isEntrance=" + isEntrance);
1104 if (a != null) {
1105 if (WindowManagerService.DEBUG_ANIM) {
1106 RuntimeException e = null;
1107 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
1108 e = new RuntimeException();
1109 e.fillInStackTrace();
1110 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001111 Slog.v(TAG, "Loaded animation " + a + " for " + this, e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001112 }
1113 setAnimation(a);
1114 mAnimationIsEntrance = isEntrance;
1115 }
1116 } else {
1117 clearAnimation();
1118 }
1119
1120 return mAnimation != null;
1121 }
1122
Craig Mautnera2c77052012-03-26 12:14:43 -07001123 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1124 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
1125 || mAnimation != null) {
1126 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
1127 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
1128 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
1129 pw.print(" mAnimation="); pw.println(mAnimation);
1130 }
1131 if (mHasTransformation || mHasLocalTransformation) {
1132 pw.print(prefix); pw.print("XForm: has=");
1133 pw.print(mHasTransformation);
1134 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
1135 pw.print(" "); mTransformation.printShortString(pw);
1136 pw.println();
1137 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001138 if (mSurface != null) {
1139 if (dumpAll) {
1140 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
1141 }
1142 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
1143 pw.print(" layer="); pw.print(mSurfaceLayer);
1144 pw.print(" alpha="); pw.print(mSurfaceAlpha);
1145 pw.print(" rect=("); pw.print(mSurfaceX);
1146 pw.print(","); pw.print(mSurfaceY);
1147 pw.print(") "); pw.print(mSurfaceW);
1148 pw.print(" x "); pw.println(mSurfaceH);
1149 }
1150 if (mPendingDestroySurface != null) {
1151 pw.print(prefix); pw.print("mPendingDestroySurface=");
1152 pw.println(mPendingDestroySurface);
1153 }
1154 if (mSurfaceResized || mSurfaceDestroyDeferred) {
1155 pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized);
1156 pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred);
1157 }
1158 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
1159 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
1160 pw.print(" mAlpha="); pw.print(mAlpha);
1161 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
1162 }
1163 if (mHaveMatrix || mWin.mGlobalScale != 1) {
1164 pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale);
1165 pw.print(" mDsDx="); pw.print(mDsDx);
1166 pw.print(" mDtDx="); pw.print(mDtDx);
1167 pw.print(" mDsDy="); pw.print(mDsDy);
1168 pw.print(" mDtDy="); pw.println(mDtDy);
1169 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001170 }
1171
1172}