blob: c07174baf4c3772eb9363f12a8b0ded5fdb86bf7 [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;
Craig Mautner2639da52012-07-09 09:39:06 -07006import static com.android.server.wm.WindowManagerService.LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE;
Craig Mautner7d8df392012-04-06 15:26:23 -07007import static com.android.server.wm.WindowManagerService.LayoutFields.SET_TURN_ON_SCREEN;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -07008
Craig Mautnerc2f9be02012-03-27 17:32:29 -07009import android.content.Context;
10import android.graphics.Matrix;
11import android.graphics.PixelFormat;
Craig Mautner7358fbf2012-04-12 21:06:33 -070012import android.graphics.Point;
13import android.graphics.PointF;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070014import android.graphics.Rect;
Craig Mautner58106812012-12-28 12:27:40 -080015import android.graphics.RectF;
Craig Mautner48ba1e72012-04-02 13:18:16 -070016import android.graphics.Region;
Craig Mautnera51a9562012-04-17 17:05:26 -070017import android.os.Debug;
Craig Mautnera2c77052012-03-26 12:14:43 -070018import android.util.Slog;
Svetoslav Ganov545252f2012-12-10 18:29:24 -080019import android.view.Display;
Craig Mautner59c00972012-07-30 12:10:24 -070020import android.view.DisplayInfo;
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -070021import android.view.MagnificationSpec;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070022import android.view.Surface;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080023import android.view.SurfaceControl;
Craig Mautner7358fbf2012-04-12 21:06:33 -070024import android.view.SurfaceSession;
Craig Mautnera2c77052012-03-26 12:14:43 -070025import android.view.WindowManager;
26import android.view.WindowManagerPolicy;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070027import android.view.WindowManager.LayoutParams;
Craig Mautnera2c77052012-03-26 12:14:43 -070028import android.view.animation.Animation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070029import android.view.animation.AnimationUtils;
Craig Mautnera2c77052012-03-26 12:14:43 -070030import android.view.animation.Transformation;
31
32import com.android.server.wm.WindowManagerService.H;
33
34import java.io.PrintWriter;
Craig Mautner7358fbf2012-04-12 21:06:33 -070035import java.util.ArrayList;
Craig Mautnera2c77052012-03-26 12:14:43 -070036
Craig Mautner59c00972012-07-30 12:10:24 -070037class WinAnimatorList extends ArrayList<WindowStateAnimator> {
Craig Mautnera91f9e22012-09-14 16:22:08 -070038 public WinAnimatorList() {
39 super();
40 }
41
42 public WinAnimatorList(WinAnimatorList other) {
43 super(other);
44 }
Craig Mautner59c00972012-07-30 12:10:24 -070045}
46
Craig Mautnera2c77052012-03-26 12:14:43 -070047/**
Craig Mautnerc2f9be02012-03-27 17:32:29 -070048 * Keep track of animations and surface operations for a single WindowState.
49 **/
Craig Mautnera2c77052012-03-26 12:14:43 -070050class WindowStateAnimator {
Craig Mautnerc2f9be02012-03-27 17:32:29 -070051 static final boolean DEBUG_VISIBILITY = WindowManagerService.DEBUG_VISIBILITY;
52 static final boolean DEBUG_ANIM = WindowManagerService.DEBUG_ANIM;
53 static final boolean DEBUG_LAYERS = WindowManagerService.DEBUG_LAYERS;
54 static final boolean DEBUG_STARTING_WINDOW = WindowManagerService.DEBUG_STARTING_WINDOW;
55 static final boolean SHOW_TRANSACTIONS = WindowManagerService.SHOW_TRANSACTIONS;
56 static final boolean SHOW_LIGHT_TRANSACTIONS = WindowManagerService.SHOW_LIGHT_TRANSACTIONS;
57 static final boolean SHOW_SURFACE_ALLOC = WindowManagerService.SHOW_SURFACE_ALLOC;
58 static final boolean localLOGV = WindowManagerService.localLOGV;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -070059 static final boolean DEBUG_ORIENTATION = WindowManagerService.DEBUG_ORIENTATION;
Craig Mautner7358fbf2012-04-12 21:06:33 -070060 static final boolean DEBUG_SURFACE_TRACE = WindowManagerService.DEBUG_SURFACE_TRACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070061
62 static final String TAG = "WindowStateAnimator";
Craig Mautnera2c77052012-03-26 12:14:43 -070063
Craig Mautner918b53b2012-07-09 14:15:54 -070064 // Unchanging local convenience fields.
Craig Mautnera2c77052012-03-26 12:14:43 -070065 final WindowManagerService mService;
66 final WindowState mWin;
Craig Mautner322e4032012-07-13 13:35:20 -070067 final WindowStateAnimator mAttachedWinAnimator;
Craig Mautnere7ae2502012-03-26 17:11:19 -070068 final WindowAnimator mAnimator;
Craig Mautner8863cca2012-09-18 15:04:34 -070069 AppWindowAnimator mAppAnimator;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070070 final Session mSession;
71 final WindowManagerPolicy mPolicy;
72 final Context mContext;
Craig Mautner918b53b2012-07-09 14:15:54 -070073 final boolean mIsWallpaper;
Craig Mautnera2c77052012-03-26 12:14:43 -070074
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -070075 // If this is a universe background window, this is the transformation
76 // it is applying to the rest of the universe.
77 final Transformation mUniverseTransform = new Transformation();
78
Craig Mautnera2c77052012-03-26 12:14:43 -070079 // Currently running animation.
80 boolean mAnimating;
81 boolean mLocalAnimating;
82 Animation mAnimation;
83 boolean mAnimationIsEntrance;
84 boolean mHasTransformation;
85 boolean mHasLocalTransformation;
86 final Transformation mTransformation = new Transformation();
87 boolean mWasAnimating; // Were we animating going into the most recent animation step?
Craig Mautnerc2f9be02012-03-27 17:32:29 -070088 int mAnimLayer;
89 int mLastLayer;
90
Mathias Agopian29479eb2013-02-14 14:36:04 -080091 SurfaceControl mSurfaceControl;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080092 SurfaceControl mPendingDestroySurface;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070093
94 /**
95 * Set when we have changed the size of the surface, to know that
96 * we must tell them application to resize (and thus redraw itself).
97 */
98 boolean mSurfaceResized;
99
100 /**
101 * Set if the client has asked that the destroy of its surface be delayed
102 * until it explicitly says it is okay.
103 */
104 boolean mSurfaceDestroyDeferred;
105
Craig Mautner7d8df392012-04-06 15:26:23 -0700106 float mShownAlpha = 0;
107 float mAlpha = 0;
108 float mLastAlpha = 0;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700109
110 // Used to save animation distances between the time they are calculated and when they are
111 // used.
112 int mAnimDw;
113 int mAnimDh;
114 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
115 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
116
117 boolean mHaveMatrix;
118
119 // For debugging, this is the last information given to the surface flinger.
120 boolean mSurfaceShown;
121 float mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
122 int mSurfaceLayer;
123 float mSurfaceAlpha;
124
125 // Set to true if, when the window gets displayed, it should perform
126 // an enter animation.
127 boolean mEnterAnimationPending;
Craig Mautnera2c77052012-03-26 12:14:43 -0700128
Craig Mautner749a7bb2012-04-02 13:49:53 -0700129 /** This is set when there is no Surface */
130 static final int NO_SURFACE = 0;
131 /** This is set after the Surface has been created but before the window has been drawn. During
132 * this time the surface is hidden. */
133 static final int DRAW_PENDING = 1;
134 /** This is set after the window has finished drawing for the first time but before its surface
135 * is shown. The surface will be displayed when the next layout is run. */
136 static final int COMMIT_DRAW_PENDING = 2;
137 /** This is set during the time after the window's drawing has been committed, and before its
138 * surface is actually shown. It is used to delay showing the surface until all windows in a
139 * token are ready to be shown. */
140 static final int READY_TO_SHOW = 3;
141 /** Set when the window has been shown in the screen the first time. */
142 static final int HAS_DRAWN = 4;
Craig Mautner6fbda632012-07-03 09:26:39 -0700143 static String drawStateToString(int state) {
144 switch (state) {
145 case NO_SURFACE: return "NO_SURFACE";
146 case DRAW_PENDING: return "DRAW_PENDING";
147 case COMMIT_DRAW_PENDING: return "COMMIT_DRAW_PENDING";
148 case READY_TO_SHOW: return "READY_TO_SHOW";
149 case HAS_DRAWN: return "HAS_DRAWN";
150 default: return Integer.toString(state);
151 }
152 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700153 int mDrawState;
Craig Mautnera608b882012-03-30 13:03:49 -0700154
Craig Mautner749a7bb2012-04-02 13:49:53 -0700155 /** Was this window last hidden? */
156 boolean mLastHidden;
Craig Mautnera608b882012-03-30 13:03:49 -0700157
Craig Mautnerbec53f72012-04-05 11:49:05 -0700158 int mAttrFlags;
159 int mAttrType;
160
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700161 final int mLayerStack;
162
Craig Mautner918b53b2012-07-09 14:15:54 -0700163 public WindowStateAnimator(final WindowState win) {
164 final WindowManagerService service = win.mService;
165
Craig Mautnera2c77052012-03-26 12:14:43 -0700166 mService = service;
Craig Mautner918b53b2012-07-09 14:15:54 -0700167 mAnimator = service.mAnimator;
168 mPolicy = service.mPolicy;
169 mContext = service.mContext;
Craig Mautner59c00972012-07-30 12:10:24 -0700170 final DisplayInfo displayInfo = win.mDisplayContent.getDisplayInfo();
171 mAnimDw = displayInfo.appWidth;
172 mAnimDh = displayInfo.appHeight;
Craig Mautner918b53b2012-07-09 14:15:54 -0700173
174 mWin = win;
Craig Mautner322e4032012-07-13 13:35:20 -0700175 mAttachedWinAnimator = win.mAttachedWindow == null
176 ? null : win.mAttachedWindow.mWinAnimator;
177 mAppAnimator = win.mAppToken == null ? null : win.mAppToken.mAppAnimator;
Craig Mautner918b53b2012-07-09 14:15:54 -0700178 mSession = win.mSession;
179 mAttrFlags = win.mAttrs.flags;
180 mAttrType = win.mAttrs.type;
181 mIsWallpaper = win.mIsWallpaper;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700182 mLayerStack = win.mDisplayContent.getDisplay().getLayerStack();
Craig Mautnera2c77052012-03-26 12:14:43 -0700183 }
184
185 public void setAnimation(Animation anim) {
Craig Mautnerbec53f72012-04-05 11:49:05 -0700186 if (localLOGV) Slog.v(TAG, "Setting animation in " + this + ": " + anim);
Craig Mautnera2c77052012-03-26 12:14:43 -0700187 mAnimating = false;
188 mLocalAnimating = false;
189 mAnimation = anim;
190 mAnimation.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION);
191 mAnimation.scaleCurrentDuration(mService.mWindowAnimationScale);
192 // Start out animation gone if window is gone, or visible if window is visible.
193 mTransformation.clear();
Craig Mautner749a7bb2012-04-02 13:49:53 -0700194 mTransformation.setAlpha(mLastHidden ? 0 : 1);
Craig Mautnera2c77052012-03-26 12:14:43 -0700195 mHasLocalTransformation = true;
196 }
197
198 public void clearAnimation() {
199 if (mAnimation != null) {
200 mAnimating = true;
201 mLocalAnimating = false;
202 mAnimation.cancel();
203 mAnimation = null;
204 }
205 }
206
207 /** Is the window or its container currently animating? */
208 boolean isAnimating() {
Craig Mautnera2c77052012-03-26 12:14:43 -0700209 return mAnimation != null
Craig Mautner322e4032012-07-13 13:35:20 -0700210 || (mAttachedWinAnimator != null && mAttachedWinAnimator.mAnimation != null)
211 || (mAppAnimator != null &&
212 (mAppAnimator.animation != null
213 || mAppAnimator.mAppToken.inPendingTransaction));
Craig Mautnera2c77052012-03-26 12:14:43 -0700214 }
215
Craig Mautner0afddcb2012-05-08 15:38:00 -0700216 /** Is the window animating the DummyAnimation? */
217 boolean isDummyAnimation() {
Craig Mautner322e4032012-07-13 13:35:20 -0700218 return mAppAnimator != null
219 && mAppAnimator.animation == AppWindowAnimator.sDummyAnimation;
Craig Mautner0afddcb2012-05-08 15:38:00 -0700220 }
221
Craig Mautnera2c77052012-03-26 12:14:43 -0700222 /** Is this window currently animating? */
223 boolean isWindowAnimating() {
224 return mAnimation != null;
225 }
226
Craig Mautnera2c77052012-03-26 12:14:43 -0700227 void cancelExitAnimationForNextAnimationLocked() {
Craig Mautnera2c77052012-03-26 12:14:43 -0700228 if (mAnimation != null) {
229 mAnimation.cancel();
230 mAnimation = null;
Craig Mautner4d7349b2012-04-20 14:52:47 -0700231 mLocalAnimating = false;
Craig Mautner96868332012-12-04 14:29:11 -0800232 destroySurfaceLocked();
Craig Mautnera2c77052012-03-26 12:14:43 -0700233 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700234 }
235
236 private boolean stepAnimation(long currentTime) {
237 if ((mAnimation == null) || !mLocalAnimating) {
238 return false;
239 }
240 mTransformation.clear();
241 final boolean more = mAnimation.getTransformation(currentTime, mTransformation);
Craig Mautner9e809442012-06-22 17:13:04 -0700242 if (false && DEBUG_ANIM) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700243 TAG, "Stepped animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700244 ": more=" + more + ", xform=" + mTransformation);
245 return more;
246 }
247
248 // This must be called while inside a transaction. Returns true if
249 // there is more animation to run.
250 boolean stepAnimationLocked(long currentTime) {
251 // Save the animation state as it was before this step so WindowManagerService can tell if
252 // we just started or just stopped animating by comparing mWasAnimating with isAnimating().
253 mWasAnimating = mAnimating;
254 if (mService.okToDisplay()) {
255 // We will run animations as long as the display isn't frozen.
256
257 if (mWin.isDrawnLw() && mAnimation != null) {
258 mHasTransformation = true;
259 mHasLocalTransformation = true;
260 if (!mLocalAnimating) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700261 if (DEBUG_ANIM) Slog.v(
262 TAG, "Starting animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700263 " @ " + currentTime + ": ww=" + mWin.mFrame.width() +
264 " wh=" + mWin.mFrame.height() +
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700265 " dw=" + mAnimDw + " dh=" + mAnimDh +
Craig Mautnera2c77052012-03-26 12:14:43 -0700266 " scale=" + mService.mWindowAnimationScale);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700267 mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(),
268 mAnimDw, mAnimDh);
Craig Mautner59c00972012-07-30 12:10:24 -0700269 final DisplayInfo displayInfo = mWin.mDisplayContent.getDisplayInfo();
270 mAnimDw = displayInfo.appWidth;
271 mAnimDh = displayInfo.appHeight;
Craig Mautnera2c77052012-03-26 12:14:43 -0700272 mAnimation.setStartTime(currentTime);
273 mLocalAnimating = true;
274 mAnimating = true;
275 }
276 if ((mAnimation != null) && mLocalAnimating) {
277 if (stepAnimation(currentTime)) {
278 return true;
279 }
280 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700281 if (DEBUG_ANIM) Slog.v(
282 TAG, "Finished animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700283 " @ " + currentTime);
284 //WindowManagerService.this.dump();
285 }
286 mHasLocalTransformation = false;
Craig Mautner322e4032012-07-13 13:35:20 -0700287 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppAnimator != null
288 && mAppAnimator.animation != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700289 // When our app token is animating, we kind-of pretend like
290 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
291 // part of this check means that we will only do this if
292 // our window is not currently exiting, or it is not
293 // locally animating itself. The idea being that one that
294 // is exiting and doing a local animation should be removed
295 // once that animation is done.
296 mAnimating = true;
297 mHasTransformation = true;
298 mTransformation.clear();
299 return false;
300 } else if (mHasTransformation) {
301 // Little trick to get through the path below to act like
302 // we have finished an animation.
303 mAnimating = true;
304 } else if (isAnimating()) {
305 mAnimating = true;
306 }
307 } else if (mAnimation != null) {
308 // If the display is frozen, and there is a pending animation,
309 // clear it and make sure we run the cleanup code.
310 mAnimating = true;
Craig Mautnera2c77052012-03-26 12:14:43 -0700311 }
312
313 if (!mAnimating && !mLocalAnimating) {
314 return false;
315 }
316
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700317 // Done animating, clean up.
318 if (DEBUG_ANIM) Slog.v(
319 TAG, "Animation done in " + this + ": exiting=" + mWin.mExiting
Craig Mautnera2c77052012-03-26 12:14:43 -0700320 + ", reportedVisible="
321 + (mWin.mAppToken != null ? mWin.mAppToken.reportedVisible : false));
322
323 mAnimating = false;
324 mLocalAnimating = false;
325 if (mAnimation != null) {
326 mAnimation.cancel();
327 mAnimation = null;
328 }
Craig Mautnere7ae2502012-03-26 17:11:19 -0700329 if (mAnimator.mWindowDetachedWallpaper == mWin) {
330 mAnimator.mWindowDetachedWallpaper = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700331 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700332 mAnimLayer = mWin.mLayer;
Craig Mautnera2c77052012-03-26 12:14:43 -0700333 if (mWin.mIsImWindow) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700334 mAnimLayer += mService.mInputMethodAnimLayerAdjustment;
Craig Mautner918b53b2012-07-09 14:15:54 -0700335 } else if (mIsWallpaper) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700336 mAnimLayer += mService.mWallpaperAnimLayerAdjustment;
Craig Mautnera2c77052012-03-26 12:14:43 -0700337 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700338 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
339 + " anim layer: " + mAnimLayer);
Craig Mautnera2c77052012-03-26 12:14:43 -0700340 mHasTransformation = false;
341 mHasLocalTransformation = false;
342 if (mWin.mPolicyVisibility != mWin.mPolicyVisibilityAfterAnim) {
343 if (WindowState.DEBUG_VISIBILITY) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700344 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
Craig Mautnera2c77052012-03-26 12:14:43 -0700345 + mWin.mPolicyVisibilityAfterAnim);
346 }
347 mWin.mPolicyVisibility = mWin.mPolicyVisibilityAfterAnim;
Craig Mautner19d59bc2012-09-04 11:15:56 -0700348 mWin.mDisplayContent.layoutNeeded = true;
Craig Mautnera2c77052012-03-26 12:14:43 -0700349 if (!mWin.mPolicyVisibility) {
350 if (mService.mCurrentFocus == mWin) {
351 mService.mFocusMayChange = true;
352 }
353 // Window is no longer visible -- make sure if we were waiting
354 // for it to be displayed before enabling the display, that
355 // we allow the display to be enabled now.
356 mService.enableScreenIfNeededLocked();
357 }
358 }
359 mTransformation.clear();
Craig Mautner749a7bb2012-04-02 13:49:53 -0700360 if (mDrawState == HAS_DRAWN
Craig Mautnera2c77052012-03-26 12:14:43 -0700361 && mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
362 && mWin.mAppToken != null
363 && mWin.mAppToken.firstWindowDrawn
364 && mWin.mAppToken.startingData != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700365 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
Craig Mautnera2c77052012-03-26 12:14:43 -0700366 + mWin.mToken + ": first real window done animating");
367 mService.mFinishedStarting.add(mWin.mAppToken);
368 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
369 }
370
371 finishExit();
Craig Mautner76a71652012-09-03 23:23:58 -0700372 final int displayId = mWin.mDisplayContent.getDisplayId();
373 mAnimator.setPendingLayoutChanges(displayId, WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700374 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) mService.debugLayoutRepeats(
Craig Mautner66f78d72012-12-04 16:46:50 -0800375 "WindowStateAnimator", mAnimator.getPendingLayoutChanges(displayId));
Craig Mautnera2c77052012-03-26 12:14:43 -0700376
377 if (mWin.mAppToken != null) {
378 mWin.mAppToken.updateReportedVisibilityLocked();
379 }
380
381 return false;
382 }
383
384 void finishExit() {
385 if (WindowManagerService.DEBUG_ANIM) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700386 TAG, "finishExit in " + this
Craig Mautnera2c77052012-03-26 12:14:43 -0700387 + ": exiting=" + mWin.mExiting
388 + " remove=" + mWin.mRemoveOnExit
389 + " windowAnimating=" + isWindowAnimating());
390
391 final int N = mWin.mChildWindows.size();
392 for (int i=0; i<N; i++) {
393 mWin.mChildWindows.get(i).mWinAnimator.finishExit();
394 }
395
396 if (!mWin.mExiting) {
397 return;
398 }
399
400 if (isWindowAnimating()) {
401 return;
402 }
403
404 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700405 TAG, "Exit animation finished in " + this
Craig Mautnera2c77052012-03-26 12:14:43 -0700406 + ": remove=" + mWin.mRemoveOnExit);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800407 if (mSurfaceControl != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700408 mService.mDestroySurface.add(mWin);
409 mWin.mDestroying = true;
410 if (WindowState.SHOW_TRANSACTIONS) WindowManagerService.logSurface(
411 mWin, "HIDE (finishExit)", null);
Craig Mautner0afddcb2012-05-08 15:38:00 -0700412 hide();
Craig Mautnera2c77052012-03-26 12:14:43 -0700413 }
414 mWin.mExiting = false;
415 if (mWin.mRemoveOnExit) {
416 mService.mPendingRemove.add(mWin);
417 mWin.mRemoveOnExit = false;
418 }
Craig Mautner96868332012-12-04 14:29:11 -0800419 mAnimator.hideWallpapersLocked(mWin);
Craig Mautner0afddcb2012-05-08 15:38:00 -0700420 }
421
422 void hide() {
423 if (!mLastHidden) {
424 //dump();
425 mLastHidden = true;
426 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
427 "HIDE (performLayout)", null);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800428 if (mSurfaceControl != null) {
Craig Mautner0afddcb2012-05-08 15:38:00 -0700429 mSurfaceShown = false;
430 try {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800431 mSurfaceControl.hide();
Craig Mautner0afddcb2012-05-08 15:38:00 -0700432 } catch (RuntimeException e) {
433 Slog.w(TAG, "Exception hiding surface in " + mWin);
434 }
435 }
436 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700437 }
438
Craig Mautnera608b882012-03-30 13:03:49 -0700439 boolean finishDrawingLocked() {
Craig Mautner6fbda632012-07-03 09:26:39 -0700440 if (DEBUG_STARTING_WINDOW &&
441 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
442 Slog.v(TAG, "Finishing drawing window " + mWin + ": mDrawState="
443 + drawStateToString(mDrawState));
444 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700445 if (mDrawState == DRAW_PENDING) {
Craig Mautneref25d7a2012-05-15 23:01:47 -0700446 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
447 Slog.v(TAG, "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING " + this + " in "
Mathias Agopian29479eb2013-02-14 14:36:04 -0800448 + mSurfaceControl);
Craig Mautner6fbda632012-07-03 09:26:39 -0700449 if (DEBUG_STARTING_WINDOW &&
450 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
451 Slog.v(TAG, "Draw state now committed in " + mWin);
452 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700453 mDrawState = COMMIT_DRAW_PENDING;
Craig Mautnera608b882012-03-30 13:03:49 -0700454 return true;
455 }
456 return false;
457 }
458
459 // This must be called while inside a transaction.
460 boolean commitFinishDrawingLocked(long currentTime) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700461 if (DEBUG_STARTING_WINDOW &&
462 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
463 Slog.i(TAG, "commitFinishDrawingLocked: " + mWin + " cur mDrawState="
464 + drawStateToString(mDrawState));
465 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700466 if (mDrawState != COMMIT_DRAW_PENDING) {
Craig Mautnera608b882012-03-30 13:03:49 -0700467 return false;
468 }
Craig Mautner6fbda632012-07-03 09:26:39 -0700469 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800470 Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurfaceControl);
Craig Mautner6fbda632012-07-03 09:26:39 -0700471 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700472 mDrawState = READY_TO_SHOW;
Craig Mautnera608b882012-03-30 13:03:49 -0700473 final boolean starting = mWin.mAttrs.type == TYPE_APPLICATION_STARTING;
474 final AppWindowToken atoken = mWin.mAppToken;
475 if (atoken == null || atoken.allDrawn || starting) {
476 performShowLocked();
477 }
478 return true;
479 }
480
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800481 static class SurfaceTrace extends SurfaceControl {
Craig Mautner7d8df392012-04-06 15:26:23 -0700482 private final static String SURFACE_TAG = "SurfaceTrace";
483 final static ArrayList<SurfaceTrace> sSurfaces = new ArrayList<SurfaceTrace>();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700484
Craig Mautner7d8df392012-04-06 15:26:23 -0700485 private float mSurfaceTraceAlpha = 0;
Craig Mautner7358fbf2012-04-12 21:06:33 -0700486 private int mLayer;
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700487 private final PointF mPosition = new PointF();
488 private final Point mSize = new Point();
489 private final Rect mWindowCrop = new Rect();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700490 private boolean mShown = false;
Jeff Brown98365d72012-08-19 20:30:52 -0700491 private int mLayerStack;
492 private String mName;
Craig Mautner7358fbf2012-04-12 21:06:33 -0700493
Craig Mautner7d8df392012-04-06 15:26:23 -0700494 public SurfaceTrace(SurfaceSession s,
Jeff Brown64a55af2012-08-26 02:47:39 -0700495 String name, int w, int h, int format, int flags)
Craig Mautner7358fbf2012-04-12 21:06:33 -0700496 throws OutOfResourcesException {
Jeff Brown64a55af2012-08-26 02:47:39 -0700497 super(s, name, w, h, format, flags);
Jeff Brown98365d72012-08-19 20:30:52 -0700498 mName = name != null ? name : "Not named";
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700499 mSize.set(w, h);
Craig Mautner7d8df392012-04-06 15:26:23 -0700500 Slog.v(SURFACE_TAG, "ctor: " + 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
505 public void setAlpha(float alpha) {
506 super.setAlpha(alpha);
Dianne Hackborn98129732012-11-01 16:28:16 -0700507 if (alpha != mSurfaceTraceAlpha) {
Craig Mautner66d77302013-04-10 15:33:26 -0700508 mSurfaceTraceAlpha = alpha;
Dianne Hackborn98129732012-11-01 16:28:16 -0700509 Slog.v(SURFACE_TAG, "setAlpha: " + this + ". Called by "
510 + Debug.getCallers(3));
511 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700512 }
513
514 @Override
515 public void setLayer(int zorder) {
516 super.setLayer(zorder);
Dianne Hackborn98129732012-11-01 16:28:16 -0700517 if (zorder != mLayer) {
Craig Mautner66d77302013-04-10 15:33:26 -0700518 mLayer = zorder;
Dianne Hackborn98129732012-11-01 16:28:16 -0700519 Slog.v(SURFACE_TAG, "setLayer: " + this + ". Called by "
520 + Debug.getCallers(3));
521 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700522
523 sSurfaces.remove(this);
524 int i;
525 for (i = sSurfaces.size() - 1; i >= 0; i--) {
Craig Mautner7d8df392012-04-06 15:26:23 -0700526 SurfaceTrace s = sSurfaces.get(i);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700527 if (s.mLayer < zorder) {
528 break;
529 }
530 }
531 sSurfaces.add(i + 1, this);
532 }
533
534 @Override
535 public void setPosition(float x, float y) {
536 super.setPosition(x, y);
Dianne Hackborn98129732012-11-01 16:28:16 -0700537 if (x != mPosition.x || y != mPosition.y) {
Craig Mautner66d77302013-04-10 15:33:26 -0700538 mPosition.set(x, y);
Dianne Hackborn98129732012-11-01 16:28:16 -0700539 Slog.v(SURFACE_TAG, "setPosition: " + this + ". Called by "
540 + Debug.getCallers(3));
541 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700542 }
543
544 @Override
545 public void setSize(int w, int h) {
546 super.setSize(w, h);
Dianne Hackborn98129732012-11-01 16:28:16 -0700547 if (w != mSize.x || h != mSize.y) {
Craig Mautner66d77302013-04-10 15:33:26 -0700548 mSize.set(w, h);
Dianne Hackborn98129732012-11-01 16:28:16 -0700549 Slog.v(SURFACE_TAG, "setSize: " + this + ". Called by "
550 + Debug.getCallers(3));
551 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700552 }
553
554 @Override
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700555 public void setWindowCrop(Rect crop) {
556 super.setWindowCrop(crop);
Craig Mautneref25d7a2012-05-15 23:01:47 -0700557 if (crop != null) {
Dianne Hackborn98129732012-11-01 16:28:16 -0700558 if (!crop.equals(mWindowCrop)) {
Craig Mautner66d77302013-04-10 15:33:26 -0700559 mWindowCrop.set(crop);
Dianne Hackborn98129732012-11-01 16:28:16 -0700560 Slog.v(SURFACE_TAG, "setWindowCrop: " + this + ". Called by "
561 + Debug.getCallers(3));
562 }
Craig Mautneref25d7a2012-05-15 23:01:47 -0700563 }
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700564 }
565
566 @Override
Jeff Brown98365d72012-08-19 20:30:52 -0700567 public void setLayerStack(int layerStack) {
568 super.setLayerStack(layerStack);
Dianne Hackborn98129732012-11-01 16:28:16 -0700569 if (layerStack != mLayerStack) {
Craig Mautner66d77302013-04-10 15:33:26 -0700570 mLayerStack = layerStack;
Dianne Hackborn98129732012-11-01 16:28:16 -0700571 Slog.v(SURFACE_TAG, "setLayerStack: " + this + ". Called by " + Debug.getCallers(3));
572 }
Craig Mautner9de49362012-08-02 14:30:30 -0700573 }
574
575 @Override
Craig Mautner7358fbf2012-04-12 21:06:33 -0700576 public void hide() {
577 super.hide();
Dianne Hackborn98129732012-11-01 16:28:16 -0700578 if (mShown) {
Craig Mautner66d77302013-04-10 15:33:26 -0700579 mShown = false;
Dianne Hackborn98129732012-11-01 16:28:16 -0700580 Slog.v(SURFACE_TAG, "hide: " + this + ". Called by "
581 + Debug.getCallers(3));
582 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700583 }
584 @Override
585 public void show() {
586 super.show();
Dianne Hackborn98129732012-11-01 16:28:16 -0700587 if (!mShown) {
Craig Mautner66d77302013-04-10 15:33:26 -0700588 mShown = true;
Dianne Hackborn98129732012-11-01 16:28:16 -0700589 Slog.v(SURFACE_TAG, "show: " + this + ". Called by "
590 + Debug.getCallers(3));
591 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700592 }
593
594 @Override
595 public void destroy() {
596 super.destroy();
Craig Mautner7d8df392012-04-06 15:26:23 -0700597 Slog.v(SURFACE_TAG, "destroy: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700598 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700599 sSurfaces.remove(this);
600 }
601
Craig Mautneracaf9cc2012-04-17 11:45:25 -0700602 @Override
603 public void release() {
604 super.release();
605 Slog.v(SURFACE_TAG, "release: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700606 + Debug.getCallers(3));
Craig Mautneracaf9cc2012-04-17 11:45:25 -0700607 sSurfaces.remove(this);
608 }
609
Craig Mautner7358fbf2012-04-12 21:06:33 -0700610 static void dumpAllSurfaces() {
611 final int N = sSurfaces.size();
612 for (int i = 0; i < N; i++) {
613 Slog.i(TAG, "SurfaceDump: " + sSurfaces.get(i));
614 }
615 }
616
617 @Override
618 public String toString() {
Craig Mautnerfbf378c2012-04-23 17:24:21 -0700619 return "Surface " + Integer.toHexString(System.identityHashCode(this)) + " "
Jeff Brown98365d72012-08-19 20:30:52 -0700620 + mName + " (" + mLayerStack + "): shown=" + mShown + " layer=" + mLayer
Craig Mautner7d8df392012-04-06 15:26:23 -0700621 + " alpha=" + mSurfaceTraceAlpha + " " + mPosition.x + "," + mPosition.y
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700622 + " " + mSize.x + "x" + mSize.y
623 + " crop=" + mWindowCrop.toShortString();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700624 }
625 }
626
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800627 SurfaceControl createSurfaceLocked() {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800628 if (mSurfaceControl == null) {
Craig Mautner83339b42012-05-01 22:13:23 -0700629 if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG,
630 "createSurface " + this + ": mDrawState=DRAW_PENDING");
Craig Mautner749a7bb2012-04-02 13:49:53 -0700631 mDrawState = DRAW_PENDING;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700632 if (mWin.mAppToken != null) {
Craig Mautner7636dfb2012-11-16 15:24:11 -0800633 if (mWin.mAppToken.mAppAnimator.animation == null) {
634 mWin.mAppToken.allDrawn = false;
635 mWin.mAppToken.deferClearAllDrawn = false;
636 } else {
637 // Currently animating, persist current state of allDrawn until animation
638 // is complete.
639 mWin.mAppToken.deferClearAllDrawn = true;
640 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700641 }
642
643 mService.makeWindowFreezingScreenIfNeededLocked(mWin);
644
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800645 int flags = SurfaceControl.HIDDEN;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700646 final WindowManager.LayoutParams attrs = mWin.mAttrs;
647
648 if ((attrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800649 flags |= SurfaceControl.SECURE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700650 }
651 if (WindowState.DEBUG_VISIBILITY) Slog.v(
652 TAG, "Creating surface in session "
653 + mSession.mSurfaceSession + " window " + this
654 + " w=" + mWin.mCompatFrame.width()
655 + " h=" + mWin.mCompatFrame.height() + " format="
656 + attrs.format + " flags=" + flags);
657
658 int w = mWin.mCompatFrame.width();
659 int h = mWin.mCompatFrame.height();
660 if ((attrs.flags & LayoutParams.FLAG_SCALED) != 0) {
661 // for a scaled surface, we always want the requested
662 // size.
663 w = mWin.mRequestedWidth;
664 h = mWin.mRequestedHeight;
665 }
666
667 // Something is wrong and SurfaceFlinger will not like this,
668 // try to revert to sane values
669 if (w <= 0) w = 1;
670 if (h <= 0) h = 1;
671
672 mSurfaceShown = false;
673 mSurfaceLayer = 0;
Craig Mautner7d8df392012-04-06 15:26:23 -0700674 mSurfaceAlpha = 0;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700675 mSurfaceX = 0;
676 mSurfaceY = 0;
677 mSurfaceW = w;
678 mSurfaceH = h;
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700679 mWin.mLastSystemDecorRect.set(0, 0, 0, 0);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700680 try {
681 final boolean isHwAccelerated = (attrs.flags &
682 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
683 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
684 if (!PixelFormat.formatHasAlpha(attrs.format)) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800685 flags |= SurfaceControl.OPAQUE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700686 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700687 if (DEBUG_SURFACE_TRACE) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800688 mSurfaceControl = new SurfaceTrace(
Jeff Brown64a55af2012-08-26 02:47:39 -0700689 mSession.mSurfaceSession,
Craig Mautner7358fbf2012-04-12 21:06:33 -0700690 attrs.getTitle().toString(),
Jeff Brown64a55af2012-08-26 02:47:39 -0700691 w, h, format, flags);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700692 } else {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800693 mSurfaceControl = new SurfaceControl(
Jeff Brown64a55af2012-08-26 02:47:39 -0700694 mSession.mSurfaceSession,
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700695 attrs.getTitle().toString(),
Jeff Brown64a55af2012-08-26 02:47:39 -0700696 w, h, format, flags);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700697 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700698 mWin.mHasSurface = true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700699 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG,
700 " CREATE SURFACE "
Mathias Agopian29479eb2013-02-14 14:36:04 -0800701 + mSurfaceControl + " IN SESSION "
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700702 + mSession.mSurfaceSession
703 + ": pid=" + mSession.mPid + " format="
704 + attrs.format + " flags=0x"
705 + Integer.toHexString(flags)
706 + " / " + this);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800707 } catch (SurfaceControl.OutOfResourcesException e) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700708 mWin.mHasSurface = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700709 Slog.w(TAG, "OutOfResourcesException creating surface");
710 mService.reclaimSomeSurfaceMemoryLocked(this, "create", true);
Craig Mautner749a7bb2012-04-02 13:49:53 -0700711 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700712 return null;
713 } catch (Exception e) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700714 mWin.mHasSurface = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700715 Slog.e(TAG, "Exception creating surface", e);
Craig Mautner749a7bb2012-04-02 13:49:53 -0700716 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700717 return null;
718 }
719
720 if (WindowManagerService.localLOGV) Slog.v(
Mathias Agopian29479eb2013-02-14 14:36:04 -0800721 TAG, "Got surface: " + mSurfaceControl
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700722 + ", set left=" + mWin.mFrame.left + " top=" + mWin.mFrame.top
723 + ", animLayer=" + mAnimLayer);
724 if (SHOW_LIGHT_TRANSACTIONS) {
725 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
726 WindowManagerService.logSurface(mWin, "CREATE pos=("
727 + mWin.mFrame.left + "," + mWin.mFrame.top + ") ("
728 + mWin.mCompatFrame.width() + "x" + mWin.mCompatFrame.height()
729 + "), layer=" + mAnimLayer + " HIDE", null);
730 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800731 SurfaceControl.openTransaction();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700732 try {
733 try {
734 mSurfaceX = mWin.mFrame.left + mWin.mXOffset;
735 mSurfaceY = mWin.mFrame.top + mWin.mYOffset;
Mathias Agopian29479eb2013-02-14 14:36:04 -0800736 mSurfaceControl.setPosition(mSurfaceX, mSurfaceY);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700737 mSurfaceLayer = mAnimLayer;
Mathias Agopian29479eb2013-02-14 14:36:04 -0800738 mSurfaceControl.setLayerStack(mLayerStack);
739 mSurfaceControl.setLayer(mAnimLayer);
740 mSurfaceControl.setAlpha(0);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700741 mSurfaceShown = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700742 } catch (RuntimeException e) {
743 Slog.w(TAG, "Error creating surface in " + w, e);
744 mService.reclaimSomeSurfaceMemoryLocked(this, "create-init", true);
745 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700746 mLastHidden = true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700747 } finally {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800748 SurfaceControl.closeTransaction();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700749 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
750 "<<< CLOSE TRANSACTION createSurfaceLocked");
751 }
752 if (WindowManagerService.localLOGV) Slog.v(
753 TAG, "Created surface " + this);
754 }
Mathias Agopian29479eb2013-02-14 14:36:04 -0800755 return mSurfaceControl;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700756 }
757
Craig Mautner96868332012-12-04 14:29:11 -0800758 void destroySurfaceLocked() {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700759 if (mWin.mAppToken != null && mWin == mWin.mAppToken.startingWindow) {
760 mWin.mAppToken.startingDisplayed = false;
761 }
762
Mathias Agopian29479eb2013-02-14 14:36:04 -0800763 if (mSurfaceControl != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700764
765 int i = mWin.mChildWindows.size();
766 while (i > 0) {
767 i--;
768 WindowState c = mWin.mChildWindows.get(i);
769 c.mAttachedHidden = true;
770 }
771
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700772 try {
773 if (DEBUG_VISIBILITY) {
774 RuntimeException e = null;
775 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
776 e = new RuntimeException();
777 e.fillInStackTrace();
778 }
779 Slog.w(TAG, "Window " + this + " destroying surface "
Mathias Agopian29479eb2013-02-14 14:36:04 -0800780 + mSurfaceControl + ", session " + mSession, e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700781 }
782 if (mSurfaceDestroyDeferred) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800783 if (mSurfaceControl != null && mPendingDestroySurface != mSurfaceControl) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700784 if (mPendingDestroySurface != null) {
785 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
786 RuntimeException e = null;
787 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
788 e = new RuntimeException();
789 e.fillInStackTrace();
790 }
791 WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
792 }
793 mPendingDestroySurface.destroy();
794 }
Mathias Agopian29479eb2013-02-14 14:36:04 -0800795 mPendingDestroySurface = mSurfaceControl;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700796 }
797 } else {
798 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
799 RuntimeException e = null;
800 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
801 e = new RuntimeException();
802 e.fillInStackTrace();
803 }
804 WindowManagerService.logSurface(mWin, "DESTROY", e);
805 }
Mathias Agopian29479eb2013-02-14 14:36:04 -0800806 mSurfaceControl.destroy();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700807 }
Craig Mautner96868332012-12-04 14:29:11 -0800808 mAnimator.hideWallpapersLocked(mWin);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700809 } catch (RuntimeException e) {
810 Slog.w(TAG, "Exception thrown when destroying Window " + this
Mathias Agopian29479eb2013-02-14 14:36:04 -0800811 + " surface " + mSurfaceControl + " session " + mSession
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700812 + ": " + e.toString());
813 }
814
815 mSurfaceShown = false;
Mathias Agopian29479eb2013-02-14 14:36:04 -0800816 mSurfaceControl = null;
Craig Mautnere8552142012-11-07 13:55:47 -0800817 mWin.mHasSurface = false;
Craig Mautnerbf08af32012-05-16 19:43:42 -0700818 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700819 }
820 }
821
Craig Mautner96868332012-12-04 14:29:11 -0800822 void destroyDeferredSurfaceLocked() {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700823 try {
824 if (mPendingDestroySurface != null) {
825 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
826 RuntimeException e = null;
827 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
828 e = new RuntimeException();
829 e.fillInStackTrace();
830 }
831 WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
832 }
833 mPendingDestroySurface.destroy();
Craig Mautner96868332012-12-04 14:29:11 -0800834 mAnimator.hideWallpapersLocked(mWin);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700835 }
836 } catch (RuntimeException e) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700837 Slog.w(TAG, "Exception thrown when destroying Window "
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700838 + this + " surface " + mPendingDestroySurface
839 + " session " + mSession + ": " + e.toString());
840 }
841 mSurfaceDestroyDeferred = false;
842 mPendingDestroySurface = null;
843 }
844
845 void computeShownFrameLocked() {
846 final boolean selfTransformation = mHasLocalTransformation;
847 Transformation attachedTransformation =
Craig Mautner322e4032012-07-13 13:35:20 -0700848 (mAttachedWinAnimator != null && mAttachedWinAnimator.mHasLocalTransformation)
849 ? mAttachedWinAnimator.mTransformation : null;
850 Transformation appTransformation = (mAppAnimator != null && mAppAnimator.hasTransformation)
851 ? mAppAnimator.transformation : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700852
853 // Wallpapers are animated based on the "real" window they
854 // are currently targeting.
Craig Mautner96868332012-12-04 14:29:11 -0800855 if (mIsWallpaper && mService.mLowerWallpaperTarget == null
856 && mService.mWallpaperTarget != null) {
857 final WindowStateAnimator wallpaperAnimator = mService.mWallpaperTarget.mWinAnimator;
Craig Mautner918b53b2012-07-09 14:15:54 -0700858 if (wallpaperAnimator.mHasLocalTransformation &&
859 wallpaperAnimator.mAnimation != null &&
860 !wallpaperAnimator.mAnimation.getDetachWallpaper()) {
861 attachedTransformation = wallpaperAnimator.mTransformation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700862 if (WindowManagerService.DEBUG_WALLPAPER && attachedTransformation != null) {
863 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
864 }
865 }
Craig Mautner96868332012-12-04 14:29:11 -0800866 final AppWindowAnimator wpAppAnimator = mAnimator.getWallpaperAppAnimator();
Craig Mautner918b53b2012-07-09 14:15:54 -0700867 if (wpAppAnimator != null && wpAppAnimator.hasTransformation
868 && wpAppAnimator.animation != null
869 && !wpAppAnimator.animation.getDetachWallpaper()) {
Craig Mautner59431632012-04-04 11:56:44 -0700870 appTransformation = wpAppAnimator.transformation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700871 if (WindowManagerService.DEBUG_WALLPAPER && appTransformation != null) {
872 Slog.v(TAG, "WP target app xform: " + appTransformation);
873 }
874 }
875 }
876
Craig Mautnera91f9e22012-09-14 16:22:08 -0700877 final int displayId = mWin.getDisplayId();
878 final ScreenRotationAnimation screenRotationAnimation =
879 mAnimator.getScreenRotationAnimationLocked(displayId);
880 final boolean screenAnimation =
881 screenRotationAnimation != null && screenRotationAnimation.isAnimating();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700882 if (selfTransformation || attachedTransformation != null
883 || appTransformation != null || screenAnimation) {
884 // cache often used attributes locally
885 final Rect frame = mWin.mFrame;
886 final float tmpFloats[] = mService.mTmpFloats;
887 final Matrix tmpMatrix = mWin.mTmpMatrix;
888
889 // Compute the desired transformation.
Dianne Hackborn4b169692012-11-29 17:51:24 -0800890 if (screenAnimation && screenRotationAnimation.isRotating()) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700891 // If we are doing a screen animation, the global rotation
892 // applied to windows can result in windows that are carefully
893 // aligned with each other to slightly separate, allowing you
894 // to see what is behind them. An unsightly mess. This...
895 // thing... magically makes it call good: scale each window
896 // slightly (two pixels larger in each dimension, from the
897 // window's center).
898 final float w = frame.width();
899 final float h = frame.height();
900 if (w>=1 && h>=1) {
901 tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2);
902 } else {
903 tmpMatrix.reset();
904 }
905 } else {
906 tmpMatrix.reset();
907 }
908 tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale);
909 if (selfTransformation) {
910 tmpMatrix.postConcat(mTransformation.getMatrix());
911 }
912 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
913 if (attachedTransformation != null) {
914 tmpMatrix.postConcat(attachedTransformation.getMatrix());
915 }
916 if (appTransformation != null) {
917 tmpMatrix.postConcat(appTransformation.getMatrix());
918 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700919 if (mAnimator.mUniverseBackground != null) {
920 tmpMatrix.postConcat(mAnimator.mUniverseBackground.mUniverseTransform.getMatrix());
921 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700922 if (screenAnimation) {
Craig Mautnera91f9e22012-09-14 16:22:08 -0700923 tmpMatrix.postConcat(screenRotationAnimation.getEnterTransformation().getMatrix());
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700924 }
Svetoslav Ganov545252f2012-12-10 18:29:24 -0800925 //TODO (multidisplay): Magnification is supported only for the default display.
926 if (mService.mDisplayMagnifier != null
927 && mWin.getDisplayId() == Display.DEFAULT_DISPLAY) {
928 MagnificationSpec spec = mService.mDisplayMagnifier
929 .getMagnificationSpecForWindowLocked(mWin);
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -0700930 if (spec != null && !spec.isNop()) {
931 tmpMatrix.postScale(spec.scale, spec.scale);
932 tmpMatrix.postTranslate(spec.offsetX, spec.offsetY);
933 }
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700934 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700935
936 // "convert" it into SurfaceFlinger's format
937 // (a 2x2 matrix + an offset)
938 // Here we must not transform the position of the surface
939 // since it is already included in the transformation.
940 //Slog.i(TAG, "Transform: " + matrix);
941
942 mHaveMatrix = true;
943 tmpMatrix.getValues(tmpFloats);
944 mDsDx = tmpFloats[Matrix.MSCALE_X];
945 mDtDx = tmpFloats[Matrix.MSKEW_Y];
946 mDsDy = tmpFloats[Matrix.MSKEW_X];
947 mDtDy = tmpFloats[Matrix.MSCALE_Y];
948 float x = tmpFloats[Matrix.MTRANS_X];
949 float y = tmpFloats[Matrix.MTRANS_Y];
950 int w = frame.width();
951 int h = frame.height();
952 mWin.mShownFrame.set(x, y, x+w, y+h);
953
954 // Now set the alpha... but because our current hardware
955 // can't do alpha transformation on a non-opaque surface,
956 // turn it off if we are running an animation that is also
957 // transforming since it is more important to have that
958 // animation be smooth.
959 mShownAlpha = mAlpha;
960 if (!mService.mLimitedAlphaCompositing
961 || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format)
962 || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
963 && x == frame.left && y == frame.top))) {
964 //Slog.i(TAG, "Applying alpha transform");
965 if (selfTransformation) {
966 mShownAlpha *= mTransformation.getAlpha();
967 }
968 if (attachedTransformation != null) {
969 mShownAlpha *= attachedTransformation.getAlpha();
970 }
971 if (appTransformation != null) {
972 mShownAlpha *= appTransformation.getAlpha();
973 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700974 if (mAnimator.mUniverseBackground != null) {
975 mShownAlpha *= mAnimator.mUniverseBackground.mUniverseTransform.getAlpha();
976 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700977 if (screenAnimation) {
Craig Mautnera91f9e22012-09-14 16:22:08 -0700978 mShownAlpha *= screenRotationAnimation.getEnterTransformation().getAlpha();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700979 }
980 } else {
981 //Slog.i(TAG, "Not applying alpha transform");
982 }
983
Craig Mautnera91f9e22012-09-14 16:22:08 -0700984 if ((DEBUG_SURFACE_TRACE || WindowManagerService.localLOGV)
985 && (mShownAlpha == 1.0 || mShownAlpha == 0.0)) Slog.v(
986 TAG, "computeShownFrameLocked: Animating " + this + " mAlpha=" + mAlpha
987 + " self=" + (selfTransformation ? mTransformation.getAlpha() : "null")
988 + " attached=" + (attachedTransformation == null ?
989 "null" : attachedTransformation.getAlpha())
990 + " app=" + (appTransformation == null ? "null" : appTransformation.getAlpha())
991 + " screen=" + (screenAnimation ?
992 screenRotationAnimation.getEnterTransformation().getAlpha() : "null"));
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700993 return;
Craig Mautner96868332012-12-04 14:29:11 -0800994 } else if (mIsWallpaper && mService.mInnerFields.mWallpaperActionPending) {
Craig Mautner4d7349b2012-04-20 14:52:47 -0700995 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700996 }
997
998 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautner4d7349b2012-04-20 14:52:47 -0700999 TAG, "computeShownFrameLocked: " + this +
1000 " not attached, mAlpha=" + mAlpha);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001001
1002 final boolean applyUniverseTransformation = (mAnimator.mUniverseBackground != null
1003 && mWin.mAttrs.type != WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND
1004 && mWin.mBaseLayer < mAnimator.mAboveUniverseLayer);
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001005 MagnificationSpec spec = null;
1006 //TODO (multidisplay): Magnification is supported only for the default display.
1007 if (mService.mDisplayMagnifier != null && mWin.getDisplayId() == Display.DEFAULT_DISPLAY) {
1008 spec = mService.mDisplayMagnifier.getMagnificationSpecForWindowLocked(mWin);
1009 }
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001010 if (applyUniverseTransformation || spec != null) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001011 final Rect frame = mWin.mFrame;
1012 final float tmpFloats[] = mService.mTmpFloats;
1013 final Matrix tmpMatrix = mWin.mTmpMatrix;
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001014
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001015 tmpMatrix.setScale(mWin.mGlobalScale, mWin.mGlobalScale);
1016 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001017
1018 if (applyUniverseTransformation) {
1019 tmpMatrix.postConcat(mAnimator.mUniverseBackground.mUniverseTransform.getMatrix());
1020 }
1021
1022 if (spec != null && !spec.isNop()) {
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -07001023 tmpMatrix.postScale(spec.scale, spec.scale);
1024 tmpMatrix.postTranslate(spec.offsetX, spec.offsetY);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001025 }
1026
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001027 tmpMatrix.getValues(tmpFloats);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001028
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001029 mHaveMatrix = true;
1030 mDsDx = tmpFloats[Matrix.MSCALE_X];
1031 mDtDx = tmpFloats[Matrix.MSKEW_Y];
1032 mDsDy = tmpFloats[Matrix.MSKEW_X];
1033 mDtDy = tmpFloats[Matrix.MSCALE_Y];
1034 float x = tmpFloats[Matrix.MTRANS_X];
1035 float y = tmpFloats[Matrix.MTRANS_Y];
1036 int w = frame.width();
1037 int h = frame.height();
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001038 mWin.mShownFrame.set(x, y, x + w, y + h);
1039
1040 mShownAlpha = mAlpha;
1041 if (applyUniverseTransformation) {
1042 mShownAlpha *= mAnimator.mUniverseBackground.mUniverseTransform.getAlpha();
1043 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001044 } else {
1045 mWin.mShownFrame.set(mWin.mFrame);
1046 if (mWin.mXOffset != 0 || mWin.mYOffset != 0) {
1047 mWin.mShownFrame.offset(mWin.mXOffset, mWin.mYOffset);
1048 }
1049 mShownAlpha = mAlpha;
1050 mHaveMatrix = false;
1051 mDsDx = mWin.mGlobalScale;
1052 mDtDx = 0;
1053 mDsDy = 0;
1054 mDtDy = mWin.mGlobalScale;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001055 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001056 }
1057
1058 void applyDecorRect(final Rect decorRect) {
1059 final WindowState w = mWin;
1060 // Compute the offset of the window in relation to the decor rect.
1061 final int offX = w.mXOffset + w.mFrame.left;
1062 final int offY = w.mYOffset + w.mFrame.top;
1063 // Initialize the decor rect to the entire frame.
1064 w.mSystemDecorRect.set(0, 0, w.mFrame.width(), w.mFrame.height());
1065 // Intersect with the decor rect, offsetted by window position.
1066 w.mSystemDecorRect.intersect(decorRect.left-offX, decorRect.top-offY,
1067 decorRect.right-offX, decorRect.bottom-offY);
1068 // If size compatibility is being applied to the window, the
1069 // surface is scaled relative to the screen. Also apply this
1070 // scaling to the crop rect. We aren't using the standard rect
1071 // scale function because we want to round things to make the crop
1072 // always round to a larger rect to ensure we don't crop too
1073 // much and hide part of the window that should be seen.
1074 if (w.mEnforceSizeCompat && w.mInvGlobalScale != 1.0f) {
1075 final float scale = w.mInvGlobalScale;
1076 w.mSystemDecorRect.left = (int) (w.mSystemDecorRect.left * scale - 0.5f);
1077 w.mSystemDecorRect.top = (int) (w.mSystemDecorRect.top * scale - 0.5f);
1078 w.mSystemDecorRect.right = (int) ((w.mSystemDecorRect.right+1) * scale - 0.5f);
1079 w.mSystemDecorRect.bottom = (int) ((w.mSystemDecorRect.bottom+1) * scale - 0.5f);
1080 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001081 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001082
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001083 void updateSurfaceWindowCrop(final boolean recoveringMemory) {
1084 final WindowState w = mWin;
Craig Mautner69b08182012-09-05 13:07:13 -07001085 DisplayInfo displayInfo = w.mDisplayContent.getDisplayInfo();
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001086
1087 // Need to recompute a new system decor rect each time.
1088 if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
1089 // Currently can't do this cropping for scaled windows. We'll
1090 // just keep the crop rect the same as the source surface.
1091 w.mSystemDecorRect.set(0, 0, w.mRequestedWidth, w.mRequestedHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07001092 } else if (!w.isDefaultDisplay()) {
Jeff Brown28e0b092012-09-25 11:31:28 -07001093 // On a different display there is no system decor. Crop the window
1094 // by the screen boundaries.
Jeff Brown36714102012-09-24 17:36:06 -07001095 w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height());
Jeff Brown28e0b092012-09-25 11:31:28 -07001096 w.mSystemDecorRect.intersect(-w.mCompatFrame.left, -w.mCompatFrame.top,
1097 displayInfo.logicalWidth - w.mCompatFrame.left,
1098 displayInfo.logicalHeight - w.mCompatFrame.top);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001099 } else if (w.mLayer >= mService.mSystemDecorLayer) {
1100 // Above the decor layer is easy, just use the entire window.
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001101 // Unless we have a universe background... in which case all the
1102 // windows need to be cropped by the screen, so they don't cover
1103 // the universe background.
1104 if (mAnimator.mUniverseBackground == null) {
1105 w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(),
1106 w.mCompatFrame.height());
1107 } else {
1108 applyDecorRect(mService.mScreenRect);
1109 }
1110 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND) {
1111 // The universe background isn't cropped.
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001112 w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(),
1113 w.mCompatFrame.height());
1114 } else {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001115 applyDecorRect(mService.mSystemDecorRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001116 }
1117
1118 if (!w.mSystemDecorRect.equals(w.mLastSystemDecorRect)) {
1119 w.mLastSystemDecorRect.set(w.mSystemDecorRect);
1120 try {
1121 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1122 "CROP " + w.mSystemDecorRect.toShortString(), null);
Mathias Agopian29479eb2013-02-14 14:36:04 -08001123 mSurfaceControl.setWindowCrop(w.mSystemDecorRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001124 } catch (RuntimeException e) {
1125 Slog.w(TAG, "Error setting crop surface of " + w
1126 + " crop=" + w.mSystemDecorRect.toShortString(), e);
1127 if (!recoveringMemory) {
1128 mService.reclaimSomeSurfaceMemoryLocked(this, "crop", true);
1129 }
1130 }
1131 }
1132 }
1133
Craig Mautnera91f9e22012-09-14 16:22:08 -07001134 void setSurfaceBoundariesLocked(final boolean recoveringMemory) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001135 final WindowState w = mWin;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001136 int width, height;
1137 if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
1138 // for a scaled surface, we just want to use
1139 // the requested size.
1140 width = w.mRequestedWidth;
1141 height = w.mRequestedHeight;
1142 } else {
1143 width = w.mCompatFrame.width();
1144 height = w.mCompatFrame.height();
1145 }
1146
1147 if (width < 1) {
1148 width = 1;
1149 }
1150 if (height < 1) {
1151 height = 1;
1152 }
1153 final boolean surfaceResized = mSurfaceW != width || mSurfaceH != height;
1154 if (surfaceResized) {
1155 mSurfaceW = width;
1156 mSurfaceH = height;
1157 }
1158
Craig Mautner4d7349b2012-04-20 14:52:47 -07001159 final float left = w.mShownFrame.left;
1160 final float top = w.mShownFrame.top;
1161 if (mSurfaceX != left || mSurfaceY != top) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001162 try {
1163 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
Craig Mautner4d7349b2012-04-20 14:52:47 -07001164 "POS " + left + ", " + top, null);
1165 mSurfaceX = left;
1166 mSurfaceY = top;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001167 mSurfaceControl.setPosition(left, top);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001168 } catch (RuntimeException e) {
1169 Slog.w(TAG, "Error positioning surface of " + w
Craig Mautner4d7349b2012-04-20 14:52:47 -07001170 + " pos=(" + left
1171 + "," + top + ")", e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001172 if (!recoveringMemory) {
1173 mService.reclaimSomeSurfaceMemoryLocked(this, "position", true);
1174 }
1175 }
1176 }
1177
1178 if (surfaceResized) {
1179 try {
1180 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1181 "SIZE " + width + "x" + height, null);
1182 mSurfaceResized = true;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001183 mSurfaceControl.setSize(width, height);
Craig Mautner76a71652012-09-03 23:23:58 -07001184 final int displayId = w.mDisplayContent.getDisplayId();
1185 mAnimator.setPendingLayoutChanges(displayId,
1186 WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
Craig Mautner3a67f352012-05-07 11:21:33 -07001187 if ((w.mAttrs.flags & LayoutParams.FLAG_DIM_BEHIND) != 0) {
Craig Mautner1420b932012-12-28 17:14:38 -08001188 mService.startDimmingLocked(this, w.mExiting ? 0 : w.mAttrs.dimAmount);
Craig Mautner3a67f352012-05-07 11:21:33 -07001189 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001190 } catch (RuntimeException e) {
1191 // If something goes wrong with the surface (such
1192 // as running out of memory), don't take down the
1193 // entire system.
1194 Slog.e(TAG, "Error resizing surface of " + w
1195 + " size=(" + width + "x" + height + ")", e);
1196 if (!recoveringMemory) {
1197 mService.reclaimSomeSurfaceMemoryLocked(this, "size", true);
1198 }
1199 }
1200 }
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001201
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001202 updateSurfaceWindowCrop(recoveringMemory);
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001203 }
1204
1205 public void prepareSurfaceLocked(final boolean recoveringMemory) {
1206 final WindowState w = mWin;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001207 if (mSurfaceControl == null) {
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001208 if (w.mOrientationChanging) {
1209 if (DEBUG_ORIENTATION) {
1210 Slog.v(TAG, "Orientation change skips hidden " + w);
1211 }
1212 w.mOrientationChanging = false;
1213 }
1214 return;
1215 }
1216
1217 boolean displayed = false;
1218
1219 computeShownFrameLocked();
1220
Craig Mautnera91f9e22012-09-14 16:22:08 -07001221 setSurfaceBoundariesLocked(recoveringMemory);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001222
Craig Mautner918b53b2012-07-09 14:15:54 -07001223 if (mIsWallpaper && !mWin.mWallpaperVisible) {
Craig Mautner0fa77c12012-06-11 15:57:19 -07001224 // Wallpaper is no longer visible and there is no wp target => hide it.
1225 hide();
Craig Mautner72669d12012-12-18 17:23:54 -08001226 } else if (w.mAttachedHidden || !w.isOnScreen()) {
Craig Mautner0afddcb2012-05-08 15:38:00 -07001227 hide();
Craig Mautner96868332012-12-04 14:29:11 -08001228 mAnimator.hideWallpapersLocked(w);
Craig Mautnerb9836b92012-06-11 11:40:09 -07001229
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001230 // If we are waiting for this window to handle an
1231 // orientation change, well, it is hidden, so
1232 // doesn't really matter. Note that this does
1233 // introduce a potential glitch if the window
1234 // becomes unhidden before it has drawn for the
1235 // new orientation.
1236 if (w.mOrientationChanging) {
1237 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001238 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001239 "Orientation change skips hidden " + w);
1240 }
1241 } else if (mLastLayer != mAnimLayer
1242 || mLastAlpha != mShownAlpha
1243 || mLastDsDx != mDsDx
1244 || mLastDtDx != mDtDx
1245 || mLastDsDy != mDsDy
1246 || mLastDtDy != mDtDy
1247 || w.mLastHScale != w.mHScale
1248 || w.mLastVScale != w.mVScale
Craig Mautner749a7bb2012-04-02 13:49:53 -07001249 || mLastHidden) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001250 displayed = true;
1251 mLastAlpha = mShownAlpha;
1252 mLastLayer = mAnimLayer;
1253 mLastDsDx = mDsDx;
1254 mLastDtDx = mDtDx;
1255 mLastDsDy = mDsDy;
1256 mLastDtDy = mDtDy;
1257 w.mLastHScale = w.mHScale;
1258 w.mLastVScale = w.mVScale;
1259 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1260 "alpha=" + mShownAlpha + " layer=" + mAnimLayer
1261 + " matrix=[" + (mDsDx*w.mHScale)
1262 + "," + (mDtDx*w.mVScale)
1263 + "][" + (mDsDy*w.mHScale)
1264 + "," + (mDtDy*w.mVScale) + "]", null);
Mathias Agopian29479eb2013-02-14 14:36:04 -08001265 if (mSurfaceControl != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001266 try {
1267 mSurfaceAlpha = mShownAlpha;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001268 mSurfaceControl.setAlpha(mShownAlpha);
Craig Mautnerad5725d2012-06-05 10:20:56 -07001269 mSurfaceLayer = mAnimLayer;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001270 mSurfaceControl.setLayer(mAnimLayer);
1271 mSurfaceControl.setMatrix(
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001272 mDsDx*w.mHScale, mDtDx*w.mVScale,
1273 mDsDy*w.mHScale, mDtDy*w.mVScale);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001274
1275 if (mLastHidden && mDrawState == HAS_DRAWN) {
1276 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1277 "SHOW (performLayout)", null);
1278 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
1279 + " during relayout");
1280 if (showSurfaceRobustlyLocked()) {
1281 mLastHidden = false;
Craig Mautner918b53b2012-07-09 14:15:54 -07001282 if (mIsWallpaper) {
Craig Mautner507a2ee2012-06-13 08:39:38 -07001283 mService.dispatchWallpaperVisibility(w, true);
1284 }
Craig Mautner749a7bb2012-04-02 13:49:53 -07001285 } else {
1286 w.mOrientationChanging = false;
1287 }
1288 }
Mathias Agopian29479eb2013-02-14 14:36:04 -08001289 if (mSurfaceControl != null) {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001290 w.mToken.hasVisible = true;
1291 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001292 } catch (RuntimeException e) {
1293 Slog.w(TAG, "Error updating surface in " + w, e);
1294 if (!recoveringMemory) {
1295 mService.reclaimSomeSurfaceMemoryLocked(this, "update", true);
1296 }
1297 }
1298 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001299 } else {
Craig Mautner9e809442012-06-22 17:13:04 -07001300 if (DEBUG_ANIM && isAnimating()) {
1301 Slog.v(TAG, "prepareSurface: No changes in animation for " + this);
Craig Mautner83339b42012-05-01 22:13:23 -07001302 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001303 displayed = true;
1304 }
1305
1306 if (displayed) {
1307 if (w.mOrientationChanging) {
1308 if (!w.isDrawnLw()) {
Craig Mautner2639da52012-07-09 09:39:06 -07001309 mAnimator.mBulkUpdateParams &= ~SET_ORIENTATION_CHANGE_COMPLETE;
Dianne Hackborna57c6952013-03-29 14:46:40 -07001310 mAnimator.mLastWindowFreezeSource = w;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001311 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001312 "Orientation continue waiting for draw in " + w);
1313 } else {
1314 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001315 if (DEBUG_ORIENTATION) Slog.v(TAG, "Orientation change complete in " + w);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001316 }
1317 }
1318 w.mToken.hasVisible = true;
1319 }
1320 }
1321
Craig Mautneref655012013-01-03 11:20:24 -08001322 void setTransparentRegionHintLocked(final Region region) {
Mathias Agopian29479eb2013-02-14 14:36:04 -08001323 if (mSurfaceControl == null) {
Craig Mautner1f4e0cc2012-04-10 14:24:38 -07001324 Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true");
1325 return;
1326 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001327 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1328 ">>> OPEN TRANSACTION setTransparentRegion");
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001329 SurfaceControl.openTransaction();
Craig Mautner48ba1e72012-04-02 13:18:16 -07001330 try {
1331 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
1332 "transparentRegionHint=" + region, null);
Mathias Agopian29479eb2013-02-14 14:36:04 -08001333 mSurfaceControl.setTransparentRegionHint(region);
Craig Mautner48ba1e72012-04-02 13:18:16 -07001334 } finally {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001335 SurfaceControl.closeTransaction();
Craig Mautner48ba1e72012-04-02 13:18:16 -07001336 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1337 "<<< CLOSE TRANSACTION setTransparentRegion");
1338 }
1339 }
1340
Craig Mautner58106812012-12-28 12:27:40 -08001341 void setWallpaperOffset(RectF shownFrame) {
1342 final int left = (int) shownFrame.left;
1343 final int top = (int) shownFrame.top;
1344 if (mSurfaceX != left || mSurfaceY != top) {
1345 mSurfaceX = left;
1346 mSurfaceY = top;
1347 if (mAnimating) {
1348 // If this window (or its app token) is animating, then the position
1349 // of the surface will be re-computed on the next animation frame.
1350 // We can't poke it directly here because it depends on whatever
1351 // transformation is being applied by the animation.
1352 return;
1353 }
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001354 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
Craig Mautner58106812012-12-28 12:27:40 -08001355 ">>> OPEN TRANSACTION setWallpaperOffset");
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001356 SurfaceControl.openTransaction();
Craig Mautner58106812012-12-28 12:27:40 -08001357 try {
1358 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
1359 "POS " + left + ", " + top, null);
Mathias Agopian29479eb2013-02-14 14:36:04 -08001360 mSurfaceControl.setPosition(mWin.mFrame.left + left, mWin.mFrame.top + top);
Craig Mautner58106812012-12-28 12:27:40 -08001361 updateSurfaceWindowCrop(false);
1362 } catch (RuntimeException e) {
1363 Slog.w(TAG, "Error positioning surface of " + mWin
1364 + " pos=(" + left + "," + top + ")", e);
1365 } finally {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001366 SurfaceControl.closeTransaction();
Craig Mautner58106812012-12-28 12:27:40 -08001367 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1368 "<<< CLOSE TRANSACTION setWallpaperOffset");
1369 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001370 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001371 }
1372
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001373 // This must be called while inside a transaction.
1374 boolean performShowLocked() {
Craig Mautner5962b122012-10-05 14:45:52 -07001375 if (mWin.isHiddenFromUserLocked()) {
Craig Mautner88400d32012-09-30 12:35:45 -07001376 Slog.w(TAG, "current user violation " + mService.mCurrentUserId + " trying to display "
Craig Mautnera2d7b112012-08-21 15:12:20 -07001377 + this + ", type " + mWin.mAttrs.type + ", belonging to " + mWin.mOwnerUid);
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001378 return false;
1379 }
Craig Mautner6fbda632012-07-03 09:26:39 -07001380 if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
1381 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001382 RuntimeException e = null;
1383 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
1384 e = new RuntimeException();
1385 e.fillInStackTrace();
1386 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001387 Slog.v(TAG, "performShow on " + this
Craig Mautner749a7bb2012-04-02 13:49:53 -07001388 + ": mDrawState=" + mDrawState + " readyForDisplay="
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001389 + mWin.isReadyForDisplayIgnoringKeyguard()
Craig Mautner6fbda632012-07-03 09:26:39 -07001390 + " starting=" + (mWin.mAttrs.type == TYPE_APPLICATION_STARTING)
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001391 + " during animation: policyVis=" + mWin.mPolicyVisibility
1392 + " attHidden=" + mWin.mAttachedHidden
1393 + " tok.hiddenRequested="
1394 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
1395 + " tok.hidden="
1396 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
1397 + " animating=" + mAnimating
1398 + " tok animating="
Craig Mautner322e4032012-07-13 13:35:20 -07001399 + (mAppAnimator != null ? mAppAnimator.animating : false), e);
Craig Mautner6fbda632012-07-03 09:26:39 -07001400 }
1401 if (mDrawState == READY_TO_SHOW && mWin.isReadyForDisplayIgnoringKeyguard()) {
1402 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
1403 WindowManagerService.logSurface(mWin, "SHOW (performShowLocked)", null);
1404 if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
1405 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
1406 Slog.v(TAG, "Showing " + this
1407 + " during animation: policyVis=" + mWin.mPolicyVisibility
1408 + " attHidden=" + mWin.mAttachedHidden
1409 + " tok.hiddenRequested="
1410 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
1411 + " tok.hidden="
1412 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
1413 + " animating=" + mAnimating
1414 + " tok animating="
Craig Mautner322e4032012-07-13 13:35:20 -07001415 + (mAppAnimator != null ? mAppAnimator.animating : false));
Craig Mautner6fbda632012-07-03 09:26:39 -07001416 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001417
1418 mService.enableScreenIfNeededLocked();
1419
1420 applyEnterAnimationLocked();
1421
Craig Mautnerde6198e2012-04-19 09:59:31 -07001422 // Force the show in the next prepareSurfaceLocked() call.
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001423 mLastAlpha = -1;
Craig Mautneref25d7a2012-05-15 23:01:47 -07001424 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM)
1425 Slog.v(TAG, "performShowLocked: mDrawState=HAS_DRAWN in " + this);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001426 mDrawState = HAS_DRAWN;
Craig Mautner96868332012-12-04 14:29:11 -08001427 mService.scheduleAnimationLocked();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001428
1429 int i = mWin.mChildWindows.size();
1430 while (i > 0) {
1431 i--;
1432 WindowState c = mWin.mChildWindows.get(i);
1433 if (c.mAttachedHidden) {
1434 c.mAttachedHidden = false;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001435 if (c.mWinAnimator.mSurfaceControl != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001436 c.mWinAnimator.performShowLocked();
1437 // It hadn't been shown, which means layout not
1438 // performed on it, so now we want to make sure to
1439 // do a layout. If called from within the transaction
1440 // loop, this will cause it to restart with a new
1441 // layout.
Craig Mautner19d59bc2012-09-04 11:15:56 -07001442 c.mDisplayContent.layoutNeeded = true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001443 }
1444 }
1445 }
1446
1447 if (mWin.mAttrs.type != TYPE_APPLICATION_STARTING
1448 && mWin.mAppToken != null) {
1449 mWin.mAppToken.firstWindowDrawn = true;
1450
1451 if (mWin.mAppToken.startingData != null) {
1452 if (WindowManagerService.DEBUG_STARTING_WINDOW ||
Craig Mautnerd87946b2012-03-29 18:00:19 -07001453 WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001454 "Finish starting " + mWin.mToken
1455 + ": first real window is shown, no animation");
1456 // If this initial window is animating, stop it -- we
1457 // will do an animation to reveal it from behind the
1458 // starting window, so there is no need for it to also
1459 // be doing its own stuff.
Craig Mautner4d7349b2012-04-20 14:52:47 -07001460 clearAnimation();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001461 mService.mFinishedStarting.add(mWin.mAppToken);
1462 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
1463 }
1464 mWin.mAppToken.updateReportedVisibilityLocked();
1465 }
1466
1467 return true;
1468 }
1469
1470 return false;
1471 }
1472
1473 /**
1474 * Have the surface flinger show a surface, robustly dealing with
1475 * error conditions. In particular, if there is not enough memory
1476 * to show the surface, then we will try to get rid of other surfaces
1477 * in order to succeed.
1478 *
1479 * @return Returns true if the surface was successfully shown.
1480 */
1481 boolean showSurfaceRobustlyLocked() {
1482 try {
Mathias Agopian29479eb2013-02-14 14:36:04 -08001483 if (mSurfaceControl != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001484 mSurfaceShown = true;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001485 mSurfaceControl.show();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001486 if (mWin.mTurnOnScreen) {
1487 if (DEBUG_VISIBILITY) Slog.v(TAG,
1488 "Show surface turning screen on: " + mWin);
1489 mWin.mTurnOnScreen = false;
Craig Mautner7d8df392012-04-06 15:26:23 -07001490 mAnimator.mBulkUpdateParams |= SET_TURN_ON_SCREEN;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001491 }
1492 }
1493 return true;
1494 } catch (RuntimeException e) {
Mathias Agopian29479eb2013-02-14 14:36:04 -08001495 Slog.w(TAG, "Failure showing surface " + mSurfaceControl + " in " + mWin, e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001496 }
1497
1498 mService.reclaimSomeSurfaceMemoryLocked(this, "show", true);
1499
1500 return false;
1501 }
1502
1503 void applyEnterAnimationLocked() {
1504 final int transit;
1505 if (mEnterAnimationPending) {
1506 mEnterAnimationPending = false;
1507 transit = WindowManagerPolicy.TRANSIT_ENTER;
1508 } else {
1509 transit = WindowManagerPolicy.TRANSIT_SHOW;
1510 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001511 applyAnimationLocked(transit, true);
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001512 //TODO (multidisplay): Magnification is supported only for the default display.
1513 if (mService.mDisplayMagnifier != null
1514 && mWin.getDisplayId() == Display.DEFAULT_DISPLAY) {
1515 mService.mDisplayMagnifier.onWindowTransitionLocked(mWin, transit);
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -07001516 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001517 }
1518
1519 /**
1520 * Choose the correct animation and set it to the passed WindowState.
Craig Mautner4b71aa12012-12-27 17:20:01 -08001521 * @param transit If AppTransition.TRANSIT_PREVIEW_DONE and the app window has been drawn
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001522 * then the animation will be app_starting_exit. Any other value loads the animation from
1523 * the switch statement below.
1524 * @param isEntrance The animation type the last time this was called. Used to keep from
1525 * loading the same animation twice.
1526 * @return true if an animation has been loaded.
1527 */
1528 boolean applyAnimationLocked(int transit, boolean isEntrance) {
1529 if (mLocalAnimating && mAnimationIsEntrance == isEntrance) {
1530 // If we are trying to apply an animation, but already running
1531 // an animation of the same type, then just leave that one alone.
1532 return true;
1533 }
1534
1535 // Only apply an animation if the display isn't frozen. If it is
1536 // frozen, there is no reason to animate and it can cause strange
1537 // artifacts when we unfreeze the display if some different animation
1538 // is running.
1539 if (mService.okToDisplay()) {
1540 int anim = mPolicy.selectAnimationLw(mWin, transit);
1541 int attr = -1;
1542 Animation a = null;
1543 if (anim != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001544 a = anim != -1 ? AnimationUtils.loadAnimation(mContext, anim) : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001545 } else {
1546 switch (transit) {
1547 case WindowManagerPolicy.TRANSIT_ENTER:
1548 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
1549 break;
1550 case WindowManagerPolicy.TRANSIT_EXIT:
1551 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
1552 break;
1553 case WindowManagerPolicy.TRANSIT_SHOW:
1554 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
1555 break;
1556 case WindowManagerPolicy.TRANSIT_HIDE:
1557 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
1558 break;
1559 }
1560 if (attr >= 0) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001561 a = mService.mAppTransition.loadAnimation(mWin.mAttrs, attr);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001562 }
1563 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001564 if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001565 "applyAnimation: win=" + this
1566 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
Craig Mautner4d7349b2012-04-20 14:52:47 -07001567 + " a=" + a
Craig Mautner8863cca2012-09-18 15:04:34 -07001568 + " transit=" + transit
Craig Mautner83339b42012-05-01 22:13:23 -07001569 + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001570 if (a != null) {
1571 if (WindowManagerService.DEBUG_ANIM) {
1572 RuntimeException e = null;
1573 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
1574 e = new RuntimeException();
1575 e.fillInStackTrace();
1576 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001577 Slog.v(TAG, "Loaded animation " + a + " for " + this, e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001578 }
1579 setAnimation(a);
1580 mAnimationIsEntrance = isEntrance;
1581 }
1582 } else {
1583 clearAnimation();
1584 }
1585
1586 return mAnimation != null;
1587 }
1588
Craig Mautnera2c77052012-03-26 12:14:43 -07001589 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1590 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
1591 || mAnimation != null) {
1592 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
1593 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
1594 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
1595 pw.print(" mAnimation="); pw.println(mAnimation);
1596 }
1597 if (mHasTransformation || mHasLocalTransformation) {
1598 pw.print(prefix); pw.print("XForm: has=");
1599 pw.print(mHasTransformation);
1600 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
1601 pw.print(" "); mTransformation.printShortString(pw);
1602 pw.println();
1603 }
Mathias Agopian29479eb2013-02-14 14:36:04 -08001604 if (mSurfaceControl != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001605 if (dumpAll) {
Mathias Agopian29479eb2013-02-14 14:36:04 -08001606 pw.print(prefix); pw.print("mSurface="); pw.println(mSurfaceControl);
Craig Mautner6fbda632012-07-03 09:26:39 -07001607 pw.print(prefix); pw.print("mDrawState=");
1608 pw.print(drawStateToString(mDrawState));
Craig Mautner749a7bb2012-04-02 13:49:53 -07001609 pw.print(" mLastHidden="); pw.println(mLastHidden);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001610 }
1611 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
1612 pw.print(" layer="); pw.print(mSurfaceLayer);
1613 pw.print(" alpha="); pw.print(mSurfaceAlpha);
1614 pw.print(" rect=("); pw.print(mSurfaceX);
1615 pw.print(","); pw.print(mSurfaceY);
1616 pw.print(") "); pw.print(mSurfaceW);
1617 pw.print(" x "); pw.println(mSurfaceH);
1618 }
1619 if (mPendingDestroySurface != null) {
1620 pw.print(prefix); pw.print("mPendingDestroySurface=");
1621 pw.println(mPendingDestroySurface);
1622 }
1623 if (mSurfaceResized || mSurfaceDestroyDeferred) {
1624 pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized);
1625 pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred);
1626 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001627 if (mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND) {
1628 pw.print(prefix); pw.print("mUniverseTransform=");
1629 mUniverseTransform.printShortString(pw);
1630 pw.println();
1631 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001632 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
1633 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
1634 pw.print(" mAlpha="); pw.print(mAlpha);
1635 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
1636 }
1637 if (mHaveMatrix || mWin.mGlobalScale != 1) {
1638 pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale);
1639 pw.print(" mDsDx="); pw.print(mDsDx);
1640 pw.print(" mDtDx="); pw.print(mDtDx);
1641 pw.print(" mDsDy="); pw.print(mDsDy);
1642 pw.print(" mDtDy="); pw.println(mDtDy);
1643 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001644 }
1645
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001646 @Override
1647 public String toString() {
Dianne Hackborn529e7442012-11-01 14:22:28 -07001648 StringBuffer sb = new StringBuffer("WindowStateAnimator{");
1649 sb.append(Integer.toHexString(System.identityHashCode(this)));
1650 sb.append(' ');
1651 sb.append(mWin.mAttrs.getTitle());
1652 sb.append('}');
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001653 return sb.toString();
1654 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001655}