blob: 355db6e079b94c79b7ae2a074a93364a213809fc [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
Craig Mautnerd09cc4b2012-04-04 10:23:31 -07008import static com.android.server.wm.WindowManagerService.LayoutFields.CLEAR_ORIENTATION_CHANGE_COMPLETE;
Craig Mautner7d8df392012-04-06 15:26:23 -07009import static com.android.server.wm.WindowManagerService.LayoutFields.SET_TURN_ON_SCREEN;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070010
Craig Mautnerc2f9be02012-03-27 17:32:29 -070011import android.content.Context;
12import android.graphics.Matrix;
13import android.graphics.PixelFormat;
Craig Mautner7358fbf2012-04-12 21:06:33 -070014import android.graphics.Point;
15import android.graphics.PointF;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070016import android.graphics.Rect;
Craig Mautner48ba1e72012-04-02 13:18:16 -070017import android.graphics.Region;
Craig Mautnera51a9562012-04-17 17:05:26 -070018import android.os.Debug;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070019import android.os.RemoteException;
Craig Mautnera2c77052012-03-26 12:14:43 -070020import android.util.Slog;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070021import android.view.Surface;
Craig Mautner7358fbf2012-04-12 21:06:33 -070022import android.view.SurfaceSession;
Craig Mautnera2c77052012-03-26 12:14:43 -070023import android.view.WindowManager;
24import android.view.WindowManagerPolicy;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070025import android.view.WindowManager.LayoutParams;
Craig Mautnera2c77052012-03-26 12:14:43 -070026import android.view.animation.Animation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070027import android.view.animation.AnimationUtils;
Craig Mautnera2c77052012-03-26 12:14:43 -070028import android.view.animation.Transformation;
29
30import com.android.server.wm.WindowManagerService.H;
31
32import java.io.PrintWriter;
Craig Mautner7358fbf2012-04-12 21:06:33 -070033import java.util.ArrayList;
Craig Mautnera2c77052012-03-26 12:14:43 -070034
35/**
Craig Mautnerc2f9be02012-03-27 17:32:29 -070036 * Keep track of animations and surface operations for a single WindowState.
37 **/
Craig Mautnera2c77052012-03-26 12:14:43 -070038class WindowStateAnimator {
Craig Mautnerc2f9be02012-03-27 17:32:29 -070039 static final boolean DEBUG_VISIBILITY = WindowManagerService.DEBUG_VISIBILITY;
40 static final boolean DEBUG_ANIM = WindowManagerService.DEBUG_ANIM;
41 static final boolean DEBUG_LAYERS = WindowManagerService.DEBUG_LAYERS;
42 static final boolean DEBUG_STARTING_WINDOW = WindowManagerService.DEBUG_STARTING_WINDOW;
43 static final boolean SHOW_TRANSACTIONS = WindowManagerService.SHOW_TRANSACTIONS;
44 static final boolean SHOW_LIGHT_TRANSACTIONS = WindowManagerService.SHOW_LIGHT_TRANSACTIONS;
45 static final boolean SHOW_SURFACE_ALLOC = WindowManagerService.SHOW_SURFACE_ALLOC;
46 static final boolean localLOGV = WindowManagerService.localLOGV;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -070047 static final boolean DEBUG_ORIENTATION = WindowManagerService.DEBUG_ORIENTATION;
Craig Mautner7358fbf2012-04-12 21:06:33 -070048 static final boolean DEBUG_SURFACE_TRACE = WindowManagerService.DEBUG_SURFACE_TRACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070049
50 static final String TAG = "WindowStateAnimator";
Craig Mautnera2c77052012-03-26 12:14:43 -070051
52 final WindowManagerService mService;
53 final WindowState mWin;
54 final WindowState mAttachedWindow;
Craig Mautnere7ae2502012-03-26 17:11:19 -070055 final WindowAnimator mAnimator;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070056 final Session mSession;
57 final WindowManagerPolicy mPolicy;
58 final Context mContext;
Craig Mautnera2c77052012-03-26 12:14:43 -070059
60 // Currently running animation.
61 boolean mAnimating;
62 boolean mLocalAnimating;
63 Animation mAnimation;
64 boolean mAnimationIsEntrance;
65 boolean mHasTransformation;
66 boolean mHasLocalTransformation;
67 final Transformation mTransformation = new Transformation();
68 boolean mWasAnimating; // Were we animating going into the most recent animation step?
Craig Mautnerc2f9be02012-03-27 17:32:29 -070069 int mAnimLayer;
70 int mLastLayer;
71
72 Surface mSurface;
73 Surface mPendingDestroySurface;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070074
75 /**
76 * Set when we have changed the size of the surface, to know that
77 * we must tell them application to resize (and thus redraw itself).
78 */
79 boolean mSurfaceResized;
80
81 /**
82 * Set if the client has asked that the destroy of its surface be delayed
83 * until it explicitly says it is okay.
84 */
85 boolean mSurfaceDestroyDeferred;
86
Craig Mautner7d8df392012-04-06 15:26:23 -070087 float mShownAlpha = 0;
88 float mAlpha = 0;
89 float mLastAlpha = 0;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070090
91 // Used to save animation distances between the time they are calculated and when they are
92 // used.
93 int mAnimDw;
94 int mAnimDh;
95 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
96 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
97
98 boolean mHaveMatrix;
99
100 // For debugging, this is the last information given to the surface flinger.
101 boolean mSurfaceShown;
102 float mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
103 int mSurfaceLayer;
104 float mSurfaceAlpha;
105
106 // Set to true if, when the window gets displayed, it should perform
107 // an enter animation.
108 boolean mEnterAnimationPending;
Craig Mautnera2c77052012-03-26 12:14:43 -0700109
Craig Mautner749a7bb2012-04-02 13:49:53 -0700110 /** This is set when there is no Surface */
111 static final int NO_SURFACE = 0;
112 /** This is set after the Surface has been created but before the window has been drawn. During
113 * this time the surface is hidden. */
114 static final int DRAW_PENDING = 1;
115 /** This is set after the window has finished drawing for the first time but before its surface
116 * is shown. The surface will be displayed when the next layout is run. */
117 static final int COMMIT_DRAW_PENDING = 2;
118 /** This is set during the time after the window's drawing has been committed, and before its
119 * surface is actually shown. It is used to delay showing the surface until all windows in a
120 * token are ready to be shown. */
121 static final int READY_TO_SHOW = 3;
122 /** Set when the window has been shown in the screen the first time. */
123 static final int HAS_DRAWN = 4;
124 int mDrawState;
Craig Mautnera608b882012-03-30 13:03:49 -0700125
Craig Mautner749a7bb2012-04-02 13:49:53 -0700126 /** Was this window last hidden? */
127 boolean mLastHidden;
Craig Mautnera608b882012-03-30 13:03:49 -0700128
Craig Mautnerbec53f72012-04-05 11:49:05 -0700129 int mAttrFlags;
130 int mAttrType;
131
Craig Mautnera2c77052012-03-26 12:14:43 -0700132 public WindowStateAnimator(final WindowManagerService service, final WindowState win,
133 final WindowState attachedWindow) {
134 mService = service;
135 mWin = win;
136 mAttachedWindow = attachedWindow;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700137 mAnimator = mService.mAnimator;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700138 mSession = win.mSession;
139 mPolicy = mService.mPolicy;
140 mContext = mService.mContext;
Craig Mautnerbec53f72012-04-05 11:49:05 -0700141 mAttrFlags = win.mAttrs.flags;
142 mAttrType = win.mAttrs.type;
Craig Mautner9aa69582012-05-09 17:41:13 -0700143 mAnimDw = service.mAppDisplayWidth;
144 mAnimDh = service.mAppDisplayHeight;
Craig Mautnera2c77052012-03-26 12:14:43 -0700145 }
146
147 public void setAnimation(Animation anim) {
Craig Mautnerbec53f72012-04-05 11:49:05 -0700148 if (localLOGV) Slog.v(TAG, "Setting animation in " + this + ": " + anim);
Craig Mautnera2c77052012-03-26 12:14:43 -0700149 mAnimating = false;
150 mLocalAnimating = false;
151 mAnimation = anim;
152 mAnimation.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION);
153 mAnimation.scaleCurrentDuration(mService.mWindowAnimationScale);
154 // Start out animation gone if window is gone, or visible if window is visible.
155 mTransformation.clear();
Craig Mautner749a7bb2012-04-02 13:49:53 -0700156 mTransformation.setAlpha(mLastHidden ? 0 : 1);
Craig Mautnera2c77052012-03-26 12:14:43 -0700157 mHasLocalTransformation = true;
158 }
159
160 public void clearAnimation() {
161 if (mAnimation != null) {
162 mAnimating = true;
163 mLocalAnimating = false;
164 mAnimation.cancel();
165 mAnimation = null;
166 }
167 }
168
169 /** Is the window or its container currently animating? */
170 boolean isAnimating() {
171 final WindowState attached = mAttachedWindow;
172 final AppWindowToken atoken = mWin.mAppToken;
173 return mAnimation != null
174 || (attached != null && attached.mWinAnimator.mAnimation != null)
175 || (atoken != null &&
Craig Mautner59431632012-04-04 11:56:44 -0700176 (atoken.mAppAnimator.animation != null
Craig Mautnera2c77052012-03-26 12:14:43 -0700177 || atoken.inPendingTransaction));
178 }
179
Craig Mautner0afddcb2012-05-08 15:38:00 -0700180 /** Is the window animating the DummyAnimation? */
181 boolean isDummyAnimation() {
182 final AppWindowToken atoken = mWin.mAppToken;
183 return atoken != null
184 && atoken.mAppAnimator.animation == AppWindowAnimator.sDummyAnimation;
185 }
186
Craig Mautnera2c77052012-03-26 12:14:43 -0700187 /** Is this window currently animating? */
188 boolean isWindowAnimating() {
189 return mAnimation != null;
190 }
191
Craig Mautnera2c77052012-03-26 12:14:43 -0700192 void cancelExitAnimationForNextAnimationLocked() {
Craig Mautnera2c77052012-03-26 12:14:43 -0700193 if (mAnimation != null) {
194 mAnimation.cancel();
195 mAnimation = null;
Craig Mautner4d7349b2012-04-20 14:52:47 -0700196 mLocalAnimating = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700197 destroySurfaceLocked();
Craig Mautnera2c77052012-03-26 12:14:43 -0700198 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700199 }
200
201 private boolean stepAnimation(long currentTime) {
202 if ((mAnimation == null) || !mLocalAnimating) {
203 return false;
204 }
205 mTransformation.clear();
206 final boolean more = mAnimation.getTransformation(currentTime, mTransformation);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700207 if (DEBUG_ANIM) Slog.v(
208 TAG, "Stepped animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700209 ": more=" + more + ", xform=" + mTransformation);
210 return more;
211 }
212
213 // This must be called while inside a transaction. Returns true if
214 // there is more animation to run.
215 boolean stepAnimationLocked(long currentTime) {
216 // Save the animation state as it was before this step so WindowManagerService can tell if
217 // we just started or just stopped animating by comparing mWasAnimating with isAnimating().
218 mWasAnimating = mAnimating;
219 if (mService.okToDisplay()) {
220 // We will run animations as long as the display isn't frozen.
221
222 if (mWin.isDrawnLw() && mAnimation != null) {
223 mHasTransformation = true;
224 mHasLocalTransformation = true;
225 if (!mLocalAnimating) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700226 if (DEBUG_ANIM) Slog.v(
227 TAG, "Starting animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700228 " @ " + currentTime + ": ww=" + mWin.mFrame.width() +
229 " wh=" + mWin.mFrame.height() +
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700230 " dw=" + mAnimDw + " dh=" + mAnimDh +
Craig Mautnera2c77052012-03-26 12:14:43 -0700231 " scale=" + mService.mWindowAnimationScale);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700232 mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(),
233 mAnimDw, mAnimDh);
Craig Mautner9aa69582012-05-09 17:41:13 -0700234 mAnimDw = mService.mAppDisplayWidth;
235 mAnimDh = mService.mAppDisplayHeight;
Craig Mautnera2c77052012-03-26 12:14:43 -0700236 mAnimation.setStartTime(currentTime);
237 mLocalAnimating = true;
238 mAnimating = true;
239 }
240 if ((mAnimation != null) && mLocalAnimating) {
241 if (stepAnimation(currentTime)) {
242 return true;
243 }
244 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700245 if (DEBUG_ANIM) Slog.v(
246 TAG, "Finished animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700247 " @ " + currentTime);
248 //WindowManagerService.this.dump();
249 }
250 mHasLocalTransformation = false;
251 if ((!mLocalAnimating || mAnimationIsEntrance) && mWin.mAppToken != null
Craig Mautner59431632012-04-04 11:56:44 -0700252 && mWin.mAppToken.mAppAnimator.animation != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700253 // When our app token is animating, we kind-of pretend like
254 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
255 // part of this check means that we will only do this if
256 // our window is not currently exiting, or it is not
257 // locally animating itself. The idea being that one that
258 // is exiting and doing a local animation should be removed
259 // once that animation is done.
260 mAnimating = true;
261 mHasTransformation = true;
262 mTransformation.clear();
263 return false;
264 } else if (mHasTransformation) {
265 // Little trick to get through the path below to act like
266 // we have finished an animation.
267 mAnimating = true;
268 } else if (isAnimating()) {
269 mAnimating = true;
270 }
271 } else if (mAnimation != null) {
272 // If the display is frozen, and there is a pending animation,
273 // clear it and make sure we run the cleanup code.
274 mAnimating = true;
Craig Mautnera2c77052012-03-26 12:14:43 -0700275 }
276
277 if (!mAnimating && !mLocalAnimating) {
278 return false;
279 }
280
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700281 // Done animating, clean up.
282 if (DEBUG_ANIM) Slog.v(
283 TAG, "Animation done in " + this + ": exiting=" + mWin.mExiting
Craig Mautnera2c77052012-03-26 12:14:43 -0700284 + ", reportedVisible="
285 + (mWin.mAppToken != null ? mWin.mAppToken.reportedVisible : false));
286
287 mAnimating = false;
288 mLocalAnimating = false;
289 if (mAnimation != null) {
290 mAnimation.cancel();
291 mAnimation = null;
292 }
Craig Mautnere7ae2502012-03-26 17:11:19 -0700293 if (mAnimator.mWindowDetachedWallpaper == mWin) {
294 mAnimator.mWindowDetachedWallpaper = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700295 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700296 mAnimLayer = mWin.mLayer;
Craig Mautnera2c77052012-03-26 12:14:43 -0700297 if (mWin.mIsImWindow) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700298 mAnimLayer += mService.mInputMethodAnimLayerAdjustment;
Craig Mautnera2c77052012-03-26 12:14:43 -0700299 } else if (mWin.mIsWallpaper) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700300 mAnimLayer += mService.mWallpaperAnimLayerAdjustment;
Craig Mautnera2c77052012-03-26 12:14:43 -0700301 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700302 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
303 + " anim layer: " + mAnimLayer);
Craig Mautnera2c77052012-03-26 12:14:43 -0700304 mHasTransformation = false;
305 mHasLocalTransformation = false;
306 if (mWin.mPolicyVisibility != mWin.mPolicyVisibilityAfterAnim) {
307 if (WindowState.DEBUG_VISIBILITY) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700308 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
Craig Mautnera2c77052012-03-26 12:14:43 -0700309 + mWin.mPolicyVisibilityAfterAnim);
310 }
311 mWin.mPolicyVisibility = mWin.mPolicyVisibilityAfterAnim;
312 mService.mLayoutNeeded = true;
313 if (!mWin.mPolicyVisibility) {
314 if (mService.mCurrentFocus == mWin) {
315 mService.mFocusMayChange = true;
316 }
317 // Window is no longer visible -- make sure if we were waiting
318 // for it to be displayed before enabling the display, that
319 // we allow the display to be enabled now.
320 mService.enableScreenIfNeededLocked();
321 }
322 }
323 mTransformation.clear();
Craig Mautner749a7bb2012-04-02 13:49:53 -0700324 if (mDrawState == HAS_DRAWN
Craig Mautnera2c77052012-03-26 12:14:43 -0700325 && mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
326 && mWin.mAppToken != null
327 && mWin.mAppToken.firstWindowDrawn
328 && mWin.mAppToken.startingData != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700329 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
Craig Mautnera2c77052012-03-26 12:14:43 -0700330 + mWin.mToken + ": first real window done animating");
331 mService.mFinishedStarting.add(mWin.mAppToken);
332 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
333 }
334
335 finishExit();
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700336 mAnimator.mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
337 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) mService.debugLayoutRepeats(
338 "WindowStateAnimator", mAnimator.mPendingLayoutChanges);
Craig Mautnera2c77052012-03-26 12:14:43 -0700339
340 if (mWin.mAppToken != null) {
341 mWin.mAppToken.updateReportedVisibilityLocked();
342 }
343
344 return false;
345 }
346
347 void finishExit() {
348 if (WindowManagerService.DEBUG_ANIM) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700349 TAG, "finishExit in " + this
Craig Mautnera2c77052012-03-26 12:14:43 -0700350 + ": exiting=" + mWin.mExiting
351 + " remove=" + mWin.mRemoveOnExit
352 + " windowAnimating=" + isWindowAnimating());
353
354 final int N = mWin.mChildWindows.size();
355 for (int i=0; i<N; i++) {
356 mWin.mChildWindows.get(i).mWinAnimator.finishExit();
357 }
358
359 if (!mWin.mExiting) {
360 return;
361 }
362
363 if (isWindowAnimating()) {
364 return;
365 }
366
367 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700368 TAG, "Exit animation finished in " + this
Craig Mautnera2c77052012-03-26 12:14:43 -0700369 + ": remove=" + mWin.mRemoveOnExit);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700370 if (mSurface != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700371 mService.mDestroySurface.add(mWin);
372 mWin.mDestroying = true;
373 if (WindowState.SHOW_TRANSACTIONS) WindowManagerService.logSurface(
374 mWin, "HIDE (finishExit)", null);
Craig Mautner0afddcb2012-05-08 15:38:00 -0700375 hide();
Craig Mautnera2c77052012-03-26 12:14:43 -0700376 }
377 mWin.mExiting = false;
378 if (mWin.mRemoveOnExit) {
379 mService.mPendingRemove.add(mWin);
380 mWin.mRemoveOnExit = false;
381 }
Craig Mautner9aa69582012-05-09 17:41:13 -0700382 if (mService.mWallpaperTarget == mWin && mService.mLowerWallpaperTarget == null) {
Craig Mautner0afddcb2012-05-08 15:38:00 -0700383 mAnimator.hideWallpapersLocked();
384 }
385 }
386
387 void hide() {
388 if (!mLastHidden) {
389 //dump();
390 mLastHidden = true;
391 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
392 "HIDE (performLayout)", null);
393 if (mSurface != null) {
394 mSurfaceShown = false;
395 try {
396 mSurface.hide();
397 } catch (RuntimeException e) {
398 Slog.w(TAG, "Exception hiding surface in " + mWin);
399 }
400 }
401 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700402 }
403
Craig Mautnera608b882012-03-30 13:03:49 -0700404 boolean finishDrawingLocked() {
Craig Mautner749a7bb2012-04-02 13:49:53 -0700405 if (mDrawState == DRAW_PENDING) {
Craig Mautner83339b42012-05-01 22:13:23 -0700406 if (DEBUG_ANIM || SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
407 TAG, "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING " + this + " in "
408 + mSurface);
Craig Mautner749a7bb2012-04-02 13:49:53 -0700409 mDrawState = COMMIT_DRAW_PENDING;
Craig Mautnera608b882012-03-30 13:03:49 -0700410 return true;
411 }
412 return false;
413 }
414
415 // This must be called while inside a transaction.
416 boolean commitFinishDrawingLocked(long currentTime) {
Craig Mautner749a7bb2012-04-02 13:49:53 -0700417 if (mDrawState != COMMIT_DRAW_PENDING) {
Craig Mautnera608b882012-03-30 13:03:49 -0700418 return false;
419 }
Craig Mautner83339b42012-05-01 22:13:23 -0700420 if (DEBUG_ANIM)
421 Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurface);
Craig Mautner749a7bb2012-04-02 13:49:53 -0700422 mDrawState = READY_TO_SHOW;
Craig Mautnera608b882012-03-30 13:03:49 -0700423 final boolean starting = mWin.mAttrs.type == TYPE_APPLICATION_STARTING;
424 final AppWindowToken atoken = mWin.mAppToken;
425 if (atoken == null || atoken.allDrawn || starting) {
426 performShowLocked();
427 }
428 return true;
429 }
430
Craig Mautner7d8df392012-04-06 15:26:23 -0700431 static class SurfaceTrace extends Surface {
432 private final static String SURFACE_TAG = "SurfaceTrace";
433 final static ArrayList<SurfaceTrace> sSurfaces = new ArrayList<SurfaceTrace>();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700434
Craig Mautner7d8df392012-04-06 15:26:23 -0700435 private float mSurfaceTraceAlpha = 0;
Craig Mautner7358fbf2012-04-12 21:06:33 -0700436 private int mLayer;
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700437 private final PointF mPosition = new PointF();
438 private final Point mSize = new Point();
439 private final Rect mWindowCrop = new Rect();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700440 private boolean mShown = false;
441 private String mName = "Not named";
442
Craig Mautner7d8df392012-04-06 15:26:23 -0700443 public SurfaceTrace(SurfaceSession s,
Craig Mautner7358fbf2012-04-12 21:06:33 -0700444 int pid, int display, int w, int h, int format, int flags) throws
445 OutOfResourcesException {
446 super(s, pid, display, w, h, format, flags);
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700447 mSize.set(w, h);
Craig Mautner7d8df392012-04-06 15:26:23 -0700448 Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700449 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700450 }
451
Craig Mautner7d8df392012-04-06 15:26:23 -0700452 public SurfaceTrace(SurfaceSession s,
Craig Mautner7358fbf2012-04-12 21:06:33 -0700453 int pid, String name, int display, int w, int h, int format, int flags)
454 throws OutOfResourcesException {
455 super(s, pid, name, display, w, h, format, flags);
456 mName = name;
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700457 mSize.set(w, h);
Craig Mautner7d8df392012-04-06 15:26:23 -0700458 Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700459 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700460 }
461
462 @Override
463 public void setAlpha(float alpha) {
464 super.setAlpha(alpha);
Craig Mautner7d8df392012-04-06 15:26:23 -0700465 mSurfaceTraceAlpha = alpha;
466 Slog.v(SURFACE_TAG, "setAlpha: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700467 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700468 }
469
470 @Override
471 public void setLayer(int zorder) {
472 super.setLayer(zorder);
473 mLayer = zorder;
Craig Mautner7d8df392012-04-06 15:26:23 -0700474 Slog.v(SURFACE_TAG, "setLayer: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700475 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700476
477 sSurfaces.remove(this);
478 int i;
479 for (i = sSurfaces.size() - 1; i >= 0; i--) {
Craig Mautner7d8df392012-04-06 15:26:23 -0700480 SurfaceTrace s = sSurfaces.get(i);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700481 if (s.mLayer < zorder) {
482 break;
483 }
484 }
485 sSurfaces.add(i + 1, this);
486 }
487
488 @Override
489 public void setPosition(float x, float y) {
490 super.setPosition(x, y);
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700491 mPosition.set(x, y);
Craig Mautner7d8df392012-04-06 15:26:23 -0700492 Slog.v(SURFACE_TAG, "setPosition: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700493 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700494 }
495
496 @Override
497 public void setSize(int w, int h) {
498 super.setSize(w, h);
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700499 mSize.set(w, h);
Craig Mautner7d8df392012-04-06 15:26:23 -0700500 Slog.v(SURFACE_TAG, "setSize: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700501 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700502 }
503
504 @Override
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700505 public void setWindowCrop(Rect crop) {
506 super.setWindowCrop(crop);
507 mWindowCrop.set(crop);
508 Slog.v(SURFACE_TAG, "setWindowCrop: " + this + ". Called by "
509 + Debug.getCallers(3));
510 }
511
512 @Override
Craig Mautner7358fbf2012-04-12 21:06:33 -0700513 public void hide() {
514 super.hide();
515 mShown = false;
Craig Mautner7d8df392012-04-06 15:26:23 -0700516 Slog.v(SURFACE_TAG, "hide: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700517 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700518 }
519 @Override
520 public void show() {
521 super.show();
522 mShown = true;
Craig Mautner7d8df392012-04-06 15:26:23 -0700523 Slog.v(SURFACE_TAG, "show: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700524 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700525 }
526
527 @Override
528 public void destroy() {
529 super.destroy();
Craig Mautner7d8df392012-04-06 15:26:23 -0700530 Slog.v(SURFACE_TAG, "destroy: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700531 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700532 sSurfaces.remove(this);
533 }
534
Craig Mautneracaf9cc2012-04-17 11:45:25 -0700535 @Override
536 public void release() {
537 super.release();
538 Slog.v(SURFACE_TAG, "release: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700539 + Debug.getCallers(3));
Craig Mautneracaf9cc2012-04-17 11:45:25 -0700540 sSurfaces.remove(this);
541 }
542
Craig Mautner7358fbf2012-04-12 21:06:33 -0700543 static void dumpAllSurfaces() {
544 final int N = sSurfaces.size();
545 for (int i = 0; i < N; i++) {
546 Slog.i(TAG, "SurfaceDump: " + sSurfaces.get(i));
547 }
548 }
549
550 @Override
551 public String toString() {
Craig Mautnerfbf378c2012-04-23 17:24:21 -0700552 return "Surface " + Integer.toHexString(System.identityHashCode(this)) + " "
553 + mName + ": shown=" + mShown + " layer=" + mLayer
Craig Mautner7d8df392012-04-06 15:26:23 -0700554 + " alpha=" + mSurfaceTraceAlpha + " " + mPosition.x + "," + mPosition.y
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700555 + " " + mSize.x + "x" + mSize.y
556 + " crop=" + mWindowCrop.toShortString();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700557 }
558 }
559
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700560 Surface createSurfaceLocked() {
561 if (mSurface == null) {
Craig Mautner83339b42012-05-01 22:13:23 -0700562 if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG,
563 "createSurface " + this + ": mDrawState=DRAW_PENDING");
Craig Mautner749a7bb2012-04-02 13:49:53 -0700564 mDrawState = DRAW_PENDING;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700565 if (mWin.mAppToken != null) {
566 mWin.mAppToken.allDrawn = false;
567 }
568
569 mService.makeWindowFreezingScreenIfNeededLocked(mWin);
570
571 int flags = 0;
572 final WindowManager.LayoutParams attrs = mWin.mAttrs;
573
574 if ((attrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
575 flags |= Surface.SECURE;
576 }
577 if (WindowState.DEBUG_VISIBILITY) Slog.v(
578 TAG, "Creating surface in session "
579 + mSession.mSurfaceSession + " window " + this
580 + " w=" + mWin.mCompatFrame.width()
581 + " h=" + mWin.mCompatFrame.height() + " format="
582 + attrs.format + " flags=" + flags);
583
584 int w = mWin.mCompatFrame.width();
585 int h = mWin.mCompatFrame.height();
586 if ((attrs.flags & LayoutParams.FLAG_SCALED) != 0) {
587 // for a scaled surface, we always want the requested
588 // size.
589 w = mWin.mRequestedWidth;
590 h = mWin.mRequestedHeight;
591 }
592
593 // Something is wrong and SurfaceFlinger will not like this,
594 // try to revert to sane values
595 if (w <= 0) w = 1;
596 if (h <= 0) h = 1;
597
598 mSurfaceShown = false;
599 mSurfaceLayer = 0;
Craig Mautner7d8df392012-04-06 15:26:23 -0700600 mSurfaceAlpha = 0;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700601 mSurfaceX = 0;
602 mSurfaceY = 0;
603 mSurfaceW = w;
604 mSurfaceH = h;
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700605 mWin.mLastSystemDecorRect.set(0, 0, 0, 0);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700606 try {
607 final boolean isHwAccelerated = (attrs.flags &
608 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
609 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
610 if (!PixelFormat.formatHasAlpha(attrs.format)) {
611 flags |= Surface.OPAQUE;
612 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700613 if (DEBUG_SURFACE_TRACE) {
Craig Mautner7d8df392012-04-06 15:26:23 -0700614 mSurface = new SurfaceTrace(
Craig Mautner7358fbf2012-04-12 21:06:33 -0700615 mSession.mSurfaceSession, mSession.mPid,
616 attrs.getTitle().toString(),
617 0, w, h, format, flags);
618 } else {
619 mSurface = new Surface(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700620 mSession.mSurfaceSession, mSession.mPid,
621 attrs.getTitle().toString(),
622 0, w, h, format, flags);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700623 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700624 mWin.mHasSurface = true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700625 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG,
626 " CREATE SURFACE "
627 + mSurface + " IN SESSION "
628 + mSession.mSurfaceSession
629 + ": pid=" + mSession.mPid + " format="
630 + attrs.format + " flags=0x"
631 + Integer.toHexString(flags)
632 + " / " + this);
633 } catch (Surface.OutOfResourcesException e) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700634 mWin.mHasSurface = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700635 Slog.w(TAG, "OutOfResourcesException creating surface");
636 mService.reclaimSomeSurfaceMemoryLocked(this, "create", true);
Craig Mautner749a7bb2012-04-02 13:49:53 -0700637 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700638 return null;
639 } catch (Exception e) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700640 mWin.mHasSurface = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700641 Slog.e(TAG, "Exception creating surface", e);
Craig Mautner749a7bb2012-04-02 13:49:53 -0700642 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700643 return null;
644 }
645
646 if (WindowManagerService.localLOGV) Slog.v(
647 TAG, "Got surface: " + mSurface
648 + ", set left=" + mWin.mFrame.left + " top=" + mWin.mFrame.top
649 + ", animLayer=" + mAnimLayer);
650 if (SHOW_LIGHT_TRANSACTIONS) {
651 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
652 WindowManagerService.logSurface(mWin, "CREATE pos=("
653 + mWin.mFrame.left + "," + mWin.mFrame.top + ") ("
654 + mWin.mCompatFrame.width() + "x" + mWin.mCompatFrame.height()
655 + "), layer=" + mAnimLayer + " HIDE", null);
656 }
657 Surface.openTransaction();
658 try {
659 try {
660 mSurfaceX = mWin.mFrame.left + mWin.mXOffset;
661 mSurfaceY = mWin.mFrame.top + mWin.mYOffset;
662 mSurface.setPosition(mSurfaceX, mSurfaceY);
663 mSurfaceLayer = mAnimLayer;
664 mSurface.setLayer(mAnimLayer);
Craig Mautner7d8df392012-04-06 15:26:23 -0700665 mSurface.setAlpha(0);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700666 mSurfaceShown = false;
667 mSurface.hide();
668 if ((mWin.mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
669 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, "DITHER", null);
670 mSurface.setFlags(Surface.SURFACE_DITHER, Surface.SURFACE_DITHER);
671 }
672 } catch (RuntimeException e) {
673 Slog.w(TAG, "Error creating surface in " + w, e);
674 mService.reclaimSomeSurfaceMemoryLocked(this, "create-init", true);
675 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700676 mLastHidden = true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700677 } finally {
678 Surface.closeTransaction();
679 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
680 "<<< CLOSE TRANSACTION createSurfaceLocked");
681 }
682 if (WindowManagerService.localLOGV) Slog.v(
683 TAG, "Created surface " + this);
684 }
685 return mSurface;
686 }
687
688 void destroySurfaceLocked() {
689 if (mWin.mAppToken != null && mWin == mWin.mAppToken.startingWindow) {
690 mWin.mAppToken.startingDisplayed = false;
691 }
692
693 if (mSurface != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700694
695 int i = mWin.mChildWindows.size();
696 while (i > 0) {
697 i--;
698 WindowState c = mWin.mChildWindows.get(i);
699 c.mAttachedHidden = true;
700 }
701
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700702 try {
703 if (DEBUG_VISIBILITY) {
704 RuntimeException e = null;
705 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
706 e = new RuntimeException();
707 e.fillInStackTrace();
708 }
709 Slog.w(TAG, "Window " + this + " destroying surface "
710 + mSurface + ", session " + mSession, e);
711 }
712 if (mSurfaceDestroyDeferred) {
713 if (mSurface != null && mPendingDestroySurface != mSurface) {
714 if (mPendingDestroySurface != null) {
715 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
716 RuntimeException e = null;
717 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
718 e = new RuntimeException();
719 e.fillInStackTrace();
720 }
721 WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
722 }
723 mPendingDestroySurface.destroy();
724 }
725 mPendingDestroySurface = mSurface;
726 }
727 } else {
728 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
729 RuntimeException e = null;
730 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
731 e = new RuntimeException();
732 e.fillInStackTrace();
733 }
734 WindowManagerService.logSurface(mWin, "DESTROY", e);
735 }
736 mSurface.destroy();
737 }
738 } catch (RuntimeException e) {
739 Slog.w(TAG, "Exception thrown when destroying Window " + this
740 + " surface " + mSurface + " session " + mSession
741 + ": " + e.toString());
742 }
743
744 mSurfaceShown = false;
745 mSurface = null;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700746 mWin.mHasSurface =false;
Craig Mautnerbf08af32012-05-16 19:43:42 -0700747 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700748 }
749 }
750
751 void destroyDeferredSurfaceLocked() {
752 try {
753 if (mPendingDestroySurface != null) {
754 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
755 RuntimeException e = null;
756 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
757 e = new RuntimeException();
758 e.fillInStackTrace();
759 }
760 WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
761 }
762 mPendingDestroySurface.destroy();
763 }
764 } catch (RuntimeException e) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700765 Slog.w(TAG, "Exception thrown when destroying Window "
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700766 + this + " surface " + mPendingDestroySurface
767 + " session " + mSession + ": " + e.toString());
768 }
769 mSurfaceDestroyDeferred = false;
770 mPendingDestroySurface = null;
771 }
772
773 void computeShownFrameLocked() {
774 final boolean selfTransformation = mHasLocalTransformation;
775 Transformation attachedTransformation =
776 (mAttachedWindow != null && mAttachedWindow.mWinAnimator.mHasLocalTransformation)
777 ? mAttachedWindow.mWinAnimator.mTransformation : null;
Craig Mautner59431632012-04-04 11:56:44 -0700778 final AppWindowAnimator appAnimator =
779 mWin.mAppToken == null ? null : mWin.mAppToken.mAppAnimator;
780 Transformation appTransformation = (appAnimator != null && appAnimator.hasTransformation)
781 ? appAnimator.transformation : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700782
783 // Wallpapers are animated based on the "real" window they
784 // are currently targeting.
785 if (mWin.mAttrs.type == TYPE_WALLPAPER && mService.mLowerWallpaperTarget == null
786 && mService.mWallpaperTarget != null) {
787 if (mService.mWallpaperTarget.mWinAnimator.mHasLocalTransformation &&
788 mService.mWallpaperTarget.mWinAnimator.mAnimation != null &&
789 !mService.mWallpaperTarget.mWinAnimator.mAnimation.getDetachWallpaper()) {
790 attachedTransformation = mService.mWallpaperTarget.mWinAnimator.mTransformation;
791 if (WindowManagerService.DEBUG_WALLPAPER && attachedTransformation != null) {
792 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
793 }
794 }
Craig Mautner59431632012-04-04 11:56:44 -0700795 final AppWindowAnimator wpAppAnimator = mService.mWallpaperTarget.mAppToken == null
796 ? null : mService.mWallpaperTarget.mAppToken.mAppAnimator;
797 if (wpAppAnimator != null &&
798 wpAppAnimator.hasTransformation &&
799 wpAppAnimator.animation != null &&
800 !wpAppAnimator.animation.getDetachWallpaper()) {
801 appTransformation = wpAppAnimator.transformation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700802 if (WindowManagerService.DEBUG_WALLPAPER && appTransformation != null) {
803 Slog.v(TAG, "WP target app xform: " + appTransformation);
804 }
805 }
806 }
807
808 final boolean screenAnimation = mService.mAnimator.mScreenRotationAnimation != null
809 && mService.mAnimator.mScreenRotationAnimation.isAnimating();
810 if (selfTransformation || attachedTransformation != null
811 || appTransformation != null || screenAnimation) {
812 // cache often used attributes locally
813 final Rect frame = mWin.mFrame;
814 final float tmpFloats[] = mService.mTmpFloats;
815 final Matrix tmpMatrix = mWin.mTmpMatrix;
816
817 // Compute the desired transformation.
818 if (screenAnimation) {
819 // If we are doing a screen animation, the global rotation
820 // applied to windows can result in windows that are carefully
821 // aligned with each other to slightly separate, allowing you
822 // to see what is behind them. An unsightly mess. This...
823 // thing... magically makes it call good: scale each window
824 // slightly (two pixels larger in each dimension, from the
825 // window's center).
826 final float w = frame.width();
827 final float h = frame.height();
828 if (w>=1 && h>=1) {
829 tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2);
830 } else {
831 tmpMatrix.reset();
832 }
833 } else {
834 tmpMatrix.reset();
835 }
836 tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale);
837 if (selfTransformation) {
838 tmpMatrix.postConcat(mTransformation.getMatrix());
839 }
840 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
841 if (attachedTransformation != null) {
842 tmpMatrix.postConcat(attachedTransformation.getMatrix());
843 }
844 if (appTransformation != null) {
845 tmpMatrix.postConcat(appTransformation.getMatrix());
846 }
847 if (screenAnimation) {
848 tmpMatrix.postConcat(
849 mService.mAnimator.mScreenRotationAnimation.getEnterTransformation().getMatrix());
850 }
851
852 // "convert" it into SurfaceFlinger's format
853 // (a 2x2 matrix + an offset)
854 // Here we must not transform the position of the surface
855 // since it is already included in the transformation.
856 //Slog.i(TAG, "Transform: " + matrix);
857
858 mHaveMatrix = true;
859 tmpMatrix.getValues(tmpFloats);
860 mDsDx = tmpFloats[Matrix.MSCALE_X];
861 mDtDx = tmpFloats[Matrix.MSKEW_Y];
862 mDsDy = tmpFloats[Matrix.MSKEW_X];
863 mDtDy = tmpFloats[Matrix.MSCALE_Y];
864 float x = tmpFloats[Matrix.MTRANS_X];
865 float y = tmpFloats[Matrix.MTRANS_Y];
866 int w = frame.width();
867 int h = frame.height();
868 mWin.mShownFrame.set(x, y, x+w, y+h);
869
870 // Now set the alpha... but because our current hardware
871 // can't do alpha transformation on a non-opaque surface,
872 // turn it off if we are running an animation that is also
873 // transforming since it is more important to have that
874 // animation be smooth.
875 mShownAlpha = mAlpha;
876 if (!mService.mLimitedAlphaCompositing
877 || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format)
878 || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
879 && x == frame.left && y == frame.top))) {
880 //Slog.i(TAG, "Applying alpha transform");
881 if (selfTransformation) {
882 mShownAlpha *= mTransformation.getAlpha();
883 }
884 if (attachedTransformation != null) {
885 mShownAlpha *= attachedTransformation.getAlpha();
886 }
887 if (appTransformation != null) {
888 mShownAlpha *= appTransformation.getAlpha();
889 }
890 if (screenAnimation) {
891 mShownAlpha *=
892 mService.mAnimator.mScreenRotationAnimation.getEnterTransformation().getAlpha();
893 }
894 } else {
895 //Slog.i(TAG, "Not applying alpha transform");
896 }
897
898 if (WindowManagerService.localLOGV) Slog.v(
899 TAG, "computeShownFrameLocked: Animating " + this +
900 ": " + mWin.mShownFrame +
901 ", alpha=" + mTransformation.getAlpha() + ", mShownAlpha=" + mShownAlpha);
902 return;
Craig Mautner4d7349b2012-04-20 14:52:47 -0700903 } else if (mWin.mIsWallpaper &&
904 (mAnimator.mPendingActions & WindowAnimator.WALLPAPER_ACTION_PENDING) != 0) {
905 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700906 }
907
908 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautner4d7349b2012-04-20 14:52:47 -0700909 TAG, "computeShownFrameLocked: " + this +
910 " not attached, mAlpha=" + mAlpha);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700911 mWin.mShownFrame.set(mWin.mFrame);
912 if (mWin.mXOffset != 0 || mWin.mYOffset != 0) {
913 mWin.mShownFrame.offset(mWin.mXOffset, mWin.mYOffset);
914 }
915 mShownAlpha = mAlpha;
916 mHaveMatrix = false;
917 mDsDx = mWin.mGlobalScale;
918 mDtDx = 0;
919 mDsDy = 0;
920 mDtDy = mWin.mGlobalScale;
921 }
Craig Mautnerd87946b2012-03-29 18:00:19 -0700922
Dianne Hackborn3e52fc22012-05-15 17:58:02 -0700923 void updateSurfaceWindowCrop(final boolean recoveringMemory) {
924 final WindowState w = mWin;
925
926 // Need to recompute a new system decor rect each time.
927 if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
928 // Currently can't do this cropping for scaled windows. We'll
929 // just keep the crop rect the same as the source surface.
930 w.mSystemDecorRect.set(0, 0, w.mRequestedWidth, w.mRequestedHeight);
931 } else if (w.mLayer >= mService.mSystemDecorLayer) {
932 // Above the decor layer is easy, just use the entire window.
933 w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(),
934 w.mCompatFrame.height());
935 } else {
936 final Rect decorRect = mService.mSystemDecorRect;
937 // Compute the offset of the window in relation to the decor rect.
938 final int offX = w.mXOffset + w.mFrame.left;
939 final int offY = w.mYOffset + w.mFrame.top;
940 // Initialize the decor rect to the entire frame.
941 w.mSystemDecorRect.set(0, 0, w.mFrame.width(), w.mFrame.height());
942 // Intersect with the decor rect, offsetted by window position.
943 w.mSystemDecorRect.intersect(decorRect.left-offX, decorRect.top-offY,
944 decorRect.right-offX, decorRect.bottom-offY);
945 // If size compatibility is being applied to the window, the
946 // surface is scaled relative to the screen. Also apply this
947 // scaling to the crop rect. We aren't using the standard rect
948 // scale function because we want to round things to make the crop
949 // always round to a larger rect to ensure we don't crop too
950 // much and hide part of the window that should be seen.
951 if (w.mEnforceSizeCompat && w.mInvGlobalScale != 1.0f) {
952 final float scale = w.mInvGlobalScale;
953 w.mSystemDecorRect.left = (int) (w.mSystemDecorRect.left * scale - 0.5f);
954 w.mSystemDecorRect.top = (int) (w.mSystemDecorRect.top * scale - 0.5f);
955 w.mSystemDecorRect.right = (int) ((w.mSystemDecorRect.right+1) * scale - 0.5f);
956 w.mSystemDecorRect.bottom = (int) ((w.mSystemDecorRect.bottom+1) * scale - 0.5f);
957 }
958 }
959
960 if (!w.mSystemDecorRect.equals(w.mLastSystemDecorRect)) {
961 w.mLastSystemDecorRect.set(w.mSystemDecorRect);
962 try {
963 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
964 "CROP " + w.mSystemDecorRect.toShortString(), null);
965 mSurface.setWindowCrop(w.mSystemDecorRect);
966 } catch (RuntimeException e) {
967 Slog.w(TAG, "Error setting crop surface of " + w
968 + " crop=" + w.mSystemDecorRect.toShortString(), e);
969 if (!recoveringMemory) {
970 mService.reclaimSomeSurfaceMemoryLocked(this, "crop", true);
971 }
972 }
973 }
974 }
975
Craig Mautneracaf9cc2012-04-17 11:45:25 -0700976 void setSurfaceBoundaries(final boolean recoveringMemory) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700977 final WindowState w = mWin;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700978 int width, height;
979 if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
980 // for a scaled surface, we just want to use
981 // the requested size.
982 width = w.mRequestedWidth;
983 height = w.mRequestedHeight;
984 } else {
985 width = w.mCompatFrame.width();
986 height = w.mCompatFrame.height();
987 }
988
989 if (width < 1) {
990 width = 1;
991 }
992 if (height < 1) {
993 height = 1;
994 }
995 final boolean surfaceResized = mSurfaceW != width || mSurfaceH != height;
996 if (surfaceResized) {
997 mSurfaceW = width;
998 mSurfaceH = height;
999 }
1000
Craig Mautner4d7349b2012-04-20 14:52:47 -07001001 final float left = w.mShownFrame.left;
1002 final float top = w.mShownFrame.top;
1003 if (mSurfaceX != left || mSurfaceY != top) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001004 try {
1005 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
Craig Mautner4d7349b2012-04-20 14:52:47 -07001006 "POS " + left + ", " + top, null);
1007 mSurfaceX = left;
1008 mSurfaceY = top;
1009 mSurface.setPosition(left, top);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001010 } catch (RuntimeException e) {
1011 Slog.w(TAG, "Error positioning surface of " + w
Craig Mautner4d7349b2012-04-20 14:52:47 -07001012 + " pos=(" + left
1013 + "," + top + ")", e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001014 if (!recoveringMemory) {
1015 mService.reclaimSomeSurfaceMemoryLocked(this, "position", true);
1016 }
1017 }
1018 }
1019
1020 if (surfaceResized) {
1021 try {
1022 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1023 "SIZE " + width + "x" + height, null);
1024 mSurfaceResized = true;
1025 mSurface.setSize(width, height);
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001026 mAnimator.mPendingLayoutChanges |=
1027 WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Craig Mautner3a67f352012-05-07 11:21:33 -07001028 if ((w.mAttrs.flags & LayoutParams.FLAG_DIM_BEHIND) != 0) {
1029 mAnimator.startDimming(this, w.mExiting ? 0 : w.mAttrs.dimAmount,
1030 mService.mAppDisplayWidth, mService.mAppDisplayHeight);
1031 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001032 } catch (RuntimeException e) {
1033 // If something goes wrong with the surface (such
1034 // as running out of memory), don't take down the
1035 // entire system.
1036 Slog.e(TAG, "Error resizing surface of " + w
1037 + " size=(" + width + "x" + height + ")", e);
1038 if (!recoveringMemory) {
1039 mService.reclaimSomeSurfaceMemoryLocked(this, "size", true);
1040 }
1041 }
1042 }
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001043
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001044 updateSurfaceWindowCrop(recoveringMemory);
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001045 }
1046
1047 public void prepareSurfaceLocked(final boolean recoveringMemory) {
1048 final WindowState w = mWin;
1049 if (mSurface == null) {
1050 if (w.mOrientationChanging) {
1051 if (DEBUG_ORIENTATION) {
1052 Slog.v(TAG, "Orientation change skips hidden " + w);
1053 }
1054 w.mOrientationChanging = false;
1055 }
1056 return;
1057 }
1058
1059 boolean displayed = false;
1060
1061 computeShownFrameLocked();
1062
1063 setSurfaceBoundaries(recoveringMemory);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001064
Craig Mautnerde6198e2012-04-19 09:59:31 -07001065 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
Craig Mautner0afddcb2012-05-08 15:38:00 -07001066 hide();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001067 // If we are waiting for this window to handle an
1068 // orientation change, well, it is hidden, so
1069 // doesn't really matter. Note that this does
1070 // introduce a potential glitch if the window
1071 // becomes unhidden before it has drawn for the
1072 // new orientation.
1073 if (w.mOrientationChanging) {
1074 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001075 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001076 "Orientation change skips hidden " + w);
1077 }
1078 } else if (mLastLayer != mAnimLayer
1079 || mLastAlpha != mShownAlpha
1080 || mLastDsDx != mDsDx
1081 || mLastDtDx != mDtDx
1082 || mLastDsDy != mDsDy
1083 || mLastDtDy != mDtDy
1084 || w.mLastHScale != w.mHScale
1085 || w.mLastVScale != w.mVScale
Craig Mautner749a7bb2012-04-02 13:49:53 -07001086 || mLastHidden) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001087 displayed = true;
1088 mLastAlpha = mShownAlpha;
1089 mLastLayer = mAnimLayer;
1090 mLastDsDx = mDsDx;
1091 mLastDtDx = mDtDx;
1092 mLastDsDy = mDsDy;
1093 mLastDtDy = mDtDy;
1094 w.mLastHScale = w.mHScale;
1095 w.mLastVScale = w.mVScale;
1096 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1097 "alpha=" + mShownAlpha + " layer=" + mAnimLayer
1098 + " matrix=[" + (mDsDx*w.mHScale)
1099 + "," + (mDtDx*w.mVScale)
1100 + "][" + (mDsDy*w.mHScale)
1101 + "," + (mDtDy*w.mVScale) + "]", null);
1102 if (mSurface != null) {
1103 try {
1104 mSurfaceAlpha = mShownAlpha;
1105 mSurface.setAlpha(mShownAlpha);
1106 mSurfaceLayer = w.mWinAnimator.mAnimLayer;
1107 mSurface.setLayer(w.mWinAnimator.mAnimLayer);
1108 mSurface.setMatrix(
1109 mDsDx*w.mHScale, mDtDx*w.mVScale,
1110 mDsDy*w.mHScale, mDtDy*w.mVScale);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001111
1112 if (mLastHidden && mDrawState == HAS_DRAWN) {
1113 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1114 "SHOW (performLayout)", null);
1115 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
1116 + " during relayout");
1117 if (showSurfaceRobustlyLocked()) {
1118 mLastHidden = false;
1119 } else {
1120 w.mOrientationChanging = false;
1121 }
1122 }
1123 if (mSurface != null) {
1124 w.mToken.hasVisible = true;
1125 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001126 } catch (RuntimeException e) {
1127 Slog.w(TAG, "Error updating surface in " + w, e);
1128 if (!recoveringMemory) {
1129 mService.reclaimSomeSurfaceMemoryLocked(this, "update", true);
1130 }
1131 }
1132 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001133 } else {
Craig Mautner83339b42012-05-01 22:13:23 -07001134 if (DEBUG_ANIM) {
Craig Mautnerbf08af32012-05-16 19:43:42 -07001135 // Slog.v(TAG, "prepareSurface: No changes in animation for " + mWin);
Craig Mautner83339b42012-05-01 22:13:23 -07001136 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001137 displayed = true;
1138 }
1139
1140 if (displayed) {
1141 if (w.mOrientationChanging) {
1142 if (!w.isDrawnLw()) {
Craig Mautnerd09cc4b2012-04-04 10:23:31 -07001143 mAnimator.mBulkUpdateParams |= CLEAR_ORIENTATION_CHANGE_COMPLETE;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001144 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001145 "Orientation continue waiting for draw in " + w);
1146 } else {
1147 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001148 if (DEBUG_ORIENTATION) Slog.v(TAG, "Orientation change complete in " + w);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001149 }
1150 }
1151 w.mToken.hasVisible = true;
1152 }
1153 }
1154
Craig Mautner48ba1e72012-04-02 13:18:16 -07001155 void setTransparentRegionHint(final Region region) {
Craig Mautner1f4e0cc2012-04-10 14:24:38 -07001156 if (mSurface == null) {
1157 Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true");
1158 return;
1159 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001160 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1161 ">>> OPEN TRANSACTION setTransparentRegion");
1162 Surface.openTransaction();
1163 try {
1164 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
1165 "transparentRegionHint=" + region, null);
1166 mSurface.setTransparentRegionHint(region);
1167 } finally {
1168 Surface.closeTransaction();
1169 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1170 "<<< CLOSE TRANSACTION setTransparentRegion");
1171 }
1172 }
1173
1174 void setWallpaperOffset(int left, int top) {
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001175 mSurfaceX = left;
1176 mSurfaceY = top;
1177 if (mAnimating) {
1178 // If this window (or its app token) is animating, then the position
1179 // of the surface will be re-computed on the next animation frame.
1180 // We can't poke it directly here because it depends on whatever
1181 // transformation is being applied by the animation.
1182 return;
1183 }
1184 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1185 ">>> OPEN TRANSACTION setWallpaperOffset");
Craig Mautner48ba1e72012-04-02 13:18:16 -07001186 Surface.openTransaction();
1187 try {
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001188 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
1189 "POS " + left + ", " + top, null);
1190 mSurface.setPosition(mWin.mFrame.left + left, mWin.mFrame.top + top);
1191 updateSurfaceWindowCrop(false);
Craig Mautner48ba1e72012-04-02 13:18:16 -07001192 } catch (RuntimeException e) {
1193 Slog.w(TAG, "Error positioning surface of " + mWin
1194 + " pos=(" + left + "," + top + ")", e);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001195 } finally {
1196 Surface.closeTransaction();
1197 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1198 "<<< CLOSE TRANSACTION setWallpaperOffset");
Craig Mautner48ba1e72012-04-02 13:18:16 -07001199 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001200 }
1201
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001202 // This must be called while inside a transaction.
1203 boolean performShowLocked() {
1204 if (DEBUG_VISIBILITY) {
1205 RuntimeException e = null;
1206 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
1207 e = new RuntimeException();
1208 e.fillInStackTrace();
1209 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001210 Slog.v(TAG, "performShow on " + this
Craig Mautner749a7bb2012-04-02 13:49:53 -07001211 + ": mDrawState=" + mDrawState + " readyForDisplay="
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001212 + mWin.isReadyForDisplay()
1213 + " starting=" + (mWin.mAttrs.type == TYPE_APPLICATION_STARTING), e);
1214 }
Craig Mautner749a7bb2012-04-02 13:49:53 -07001215 if (mDrawState == READY_TO_SHOW && mWin.isReadyForDisplay()) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001216 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001217 WindowManagerService.logSurface(mWin, "SHOW (performShowLocked)", null);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001218 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001219 + " during animation: policyVis=" + mWin.mPolicyVisibility
1220 + " attHidden=" + mWin.mAttachedHidden
1221 + " tok.hiddenRequested="
1222 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
1223 + " tok.hidden="
1224 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
1225 + " animating=" + mAnimating
1226 + " tok animating="
Craig Mautner59431632012-04-04 11:56:44 -07001227 + (mWin.mAppToken != null ? mWin.mAppToken.mAppAnimator.animating : false));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001228
1229 mService.enableScreenIfNeededLocked();
1230
1231 applyEnterAnimationLocked();
1232
Craig Mautnerde6198e2012-04-19 09:59:31 -07001233 // Force the show in the next prepareSurfaceLocked() call.
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001234 mLastAlpha = -1;
Craig Mautner83339b42012-05-01 22:13:23 -07001235 if (DEBUG_ANIM) Slog.v(TAG, "performShowLocked: mDrawState=HAS_DRAWN");
Craig Mautner749a7bb2012-04-02 13:49:53 -07001236 mDrawState = HAS_DRAWN;
Craig Mautnerde6198e2012-04-19 09:59:31 -07001237 mService.scheduleAnimationLocked();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001238
1239 int i = mWin.mChildWindows.size();
1240 while (i > 0) {
1241 i--;
1242 WindowState c = mWin.mChildWindows.get(i);
1243 if (c.mAttachedHidden) {
1244 c.mAttachedHidden = false;
1245 if (c.mWinAnimator.mSurface != null) {
1246 c.mWinAnimator.performShowLocked();
1247 // It hadn't been shown, which means layout not
1248 // performed on it, so now we want to make sure to
1249 // do a layout. If called from within the transaction
1250 // loop, this will cause it to restart with a new
1251 // layout.
1252 mService.mLayoutNeeded = true;
1253 }
1254 }
1255 }
1256
1257 if (mWin.mAttrs.type != TYPE_APPLICATION_STARTING
1258 && mWin.mAppToken != null) {
1259 mWin.mAppToken.firstWindowDrawn = true;
1260
1261 if (mWin.mAppToken.startingData != null) {
1262 if (WindowManagerService.DEBUG_STARTING_WINDOW ||
Craig Mautnerd87946b2012-03-29 18:00:19 -07001263 WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001264 "Finish starting " + mWin.mToken
1265 + ": first real window is shown, no animation");
1266 // If this initial window is animating, stop it -- we
1267 // will do an animation to reveal it from behind the
1268 // starting window, so there is no need for it to also
1269 // be doing its own stuff.
Craig Mautner4d7349b2012-04-20 14:52:47 -07001270 clearAnimation();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001271 mService.mFinishedStarting.add(mWin.mAppToken);
1272 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
1273 }
1274 mWin.mAppToken.updateReportedVisibilityLocked();
1275 }
1276
1277 return true;
1278 }
1279
1280 return false;
1281 }
1282
1283 /**
1284 * Have the surface flinger show a surface, robustly dealing with
1285 * error conditions. In particular, if there is not enough memory
1286 * to show the surface, then we will try to get rid of other surfaces
1287 * in order to succeed.
1288 *
1289 * @return Returns true if the surface was successfully shown.
1290 */
1291 boolean showSurfaceRobustlyLocked() {
1292 try {
1293 if (mSurface != null) {
1294 mSurfaceShown = true;
1295 mSurface.show();
1296 if (mWin.mTurnOnScreen) {
1297 if (DEBUG_VISIBILITY) Slog.v(TAG,
1298 "Show surface turning screen on: " + mWin);
1299 mWin.mTurnOnScreen = false;
Craig Mautner7d8df392012-04-06 15:26:23 -07001300 mAnimator.mBulkUpdateParams |= SET_TURN_ON_SCREEN;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001301 }
1302 }
1303 return true;
1304 } catch (RuntimeException e) {
1305 Slog.w(TAG, "Failure showing surface " + mSurface + " in " + mWin, e);
1306 }
1307
1308 mService.reclaimSomeSurfaceMemoryLocked(this, "show", true);
1309
1310 return false;
1311 }
1312
1313 void applyEnterAnimationLocked() {
1314 final int transit;
1315 if (mEnterAnimationPending) {
1316 mEnterAnimationPending = false;
1317 transit = WindowManagerPolicy.TRANSIT_ENTER;
1318 } else {
1319 transit = WindowManagerPolicy.TRANSIT_SHOW;
1320 }
1321
1322 applyAnimationLocked(transit, true);
1323 }
1324
Craig Mautner48ba1e72012-04-02 13:18:16 -07001325 // TODO(cmautner): Move back to WindowState?
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001326 /**
1327 * Choose the correct animation and set it to the passed WindowState.
1328 * @param transit If WindowManagerPolicy.TRANSIT_PREVIEW_DONE and the app window has been drawn
1329 * then the animation will be app_starting_exit. Any other value loads the animation from
1330 * the switch statement below.
1331 * @param isEntrance The animation type the last time this was called. Used to keep from
1332 * loading the same animation twice.
1333 * @return true if an animation has been loaded.
1334 */
1335 boolean applyAnimationLocked(int transit, boolean isEntrance) {
1336 if (mLocalAnimating && mAnimationIsEntrance == isEntrance) {
1337 // If we are trying to apply an animation, but already running
1338 // an animation of the same type, then just leave that one alone.
1339 return true;
1340 }
1341
1342 // Only apply an animation if the display isn't frozen. If it is
1343 // frozen, there is no reason to animate and it can cause strange
1344 // artifacts when we unfreeze the display if some different animation
1345 // is running.
1346 if (mService.okToDisplay()) {
1347 int anim = mPolicy.selectAnimationLw(mWin, transit);
1348 int attr = -1;
1349 Animation a = null;
1350 if (anim != 0) {
1351 a = AnimationUtils.loadAnimation(mContext, anim);
1352 } else {
1353 switch (transit) {
1354 case WindowManagerPolicy.TRANSIT_ENTER:
1355 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
1356 break;
1357 case WindowManagerPolicy.TRANSIT_EXIT:
1358 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
1359 break;
1360 case WindowManagerPolicy.TRANSIT_SHOW:
1361 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
1362 break;
1363 case WindowManagerPolicy.TRANSIT_HIDE:
1364 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
1365 break;
1366 }
1367 if (attr >= 0) {
1368 a = mService.loadAnimation(mWin.mAttrs, attr);
1369 }
1370 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001371 if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001372 "applyAnimation: win=" + this
1373 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
Craig Mautner4d7349b2012-04-20 14:52:47 -07001374 + " a=" + a
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001375 + " mAnimation=" + mAnimation
Craig Mautner83339b42012-05-01 22:13:23 -07001376 + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001377 if (a != null) {
1378 if (WindowManagerService.DEBUG_ANIM) {
1379 RuntimeException e = null;
1380 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
1381 e = new RuntimeException();
1382 e.fillInStackTrace();
1383 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001384 Slog.v(TAG, "Loaded animation " + a + " for " + this, e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001385 }
1386 setAnimation(a);
1387 mAnimationIsEntrance = isEntrance;
1388 }
1389 } else {
1390 clearAnimation();
1391 }
1392
1393 return mAnimation != null;
1394 }
1395
Craig Mautnera2c77052012-03-26 12:14:43 -07001396 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1397 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
1398 || mAnimation != null) {
1399 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
1400 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
1401 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
1402 pw.print(" mAnimation="); pw.println(mAnimation);
1403 }
1404 if (mHasTransformation || mHasLocalTransformation) {
1405 pw.print(prefix); pw.print("XForm: has=");
1406 pw.print(mHasTransformation);
1407 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
1408 pw.print(" "); mTransformation.printShortString(pw);
1409 pw.println();
1410 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001411 if (mSurface != null) {
1412 if (dumpAll) {
1413 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001414 pw.print(prefix); pw.print("mDrawState="); pw.print(mDrawState);
1415 pw.print(" mLastHidden="); pw.println(mLastHidden);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001416 }
1417 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
1418 pw.print(" layer="); pw.print(mSurfaceLayer);
1419 pw.print(" alpha="); pw.print(mSurfaceAlpha);
1420 pw.print(" rect=("); pw.print(mSurfaceX);
1421 pw.print(","); pw.print(mSurfaceY);
1422 pw.print(") "); pw.print(mSurfaceW);
1423 pw.print(" x "); pw.println(mSurfaceH);
1424 }
1425 if (mPendingDestroySurface != null) {
1426 pw.print(prefix); pw.print("mPendingDestroySurface=");
1427 pw.println(mPendingDestroySurface);
1428 }
1429 if (mSurfaceResized || mSurfaceDestroyDeferred) {
1430 pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized);
1431 pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred);
1432 }
1433 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
1434 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
1435 pw.print(" mAlpha="); pw.print(mAlpha);
1436 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
1437 }
1438 if (mHaveMatrix || mWin.mGlobalScale != 1) {
1439 pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale);
1440 pw.print(" mDsDx="); pw.print(mDsDx);
1441 pw.print(" mDtDx="); pw.print(mDtDx);
1442 pw.print(" mDsDy="); pw.print(mDsDy);
1443 pw.print(" mDtDy="); pw.println(mDtDy);
1444 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001445 }
1446
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001447 @Override
1448 public String toString() {
1449 StringBuffer sb = new StringBuffer("WindowStateAnimator (");
1450 sb.append(mWin.mLastTitle + "): ");
1451 sb.append("mSurface " + mSurface);
1452 sb.append(", mAnimation " + mAnimation);
1453 return sb.toString();
1454 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001455}