blob: a52d85ca0004073f712785397a9658b94ac1ae58 [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 Mautnerb3b36ba2013-05-20 13:21:10 -07006import static com.android.server.wm.WindowManagerService.DEBUG_ANIM;
7import static com.android.server.wm.WindowManagerService.DEBUG_LAYERS;
8import static com.android.server.wm.WindowManagerService.DEBUG_ORIENTATION;
9import static com.android.server.wm.WindowManagerService.DEBUG_STARTING_WINDOW;
10import static com.android.server.wm.WindowManagerService.DEBUG_SURFACE_TRACE;
11import static com.android.server.wm.WindowManagerService.SHOW_TRANSACTIONS;
12import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
13import static com.android.server.wm.WindowManagerService.SHOW_LIGHT_TRANSACTIONS;
14import static com.android.server.wm.WindowManagerService.SHOW_SURFACE_ALLOC;
15import static com.android.server.wm.WindowManagerService.localLOGV;
Craig Mautner2639da52012-07-09 09:39:06 -070016import static com.android.server.wm.WindowManagerService.LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE;
Craig Mautner7d8df392012-04-06 15:26:23 -070017import static com.android.server.wm.WindowManagerService.LayoutFields.SET_TURN_ON_SCREEN;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070018
Craig Mautnerc2f9be02012-03-27 17:32:29 -070019import android.content.Context;
20import android.graphics.Matrix;
21import android.graphics.PixelFormat;
Craig Mautner7358fbf2012-04-12 21:06:33 -070022import android.graphics.Point;
23import android.graphics.PointF;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070024import android.graphics.Rect;
Craig Mautner58106812012-12-28 12:27:40 -080025import android.graphics.RectF;
Craig Mautner48ba1e72012-04-02 13:18:16 -070026import android.graphics.Region;
Craig Mautnera51a9562012-04-17 17:05:26 -070027import android.os.Debug;
Craig Mautnera2c77052012-03-26 12:14:43 -070028import android.util.Slog;
Svetoslav Ganov545252f2012-12-10 18:29:24 -080029import android.view.Display;
Craig Mautner59c00972012-07-30 12:10:24 -070030import android.view.DisplayInfo;
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -070031import android.view.MagnificationSpec;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080032import android.view.SurfaceControl;
Craig Mautner7358fbf2012-04-12 21:06:33 -070033import android.view.SurfaceSession;
Craig Mautnera2c77052012-03-26 12:14:43 -070034import android.view.WindowManager;
35import android.view.WindowManagerPolicy;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070036import android.view.WindowManager.LayoutParams;
Craig Mautnera2c77052012-03-26 12:14:43 -070037import android.view.animation.Animation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070038import android.view.animation.AnimationUtils;
Craig Mautnera2c77052012-03-26 12:14:43 -070039import android.view.animation.Transformation;
40
41import com.android.server.wm.WindowManagerService.H;
42
43import java.io.PrintWriter;
Craig Mautner7358fbf2012-04-12 21:06:33 -070044import java.util.ArrayList;
Craig Mautnera2c77052012-03-26 12:14:43 -070045
Craig Mautner59c00972012-07-30 12:10:24 -070046class WinAnimatorList extends ArrayList<WindowStateAnimator> {
47}
48
Craig Mautnera2c77052012-03-26 12:14:43 -070049/**
Craig Mautnerc2f9be02012-03-27 17:32:29 -070050 * Keep track of animations and surface operations for a single WindowState.
51 **/
Craig Mautnera2c77052012-03-26 12:14:43 -070052class WindowStateAnimator {
Craig Mautnerc2f9be02012-03-27 17:32:29 -070053 static final String TAG = "WindowStateAnimator";
Craig Mautnera2c77052012-03-26 12:14:43 -070054
Craig Mautner918b53b2012-07-09 14:15:54 -070055 // Unchanging local convenience fields.
Craig Mautnera2c77052012-03-26 12:14:43 -070056 final WindowManagerService mService;
57 final WindowState mWin;
Craig Mautner322e4032012-07-13 13:35:20 -070058 final WindowStateAnimator mAttachedWinAnimator;
Craig Mautnere7ae2502012-03-26 17:11:19 -070059 final WindowAnimator mAnimator;
Craig Mautner8863cca2012-09-18 15:04:34 -070060 AppWindowAnimator mAppAnimator;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070061 final Session mSession;
62 final WindowManagerPolicy mPolicy;
63 final Context mContext;
Craig Mautner918b53b2012-07-09 14:15:54 -070064 final boolean mIsWallpaper;
Craig Mautnera2c77052012-03-26 12:14:43 -070065
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -070066 // If this is a universe background window, this is the transformation
67 // it is applying to the rest of the universe.
68 final Transformation mUniverseTransform = new Transformation();
69
Craig Mautnera2c77052012-03-26 12:14:43 -070070 // Currently running animation.
71 boolean mAnimating;
72 boolean mLocalAnimating;
73 Animation mAnimation;
74 boolean mAnimationIsEntrance;
75 boolean mHasTransformation;
76 boolean mHasLocalTransformation;
77 final Transformation mTransformation = new Transformation();
78 boolean mWasAnimating; // Were we animating going into the most recent animation step?
Craig Mautnerc2f9be02012-03-27 17:32:29 -070079 int mAnimLayer;
80 int mLastLayer;
81
Mathias Agopian29479eb2013-02-14 14:36:04 -080082 SurfaceControl mSurfaceControl;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080083 SurfaceControl mPendingDestroySurface;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070084
85 /**
86 * Set when we have changed the size of the surface, to know that
87 * we must tell them application to resize (and thus redraw itself).
88 */
89 boolean mSurfaceResized;
90
91 /**
92 * Set if the client has asked that the destroy of its surface be delayed
93 * until it explicitly says it is okay.
94 */
95 boolean mSurfaceDestroyDeferred;
96
Craig Mautner7d8df392012-04-06 15:26:23 -070097 float mShownAlpha = 0;
98 float mAlpha = 0;
99 float mLastAlpha = 0;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700100
101 // Used to save animation distances between the time they are calculated and when they are
102 // used.
103 int mAnimDw;
104 int mAnimDh;
105 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
106 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
107
108 boolean mHaveMatrix;
109
110 // For debugging, this is the last information given to the surface flinger.
111 boolean mSurfaceShown;
112 float mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
113 int mSurfaceLayer;
114 float mSurfaceAlpha;
115
116 // Set to true if, when the window gets displayed, it should perform
117 // an enter animation.
118 boolean mEnterAnimationPending;
Craig Mautnera2c77052012-03-26 12:14:43 -0700119
Craig Mautner749a7bb2012-04-02 13:49:53 -0700120 /** This is set when there is no Surface */
121 static final int NO_SURFACE = 0;
122 /** This is set after the Surface has been created but before the window has been drawn. During
123 * this time the surface is hidden. */
124 static final int DRAW_PENDING = 1;
125 /** This is set after the window has finished drawing for the first time but before its surface
126 * is shown. The surface will be displayed when the next layout is run. */
127 static final int COMMIT_DRAW_PENDING = 2;
128 /** This is set during the time after the window's drawing has been committed, and before its
129 * surface is actually shown. It is used to delay showing the surface until all windows in a
130 * token are ready to be shown. */
131 static final int READY_TO_SHOW = 3;
132 /** Set when the window has been shown in the screen the first time. */
133 static final int HAS_DRAWN = 4;
Craig Mautner6fbda632012-07-03 09:26:39 -0700134 static String drawStateToString(int state) {
135 switch (state) {
136 case NO_SURFACE: return "NO_SURFACE";
137 case DRAW_PENDING: return "DRAW_PENDING";
138 case COMMIT_DRAW_PENDING: return "COMMIT_DRAW_PENDING";
139 case READY_TO_SHOW: return "READY_TO_SHOW";
140 case HAS_DRAWN: return "HAS_DRAWN";
141 default: return Integer.toString(state);
142 }
143 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700144 int mDrawState;
Craig Mautnera608b882012-03-30 13:03:49 -0700145
Craig Mautner749a7bb2012-04-02 13:49:53 -0700146 /** Was this window last hidden? */
147 boolean mLastHidden;
Craig Mautnera608b882012-03-30 13:03:49 -0700148
Craig Mautnerbec53f72012-04-05 11:49:05 -0700149 int mAttrFlags;
150 int mAttrType;
151
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700152 final int mLayerStack;
153
Craig Mautner918b53b2012-07-09 14:15:54 -0700154 public WindowStateAnimator(final WindowState win) {
155 final WindowManagerService service = win.mService;
156
Craig Mautnera2c77052012-03-26 12:14:43 -0700157 mService = service;
Craig Mautner918b53b2012-07-09 14:15:54 -0700158 mAnimator = service.mAnimator;
159 mPolicy = service.mPolicy;
160 mContext = service.mContext;
Craig Mautner59c00972012-07-30 12:10:24 -0700161 final DisplayInfo displayInfo = win.mDisplayContent.getDisplayInfo();
162 mAnimDw = displayInfo.appWidth;
163 mAnimDh = displayInfo.appHeight;
Craig Mautner918b53b2012-07-09 14:15:54 -0700164
165 mWin = win;
Craig Mautner322e4032012-07-13 13:35:20 -0700166 mAttachedWinAnimator = win.mAttachedWindow == null
167 ? null : win.mAttachedWindow.mWinAnimator;
168 mAppAnimator = win.mAppToken == null ? null : win.mAppToken.mAppAnimator;
Craig Mautner918b53b2012-07-09 14:15:54 -0700169 mSession = win.mSession;
170 mAttrFlags = win.mAttrs.flags;
171 mAttrType = win.mAttrs.type;
172 mIsWallpaper = win.mIsWallpaper;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700173 mLayerStack = win.mDisplayContent.getDisplay().getLayerStack();
Craig Mautnera2c77052012-03-26 12:14:43 -0700174 }
175
176 public void setAnimation(Animation anim) {
Craig Mautnerbec53f72012-04-05 11:49:05 -0700177 if (localLOGV) Slog.v(TAG, "Setting animation in " + this + ": " + anim);
Craig Mautnera2c77052012-03-26 12:14:43 -0700178 mAnimating = false;
179 mLocalAnimating = false;
180 mAnimation = anim;
181 mAnimation.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION);
182 mAnimation.scaleCurrentDuration(mService.mWindowAnimationScale);
183 // Start out animation gone if window is gone, or visible if window is visible.
184 mTransformation.clear();
Craig Mautner749a7bb2012-04-02 13:49:53 -0700185 mTransformation.setAlpha(mLastHidden ? 0 : 1);
Craig Mautnera2c77052012-03-26 12:14:43 -0700186 mHasLocalTransformation = true;
187 }
188
189 public void clearAnimation() {
190 if (mAnimation != null) {
191 mAnimating = true;
192 mLocalAnimating = false;
193 mAnimation.cancel();
194 mAnimation = null;
195 }
196 }
197
198 /** Is the window or its container currently animating? */
199 boolean isAnimating() {
Craig Mautnera2c77052012-03-26 12:14:43 -0700200 return mAnimation != null
Craig Mautner322e4032012-07-13 13:35:20 -0700201 || (mAttachedWinAnimator != null && mAttachedWinAnimator.mAnimation != null)
202 || (mAppAnimator != null &&
203 (mAppAnimator.animation != null
204 || mAppAnimator.mAppToken.inPendingTransaction));
Craig Mautnera2c77052012-03-26 12:14:43 -0700205 }
206
Craig Mautner0afddcb2012-05-08 15:38:00 -0700207 /** Is the window animating the DummyAnimation? */
208 boolean isDummyAnimation() {
Craig Mautner322e4032012-07-13 13:35:20 -0700209 return mAppAnimator != null
210 && mAppAnimator.animation == AppWindowAnimator.sDummyAnimation;
Craig Mautner0afddcb2012-05-08 15:38:00 -0700211 }
212
Craig Mautnera2c77052012-03-26 12:14:43 -0700213 /** Is this window currently animating? */
214 boolean isWindowAnimating() {
215 return mAnimation != null;
216 }
217
Craig Mautnera2c77052012-03-26 12:14:43 -0700218 void cancelExitAnimationForNextAnimationLocked() {
Craig Mautnera2c77052012-03-26 12:14:43 -0700219 if (mAnimation != null) {
220 mAnimation.cancel();
221 mAnimation = null;
Craig Mautner4d7349b2012-04-20 14:52:47 -0700222 mLocalAnimating = false;
Craig Mautner96868332012-12-04 14:29:11 -0800223 destroySurfaceLocked();
Craig Mautnera2c77052012-03-26 12:14:43 -0700224 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700225 }
226
227 private boolean stepAnimation(long currentTime) {
228 if ((mAnimation == null) || !mLocalAnimating) {
229 return false;
230 }
231 mTransformation.clear();
232 final boolean more = mAnimation.getTransformation(currentTime, mTransformation);
Craig Mautner9e809442012-06-22 17:13:04 -0700233 if (false && DEBUG_ANIM) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700234 TAG, "Stepped animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700235 ": more=" + more + ", xform=" + mTransformation);
236 return more;
237 }
238
239 // This must be called while inside a transaction. Returns true if
240 // there is more animation to run.
241 boolean stepAnimationLocked(long currentTime) {
242 // Save the animation state as it was before this step so WindowManagerService can tell if
243 // we just started or just stopped animating by comparing mWasAnimating with isAnimating().
244 mWasAnimating = mAnimating;
245 if (mService.okToDisplay()) {
246 // We will run animations as long as the display isn't frozen.
247
248 if (mWin.isDrawnLw() && mAnimation != null) {
249 mHasTransformation = true;
250 mHasLocalTransformation = true;
251 if (!mLocalAnimating) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700252 if (DEBUG_ANIM) Slog.v(
253 TAG, "Starting animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700254 " @ " + currentTime + ": ww=" + mWin.mFrame.width() +
255 " wh=" + mWin.mFrame.height() +
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700256 " dw=" + mAnimDw + " dh=" + mAnimDh +
Craig Mautnera2c77052012-03-26 12:14:43 -0700257 " scale=" + mService.mWindowAnimationScale);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700258 mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(),
259 mAnimDw, mAnimDh);
Craig Mautner59c00972012-07-30 12:10:24 -0700260 final DisplayInfo displayInfo = mWin.mDisplayContent.getDisplayInfo();
261 mAnimDw = displayInfo.appWidth;
262 mAnimDh = displayInfo.appHeight;
Craig Mautnera2c77052012-03-26 12:14:43 -0700263 mAnimation.setStartTime(currentTime);
264 mLocalAnimating = true;
265 mAnimating = true;
266 }
267 if ((mAnimation != null) && mLocalAnimating) {
268 if (stepAnimation(currentTime)) {
269 return true;
270 }
271 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700272 if (DEBUG_ANIM) Slog.v(
273 TAG, "Finished animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700274 " @ " + currentTime);
275 //WindowManagerService.this.dump();
276 }
277 mHasLocalTransformation = false;
Craig Mautner322e4032012-07-13 13:35:20 -0700278 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppAnimator != null
279 && mAppAnimator.animation != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700280 // When our app token is animating, we kind-of pretend like
281 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
282 // part of this check means that we will only do this if
283 // our window is not currently exiting, or it is not
284 // locally animating itself. The idea being that one that
285 // is exiting and doing a local animation should be removed
286 // once that animation is done.
287 mAnimating = true;
288 mHasTransformation = true;
289 mTransformation.clear();
290 return false;
291 } else if (mHasTransformation) {
292 // Little trick to get through the path below to act like
293 // we have finished an animation.
294 mAnimating = true;
295 } else if (isAnimating()) {
296 mAnimating = true;
297 }
298 } else if (mAnimation != null) {
299 // If the display is frozen, and there is a pending animation,
300 // clear it and make sure we run the cleanup code.
301 mAnimating = true;
Craig Mautnera2c77052012-03-26 12:14:43 -0700302 }
303
304 if (!mAnimating && !mLocalAnimating) {
305 return false;
306 }
307
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700308 // Done animating, clean up.
309 if (DEBUG_ANIM) Slog.v(
310 TAG, "Animation done in " + this + ": exiting=" + mWin.mExiting
Craig Mautnera2c77052012-03-26 12:14:43 -0700311 + ", reportedVisible="
312 + (mWin.mAppToken != null ? mWin.mAppToken.reportedVisible : false));
313
314 mAnimating = false;
315 mLocalAnimating = false;
316 if (mAnimation != null) {
317 mAnimation.cancel();
318 mAnimation = null;
319 }
Craig Mautnere7ae2502012-03-26 17:11:19 -0700320 if (mAnimator.mWindowDetachedWallpaper == mWin) {
321 mAnimator.mWindowDetachedWallpaper = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700322 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700323 mAnimLayer = mWin.mLayer;
Craig Mautnera2c77052012-03-26 12:14:43 -0700324 if (mWin.mIsImWindow) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700325 mAnimLayer += mService.mInputMethodAnimLayerAdjustment;
Craig Mautner918b53b2012-07-09 14:15:54 -0700326 } else if (mIsWallpaper) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700327 mAnimLayer += mService.mWallpaperAnimLayerAdjustment;
Craig Mautnera2c77052012-03-26 12:14:43 -0700328 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700329 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
330 + " anim layer: " + mAnimLayer);
Craig Mautnera2c77052012-03-26 12:14:43 -0700331 mHasTransformation = false;
332 mHasLocalTransformation = false;
333 if (mWin.mPolicyVisibility != mWin.mPolicyVisibilityAfterAnim) {
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700334 if (DEBUG_VISIBILITY) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700335 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
Craig Mautnera2c77052012-03-26 12:14:43 -0700336 + mWin.mPolicyVisibilityAfterAnim);
337 }
338 mWin.mPolicyVisibility = mWin.mPolicyVisibilityAfterAnim;
Craig Mautner19d59bc2012-09-04 11:15:56 -0700339 mWin.mDisplayContent.layoutNeeded = true;
Craig Mautnera2c77052012-03-26 12:14:43 -0700340 if (!mWin.mPolicyVisibility) {
341 if (mService.mCurrentFocus == mWin) {
342 mService.mFocusMayChange = true;
343 }
344 // Window is no longer visible -- make sure if we were waiting
345 // for it to be displayed before enabling the display, that
346 // we allow the display to be enabled now.
347 mService.enableScreenIfNeededLocked();
348 }
349 }
350 mTransformation.clear();
Craig Mautner749a7bb2012-04-02 13:49:53 -0700351 if (mDrawState == HAS_DRAWN
Craig Mautnera2c77052012-03-26 12:14:43 -0700352 && mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
353 && mWin.mAppToken != null
354 && mWin.mAppToken.firstWindowDrawn
355 && mWin.mAppToken.startingData != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700356 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
Craig Mautnera2c77052012-03-26 12:14:43 -0700357 + mWin.mToken + ": first real window done animating");
358 mService.mFinishedStarting.add(mWin.mAppToken);
359 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
360 }
361
362 finishExit();
Craig Mautner76a71652012-09-03 23:23:58 -0700363 final int displayId = mWin.mDisplayContent.getDisplayId();
364 mAnimator.setPendingLayoutChanges(displayId, WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700365 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) mService.debugLayoutRepeats(
Craig Mautner66f78d72012-12-04 16:46:50 -0800366 "WindowStateAnimator", mAnimator.getPendingLayoutChanges(displayId));
Craig Mautnera2c77052012-03-26 12:14:43 -0700367
368 if (mWin.mAppToken != null) {
369 mWin.mAppToken.updateReportedVisibilityLocked();
370 }
371
372 return false;
373 }
374
375 void finishExit() {
376 if (WindowManagerService.DEBUG_ANIM) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700377 TAG, "finishExit in " + this
Craig Mautnera2c77052012-03-26 12:14:43 -0700378 + ": exiting=" + mWin.mExiting
379 + " remove=" + mWin.mRemoveOnExit
380 + " windowAnimating=" + isWindowAnimating());
381
382 final int N = mWin.mChildWindows.size();
383 for (int i=0; i<N; i++) {
384 mWin.mChildWindows.get(i).mWinAnimator.finishExit();
385 }
386
387 if (!mWin.mExiting) {
388 return;
389 }
390
391 if (isWindowAnimating()) {
392 return;
393 }
394
395 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700396 TAG, "Exit animation finished in " + this
Craig Mautnera2c77052012-03-26 12:14:43 -0700397 + ": remove=" + mWin.mRemoveOnExit);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800398 if (mSurfaceControl != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700399 mService.mDestroySurface.add(mWin);
400 mWin.mDestroying = true;
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700401 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(
Craig Mautnera2c77052012-03-26 12:14:43 -0700402 mWin, "HIDE (finishExit)", null);
Craig Mautner0afddcb2012-05-08 15:38:00 -0700403 hide();
Craig Mautnera2c77052012-03-26 12:14:43 -0700404 }
405 mWin.mExiting = false;
406 if (mWin.mRemoveOnExit) {
407 mService.mPendingRemove.add(mWin);
408 mWin.mRemoveOnExit = false;
409 }
Craig Mautner96868332012-12-04 14:29:11 -0800410 mAnimator.hideWallpapersLocked(mWin);
Craig Mautner0afddcb2012-05-08 15:38:00 -0700411 }
412
413 void hide() {
414 if (!mLastHidden) {
415 //dump();
416 mLastHidden = true;
417 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
418 "HIDE (performLayout)", null);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800419 if (mSurfaceControl != null) {
Craig Mautner0afddcb2012-05-08 15:38:00 -0700420 mSurfaceShown = false;
421 try {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800422 mSurfaceControl.hide();
Craig Mautner0afddcb2012-05-08 15:38:00 -0700423 } catch (RuntimeException e) {
424 Slog.w(TAG, "Exception hiding surface in " + mWin);
425 }
426 }
427 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700428 }
429
Craig Mautnera608b882012-03-30 13:03:49 -0700430 boolean finishDrawingLocked() {
Craig Mautner6fbda632012-07-03 09:26:39 -0700431 if (DEBUG_STARTING_WINDOW &&
432 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
433 Slog.v(TAG, "Finishing drawing window " + mWin + ": mDrawState="
434 + drawStateToString(mDrawState));
435 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700436 if (mDrawState == DRAW_PENDING) {
Craig Mautneref25d7a2012-05-15 23:01:47 -0700437 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
438 Slog.v(TAG, "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING " + this + " in "
Mathias Agopian29479eb2013-02-14 14:36:04 -0800439 + mSurfaceControl);
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, "Draw state now committed in " + mWin);
443 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700444 mDrawState = COMMIT_DRAW_PENDING;
Craig Mautnera608b882012-03-30 13:03:49 -0700445 return true;
446 }
447 return false;
448 }
449
450 // This must be called while inside a transaction.
451 boolean commitFinishDrawingLocked(long currentTime) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700452 if (DEBUG_STARTING_WINDOW &&
453 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
454 Slog.i(TAG, "commitFinishDrawingLocked: " + mWin + " cur mDrawState="
455 + drawStateToString(mDrawState));
456 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700457 if (mDrawState != COMMIT_DRAW_PENDING) {
Craig Mautnera608b882012-03-30 13:03:49 -0700458 return false;
459 }
Craig Mautner6fbda632012-07-03 09:26:39 -0700460 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800461 Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurfaceControl);
Craig Mautner6fbda632012-07-03 09:26:39 -0700462 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700463 mDrawState = READY_TO_SHOW;
Craig Mautnera608b882012-03-30 13:03:49 -0700464 final boolean starting = mWin.mAttrs.type == TYPE_APPLICATION_STARTING;
465 final AppWindowToken atoken = mWin.mAppToken;
466 if (atoken == null || atoken.allDrawn || starting) {
467 performShowLocked();
468 }
469 return true;
470 }
471
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800472 static class SurfaceTrace extends SurfaceControl {
Craig Mautner7d8df392012-04-06 15:26:23 -0700473 private final static String SURFACE_TAG = "SurfaceTrace";
474 final static ArrayList<SurfaceTrace> sSurfaces = new ArrayList<SurfaceTrace>();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700475
Craig Mautner7d8df392012-04-06 15:26:23 -0700476 private float mSurfaceTraceAlpha = 0;
Craig Mautner7358fbf2012-04-12 21:06:33 -0700477 private int mLayer;
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700478 private final PointF mPosition = new PointF();
479 private final Point mSize = new Point();
480 private final Rect mWindowCrop = new Rect();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700481 private boolean mShown = false;
Jeff Brown98365d72012-08-19 20:30:52 -0700482 private int mLayerStack;
483 private String mName;
Craig Mautner7358fbf2012-04-12 21:06:33 -0700484
Craig Mautner7d8df392012-04-06 15:26:23 -0700485 public SurfaceTrace(SurfaceSession s,
Jeff Brown64a55af2012-08-26 02:47:39 -0700486 String name, int w, int h, int format, int flags)
Craig Mautner7358fbf2012-04-12 21:06:33 -0700487 throws OutOfResourcesException {
Jeff Brown64a55af2012-08-26 02:47:39 -0700488 super(s, name, w, h, format, flags);
Jeff Brown98365d72012-08-19 20:30:52 -0700489 mName = name != null ? name : "Not named";
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700490 mSize.set(w, h);
Craig Mautner7d8df392012-04-06 15:26:23 -0700491 Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700492 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700493 }
494
495 @Override
496 public void setAlpha(float alpha) {
497 super.setAlpha(alpha);
Dianne Hackborn98129732012-11-01 16:28:16 -0700498 if (alpha != mSurfaceTraceAlpha) {
Craig Mautner66d77302013-04-10 15:33:26 -0700499 mSurfaceTraceAlpha = alpha;
Dianne Hackborn98129732012-11-01 16:28:16 -0700500 Slog.v(SURFACE_TAG, "setAlpha: " + this + ". Called by "
501 + Debug.getCallers(3));
502 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700503 }
504
505 @Override
506 public void setLayer(int zorder) {
507 super.setLayer(zorder);
Dianne Hackborn98129732012-11-01 16:28:16 -0700508 if (zorder != mLayer) {
Craig Mautner66d77302013-04-10 15:33:26 -0700509 mLayer = zorder;
Dianne Hackborn98129732012-11-01 16:28:16 -0700510 Slog.v(SURFACE_TAG, "setLayer: " + this + ". Called by "
511 + Debug.getCallers(3));
512 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700513
514 sSurfaces.remove(this);
515 int i;
516 for (i = sSurfaces.size() - 1; i >= 0; i--) {
Craig Mautner7d8df392012-04-06 15:26:23 -0700517 SurfaceTrace s = sSurfaces.get(i);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700518 if (s.mLayer < zorder) {
519 break;
520 }
521 }
522 sSurfaces.add(i + 1, this);
523 }
524
525 @Override
526 public void setPosition(float x, float y) {
527 super.setPosition(x, y);
Dianne Hackborn98129732012-11-01 16:28:16 -0700528 if (x != mPosition.x || y != mPosition.y) {
Craig Mautner66d77302013-04-10 15:33:26 -0700529 mPosition.set(x, y);
Dianne Hackborn98129732012-11-01 16:28:16 -0700530 Slog.v(SURFACE_TAG, "setPosition: " + this + ". Called by "
531 + Debug.getCallers(3));
532 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700533 }
534
535 @Override
536 public void setSize(int w, int h) {
537 super.setSize(w, h);
Dianne Hackborn98129732012-11-01 16:28:16 -0700538 if (w != mSize.x || h != mSize.y) {
Craig Mautner66d77302013-04-10 15:33:26 -0700539 mSize.set(w, h);
Dianne Hackborn98129732012-11-01 16:28:16 -0700540 Slog.v(SURFACE_TAG, "setSize: " + this + ". Called by "
541 + Debug.getCallers(3));
542 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700543 }
544
545 @Override
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700546 public void setWindowCrop(Rect crop) {
547 super.setWindowCrop(crop);
Craig Mautneref25d7a2012-05-15 23:01:47 -0700548 if (crop != null) {
Dianne Hackborn98129732012-11-01 16:28:16 -0700549 if (!crop.equals(mWindowCrop)) {
Craig Mautner66d77302013-04-10 15:33:26 -0700550 mWindowCrop.set(crop);
Dianne Hackborn98129732012-11-01 16:28:16 -0700551 Slog.v(SURFACE_TAG, "setWindowCrop: " + this + ". Called by "
552 + Debug.getCallers(3));
553 }
Craig Mautneref25d7a2012-05-15 23:01:47 -0700554 }
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700555 }
556
557 @Override
Jeff Brown98365d72012-08-19 20:30:52 -0700558 public void setLayerStack(int layerStack) {
559 super.setLayerStack(layerStack);
Dianne Hackborn98129732012-11-01 16:28:16 -0700560 if (layerStack != mLayerStack) {
Craig Mautner66d77302013-04-10 15:33:26 -0700561 mLayerStack = layerStack;
Dianne Hackborn98129732012-11-01 16:28:16 -0700562 Slog.v(SURFACE_TAG, "setLayerStack: " + this + ". Called by " + Debug.getCallers(3));
563 }
Craig Mautner9de49362012-08-02 14:30:30 -0700564 }
565
566 @Override
Craig Mautner7358fbf2012-04-12 21:06:33 -0700567 public void hide() {
568 super.hide();
Dianne Hackborn98129732012-11-01 16:28:16 -0700569 if (mShown) {
Craig Mautner66d77302013-04-10 15:33:26 -0700570 mShown = false;
Dianne Hackborn98129732012-11-01 16:28:16 -0700571 Slog.v(SURFACE_TAG, "hide: " + this + ". Called by "
572 + Debug.getCallers(3));
573 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700574 }
575 @Override
576 public void show() {
577 super.show();
Dianne Hackborn98129732012-11-01 16:28:16 -0700578 if (!mShown) {
Craig Mautner66d77302013-04-10 15:33:26 -0700579 mShown = true;
Dianne Hackborn98129732012-11-01 16:28:16 -0700580 Slog.v(SURFACE_TAG, "show: " + this + ". Called by "
581 + Debug.getCallers(3));
582 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700583 }
584
585 @Override
586 public void destroy() {
587 super.destroy();
Craig Mautner7d8df392012-04-06 15:26:23 -0700588 Slog.v(SURFACE_TAG, "destroy: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700589 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700590 sSurfaces.remove(this);
591 }
592
Craig Mautneracaf9cc2012-04-17 11:45:25 -0700593 @Override
594 public void release() {
595 super.release();
596 Slog.v(SURFACE_TAG, "release: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700597 + Debug.getCallers(3));
Craig Mautneracaf9cc2012-04-17 11:45:25 -0700598 sSurfaces.remove(this);
599 }
600
Craig Mautner7358fbf2012-04-12 21:06:33 -0700601 static void dumpAllSurfaces() {
602 final int N = sSurfaces.size();
603 for (int i = 0; i < N; i++) {
604 Slog.i(TAG, "SurfaceDump: " + sSurfaces.get(i));
605 }
606 }
607
608 @Override
609 public String toString() {
Craig Mautnerfbf378c2012-04-23 17:24:21 -0700610 return "Surface " + Integer.toHexString(System.identityHashCode(this)) + " "
Jeff Brown98365d72012-08-19 20:30:52 -0700611 + mName + " (" + mLayerStack + "): shown=" + mShown + " layer=" + mLayer
Craig Mautner7d8df392012-04-06 15:26:23 -0700612 + " alpha=" + mSurfaceTraceAlpha + " " + mPosition.x + "," + mPosition.y
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700613 + " " + mSize.x + "x" + mSize.y
614 + " crop=" + mWindowCrop.toShortString();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700615 }
616 }
617
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800618 SurfaceControl createSurfaceLocked() {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800619 if (mSurfaceControl == null) {
Craig Mautner83339b42012-05-01 22:13:23 -0700620 if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG,
621 "createSurface " + this + ": mDrawState=DRAW_PENDING");
Craig Mautner749a7bb2012-04-02 13:49:53 -0700622 mDrawState = DRAW_PENDING;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700623 if (mWin.mAppToken != null) {
Craig Mautner7636dfb2012-11-16 15:24:11 -0800624 if (mWin.mAppToken.mAppAnimator.animation == null) {
625 mWin.mAppToken.allDrawn = false;
626 mWin.mAppToken.deferClearAllDrawn = false;
627 } else {
628 // Currently animating, persist current state of allDrawn until animation
629 // is complete.
630 mWin.mAppToken.deferClearAllDrawn = true;
631 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700632 }
633
634 mService.makeWindowFreezingScreenIfNeededLocked(mWin);
635
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800636 int flags = SurfaceControl.HIDDEN;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700637 final WindowManager.LayoutParams attrs = mWin.mAttrs;
638
639 if ((attrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800640 flags |= SurfaceControl.SECURE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700641 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700642 if (DEBUG_VISIBILITY) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700643 TAG, "Creating surface in session "
644 + mSession.mSurfaceSession + " window " + this
645 + " w=" + mWin.mCompatFrame.width()
646 + " h=" + mWin.mCompatFrame.height() + " format="
647 + attrs.format + " flags=" + flags);
648
649 int w = mWin.mCompatFrame.width();
650 int h = mWin.mCompatFrame.height();
651 if ((attrs.flags & LayoutParams.FLAG_SCALED) != 0) {
652 // for a scaled surface, we always want the requested
653 // size.
654 w = mWin.mRequestedWidth;
655 h = mWin.mRequestedHeight;
656 }
657
658 // Something is wrong and SurfaceFlinger will not like this,
659 // try to revert to sane values
660 if (w <= 0) w = 1;
661 if (h <= 0) h = 1;
662
663 mSurfaceShown = false;
664 mSurfaceLayer = 0;
Craig Mautner7d8df392012-04-06 15:26:23 -0700665 mSurfaceAlpha = 0;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700666 mSurfaceX = 0;
667 mSurfaceY = 0;
668 mSurfaceW = w;
669 mSurfaceH = h;
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700670 mWin.mLastSystemDecorRect.set(0, 0, 0, 0);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700671 try {
672 final boolean isHwAccelerated = (attrs.flags &
673 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
674 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
675 if (!PixelFormat.formatHasAlpha(attrs.format)) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800676 flags |= SurfaceControl.OPAQUE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700677 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700678 if (DEBUG_SURFACE_TRACE) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800679 mSurfaceControl = new SurfaceTrace(
Jeff Brown64a55af2012-08-26 02:47:39 -0700680 mSession.mSurfaceSession,
Craig Mautner7358fbf2012-04-12 21:06:33 -0700681 attrs.getTitle().toString(),
Jeff Brown64a55af2012-08-26 02:47:39 -0700682 w, h, format, flags);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700683 } else {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800684 mSurfaceControl = new SurfaceControl(
Jeff Brown64a55af2012-08-26 02:47:39 -0700685 mSession.mSurfaceSession,
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700686 attrs.getTitle().toString(),
Jeff Brown64a55af2012-08-26 02:47:39 -0700687 w, h, format, flags);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700688 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700689 mWin.mHasSurface = true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700690 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG,
691 " CREATE SURFACE "
Mathias Agopian29479eb2013-02-14 14:36:04 -0800692 + mSurfaceControl + " IN SESSION "
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700693 + mSession.mSurfaceSession
694 + ": pid=" + mSession.mPid + " format="
695 + attrs.format + " flags=0x"
696 + Integer.toHexString(flags)
697 + " / " + this);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800698 } catch (SurfaceControl.OutOfResourcesException e) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700699 mWin.mHasSurface = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700700 Slog.w(TAG, "OutOfResourcesException creating surface");
701 mService.reclaimSomeSurfaceMemoryLocked(this, "create", true);
Craig Mautner749a7bb2012-04-02 13:49:53 -0700702 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700703 return null;
704 } catch (Exception e) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700705 mWin.mHasSurface = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700706 Slog.e(TAG, "Exception creating surface", e);
Craig Mautner749a7bb2012-04-02 13:49:53 -0700707 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700708 return null;
709 }
710
711 if (WindowManagerService.localLOGV) Slog.v(
Mathias Agopian29479eb2013-02-14 14:36:04 -0800712 TAG, "Got surface: " + mSurfaceControl
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700713 + ", set left=" + mWin.mFrame.left + " top=" + mWin.mFrame.top
714 + ", animLayer=" + mAnimLayer);
715 if (SHOW_LIGHT_TRANSACTIONS) {
716 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
717 WindowManagerService.logSurface(mWin, "CREATE pos=("
718 + mWin.mFrame.left + "," + mWin.mFrame.top + ") ("
719 + mWin.mCompatFrame.width() + "x" + mWin.mCompatFrame.height()
720 + "), layer=" + mAnimLayer + " HIDE", null);
721 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800722 SurfaceControl.openTransaction();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700723 try {
724 try {
725 mSurfaceX = mWin.mFrame.left + mWin.mXOffset;
726 mSurfaceY = mWin.mFrame.top + mWin.mYOffset;
Mathias Agopian29479eb2013-02-14 14:36:04 -0800727 mSurfaceControl.setPosition(mSurfaceX, mSurfaceY);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700728 mSurfaceLayer = mAnimLayer;
Mathias Agopian29479eb2013-02-14 14:36:04 -0800729 mSurfaceControl.setLayerStack(mLayerStack);
730 mSurfaceControl.setLayer(mAnimLayer);
731 mSurfaceControl.setAlpha(0);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700732 mSurfaceShown = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700733 } catch (RuntimeException e) {
734 Slog.w(TAG, "Error creating surface in " + w, e);
735 mService.reclaimSomeSurfaceMemoryLocked(this, "create-init", true);
736 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700737 mLastHidden = true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700738 } finally {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800739 SurfaceControl.closeTransaction();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700740 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
741 "<<< CLOSE TRANSACTION createSurfaceLocked");
742 }
743 if (WindowManagerService.localLOGV) Slog.v(
744 TAG, "Created surface " + this);
745 }
Mathias Agopian29479eb2013-02-14 14:36:04 -0800746 return mSurfaceControl;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700747 }
748
Craig Mautner96868332012-12-04 14:29:11 -0800749 void destroySurfaceLocked() {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700750 if (mWin.mAppToken != null && mWin == mWin.mAppToken.startingWindow) {
751 mWin.mAppToken.startingDisplayed = false;
752 }
753
Mathias Agopian29479eb2013-02-14 14:36:04 -0800754 if (mSurfaceControl != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700755
756 int i = mWin.mChildWindows.size();
757 while (i > 0) {
758 i--;
759 WindowState c = mWin.mChildWindows.get(i);
760 c.mAttachedHidden = true;
761 }
762
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700763 try {
764 if (DEBUG_VISIBILITY) {
765 RuntimeException e = null;
766 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
767 e = new RuntimeException();
768 e.fillInStackTrace();
769 }
770 Slog.w(TAG, "Window " + this + " destroying surface "
Mathias Agopian29479eb2013-02-14 14:36:04 -0800771 + mSurfaceControl + ", session " + mSession, e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700772 }
773 if (mSurfaceDestroyDeferred) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800774 if (mSurfaceControl != null && mPendingDestroySurface != mSurfaceControl) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700775 if (mPendingDestroySurface != null) {
776 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
777 RuntimeException e = null;
778 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
779 e = new RuntimeException();
780 e.fillInStackTrace();
781 }
782 WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
783 }
784 mPendingDestroySurface.destroy();
785 }
Mathias Agopian29479eb2013-02-14 14:36:04 -0800786 mPendingDestroySurface = mSurfaceControl;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700787 }
788 } else {
789 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
790 RuntimeException e = null;
791 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
792 e = new RuntimeException();
793 e.fillInStackTrace();
794 }
795 WindowManagerService.logSurface(mWin, "DESTROY", e);
796 }
Mathias Agopian29479eb2013-02-14 14:36:04 -0800797 mSurfaceControl.destroy();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700798 }
Craig Mautner96868332012-12-04 14:29:11 -0800799 mAnimator.hideWallpapersLocked(mWin);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700800 } catch (RuntimeException e) {
801 Slog.w(TAG, "Exception thrown when destroying Window " + this
Mathias Agopian29479eb2013-02-14 14:36:04 -0800802 + " surface " + mSurfaceControl + " session " + mSession
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700803 + ": " + e.toString());
804 }
805
806 mSurfaceShown = false;
Mathias Agopian29479eb2013-02-14 14:36:04 -0800807 mSurfaceControl = null;
Craig Mautnere8552142012-11-07 13:55:47 -0800808 mWin.mHasSurface = false;
Craig Mautnerbf08af32012-05-16 19:43:42 -0700809 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700810 }
811 }
812
Craig Mautner96868332012-12-04 14:29:11 -0800813 void destroyDeferredSurfaceLocked() {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700814 try {
815 if (mPendingDestroySurface != null) {
816 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
817 RuntimeException e = null;
818 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
819 e = new RuntimeException();
820 e.fillInStackTrace();
821 }
822 WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
823 }
824 mPendingDestroySurface.destroy();
Craig Mautner96868332012-12-04 14:29:11 -0800825 mAnimator.hideWallpapersLocked(mWin);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700826 }
827 } catch (RuntimeException e) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700828 Slog.w(TAG, "Exception thrown when destroying Window "
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700829 + this + " surface " + mPendingDestroySurface
830 + " session " + mSession + ": " + e.toString());
831 }
832 mSurfaceDestroyDeferred = false;
833 mPendingDestroySurface = null;
834 }
835
836 void computeShownFrameLocked() {
837 final boolean selfTransformation = mHasLocalTransformation;
838 Transformation attachedTransformation =
Craig Mautner322e4032012-07-13 13:35:20 -0700839 (mAttachedWinAnimator != null && mAttachedWinAnimator.mHasLocalTransformation)
840 ? mAttachedWinAnimator.mTransformation : null;
841 Transformation appTransformation = (mAppAnimator != null && mAppAnimator.hasTransformation)
842 ? mAppAnimator.transformation : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700843
844 // Wallpapers are animated based on the "real" window they
845 // are currently targeting.
Craig Mautner96868332012-12-04 14:29:11 -0800846 if (mIsWallpaper && mService.mLowerWallpaperTarget == null
847 && mService.mWallpaperTarget != null) {
848 final WindowStateAnimator wallpaperAnimator = mService.mWallpaperTarget.mWinAnimator;
Craig Mautner918b53b2012-07-09 14:15:54 -0700849 if (wallpaperAnimator.mHasLocalTransformation &&
850 wallpaperAnimator.mAnimation != null &&
851 !wallpaperAnimator.mAnimation.getDetachWallpaper()) {
852 attachedTransformation = wallpaperAnimator.mTransformation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700853 if (WindowManagerService.DEBUG_WALLPAPER && attachedTransformation != null) {
854 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
855 }
856 }
Craig Mautner96868332012-12-04 14:29:11 -0800857 final AppWindowAnimator wpAppAnimator = mAnimator.getWallpaperAppAnimator();
Craig Mautner918b53b2012-07-09 14:15:54 -0700858 if (wpAppAnimator != null && wpAppAnimator.hasTransformation
859 && wpAppAnimator.animation != null
860 && !wpAppAnimator.animation.getDetachWallpaper()) {
Craig Mautner59431632012-04-04 11:56:44 -0700861 appTransformation = wpAppAnimator.transformation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700862 if (WindowManagerService.DEBUG_WALLPAPER && appTransformation != null) {
863 Slog.v(TAG, "WP target app xform: " + appTransformation);
864 }
865 }
866 }
867
Craig Mautnera91f9e22012-09-14 16:22:08 -0700868 final int displayId = mWin.getDisplayId();
869 final ScreenRotationAnimation screenRotationAnimation =
870 mAnimator.getScreenRotationAnimationLocked(displayId);
871 final boolean screenAnimation =
872 screenRotationAnimation != null && screenRotationAnimation.isAnimating();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700873 if (selfTransformation || attachedTransformation != null
874 || appTransformation != null || screenAnimation) {
875 // cache often used attributes locally
876 final Rect frame = mWin.mFrame;
877 final float tmpFloats[] = mService.mTmpFloats;
878 final Matrix tmpMatrix = mWin.mTmpMatrix;
879
880 // Compute the desired transformation.
Dianne Hackborn4b169692012-11-29 17:51:24 -0800881 if (screenAnimation && screenRotationAnimation.isRotating()) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700882 // If we are doing a screen animation, the global rotation
883 // applied to windows can result in windows that are carefully
884 // aligned with each other to slightly separate, allowing you
885 // to see what is behind them. An unsightly mess. This...
886 // thing... magically makes it call good: scale each window
887 // slightly (two pixels larger in each dimension, from the
888 // window's center).
889 final float w = frame.width();
890 final float h = frame.height();
891 if (w>=1 && h>=1) {
892 tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2);
893 } else {
894 tmpMatrix.reset();
895 }
896 } else {
897 tmpMatrix.reset();
898 }
899 tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale);
900 if (selfTransformation) {
901 tmpMatrix.postConcat(mTransformation.getMatrix());
902 }
903 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
904 if (attachedTransformation != null) {
905 tmpMatrix.postConcat(attachedTransformation.getMatrix());
906 }
907 if (appTransformation != null) {
908 tmpMatrix.postConcat(appTransformation.getMatrix());
909 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700910 if (mAnimator.mUniverseBackground != null) {
911 tmpMatrix.postConcat(mAnimator.mUniverseBackground.mUniverseTransform.getMatrix());
912 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700913 if (screenAnimation) {
Craig Mautnera91f9e22012-09-14 16:22:08 -0700914 tmpMatrix.postConcat(screenRotationAnimation.getEnterTransformation().getMatrix());
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700915 }
Svetoslav Ganov545252f2012-12-10 18:29:24 -0800916 //TODO (multidisplay): Magnification is supported only for the default display.
917 if (mService.mDisplayMagnifier != null
918 && mWin.getDisplayId() == Display.DEFAULT_DISPLAY) {
919 MagnificationSpec spec = mService.mDisplayMagnifier
920 .getMagnificationSpecForWindowLocked(mWin);
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -0700921 if (spec != null && !spec.isNop()) {
922 tmpMatrix.postScale(spec.scale, spec.scale);
923 tmpMatrix.postTranslate(spec.offsetX, spec.offsetY);
924 }
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700925 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700926
927 // "convert" it into SurfaceFlinger's format
928 // (a 2x2 matrix + an offset)
929 // Here we must not transform the position of the surface
930 // since it is already included in the transformation.
931 //Slog.i(TAG, "Transform: " + matrix);
932
933 mHaveMatrix = true;
934 tmpMatrix.getValues(tmpFloats);
935 mDsDx = tmpFloats[Matrix.MSCALE_X];
936 mDtDx = tmpFloats[Matrix.MSKEW_Y];
937 mDsDy = tmpFloats[Matrix.MSKEW_X];
938 mDtDy = tmpFloats[Matrix.MSCALE_Y];
939 float x = tmpFloats[Matrix.MTRANS_X];
940 float y = tmpFloats[Matrix.MTRANS_Y];
941 int w = frame.width();
942 int h = frame.height();
943 mWin.mShownFrame.set(x, y, x+w, y+h);
944
945 // Now set the alpha... but because our current hardware
946 // can't do alpha transformation on a non-opaque surface,
947 // turn it off if we are running an animation that is also
948 // transforming since it is more important to have that
949 // animation be smooth.
950 mShownAlpha = mAlpha;
951 if (!mService.mLimitedAlphaCompositing
952 || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format)
953 || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
954 && x == frame.left && y == frame.top))) {
955 //Slog.i(TAG, "Applying alpha transform");
956 if (selfTransformation) {
957 mShownAlpha *= mTransformation.getAlpha();
958 }
959 if (attachedTransformation != null) {
960 mShownAlpha *= attachedTransformation.getAlpha();
961 }
962 if (appTransformation != null) {
963 mShownAlpha *= appTransformation.getAlpha();
964 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700965 if (mAnimator.mUniverseBackground != null) {
966 mShownAlpha *= mAnimator.mUniverseBackground.mUniverseTransform.getAlpha();
967 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700968 if (screenAnimation) {
Craig Mautnera91f9e22012-09-14 16:22:08 -0700969 mShownAlpha *= screenRotationAnimation.getEnterTransformation().getAlpha();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700970 }
971 } else {
972 //Slog.i(TAG, "Not applying alpha transform");
973 }
974
Craig Mautnera91f9e22012-09-14 16:22:08 -0700975 if ((DEBUG_SURFACE_TRACE || WindowManagerService.localLOGV)
976 && (mShownAlpha == 1.0 || mShownAlpha == 0.0)) Slog.v(
977 TAG, "computeShownFrameLocked: Animating " + this + " mAlpha=" + mAlpha
978 + " self=" + (selfTransformation ? mTransformation.getAlpha() : "null")
979 + " attached=" + (attachedTransformation == null ?
980 "null" : attachedTransformation.getAlpha())
981 + " app=" + (appTransformation == null ? "null" : appTransformation.getAlpha())
982 + " screen=" + (screenAnimation ?
983 screenRotationAnimation.getEnterTransformation().getAlpha() : "null"));
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700984 return;
Craig Mautner96868332012-12-04 14:29:11 -0800985 } else if (mIsWallpaper && mService.mInnerFields.mWallpaperActionPending) {
Craig Mautner4d7349b2012-04-20 14:52:47 -0700986 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700987 }
988
989 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautner4d7349b2012-04-20 14:52:47 -0700990 TAG, "computeShownFrameLocked: " + this +
991 " not attached, mAlpha=" + mAlpha);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700992
993 final boolean applyUniverseTransformation = (mAnimator.mUniverseBackground != null
994 && mWin.mAttrs.type != WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND
995 && mWin.mBaseLayer < mAnimator.mAboveUniverseLayer);
Svetoslav Ganov545252f2012-12-10 18:29:24 -0800996 MagnificationSpec spec = null;
997 //TODO (multidisplay): Magnification is supported only for the default display.
998 if (mService.mDisplayMagnifier != null && mWin.getDisplayId() == Display.DEFAULT_DISPLAY) {
999 spec = mService.mDisplayMagnifier.getMagnificationSpecForWindowLocked(mWin);
1000 }
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001001 if (applyUniverseTransformation || spec != null) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001002 final Rect frame = mWin.mFrame;
1003 final float tmpFloats[] = mService.mTmpFloats;
1004 final Matrix tmpMatrix = mWin.mTmpMatrix;
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001005
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001006 tmpMatrix.setScale(mWin.mGlobalScale, mWin.mGlobalScale);
1007 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001008
1009 if (applyUniverseTransformation) {
1010 tmpMatrix.postConcat(mAnimator.mUniverseBackground.mUniverseTransform.getMatrix());
1011 }
1012
1013 if (spec != null && !spec.isNop()) {
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -07001014 tmpMatrix.postScale(spec.scale, spec.scale);
1015 tmpMatrix.postTranslate(spec.offsetX, spec.offsetY);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001016 }
1017
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001018 tmpMatrix.getValues(tmpFloats);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001019
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001020 mHaveMatrix = true;
1021 mDsDx = tmpFloats[Matrix.MSCALE_X];
1022 mDtDx = tmpFloats[Matrix.MSKEW_Y];
1023 mDsDy = tmpFloats[Matrix.MSKEW_X];
1024 mDtDy = tmpFloats[Matrix.MSCALE_Y];
1025 float x = tmpFloats[Matrix.MTRANS_X];
1026 float y = tmpFloats[Matrix.MTRANS_Y];
1027 int w = frame.width();
1028 int h = frame.height();
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001029 mWin.mShownFrame.set(x, y, x + w, y + h);
1030
1031 mShownAlpha = mAlpha;
1032 if (applyUniverseTransformation) {
1033 mShownAlpha *= mAnimator.mUniverseBackground.mUniverseTransform.getAlpha();
1034 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001035 } else {
1036 mWin.mShownFrame.set(mWin.mFrame);
1037 if (mWin.mXOffset != 0 || mWin.mYOffset != 0) {
1038 mWin.mShownFrame.offset(mWin.mXOffset, mWin.mYOffset);
1039 }
1040 mShownAlpha = mAlpha;
1041 mHaveMatrix = false;
1042 mDsDx = mWin.mGlobalScale;
1043 mDtDx = 0;
1044 mDsDy = 0;
1045 mDtDy = mWin.mGlobalScale;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001046 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001047 }
1048
1049 void applyDecorRect(final Rect decorRect) {
1050 final WindowState w = mWin;
1051 // Compute the offset of the window in relation to the decor rect.
1052 final int offX = w.mXOffset + w.mFrame.left;
1053 final int offY = w.mYOffset + w.mFrame.top;
1054 // Initialize the decor rect to the entire frame.
1055 w.mSystemDecorRect.set(0, 0, w.mFrame.width(), w.mFrame.height());
1056 // Intersect with the decor rect, offsetted by window position.
1057 w.mSystemDecorRect.intersect(decorRect.left-offX, decorRect.top-offY,
1058 decorRect.right-offX, decorRect.bottom-offY);
1059 // If size compatibility is being applied to the window, the
1060 // surface is scaled relative to the screen. Also apply this
1061 // scaling to the crop rect. We aren't using the standard rect
1062 // scale function because we want to round things to make the crop
1063 // always round to a larger rect to ensure we don't crop too
1064 // much and hide part of the window that should be seen.
1065 if (w.mEnforceSizeCompat && w.mInvGlobalScale != 1.0f) {
1066 final float scale = w.mInvGlobalScale;
1067 w.mSystemDecorRect.left = (int) (w.mSystemDecorRect.left * scale - 0.5f);
1068 w.mSystemDecorRect.top = (int) (w.mSystemDecorRect.top * scale - 0.5f);
1069 w.mSystemDecorRect.right = (int) ((w.mSystemDecorRect.right+1) * scale - 0.5f);
1070 w.mSystemDecorRect.bottom = (int) ((w.mSystemDecorRect.bottom+1) * scale - 0.5f);
1071 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001072 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001073
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001074 void updateSurfaceWindowCrop(final boolean recoveringMemory) {
1075 final WindowState w = mWin;
Craig Mautner69b08182012-09-05 13:07:13 -07001076 DisplayInfo displayInfo = w.mDisplayContent.getDisplayInfo();
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001077
1078 // Need to recompute a new system decor rect each time.
1079 if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
1080 // Currently can't do this cropping for scaled windows. We'll
1081 // just keep the crop rect the same as the source surface.
1082 w.mSystemDecorRect.set(0, 0, w.mRequestedWidth, w.mRequestedHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07001083 } else if (!w.isDefaultDisplay()) {
Jeff Brown28e0b092012-09-25 11:31:28 -07001084 // On a different display there is no system decor. Crop the window
1085 // by the screen boundaries.
Jeff Brown36714102012-09-24 17:36:06 -07001086 w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height());
Jeff Brown28e0b092012-09-25 11:31:28 -07001087 w.mSystemDecorRect.intersect(-w.mCompatFrame.left, -w.mCompatFrame.top,
1088 displayInfo.logicalWidth - w.mCompatFrame.left,
1089 displayInfo.logicalHeight - w.mCompatFrame.top);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001090 } else if (w.mLayer >= mService.mSystemDecorLayer) {
1091 // Above the decor layer is easy, just use the entire window.
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001092 // Unless we have a universe background... in which case all the
1093 // windows need to be cropped by the screen, so they don't cover
1094 // the universe background.
1095 if (mAnimator.mUniverseBackground == null) {
1096 w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(),
1097 w.mCompatFrame.height());
1098 } else {
1099 applyDecorRect(mService.mScreenRect);
1100 }
1101 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND) {
1102 // The universe background isn't cropped.
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001103 w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(),
1104 w.mCompatFrame.height());
1105 } else {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001106 applyDecorRect(mService.mSystemDecorRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001107 }
1108
1109 if (!w.mSystemDecorRect.equals(w.mLastSystemDecorRect)) {
1110 w.mLastSystemDecorRect.set(w.mSystemDecorRect);
1111 try {
1112 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1113 "CROP " + w.mSystemDecorRect.toShortString(), null);
Mathias Agopian29479eb2013-02-14 14:36:04 -08001114 mSurfaceControl.setWindowCrop(w.mSystemDecorRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001115 } catch (RuntimeException e) {
1116 Slog.w(TAG, "Error setting crop surface of " + w
1117 + " crop=" + w.mSystemDecorRect.toShortString(), e);
1118 if (!recoveringMemory) {
1119 mService.reclaimSomeSurfaceMemoryLocked(this, "crop", true);
1120 }
1121 }
1122 }
1123 }
1124
Craig Mautnera91f9e22012-09-14 16:22:08 -07001125 void setSurfaceBoundariesLocked(final boolean recoveringMemory) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001126 final WindowState w = mWin;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001127 int width, height;
1128 if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
1129 // for a scaled surface, we just want to use
1130 // the requested size.
1131 width = w.mRequestedWidth;
1132 height = w.mRequestedHeight;
1133 } else {
1134 width = w.mCompatFrame.width();
1135 height = w.mCompatFrame.height();
1136 }
1137
1138 if (width < 1) {
1139 width = 1;
1140 }
1141 if (height < 1) {
1142 height = 1;
1143 }
1144 final boolean surfaceResized = mSurfaceW != width || mSurfaceH != height;
1145 if (surfaceResized) {
1146 mSurfaceW = width;
1147 mSurfaceH = height;
1148 }
1149
Craig Mautner4d7349b2012-04-20 14:52:47 -07001150 final float left = w.mShownFrame.left;
1151 final float top = w.mShownFrame.top;
1152 if (mSurfaceX != left || mSurfaceY != top) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001153 try {
1154 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
Craig Mautner4d7349b2012-04-20 14:52:47 -07001155 "POS " + left + ", " + top, null);
1156 mSurfaceX = left;
1157 mSurfaceY = top;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001158 mSurfaceControl.setPosition(left, top);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001159 } catch (RuntimeException e) {
1160 Slog.w(TAG, "Error positioning surface of " + w
Craig Mautner4d7349b2012-04-20 14:52:47 -07001161 + " pos=(" + left
1162 + "," + top + ")", e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001163 if (!recoveringMemory) {
1164 mService.reclaimSomeSurfaceMemoryLocked(this, "position", true);
1165 }
1166 }
1167 }
1168
1169 if (surfaceResized) {
1170 try {
1171 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1172 "SIZE " + width + "x" + height, null);
1173 mSurfaceResized = true;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001174 mSurfaceControl.setSize(width, height);
Craig Mautner76a71652012-09-03 23:23:58 -07001175 final int displayId = w.mDisplayContent.getDisplayId();
1176 mAnimator.setPendingLayoutChanges(displayId,
1177 WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
Craig Mautner3a67f352012-05-07 11:21:33 -07001178 if ((w.mAttrs.flags & LayoutParams.FLAG_DIM_BEHIND) != 0) {
Craig Mautner05d29032013-05-03 13:40:13 -07001179 w.getStack().startDimmingIfNeeded(this);
Craig Mautner3a67f352012-05-07 11:21:33 -07001180 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001181 } catch (RuntimeException e) {
1182 // If something goes wrong with the surface (such
1183 // as running out of memory), don't take down the
1184 // entire system.
1185 Slog.e(TAG, "Error resizing surface of " + w
1186 + " size=(" + width + "x" + height + ")", e);
1187 if (!recoveringMemory) {
1188 mService.reclaimSomeSurfaceMemoryLocked(this, "size", true);
1189 }
1190 }
1191 }
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001192
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001193 updateSurfaceWindowCrop(recoveringMemory);
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001194 }
1195
1196 public void prepareSurfaceLocked(final boolean recoveringMemory) {
1197 final WindowState w = mWin;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001198 if (mSurfaceControl == null) {
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001199 if (w.mOrientationChanging) {
1200 if (DEBUG_ORIENTATION) {
1201 Slog.v(TAG, "Orientation change skips hidden " + w);
1202 }
1203 w.mOrientationChanging = false;
1204 }
1205 return;
1206 }
1207
1208 boolean displayed = false;
1209
1210 computeShownFrameLocked();
1211
Craig Mautnera91f9e22012-09-14 16:22:08 -07001212 setSurfaceBoundariesLocked(recoveringMemory);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001213
Craig Mautner918b53b2012-07-09 14:15:54 -07001214 if (mIsWallpaper && !mWin.mWallpaperVisible) {
Craig Mautner0fa77c12012-06-11 15:57:19 -07001215 // Wallpaper is no longer visible and there is no wp target => hide it.
1216 hide();
Craig Mautner72669d12012-12-18 17:23:54 -08001217 } else if (w.mAttachedHidden || !w.isOnScreen()) {
Craig Mautner0afddcb2012-05-08 15:38:00 -07001218 hide();
Craig Mautner96868332012-12-04 14:29:11 -08001219 mAnimator.hideWallpapersLocked(w);
Craig Mautnerb9836b92012-06-11 11:40:09 -07001220
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001221 // If we are waiting for this window to handle an
1222 // orientation change, well, it is hidden, so
1223 // doesn't really matter. Note that this does
1224 // introduce a potential glitch if the window
1225 // becomes unhidden before it has drawn for the
1226 // new orientation.
1227 if (w.mOrientationChanging) {
1228 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001229 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001230 "Orientation change skips hidden " + w);
1231 }
1232 } else if (mLastLayer != mAnimLayer
1233 || mLastAlpha != mShownAlpha
1234 || mLastDsDx != mDsDx
1235 || mLastDtDx != mDtDx
1236 || mLastDsDy != mDsDy
1237 || mLastDtDy != mDtDy
1238 || w.mLastHScale != w.mHScale
1239 || w.mLastVScale != w.mVScale
Craig Mautner749a7bb2012-04-02 13:49:53 -07001240 || mLastHidden) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001241 displayed = true;
1242 mLastAlpha = mShownAlpha;
1243 mLastLayer = mAnimLayer;
1244 mLastDsDx = mDsDx;
1245 mLastDtDx = mDtDx;
1246 mLastDsDy = mDsDy;
1247 mLastDtDy = mDtDy;
1248 w.mLastHScale = w.mHScale;
1249 w.mLastVScale = w.mVScale;
1250 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1251 "alpha=" + mShownAlpha + " layer=" + mAnimLayer
1252 + " matrix=[" + (mDsDx*w.mHScale)
1253 + "," + (mDtDx*w.mVScale)
1254 + "][" + (mDsDy*w.mHScale)
1255 + "," + (mDtDy*w.mVScale) + "]", null);
Mathias Agopian29479eb2013-02-14 14:36:04 -08001256 if (mSurfaceControl != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001257 try {
1258 mSurfaceAlpha = mShownAlpha;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001259 mSurfaceControl.setAlpha(mShownAlpha);
Craig Mautnerad5725d2012-06-05 10:20:56 -07001260 mSurfaceLayer = mAnimLayer;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001261 mSurfaceControl.setLayer(mAnimLayer);
1262 mSurfaceControl.setMatrix(
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001263 mDsDx*w.mHScale, mDtDx*w.mVScale,
1264 mDsDy*w.mHScale, mDtDy*w.mVScale);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001265
1266 if (mLastHidden && mDrawState == HAS_DRAWN) {
1267 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1268 "SHOW (performLayout)", null);
1269 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
1270 + " during relayout");
1271 if (showSurfaceRobustlyLocked()) {
1272 mLastHidden = false;
Craig Mautner918b53b2012-07-09 14:15:54 -07001273 if (mIsWallpaper) {
Craig Mautner507a2ee2012-06-13 08:39:38 -07001274 mService.dispatchWallpaperVisibility(w, true);
1275 }
Craig Mautner749a7bb2012-04-02 13:49:53 -07001276 } else {
1277 w.mOrientationChanging = false;
1278 }
1279 }
Mathias Agopian29479eb2013-02-14 14:36:04 -08001280 if (mSurfaceControl != null) {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001281 w.mToken.hasVisible = true;
1282 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001283 } catch (RuntimeException e) {
1284 Slog.w(TAG, "Error updating surface in " + w, e);
1285 if (!recoveringMemory) {
1286 mService.reclaimSomeSurfaceMemoryLocked(this, "update", true);
1287 }
1288 }
1289 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001290 } else {
Craig Mautner9e809442012-06-22 17:13:04 -07001291 if (DEBUG_ANIM && isAnimating()) {
1292 Slog.v(TAG, "prepareSurface: No changes in animation for " + this);
Craig Mautner83339b42012-05-01 22:13:23 -07001293 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001294 displayed = true;
1295 }
1296
1297 if (displayed) {
1298 if (w.mOrientationChanging) {
1299 if (!w.isDrawnLw()) {
Craig Mautner2639da52012-07-09 09:39:06 -07001300 mAnimator.mBulkUpdateParams &= ~SET_ORIENTATION_CHANGE_COMPLETE;
Dianne Hackborna57c6952013-03-29 14:46:40 -07001301 mAnimator.mLastWindowFreezeSource = w;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001302 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001303 "Orientation continue waiting for draw in " + w);
1304 } else {
1305 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001306 if (DEBUG_ORIENTATION) Slog.v(TAG, "Orientation change complete in " + w);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001307 }
1308 }
1309 w.mToken.hasVisible = true;
1310 }
1311 }
1312
Craig Mautneref655012013-01-03 11:20:24 -08001313 void setTransparentRegionHintLocked(final Region region) {
Mathias Agopian29479eb2013-02-14 14:36:04 -08001314 if (mSurfaceControl == null) {
Craig Mautner1f4e0cc2012-04-10 14:24:38 -07001315 Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true");
1316 return;
1317 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001318 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1319 ">>> OPEN TRANSACTION setTransparentRegion");
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001320 SurfaceControl.openTransaction();
Craig Mautner48ba1e72012-04-02 13:18:16 -07001321 try {
1322 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
1323 "transparentRegionHint=" + region, null);
Mathias Agopian29479eb2013-02-14 14:36:04 -08001324 mSurfaceControl.setTransparentRegionHint(region);
Craig Mautner48ba1e72012-04-02 13:18:16 -07001325 } finally {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001326 SurfaceControl.closeTransaction();
Craig Mautner48ba1e72012-04-02 13:18:16 -07001327 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1328 "<<< CLOSE TRANSACTION setTransparentRegion");
1329 }
1330 }
1331
Craig Mautner58106812012-12-28 12:27:40 -08001332 void setWallpaperOffset(RectF shownFrame) {
1333 final int left = (int) shownFrame.left;
1334 final int top = (int) shownFrame.top;
1335 if (mSurfaceX != left || mSurfaceY != top) {
1336 mSurfaceX = left;
1337 mSurfaceY = top;
1338 if (mAnimating) {
1339 // If this window (or its app token) is animating, then the position
1340 // of the surface will be re-computed on the next animation frame.
1341 // We can't poke it directly here because it depends on whatever
1342 // transformation is being applied by the animation.
1343 return;
1344 }
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001345 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
Craig Mautner58106812012-12-28 12:27:40 -08001346 ">>> OPEN TRANSACTION setWallpaperOffset");
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001347 SurfaceControl.openTransaction();
Craig Mautner58106812012-12-28 12:27:40 -08001348 try {
1349 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
1350 "POS " + left + ", " + top, null);
Mathias Agopian29479eb2013-02-14 14:36:04 -08001351 mSurfaceControl.setPosition(mWin.mFrame.left + left, mWin.mFrame.top + top);
Craig Mautner58106812012-12-28 12:27:40 -08001352 updateSurfaceWindowCrop(false);
1353 } catch (RuntimeException e) {
1354 Slog.w(TAG, "Error positioning surface of " + mWin
1355 + " pos=(" + left + "," + top + ")", e);
1356 } finally {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001357 SurfaceControl.closeTransaction();
Craig Mautner58106812012-12-28 12:27:40 -08001358 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1359 "<<< CLOSE TRANSACTION setWallpaperOffset");
1360 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001361 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001362 }
1363
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001364 // This must be called while inside a transaction.
1365 boolean performShowLocked() {
Craig Mautner5962b122012-10-05 14:45:52 -07001366 if (mWin.isHiddenFromUserLocked()) {
Craig Mautner88400d32012-09-30 12:35:45 -07001367 Slog.w(TAG, "current user violation " + mService.mCurrentUserId + " trying to display "
Craig Mautnera2d7b112012-08-21 15:12:20 -07001368 + this + ", type " + mWin.mAttrs.type + ", belonging to " + mWin.mOwnerUid);
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001369 return false;
1370 }
Craig Mautner6fbda632012-07-03 09:26:39 -07001371 if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
1372 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001373 RuntimeException e = null;
1374 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
1375 e = new RuntimeException();
1376 e.fillInStackTrace();
1377 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001378 Slog.v(TAG, "performShow on " + this
Craig Mautner749a7bb2012-04-02 13:49:53 -07001379 + ": mDrawState=" + mDrawState + " readyForDisplay="
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001380 + mWin.isReadyForDisplayIgnoringKeyguard()
Craig Mautner6fbda632012-07-03 09:26:39 -07001381 + " starting=" + (mWin.mAttrs.type == TYPE_APPLICATION_STARTING)
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001382 + " during animation: policyVis=" + mWin.mPolicyVisibility
1383 + " attHidden=" + mWin.mAttachedHidden
1384 + " tok.hiddenRequested="
1385 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
1386 + " tok.hidden="
1387 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
1388 + " animating=" + mAnimating
1389 + " tok animating="
Craig Mautner322e4032012-07-13 13:35:20 -07001390 + (mAppAnimator != null ? mAppAnimator.animating : false), e);
Craig Mautner6fbda632012-07-03 09:26:39 -07001391 }
1392 if (mDrawState == READY_TO_SHOW && mWin.isReadyForDisplayIgnoringKeyguard()) {
1393 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
1394 WindowManagerService.logSurface(mWin, "SHOW (performShowLocked)", null);
1395 if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
1396 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
1397 Slog.v(TAG, "Showing " + this
1398 + " during animation: policyVis=" + mWin.mPolicyVisibility
1399 + " attHidden=" + mWin.mAttachedHidden
1400 + " tok.hiddenRequested="
1401 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
1402 + " tok.hidden="
1403 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
1404 + " animating=" + mAnimating
1405 + " tok animating="
Craig Mautner322e4032012-07-13 13:35:20 -07001406 + (mAppAnimator != null ? mAppAnimator.animating : false));
Craig Mautner6fbda632012-07-03 09:26:39 -07001407 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001408
1409 mService.enableScreenIfNeededLocked();
1410
1411 applyEnterAnimationLocked();
1412
Craig Mautnerde6198e2012-04-19 09:59:31 -07001413 // Force the show in the next prepareSurfaceLocked() call.
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001414 mLastAlpha = -1;
Craig Mautneref25d7a2012-05-15 23:01:47 -07001415 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM)
1416 Slog.v(TAG, "performShowLocked: mDrawState=HAS_DRAWN in " + this);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001417 mDrawState = HAS_DRAWN;
Craig Mautner96868332012-12-04 14:29:11 -08001418 mService.scheduleAnimationLocked();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001419
1420 int i = mWin.mChildWindows.size();
1421 while (i > 0) {
1422 i--;
1423 WindowState c = mWin.mChildWindows.get(i);
1424 if (c.mAttachedHidden) {
1425 c.mAttachedHidden = false;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001426 if (c.mWinAnimator.mSurfaceControl != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001427 c.mWinAnimator.performShowLocked();
1428 // It hadn't been shown, which means layout not
1429 // performed on it, so now we want to make sure to
1430 // do a layout. If called from within the transaction
1431 // loop, this will cause it to restart with a new
1432 // layout.
Craig Mautner19d59bc2012-09-04 11:15:56 -07001433 c.mDisplayContent.layoutNeeded = true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001434 }
1435 }
1436 }
1437
1438 if (mWin.mAttrs.type != TYPE_APPLICATION_STARTING
1439 && mWin.mAppToken != null) {
1440 mWin.mAppToken.firstWindowDrawn = true;
1441
1442 if (mWin.mAppToken.startingData != null) {
1443 if (WindowManagerService.DEBUG_STARTING_WINDOW ||
Craig Mautnerd87946b2012-03-29 18:00:19 -07001444 WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001445 "Finish starting " + mWin.mToken
1446 + ": first real window is shown, no animation");
1447 // If this initial window is animating, stop it -- we
1448 // will do an animation to reveal it from behind the
1449 // starting window, so there is no need for it to also
1450 // be doing its own stuff.
Craig Mautner4d7349b2012-04-20 14:52:47 -07001451 clearAnimation();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001452 mService.mFinishedStarting.add(mWin.mAppToken);
1453 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
1454 }
1455 mWin.mAppToken.updateReportedVisibilityLocked();
1456 }
1457
1458 return true;
1459 }
1460
1461 return false;
1462 }
1463
1464 /**
1465 * Have the surface flinger show a surface, robustly dealing with
1466 * error conditions. In particular, if there is not enough memory
1467 * to show the surface, then we will try to get rid of other surfaces
1468 * in order to succeed.
1469 *
1470 * @return Returns true if the surface was successfully shown.
1471 */
1472 boolean showSurfaceRobustlyLocked() {
1473 try {
Mathias Agopian29479eb2013-02-14 14:36:04 -08001474 if (mSurfaceControl != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001475 mSurfaceShown = true;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001476 mSurfaceControl.show();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001477 if (mWin.mTurnOnScreen) {
1478 if (DEBUG_VISIBILITY) Slog.v(TAG,
1479 "Show surface turning screen on: " + mWin);
1480 mWin.mTurnOnScreen = false;
Craig Mautner7d8df392012-04-06 15:26:23 -07001481 mAnimator.mBulkUpdateParams |= SET_TURN_ON_SCREEN;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001482 }
1483 }
1484 return true;
1485 } catch (RuntimeException e) {
Mathias Agopian29479eb2013-02-14 14:36:04 -08001486 Slog.w(TAG, "Failure showing surface " + mSurfaceControl + " in " + mWin, e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001487 }
1488
1489 mService.reclaimSomeSurfaceMemoryLocked(this, "show", true);
1490
1491 return false;
1492 }
1493
1494 void applyEnterAnimationLocked() {
1495 final int transit;
1496 if (mEnterAnimationPending) {
1497 mEnterAnimationPending = false;
1498 transit = WindowManagerPolicy.TRANSIT_ENTER;
1499 } else {
1500 transit = WindowManagerPolicy.TRANSIT_SHOW;
1501 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001502 applyAnimationLocked(transit, true);
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001503 //TODO (multidisplay): Magnification is supported only for the default display.
1504 if (mService.mDisplayMagnifier != null
1505 && mWin.getDisplayId() == Display.DEFAULT_DISPLAY) {
1506 mService.mDisplayMagnifier.onWindowTransitionLocked(mWin, transit);
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -07001507 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001508 }
1509
1510 /**
1511 * Choose the correct animation and set it to the passed WindowState.
Craig Mautner4b71aa12012-12-27 17:20:01 -08001512 * @param transit If AppTransition.TRANSIT_PREVIEW_DONE and the app window has been drawn
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001513 * then the animation will be app_starting_exit. Any other value loads the animation from
1514 * the switch statement below.
1515 * @param isEntrance The animation type the last time this was called. Used to keep from
1516 * loading the same animation twice.
1517 * @return true if an animation has been loaded.
1518 */
1519 boolean applyAnimationLocked(int transit, boolean isEntrance) {
1520 if (mLocalAnimating && mAnimationIsEntrance == isEntrance) {
1521 // If we are trying to apply an animation, but already running
1522 // an animation of the same type, then just leave that one alone.
1523 return true;
1524 }
1525
1526 // Only apply an animation if the display isn't frozen. If it is
1527 // frozen, there is no reason to animate and it can cause strange
1528 // artifacts when we unfreeze the display if some different animation
1529 // is running.
1530 if (mService.okToDisplay()) {
1531 int anim = mPolicy.selectAnimationLw(mWin, transit);
1532 int attr = -1;
1533 Animation a = null;
1534 if (anim != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001535 a = anim != -1 ? AnimationUtils.loadAnimation(mContext, anim) : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001536 } else {
1537 switch (transit) {
1538 case WindowManagerPolicy.TRANSIT_ENTER:
1539 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
1540 break;
1541 case WindowManagerPolicy.TRANSIT_EXIT:
1542 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
1543 break;
1544 case WindowManagerPolicy.TRANSIT_SHOW:
1545 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
1546 break;
1547 case WindowManagerPolicy.TRANSIT_HIDE:
1548 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
1549 break;
1550 }
1551 if (attr >= 0) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001552 a = mService.mAppTransition.loadAnimation(mWin.mAttrs, attr);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001553 }
1554 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001555 if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001556 "applyAnimation: win=" + this
1557 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
Craig Mautner4d7349b2012-04-20 14:52:47 -07001558 + " a=" + a
Craig Mautner8863cca2012-09-18 15:04:34 -07001559 + " transit=" + transit
Craig Mautner83339b42012-05-01 22:13:23 -07001560 + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001561 if (a != null) {
1562 if (WindowManagerService.DEBUG_ANIM) {
1563 RuntimeException e = null;
1564 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
1565 e = new RuntimeException();
1566 e.fillInStackTrace();
1567 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001568 Slog.v(TAG, "Loaded animation " + a + " for " + this, e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001569 }
1570 setAnimation(a);
1571 mAnimationIsEntrance = isEntrance;
1572 }
1573 } else {
1574 clearAnimation();
1575 }
1576
1577 return mAnimation != null;
1578 }
1579
Craig Mautnera2c77052012-03-26 12:14:43 -07001580 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1581 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
1582 || mAnimation != null) {
1583 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
1584 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
1585 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
1586 pw.print(" mAnimation="); pw.println(mAnimation);
1587 }
1588 if (mHasTransformation || mHasLocalTransformation) {
1589 pw.print(prefix); pw.print("XForm: has=");
1590 pw.print(mHasTransformation);
1591 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
1592 pw.print(" "); mTransformation.printShortString(pw);
1593 pw.println();
1594 }
Mathias Agopian29479eb2013-02-14 14:36:04 -08001595 if (mSurfaceControl != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001596 if (dumpAll) {
Mathias Agopian29479eb2013-02-14 14:36:04 -08001597 pw.print(prefix); pw.print("mSurface="); pw.println(mSurfaceControl);
Craig Mautner6fbda632012-07-03 09:26:39 -07001598 pw.print(prefix); pw.print("mDrawState=");
1599 pw.print(drawStateToString(mDrawState));
Craig Mautner749a7bb2012-04-02 13:49:53 -07001600 pw.print(" mLastHidden="); pw.println(mLastHidden);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001601 }
1602 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
1603 pw.print(" layer="); pw.print(mSurfaceLayer);
1604 pw.print(" alpha="); pw.print(mSurfaceAlpha);
1605 pw.print(" rect=("); pw.print(mSurfaceX);
1606 pw.print(","); pw.print(mSurfaceY);
1607 pw.print(") "); pw.print(mSurfaceW);
1608 pw.print(" x "); pw.println(mSurfaceH);
1609 }
1610 if (mPendingDestroySurface != null) {
1611 pw.print(prefix); pw.print("mPendingDestroySurface=");
1612 pw.println(mPendingDestroySurface);
1613 }
1614 if (mSurfaceResized || mSurfaceDestroyDeferred) {
1615 pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized);
1616 pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred);
1617 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001618 if (mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND) {
1619 pw.print(prefix); pw.print("mUniverseTransform=");
1620 mUniverseTransform.printShortString(pw);
1621 pw.println();
1622 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001623 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
1624 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
1625 pw.print(" mAlpha="); pw.print(mAlpha);
1626 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
1627 }
1628 if (mHaveMatrix || mWin.mGlobalScale != 1) {
1629 pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale);
1630 pw.print(" mDsDx="); pw.print(mDsDx);
1631 pw.print(" mDtDx="); pw.print(mDtDx);
1632 pw.print(" mDsDy="); pw.print(mDsDy);
1633 pw.print(" mDtDy="); pw.println(mDtDy);
1634 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001635 }
1636
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001637 @Override
1638 public String toString() {
Dianne Hackborn529e7442012-11-01 14:22:28 -07001639 StringBuffer sb = new StringBuffer("WindowStateAnimator{");
1640 sb.append(Integer.toHexString(System.identityHashCode(this)));
1641 sb.append(' ');
1642 sb.append(mWin.mAttrs.getTitle());
1643 sb.append('}');
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001644 return sb.toString();
1645 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001646}