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