blob: 485f4a773c7a8d1639707e34316ce18629ae4082 [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();
Craig Mautnerad5725d2012-06-05 10:20:56 -0700384 mAnimator.mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Craig Mautner0afddcb2012-05-08 15:38:00 -0700385 }
386 }
387
388 void hide() {
389 if (!mLastHidden) {
390 //dump();
391 mLastHidden = true;
392 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
393 "HIDE (performLayout)", null);
394 if (mSurface != null) {
395 mSurfaceShown = false;
396 try {
397 mSurface.hide();
398 } catch (RuntimeException e) {
399 Slog.w(TAG, "Exception hiding surface in " + mWin);
400 }
401 }
402 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700403 }
404
Craig Mautnera608b882012-03-30 13:03:49 -0700405 boolean finishDrawingLocked() {
Craig Mautner749a7bb2012-04-02 13:49:53 -0700406 if (mDrawState == DRAW_PENDING) {
Craig Mautneref25d7a2012-05-15 23:01:47 -0700407 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
408 Slog.v(TAG, "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING " + this + " in "
Craig Mautner83339b42012-05-01 22:13:23 -0700409 + mSurface);
Craig Mautner749a7bb2012-04-02 13:49:53 -0700410 mDrawState = COMMIT_DRAW_PENDING;
Craig Mautnera608b882012-03-30 13:03:49 -0700411 return true;
412 }
413 return false;
414 }
415
416 // This must be called while inside a transaction.
417 boolean commitFinishDrawingLocked(long currentTime) {
Craig Mautner749a7bb2012-04-02 13:49:53 -0700418 if (mDrawState != COMMIT_DRAW_PENDING) {
Craig Mautnera608b882012-03-30 13:03:49 -0700419 return false;
420 }
Craig Mautneref25d7a2012-05-15 23:01:47 -0700421 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM)
Craig Mautner83339b42012-05-01 22:13:23 -0700422 Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurface);
Craig Mautner749a7bb2012-04-02 13:49:53 -0700423 mDrawState = READY_TO_SHOW;
Craig Mautnera608b882012-03-30 13:03:49 -0700424 final boolean starting = mWin.mAttrs.type == TYPE_APPLICATION_STARTING;
425 final AppWindowToken atoken = mWin.mAppToken;
426 if (atoken == null || atoken.allDrawn || starting) {
427 performShowLocked();
428 }
429 return true;
430 }
431
Craig Mautner7d8df392012-04-06 15:26:23 -0700432 static class SurfaceTrace extends Surface {
433 private final static String SURFACE_TAG = "SurfaceTrace";
434 final static ArrayList<SurfaceTrace> sSurfaces = new ArrayList<SurfaceTrace>();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700435
Craig Mautner7d8df392012-04-06 15:26:23 -0700436 private float mSurfaceTraceAlpha = 0;
Craig Mautner7358fbf2012-04-12 21:06:33 -0700437 private int mLayer;
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700438 private final PointF mPosition = new PointF();
439 private final Point mSize = new Point();
440 private final Rect mWindowCrop = new Rect();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700441 private boolean mShown = false;
442 private String mName = "Not named";
443
Craig Mautner7d8df392012-04-06 15:26:23 -0700444 public SurfaceTrace(SurfaceSession s,
Craig Mautner7358fbf2012-04-12 21:06:33 -0700445 int pid, int display, int w, int h, int format, int flags) throws
446 OutOfResourcesException {
447 super(s, pid, display, w, h, format, flags);
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700448 mSize.set(w, h);
Craig Mautner7d8df392012-04-06 15:26:23 -0700449 Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700450 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700451 }
452
Craig Mautner7d8df392012-04-06 15:26:23 -0700453 public SurfaceTrace(SurfaceSession s,
Craig Mautner7358fbf2012-04-12 21:06:33 -0700454 int pid, String name, int display, int w, int h, int format, int flags)
455 throws OutOfResourcesException {
456 super(s, pid, name, display, w, h, format, flags);
457 mName = name;
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700458 mSize.set(w, h);
Craig Mautner7d8df392012-04-06 15:26:23 -0700459 Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700460 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700461 }
462
463 @Override
464 public void setAlpha(float alpha) {
465 super.setAlpha(alpha);
Craig Mautner7d8df392012-04-06 15:26:23 -0700466 mSurfaceTraceAlpha = alpha;
467 Slog.v(SURFACE_TAG, "setAlpha: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700468 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700469 }
470
471 @Override
472 public void setLayer(int zorder) {
473 super.setLayer(zorder);
474 mLayer = zorder;
Craig Mautner7d8df392012-04-06 15:26:23 -0700475 Slog.v(SURFACE_TAG, "setLayer: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700476 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700477
478 sSurfaces.remove(this);
479 int i;
480 for (i = sSurfaces.size() - 1; i >= 0; i--) {
Craig Mautner7d8df392012-04-06 15:26:23 -0700481 SurfaceTrace s = sSurfaces.get(i);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700482 if (s.mLayer < zorder) {
483 break;
484 }
485 }
486 sSurfaces.add(i + 1, this);
487 }
488
489 @Override
490 public void setPosition(float x, float y) {
491 super.setPosition(x, y);
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700492 mPosition.set(x, y);
Craig Mautner7d8df392012-04-06 15:26:23 -0700493 Slog.v(SURFACE_TAG, "setPosition: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700494 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700495 }
496
497 @Override
498 public void setSize(int w, int h) {
499 super.setSize(w, h);
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700500 mSize.set(w, h);
Craig Mautner7d8df392012-04-06 15:26:23 -0700501 Slog.v(SURFACE_TAG, "setSize: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700502 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700503 }
504
505 @Override
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700506 public void setWindowCrop(Rect crop) {
507 super.setWindowCrop(crop);
Craig Mautneref25d7a2012-05-15 23:01:47 -0700508 if (crop != null) {
509 mWindowCrop.set(crop);
510 }
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700511 Slog.v(SURFACE_TAG, "setWindowCrop: " + this + ". Called by "
512 + Debug.getCallers(3));
513 }
514
515 @Override
Craig Mautner7358fbf2012-04-12 21:06:33 -0700516 public void hide() {
517 super.hide();
518 mShown = false;
Craig Mautner7d8df392012-04-06 15:26:23 -0700519 Slog.v(SURFACE_TAG, "hide: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700520 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700521 }
522 @Override
523 public void show() {
524 super.show();
525 mShown = true;
Craig Mautner7d8df392012-04-06 15:26:23 -0700526 Slog.v(SURFACE_TAG, "show: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700527 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700528 }
529
530 @Override
531 public void destroy() {
532 super.destroy();
Craig Mautner7d8df392012-04-06 15:26:23 -0700533 Slog.v(SURFACE_TAG, "destroy: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700534 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700535 sSurfaces.remove(this);
536 }
537
Craig Mautneracaf9cc2012-04-17 11:45:25 -0700538 @Override
539 public void release() {
540 super.release();
541 Slog.v(SURFACE_TAG, "release: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700542 + Debug.getCallers(3));
Craig Mautneracaf9cc2012-04-17 11:45:25 -0700543 sSurfaces.remove(this);
544 }
545
Craig Mautner7358fbf2012-04-12 21:06:33 -0700546 static void dumpAllSurfaces() {
547 final int N = sSurfaces.size();
548 for (int i = 0; i < N; i++) {
549 Slog.i(TAG, "SurfaceDump: " + sSurfaces.get(i));
550 }
551 }
552
553 @Override
554 public String toString() {
Craig Mautnerfbf378c2012-04-23 17:24:21 -0700555 return "Surface " + Integer.toHexString(System.identityHashCode(this)) + " "
556 + mName + ": shown=" + mShown + " layer=" + mLayer
Craig Mautner7d8df392012-04-06 15:26:23 -0700557 + " alpha=" + mSurfaceTraceAlpha + " " + mPosition.x + "," + mPosition.y
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700558 + " " + mSize.x + "x" + mSize.y
559 + " crop=" + mWindowCrop.toShortString();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700560 }
561 }
562
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700563 Surface createSurfaceLocked() {
564 if (mSurface == null) {
Craig Mautner83339b42012-05-01 22:13:23 -0700565 if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG,
566 "createSurface " + this + ": mDrawState=DRAW_PENDING");
Craig Mautner749a7bb2012-04-02 13:49:53 -0700567 mDrawState = DRAW_PENDING;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700568 if (mWin.mAppToken != null) {
569 mWin.mAppToken.allDrawn = false;
570 }
571
572 mService.makeWindowFreezingScreenIfNeededLocked(mWin);
573
574 int flags = 0;
575 final WindowManager.LayoutParams attrs = mWin.mAttrs;
576
577 if ((attrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
578 flags |= Surface.SECURE;
579 }
580 if (WindowState.DEBUG_VISIBILITY) Slog.v(
581 TAG, "Creating surface in session "
582 + mSession.mSurfaceSession + " window " + this
583 + " w=" + mWin.mCompatFrame.width()
584 + " h=" + mWin.mCompatFrame.height() + " format="
585 + attrs.format + " flags=" + flags);
586
587 int w = mWin.mCompatFrame.width();
588 int h = mWin.mCompatFrame.height();
589 if ((attrs.flags & LayoutParams.FLAG_SCALED) != 0) {
590 // for a scaled surface, we always want the requested
591 // size.
592 w = mWin.mRequestedWidth;
593 h = mWin.mRequestedHeight;
594 }
595
596 // Something is wrong and SurfaceFlinger will not like this,
597 // try to revert to sane values
598 if (w <= 0) w = 1;
599 if (h <= 0) h = 1;
600
601 mSurfaceShown = false;
602 mSurfaceLayer = 0;
Craig Mautner7d8df392012-04-06 15:26:23 -0700603 mSurfaceAlpha = 0;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700604 mSurfaceX = 0;
605 mSurfaceY = 0;
606 mSurfaceW = w;
607 mSurfaceH = h;
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700608 mWin.mLastSystemDecorRect.set(0, 0, 0, 0);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700609 try {
610 final boolean isHwAccelerated = (attrs.flags &
611 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
612 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
613 if (!PixelFormat.formatHasAlpha(attrs.format)) {
614 flags |= Surface.OPAQUE;
615 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700616 if (DEBUG_SURFACE_TRACE) {
Craig Mautner7d8df392012-04-06 15:26:23 -0700617 mSurface = new SurfaceTrace(
Craig Mautner7358fbf2012-04-12 21:06:33 -0700618 mSession.mSurfaceSession, mSession.mPid,
619 attrs.getTitle().toString(),
620 0, w, h, format, flags);
621 } else {
622 mSurface = new Surface(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700623 mSession.mSurfaceSession, mSession.mPid,
624 attrs.getTitle().toString(),
625 0, w, h, format, flags);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700626 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700627 mWin.mHasSurface = true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700628 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG,
629 " CREATE SURFACE "
630 + mSurface + " IN SESSION "
631 + mSession.mSurfaceSession
632 + ": pid=" + mSession.mPid + " format="
633 + attrs.format + " flags=0x"
634 + Integer.toHexString(flags)
635 + " / " + this);
636 } catch (Surface.OutOfResourcesException e) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700637 mWin.mHasSurface = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700638 Slog.w(TAG, "OutOfResourcesException creating surface");
639 mService.reclaimSomeSurfaceMemoryLocked(this, "create", true);
Craig Mautner749a7bb2012-04-02 13:49:53 -0700640 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700641 return null;
642 } catch (Exception e) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700643 mWin.mHasSurface = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700644 Slog.e(TAG, "Exception creating surface", e);
Craig Mautner749a7bb2012-04-02 13:49:53 -0700645 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700646 return null;
647 }
648
649 if (WindowManagerService.localLOGV) Slog.v(
650 TAG, "Got surface: " + mSurface
651 + ", set left=" + mWin.mFrame.left + " top=" + mWin.mFrame.top
652 + ", animLayer=" + mAnimLayer);
653 if (SHOW_LIGHT_TRANSACTIONS) {
654 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
655 WindowManagerService.logSurface(mWin, "CREATE pos=("
656 + mWin.mFrame.left + "," + mWin.mFrame.top + ") ("
657 + mWin.mCompatFrame.width() + "x" + mWin.mCompatFrame.height()
658 + "), layer=" + mAnimLayer + " HIDE", null);
659 }
660 Surface.openTransaction();
661 try {
662 try {
663 mSurfaceX = mWin.mFrame.left + mWin.mXOffset;
664 mSurfaceY = mWin.mFrame.top + mWin.mYOffset;
665 mSurface.setPosition(mSurfaceX, mSurfaceY);
666 mSurfaceLayer = mAnimLayer;
667 mSurface.setLayer(mAnimLayer);
Craig Mautner7d8df392012-04-06 15:26:23 -0700668 mSurface.setAlpha(0);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700669 mSurfaceShown = false;
670 mSurface.hide();
671 if ((mWin.mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
672 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, "DITHER", null);
673 mSurface.setFlags(Surface.SURFACE_DITHER, Surface.SURFACE_DITHER);
674 }
675 } catch (RuntimeException e) {
676 Slog.w(TAG, "Error creating surface in " + w, e);
677 mService.reclaimSomeSurfaceMemoryLocked(this, "create-init", true);
678 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700679 mLastHidden = true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700680 } finally {
681 Surface.closeTransaction();
682 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
683 "<<< CLOSE TRANSACTION createSurfaceLocked");
684 }
685 if (WindowManagerService.localLOGV) Slog.v(
686 TAG, "Created surface " + this);
687 }
688 return mSurface;
689 }
690
691 void destroySurfaceLocked() {
692 if (mWin.mAppToken != null && mWin == mWin.mAppToken.startingWindow) {
693 mWin.mAppToken.startingDisplayed = false;
694 }
695
696 if (mSurface != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700697
698 int i = mWin.mChildWindows.size();
699 while (i > 0) {
700 i--;
701 WindowState c = mWin.mChildWindows.get(i);
702 c.mAttachedHidden = true;
703 }
704
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700705 try {
706 if (DEBUG_VISIBILITY) {
707 RuntimeException e = null;
708 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
709 e = new RuntimeException();
710 e.fillInStackTrace();
711 }
712 Slog.w(TAG, "Window " + this + " destroying surface "
713 + mSurface + ", session " + mSession, e);
714 }
715 if (mSurfaceDestroyDeferred) {
716 if (mSurface != null && mPendingDestroySurface != mSurface) {
717 if (mPendingDestroySurface != null) {
718 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
719 RuntimeException e = null;
720 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
721 e = new RuntimeException();
722 e.fillInStackTrace();
723 }
724 WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
725 }
726 mPendingDestroySurface.destroy();
727 }
728 mPendingDestroySurface = mSurface;
729 }
730 } else {
731 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
732 RuntimeException e = null;
733 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
734 e = new RuntimeException();
735 e.fillInStackTrace();
736 }
737 WindowManagerService.logSurface(mWin, "DESTROY", e);
738 }
739 mSurface.destroy();
740 }
741 } catch (RuntimeException e) {
742 Slog.w(TAG, "Exception thrown when destroying Window " + this
743 + " surface " + mSurface + " session " + mSession
744 + ": " + e.toString());
745 }
746
747 mSurfaceShown = false;
748 mSurface = null;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700749 mWin.mHasSurface =false;
Craig Mautnerbf08af32012-05-16 19:43:42 -0700750 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700751 }
752 }
753
754 void destroyDeferredSurfaceLocked() {
755 try {
756 if (mPendingDestroySurface != null) {
757 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
758 RuntimeException e = null;
759 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
760 e = new RuntimeException();
761 e.fillInStackTrace();
762 }
763 WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
764 }
765 mPendingDestroySurface.destroy();
766 }
767 } catch (RuntimeException e) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700768 Slog.w(TAG, "Exception thrown when destroying Window "
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700769 + this + " surface " + mPendingDestroySurface
770 + " session " + mSession + ": " + e.toString());
771 }
772 mSurfaceDestroyDeferred = false;
773 mPendingDestroySurface = null;
774 }
775
776 void computeShownFrameLocked() {
777 final boolean selfTransformation = mHasLocalTransformation;
778 Transformation attachedTransformation =
779 (mAttachedWindow != null && mAttachedWindow.mWinAnimator.mHasLocalTransformation)
780 ? mAttachedWindow.mWinAnimator.mTransformation : null;
Craig Mautner59431632012-04-04 11:56:44 -0700781 final AppWindowAnimator appAnimator =
782 mWin.mAppToken == null ? null : mWin.mAppToken.mAppAnimator;
783 Transformation appTransformation = (appAnimator != null && appAnimator.hasTransformation)
784 ? appAnimator.transformation : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700785
786 // Wallpapers are animated based on the "real" window they
787 // are currently targeting.
788 if (mWin.mAttrs.type == TYPE_WALLPAPER && mService.mLowerWallpaperTarget == null
789 && mService.mWallpaperTarget != null) {
790 if (mService.mWallpaperTarget.mWinAnimator.mHasLocalTransformation &&
791 mService.mWallpaperTarget.mWinAnimator.mAnimation != null &&
792 !mService.mWallpaperTarget.mWinAnimator.mAnimation.getDetachWallpaper()) {
793 attachedTransformation = mService.mWallpaperTarget.mWinAnimator.mTransformation;
794 if (WindowManagerService.DEBUG_WALLPAPER && attachedTransformation != null) {
795 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
796 }
797 }
Craig Mautner59431632012-04-04 11:56:44 -0700798 final AppWindowAnimator wpAppAnimator = mService.mWallpaperTarget.mAppToken == null
799 ? null : mService.mWallpaperTarget.mAppToken.mAppAnimator;
800 if (wpAppAnimator != null &&
801 wpAppAnimator.hasTransformation &&
802 wpAppAnimator.animation != null &&
803 !wpAppAnimator.animation.getDetachWallpaper()) {
804 appTransformation = wpAppAnimator.transformation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700805 if (WindowManagerService.DEBUG_WALLPAPER && appTransformation != null) {
806 Slog.v(TAG, "WP target app xform: " + appTransformation);
807 }
808 }
809 }
810
811 final boolean screenAnimation = mService.mAnimator.mScreenRotationAnimation != null
812 && mService.mAnimator.mScreenRotationAnimation.isAnimating();
813 if (selfTransformation || attachedTransformation != null
814 || appTransformation != null || screenAnimation) {
815 // cache often used attributes locally
816 final Rect frame = mWin.mFrame;
817 final float tmpFloats[] = mService.mTmpFloats;
818 final Matrix tmpMatrix = mWin.mTmpMatrix;
819
820 // Compute the desired transformation.
821 if (screenAnimation) {
822 // If we are doing a screen animation, the global rotation
823 // applied to windows can result in windows that are carefully
824 // aligned with each other to slightly separate, allowing you
825 // to see what is behind them. An unsightly mess. This...
826 // thing... magically makes it call good: scale each window
827 // slightly (two pixels larger in each dimension, from the
828 // window's center).
829 final float w = frame.width();
830 final float h = frame.height();
831 if (w>=1 && h>=1) {
832 tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2);
833 } else {
834 tmpMatrix.reset();
835 }
836 } else {
837 tmpMatrix.reset();
838 }
839 tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale);
840 if (selfTransformation) {
841 tmpMatrix.postConcat(mTransformation.getMatrix());
842 }
843 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
844 if (attachedTransformation != null) {
845 tmpMatrix.postConcat(attachedTransformation.getMatrix());
846 }
847 if (appTransformation != null) {
848 tmpMatrix.postConcat(appTransformation.getMatrix());
849 }
850 if (screenAnimation) {
851 tmpMatrix.postConcat(
852 mService.mAnimator.mScreenRotationAnimation.getEnterTransformation().getMatrix());
853 }
854
855 // "convert" it into SurfaceFlinger's format
856 // (a 2x2 matrix + an offset)
857 // Here we must not transform the position of the surface
858 // since it is already included in the transformation.
859 //Slog.i(TAG, "Transform: " + matrix);
860
861 mHaveMatrix = true;
862 tmpMatrix.getValues(tmpFloats);
863 mDsDx = tmpFloats[Matrix.MSCALE_X];
864 mDtDx = tmpFloats[Matrix.MSKEW_Y];
865 mDsDy = tmpFloats[Matrix.MSKEW_X];
866 mDtDy = tmpFloats[Matrix.MSCALE_Y];
867 float x = tmpFloats[Matrix.MTRANS_X];
868 float y = tmpFloats[Matrix.MTRANS_Y];
869 int w = frame.width();
870 int h = frame.height();
871 mWin.mShownFrame.set(x, y, x+w, y+h);
872
873 // Now set the alpha... but because our current hardware
874 // can't do alpha transformation on a non-opaque surface,
875 // turn it off if we are running an animation that is also
876 // transforming since it is more important to have that
877 // animation be smooth.
878 mShownAlpha = mAlpha;
879 if (!mService.mLimitedAlphaCompositing
880 || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format)
881 || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
882 && x == frame.left && y == frame.top))) {
883 //Slog.i(TAG, "Applying alpha transform");
884 if (selfTransformation) {
885 mShownAlpha *= mTransformation.getAlpha();
886 }
887 if (attachedTransformation != null) {
888 mShownAlpha *= attachedTransformation.getAlpha();
889 }
890 if (appTransformation != null) {
891 mShownAlpha *= appTransformation.getAlpha();
892 }
893 if (screenAnimation) {
894 mShownAlpha *=
895 mService.mAnimator.mScreenRotationAnimation.getEnterTransformation().getAlpha();
896 }
897 } else {
898 //Slog.i(TAG, "Not applying alpha transform");
899 }
900
901 if (WindowManagerService.localLOGV) Slog.v(
902 TAG, "computeShownFrameLocked: Animating " + this +
903 ": " + mWin.mShownFrame +
904 ", alpha=" + mTransformation.getAlpha() + ", mShownAlpha=" + mShownAlpha);
905 return;
Craig Mautner4d7349b2012-04-20 14:52:47 -0700906 } else if (mWin.mIsWallpaper &&
907 (mAnimator.mPendingActions & WindowAnimator.WALLPAPER_ACTION_PENDING) != 0) {
908 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700909 }
910
911 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautner4d7349b2012-04-20 14:52:47 -0700912 TAG, "computeShownFrameLocked: " + this +
913 " not attached, mAlpha=" + mAlpha);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700914 mWin.mShownFrame.set(mWin.mFrame);
915 if (mWin.mXOffset != 0 || mWin.mYOffset != 0) {
916 mWin.mShownFrame.offset(mWin.mXOffset, mWin.mYOffset);
917 }
918 mShownAlpha = mAlpha;
919 mHaveMatrix = false;
920 mDsDx = mWin.mGlobalScale;
921 mDtDx = 0;
922 mDsDy = 0;
923 mDtDy = mWin.mGlobalScale;
924 }
Craig Mautnerd87946b2012-03-29 18:00:19 -0700925
Dianne Hackborn3e52fc22012-05-15 17:58:02 -0700926 void updateSurfaceWindowCrop(final boolean recoveringMemory) {
927 final WindowState w = mWin;
928
929 // Need to recompute a new system decor rect each time.
930 if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
931 // Currently can't do this cropping for scaled windows. We'll
932 // just keep the crop rect the same as the source surface.
933 w.mSystemDecorRect.set(0, 0, w.mRequestedWidth, w.mRequestedHeight);
934 } else if (w.mLayer >= mService.mSystemDecorLayer) {
935 // Above the decor layer is easy, just use the entire window.
936 w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(),
937 w.mCompatFrame.height());
938 } else {
939 final Rect decorRect = mService.mSystemDecorRect;
940 // Compute the offset of the window in relation to the decor rect.
941 final int offX = w.mXOffset + w.mFrame.left;
942 final int offY = w.mYOffset + w.mFrame.top;
943 // Initialize the decor rect to the entire frame.
944 w.mSystemDecorRect.set(0, 0, w.mFrame.width(), w.mFrame.height());
945 // Intersect with the decor rect, offsetted by window position.
946 w.mSystemDecorRect.intersect(decorRect.left-offX, decorRect.top-offY,
947 decorRect.right-offX, decorRect.bottom-offY);
948 // If size compatibility is being applied to the window, the
949 // surface is scaled relative to the screen. Also apply this
950 // scaling to the crop rect. We aren't using the standard rect
951 // scale function because we want to round things to make the crop
952 // always round to a larger rect to ensure we don't crop too
953 // much and hide part of the window that should be seen.
954 if (w.mEnforceSizeCompat && w.mInvGlobalScale != 1.0f) {
955 final float scale = w.mInvGlobalScale;
956 w.mSystemDecorRect.left = (int) (w.mSystemDecorRect.left * scale - 0.5f);
957 w.mSystemDecorRect.top = (int) (w.mSystemDecorRect.top * scale - 0.5f);
958 w.mSystemDecorRect.right = (int) ((w.mSystemDecorRect.right+1) * scale - 0.5f);
959 w.mSystemDecorRect.bottom = (int) ((w.mSystemDecorRect.bottom+1) * scale - 0.5f);
960 }
961 }
962
963 if (!w.mSystemDecorRect.equals(w.mLastSystemDecorRect)) {
964 w.mLastSystemDecorRect.set(w.mSystemDecorRect);
965 try {
966 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
967 "CROP " + w.mSystemDecorRect.toShortString(), null);
968 mSurface.setWindowCrop(w.mSystemDecorRect);
969 } catch (RuntimeException e) {
970 Slog.w(TAG, "Error setting crop surface of " + w
971 + " crop=" + w.mSystemDecorRect.toShortString(), e);
972 if (!recoveringMemory) {
973 mService.reclaimSomeSurfaceMemoryLocked(this, "crop", true);
974 }
975 }
976 }
977 }
978
Craig Mautneracaf9cc2012-04-17 11:45:25 -0700979 void setSurfaceBoundaries(final boolean recoveringMemory) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700980 final WindowState w = mWin;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700981 int width, height;
982 if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
983 // for a scaled surface, we just want to use
984 // the requested size.
985 width = w.mRequestedWidth;
986 height = w.mRequestedHeight;
987 } else {
988 width = w.mCompatFrame.width();
989 height = w.mCompatFrame.height();
990 }
991
992 if (width < 1) {
993 width = 1;
994 }
995 if (height < 1) {
996 height = 1;
997 }
998 final boolean surfaceResized = mSurfaceW != width || mSurfaceH != height;
999 if (surfaceResized) {
1000 mSurfaceW = width;
1001 mSurfaceH = height;
1002 }
1003
Craig Mautner4d7349b2012-04-20 14:52:47 -07001004 final float left = w.mShownFrame.left;
1005 final float top = w.mShownFrame.top;
1006 if (mSurfaceX != left || mSurfaceY != top) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001007 try {
1008 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
Craig Mautner4d7349b2012-04-20 14:52:47 -07001009 "POS " + left + ", " + top, null);
1010 mSurfaceX = left;
1011 mSurfaceY = top;
1012 mSurface.setPosition(left, top);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001013 } catch (RuntimeException e) {
1014 Slog.w(TAG, "Error positioning surface of " + w
Craig Mautner4d7349b2012-04-20 14:52:47 -07001015 + " pos=(" + left
1016 + "," + top + ")", e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001017 if (!recoveringMemory) {
1018 mService.reclaimSomeSurfaceMemoryLocked(this, "position", true);
1019 }
1020 }
1021 }
1022
1023 if (surfaceResized) {
1024 try {
1025 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1026 "SIZE " + width + "x" + height, null);
1027 mSurfaceResized = true;
1028 mSurface.setSize(width, height);
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001029 mAnimator.mPendingLayoutChanges |=
1030 WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Craig Mautner3a67f352012-05-07 11:21:33 -07001031 if ((w.mAttrs.flags & LayoutParams.FLAG_DIM_BEHIND) != 0) {
1032 mAnimator.startDimming(this, w.mExiting ? 0 : w.mAttrs.dimAmount,
1033 mService.mAppDisplayWidth, mService.mAppDisplayHeight);
1034 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001035 } catch (RuntimeException e) {
1036 // If something goes wrong with the surface (such
1037 // as running out of memory), don't take down the
1038 // entire system.
1039 Slog.e(TAG, "Error resizing surface of " + w
1040 + " size=(" + width + "x" + height + ")", e);
1041 if (!recoveringMemory) {
1042 mService.reclaimSomeSurfaceMemoryLocked(this, "size", true);
1043 }
1044 }
1045 }
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001046
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001047 updateSurfaceWindowCrop(recoveringMemory);
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001048 }
1049
1050 public void prepareSurfaceLocked(final boolean recoveringMemory) {
1051 final WindowState w = mWin;
1052 if (mSurface == null) {
1053 if (w.mOrientationChanging) {
1054 if (DEBUG_ORIENTATION) {
1055 Slog.v(TAG, "Orientation change skips hidden " + w);
1056 }
1057 w.mOrientationChanging = false;
1058 }
1059 return;
1060 }
1061
1062 boolean displayed = false;
1063
1064 computeShownFrameLocked();
1065
1066 setSurfaceBoundaries(recoveringMemory);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001067
Craig Mautnerde6198e2012-04-19 09:59:31 -07001068 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
Craig Mautner0afddcb2012-05-08 15:38:00 -07001069 hide();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001070 // If we are waiting for this window to handle an
1071 // orientation change, well, it is hidden, so
1072 // doesn't really matter. Note that this does
1073 // introduce a potential glitch if the window
1074 // becomes unhidden before it has drawn for the
1075 // new orientation.
1076 if (w.mOrientationChanging) {
1077 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001078 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001079 "Orientation change skips hidden " + w);
1080 }
1081 } else if (mLastLayer != mAnimLayer
1082 || mLastAlpha != mShownAlpha
1083 || mLastDsDx != mDsDx
1084 || mLastDtDx != mDtDx
1085 || mLastDsDy != mDsDy
1086 || mLastDtDy != mDtDy
1087 || w.mLastHScale != w.mHScale
1088 || w.mLastVScale != w.mVScale
Craig Mautner749a7bb2012-04-02 13:49:53 -07001089 || mLastHidden) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001090 displayed = true;
1091 mLastAlpha = mShownAlpha;
1092 mLastLayer = mAnimLayer;
1093 mLastDsDx = mDsDx;
1094 mLastDtDx = mDtDx;
1095 mLastDsDy = mDsDy;
1096 mLastDtDy = mDtDy;
1097 w.mLastHScale = w.mHScale;
1098 w.mLastVScale = w.mVScale;
1099 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1100 "alpha=" + mShownAlpha + " layer=" + mAnimLayer
1101 + " matrix=[" + (mDsDx*w.mHScale)
1102 + "," + (mDtDx*w.mVScale)
1103 + "][" + (mDsDy*w.mHScale)
1104 + "," + (mDtDy*w.mVScale) + "]", null);
1105 if (mSurface != null) {
1106 try {
1107 mSurfaceAlpha = mShownAlpha;
1108 mSurface.setAlpha(mShownAlpha);
Craig Mautnerad5725d2012-06-05 10:20:56 -07001109 mSurfaceLayer = mAnimLayer;
1110 mSurface.setLayer(mAnimLayer);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001111 mSurface.setMatrix(
1112 mDsDx*w.mHScale, mDtDx*w.mVScale,
1113 mDsDy*w.mHScale, mDtDy*w.mVScale);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001114
1115 if (mLastHidden && mDrawState == HAS_DRAWN) {
1116 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1117 "SHOW (performLayout)", null);
1118 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
1119 + " during relayout");
1120 if (showSurfaceRobustlyLocked()) {
1121 mLastHidden = false;
1122 } else {
1123 w.mOrientationChanging = false;
1124 }
1125 }
1126 if (mSurface != null) {
1127 w.mToken.hasVisible = true;
1128 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001129 } catch (RuntimeException e) {
1130 Slog.w(TAG, "Error updating surface in " + w, e);
1131 if (!recoveringMemory) {
1132 mService.reclaimSomeSurfaceMemoryLocked(this, "update", true);
1133 }
1134 }
1135 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001136 } else {
Craig Mautner83339b42012-05-01 22:13:23 -07001137 if (DEBUG_ANIM) {
Craig Mautnerbf08af32012-05-16 19:43:42 -07001138 // Slog.v(TAG, "prepareSurface: No changes in animation for " + mWin);
Craig Mautner83339b42012-05-01 22:13:23 -07001139 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001140 displayed = true;
1141 }
1142
1143 if (displayed) {
1144 if (w.mOrientationChanging) {
1145 if (!w.isDrawnLw()) {
Craig Mautnerd09cc4b2012-04-04 10:23:31 -07001146 mAnimator.mBulkUpdateParams |= CLEAR_ORIENTATION_CHANGE_COMPLETE;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001147 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001148 "Orientation continue waiting for draw in " + w);
1149 } else {
1150 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001151 if (DEBUG_ORIENTATION) Slog.v(TAG, "Orientation change complete in " + w);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001152 }
1153 }
1154 w.mToken.hasVisible = true;
1155 }
1156 }
1157
Craig Mautner48ba1e72012-04-02 13:18:16 -07001158 void setTransparentRegionHint(final Region region) {
Craig Mautner1f4e0cc2012-04-10 14:24:38 -07001159 if (mSurface == null) {
1160 Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true");
1161 return;
1162 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001163 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1164 ">>> OPEN TRANSACTION setTransparentRegion");
1165 Surface.openTransaction();
1166 try {
1167 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
1168 "transparentRegionHint=" + region, null);
1169 mSurface.setTransparentRegionHint(region);
1170 } finally {
1171 Surface.closeTransaction();
1172 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1173 "<<< CLOSE TRANSACTION setTransparentRegion");
1174 }
1175 }
1176
1177 void setWallpaperOffset(int left, int top) {
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001178 mSurfaceX = left;
1179 mSurfaceY = top;
1180 if (mAnimating) {
1181 // If this window (or its app token) is animating, then the position
1182 // of the surface will be re-computed on the next animation frame.
1183 // We can't poke it directly here because it depends on whatever
1184 // transformation is being applied by the animation.
1185 return;
1186 }
1187 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1188 ">>> OPEN TRANSACTION setWallpaperOffset");
Craig Mautner48ba1e72012-04-02 13:18:16 -07001189 Surface.openTransaction();
1190 try {
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001191 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
1192 "POS " + left + ", " + top, null);
1193 mSurface.setPosition(mWin.mFrame.left + left, mWin.mFrame.top + top);
1194 updateSurfaceWindowCrop(false);
Craig Mautner48ba1e72012-04-02 13:18:16 -07001195 } catch (RuntimeException e) {
1196 Slog.w(TAG, "Error positioning surface of " + mWin
1197 + " pos=(" + left + "," + top + ")", e);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001198 } finally {
1199 Surface.closeTransaction();
1200 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1201 "<<< CLOSE TRANSACTION setWallpaperOffset");
Craig Mautner48ba1e72012-04-02 13:18:16 -07001202 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001203 }
1204
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001205 // This must be called while inside a transaction.
1206 boolean performShowLocked() {
1207 if (DEBUG_VISIBILITY) {
1208 RuntimeException e = null;
1209 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
1210 e = new RuntimeException();
1211 e.fillInStackTrace();
1212 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001213 Slog.v(TAG, "performShow on " + this
Craig Mautner749a7bb2012-04-02 13:49:53 -07001214 + ": mDrawState=" + mDrawState + " readyForDisplay="
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001215 + mWin.isReadyForDisplay()
1216 + " starting=" + (mWin.mAttrs.type == TYPE_APPLICATION_STARTING), e);
1217 }
Craig Mautner749a7bb2012-04-02 13:49:53 -07001218 if (mDrawState == READY_TO_SHOW && mWin.isReadyForDisplay()) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001219 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001220 WindowManagerService.logSurface(mWin, "SHOW (performShowLocked)", null);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001221 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001222 + " during animation: policyVis=" + mWin.mPolicyVisibility
1223 + " attHidden=" + mWin.mAttachedHidden
1224 + " tok.hiddenRequested="
1225 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
1226 + " tok.hidden="
1227 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
1228 + " animating=" + mAnimating
1229 + " tok animating="
Craig Mautner59431632012-04-04 11:56:44 -07001230 + (mWin.mAppToken != null ? mWin.mAppToken.mAppAnimator.animating : false));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001231
1232 mService.enableScreenIfNeededLocked();
1233
1234 applyEnterAnimationLocked();
1235
Craig Mautnerde6198e2012-04-19 09:59:31 -07001236 // Force the show in the next prepareSurfaceLocked() call.
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001237 mLastAlpha = -1;
Craig Mautneref25d7a2012-05-15 23:01:47 -07001238 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM)
1239 Slog.v(TAG, "performShowLocked: mDrawState=HAS_DRAWN in " + this);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001240 mDrawState = HAS_DRAWN;
Craig Mautnerde6198e2012-04-19 09:59:31 -07001241 mService.scheduleAnimationLocked();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001242
1243 int i = mWin.mChildWindows.size();
1244 while (i > 0) {
1245 i--;
1246 WindowState c = mWin.mChildWindows.get(i);
1247 if (c.mAttachedHidden) {
1248 c.mAttachedHidden = false;
1249 if (c.mWinAnimator.mSurface != null) {
1250 c.mWinAnimator.performShowLocked();
1251 // It hadn't been shown, which means layout not
1252 // performed on it, so now we want to make sure to
1253 // do a layout. If called from within the transaction
1254 // loop, this will cause it to restart with a new
1255 // layout.
1256 mService.mLayoutNeeded = true;
1257 }
1258 }
1259 }
1260
1261 if (mWin.mAttrs.type != TYPE_APPLICATION_STARTING
1262 && mWin.mAppToken != null) {
1263 mWin.mAppToken.firstWindowDrawn = true;
1264
1265 if (mWin.mAppToken.startingData != null) {
1266 if (WindowManagerService.DEBUG_STARTING_WINDOW ||
Craig Mautnerd87946b2012-03-29 18:00:19 -07001267 WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001268 "Finish starting " + mWin.mToken
1269 + ": first real window is shown, no animation");
1270 // If this initial window is animating, stop it -- we
1271 // will do an animation to reveal it from behind the
1272 // starting window, so there is no need for it to also
1273 // be doing its own stuff.
Craig Mautner4d7349b2012-04-20 14:52:47 -07001274 clearAnimation();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001275 mService.mFinishedStarting.add(mWin.mAppToken);
1276 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
1277 }
1278 mWin.mAppToken.updateReportedVisibilityLocked();
1279 }
1280
1281 return true;
1282 }
1283
1284 return false;
1285 }
1286
1287 /**
1288 * Have the surface flinger show a surface, robustly dealing with
1289 * error conditions. In particular, if there is not enough memory
1290 * to show the surface, then we will try to get rid of other surfaces
1291 * in order to succeed.
1292 *
1293 * @return Returns true if the surface was successfully shown.
1294 */
1295 boolean showSurfaceRobustlyLocked() {
1296 try {
1297 if (mSurface != null) {
1298 mSurfaceShown = true;
1299 mSurface.show();
1300 if (mWin.mTurnOnScreen) {
1301 if (DEBUG_VISIBILITY) Slog.v(TAG,
1302 "Show surface turning screen on: " + mWin);
1303 mWin.mTurnOnScreen = false;
Craig Mautner7d8df392012-04-06 15:26:23 -07001304 mAnimator.mBulkUpdateParams |= SET_TURN_ON_SCREEN;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001305 }
1306 }
1307 return true;
1308 } catch (RuntimeException e) {
1309 Slog.w(TAG, "Failure showing surface " + mSurface + " in " + mWin, e);
1310 }
1311
1312 mService.reclaimSomeSurfaceMemoryLocked(this, "show", true);
1313
1314 return false;
1315 }
1316
1317 void applyEnterAnimationLocked() {
1318 final int transit;
1319 if (mEnterAnimationPending) {
1320 mEnterAnimationPending = false;
1321 transit = WindowManagerPolicy.TRANSIT_ENTER;
1322 } else {
1323 transit = WindowManagerPolicy.TRANSIT_SHOW;
1324 }
1325
1326 applyAnimationLocked(transit, true);
1327 }
1328
Craig Mautner48ba1e72012-04-02 13:18:16 -07001329 // TODO(cmautner): Move back to WindowState?
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001330 /**
1331 * Choose the correct animation and set it to the passed WindowState.
1332 * @param transit If WindowManagerPolicy.TRANSIT_PREVIEW_DONE and the app window has been drawn
1333 * then the animation will be app_starting_exit. Any other value loads the animation from
1334 * the switch statement below.
1335 * @param isEntrance The animation type the last time this was called. Used to keep from
1336 * loading the same animation twice.
1337 * @return true if an animation has been loaded.
1338 */
1339 boolean applyAnimationLocked(int transit, boolean isEntrance) {
1340 if (mLocalAnimating && mAnimationIsEntrance == isEntrance) {
1341 // If we are trying to apply an animation, but already running
1342 // an animation of the same type, then just leave that one alone.
1343 return true;
1344 }
1345
1346 // Only apply an animation if the display isn't frozen. If it is
1347 // frozen, there is no reason to animate and it can cause strange
1348 // artifacts when we unfreeze the display if some different animation
1349 // is running.
1350 if (mService.okToDisplay()) {
1351 int anim = mPolicy.selectAnimationLw(mWin, transit);
1352 int attr = -1;
1353 Animation a = null;
1354 if (anim != 0) {
1355 a = AnimationUtils.loadAnimation(mContext, anim);
1356 } else {
1357 switch (transit) {
1358 case WindowManagerPolicy.TRANSIT_ENTER:
1359 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
1360 break;
1361 case WindowManagerPolicy.TRANSIT_EXIT:
1362 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
1363 break;
1364 case WindowManagerPolicy.TRANSIT_SHOW:
1365 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
1366 break;
1367 case WindowManagerPolicy.TRANSIT_HIDE:
1368 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
1369 break;
1370 }
1371 if (attr >= 0) {
1372 a = mService.loadAnimation(mWin.mAttrs, attr);
1373 }
1374 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001375 if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001376 "applyAnimation: win=" + this
1377 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
Craig Mautner4d7349b2012-04-20 14:52:47 -07001378 + " a=" + a
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001379 + " mAnimation=" + mAnimation
Craig Mautner83339b42012-05-01 22:13:23 -07001380 + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001381 if (a != null) {
1382 if (WindowManagerService.DEBUG_ANIM) {
1383 RuntimeException e = null;
1384 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
1385 e = new RuntimeException();
1386 e.fillInStackTrace();
1387 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001388 Slog.v(TAG, "Loaded animation " + a + " for " + this, e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001389 }
1390 setAnimation(a);
1391 mAnimationIsEntrance = isEntrance;
1392 }
1393 } else {
1394 clearAnimation();
1395 }
1396
1397 return mAnimation != null;
1398 }
1399
Craig Mautnera2c77052012-03-26 12:14:43 -07001400 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1401 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
1402 || mAnimation != null) {
1403 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
1404 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
1405 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
1406 pw.print(" mAnimation="); pw.println(mAnimation);
1407 }
1408 if (mHasTransformation || mHasLocalTransformation) {
1409 pw.print(prefix); pw.print("XForm: has=");
1410 pw.print(mHasTransformation);
1411 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
1412 pw.print(" "); mTransformation.printShortString(pw);
1413 pw.println();
1414 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001415 if (mSurface != null) {
1416 if (dumpAll) {
1417 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001418 pw.print(prefix); pw.print("mDrawState="); pw.print(mDrawState);
1419 pw.print(" mLastHidden="); pw.println(mLastHidden);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001420 }
1421 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
1422 pw.print(" layer="); pw.print(mSurfaceLayer);
1423 pw.print(" alpha="); pw.print(mSurfaceAlpha);
1424 pw.print(" rect=("); pw.print(mSurfaceX);
1425 pw.print(","); pw.print(mSurfaceY);
1426 pw.print(") "); pw.print(mSurfaceW);
1427 pw.print(" x "); pw.println(mSurfaceH);
1428 }
1429 if (mPendingDestroySurface != null) {
1430 pw.print(prefix); pw.print("mPendingDestroySurface=");
1431 pw.println(mPendingDestroySurface);
1432 }
1433 if (mSurfaceResized || mSurfaceDestroyDeferred) {
1434 pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized);
1435 pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred);
1436 }
1437 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
1438 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
1439 pw.print(" mAlpha="); pw.print(mAlpha);
1440 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
1441 }
1442 if (mHaveMatrix || mWin.mGlobalScale != 1) {
1443 pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale);
1444 pw.print(" mDsDx="); pw.print(mDsDx);
1445 pw.print(" mDtDx="); pw.print(mDtDx);
1446 pw.print(" mDsDy="); pw.print(mDsDy);
1447 pw.print(" mDtDy="); pw.println(mDtDy);
1448 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001449 }
1450
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001451 @Override
1452 public String toString() {
1453 StringBuffer sb = new StringBuffer("WindowStateAnimator (");
1454 sb.append(mWin.mLastTitle + "): ");
1455 sb.append("mSurface " + mSurface);
1456 sb.append(", mAnimation " + mAnimation);
1457 return sb.toString();
1458 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001459}