blob: dd34b2e1e4bb313d7d70007b6c7d5ca70e982838 [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 Mautnerc2f9be02012-03-27 17:32:29 -07006
Craig Mautner2639da52012-07-09 09:39:06 -07007import static com.android.server.wm.WindowManagerService.LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE;
Craig Mautner7d8df392012-04-06 15:26:23 -07008import static com.android.server.wm.WindowManagerService.LayoutFields.SET_TURN_ON_SCREEN;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -07009
Craig Mautnerc2f9be02012-03-27 17:32:29 -070010import android.content.Context;
11import android.graphics.Matrix;
12import android.graphics.PixelFormat;
Craig Mautner7358fbf2012-04-12 21:06:33 -070013import android.graphics.Point;
14import android.graphics.PointF;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070015import android.graphics.Rect;
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;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070019import android.view.Surface;
Craig Mautner7358fbf2012-04-12 21:06:33 -070020import android.view.SurfaceSession;
Craig Mautnera2c77052012-03-26 12:14:43 -070021import android.view.WindowManager;
22import android.view.WindowManagerPolicy;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070023import android.view.WindowManager.LayoutParams;
Craig Mautnera2c77052012-03-26 12:14:43 -070024import android.view.animation.Animation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070025import android.view.animation.AnimationUtils;
Craig Mautnera2c77052012-03-26 12:14:43 -070026import android.view.animation.Transformation;
27
28import com.android.server.wm.WindowManagerService.H;
29
30import java.io.PrintWriter;
Craig Mautner7358fbf2012-04-12 21:06:33 -070031import java.util.ArrayList;
Craig Mautnera2c77052012-03-26 12:14:43 -070032
33/**
Craig Mautnerc2f9be02012-03-27 17:32:29 -070034 * Keep track of animations and surface operations for a single WindowState.
35 **/
Craig Mautnera2c77052012-03-26 12:14:43 -070036class WindowStateAnimator {
Craig Mautnerc2f9be02012-03-27 17:32:29 -070037 static final boolean DEBUG_VISIBILITY = WindowManagerService.DEBUG_VISIBILITY;
38 static final boolean DEBUG_ANIM = WindowManagerService.DEBUG_ANIM;
39 static final boolean DEBUG_LAYERS = WindowManagerService.DEBUG_LAYERS;
40 static final boolean DEBUG_STARTING_WINDOW = WindowManagerService.DEBUG_STARTING_WINDOW;
41 static final boolean SHOW_TRANSACTIONS = WindowManagerService.SHOW_TRANSACTIONS;
42 static final boolean SHOW_LIGHT_TRANSACTIONS = WindowManagerService.SHOW_LIGHT_TRANSACTIONS;
43 static final boolean SHOW_SURFACE_ALLOC = WindowManagerService.SHOW_SURFACE_ALLOC;
44 static final boolean localLOGV = WindowManagerService.localLOGV;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -070045 static final boolean DEBUG_ORIENTATION = WindowManagerService.DEBUG_ORIENTATION;
Craig Mautner7358fbf2012-04-12 21:06:33 -070046 static final boolean DEBUG_SURFACE_TRACE = WindowManagerService.DEBUG_SURFACE_TRACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070047
48 static final String TAG = "WindowStateAnimator";
Craig Mautnera2c77052012-03-26 12:14:43 -070049
Craig Mautner918b53b2012-07-09 14:15:54 -070050 // Unchanging local convenience fields.
Craig Mautnera2c77052012-03-26 12:14:43 -070051 final WindowManagerService mService;
52 final WindowState mWin;
Craig Mautner322e4032012-07-13 13:35:20 -070053 final WindowStateAnimator mAttachedWinAnimator;
Craig Mautnere7ae2502012-03-26 17:11:19 -070054 final WindowAnimator mAnimator;
Craig Mautner322e4032012-07-13 13:35:20 -070055 final AppWindowAnimator mAppAnimator;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070056 final Session mSession;
57 final WindowManagerPolicy mPolicy;
58 final Context mContext;
Craig Mautner918b53b2012-07-09 14:15:54 -070059 final boolean mIsWallpaper;
Craig Mautnera2c77052012-03-26 12:14:43 -070060
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -070061 // If this is a universe background window, this is the transformation
62 // it is applying to the rest of the universe.
63 final Transformation mUniverseTransform = new Transformation();
64
Craig Mautnera2c77052012-03-26 12:14:43 -070065 // Currently running animation.
66 boolean mAnimating;
67 boolean mLocalAnimating;
68 Animation mAnimation;
69 boolean mAnimationIsEntrance;
70 boolean mHasTransformation;
71 boolean mHasLocalTransformation;
72 final Transformation mTransformation = new Transformation();
73 boolean mWasAnimating; // Were we animating going into the most recent animation step?
Craig Mautnerc2f9be02012-03-27 17:32:29 -070074 int mAnimLayer;
75 int mLastLayer;
76
77 Surface mSurface;
78 Surface mPendingDestroySurface;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070079
80 /**
81 * Set when we have changed the size of the surface, to know that
82 * we must tell them application to resize (and thus redraw itself).
83 */
84 boolean mSurfaceResized;
85
86 /**
87 * Set if the client has asked that the destroy of its surface be delayed
88 * until it explicitly says it is okay.
89 */
90 boolean mSurfaceDestroyDeferred;
91
Craig Mautner7d8df392012-04-06 15:26:23 -070092 float mShownAlpha = 0;
93 float mAlpha = 0;
94 float mLastAlpha = 0;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070095
96 // Used to save animation distances between the time they are calculated and when they are
97 // used.
98 int mAnimDw;
99 int mAnimDh;
100 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
101 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
102
103 boolean mHaveMatrix;
104
105 // For debugging, this is the last information given to the surface flinger.
106 boolean mSurfaceShown;
107 float mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
108 int mSurfaceLayer;
109 float mSurfaceAlpha;
110
111 // Set to true if, when the window gets displayed, it should perform
112 // an enter animation.
113 boolean mEnterAnimationPending;
Craig Mautnera2c77052012-03-26 12:14:43 -0700114
Craig Mautner749a7bb2012-04-02 13:49:53 -0700115 /** This is set when there is no Surface */
116 static final int NO_SURFACE = 0;
117 /** This is set after the Surface has been created but before the window has been drawn. During
118 * this time the surface is hidden. */
119 static final int DRAW_PENDING = 1;
120 /** This is set after the window has finished drawing for the first time but before its surface
121 * is shown. The surface will be displayed when the next layout is run. */
122 static final int COMMIT_DRAW_PENDING = 2;
123 /** This is set during the time after the window's drawing has been committed, and before its
124 * surface is actually shown. It is used to delay showing the surface until all windows in a
125 * token are ready to be shown. */
126 static final int READY_TO_SHOW = 3;
127 /** Set when the window has been shown in the screen the first time. */
128 static final int HAS_DRAWN = 4;
Craig Mautner6fbda632012-07-03 09:26:39 -0700129 static String drawStateToString(int state) {
130 switch (state) {
131 case NO_SURFACE: return "NO_SURFACE";
132 case DRAW_PENDING: return "DRAW_PENDING";
133 case COMMIT_DRAW_PENDING: return "COMMIT_DRAW_PENDING";
134 case READY_TO_SHOW: return "READY_TO_SHOW";
135 case HAS_DRAWN: return "HAS_DRAWN";
136 default: return Integer.toString(state);
137 }
138 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700139 int mDrawState;
Craig Mautnera608b882012-03-30 13:03:49 -0700140
Craig Mautner749a7bb2012-04-02 13:49:53 -0700141 /** Was this window last hidden? */
142 boolean mLastHidden;
Craig Mautnera608b882012-03-30 13:03:49 -0700143
Craig Mautnerbec53f72012-04-05 11:49:05 -0700144 int mAttrFlags;
145 int mAttrType;
146
Craig Mautner918b53b2012-07-09 14:15:54 -0700147 public WindowStateAnimator(final WindowState win) {
148 final WindowManagerService service = win.mService;
149
Craig Mautnera2c77052012-03-26 12:14:43 -0700150 mService = service;
Craig Mautner918b53b2012-07-09 14:15:54 -0700151 mAnimator = service.mAnimator;
152 mPolicy = service.mPolicy;
153 mContext = service.mContext;
Craig Mautner9aa69582012-05-09 17:41:13 -0700154 mAnimDw = service.mAppDisplayWidth;
155 mAnimDh = service.mAppDisplayHeight;
Craig Mautner918b53b2012-07-09 14:15:54 -0700156
157 mWin = win;
Craig Mautner322e4032012-07-13 13:35:20 -0700158 mAttachedWinAnimator = win.mAttachedWindow == null
159 ? null : win.mAttachedWindow.mWinAnimator;
160 mAppAnimator = win.mAppToken == null ? null : win.mAppToken.mAppAnimator;
Craig Mautner918b53b2012-07-09 14:15:54 -0700161 mSession = win.mSession;
162 mAttrFlags = win.mAttrs.flags;
163 mAttrType = win.mAttrs.type;
164 mIsWallpaper = win.mIsWallpaper;
Craig Mautnera2c77052012-03-26 12:14:43 -0700165 }
166
167 public void setAnimation(Animation anim) {
Craig Mautnerbec53f72012-04-05 11:49:05 -0700168 if (localLOGV) Slog.v(TAG, "Setting animation in " + this + ": " + anim);
Craig Mautnera2c77052012-03-26 12:14:43 -0700169 mAnimating = false;
170 mLocalAnimating = false;
171 mAnimation = anim;
172 mAnimation.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION);
173 mAnimation.scaleCurrentDuration(mService.mWindowAnimationScale);
174 // Start out animation gone if window is gone, or visible if window is visible.
175 mTransformation.clear();
Craig Mautner749a7bb2012-04-02 13:49:53 -0700176 mTransformation.setAlpha(mLastHidden ? 0 : 1);
Craig Mautnera2c77052012-03-26 12:14:43 -0700177 mHasLocalTransformation = true;
178 }
179
180 public void clearAnimation() {
181 if (mAnimation != null) {
182 mAnimating = true;
183 mLocalAnimating = false;
184 mAnimation.cancel();
185 mAnimation = null;
186 }
187 }
188
189 /** Is the window or its container currently animating? */
190 boolean isAnimating() {
Craig Mautnera2c77052012-03-26 12:14:43 -0700191 return mAnimation != null
Craig Mautner322e4032012-07-13 13:35:20 -0700192 || (mAttachedWinAnimator != null && mAttachedWinAnimator.mAnimation != null)
193 || (mAppAnimator != null &&
194 (mAppAnimator.animation != null
195 || mAppAnimator.mAppToken.inPendingTransaction));
Craig Mautnera2c77052012-03-26 12:14:43 -0700196 }
197
Craig Mautner0afddcb2012-05-08 15:38:00 -0700198 /** Is the window animating the DummyAnimation? */
199 boolean isDummyAnimation() {
Craig Mautner322e4032012-07-13 13:35:20 -0700200 return mAppAnimator != null
201 && mAppAnimator.animation == AppWindowAnimator.sDummyAnimation;
Craig Mautner0afddcb2012-05-08 15:38:00 -0700202 }
203
Craig Mautnera2c77052012-03-26 12:14:43 -0700204 /** Is this window currently animating? */
205 boolean isWindowAnimating() {
206 return mAnimation != null;
207 }
208
Craig Mautnera2c77052012-03-26 12:14:43 -0700209 void cancelExitAnimationForNextAnimationLocked() {
Craig Mautnera2c77052012-03-26 12:14:43 -0700210 if (mAnimation != null) {
211 mAnimation.cancel();
212 mAnimation = null;
Craig Mautner4d7349b2012-04-20 14:52:47 -0700213 mLocalAnimating = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700214 destroySurfaceLocked();
Craig Mautnera2c77052012-03-26 12:14:43 -0700215 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700216 }
217
218 private boolean stepAnimation(long currentTime) {
219 if ((mAnimation == null) || !mLocalAnimating) {
220 return false;
221 }
222 mTransformation.clear();
223 final boolean more = mAnimation.getTransformation(currentTime, mTransformation);
Craig Mautner9e809442012-06-22 17:13:04 -0700224 if (false && DEBUG_ANIM) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700225 TAG, "Stepped animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700226 ": more=" + more + ", xform=" + mTransformation);
227 return more;
228 }
229
230 // This must be called while inside a transaction. Returns true if
231 // there is more animation to run.
232 boolean stepAnimationLocked(long currentTime) {
233 // Save the animation state as it was before this step so WindowManagerService can tell if
234 // we just started or just stopped animating by comparing mWasAnimating with isAnimating().
235 mWasAnimating = mAnimating;
236 if (mService.okToDisplay()) {
237 // We will run animations as long as the display isn't frozen.
238
239 if (mWin.isDrawnLw() && mAnimation != null) {
240 mHasTransformation = true;
241 mHasLocalTransformation = true;
242 if (!mLocalAnimating) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700243 if (DEBUG_ANIM) Slog.v(
244 TAG, "Starting animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700245 " @ " + currentTime + ": ww=" + mWin.mFrame.width() +
246 " wh=" + mWin.mFrame.height() +
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700247 " dw=" + mAnimDw + " dh=" + mAnimDh +
Craig Mautnera2c77052012-03-26 12:14:43 -0700248 " scale=" + mService.mWindowAnimationScale);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700249 mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(),
250 mAnimDw, mAnimDh);
Craig Mautner9aa69582012-05-09 17:41:13 -0700251 mAnimDw = mService.mAppDisplayWidth;
252 mAnimDh = mService.mAppDisplayHeight;
Craig Mautnera2c77052012-03-26 12:14:43 -0700253 mAnimation.setStartTime(currentTime);
254 mLocalAnimating = true;
255 mAnimating = true;
256 }
257 if ((mAnimation != null) && mLocalAnimating) {
258 if (stepAnimation(currentTime)) {
259 return true;
260 }
261 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700262 if (DEBUG_ANIM) Slog.v(
263 TAG, "Finished animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700264 " @ " + currentTime);
265 //WindowManagerService.this.dump();
266 }
267 mHasLocalTransformation = false;
Craig Mautner322e4032012-07-13 13:35:20 -0700268 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppAnimator != null
269 && mAppAnimator.animation != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700270 // When our app token is animating, we kind-of pretend like
271 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
272 // part of this check means that we will only do this if
273 // our window is not currently exiting, or it is not
274 // locally animating itself. The idea being that one that
275 // is exiting and doing a local animation should be removed
276 // once that animation is done.
277 mAnimating = true;
278 mHasTransformation = true;
279 mTransformation.clear();
280 return false;
281 } else if (mHasTransformation) {
282 // Little trick to get through the path below to act like
283 // we have finished an animation.
284 mAnimating = true;
285 } else if (isAnimating()) {
286 mAnimating = true;
287 }
288 } else if (mAnimation != null) {
289 // If the display is frozen, and there is a pending animation,
290 // clear it and make sure we run the cleanup code.
291 mAnimating = true;
Craig Mautnera2c77052012-03-26 12:14:43 -0700292 }
293
294 if (!mAnimating && !mLocalAnimating) {
295 return false;
296 }
297
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700298 // Done animating, clean up.
299 if (DEBUG_ANIM) Slog.v(
300 TAG, "Animation done in " + this + ": exiting=" + mWin.mExiting
Craig Mautnera2c77052012-03-26 12:14:43 -0700301 + ", reportedVisible="
302 + (mWin.mAppToken != null ? mWin.mAppToken.reportedVisible : false));
303
304 mAnimating = false;
305 mLocalAnimating = false;
306 if (mAnimation != null) {
307 mAnimation.cancel();
308 mAnimation = null;
309 }
Craig Mautnere7ae2502012-03-26 17:11:19 -0700310 if (mAnimator.mWindowDetachedWallpaper == mWin) {
311 mAnimator.mWindowDetachedWallpaper = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700312 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700313 mAnimLayer = mWin.mLayer;
Craig Mautnera2c77052012-03-26 12:14:43 -0700314 if (mWin.mIsImWindow) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700315 mAnimLayer += mService.mInputMethodAnimLayerAdjustment;
Craig Mautner918b53b2012-07-09 14:15:54 -0700316 } else if (mIsWallpaper) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700317 mAnimLayer += mService.mWallpaperAnimLayerAdjustment;
Craig Mautnera2c77052012-03-26 12:14:43 -0700318 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700319 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
320 + " anim layer: " + mAnimLayer);
Craig Mautnera2c77052012-03-26 12:14:43 -0700321 mHasTransformation = false;
322 mHasLocalTransformation = false;
323 if (mWin.mPolicyVisibility != mWin.mPolicyVisibilityAfterAnim) {
324 if (WindowState.DEBUG_VISIBILITY) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700325 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
Craig Mautnera2c77052012-03-26 12:14:43 -0700326 + mWin.mPolicyVisibilityAfterAnim);
327 }
328 mWin.mPolicyVisibility = mWin.mPolicyVisibilityAfterAnim;
329 mService.mLayoutNeeded = true;
330 if (!mWin.mPolicyVisibility) {
331 if (mService.mCurrentFocus == mWin) {
332 mService.mFocusMayChange = true;
333 }
334 // Window is no longer visible -- make sure if we were waiting
335 // for it to be displayed before enabling the display, that
336 // we allow the display to be enabled now.
337 mService.enableScreenIfNeededLocked();
338 }
339 }
340 mTransformation.clear();
Craig Mautner749a7bb2012-04-02 13:49:53 -0700341 if (mDrawState == HAS_DRAWN
Craig Mautnera2c77052012-03-26 12:14:43 -0700342 && mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
343 && mWin.mAppToken != null
344 && mWin.mAppToken.firstWindowDrawn
345 && mWin.mAppToken.startingData != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700346 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
Craig Mautnera2c77052012-03-26 12:14:43 -0700347 + mWin.mToken + ": first real window done animating");
348 mService.mFinishedStarting.add(mWin.mAppToken);
349 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
350 }
351
352 finishExit();
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700353 mAnimator.mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
354 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) mService.debugLayoutRepeats(
355 "WindowStateAnimator", mAnimator.mPendingLayoutChanges);
Craig Mautnera2c77052012-03-26 12:14:43 -0700356
357 if (mWin.mAppToken != null) {
358 mWin.mAppToken.updateReportedVisibilityLocked();
359 }
360
361 return false;
362 }
363
364 void finishExit() {
365 if (WindowManagerService.DEBUG_ANIM) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700366 TAG, "finishExit in " + this
Craig Mautnera2c77052012-03-26 12:14:43 -0700367 + ": exiting=" + mWin.mExiting
368 + " remove=" + mWin.mRemoveOnExit
369 + " windowAnimating=" + isWindowAnimating());
370
371 final int N = mWin.mChildWindows.size();
372 for (int i=0; i<N; i++) {
373 mWin.mChildWindows.get(i).mWinAnimator.finishExit();
374 }
375
376 if (!mWin.mExiting) {
377 return;
378 }
379
380 if (isWindowAnimating()) {
381 return;
382 }
383
384 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700385 TAG, "Exit animation finished in " + this
Craig Mautnera2c77052012-03-26 12:14:43 -0700386 + ": remove=" + mWin.mRemoveOnExit);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700387 if (mSurface != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700388 mService.mDestroySurface.add(mWin);
389 mWin.mDestroying = true;
390 if (WindowState.SHOW_TRANSACTIONS) WindowManagerService.logSurface(
391 mWin, "HIDE (finishExit)", null);
Craig Mautner0afddcb2012-05-08 15:38:00 -0700392 hide();
Craig Mautnera2c77052012-03-26 12:14:43 -0700393 }
394 mWin.mExiting = false;
395 if (mWin.mRemoveOnExit) {
396 mService.mPendingRemove.add(mWin);
397 mWin.mRemoveOnExit = false;
398 }
Craig Mautnerb9836b92012-06-11 11:40:09 -0700399 mAnimator.hideWallpapersLocked(mWin);
Craig Mautner0afddcb2012-05-08 15:38:00 -0700400 }
401
402 void hide() {
403 if (!mLastHidden) {
404 //dump();
405 mLastHidden = true;
406 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
407 "HIDE (performLayout)", null);
408 if (mSurface != null) {
409 mSurfaceShown = false;
410 try {
411 mSurface.hide();
412 } catch (RuntimeException e) {
413 Slog.w(TAG, "Exception hiding surface in " + mWin);
414 }
415 }
416 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700417 }
418
Craig Mautnera608b882012-03-30 13:03:49 -0700419 boolean finishDrawingLocked() {
Craig Mautner6fbda632012-07-03 09:26:39 -0700420 if (DEBUG_STARTING_WINDOW &&
421 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
422 Slog.v(TAG, "Finishing drawing window " + mWin + ": mDrawState="
423 + drawStateToString(mDrawState));
424 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700425 if (mDrawState == DRAW_PENDING) {
Craig Mautneref25d7a2012-05-15 23:01:47 -0700426 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
427 Slog.v(TAG, "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING " + this + " in "
Craig Mautner83339b42012-05-01 22:13:23 -0700428 + mSurface);
Craig Mautner6fbda632012-07-03 09:26:39 -0700429 if (DEBUG_STARTING_WINDOW &&
430 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
431 Slog.v(TAG, "Draw state now committed in " + mWin);
432 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700433 mDrawState = COMMIT_DRAW_PENDING;
Craig Mautnera608b882012-03-30 13:03:49 -0700434 return true;
435 }
436 return false;
437 }
438
439 // This must be called while inside a transaction.
440 boolean commitFinishDrawingLocked(long currentTime) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700441 if (DEBUG_STARTING_WINDOW &&
442 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
443 Slog.i(TAG, "commitFinishDrawingLocked: " + mWin + " cur mDrawState="
444 + drawStateToString(mDrawState));
445 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700446 if (mDrawState != COMMIT_DRAW_PENDING) {
Craig Mautnera608b882012-03-30 13:03:49 -0700447 return false;
448 }
Craig Mautner6fbda632012-07-03 09:26:39 -0700449 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) {
Craig Mautner83339b42012-05-01 22:13:23 -0700450 Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurface);
Craig Mautner6fbda632012-07-03 09:26:39 -0700451 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700452 mDrawState = READY_TO_SHOW;
Craig Mautnera608b882012-03-30 13:03:49 -0700453 final boolean starting = mWin.mAttrs.type == TYPE_APPLICATION_STARTING;
454 final AppWindowToken atoken = mWin.mAppToken;
455 if (atoken == null || atoken.allDrawn || starting) {
456 performShowLocked();
457 }
458 return true;
459 }
460
Craig Mautner7d8df392012-04-06 15:26:23 -0700461 static class SurfaceTrace extends Surface {
462 private final static String SURFACE_TAG = "SurfaceTrace";
463 final static ArrayList<SurfaceTrace> sSurfaces = new ArrayList<SurfaceTrace>();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700464
Craig Mautner7d8df392012-04-06 15:26:23 -0700465 private float mSurfaceTraceAlpha = 0;
Craig Mautner7358fbf2012-04-12 21:06:33 -0700466 private int mLayer;
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700467 private final PointF mPosition = new PointF();
468 private final Point mSize = new Point();
469 private final Rect mWindowCrop = new Rect();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700470 private boolean mShown = false;
471 private String mName = "Not named";
472
Craig Mautner7d8df392012-04-06 15:26:23 -0700473 public SurfaceTrace(SurfaceSession s,
Craig Mautner7358fbf2012-04-12 21:06:33 -0700474 int pid, int display, int w, int h, int format, int flags) throws
475 OutOfResourcesException {
476 super(s, pid, display, w, h, format, flags);
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700477 mSize.set(w, h);
Craig Mautner7d8df392012-04-06 15:26:23 -0700478 Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700479 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700480 }
481
Craig Mautner7d8df392012-04-06 15:26:23 -0700482 public SurfaceTrace(SurfaceSession s,
Craig Mautner7358fbf2012-04-12 21:06:33 -0700483 int pid, String name, int display, int w, int h, int format, int flags)
484 throws OutOfResourcesException {
485 super(s, pid, name, display, w, h, format, flags);
486 mName = name;
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700487 mSize.set(w, h);
Craig Mautner7d8df392012-04-06 15:26:23 -0700488 Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700489 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700490 }
491
492 @Override
493 public void setAlpha(float alpha) {
494 super.setAlpha(alpha);
Craig Mautner7d8df392012-04-06 15:26:23 -0700495 mSurfaceTraceAlpha = alpha;
496 Slog.v(SURFACE_TAG, "setAlpha: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700497 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700498 }
499
500 @Override
501 public void setLayer(int zorder) {
502 super.setLayer(zorder);
503 mLayer = zorder;
Craig Mautner7d8df392012-04-06 15:26:23 -0700504 Slog.v(SURFACE_TAG, "setLayer: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700505 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700506
507 sSurfaces.remove(this);
508 int i;
509 for (i = sSurfaces.size() - 1; i >= 0; i--) {
Craig Mautner7d8df392012-04-06 15:26:23 -0700510 SurfaceTrace s = sSurfaces.get(i);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700511 if (s.mLayer < zorder) {
512 break;
513 }
514 }
515 sSurfaces.add(i + 1, this);
516 }
517
518 @Override
519 public void setPosition(float x, float y) {
520 super.setPosition(x, y);
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700521 mPosition.set(x, y);
Craig Mautner7d8df392012-04-06 15:26:23 -0700522 Slog.v(SURFACE_TAG, "setPosition: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700523 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700524 }
525
526 @Override
527 public void setSize(int w, int h) {
528 super.setSize(w, h);
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700529 mSize.set(w, h);
Craig Mautner7d8df392012-04-06 15:26:23 -0700530 Slog.v(SURFACE_TAG, "setSize: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700531 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700532 }
533
534 @Override
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700535 public void setWindowCrop(Rect crop) {
536 super.setWindowCrop(crop);
Craig Mautneref25d7a2012-05-15 23:01:47 -0700537 if (crop != null) {
538 mWindowCrop.set(crop);
539 }
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700540 Slog.v(SURFACE_TAG, "setWindowCrop: " + this + ". Called by "
541 + Debug.getCallers(3));
542 }
543
544 @Override
Craig Mautner7358fbf2012-04-12 21:06:33 -0700545 public void hide() {
546 super.hide();
547 mShown = false;
Craig Mautner7d8df392012-04-06 15:26:23 -0700548 Slog.v(SURFACE_TAG, "hide: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700549 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700550 }
551 @Override
552 public void show() {
553 super.show();
554 mShown = true;
Craig Mautner7d8df392012-04-06 15:26:23 -0700555 Slog.v(SURFACE_TAG, "show: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700556 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700557 }
558
559 @Override
560 public void destroy() {
561 super.destroy();
Craig Mautner7d8df392012-04-06 15:26:23 -0700562 Slog.v(SURFACE_TAG, "destroy: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700563 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700564 sSurfaces.remove(this);
565 }
566
Craig Mautneracaf9cc2012-04-17 11:45:25 -0700567 @Override
568 public void release() {
569 super.release();
570 Slog.v(SURFACE_TAG, "release: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700571 + Debug.getCallers(3));
Craig Mautneracaf9cc2012-04-17 11:45:25 -0700572 sSurfaces.remove(this);
573 }
574
Craig Mautner7358fbf2012-04-12 21:06:33 -0700575 static void dumpAllSurfaces() {
576 final int N = sSurfaces.size();
577 for (int i = 0; i < N; i++) {
578 Slog.i(TAG, "SurfaceDump: " + sSurfaces.get(i));
579 }
580 }
581
582 @Override
583 public String toString() {
Craig Mautnerfbf378c2012-04-23 17:24:21 -0700584 return "Surface " + Integer.toHexString(System.identityHashCode(this)) + " "
585 + mName + ": shown=" + mShown + " layer=" + mLayer
Craig Mautner7d8df392012-04-06 15:26:23 -0700586 + " alpha=" + mSurfaceTraceAlpha + " " + mPosition.x + "," + mPosition.y
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700587 + " " + mSize.x + "x" + mSize.y
588 + " crop=" + mWindowCrop.toShortString();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700589 }
590 }
591
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700592 Surface createSurfaceLocked() {
593 if (mSurface == null) {
Craig Mautner83339b42012-05-01 22:13:23 -0700594 if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG,
595 "createSurface " + this + ": mDrawState=DRAW_PENDING");
Craig Mautner749a7bb2012-04-02 13:49:53 -0700596 mDrawState = DRAW_PENDING;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700597 if (mWin.mAppToken != null) {
598 mWin.mAppToken.allDrawn = false;
599 }
600
601 mService.makeWindowFreezingScreenIfNeededLocked(mWin);
602
603 int flags = 0;
604 final WindowManager.LayoutParams attrs = mWin.mAttrs;
605
606 if ((attrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
607 flags |= Surface.SECURE;
608 }
609 if (WindowState.DEBUG_VISIBILITY) Slog.v(
610 TAG, "Creating surface in session "
611 + mSession.mSurfaceSession + " window " + this
612 + " w=" + mWin.mCompatFrame.width()
613 + " h=" + mWin.mCompatFrame.height() + " format="
614 + attrs.format + " flags=" + flags);
615
616 int w = mWin.mCompatFrame.width();
617 int h = mWin.mCompatFrame.height();
618 if ((attrs.flags & LayoutParams.FLAG_SCALED) != 0) {
619 // for a scaled surface, we always want the requested
620 // size.
621 w = mWin.mRequestedWidth;
622 h = mWin.mRequestedHeight;
623 }
624
625 // Something is wrong and SurfaceFlinger will not like this,
626 // try to revert to sane values
627 if (w <= 0) w = 1;
628 if (h <= 0) h = 1;
629
630 mSurfaceShown = false;
631 mSurfaceLayer = 0;
Craig Mautner7d8df392012-04-06 15:26:23 -0700632 mSurfaceAlpha = 0;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700633 mSurfaceX = 0;
634 mSurfaceY = 0;
635 mSurfaceW = w;
636 mSurfaceH = h;
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700637 mWin.mLastSystemDecorRect.set(0, 0, 0, 0);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700638 try {
639 final boolean isHwAccelerated = (attrs.flags &
640 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
641 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
642 if (!PixelFormat.formatHasAlpha(attrs.format)) {
643 flags |= Surface.OPAQUE;
644 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700645 if (DEBUG_SURFACE_TRACE) {
Craig Mautner7d8df392012-04-06 15:26:23 -0700646 mSurface = new SurfaceTrace(
Craig Mautner7358fbf2012-04-12 21:06:33 -0700647 mSession.mSurfaceSession, mSession.mPid,
648 attrs.getTitle().toString(),
649 0, w, h, format, flags);
650 } else {
651 mSurface = new Surface(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700652 mSession.mSurfaceSession, mSession.mPid,
653 attrs.getTitle().toString(),
654 0, w, h, format, flags);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700655 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700656 mWin.mHasSurface = true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700657 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG,
658 " CREATE SURFACE "
659 + mSurface + " IN SESSION "
660 + mSession.mSurfaceSession
661 + ": pid=" + mSession.mPid + " format="
662 + attrs.format + " flags=0x"
663 + Integer.toHexString(flags)
664 + " / " + this);
665 } catch (Surface.OutOfResourcesException e) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700666 mWin.mHasSurface = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700667 Slog.w(TAG, "OutOfResourcesException creating surface");
668 mService.reclaimSomeSurfaceMemoryLocked(this, "create", true);
Craig Mautner749a7bb2012-04-02 13:49:53 -0700669 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700670 return null;
671 } catch (Exception e) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700672 mWin.mHasSurface = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700673 Slog.e(TAG, "Exception creating surface", e);
Craig Mautner749a7bb2012-04-02 13:49:53 -0700674 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700675 return null;
676 }
677
678 if (WindowManagerService.localLOGV) Slog.v(
679 TAG, "Got surface: " + mSurface
680 + ", set left=" + mWin.mFrame.left + " top=" + mWin.mFrame.top
681 + ", animLayer=" + mAnimLayer);
682 if (SHOW_LIGHT_TRANSACTIONS) {
683 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
684 WindowManagerService.logSurface(mWin, "CREATE pos=("
685 + mWin.mFrame.left + "," + mWin.mFrame.top + ") ("
686 + mWin.mCompatFrame.width() + "x" + mWin.mCompatFrame.height()
687 + "), layer=" + mAnimLayer + " HIDE", null);
688 }
689 Surface.openTransaction();
690 try {
691 try {
692 mSurfaceX = mWin.mFrame.left + mWin.mXOffset;
693 mSurfaceY = mWin.mFrame.top + mWin.mYOffset;
694 mSurface.setPosition(mSurfaceX, mSurfaceY);
695 mSurfaceLayer = mAnimLayer;
696 mSurface.setLayer(mAnimLayer);
Craig Mautner7d8df392012-04-06 15:26:23 -0700697 mSurface.setAlpha(0);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700698 mSurfaceShown = false;
699 mSurface.hide();
700 if ((mWin.mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
701 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, "DITHER", null);
702 mSurface.setFlags(Surface.SURFACE_DITHER, Surface.SURFACE_DITHER);
703 }
704 } catch (RuntimeException e) {
705 Slog.w(TAG, "Error creating surface in " + w, e);
706 mService.reclaimSomeSurfaceMemoryLocked(this, "create-init", true);
707 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700708 mLastHidden = true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700709 } finally {
710 Surface.closeTransaction();
711 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
712 "<<< CLOSE TRANSACTION createSurfaceLocked");
713 }
714 if (WindowManagerService.localLOGV) Slog.v(
715 TAG, "Created surface " + this);
716 }
717 return mSurface;
718 }
719
720 void destroySurfaceLocked() {
721 if (mWin.mAppToken != null && mWin == mWin.mAppToken.startingWindow) {
722 mWin.mAppToken.startingDisplayed = false;
723 }
724
725 if (mSurface != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700726
727 int i = mWin.mChildWindows.size();
728 while (i > 0) {
729 i--;
730 WindowState c = mWin.mChildWindows.get(i);
731 c.mAttachedHidden = true;
732 }
733
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700734 try {
735 if (DEBUG_VISIBILITY) {
736 RuntimeException e = null;
737 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
738 e = new RuntimeException();
739 e.fillInStackTrace();
740 }
741 Slog.w(TAG, "Window " + this + " destroying surface "
742 + mSurface + ", session " + mSession, e);
743 }
744 if (mSurfaceDestroyDeferred) {
745 if (mSurface != null && mPendingDestroySurface != mSurface) {
746 if (mPendingDestroySurface != null) {
747 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
748 RuntimeException e = null;
749 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
750 e = new RuntimeException();
751 e.fillInStackTrace();
752 }
753 WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
754 }
755 mPendingDestroySurface.destroy();
756 }
757 mPendingDestroySurface = mSurface;
758 }
759 } else {
760 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
761 RuntimeException e = null;
762 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
763 e = new RuntimeException();
764 e.fillInStackTrace();
765 }
766 WindowManagerService.logSurface(mWin, "DESTROY", e);
767 }
768 mSurface.destroy();
769 }
Craig Mautnerb9836b92012-06-11 11:40:09 -0700770 mAnimator.hideWallpapersLocked(mWin);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700771 } catch (RuntimeException e) {
772 Slog.w(TAG, "Exception thrown when destroying Window " + this
773 + " surface " + mSurface + " session " + mSession
774 + ": " + e.toString());
775 }
776
777 mSurfaceShown = false;
778 mSurface = null;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700779 mWin.mHasSurface =false;
Craig Mautnerbf08af32012-05-16 19:43:42 -0700780 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700781 }
782 }
783
784 void destroyDeferredSurfaceLocked() {
785 try {
786 if (mPendingDestroySurface != null) {
787 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
788 RuntimeException e = null;
789 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
790 e = new RuntimeException();
791 e.fillInStackTrace();
792 }
793 WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
794 }
795 mPendingDestroySurface.destroy();
Craig Mautnerb9836b92012-06-11 11:40:09 -0700796 mAnimator.hideWallpapersLocked(mWin);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700797 }
798 } catch (RuntimeException e) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700799 Slog.w(TAG, "Exception thrown when destroying Window "
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700800 + this + " surface " + mPendingDestroySurface
801 + " session " + mSession + ": " + e.toString());
802 }
803 mSurfaceDestroyDeferred = false;
804 mPendingDestroySurface = null;
805 }
806
807 void computeShownFrameLocked() {
808 final boolean selfTransformation = mHasLocalTransformation;
809 Transformation attachedTransformation =
Craig Mautner322e4032012-07-13 13:35:20 -0700810 (mAttachedWinAnimator != null && mAttachedWinAnimator.mHasLocalTransformation)
811 ? mAttachedWinAnimator.mTransformation : null;
812 Transformation appTransformation = (mAppAnimator != null && mAppAnimator.hasTransformation)
813 ? mAppAnimator.transformation : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700814
815 // Wallpapers are animated based on the "real" window they
816 // are currently targeting.
Craig Mautner918b53b2012-07-09 14:15:54 -0700817 if (mIsWallpaper && mAnimator.mLowerWallpaperTarget == null
818 && mAnimator.mWallpaperTarget != null) {
819 final WindowStateAnimator wallpaperAnimator = mAnimator.mWallpaperTarget.mWinAnimator;
820 if (wallpaperAnimator.mHasLocalTransformation &&
821 wallpaperAnimator.mAnimation != null &&
822 !wallpaperAnimator.mAnimation.getDetachWallpaper()) {
823 attachedTransformation = wallpaperAnimator.mTransformation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700824 if (WindowManagerService.DEBUG_WALLPAPER && attachedTransformation != null) {
825 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
826 }
827 }
Craig Mautner918b53b2012-07-09 14:15:54 -0700828 final AppWindowAnimator wpAppAnimator = mAnimator.mWpAppAnimator;
829 if (wpAppAnimator != null && wpAppAnimator.hasTransformation
830 && wpAppAnimator.animation != null
831 && !wpAppAnimator.animation.getDetachWallpaper()) {
Craig Mautner59431632012-04-04 11:56:44 -0700832 appTransformation = wpAppAnimator.transformation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700833 if (WindowManagerService.DEBUG_WALLPAPER && appTransformation != null) {
834 Slog.v(TAG, "WP target app xform: " + appTransformation);
835 }
836 }
837 }
838
839 final boolean screenAnimation = mService.mAnimator.mScreenRotationAnimation != null
840 && mService.mAnimator.mScreenRotationAnimation.isAnimating();
841 if (selfTransformation || attachedTransformation != null
842 || appTransformation != null || screenAnimation) {
843 // cache often used attributes locally
844 final Rect frame = mWin.mFrame;
845 final float tmpFloats[] = mService.mTmpFloats;
846 final Matrix tmpMatrix = mWin.mTmpMatrix;
847
848 // Compute the desired transformation.
849 if (screenAnimation) {
850 // If we are doing a screen animation, the global rotation
851 // applied to windows can result in windows that are carefully
852 // aligned with each other to slightly separate, allowing you
853 // to see what is behind them. An unsightly mess. This...
854 // thing... magically makes it call good: scale each window
855 // slightly (two pixels larger in each dimension, from the
856 // window's center).
857 final float w = frame.width();
858 final float h = frame.height();
859 if (w>=1 && h>=1) {
860 tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2);
861 } else {
862 tmpMatrix.reset();
863 }
864 } else {
865 tmpMatrix.reset();
866 }
867 tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale);
868 if (selfTransformation) {
869 tmpMatrix.postConcat(mTransformation.getMatrix());
870 }
871 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
872 if (attachedTransformation != null) {
873 tmpMatrix.postConcat(attachedTransformation.getMatrix());
874 }
875 if (appTransformation != null) {
876 tmpMatrix.postConcat(appTransformation.getMatrix());
877 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700878 if (mAnimator.mUniverseBackground != null) {
879 tmpMatrix.postConcat(mAnimator.mUniverseBackground.mUniverseTransform.getMatrix());
880 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700881 if (screenAnimation) {
882 tmpMatrix.postConcat(
883 mService.mAnimator.mScreenRotationAnimation.getEnterTransformation().getMatrix());
884 }
885
886 // "convert" it into SurfaceFlinger's format
887 // (a 2x2 matrix + an offset)
888 // Here we must not transform the position of the surface
889 // since it is already included in the transformation.
890 //Slog.i(TAG, "Transform: " + matrix);
891
892 mHaveMatrix = true;
893 tmpMatrix.getValues(tmpFloats);
894 mDsDx = tmpFloats[Matrix.MSCALE_X];
895 mDtDx = tmpFloats[Matrix.MSKEW_Y];
896 mDsDy = tmpFloats[Matrix.MSKEW_X];
897 mDtDy = tmpFloats[Matrix.MSCALE_Y];
898 float x = tmpFloats[Matrix.MTRANS_X];
899 float y = tmpFloats[Matrix.MTRANS_Y];
900 int w = frame.width();
901 int h = frame.height();
902 mWin.mShownFrame.set(x, y, x+w, y+h);
903
904 // Now set the alpha... but because our current hardware
905 // can't do alpha transformation on a non-opaque surface,
906 // turn it off if we are running an animation that is also
907 // transforming since it is more important to have that
908 // animation be smooth.
909 mShownAlpha = mAlpha;
910 if (!mService.mLimitedAlphaCompositing
911 || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format)
912 || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
913 && x == frame.left && y == frame.top))) {
914 //Slog.i(TAG, "Applying alpha transform");
915 if (selfTransformation) {
916 mShownAlpha *= mTransformation.getAlpha();
917 }
918 if (attachedTransformation != null) {
919 mShownAlpha *= attachedTransformation.getAlpha();
920 }
921 if (appTransformation != null) {
922 mShownAlpha *= appTransformation.getAlpha();
923 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700924 if (mAnimator.mUniverseBackground != null) {
925 mShownAlpha *= mAnimator.mUniverseBackground.mUniverseTransform.getAlpha();
926 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700927 if (screenAnimation) {
928 mShownAlpha *=
929 mService.mAnimator.mScreenRotationAnimation.getEnterTransformation().getAlpha();
930 }
931 } else {
932 //Slog.i(TAG, "Not applying alpha transform");
933 }
934
Craig Mautner9e809442012-06-22 17:13:04 -0700935 if ((DEBUG_SURFACE_TRACE || WindowManagerService.localLOGV) && (mShownAlpha == 1.0 || mShownAlpha == 0.0)) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700936 TAG, "computeShownFrameLocked: Animating " + this +
Craig Mautnerf4120952012-06-21 18:25:39 -0700937 " mAlpha=" + mAlpha +
938 " self=" + (selfTransformation ? mTransformation.getAlpha() : "null") +
939 " attached=" + (attachedTransformation == null ? "null" : attachedTransformation.getAlpha()) +
940 " app=" + (appTransformation == null ? "null" : appTransformation.getAlpha()) +
941 " screen=" + (screenAnimation ? mService.mAnimator.mScreenRotationAnimation.getEnterTransformation().getAlpha()
942 : "null"));
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700943 return;
Craig Mautner918b53b2012-07-09 14:15:54 -0700944 } else if (mIsWallpaper &&
Craig Mautner4d7349b2012-04-20 14:52:47 -0700945 (mAnimator.mPendingActions & WindowAnimator.WALLPAPER_ACTION_PENDING) != 0) {
946 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700947 }
948
949 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautner4d7349b2012-04-20 14:52:47 -0700950 TAG, "computeShownFrameLocked: " + this +
951 " not attached, mAlpha=" + mAlpha);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700952 if (mAnimator.mUniverseBackground != null &&
953 mWin.mAttrs.type != WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND
954 && mWin.mBaseLayer < mAnimator.mAboveUniverseLayer) {
955 final Rect frame = mWin.mFrame;
956 final float tmpFloats[] = mService.mTmpFloats;
957 final Matrix tmpMatrix = mWin.mTmpMatrix;
958 tmpMatrix.setScale(mWin.mGlobalScale, mWin.mGlobalScale);
959 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
960 tmpMatrix.postConcat(mAnimator.mUniverseBackground.mUniverseTransform.getMatrix());
961 tmpMatrix.getValues(tmpFloats);
962 mHaveMatrix = true;
963 mDsDx = tmpFloats[Matrix.MSCALE_X];
964 mDtDx = tmpFloats[Matrix.MSKEW_Y];
965 mDsDy = tmpFloats[Matrix.MSKEW_X];
966 mDtDy = tmpFloats[Matrix.MSCALE_Y];
967 float x = tmpFloats[Matrix.MTRANS_X];
968 float y = tmpFloats[Matrix.MTRANS_Y];
969 int w = frame.width();
970 int h = frame.height();
971 mWin.mShownFrame.set(x, y, x+w, y+h);
972 mShownAlpha = mAlpha * mAnimator.mUniverseBackground.mUniverseTransform.getAlpha();
973 } else {
974 mWin.mShownFrame.set(mWin.mFrame);
975 if (mWin.mXOffset != 0 || mWin.mYOffset != 0) {
976 mWin.mShownFrame.offset(mWin.mXOffset, mWin.mYOffset);
977 }
978 mShownAlpha = mAlpha;
979 mHaveMatrix = false;
980 mDsDx = mWin.mGlobalScale;
981 mDtDx = 0;
982 mDsDy = 0;
983 mDtDy = mWin.mGlobalScale;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700984 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700985 }
986
987 void applyDecorRect(final Rect decorRect) {
988 final WindowState w = mWin;
989 // Compute the offset of the window in relation to the decor rect.
990 final int offX = w.mXOffset + w.mFrame.left;
991 final int offY = w.mYOffset + w.mFrame.top;
992 // Initialize the decor rect to the entire frame.
993 w.mSystemDecorRect.set(0, 0, w.mFrame.width(), w.mFrame.height());
994 // Intersect with the decor rect, offsetted by window position.
995 w.mSystemDecorRect.intersect(decorRect.left-offX, decorRect.top-offY,
996 decorRect.right-offX, decorRect.bottom-offY);
997 // If size compatibility is being applied to the window, the
998 // surface is scaled relative to the screen. Also apply this
999 // scaling to the crop rect. We aren't using the standard rect
1000 // scale function because we want to round things to make the crop
1001 // always round to a larger rect to ensure we don't crop too
1002 // much and hide part of the window that should be seen.
1003 if (w.mEnforceSizeCompat && w.mInvGlobalScale != 1.0f) {
1004 final float scale = w.mInvGlobalScale;
1005 w.mSystemDecorRect.left = (int) (w.mSystemDecorRect.left * scale - 0.5f);
1006 w.mSystemDecorRect.top = (int) (w.mSystemDecorRect.top * scale - 0.5f);
1007 w.mSystemDecorRect.right = (int) ((w.mSystemDecorRect.right+1) * scale - 0.5f);
1008 w.mSystemDecorRect.bottom = (int) ((w.mSystemDecorRect.bottom+1) * scale - 0.5f);
1009 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001010 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001011
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001012 void updateSurfaceWindowCrop(final boolean recoveringMemory) {
1013 final WindowState w = mWin;
1014
1015 // Need to recompute a new system decor rect each time.
1016 if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
1017 // Currently can't do this cropping for scaled windows. We'll
1018 // just keep the crop rect the same as the source surface.
1019 w.mSystemDecorRect.set(0, 0, w.mRequestedWidth, w.mRequestedHeight);
1020 } else if (w.mLayer >= mService.mSystemDecorLayer) {
1021 // Above the decor layer is easy, just use the entire window.
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001022 // Unless we have a universe background... in which case all the
1023 // windows need to be cropped by the screen, so they don't cover
1024 // the universe background.
1025 if (mAnimator.mUniverseBackground == null) {
1026 w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(),
1027 w.mCompatFrame.height());
1028 } else {
1029 applyDecorRect(mService.mScreenRect);
1030 }
1031 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND) {
1032 // The universe background isn't cropped.
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001033 w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(),
1034 w.mCompatFrame.height());
1035 } else {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001036 applyDecorRect(mService.mSystemDecorRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001037 }
1038
1039 if (!w.mSystemDecorRect.equals(w.mLastSystemDecorRect)) {
1040 w.mLastSystemDecorRect.set(w.mSystemDecorRect);
1041 try {
1042 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1043 "CROP " + w.mSystemDecorRect.toShortString(), null);
1044 mSurface.setWindowCrop(w.mSystemDecorRect);
1045 } catch (RuntimeException e) {
1046 Slog.w(TAG, "Error setting crop surface of " + w
1047 + " crop=" + w.mSystemDecorRect.toShortString(), e);
1048 if (!recoveringMemory) {
1049 mService.reclaimSomeSurfaceMemoryLocked(this, "crop", true);
1050 }
1051 }
1052 }
1053 }
1054
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001055 void setSurfaceBoundaries(final boolean recoveringMemory) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001056 final WindowState w = mWin;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001057 int width, height;
1058 if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
1059 // for a scaled surface, we just want to use
1060 // the requested size.
1061 width = w.mRequestedWidth;
1062 height = w.mRequestedHeight;
1063 } else {
1064 width = w.mCompatFrame.width();
1065 height = w.mCompatFrame.height();
1066 }
1067
1068 if (width < 1) {
1069 width = 1;
1070 }
1071 if (height < 1) {
1072 height = 1;
1073 }
1074 final boolean surfaceResized = mSurfaceW != width || mSurfaceH != height;
1075 if (surfaceResized) {
1076 mSurfaceW = width;
1077 mSurfaceH = height;
1078 }
1079
Craig Mautner4d7349b2012-04-20 14:52:47 -07001080 final float left = w.mShownFrame.left;
1081 final float top = w.mShownFrame.top;
1082 if (mSurfaceX != left || mSurfaceY != top) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001083 try {
1084 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
Craig Mautner4d7349b2012-04-20 14:52:47 -07001085 "POS " + left + ", " + top, null);
1086 mSurfaceX = left;
1087 mSurfaceY = top;
1088 mSurface.setPosition(left, top);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001089 } catch (RuntimeException e) {
1090 Slog.w(TAG, "Error positioning surface of " + w
Craig Mautner4d7349b2012-04-20 14:52:47 -07001091 + " pos=(" + left
1092 + "," + top + ")", e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001093 if (!recoveringMemory) {
1094 mService.reclaimSomeSurfaceMemoryLocked(this, "position", true);
1095 }
1096 }
1097 }
1098
1099 if (surfaceResized) {
1100 try {
1101 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1102 "SIZE " + width + "x" + height, null);
1103 mSurfaceResized = true;
1104 mSurface.setSize(width, height);
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001105 mAnimator.mPendingLayoutChanges |=
1106 WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Craig Mautner3a67f352012-05-07 11:21:33 -07001107 if ((w.mAttrs.flags & LayoutParams.FLAG_DIM_BEHIND) != 0) {
Craig Mautnera76fdb72012-07-03 19:03:02 -07001108 mService.startDimming(this, w.mExiting ? 0 : w.mAttrs.dimAmount,
Craig Mautner3a67f352012-05-07 11:21:33 -07001109 mService.mAppDisplayWidth, mService.mAppDisplayHeight);
1110 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001111 } catch (RuntimeException e) {
1112 // If something goes wrong with the surface (such
1113 // as running out of memory), don't take down the
1114 // entire system.
1115 Slog.e(TAG, "Error resizing surface of " + w
1116 + " size=(" + width + "x" + height + ")", e);
1117 if (!recoveringMemory) {
1118 mService.reclaimSomeSurfaceMemoryLocked(this, "size", true);
1119 }
1120 }
1121 }
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001122
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001123 updateSurfaceWindowCrop(recoveringMemory);
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001124 }
1125
1126 public void prepareSurfaceLocked(final boolean recoveringMemory) {
1127 final WindowState w = mWin;
1128 if (mSurface == null) {
1129 if (w.mOrientationChanging) {
1130 if (DEBUG_ORIENTATION) {
1131 Slog.v(TAG, "Orientation change skips hidden " + w);
1132 }
1133 w.mOrientationChanging = false;
1134 }
1135 return;
1136 }
1137
1138 boolean displayed = false;
1139
1140 computeShownFrameLocked();
1141
1142 setSurfaceBoundaries(recoveringMemory);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001143
Craig Mautner918b53b2012-07-09 14:15:54 -07001144 if (mIsWallpaper && !mWin.mWallpaperVisible) {
Craig Mautner0fa77c12012-06-11 15:57:19 -07001145 // Wallpaper is no longer visible and there is no wp target => hide it.
1146 hide();
1147 } else if (w.mAttachedHidden || !w.isReadyForDisplay()) {
Craig Mautner0afddcb2012-05-08 15:38:00 -07001148 hide();
Craig Mautnerb9836b92012-06-11 11:40:09 -07001149 mAnimator.hideWallpapersLocked(w);
1150
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001151 // If we are waiting for this window to handle an
1152 // orientation change, well, it is hidden, so
1153 // doesn't really matter. Note that this does
1154 // introduce a potential glitch if the window
1155 // becomes unhidden before it has drawn for the
1156 // new orientation.
1157 if (w.mOrientationChanging) {
1158 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001159 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001160 "Orientation change skips hidden " + w);
1161 }
1162 } else if (mLastLayer != mAnimLayer
1163 || mLastAlpha != mShownAlpha
1164 || mLastDsDx != mDsDx
1165 || mLastDtDx != mDtDx
1166 || mLastDsDy != mDsDy
1167 || mLastDtDy != mDtDy
1168 || w.mLastHScale != w.mHScale
1169 || w.mLastVScale != w.mVScale
Craig Mautner749a7bb2012-04-02 13:49:53 -07001170 || mLastHidden) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001171 displayed = true;
1172 mLastAlpha = mShownAlpha;
1173 mLastLayer = mAnimLayer;
1174 mLastDsDx = mDsDx;
1175 mLastDtDx = mDtDx;
1176 mLastDsDy = mDsDy;
1177 mLastDtDy = mDtDy;
1178 w.mLastHScale = w.mHScale;
1179 w.mLastVScale = w.mVScale;
1180 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1181 "alpha=" + mShownAlpha + " layer=" + mAnimLayer
1182 + " matrix=[" + (mDsDx*w.mHScale)
1183 + "," + (mDtDx*w.mVScale)
1184 + "][" + (mDsDy*w.mHScale)
1185 + "," + (mDtDy*w.mVScale) + "]", null);
1186 if (mSurface != null) {
1187 try {
1188 mSurfaceAlpha = mShownAlpha;
1189 mSurface.setAlpha(mShownAlpha);
Craig Mautnerad5725d2012-06-05 10:20:56 -07001190 mSurfaceLayer = mAnimLayer;
1191 mSurface.setLayer(mAnimLayer);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001192 mSurface.setMatrix(
1193 mDsDx*w.mHScale, mDtDx*w.mVScale,
1194 mDsDy*w.mHScale, mDtDy*w.mVScale);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001195
1196 if (mLastHidden && mDrawState == HAS_DRAWN) {
1197 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1198 "SHOW (performLayout)", null);
1199 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
1200 + " during relayout");
1201 if (showSurfaceRobustlyLocked()) {
1202 mLastHidden = false;
Craig Mautner918b53b2012-07-09 14:15:54 -07001203 if (mIsWallpaper) {
Craig Mautner507a2ee2012-06-13 08:39:38 -07001204 mService.dispatchWallpaperVisibility(w, true);
1205 }
Craig Mautner749a7bb2012-04-02 13:49:53 -07001206 } else {
1207 w.mOrientationChanging = false;
1208 }
1209 }
1210 if (mSurface != null) {
1211 w.mToken.hasVisible = true;
1212 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001213 } catch (RuntimeException e) {
1214 Slog.w(TAG, "Error updating surface in " + w, e);
1215 if (!recoveringMemory) {
1216 mService.reclaimSomeSurfaceMemoryLocked(this, "update", true);
1217 }
1218 }
1219 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001220 } else {
Craig Mautner9e809442012-06-22 17:13:04 -07001221 if (DEBUG_ANIM && isAnimating()) {
1222 Slog.v(TAG, "prepareSurface: No changes in animation for " + this);
Craig Mautner83339b42012-05-01 22:13:23 -07001223 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001224 displayed = true;
1225 }
1226
1227 if (displayed) {
1228 if (w.mOrientationChanging) {
1229 if (!w.isDrawnLw()) {
Craig Mautner2639da52012-07-09 09:39:06 -07001230 mAnimator.mBulkUpdateParams &= ~SET_ORIENTATION_CHANGE_COMPLETE;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001231 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001232 "Orientation continue waiting for draw in " + w);
1233 } else {
1234 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001235 if (DEBUG_ORIENTATION) Slog.v(TAG, "Orientation change complete in " + w);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001236 }
1237 }
1238 w.mToken.hasVisible = true;
1239 }
1240 }
1241
Craig Mautner48ba1e72012-04-02 13:18:16 -07001242 void setTransparentRegionHint(final Region region) {
Craig Mautner1f4e0cc2012-04-10 14:24:38 -07001243 if (mSurface == null) {
1244 Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true");
1245 return;
1246 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001247 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1248 ">>> OPEN TRANSACTION setTransparentRegion");
1249 Surface.openTransaction();
1250 try {
1251 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
1252 "transparentRegionHint=" + region, null);
1253 mSurface.setTransparentRegionHint(region);
1254 } finally {
1255 Surface.closeTransaction();
1256 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1257 "<<< CLOSE TRANSACTION setTransparentRegion");
1258 }
1259 }
1260
1261 void setWallpaperOffset(int left, int top) {
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001262 mSurfaceX = left;
1263 mSurfaceY = top;
1264 if (mAnimating) {
1265 // If this window (or its app token) is animating, then the position
1266 // of the surface will be re-computed on the next animation frame.
1267 // We can't poke it directly here because it depends on whatever
1268 // transformation is being applied by the animation.
1269 return;
1270 }
1271 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1272 ">>> OPEN TRANSACTION setWallpaperOffset");
Craig Mautner48ba1e72012-04-02 13:18:16 -07001273 Surface.openTransaction();
1274 try {
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001275 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
1276 "POS " + left + ", " + top, null);
1277 mSurface.setPosition(mWin.mFrame.left + left, mWin.mFrame.top + top);
1278 updateSurfaceWindowCrop(false);
Craig Mautner48ba1e72012-04-02 13:18:16 -07001279 } catch (RuntimeException e) {
1280 Slog.w(TAG, "Error positioning surface of " + mWin
1281 + " pos=(" + left + "," + top + ")", e);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001282 } finally {
1283 Surface.closeTransaction();
1284 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1285 "<<< CLOSE TRANSACTION setWallpaperOffset");
Craig Mautner48ba1e72012-04-02 13:18:16 -07001286 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001287 }
1288
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001289 // This must be called while inside a transaction.
1290 boolean performShowLocked() {
Craig Mautner6fbda632012-07-03 09:26:39 -07001291 if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
1292 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001293 RuntimeException e = null;
1294 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
1295 e = new RuntimeException();
1296 e.fillInStackTrace();
1297 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001298 Slog.v(TAG, "performShow on " + this
Craig Mautner749a7bb2012-04-02 13:49:53 -07001299 + ": mDrawState=" + mDrawState + " readyForDisplay="
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001300 + mWin.isReadyForDisplayIgnoringKeyguard()
Craig Mautner6fbda632012-07-03 09:26:39 -07001301 + " starting=" + (mWin.mAttrs.type == TYPE_APPLICATION_STARTING)
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001302 + " during animation: policyVis=" + mWin.mPolicyVisibility
1303 + " attHidden=" + mWin.mAttachedHidden
1304 + " tok.hiddenRequested="
1305 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
1306 + " tok.hidden="
1307 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
1308 + " animating=" + mAnimating
1309 + " tok animating="
Craig Mautner322e4032012-07-13 13:35:20 -07001310 + (mAppAnimator != null ? mAppAnimator.animating : false), e);
Craig Mautner6fbda632012-07-03 09:26:39 -07001311 }
1312 if (mDrawState == READY_TO_SHOW && mWin.isReadyForDisplayIgnoringKeyguard()) {
1313 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
1314 WindowManagerService.logSurface(mWin, "SHOW (performShowLocked)", null);
1315 if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
1316 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
1317 Slog.v(TAG, "Showing " + this
1318 + " during animation: policyVis=" + mWin.mPolicyVisibility
1319 + " attHidden=" + mWin.mAttachedHidden
1320 + " tok.hiddenRequested="
1321 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
1322 + " tok.hidden="
1323 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
1324 + " animating=" + mAnimating
1325 + " tok animating="
Craig Mautner322e4032012-07-13 13:35:20 -07001326 + (mAppAnimator != null ? mAppAnimator.animating : false));
Craig Mautner6fbda632012-07-03 09:26:39 -07001327 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001328
1329 mService.enableScreenIfNeededLocked();
1330
1331 applyEnterAnimationLocked();
1332
Craig Mautnerde6198e2012-04-19 09:59:31 -07001333 // Force the show in the next prepareSurfaceLocked() call.
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001334 mLastAlpha = -1;
Craig Mautneref25d7a2012-05-15 23:01:47 -07001335 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM)
1336 Slog.v(TAG, "performShowLocked: mDrawState=HAS_DRAWN in " + this);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001337 mDrawState = HAS_DRAWN;
Craig Mautner711f90a2012-07-03 18:43:52 -07001338 mService.updateLayoutToAnimationLocked();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001339
1340 int i = mWin.mChildWindows.size();
1341 while (i > 0) {
1342 i--;
1343 WindowState c = mWin.mChildWindows.get(i);
1344 if (c.mAttachedHidden) {
1345 c.mAttachedHidden = false;
1346 if (c.mWinAnimator.mSurface != null) {
1347 c.mWinAnimator.performShowLocked();
1348 // It hadn't been shown, which means layout not
1349 // performed on it, so now we want to make sure to
1350 // do a layout. If called from within the transaction
1351 // loop, this will cause it to restart with a new
1352 // layout.
1353 mService.mLayoutNeeded = true;
1354 }
1355 }
1356 }
1357
1358 if (mWin.mAttrs.type != TYPE_APPLICATION_STARTING
1359 && mWin.mAppToken != null) {
1360 mWin.mAppToken.firstWindowDrawn = true;
1361
1362 if (mWin.mAppToken.startingData != null) {
1363 if (WindowManagerService.DEBUG_STARTING_WINDOW ||
Craig Mautnerd87946b2012-03-29 18:00:19 -07001364 WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001365 "Finish starting " + mWin.mToken
1366 + ": first real window is shown, no animation");
1367 // If this initial window is animating, stop it -- we
1368 // will do an animation to reveal it from behind the
1369 // starting window, so there is no need for it to also
1370 // be doing its own stuff.
Craig Mautner4d7349b2012-04-20 14:52:47 -07001371 clearAnimation();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001372 mService.mFinishedStarting.add(mWin.mAppToken);
1373 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
1374 }
1375 mWin.mAppToken.updateReportedVisibilityLocked();
1376 }
1377
1378 return true;
1379 }
1380
1381 return false;
1382 }
1383
1384 /**
1385 * Have the surface flinger show a surface, robustly dealing with
1386 * error conditions. In particular, if there is not enough memory
1387 * to show the surface, then we will try to get rid of other surfaces
1388 * in order to succeed.
1389 *
1390 * @return Returns true if the surface was successfully shown.
1391 */
1392 boolean showSurfaceRobustlyLocked() {
1393 try {
1394 if (mSurface != null) {
1395 mSurfaceShown = true;
1396 mSurface.show();
1397 if (mWin.mTurnOnScreen) {
1398 if (DEBUG_VISIBILITY) Slog.v(TAG,
1399 "Show surface turning screen on: " + mWin);
1400 mWin.mTurnOnScreen = false;
Craig Mautner7d8df392012-04-06 15:26:23 -07001401 mAnimator.mBulkUpdateParams |= SET_TURN_ON_SCREEN;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001402 }
1403 }
1404 return true;
1405 } catch (RuntimeException e) {
1406 Slog.w(TAG, "Failure showing surface " + mSurface + " in " + mWin, e);
1407 }
1408
1409 mService.reclaimSomeSurfaceMemoryLocked(this, "show", true);
1410
1411 return false;
1412 }
1413
1414 void applyEnterAnimationLocked() {
1415 final int transit;
1416 if (mEnterAnimationPending) {
1417 mEnterAnimationPending = false;
1418 transit = WindowManagerPolicy.TRANSIT_ENTER;
1419 } else {
1420 transit = WindowManagerPolicy.TRANSIT_SHOW;
1421 }
1422
1423 applyAnimationLocked(transit, true);
1424 }
1425
Craig Mautner48ba1e72012-04-02 13:18:16 -07001426 // TODO(cmautner): Move back to WindowState?
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001427 /**
1428 * Choose the correct animation and set it to the passed WindowState.
1429 * @param transit If WindowManagerPolicy.TRANSIT_PREVIEW_DONE and the app window has been drawn
1430 * then the animation will be app_starting_exit. Any other value loads the animation from
1431 * the switch statement below.
1432 * @param isEntrance The animation type the last time this was called. Used to keep from
1433 * loading the same animation twice.
1434 * @return true if an animation has been loaded.
1435 */
1436 boolean applyAnimationLocked(int transit, boolean isEntrance) {
1437 if (mLocalAnimating && mAnimationIsEntrance == isEntrance) {
1438 // If we are trying to apply an animation, but already running
1439 // an animation of the same type, then just leave that one alone.
1440 return true;
1441 }
1442
1443 // Only apply an animation if the display isn't frozen. If it is
1444 // frozen, there is no reason to animate and it can cause strange
1445 // artifacts when we unfreeze the display if some different animation
1446 // is running.
1447 if (mService.okToDisplay()) {
1448 int anim = mPolicy.selectAnimationLw(mWin, transit);
1449 int attr = -1;
1450 Animation a = null;
1451 if (anim != 0) {
1452 a = AnimationUtils.loadAnimation(mContext, anim);
1453 } else {
1454 switch (transit) {
1455 case WindowManagerPolicy.TRANSIT_ENTER:
1456 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
1457 break;
1458 case WindowManagerPolicy.TRANSIT_EXIT:
1459 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
1460 break;
1461 case WindowManagerPolicy.TRANSIT_SHOW:
1462 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
1463 break;
1464 case WindowManagerPolicy.TRANSIT_HIDE:
1465 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
1466 break;
1467 }
1468 if (attr >= 0) {
1469 a = mService.loadAnimation(mWin.mAttrs, attr);
1470 }
1471 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001472 if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001473 "applyAnimation: win=" + this
1474 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
Craig Mautner4d7349b2012-04-20 14:52:47 -07001475 + " a=" + a
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001476 + " mAnimation=" + mAnimation
Craig Mautner83339b42012-05-01 22:13:23 -07001477 + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001478 if (a != null) {
1479 if (WindowManagerService.DEBUG_ANIM) {
1480 RuntimeException e = null;
1481 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
1482 e = new RuntimeException();
1483 e.fillInStackTrace();
1484 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001485 Slog.v(TAG, "Loaded animation " + a + " for " + this, e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001486 }
1487 setAnimation(a);
1488 mAnimationIsEntrance = isEntrance;
1489 }
1490 } else {
1491 clearAnimation();
1492 }
1493
1494 return mAnimation != null;
1495 }
1496
Craig Mautnera2c77052012-03-26 12:14:43 -07001497 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1498 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
1499 || mAnimation != null) {
1500 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
1501 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
1502 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
1503 pw.print(" mAnimation="); pw.println(mAnimation);
1504 }
1505 if (mHasTransformation || mHasLocalTransformation) {
1506 pw.print(prefix); pw.print("XForm: has=");
1507 pw.print(mHasTransformation);
1508 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
1509 pw.print(" "); mTransformation.printShortString(pw);
1510 pw.println();
1511 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001512 if (mSurface != null) {
1513 if (dumpAll) {
1514 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Craig Mautner6fbda632012-07-03 09:26:39 -07001515 pw.print(prefix); pw.print("mDrawState=");
1516 pw.print(drawStateToString(mDrawState));
Craig Mautner749a7bb2012-04-02 13:49:53 -07001517 pw.print(" mLastHidden="); pw.println(mLastHidden);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001518 }
1519 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
1520 pw.print(" layer="); pw.print(mSurfaceLayer);
1521 pw.print(" alpha="); pw.print(mSurfaceAlpha);
1522 pw.print(" rect=("); pw.print(mSurfaceX);
1523 pw.print(","); pw.print(mSurfaceY);
1524 pw.print(") "); pw.print(mSurfaceW);
1525 pw.print(" x "); pw.println(mSurfaceH);
1526 }
1527 if (mPendingDestroySurface != null) {
1528 pw.print(prefix); pw.print("mPendingDestroySurface=");
1529 pw.println(mPendingDestroySurface);
1530 }
1531 if (mSurfaceResized || mSurfaceDestroyDeferred) {
1532 pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized);
1533 pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred);
1534 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001535 if (mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND) {
1536 pw.print(prefix); pw.print("mUniverseTransform=");
1537 mUniverseTransform.printShortString(pw);
1538 pw.println();
1539 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001540 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
1541 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
1542 pw.print(" mAlpha="); pw.print(mAlpha);
1543 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
1544 }
1545 if (mHaveMatrix || mWin.mGlobalScale != 1) {
1546 pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale);
1547 pw.print(" mDsDx="); pw.print(mDsDx);
1548 pw.print(" mDtDx="); pw.print(mDtDx);
1549 pw.print(" mDsDy="); pw.print(mDsDy);
1550 pw.print(" mDtDy="); pw.println(mDtDy);
1551 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001552 }
1553
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001554 @Override
1555 public String toString() {
1556 StringBuffer sb = new StringBuffer("WindowStateAnimator (");
1557 sb.append(mWin.mLastTitle + "): ");
1558 sb.append("mSurface " + mSurface);
1559 sb.append(", mAnimation " + mAnimation);
1560 return sb.toString();
1561 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001562}