blob: 87d420f0d9195840874fa2bd046539f90c314178 [file] [log] [blame]
Craig Mautnerc2c0a612014-02-20 20:25:41 -08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Craig Mautnera2c77052012-03-26 12:14:43 -070016
17package com.android.server.wm;
18
Adrian Roosce4a0cf2014-09-15 16:54:24 +020019import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070020import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Craig Mautnerb3b36ba2013-05-20 13:21:10 -070021import static com.android.server.wm.WindowManagerService.DEBUG_ANIM;
22import static com.android.server.wm.WindowManagerService.DEBUG_LAYERS;
23import static com.android.server.wm.WindowManagerService.DEBUG_ORIENTATION;
24import static com.android.server.wm.WindowManagerService.DEBUG_STARTING_WINDOW;
25import static com.android.server.wm.WindowManagerService.DEBUG_SURFACE_TRACE;
26import static com.android.server.wm.WindowManagerService.SHOW_TRANSACTIONS;
27import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
28import static com.android.server.wm.WindowManagerService.SHOW_LIGHT_TRANSACTIONS;
29import static com.android.server.wm.WindowManagerService.SHOW_SURFACE_ALLOC;
30import static com.android.server.wm.WindowManagerService.localLOGV;
Craig Mautner2639da52012-07-09 09:39:06 -070031import static com.android.server.wm.WindowManagerService.LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE;
Craig Mautner7d8df392012-04-06 15:26:23 -070032import static com.android.server.wm.WindowManagerService.LayoutFields.SET_TURN_ON_SCREEN;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070033
Craig Mautnerc2f9be02012-03-27 17:32:29 -070034import android.content.Context;
35import android.graphics.Matrix;
36import android.graphics.PixelFormat;
Craig Mautner7358fbf2012-04-12 21:06:33 -070037import android.graphics.Point;
38import android.graphics.PointF;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070039import android.graphics.Rect;
Craig Mautner58106812012-12-28 12:27:40 -080040import android.graphics.RectF;
Craig Mautner48ba1e72012-04-02 13:18:16 -070041import android.graphics.Region;
Craig Mautnera51a9562012-04-17 17:05:26 -070042import android.os.Debug;
Craig Mautner9c795042014-10-28 19:59:59 -070043import android.os.RemoteException;
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +010044import android.os.UserHandle;
Craig Mautnera2c77052012-03-26 12:14:43 -070045import android.util.Slog;
Svetoslav Ganov545252f2012-12-10 18:29:24 -080046import android.view.Display;
Craig Mautner59c00972012-07-30 12:10:24 -070047import android.view.DisplayInfo;
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -070048import android.view.MagnificationSpec;
Igor Murashkina86ab6402013-08-30 12:58:36 -070049import android.view.Surface.OutOfResourcesException;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080050import android.view.SurfaceControl;
Craig Mautner7358fbf2012-04-12 21:06:33 -070051import android.view.SurfaceSession;
Adrian Roos3eeb4e62014-05-19 12:43:26 +020052import android.view.View;
Craig Mautnera2c77052012-03-26 12:14:43 -070053import android.view.WindowManager;
54import android.view.WindowManagerPolicy;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070055import android.view.WindowManager.LayoutParams;
Jorim Jaggif8d77da2014-11-11 16:59:12 +010056import android.view.animation.AlphaAnimation;
Craig Mautnera2c77052012-03-26 12:14:43 -070057import android.view.animation.Animation;
Jorim Jaggif8d77da2014-11-11 16:59:12 +010058import android.view.animation.AnimationSet;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070059import android.view.animation.AnimationUtils;
Craig Mautnera2c77052012-03-26 12:14:43 -070060import android.view.animation.Transformation;
61
Jorim Jaggif8d77da2014-11-11 16:59:12 +010062import com.android.internal.R;
Craig Mautnera2c77052012-03-26 12:14:43 -070063import com.android.server.wm.WindowManagerService.H;
64
65import java.io.PrintWriter;
Craig Mautner7358fbf2012-04-12 21:06:33 -070066import java.util.ArrayList;
Craig Mautnera2c77052012-03-26 12:14:43 -070067
Craig Mautner59c00972012-07-30 12:10:24 -070068class WinAnimatorList extends ArrayList<WindowStateAnimator> {
69}
70
Craig Mautnera2c77052012-03-26 12:14:43 -070071/**
Craig Mautnerc2f9be02012-03-27 17:32:29 -070072 * Keep track of animations and surface operations for a single WindowState.
73 **/
Craig Mautnera2c77052012-03-26 12:14:43 -070074class WindowStateAnimator {
Craig Mautnerc2f9be02012-03-27 17:32:29 -070075 static final String TAG = "WindowStateAnimator";
Craig Mautnera2c77052012-03-26 12:14:43 -070076
Craig Mautner918b53b2012-07-09 14:15:54 -070077 // Unchanging local convenience fields.
Craig Mautnera2c77052012-03-26 12:14:43 -070078 final WindowManagerService mService;
79 final WindowState mWin;
Craig Mautner322e4032012-07-13 13:35:20 -070080 final WindowStateAnimator mAttachedWinAnimator;
Craig Mautnere7ae2502012-03-26 17:11:19 -070081 final WindowAnimator mAnimator;
Craig Mautner8863cca2012-09-18 15:04:34 -070082 AppWindowAnimator mAppAnimator;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070083 final Session mSession;
84 final WindowManagerPolicy mPolicy;
85 final Context mContext;
Craig Mautner918b53b2012-07-09 14:15:54 -070086 final boolean mIsWallpaper;
Craig Mautnera2c77052012-03-26 12:14:43 -070087
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -070088 // If this is a universe background window, this is the transformation
89 // it is applying to the rest of the universe.
90 final Transformation mUniverseTransform = new Transformation();
91
Craig Mautnera2c77052012-03-26 12:14:43 -070092 // Currently running animation.
93 boolean mAnimating;
94 boolean mLocalAnimating;
95 Animation mAnimation;
96 boolean mAnimationIsEntrance;
97 boolean mHasTransformation;
98 boolean mHasLocalTransformation;
99 final Transformation mTransformation = new Transformation();
100 boolean mWasAnimating; // Were we animating going into the most recent animation step?
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700101 int mAnimLayer;
102 int mLastLayer;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100103 long mAnimationStartTime;
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100104 long mLastAnimationTime;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700105
Mathias Agopian29479eb2013-02-14 14:36:04 -0800106 SurfaceControl mSurfaceControl;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800107 SurfaceControl mPendingDestroySurface;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700108
109 /**
110 * Set when we have changed the size of the surface, to know that
111 * we must tell them application to resize (and thus redraw itself).
112 */
113 boolean mSurfaceResized;
114
115 /**
116 * Set if the client has asked that the destroy of its surface be delayed
117 * until it explicitly says it is okay.
118 */
119 boolean mSurfaceDestroyDeferred;
120
Craig Mautner7d8df392012-04-06 15:26:23 -0700121 float mShownAlpha = 0;
122 float mAlpha = 0;
123 float mLastAlpha = 0;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700124
Winson Chung399f6202014-03-19 10:47:20 -0700125 boolean mHasClipRect;
126 Rect mClipRect = new Rect();
127 Rect mTmpClipRect = new Rect();
128 Rect mLastClipRect = new Rect();
129
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700130 // Used to save animation distances between the time they are calculated and when they are
131 // used.
132 int mAnimDw;
133 int mAnimDh;
134 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
135 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
136
137 boolean mHaveMatrix;
138
139 // For debugging, this is the last information given to the surface flinger.
140 boolean mSurfaceShown;
Alan Viveretteccb11e12014-07-08 16:04:02 -0700141 float mSurfaceX, mSurfaceY;
142 float mSurfaceW, mSurfaceH;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700143 int mSurfaceLayer;
144 float mSurfaceAlpha;
145
146 // Set to true if, when the window gets displayed, it should perform
147 // an enter animation.
148 boolean mEnterAnimationPending;
Craig Mautnera2c77052012-03-26 12:14:43 -0700149
Craig Mautner9c795042014-10-28 19:59:59 -0700150 /** Used to indicate that this window is undergoing an enter animation. Used for system
151 * windows to make the callback to View.dispatchOnWindowShownCallback(). Set when the
152 * window is first added or shown, cleared when the callback has been made. */
153 boolean mEnteringAnimation;
154
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100155 boolean mKeyguardGoingAwayAnimation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200156
Craig Mautner749a7bb2012-04-02 13:49:53 -0700157 /** This is set when there is no Surface */
158 static final int NO_SURFACE = 0;
159 /** This is set after the Surface has been created but before the window has been drawn. During
160 * this time the surface is hidden. */
161 static final int DRAW_PENDING = 1;
162 /** This is set after the window has finished drawing for the first time but before its surface
163 * is shown. The surface will be displayed when the next layout is run. */
164 static final int COMMIT_DRAW_PENDING = 2;
165 /** This is set during the time after the window's drawing has been committed, and before its
166 * surface is actually shown. It is used to delay showing the surface until all windows in a
167 * token are ready to be shown. */
168 static final int READY_TO_SHOW = 3;
169 /** Set when the window has been shown in the screen the first time. */
170 static final int HAS_DRAWN = 4;
Adrian Roos3eeb4e62014-05-19 12:43:26 +0200171
172 private static final int SYSTEM_UI_FLAGS_LAYOUT_STABLE_FULLSCREEN =
173 View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
174
Craig Mautner276a6eb2014-11-04 15:32:57 -0800175 String drawStateToString() {
176 switch (mDrawState) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700177 case NO_SURFACE: return "NO_SURFACE";
178 case DRAW_PENDING: return "DRAW_PENDING";
179 case COMMIT_DRAW_PENDING: return "COMMIT_DRAW_PENDING";
180 case READY_TO_SHOW: return "READY_TO_SHOW";
181 case HAS_DRAWN: return "HAS_DRAWN";
Craig Mautner276a6eb2014-11-04 15:32:57 -0800182 default: return Integer.toString(mDrawState);
Craig Mautner6fbda632012-07-03 09:26:39 -0700183 }
184 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700185 int mDrawState;
Craig Mautnera608b882012-03-30 13:03:49 -0700186
Craig Mautner749a7bb2012-04-02 13:49:53 -0700187 /** Was this window last hidden? */
188 boolean mLastHidden;
Craig Mautnera608b882012-03-30 13:03:49 -0700189
Craig Mautnerbec53f72012-04-05 11:49:05 -0700190 int mAttrType;
191
Craig Mautner918b53b2012-07-09 14:15:54 -0700192 public WindowStateAnimator(final WindowState win) {
193 final WindowManagerService service = win.mService;
194
Craig Mautnera2c77052012-03-26 12:14:43 -0700195 mService = service;
Craig Mautner918b53b2012-07-09 14:15:54 -0700196 mAnimator = service.mAnimator;
197 mPolicy = service.mPolicy;
198 mContext = service.mContext;
Craig Mautnerd3849f52014-03-27 13:19:29 -0700199 final DisplayContent displayContent = win.getDisplayContent();
200 if (displayContent != null) {
201 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
202 mAnimDw = displayInfo.appWidth;
203 mAnimDh = displayInfo.appHeight;
204 } else {
205 Slog.w(TAG, "WindowStateAnimator ctor: Display has been removed");
206 // This is checked on return and dealt with.
207 }
Craig Mautner918b53b2012-07-09 14:15:54 -0700208
209 mWin = win;
Craig Mautner322e4032012-07-13 13:35:20 -0700210 mAttachedWinAnimator = win.mAttachedWindow == null
211 ? null : win.mAttachedWindow.mWinAnimator;
212 mAppAnimator = win.mAppToken == null ? null : win.mAppToken.mAppAnimator;
Craig Mautner918b53b2012-07-09 14:15:54 -0700213 mSession = win.mSession;
Craig Mautner918b53b2012-07-09 14:15:54 -0700214 mAttrType = win.mAttrs.type;
215 mIsWallpaper = win.mIsWallpaper;
Craig Mautnera2c77052012-03-26 12:14:43 -0700216 }
217
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100218 public void setAnimation(Animation anim, long startTime) {
Craig Mautnerbec53f72012-04-05 11:49:05 -0700219 if (localLOGV) Slog.v(TAG, "Setting animation in " + this + ": " + anim);
Craig Mautnera2c77052012-03-26 12:14:43 -0700220 mAnimating = false;
221 mLocalAnimating = false;
222 mAnimation = anim;
223 mAnimation.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION);
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700224 mAnimation.scaleCurrentDuration(mService.getWindowAnimationScaleLocked());
Craig Mautnera2c77052012-03-26 12:14:43 -0700225 // Start out animation gone if window is gone, or visible if window is visible.
226 mTransformation.clear();
Craig Mautner749a7bb2012-04-02 13:49:53 -0700227 mTransformation.setAlpha(mLastHidden ? 0 : 1);
Craig Mautnera2c77052012-03-26 12:14:43 -0700228 mHasLocalTransformation = true;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100229 mAnimationStartTime = startTime;
230 }
231
232 public void setAnimation(Animation anim) {
233 setAnimation(anim, -1);
Craig Mautnera2c77052012-03-26 12:14:43 -0700234 }
235
236 public void clearAnimation() {
237 if (mAnimation != null) {
238 mAnimating = true;
239 mLocalAnimating = false;
240 mAnimation.cancel();
241 mAnimation = null;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100242 mKeyguardGoingAwayAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -0700243 }
244 }
245
246 /** Is the window or its container currently animating? */
247 boolean isAnimating() {
Craig Mautnera2c77052012-03-26 12:14:43 -0700248 return mAnimation != null
Craig Mautner322e4032012-07-13 13:35:20 -0700249 || (mAttachedWinAnimator != null && mAttachedWinAnimator.mAnimation != null)
250 || (mAppAnimator != null &&
251 (mAppAnimator.animation != null
252 || mAppAnimator.mAppToken.inPendingTransaction));
Craig Mautnera2c77052012-03-26 12:14:43 -0700253 }
254
Craig Mautner0afddcb2012-05-08 15:38:00 -0700255 /** Is the window animating the DummyAnimation? */
256 boolean isDummyAnimation() {
Craig Mautner322e4032012-07-13 13:35:20 -0700257 return mAppAnimator != null
258 && mAppAnimator.animation == AppWindowAnimator.sDummyAnimation;
Craig Mautner0afddcb2012-05-08 15:38:00 -0700259 }
260
Craig Mautnera2c77052012-03-26 12:14:43 -0700261 /** Is this window currently animating? */
262 boolean isWindowAnimating() {
263 return mAnimation != null;
264 }
265
Craig Mautnera2c77052012-03-26 12:14:43 -0700266 void cancelExitAnimationForNextAnimationLocked() {
Craig Mautnera2c77052012-03-26 12:14:43 -0700267 if (mAnimation != null) {
268 mAnimation.cancel();
269 mAnimation = null;
Craig Mautner4d7349b2012-04-20 14:52:47 -0700270 mLocalAnimating = false;
Craig Mautner96868332012-12-04 14:29:11 -0800271 destroySurfaceLocked();
Craig Mautnera2c77052012-03-26 12:14:43 -0700272 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700273 }
274
275 private boolean stepAnimation(long currentTime) {
276 if ((mAnimation == null) || !mLocalAnimating) {
277 return false;
278 }
279 mTransformation.clear();
280 final boolean more = mAnimation.getTransformation(currentTime, mTransformation);
Craig Mautner9e809442012-06-22 17:13:04 -0700281 if (false && DEBUG_ANIM) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700282 TAG, "Stepped animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700283 ": more=" + more + ", xform=" + mTransformation);
284 return more;
285 }
286
287 // This must be called while inside a transaction. Returns true if
288 // there is more animation to run.
289 boolean stepAnimationLocked(long currentTime) {
290 // Save the animation state as it was before this step so WindowManagerService can tell if
291 // we just started or just stopped animating by comparing mWasAnimating with isAnimating().
292 mWasAnimating = mAnimating;
Craig Mautnerdf88d732014-01-27 09:21:32 -0800293 final DisplayContent displayContent = mWin.getDisplayContent();
294 if (displayContent != null && mService.okToDisplay()) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700295 // We will run animations as long as the display isn't frozen.
296
297 if (mWin.isDrawnLw() && mAnimation != null) {
298 mHasTransformation = true;
299 mHasLocalTransformation = true;
300 if (!mLocalAnimating) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700301 if (DEBUG_ANIM) Slog.v(
302 TAG, "Starting animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700303 " @ " + currentTime + ": ww=" + mWin.mFrame.width() +
304 " wh=" + mWin.mFrame.height() +
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700305 " dw=" + mAnimDw + " dh=" + mAnimDh +
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700306 " scale=" + mService.getWindowAnimationScaleLocked());
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700307 mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(),
308 mAnimDw, mAnimDh);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800309 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Craig Mautner59c00972012-07-30 12:10:24 -0700310 mAnimDw = displayInfo.appWidth;
311 mAnimDh = displayInfo.appHeight;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100312 mAnimation.setStartTime(mAnimationStartTime != -1
313 ? mAnimationStartTime
314 : currentTime);
Craig Mautnera2c77052012-03-26 12:14:43 -0700315 mLocalAnimating = true;
316 mAnimating = true;
317 }
318 if ((mAnimation != null) && mLocalAnimating) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100319 mLastAnimationTime = currentTime;
Craig Mautnera2c77052012-03-26 12:14:43 -0700320 if (stepAnimation(currentTime)) {
321 return true;
322 }
323 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700324 if (DEBUG_ANIM) Slog.v(
325 TAG, "Finished animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700326 " @ " + currentTime);
327 //WindowManagerService.this.dump();
328 }
329 mHasLocalTransformation = false;
Craig Mautner322e4032012-07-13 13:35:20 -0700330 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppAnimator != null
331 && mAppAnimator.animation != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700332 // When our app token is animating, we kind-of pretend like
333 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
334 // part of this check means that we will only do this if
335 // our window is not currently exiting, or it is not
336 // locally animating itself. The idea being that one that
337 // is exiting and doing a local animation should be removed
338 // once that animation is done.
339 mAnimating = true;
340 mHasTransformation = true;
341 mTransformation.clear();
342 return false;
343 } else if (mHasTransformation) {
344 // Little trick to get through the path below to act like
345 // we have finished an animation.
346 mAnimating = true;
347 } else if (isAnimating()) {
348 mAnimating = true;
349 }
350 } else if (mAnimation != null) {
351 // If the display is frozen, and there is a pending animation,
352 // clear it and make sure we run the cleanup code.
353 mAnimating = true;
Craig Mautnera2c77052012-03-26 12:14:43 -0700354 }
355
356 if (!mAnimating && !mLocalAnimating) {
357 return false;
358 }
359
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700360 // Done animating, clean up.
361 if (DEBUG_ANIM) Slog.v(
362 TAG, "Animation done in " + this + ": exiting=" + mWin.mExiting
Craig Mautnera2c77052012-03-26 12:14:43 -0700363 + ", reportedVisible="
364 + (mWin.mAppToken != null ? mWin.mAppToken.reportedVisible : false));
365
366 mAnimating = false;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100367 mKeyguardGoingAwayAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -0700368 mLocalAnimating = false;
369 if (mAnimation != null) {
370 mAnimation.cancel();
371 mAnimation = null;
372 }
Craig Mautnere7ae2502012-03-26 17:11:19 -0700373 if (mAnimator.mWindowDetachedWallpaper == mWin) {
374 mAnimator.mWindowDetachedWallpaper = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700375 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700376 mAnimLayer = mWin.mLayer;
Craig Mautnera2c77052012-03-26 12:14:43 -0700377 if (mWin.mIsImWindow) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700378 mAnimLayer += mService.mInputMethodAnimLayerAdjustment;
Craig Mautner918b53b2012-07-09 14:15:54 -0700379 } else if (mIsWallpaper) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700380 mAnimLayer += mService.mWallpaperAnimLayerAdjustment;
Craig Mautnera2c77052012-03-26 12:14:43 -0700381 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700382 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
383 + " anim layer: " + mAnimLayer);
Craig Mautnera2c77052012-03-26 12:14:43 -0700384 mHasTransformation = false;
385 mHasLocalTransformation = false;
386 if (mWin.mPolicyVisibility != mWin.mPolicyVisibilityAfterAnim) {
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700387 if (DEBUG_VISIBILITY) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700388 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
Craig Mautnera2c77052012-03-26 12:14:43 -0700389 + mWin.mPolicyVisibilityAfterAnim);
390 }
391 mWin.mPolicyVisibility = mWin.mPolicyVisibilityAfterAnim;
Craig Mautnerdf88d732014-01-27 09:21:32 -0800392 if (displayContent != null) {
393 displayContent.layoutNeeded = true;
394 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700395 if (!mWin.mPolicyVisibility) {
396 if (mService.mCurrentFocus == mWin) {
Craig Mautner58458122013-09-14 14:59:50 -0700397 if (WindowManagerService.DEBUG_FOCUS_LIGHT) Slog.i(TAG,
398 "setAnimationLocked: setting mFocusMayChange true");
Craig Mautnera2c77052012-03-26 12:14:43 -0700399 mService.mFocusMayChange = true;
400 }
401 // Window is no longer visible -- make sure if we were waiting
402 // for it to be displayed before enabling the display, that
403 // we allow the display to be enabled now.
404 mService.enableScreenIfNeededLocked();
405 }
406 }
407 mTransformation.clear();
Craig Mautner749a7bb2012-04-02 13:49:53 -0700408 if (mDrawState == HAS_DRAWN
Craig Mautnera2c77052012-03-26 12:14:43 -0700409 && mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
410 && mWin.mAppToken != null
411 && mWin.mAppToken.firstWindowDrawn
412 && mWin.mAppToken.startingData != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700413 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
Craig Mautnera2c77052012-03-26 12:14:43 -0700414 + mWin.mToken + ": first real window done animating");
415 mService.mFinishedStarting.add(mWin.mAppToken);
416 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
Craig Mautner81defc72013-10-29 11:10:42 -0700417 } else if (mAttrType == LayoutParams.TYPE_STATUS_BAR && mWin.mPolicyVisibility) {
418 // Upon completion of a not-visible to visible status bar animation a relayout is
419 // required.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800420 if (displayContent != null) {
421 displayContent.layoutNeeded = true;
422 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700423 }
424
425 finishExit();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800426 final int displayId = mWin.getDisplayId();
Craig Mautner76a71652012-09-03 23:23:58 -0700427 mAnimator.setPendingLayoutChanges(displayId, WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700428 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) mService.debugLayoutRepeats(
Craig Mautner66f78d72012-12-04 16:46:50 -0800429 "WindowStateAnimator", mAnimator.getPendingLayoutChanges(displayId));
Craig Mautnera2c77052012-03-26 12:14:43 -0700430
431 if (mWin.mAppToken != null) {
432 mWin.mAppToken.updateReportedVisibilityLocked();
433 }
434
435 return false;
436 }
437
438 void finishExit() {
439 if (WindowManagerService.DEBUG_ANIM) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700440 TAG, "finishExit in " + this
Craig Mautnera2c77052012-03-26 12:14:43 -0700441 + ": exiting=" + mWin.mExiting
442 + " remove=" + mWin.mRemoveOnExit
443 + " windowAnimating=" + isWindowAnimating());
444
445 final int N = mWin.mChildWindows.size();
446 for (int i=0; i<N; i++) {
447 mWin.mChildWindows.get(i).mWinAnimator.finishExit();
448 }
449
Craig Mautner9c795042014-10-28 19:59:59 -0700450 if (mEnteringAnimation && mWin.mAppToken == null) {
451 try {
452 mEnteringAnimation = false;
453 mWin.mClient.dispatchWindowShown();
454 } catch (RemoteException e) {
455 }
456 }
457
Craig Mautnera2c77052012-03-26 12:14:43 -0700458 if (!mWin.mExiting) {
459 return;
460 }
461
462 if (isWindowAnimating()) {
463 return;
464 }
465
466 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700467 TAG, "Exit animation finished in " + this
Craig Mautnera2c77052012-03-26 12:14:43 -0700468 + ": remove=" + mWin.mRemoveOnExit);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800469 if (mSurfaceControl != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700470 mService.mDestroySurface.add(mWin);
471 mWin.mDestroying = true;
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700472 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(
Craig Mautnera2c77052012-03-26 12:14:43 -0700473 mWin, "HIDE (finishExit)", null);
Craig Mautner0afddcb2012-05-08 15:38:00 -0700474 hide();
Craig Mautnera2c77052012-03-26 12:14:43 -0700475 }
476 mWin.mExiting = false;
477 if (mWin.mRemoveOnExit) {
478 mService.mPendingRemove.add(mWin);
479 mWin.mRemoveOnExit = false;
480 }
Craig Mautner96868332012-12-04 14:29:11 -0800481 mAnimator.hideWallpapersLocked(mWin);
Craig Mautner0afddcb2012-05-08 15:38:00 -0700482 }
483
484 void hide() {
485 if (!mLastHidden) {
486 //dump();
487 mLastHidden = true;
488 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
489 "HIDE (performLayout)", null);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800490 if (mSurfaceControl != null) {
Craig Mautner0afddcb2012-05-08 15:38:00 -0700491 mSurfaceShown = false;
492 try {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800493 mSurfaceControl.hide();
Craig Mautner0afddcb2012-05-08 15:38:00 -0700494 } catch (RuntimeException e) {
495 Slog.w(TAG, "Exception hiding surface in " + mWin);
496 }
497 }
498 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700499 }
500
Craig Mautnera608b882012-03-30 13:03:49 -0700501 boolean finishDrawingLocked() {
Craig Mautner42d04db2014-11-06 12:13:23 -0800502 final boolean startingWindow =
503 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
504 if (DEBUG_STARTING_WINDOW && startingWindow) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700505 Slog.v(TAG, "Finishing drawing window " + mWin + ": mDrawState="
Craig Mautner276a6eb2014-11-04 15:32:57 -0800506 + drawStateToString());
Craig Mautner6fbda632012-07-03 09:26:39 -0700507 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700508 if (mDrawState == DRAW_PENDING) {
Craig Mautneref25d7a2012-05-15 23:01:47 -0700509 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
510 Slog.v(TAG, "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING " + this + " in "
Mathias Agopian29479eb2013-02-14 14:36:04 -0800511 + mSurfaceControl);
Craig Mautner42d04db2014-11-06 12:13:23 -0800512 if (DEBUG_STARTING_WINDOW && startingWindow) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700513 Slog.v(TAG, "Draw state now committed in " + mWin);
514 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700515 mDrawState = COMMIT_DRAW_PENDING;
Craig Mautnera608b882012-03-30 13:03:49 -0700516 return true;
517 }
518 return false;
519 }
520
521 // This must be called while inside a transaction.
522 boolean commitFinishDrawingLocked(long currentTime) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700523 if (DEBUG_STARTING_WINDOW &&
524 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
525 Slog.i(TAG, "commitFinishDrawingLocked: " + mWin + " cur mDrawState="
Craig Mautner276a6eb2014-11-04 15:32:57 -0800526 + drawStateToString());
Craig Mautner6fbda632012-07-03 09:26:39 -0700527 }
Craig Mautner276a6eb2014-11-04 15:32:57 -0800528 if (mDrawState != COMMIT_DRAW_PENDING && mDrawState != READY_TO_SHOW) {
Craig Mautnera608b882012-03-30 13:03:49 -0700529 return false;
530 }
Craig Mautner6fbda632012-07-03 09:26:39 -0700531 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800532 Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurfaceControl);
Craig Mautner6fbda632012-07-03 09:26:39 -0700533 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700534 mDrawState = READY_TO_SHOW;
Craig Mautnera608b882012-03-30 13:03:49 -0700535 final AppWindowToken atoken = mWin.mAppToken;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800536 if (atoken == null || atoken.allDrawn || mWin.mAttrs.type == TYPE_APPLICATION_STARTING) {
Craig Mautnera608b882012-03-30 13:03:49 -0700537 performShowLocked();
538 }
539 return true;
540 }
541
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800542 static class SurfaceTrace extends SurfaceControl {
Craig Mautner7d8df392012-04-06 15:26:23 -0700543 private final static String SURFACE_TAG = "SurfaceTrace";
Craig Mautner49a2edf2014-09-25 14:49:26 -0700544 private final static boolean logSurfaceTrace = DEBUG_SURFACE_TRACE;
Craig Mautner7d8df392012-04-06 15:26:23 -0700545 final static ArrayList<SurfaceTrace> sSurfaces = new ArrayList<SurfaceTrace>();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700546
Craig Mautner7d8df392012-04-06 15:26:23 -0700547 private float mSurfaceTraceAlpha = 0;
Craig Mautner7358fbf2012-04-12 21:06:33 -0700548 private int mLayer;
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700549 private final PointF mPosition = new PointF();
550 private final Point mSize = new Point();
551 private final Rect mWindowCrop = new Rect();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700552 private boolean mShown = false;
Jeff Brown98365d72012-08-19 20:30:52 -0700553 private int mLayerStack;
Craig Mautner71dd1b62014-02-18 15:48:52 -0800554 private boolean mIsOpaque;
Craig Mautner78505d82014-09-02 14:36:31 -0700555 private float mDsdx, mDtdx, mDsdy, mDtdy;
Igor Murashkina86ab6402013-08-30 12:58:36 -0700556 private final String mName;
Craig Mautner7358fbf2012-04-12 21:06:33 -0700557
Craig Mautner7d8df392012-04-06 15:26:23 -0700558 public SurfaceTrace(SurfaceSession s,
Jeff Brown64a55af2012-08-26 02:47:39 -0700559 String name, int w, int h, int format, int flags)
Craig Mautner7358fbf2012-04-12 21:06:33 -0700560 throws OutOfResourcesException {
Jeff Brown64a55af2012-08-26 02:47:39 -0700561 super(s, name, w, h, format, flags);
Jeff Brown98365d72012-08-19 20:30:52 -0700562 mName = name != null ? name : "Not named";
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700563 mSize.set(w, h);
Craig Mautner49a2edf2014-09-25 14:49:26 -0700564 if (logSurfaceTrace) Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700565 + Debug.getCallers(3));
Dianne Hackborn0ed82e22014-09-19 16:16:04 -0700566 synchronized (sSurfaces) {
567 sSurfaces.add(0, this);
568 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700569 }
570
571 @Override
572 public void setAlpha(float alpha) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700573 if (mSurfaceTraceAlpha != alpha) {
Craig Mautner49a2edf2014-09-25 14:49:26 -0700574 if (logSurfaceTrace) Slog.v(SURFACE_TAG, "setAlpha(" + alpha + "): OLD:" + this +
575 ". Called by " + Debug.getCallers(3));
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700576 mSurfaceTraceAlpha = alpha;
Dianne Hackborn98129732012-11-01 16:28:16 -0700577 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700578 super.setAlpha(alpha);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700579 }
580
581 @Override
582 public void setLayer(int zorder) {
Dianne Hackborn98129732012-11-01 16:28:16 -0700583 if (zorder != mLayer) {
Craig Mautner49a2edf2014-09-25 14:49:26 -0700584 if (logSurfaceTrace) Slog.v(SURFACE_TAG, "setLayer(" + zorder + "): OLD:" + this
585 + ". Called by " + Debug.getCallers(3));
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700586 mLayer = zorder;
Dianne Hackborn98129732012-11-01 16:28:16 -0700587 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700588 super.setLayer(zorder);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700589
Dianne Hackborn0ed82e22014-09-19 16:16:04 -0700590 synchronized (sSurfaces) {
591 sSurfaces.remove(this);
592 int i;
593 for (i = sSurfaces.size() - 1; i >= 0; i--) {
594 SurfaceTrace s = sSurfaces.get(i);
595 if (s.mLayer < zorder) {
596 break;
597 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700598 }
Dianne Hackborn0ed82e22014-09-19 16:16:04 -0700599 sSurfaces.add(i + 1, this);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700600 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700601 }
602
603 @Override
604 public void setPosition(float x, float y) {
Dianne Hackborn98129732012-11-01 16:28:16 -0700605 if (x != mPosition.x || y != mPosition.y) {
Craig Mautner49a2edf2014-09-25 14:49:26 -0700606 if (logSurfaceTrace) Slog.v(SURFACE_TAG, "setPosition(" + x + "," + y + "): OLD:"
607 + this + ". Called by " + Debug.getCallers(3));
Craig Mautner66d77302013-04-10 15:33:26 -0700608 mPosition.set(x, y);
Dianne Hackborn98129732012-11-01 16:28:16 -0700609 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700610 super.setPosition(x, y);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700611 }
612
613 @Override
614 public void setSize(int w, int h) {
Dianne Hackborn98129732012-11-01 16:28:16 -0700615 if (w != mSize.x || h != mSize.y) {
Craig Mautner49a2edf2014-09-25 14:49:26 -0700616 if (logSurfaceTrace) Slog.v(SURFACE_TAG, "setSize(" + w + "," + h + "): OLD:"
617 + this + ". Called by " + Debug.getCallers(3));
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700618 mSize.set(w, h);
Dianne Hackborn98129732012-11-01 16:28:16 -0700619 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700620 super.setSize(w, h);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700621 }
622
623 @Override
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700624 public void setWindowCrop(Rect crop) {
Craig Mautneref25d7a2012-05-15 23:01:47 -0700625 if (crop != null) {
Dianne Hackborn98129732012-11-01 16:28:16 -0700626 if (!crop.equals(mWindowCrop)) {
Craig Mautner49a2edf2014-09-25 14:49:26 -0700627 if (logSurfaceTrace) Slog.v(SURFACE_TAG, "setWindowCrop("
628 + crop.toShortString() + "): OLD:" + this + ". Called by "
629 + Debug.getCallers(3));
Craig Mautner66d77302013-04-10 15:33:26 -0700630 mWindowCrop.set(crop);
Dianne Hackborn98129732012-11-01 16:28:16 -0700631 }
Craig Mautneref25d7a2012-05-15 23:01:47 -0700632 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700633 super.setWindowCrop(crop);
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700634 }
635
636 @Override
Jeff Brown98365d72012-08-19 20:30:52 -0700637 public void setLayerStack(int layerStack) {
Dianne Hackborn98129732012-11-01 16:28:16 -0700638 if (layerStack != mLayerStack) {
Craig Mautner49a2edf2014-09-25 14:49:26 -0700639 if (logSurfaceTrace) Slog.v(SURFACE_TAG, "setLayerStack(" + layerStack + "): OLD:"
640 + this + ". Called by " + Debug.getCallers(3));
Craig Mautner66d77302013-04-10 15:33:26 -0700641 mLayerStack = layerStack;
Dianne Hackborn98129732012-11-01 16:28:16 -0700642 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700643 super.setLayerStack(layerStack);
Craig Mautner9de49362012-08-02 14:30:30 -0700644 }
645
646 @Override
Craig Mautner71dd1b62014-02-18 15:48:52 -0800647 public void setOpaque(boolean isOpaque) {
648 if (isOpaque != mIsOpaque) {
Craig Mautner49a2edf2014-09-25 14:49:26 -0700649 if (logSurfaceTrace) Slog.v(SURFACE_TAG, "setOpaque(" + isOpaque + "): OLD:"
650 + this + ". Called by " + Debug.getCallers(3));
Craig Mautner71dd1b62014-02-18 15:48:52 -0800651 mIsOpaque = isOpaque;
652 }
653 super.setOpaque(isOpaque);
654 }
655
656 @Override
Craig Mautner78505d82014-09-02 14:36:31 -0700657 public void setMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
658 if (dsdx != mDsdx || dtdx != mDtdx || dsdy != mDsdy || dtdy != mDtdy) {
Craig Mautner49a2edf2014-09-25 14:49:26 -0700659 if (logSurfaceTrace) Slog.v(SURFACE_TAG, "setMatrix(" + dsdx + "," + dtdx + ","
660 + dsdy + "," + dtdy + "): OLD:" + this + ". Called by "
661 + Debug.getCallers(3));
Craig Mautner78505d82014-09-02 14:36:31 -0700662 mDsdx = dsdx;
663 mDtdx = dtdx;
664 mDsdy = dsdy;
665 mDtdy = dtdy;
666 }
667 super.setMatrix(dsdx, dtdx, dsdy, dtdy);
668 }
669
670 @Override
Craig Mautner7358fbf2012-04-12 21:06:33 -0700671 public void hide() {
Dianne Hackborn98129732012-11-01 16:28:16 -0700672 if (mShown) {
Craig Mautner49a2edf2014-09-25 14:49:26 -0700673 if (logSurfaceTrace) Slog.v(SURFACE_TAG, "hide: OLD:" + this + ". Called by "
674 + Debug.getCallers(3));
Craig Mautner66d77302013-04-10 15:33:26 -0700675 mShown = false;
Dianne Hackborn98129732012-11-01 16:28:16 -0700676 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700677 super.hide();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700678 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700679
Craig Mautner7358fbf2012-04-12 21:06:33 -0700680 @Override
681 public void show() {
Dianne Hackborn98129732012-11-01 16:28:16 -0700682 if (!mShown) {
Craig Mautner49a2edf2014-09-25 14:49:26 -0700683 if (logSurfaceTrace) Slog.v(SURFACE_TAG, "show: OLD:" + this + ". Called by "
684 + Debug.getCallers(3));
Craig Mautner66d77302013-04-10 15:33:26 -0700685 mShown = true;
Dianne Hackborn98129732012-11-01 16:28:16 -0700686 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700687 super.show();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700688 }
689
690 @Override
691 public void destroy() {
692 super.destroy();
Craig Mautner49a2edf2014-09-25 14:49:26 -0700693 if (logSurfaceTrace) Slog.v(SURFACE_TAG, "destroy: " + this + ". Called by "
694 + Debug.getCallers(3));
Dianne Hackborn0ed82e22014-09-19 16:16:04 -0700695 synchronized (sSurfaces) {
696 sSurfaces.remove(this);
697 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700698 }
699
Craig Mautneracaf9cc2012-04-17 11:45:25 -0700700 @Override
701 public void release() {
702 super.release();
Craig Mautner49a2edf2014-09-25 14:49:26 -0700703 if (logSurfaceTrace) Slog.v(SURFACE_TAG, "release: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700704 + Debug.getCallers(3));
Dianne Hackborn0ed82e22014-09-19 16:16:04 -0700705 synchronized (sSurfaces) {
706 sSurfaces.remove(this);
707 }
Craig Mautneracaf9cc2012-04-17 11:45:25 -0700708 }
709
Dianne Hackborn0ed82e22014-09-19 16:16:04 -0700710 static void dumpAllSurfaces(PrintWriter pw, String header) {
711 synchronized (sSurfaces) {
712 final int N = sSurfaces.size();
713 if (N <= 0) {
714 return;
715 }
716 if (header != null) {
717 pw.println(header);
718 }
719 pw.println("WINDOW MANAGER SURFACES (dumpsys window surfaces)");
720 for (int i = 0; i < N; i++) {
721 SurfaceTrace s = sSurfaces.get(i);
722 pw.print(" Surface #"); pw.print(i); pw.print(": #");
723 pw.print(Integer.toHexString(System.identityHashCode(s)));
724 pw.print(" "); pw.println(s.mName);
725 pw.print(" mLayerStack="); pw.print(s.mLayerStack);
726 pw.print(" mLayer="); pw.println(s.mLayer);
727 pw.print(" mShown="); pw.print(s.mShown); pw.print(" mAlpha=");
728 pw.print(s.mSurfaceTraceAlpha); pw.print(" mIsOpaque=");
729 pw.println(s.mIsOpaque);
730 pw.print(" mPosition="); pw.print(s.mPosition.x); pw.print(",");
731 pw.print(s.mPosition.y);
732 pw.print(" mSize="); pw.print(s.mSize.x); pw.print("x");
733 pw.println(s.mSize.y);
734 pw.print(" mCrop="); s.mWindowCrop.printShortString(pw); pw.println();
735 pw.print(" Transform: ("); pw.print(s.mDsdx); pw.print(", ");
736 pw.print(s.mDtdx); pw.print(", "); pw.print(s.mDsdy);
737 pw.print(", "); pw.print(s.mDtdy); pw.println(")");
738 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700739 }
740 }
741
742 @Override
743 public String toString() {
Craig Mautnerfbf378c2012-04-23 17:24:21 -0700744 return "Surface " + Integer.toHexString(System.identityHashCode(this)) + " "
Jeff Brown98365d72012-08-19 20:30:52 -0700745 + mName + " (" + mLayerStack + "): shown=" + mShown + " layer=" + mLayer
Craig Mautner7d8df392012-04-06 15:26:23 -0700746 + " alpha=" + mSurfaceTraceAlpha + " " + mPosition.x + "," + mPosition.y
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700747 + " " + mSize.x + "x" + mSize.y
Craig Mautner71dd1b62014-02-18 15:48:52 -0800748 + " crop=" + mWindowCrop.toShortString()
Craig Mautner78505d82014-09-02 14:36:31 -0700749 + " opaque=" + mIsOpaque
750 + " (" + mDsdx + "," + mDtdx + "," + mDsdy + "," + mDtdy + ")";
Craig Mautner7358fbf2012-04-12 21:06:33 -0700751 }
752 }
753
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800754 SurfaceControl createSurfaceLocked() {
Alan Viveretteccb11e12014-07-08 16:04:02 -0700755 final WindowState w = mWin;
Mathias Agopian29479eb2013-02-14 14:36:04 -0800756 if (mSurfaceControl == null) {
Craig Mautner83339b42012-05-01 22:13:23 -0700757 if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG,
758 "createSurface " + this + ": mDrawState=DRAW_PENDING");
Craig Mautner749a7bb2012-04-02 13:49:53 -0700759 mDrawState = DRAW_PENDING;
Alan Viveretteccb11e12014-07-08 16:04:02 -0700760 if (w.mAppToken != null) {
761 if (w.mAppToken.mAppAnimator.animation == null) {
762 w.mAppToken.allDrawn = false;
763 w.mAppToken.deferClearAllDrawn = false;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800764 } else {
765 // Currently animating, persist current state of allDrawn until animation
766 // is complete.
Alan Viveretteccb11e12014-07-08 16:04:02 -0700767 w.mAppToken.deferClearAllDrawn = true;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800768 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700769 }
770
Alan Viveretteccb11e12014-07-08 16:04:02 -0700771 mService.makeWindowFreezingScreenIfNeededLocked(w);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700772
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800773 int flags = SurfaceControl.HIDDEN;
Alan Viveretteccb11e12014-07-08 16:04:02 -0700774 final WindowManager.LayoutParams attrs = w.mAttrs;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700775
776 if ((attrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800777 flags |= SurfaceControl.SECURE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700778 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700779
Sander Alewijnsed2a1eec2014-07-09 12:57:05 +0100780 if (mService.isScreenCaptureDisabledLocked(UserHandle.getUserId(mWin.mOwnerUid))) {
781 flags |= SurfaceControl.SECURE;
782 }
783
Alan Viveretteccb11e12014-07-08 16:04:02 -0700784 int width;
785 int height;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700786 if ((attrs.flags & LayoutParams.FLAG_SCALED) != 0) {
787 // for a scaled surface, we always want the requested
788 // size.
Alan Viveretteccb11e12014-07-08 16:04:02 -0700789 width = w.mRequestedWidth;
790 height = w.mRequestedHeight;
791 } else {
792 width = w.mCompatFrame.width();
793 height = w.mCompatFrame.height();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700794 }
795
796 // Something is wrong and SurfaceFlinger will not like this,
797 // try to revert to sane values
Alan Viveretteccb11e12014-07-08 16:04:02 -0700798 if (width <= 0) {
799 width = 1;
800 }
801 if (height <= 0) {
802 height = 1;
803 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700804
Alan Viveretteccb11e12014-07-08 16:04:02 -0700805 float left = w.mFrame.left + w.mXOffset;
806 float top = w.mFrame.top + w.mYOffset;
807
808 // Adjust for surface insets.
Alan Viverette49a22e82014-07-12 20:01:27 -0700809 width += attrs.surfaceInsets.left + attrs.surfaceInsets.right;
810 height += attrs.surfaceInsets.top + attrs.surfaceInsets.bottom;
811 left -= attrs.surfaceInsets.left;
812 top -= attrs.surfaceInsets.top;
Alan Viveretteccb11e12014-07-08 16:04:02 -0700813
814 if (DEBUG_VISIBILITY) {
815 Slog.v(TAG, "Creating surface in session "
816 + mSession.mSurfaceSession + " window " + this
817 + " w=" + width + " h=" + height
818 + " x=" + left + " y=" + top
819 + " format=" + attrs.format + " flags=" + flags);
820 }
821
822 // We may abort, so initialize to defaults.
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700823 mSurfaceShown = false;
824 mSurfaceLayer = 0;
Craig Mautner7d8df392012-04-06 15:26:23 -0700825 mSurfaceAlpha = 0;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700826 mSurfaceX = 0;
827 mSurfaceY = 0;
Alan Viveretteccb11e12014-07-08 16:04:02 -0700828 w.mLastSystemDecorRect.set(0, 0, 0, 0);
Antoine Labour7db86872014-07-23 21:15:48 -0700829 mLastClipRect.set(0, 0, 0, 0);
Alan Viveretteccb11e12014-07-08 16:04:02 -0700830
831 // Set up surface control with initial size.
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700832 try {
Alan Viveretteccb11e12014-07-08 16:04:02 -0700833 mSurfaceW = width;
834 mSurfaceH = height;
835
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700836 final boolean isHwAccelerated = (attrs.flags &
837 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
838 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
Chris Craik868d7452014-08-27 16:51:56 -0700839 if (!PixelFormat.formatHasAlpha(attrs.format)
840 && attrs.surfaceInsets.left == 0
841 && attrs.surfaceInsets.top == 0
842 && attrs.surfaceInsets.right == 0
843 && attrs.surfaceInsets.bottom == 0) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800844 flags |= SurfaceControl.OPAQUE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700845 }
Alan Viveretteccb11e12014-07-08 16:04:02 -0700846
Craig Mautner7358fbf2012-04-12 21:06:33 -0700847 if (DEBUG_SURFACE_TRACE) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800848 mSurfaceControl = new SurfaceTrace(
Jeff Brown64a55af2012-08-26 02:47:39 -0700849 mSession.mSurfaceSession,
Craig Mautner7358fbf2012-04-12 21:06:33 -0700850 attrs.getTitle().toString(),
Alan Viveretteccb11e12014-07-08 16:04:02 -0700851 width, height, format, flags);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700852 } else {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800853 mSurfaceControl = new SurfaceControl(
Jeff Brown64a55af2012-08-26 02:47:39 -0700854 mSession.mSurfaceSession,
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700855 attrs.getTitle().toString(),
Alan Viveretteccb11e12014-07-08 16:04:02 -0700856 width, height, format, flags);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700857 }
Alan Viveretteccb11e12014-07-08 16:04:02 -0700858
859 w.mHasSurface = true;
860
861 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
862 Slog.i(TAG, " CREATE SURFACE "
863 + mSurfaceControl + " IN SESSION "
864 + mSession.mSurfaceSession
865 + ": pid=" + mSession.mPid + " format="
866 + attrs.format + " flags=0x"
867 + Integer.toHexString(flags)
868 + " / " + this);
869 }
Igor Murashkina86ab6402013-08-30 12:58:36 -0700870 } catch (OutOfResourcesException e) {
Alan Viveretteccb11e12014-07-08 16:04:02 -0700871 w.mHasSurface = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700872 Slog.w(TAG, "OutOfResourcesException creating surface");
873 mService.reclaimSomeSurfaceMemoryLocked(this, "create", true);
Craig Mautner749a7bb2012-04-02 13:49:53 -0700874 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700875 return null;
876 } catch (Exception e) {
Alan Viveretteccb11e12014-07-08 16:04:02 -0700877 w.mHasSurface = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700878 Slog.e(TAG, "Exception creating surface", e);
Craig Mautner749a7bb2012-04-02 13:49:53 -0700879 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700880 return null;
881 }
882
Alan Viveretteccb11e12014-07-08 16:04:02 -0700883 if (WindowManagerService.localLOGV) {
884 Slog.v(TAG, "Got surface: " + mSurfaceControl
885 + ", set left=" + w.mFrame.left + " top=" + w.mFrame.top
886 + ", animLayer=" + mAnimLayer);
887 }
888
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700889 if (SHOW_LIGHT_TRANSACTIONS) {
890 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
Alan Viveretteccb11e12014-07-08 16:04:02 -0700891 WindowManagerService.logSurface(w, "CREATE pos=("
892 + w.mFrame.left + "," + w.mFrame.top + ") ("
893 + w.mCompatFrame.width() + "x" + w.mCompatFrame.height()
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700894 + "), layer=" + mAnimLayer + " HIDE", null);
895 }
Alan Viveretteccb11e12014-07-08 16:04:02 -0700896
897 // Start a new transaction and apply position & offset.
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800898 SurfaceControl.openTransaction();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700899 try {
Alan Viveretteccb11e12014-07-08 16:04:02 -0700900 mSurfaceX = left;
901 mSurfaceY = top;
902
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700903 try {
Alan Viveretteccb11e12014-07-08 16:04:02 -0700904 mSurfaceControl.setPosition(left, top);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700905 mSurfaceLayer = mAnimLayer;
Alan Viveretteccb11e12014-07-08 16:04:02 -0700906 final DisplayContent displayContent = w.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800907 if (displayContent != null) {
908 mSurfaceControl.setLayerStack(displayContent.getDisplay().getLayerStack());
909 }
Mathias Agopian29479eb2013-02-14 14:36:04 -0800910 mSurfaceControl.setLayer(mAnimLayer);
911 mSurfaceControl.setAlpha(0);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700912 mSurfaceShown = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700913 } catch (RuntimeException e) {
914 Slog.w(TAG, "Error creating surface in " + w, e);
915 mService.reclaimSomeSurfaceMemoryLocked(this, "create-init", true);
916 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700917 mLastHidden = true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700918 } finally {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800919 SurfaceControl.closeTransaction();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700920 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
921 "<<< CLOSE TRANSACTION createSurfaceLocked");
922 }
923 if (WindowManagerService.localLOGV) Slog.v(
924 TAG, "Created surface " + this);
925 }
Mathias Agopian29479eb2013-02-14 14:36:04 -0800926 return mSurfaceControl;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700927 }
928
Craig Mautner96868332012-12-04 14:29:11 -0800929 void destroySurfaceLocked() {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700930 if (mWin.mAppToken != null && mWin == mWin.mAppToken.startingWindow) {
931 mWin.mAppToken.startingDisplayed = false;
932 }
933
Mathias Agopian29479eb2013-02-14 14:36:04 -0800934 if (mSurfaceControl != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700935
936 int i = mWin.mChildWindows.size();
937 while (i > 0) {
938 i--;
939 WindowState c = mWin.mChildWindows.get(i);
940 c.mAttachedHidden = true;
941 }
942
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700943 try {
944 if (DEBUG_VISIBILITY) {
945 RuntimeException e = null;
946 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
947 e = new RuntimeException();
948 e.fillInStackTrace();
949 }
950 Slog.w(TAG, "Window " + this + " destroying surface "
Mathias Agopian29479eb2013-02-14 14:36:04 -0800951 + mSurfaceControl + ", session " + mSession, e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700952 }
953 if (mSurfaceDestroyDeferred) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800954 if (mSurfaceControl != null && mPendingDestroySurface != mSurfaceControl) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700955 if (mPendingDestroySurface != null) {
956 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
957 RuntimeException e = null;
958 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
959 e = new RuntimeException();
960 e.fillInStackTrace();
961 }
962 WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
963 }
964 mPendingDestroySurface.destroy();
965 }
Mathias Agopian29479eb2013-02-14 14:36:04 -0800966 mPendingDestroySurface = mSurfaceControl;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700967 }
968 } else {
969 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
970 RuntimeException e = null;
971 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
972 e = new RuntimeException();
973 e.fillInStackTrace();
974 }
975 WindowManagerService.logSurface(mWin, "DESTROY", e);
976 }
Mathias Agopian29479eb2013-02-14 14:36:04 -0800977 mSurfaceControl.destroy();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700978 }
Craig Mautner96868332012-12-04 14:29:11 -0800979 mAnimator.hideWallpapersLocked(mWin);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700980 } catch (RuntimeException e) {
981 Slog.w(TAG, "Exception thrown when destroying Window " + this
Mathias Agopian29479eb2013-02-14 14:36:04 -0800982 + " surface " + mSurfaceControl + " session " + mSession
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700983 + ": " + e.toString());
984 }
985
986 mSurfaceShown = false;
Mathias Agopian29479eb2013-02-14 14:36:04 -0800987 mSurfaceControl = null;
Craig Mautnere8552142012-11-07 13:55:47 -0800988 mWin.mHasSurface = false;
Craig Mautnerbf08af32012-05-16 19:43:42 -0700989 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700990 }
991 }
992
Craig Mautner96868332012-12-04 14:29:11 -0800993 void destroyDeferredSurfaceLocked() {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700994 try {
995 if (mPendingDestroySurface != null) {
996 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
997 RuntimeException e = null;
998 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
999 e = new RuntimeException();
1000 e.fillInStackTrace();
1001 }
1002 WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
1003 }
1004 mPendingDestroySurface.destroy();
Craig Mautner96868332012-12-04 14:29:11 -08001005 mAnimator.hideWallpapersLocked(mWin);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001006 }
1007 } catch (RuntimeException e) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001008 Slog.w(TAG, "Exception thrown when destroying Window "
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001009 + this + " surface " + mPendingDestroySurface
1010 + " session " + mSession + ": " + e.toString());
1011 }
1012 mSurfaceDestroyDeferred = false;
1013 mPendingDestroySurface = null;
1014 }
1015
1016 void computeShownFrameLocked() {
1017 final boolean selfTransformation = mHasLocalTransformation;
1018 Transformation attachedTransformation =
Craig Mautner322e4032012-07-13 13:35:20 -07001019 (mAttachedWinAnimator != null && mAttachedWinAnimator.mHasLocalTransformation)
1020 ? mAttachedWinAnimator.mTransformation : null;
1021 Transformation appTransformation = (mAppAnimator != null && mAppAnimator.hasTransformation)
1022 ? mAppAnimator.transformation : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001023
1024 // Wallpapers are animated based on the "real" window they
1025 // are currently targeting.
Craig Mautner798adef2013-10-22 14:29:01 -07001026 final WindowState wallpaperTarget = mService.mWallpaperTarget;
1027 if (mIsWallpaper && wallpaperTarget != null && mService.mAnimateWallpaperWithTarget) {
1028 final WindowStateAnimator wallpaperAnimator = wallpaperTarget.mWinAnimator;
Craig Mautner918b53b2012-07-09 14:15:54 -07001029 if (wallpaperAnimator.mHasLocalTransformation &&
1030 wallpaperAnimator.mAnimation != null &&
1031 !wallpaperAnimator.mAnimation.getDetachWallpaper()) {
1032 attachedTransformation = wallpaperAnimator.mTransformation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001033 if (WindowManagerService.DEBUG_WALLPAPER && attachedTransformation != null) {
1034 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
1035 }
1036 }
Craig Mautner798adef2013-10-22 14:29:01 -07001037 final AppWindowAnimator wpAppAnimator = wallpaperTarget.mAppToken == null ?
1038 null : wallpaperTarget.mAppToken.mAppAnimator;
1039 if (wpAppAnimator != null && wpAppAnimator.hasTransformation
Craig Mautner918b53b2012-07-09 14:15:54 -07001040 && wpAppAnimator.animation != null
1041 && !wpAppAnimator.animation.getDetachWallpaper()) {
Craig Mautner59431632012-04-04 11:56:44 -07001042 appTransformation = wpAppAnimator.transformation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001043 if (WindowManagerService.DEBUG_WALLPAPER && appTransformation != null) {
1044 Slog.v(TAG, "WP target app xform: " + appTransformation);
1045 }
1046 }
1047 }
1048
Craig Mautnera91f9e22012-09-14 16:22:08 -07001049 final int displayId = mWin.getDisplayId();
1050 final ScreenRotationAnimation screenRotationAnimation =
1051 mAnimator.getScreenRotationAnimationLocked(displayId);
1052 final boolean screenAnimation =
1053 screenRotationAnimation != null && screenRotationAnimation.isAnimating();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001054 if (selfTransformation || attachedTransformation != null
1055 || appTransformation != null || screenAnimation) {
1056 // cache often used attributes locally
1057 final Rect frame = mWin.mFrame;
1058 final float tmpFloats[] = mService.mTmpFloats;
1059 final Matrix tmpMatrix = mWin.mTmpMatrix;
1060
1061 // Compute the desired transformation.
Dianne Hackborn4b169692012-11-29 17:51:24 -08001062 if (screenAnimation && screenRotationAnimation.isRotating()) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001063 // If we are doing a screen animation, the global rotation
1064 // applied to windows can result in windows that are carefully
1065 // aligned with each other to slightly separate, allowing you
1066 // to see what is behind them. An unsightly mess. This...
1067 // thing... magically makes it call good: scale each window
1068 // slightly (two pixels larger in each dimension, from the
1069 // window's center).
1070 final float w = frame.width();
1071 final float h = frame.height();
1072 if (w>=1 && h>=1) {
1073 tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2);
1074 } else {
1075 tmpMatrix.reset();
1076 }
1077 } else {
1078 tmpMatrix.reset();
1079 }
1080 tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale);
1081 if (selfTransformation) {
1082 tmpMatrix.postConcat(mTransformation.getMatrix());
1083 }
1084 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
1085 if (attachedTransformation != null) {
1086 tmpMatrix.postConcat(attachedTransformation.getMatrix());
1087 }
1088 if (appTransformation != null) {
1089 tmpMatrix.postConcat(appTransformation.getMatrix());
1090 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001091 if (mAnimator.mUniverseBackground != null) {
1092 tmpMatrix.postConcat(mAnimator.mUniverseBackground.mUniverseTransform.getMatrix());
1093 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001094 if (screenAnimation) {
Craig Mautnera91f9e22012-09-14 16:22:08 -07001095 tmpMatrix.postConcat(screenRotationAnimation.getEnterTransformation().getMatrix());
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001096 }
Winson Chung399f6202014-03-19 10:47:20 -07001097
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001098 //TODO (multidisplay): Magnification is supported only for the default display.
Svetoslav8e3feb12014-02-24 13:46:47 -08001099 if (mService.mAccessibilityController != null && displayId == Display.DEFAULT_DISPLAY) {
1100 MagnificationSpec spec = mService.mAccessibilityController
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001101 .getMagnificationSpecForWindowLocked(mWin);
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -07001102 if (spec != null && !spec.isNop()) {
1103 tmpMatrix.postScale(spec.scale, spec.scale);
1104 tmpMatrix.postTranslate(spec.offsetX, spec.offsetY);
1105 }
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001106 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001107
1108 // "convert" it into SurfaceFlinger's format
1109 // (a 2x2 matrix + an offset)
1110 // Here we must not transform the position of the surface
1111 // since it is already included in the transformation.
1112 //Slog.i(TAG, "Transform: " + matrix);
1113
1114 mHaveMatrix = true;
1115 tmpMatrix.getValues(tmpFloats);
1116 mDsDx = tmpFloats[Matrix.MSCALE_X];
1117 mDtDx = tmpFloats[Matrix.MSKEW_Y];
1118 mDsDy = tmpFloats[Matrix.MSKEW_X];
1119 mDtDy = tmpFloats[Matrix.MSCALE_Y];
1120 float x = tmpFloats[Matrix.MTRANS_X];
1121 float y = tmpFloats[Matrix.MTRANS_Y];
1122 int w = frame.width();
1123 int h = frame.height();
1124 mWin.mShownFrame.set(x, y, x+w, y+h);
1125
1126 // Now set the alpha... but because our current hardware
1127 // can't do alpha transformation on a non-opaque surface,
1128 // turn it off if we are running an animation that is also
1129 // transforming since it is more important to have that
1130 // animation be smooth.
1131 mShownAlpha = mAlpha;
Winson Chung399f6202014-03-19 10:47:20 -07001132 mHasClipRect = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001133 if (!mService.mLimitedAlphaCompositing
1134 || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format)
1135 || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
1136 && x == frame.left && y == frame.top))) {
1137 //Slog.i(TAG, "Applying alpha transform");
1138 if (selfTransformation) {
1139 mShownAlpha *= mTransformation.getAlpha();
1140 }
1141 if (attachedTransformation != null) {
1142 mShownAlpha *= attachedTransformation.getAlpha();
1143 }
1144 if (appTransformation != null) {
1145 mShownAlpha *= appTransformation.getAlpha();
Winson Chung399f6202014-03-19 10:47:20 -07001146 if (appTransformation.hasClipRect()) {
1147 mClipRect.set(appTransformation.getClipRect());
Craig Mautner78505d82014-09-02 14:36:31 -07001148 if (mWin.mHScale > 0) {
1149 mClipRect.left /= mWin.mHScale;
1150 mClipRect.right /= mWin.mHScale;
1151 }
1152 if (mWin.mVScale > 0) {
1153 mClipRect.top /= mWin.mVScale;
1154 mClipRect.bottom /= mWin.mVScale;
1155 }
Winson Chung399f6202014-03-19 10:47:20 -07001156 mHasClipRect = true;
1157 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001158 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001159 if (mAnimator.mUniverseBackground != null) {
1160 mShownAlpha *= mAnimator.mUniverseBackground.mUniverseTransform.getAlpha();
1161 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001162 if (screenAnimation) {
Craig Mautnera91f9e22012-09-14 16:22:08 -07001163 mShownAlpha *= screenRotationAnimation.getEnterTransformation().getAlpha();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001164 }
1165 } else {
1166 //Slog.i(TAG, "Not applying alpha transform");
1167 }
1168
Craig Mautnera91f9e22012-09-14 16:22:08 -07001169 if ((DEBUG_SURFACE_TRACE || WindowManagerService.localLOGV)
1170 && (mShownAlpha == 1.0 || mShownAlpha == 0.0)) Slog.v(
1171 TAG, "computeShownFrameLocked: Animating " + this + " mAlpha=" + mAlpha
1172 + " self=" + (selfTransformation ? mTransformation.getAlpha() : "null")
1173 + " attached=" + (attachedTransformation == null ?
1174 "null" : attachedTransformation.getAlpha())
1175 + " app=" + (appTransformation == null ? "null" : appTransformation.getAlpha())
1176 + " screen=" + (screenAnimation ?
1177 screenRotationAnimation.getEnterTransformation().getAlpha() : "null"));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001178 return;
Craig Mautner96868332012-12-04 14:29:11 -08001179 } else if (mIsWallpaper && mService.mInnerFields.mWallpaperActionPending) {
Craig Mautner4d7349b2012-04-20 14:52:47 -07001180 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001181 }
1182
1183 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautner4d7349b2012-04-20 14:52:47 -07001184 TAG, "computeShownFrameLocked: " + this +
1185 " not attached, mAlpha=" + mAlpha);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001186
1187 final boolean applyUniverseTransformation = (mAnimator.mUniverseBackground != null
1188 && mWin.mAttrs.type != WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND
1189 && mWin.mBaseLayer < mAnimator.mAboveUniverseLayer);
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001190 MagnificationSpec spec = null;
1191 //TODO (multidisplay): Magnification is supported only for the default display.
Svetoslav8e3feb12014-02-24 13:46:47 -08001192 if (mService.mAccessibilityController != null && displayId == Display.DEFAULT_DISPLAY) {
1193 spec = mService.mAccessibilityController.getMagnificationSpecForWindowLocked(mWin);
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001194 }
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001195 if (applyUniverseTransformation || spec != null) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001196 final Rect frame = mWin.mFrame;
1197 final float tmpFloats[] = mService.mTmpFloats;
1198 final Matrix tmpMatrix = mWin.mTmpMatrix;
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001199
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001200 tmpMatrix.setScale(mWin.mGlobalScale, mWin.mGlobalScale);
1201 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001202
1203 if (applyUniverseTransformation) {
1204 tmpMatrix.postConcat(mAnimator.mUniverseBackground.mUniverseTransform.getMatrix());
1205 }
1206
1207 if (spec != null && !spec.isNop()) {
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -07001208 tmpMatrix.postScale(spec.scale, spec.scale);
1209 tmpMatrix.postTranslate(spec.offsetX, spec.offsetY);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001210 }
1211
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001212 tmpMatrix.getValues(tmpFloats);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001213
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001214 mHaveMatrix = true;
1215 mDsDx = tmpFloats[Matrix.MSCALE_X];
1216 mDtDx = tmpFloats[Matrix.MSKEW_Y];
1217 mDsDy = tmpFloats[Matrix.MSKEW_X];
1218 mDtDy = tmpFloats[Matrix.MSCALE_Y];
1219 float x = tmpFloats[Matrix.MTRANS_X];
1220 float y = tmpFloats[Matrix.MTRANS_Y];
1221 int w = frame.width();
1222 int h = frame.height();
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001223 mWin.mShownFrame.set(x, y, x + w, y + h);
1224
1225 mShownAlpha = mAlpha;
1226 if (applyUniverseTransformation) {
1227 mShownAlpha *= mAnimator.mUniverseBackground.mUniverseTransform.getAlpha();
1228 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001229 } else {
1230 mWin.mShownFrame.set(mWin.mFrame);
1231 if (mWin.mXOffset != 0 || mWin.mYOffset != 0) {
1232 mWin.mShownFrame.offset(mWin.mXOffset, mWin.mYOffset);
1233 }
1234 mShownAlpha = mAlpha;
1235 mHaveMatrix = false;
1236 mDsDx = mWin.mGlobalScale;
1237 mDtDx = 0;
1238 mDsDy = 0;
1239 mDtDy = mWin.mGlobalScale;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001240 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001241 }
1242
1243 void applyDecorRect(final Rect decorRect) {
1244 final WindowState w = mWin;
Alan Viverette49a22e82014-07-12 20:01:27 -07001245 final int width = w.mFrame.width();
1246 final int height = w.mFrame.height();
Alan Viveretteccb11e12014-07-08 16:04:02 -07001247
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001248 // Compute the offset of the window in relation to the decor rect.
Alan Viverette49a22e82014-07-12 20:01:27 -07001249 final int left = w.mXOffset + w.mFrame.left;
1250 final int top = w.mYOffset + w.mFrame.top;
Alan Viveretteccb11e12014-07-08 16:04:02 -07001251
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001252 // Initialize the decor rect to the entire frame.
Alan Viveretteccb11e12014-07-08 16:04:02 -07001253 w.mSystemDecorRect.set(0, 0, width, height);
1254
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001255 // Intersect with the decor rect, offsetted by window position.
Alan Viveretteccb11e12014-07-08 16:04:02 -07001256 w.mSystemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
1257 decorRect.right - left, decorRect.bottom - top);
1258
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001259 // If size compatibility is being applied to the window, the
1260 // surface is scaled relative to the screen. Also apply this
1261 // scaling to the crop rect. We aren't using the standard rect
1262 // scale function because we want to round things to make the crop
1263 // always round to a larger rect to ensure we don't crop too
1264 // much and hide part of the window that should be seen.
1265 if (w.mEnforceSizeCompat && w.mInvGlobalScale != 1.0f) {
1266 final float scale = w.mInvGlobalScale;
1267 w.mSystemDecorRect.left = (int) (w.mSystemDecorRect.left * scale - 0.5f);
1268 w.mSystemDecorRect.top = (int) (w.mSystemDecorRect.top * scale - 0.5f);
1269 w.mSystemDecorRect.right = (int) ((w.mSystemDecorRect.right+1) * scale - 0.5f);
1270 w.mSystemDecorRect.bottom = (int) ((w.mSystemDecorRect.bottom+1) * scale - 0.5f);
1271 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001272 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001273
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001274 void updateSurfaceWindowCrop(final boolean recoveringMemory) {
1275 final WindowState w = mWin;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001276 final DisplayContent displayContent = w.getDisplayContent();
1277 if (displayContent == null) {
1278 return;
1279 }
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001280
1281 // Need to recompute a new system decor rect each time.
1282 if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
1283 // Currently can't do this cropping for scaled windows. We'll
1284 // just keep the crop rect the same as the source surface.
1285 w.mSystemDecorRect.set(0, 0, w.mRequestedWidth, w.mRequestedHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07001286 } else if (!w.isDefaultDisplay()) {
Jeff Brown28e0b092012-09-25 11:31:28 -07001287 // On a different display there is no system decor. Crop the window
1288 // by the screen boundaries.
Alan Viverette49a22e82014-07-12 20:01:27 -07001289 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Jeff Brown36714102012-09-24 17:36:06 -07001290 w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height());
Jeff Brown28e0b092012-09-25 11:31:28 -07001291 w.mSystemDecorRect.intersect(-w.mCompatFrame.left, -w.mCompatFrame.top,
1292 displayInfo.logicalWidth - w.mCompatFrame.left,
1293 displayInfo.logicalHeight - w.mCompatFrame.top);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001294 } else if (w.mLayer >= mService.mSystemDecorLayer) {
1295 // Above the decor layer is easy, just use the entire window.
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001296 // Unless we have a universe background... in which case all the
1297 // windows need to be cropped by the screen, so they don't cover
1298 // the universe background.
1299 if (mAnimator.mUniverseBackground == null) {
Alan Viverette49a22e82014-07-12 20:01:27 -07001300 w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height());
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001301 } else {
1302 applyDecorRect(mService.mScreenRect);
1303 }
John Spurlock46646232013-09-30 22:32:42 -04001304 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND
1305 || w.mDecorFrame.isEmpty()) {
1306 // The universe background isn't cropped, nor windows without policy decor.
Alan Viverette49a22e82014-07-12 20:01:27 -07001307 w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height());
Adrian Roosd47ad032014-08-15 23:17:05 +02001308 } else if (w.mAttrs.type == LayoutParams.TYPE_WALLPAPER && mAnimator.mAnimating) {
1309 // If we're animating, the wallpaper crop should only be updated at the end of the
1310 // animation.
1311 mTmpClipRect.set(w.mSystemDecorRect);
1312 applyDecorRect(w.mDecorFrame);
1313 w.mSystemDecorRect.union(mTmpClipRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001314 } else {
John Spurlock46646232013-09-30 22:32:42 -04001315 // Crop to the system decor specified by policy.
1316 applyDecorRect(w.mDecorFrame);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001317 }
1318
Alan Viverette49a22e82014-07-12 20:01:27 -07001319 // By default, the clip rect is the system decor.
1320 final Rect clipRect = mTmpClipRect;
1321 clipRect.set(w.mSystemDecorRect);
Winson Chung399f6202014-03-19 10:47:20 -07001322
Alan Viverette49a22e82014-07-12 20:01:27 -07001323 // Expand the clip rect for surface insets.
1324 final WindowManager.LayoutParams attrs = w.mAttrs;
1325 clipRect.left -= attrs.surfaceInsets.left;
1326 clipRect.top -= attrs.surfaceInsets.top;
1327 clipRect.right += attrs.surfaceInsets.right;
1328 clipRect.bottom += attrs.surfaceInsets.bottom;
1329
1330 // If we have an animated clip rect, intersect it with the clip rect.
1331 if (mHasClipRect) {
1332 // NOTE: We are adding a temporary workaround due to the status bar
1333 // not always reporting the correct system decor rect. In such
1334 // cases, we take into account the specified content insets as well.
Adrian Roos3eeb4e62014-05-19 12:43:26 +02001335 if ((w.mSystemUiVisibility & SYSTEM_UI_FLAGS_LAYOUT_STABLE_FULLSCREEN)
Adrian Roosce4a0cf2014-09-15 16:54:24 +02001336 == SYSTEM_UI_FLAGS_LAYOUT_STABLE_FULLSCREEN
1337 || (w.mAttrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Alan Viverette49a22e82014-07-12 20:01:27 -07001338 // Don't apply the workaround to apps explicitly requesting
Adrian Roosce4a0cf2014-09-15 16:54:24 +02001339 // fullscreen layout or when the bars are transparent.
Alan Viverette49a22e82014-07-12 20:01:27 -07001340 clipRect.intersect(mClipRect);
Adrian Roos3eeb4e62014-05-19 12:43:26 +02001341 } else {
Alan Viverette49a22e82014-07-12 20:01:27 -07001342 final int offsetTop = Math.max(clipRect.top, w.mContentInsets.top);
1343 clipRect.offset(0, -offsetTop);
1344 clipRect.intersect(mClipRect);
1345 clipRect.offset(0, offsetTop);
Adrian Roos3eeb4e62014-05-19 12:43:26 +02001346 }
Winson Chung399f6202014-03-19 10:47:20 -07001347 }
1348
Alan Viverette49a22e82014-07-12 20:01:27 -07001349 // The clip rect was generated assuming (0,0) as the window origin,
1350 // so we need to translate to match the actual surface coordinates.
1351 clipRect.offset(attrs.surfaceInsets.left, attrs.surfaceInsets.top);
1352
Winson Chung399f6202014-03-19 10:47:20 -07001353 if (!clipRect.equals(mLastClipRect)) {
1354 mLastClipRect.set(clipRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001355 try {
1356 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
Winson Chung399f6202014-03-19 10:47:20 -07001357 "CROP " + clipRect.toShortString(), null);
1358 mSurfaceControl.setWindowCrop(clipRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001359 } catch (RuntimeException e) {
1360 Slog.w(TAG, "Error setting crop surface of " + w
Winson Chung399f6202014-03-19 10:47:20 -07001361 + " crop=" + clipRect.toShortString(), e);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001362 if (!recoveringMemory) {
1363 mService.reclaimSomeSurfaceMemoryLocked(this, "crop", true);
1364 }
1365 }
1366 }
1367 }
1368
Craig Mautnera91f9e22012-09-14 16:22:08 -07001369 void setSurfaceBoundariesLocked(final boolean recoveringMemory) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001370 final WindowState w = mWin;
Alan Viveretteccb11e12014-07-08 16:04:02 -07001371
1372 int width;
1373 int height;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001374 if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
Alan Viveretteccb11e12014-07-08 16:04:02 -07001375 // for a scaled surface, we always want the requested
1376 // size.
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001377 width = w.mRequestedWidth;
1378 height = w.mRequestedHeight;
1379 } else {
1380 width = w.mCompatFrame.width();
1381 height = w.mCompatFrame.height();
1382 }
1383
Alan Viveretteccb11e12014-07-08 16:04:02 -07001384 // Something is wrong and SurfaceFlinger will not like this,
1385 // try to revert to sane values
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001386 if (width < 1) {
1387 width = 1;
1388 }
1389 if (height < 1) {
1390 height = 1;
1391 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001392
Alan Viveretteccb11e12014-07-08 16:04:02 -07001393 float left = w.mShownFrame.left;
1394 float top = w.mShownFrame.top;
1395
1396 // Adjust for surface insets.
1397 final LayoutParams attrs = w.getAttrs();
Alan Viverette49a22e82014-07-12 20:01:27 -07001398 width += attrs.surfaceInsets.left + attrs.surfaceInsets.right;
1399 height += attrs.surfaceInsets.top + attrs.surfaceInsets.bottom;
1400 left -= attrs.surfaceInsets.left;
1401 top -= attrs.surfaceInsets.top;
Alan Viveretteccb11e12014-07-08 16:04:02 -07001402
1403 final boolean surfaceMoved = mSurfaceX != left || mSurfaceY != top;
1404 if (surfaceMoved) {
1405 mSurfaceX = left;
1406 mSurfaceY = top;
1407
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001408 try {
1409 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
Craig Mautner4d7349b2012-04-20 14:52:47 -07001410 "POS " + left + ", " + top, null);
Mathias Agopian29479eb2013-02-14 14:36:04 -08001411 mSurfaceControl.setPosition(left, top);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001412 } catch (RuntimeException e) {
1413 Slog.w(TAG, "Error positioning surface of " + w
Alan Viveretteccb11e12014-07-08 16:04:02 -07001414 + " pos=(" + left + "," + top + ")", e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001415 if (!recoveringMemory) {
1416 mService.reclaimSomeSurfaceMemoryLocked(this, "position", true);
1417 }
1418 }
1419 }
1420
Alan Viveretteccb11e12014-07-08 16:04:02 -07001421 final boolean surfaceResized = mSurfaceW != width || mSurfaceH != height;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001422 if (surfaceResized) {
Alan Viveretteccb11e12014-07-08 16:04:02 -07001423 mSurfaceW = width;
1424 mSurfaceH = height;
1425 mSurfaceResized = true;
1426
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001427 try {
1428 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1429 "SIZE " + width + "x" + height, null);
Mathias Agopian29479eb2013-02-14 14:36:04 -08001430 mSurfaceControl.setSize(width, height);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001431 mAnimator.setPendingLayoutChanges(w.getDisplayId(),
Craig Mautner76a71652012-09-03 23:23:58 -07001432 WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
Craig Mautner3a67f352012-05-07 11:21:33 -07001433 if ((w.mAttrs.flags & LayoutParams.FLAG_DIM_BEHIND) != 0) {
Craig Mautner41a7b792014-09-11 18:40:22 -07001434 final TaskStack stack = w.getStack();
1435 if (stack != null) {
1436 stack.startDimmingIfNeeded(this);
1437 }
Craig Mautner3a67f352012-05-07 11:21:33 -07001438 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001439 } catch (RuntimeException e) {
1440 // If something goes wrong with the surface (such
1441 // as running out of memory), don't take down the
1442 // entire system.
1443 Slog.e(TAG, "Error resizing surface of " + w
1444 + " size=(" + width + "x" + height + ")", e);
1445 if (!recoveringMemory) {
1446 mService.reclaimSomeSurfaceMemoryLocked(this, "size", true);
1447 }
1448 }
1449 }
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001450
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001451 updateSurfaceWindowCrop(recoveringMemory);
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001452 }
1453
1454 public void prepareSurfaceLocked(final boolean recoveringMemory) {
1455 final WindowState w = mWin;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001456 if (mSurfaceControl == null) {
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001457 if (w.mOrientationChanging) {
1458 if (DEBUG_ORIENTATION) {
1459 Slog.v(TAG, "Orientation change skips hidden " + w);
1460 }
1461 w.mOrientationChanging = false;
1462 }
1463 return;
1464 }
1465
1466 boolean displayed = false;
1467
1468 computeShownFrameLocked();
1469
Craig Mautnera91f9e22012-09-14 16:22:08 -07001470 setSurfaceBoundariesLocked(recoveringMemory);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001471
Craig Mautner918b53b2012-07-09 14:15:54 -07001472 if (mIsWallpaper && !mWin.mWallpaperVisible) {
Craig Mautner0fa77c12012-06-11 15:57:19 -07001473 // Wallpaper is no longer visible and there is no wp target => hide it.
1474 hide();
Craig Mautner72669d12012-12-18 17:23:54 -08001475 } else if (w.mAttachedHidden || !w.isOnScreen()) {
Craig Mautner0afddcb2012-05-08 15:38:00 -07001476 hide();
Craig Mautner96868332012-12-04 14:29:11 -08001477 mAnimator.hideWallpapersLocked(w);
Craig Mautnerb9836b92012-06-11 11:40:09 -07001478
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001479 // If we are waiting for this window to handle an
1480 // orientation change, well, it is hidden, so
1481 // doesn't really matter. Note that this does
1482 // introduce a potential glitch if the window
1483 // becomes unhidden before it has drawn for the
1484 // new orientation.
1485 if (w.mOrientationChanging) {
1486 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001487 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001488 "Orientation change skips hidden " + w);
1489 }
1490 } else if (mLastLayer != mAnimLayer
1491 || mLastAlpha != mShownAlpha
1492 || mLastDsDx != mDsDx
1493 || mLastDtDx != mDtDx
1494 || mLastDsDy != mDsDy
1495 || mLastDtDy != mDtDy
1496 || w.mLastHScale != w.mHScale
1497 || w.mLastVScale != w.mVScale
Craig Mautner749a7bb2012-04-02 13:49:53 -07001498 || mLastHidden) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001499 displayed = true;
1500 mLastAlpha = mShownAlpha;
1501 mLastLayer = mAnimLayer;
1502 mLastDsDx = mDsDx;
1503 mLastDtDx = mDtDx;
1504 mLastDsDy = mDsDy;
1505 mLastDtDy = mDtDy;
1506 w.mLastHScale = w.mHScale;
1507 w.mLastVScale = w.mVScale;
1508 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1509 "alpha=" + mShownAlpha + " layer=" + mAnimLayer
Craig Mautner78505d82014-09-02 14:36:31 -07001510 + " matrix=[" + mDsDx + "*" + w.mHScale
1511 + "," + mDtDx + "*" + w.mVScale
1512 + "][" + mDsDy + "*" + w.mHScale
1513 + "," + mDtDy + "*" + w.mVScale + "]", null);
Mathias Agopian29479eb2013-02-14 14:36:04 -08001514 if (mSurfaceControl != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001515 try {
1516 mSurfaceAlpha = mShownAlpha;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001517 mSurfaceControl.setAlpha(mShownAlpha);
Craig Mautnerad5725d2012-06-05 10:20:56 -07001518 mSurfaceLayer = mAnimLayer;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001519 mSurfaceControl.setLayer(mAnimLayer);
1520 mSurfaceControl.setMatrix(
Winson Chung399f6202014-03-19 10:47:20 -07001521 mDsDx * w.mHScale, mDtDx * w.mVScale,
1522 mDsDy * w.mHScale, mDtDy * w.mVScale);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001523
1524 if (mLastHidden && mDrawState == HAS_DRAWN) {
1525 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1526 "SHOW (performLayout)", null);
1527 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
1528 + " during relayout");
1529 if (showSurfaceRobustlyLocked()) {
1530 mLastHidden = false;
Craig Mautner918b53b2012-07-09 14:15:54 -07001531 if (mIsWallpaper) {
Craig Mautner507a2ee2012-06-13 08:39:38 -07001532 mService.dispatchWallpaperVisibility(w, true);
1533 }
Craig Mautner8efb0a42013-08-08 14:59:00 -07001534 // This draw means the difference between unique content and mirroring.
1535 // Run another pass through performLayout to set mHasContent in the
1536 // LogicalDisplay.
1537 mAnimator.setPendingLayoutChanges(w.getDisplayId(),
1538 WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001539 } else {
1540 w.mOrientationChanging = false;
1541 }
1542 }
Mathias Agopian29479eb2013-02-14 14:36:04 -08001543 if (mSurfaceControl != null) {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001544 w.mToken.hasVisible = true;
1545 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001546 } catch (RuntimeException e) {
1547 Slog.w(TAG, "Error updating surface in " + w, e);
1548 if (!recoveringMemory) {
1549 mService.reclaimSomeSurfaceMemoryLocked(this, "update", true);
1550 }
1551 }
1552 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001553 } else {
Craig Mautner9e809442012-06-22 17:13:04 -07001554 if (DEBUG_ANIM && isAnimating()) {
1555 Slog.v(TAG, "prepareSurface: No changes in animation for " + this);
Craig Mautner83339b42012-05-01 22:13:23 -07001556 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001557 displayed = true;
1558 }
1559
1560 if (displayed) {
1561 if (w.mOrientationChanging) {
1562 if (!w.isDrawnLw()) {
Craig Mautner2639da52012-07-09 09:39:06 -07001563 mAnimator.mBulkUpdateParams &= ~SET_ORIENTATION_CHANGE_COMPLETE;
Dianne Hackborna57c6952013-03-29 14:46:40 -07001564 mAnimator.mLastWindowFreezeSource = w;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001565 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001566 "Orientation continue waiting for draw in " + w);
1567 } else {
1568 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001569 if (DEBUG_ORIENTATION) Slog.v(TAG, "Orientation change complete in " + w);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001570 }
1571 }
1572 w.mToken.hasVisible = true;
1573 }
1574 }
1575
Craig Mautneref655012013-01-03 11:20:24 -08001576 void setTransparentRegionHintLocked(final Region region) {
Mathias Agopian29479eb2013-02-14 14:36:04 -08001577 if (mSurfaceControl == null) {
Craig Mautner1f4e0cc2012-04-10 14:24:38 -07001578 Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true");
1579 return;
1580 }
Craig Mautner71dd1b62014-02-18 15:48:52 -08001581 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setTransparentRegion");
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001582 SurfaceControl.openTransaction();
Craig Mautner48ba1e72012-04-02 13:18:16 -07001583 try {
1584 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
1585 "transparentRegionHint=" + region, null);
Mathias Agopian29479eb2013-02-14 14:36:04 -08001586 mSurfaceControl.setTransparentRegionHint(region);
Craig Mautner48ba1e72012-04-02 13:18:16 -07001587 } finally {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001588 SurfaceControl.closeTransaction();
Craig Mautner48ba1e72012-04-02 13:18:16 -07001589 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1590 "<<< CLOSE TRANSACTION setTransparentRegion");
1591 }
1592 }
1593
Craig Mautner58106812012-12-28 12:27:40 -08001594 void setWallpaperOffset(RectF shownFrame) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07001595 final LayoutParams attrs = mWin.getAttrs();
1596 final int left = ((int) shownFrame.left) - attrs.surfaceInsets.left;
1597 final int top = ((int) shownFrame.top) - attrs.surfaceInsets.top;
Craig Mautner58106812012-12-28 12:27:40 -08001598 if (mSurfaceX != left || mSurfaceY != top) {
1599 mSurfaceX = left;
1600 mSurfaceY = top;
1601 if (mAnimating) {
1602 // If this window (or its app token) is animating, then the position
1603 // of the surface will be re-computed on the next animation frame.
1604 // We can't poke it directly here because it depends on whatever
1605 // transformation is being applied by the animation.
1606 return;
1607 }
Craig Mautner71dd1b62014-02-18 15:48:52 -08001608 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setWallpaperOffset");
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001609 SurfaceControl.openTransaction();
Craig Mautner58106812012-12-28 12:27:40 -08001610 try {
1611 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
1612 "POS " + left + ", " + top, null);
Mathias Agopian29479eb2013-02-14 14:36:04 -08001613 mSurfaceControl.setPosition(mWin.mFrame.left + left, mWin.mFrame.top + top);
Craig Mautner58106812012-12-28 12:27:40 -08001614 updateSurfaceWindowCrop(false);
1615 } catch (RuntimeException e) {
1616 Slog.w(TAG, "Error positioning surface of " + mWin
1617 + " pos=(" + left + "," + top + ")", e);
1618 } finally {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001619 SurfaceControl.closeTransaction();
Craig Mautner58106812012-12-28 12:27:40 -08001620 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1621 "<<< CLOSE TRANSACTION setWallpaperOffset");
1622 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001623 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001624 }
1625
Craig Mautner6f612042014-09-07 13:13:23 -07001626 void setOpaqueLocked(boolean isOpaque) {
Craig Mautner71dd1b62014-02-18 15:48:52 -08001627 if (mSurfaceControl == null) {
1628 return;
1629 }
Craig Mautner6f612042014-09-07 13:13:23 -07001630 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setOpaqueLocked");
Craig Mautner71dd1b62014-02-18 15:48:52 -08001631 SurfaceControl.openTransaction();
1632 try {
1633 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, "isOpaque=" + isOpaque,
1634 null);
1635 mSurfaceControl.setOpaque(isOpaque);
1636 } finally {
1637 SurfaceControl.closeTransaction();
Craig Mautner6f612042014-09-07 13:13:23 -07001638 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION setOpaqueLocked");
Craig Mautner71dd1b62014-02-18 15:48:52 -08001639 }
1640 }
1641
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001642 // This must be called while inside a transaction.
1643 boolean performShowLocked() {
Craig Mautner5962b122012-10-05 14:45:52 -07001644 if (mWin.isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001645 return false;
1646 }
Craig Mautner6fbda632012-07-03 09:26:39 -07001647 if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
1648 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001649 RuntimeException e = null;
1650 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
1651 e = new RuntimeException();
1652 e.fillInStackTrace();
1653 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001654 Slog.v(TAG, "performShow on " + this
Craig Mautner749a7bb2012-04-02 13:49:53 -07001655 + ": mDrawState=" + mDrawState + " readyForDisplay="
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001656 + mWin.isReadyForDisplayIgnoringKeyguard()
Craig Mautner6fbda632012-07-03 09:26:39 -07001657 + " starting=" + (mWin.mAttrs.type == TYPE_APPLICATION_STARTING)
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001658 + " during animation: policyVis=" + mWin.mPolicyVisibility
1659 + " attHidden=" + mWin.mAttachedHidden
1660 + " tok.hiddenRequested="
1661 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
1662 + " tok.hidden="
1663 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
1664 + " animating=" + mAnimating
1665 + " tok animating="
Craig Mautner322e4032012-07-13 13:35:20 -07001666 + (mAppAnimator != null ? mAppAnimator.animating : false), e);
Craig Mautner6fbda632012-07-03 09:26:39 -07001667 }
1668 if (mDrawState == READY_TO_SHOW && mWin.isReadyForDisplayIgnoringKeyguard()) {
1669 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
1670 WindowManagerService.logSurface(mWin, "SHOW (performShowLocked)", null);
1671 if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
1672 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
1673 Slog.v(TAG, "Showing " + this
1674 + " during animation: policyVis=" + mWin.mPolicyVisibility
1675 + " attHidden=" + mWin.mAttachedHidden
1676 + " tok.hiddenRequested="
1677 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
1678 + " tok.hidden="
1679 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
1680 + " animating=" + mAnimating
1681 + " tok animating="
Craig Mautner322e4032012-07-13 13:35:20 -07001682 + (mAppAnimator != null ? mAppAnimator.animating : false));
Craig Mautner6fbda632012-07-03 09:26:39 -07001683 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001684
1685 mService.enableScreenIfNeededLocked();
1686
1687 applyEnterAnimationLocked();
1688
Craig Mautnerde6198e2012-04-19 09:59:31 -07001689 // Force the show in the next prepareSurfaceLocked() call.
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001690 mLastAlpha = -1;
Craig Mautneref25d7a2012-05-15 23:01:47 -07001691 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM)
1692 Slog.v(TAG, "performShowLocked: mDrawState=HAS_DRAWN in " + this);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001693 mDrawState = HAS_DRAWN;
Craig Mautner96868332012-12-04 14:29:11 -08001694 mService.scheduleAnimationLocked();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001695
1696 int i = mWin.mChildWindows.size();
1697 while (i > 0) {
1698 i--;
1699 WindowState c = mWin.mChildWindows.get(i);
1700 if (c.mAttachedHidden) {
1701 c.mAttachedHidden = false;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001702 if (c.mWinAnimator.mSurfaceControl != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001703 c.mWinAnimator.performShowLocked();
1704 // It hadn't been shown, which means layout not
1705 // performed on it, so now we want to make sure to
1706 // do a layout. If called from within the transaction
1707 // loop, this will cause it to restart with a new
1708 // layout.
Craig Mautnerdf88d732014-01-27 09:21:32 -08001709 final DisplayContent displayContent = c.getDisplayContent();
1710 if (displayContent != null) {
1711 displayContent.layoutNeeded = true;
1712 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001713 }
1714 }
1715 }
1716
1717 if (mWin.mAttrs.type != TYPE_APPLICATION_STARTING
1718 && mWin.mAppToken != null) {
1719 mWin.mAppToken.firstWindowDrawn = true;
1720
1721 if (mWin.mAppToken.startingData != null) {
1722 if (WindowManagerService.DEBUG_STARTING_WINDOW ||
Craig Mautnerd87946b2012-03-29 18:00:19 -07001723 WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001724 "Finish starting " + mWin.mToken
1725 + ": first real window is shown, no animation");
1726 // If this initial window is animating, stop it -- we
1727 // will do an animation to reveal it from behind the
1728 // starting window, so there is no need for it to also
1729 // be doing its own stuff.
Craig Mautner4d7349b2012-04-20 14:52:47 -07001730 clearAnimation();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001731 mService.mFinishedStarting.add(mWin.mAppToken);
1732 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
1733 }
1734 mWin.mAppToken.updateReportedVisibilityLocked();
1735 }
1736
1737 return true;
1738 }
1739
1740 return false;
1741 }
1742
1743 /**
1744 * Have the surface flinger show a surface, robustly dealing with
1745 * error conditions. In particular, if there is not enough memory
1746 * to show the surface, then we will try to get rid of other surfaces
1747 * in order to succeed.
1748 *
1749 * @return Returns true if the surface was successfully shown.
1750 */
1751 boolean showSurfaceRobustlyLocked() {
1752 try {
Mathias Agopian29479eb2013-02-14 14:36:04 -08001753 if (mSurfaceControl != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001754 mSurfaceShown = true;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001755 mSurfaceControl.show();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001756 if (mWin.mTurnOnScreen) {
1757 if (DEBUG_VISIBILITY) Slog.v(TAG,
1758 "Show surface turning screen on: " + mWin);
1759 mWin.mTurnOnScreen = false;
Craig Mautner7d8df392012-04-06 15:26:23 -07001760 mAnimator.mBulkUpdateParams |= SET_TURN_ON_SCREEN;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001761 }
1762 }
1763 return true;
1764 } catch (RuntimeException e) {
Mathias Agopian29479eb2013-02-14 14:36:04 -08001765 Slog.w(TAG, "Failure showing surface " + mSurfaceControl + " in " + mWin, e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001766 }
1767
1768 mService.reclaimSomeSurfaceMemoryLocked(this, "show", true);
1769
1770 return false;
1771 }
1772
1773 void applyEnterAnimationLocked() {
1774 final int transit;
1775 if (mEnterAnimationPending) {
1776 mEnterAnimationPending = false;
1777 transit = WindowManagerPolicy.TRANSIT_ENTER;
1778 } else {
1779 transit = WindowManagerPolicy.TRANSIT_SHOW;
1780 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001781 applyAnimationLocked(transit, true);
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001782 //TODO (multidisplay): Magnification is supported only for the default display.
Svetoslav8e3feb12014-02-24 13:46:47 -08001783 if (mService.mAccessibilityController != null
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001784 && mWin.getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslav8e3feb12014-02-24 13:46:47 -08001785 mService.mAccessibilityController.onWindowTransitionLocked(mWin, transit);
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -07001786 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001787 }
1788
1789 /**
1790 * Choose the correct animation and set it to the passed WindowState.
Craig Mautner4b71aa12012-12-27 17:20:01 -08001791 * @param transit If AppTransition.TRANSIT_PREVIEW_DONE and the app window has been drawn
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001792 * then the animation will be app_starting_exit. Any other value loads the animation from
1793 * the switch statement below.
1794 * @param isEntrance The animation type the last time this was called. Used to keep from
1795 * loading the same animation twice.
1796 * @return true if an animation has been loaded.
1797 */
1798 boolean applyAnimationLocked(int transit, boolean isEntrance) {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001799 if ((mLocalAnimating && mAnimationIsEntrance == isEntrance)
1800 || mKeyguardGoingAwayAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001801 // If we are trying to apply an animation, but already running
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001802 // an animation of the same type, then just leave that one alone.
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001803
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001804 // If we are in a keyguard exit animation, and the window should animate away, modify
1805 // keyguard exit animation such that it also fades out.
1806 if (mAnimation != null && mKeyguardGoingAwayAnimation
1807 && transit == WindowManagerPolicy.TRANSIT_PREVIEW_DONE) {
1808 applyFadeoutDuringKeyguardExitAnimation();
1809 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001810 return true;
1811 }
1812
1813 // Only apply an animation if the display isn't frozen. If it is
1814 // frozen, there is no reason to animate and it can cause strange
1815 // artifacts when we unfreeze the display if some different animation
1816 // is running.
1817 if (mService.okToDisplay()) {
1818 int anim = mPolicy.selectAnimationLw(mWin, transit);
1819 int attr = -1;
1820 Animation a = null;
1821 if (anim != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001822 a = anim != -1 ? AnimationUtils.loadAnimation(mContext, anim) : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001823 } else {
1824 switch (transit) {
1825 case WindowManagerPolicy.TRANSIT_ENTER:
1826 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
1827 break;
1828 case WindowManagerPolicy.TRANSIT_EXIT:
1829 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
1830 break;
1831 case WindowManagerPolicy.TRANSIT_SHOW:
1832 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
1833 break;
1834 case WindowManagerPolicy.TRANSIT_HIDE:
1835 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
1836 break;
1837 }
1838 if (attr >= 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001839 a = mService.mAppTransition.loadAnimationAttr(mWin.mAttrs, attr);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001840 }
1841 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001842 if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001843 "applyAnimation: win=" + this
1844 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
Craig Mautner4d7349b2012-04-20 14:52:47 -07001845 + " a=" + a
Craig Mautner8863cca2012-09-18 15:04:34 -07001846 + " transit=" + transit
Craig Mautner83339b42012-05-01 22:13:23 -07001847 + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001848 if (a != null) {
1849 if (WindowManagerService.DEBUG_ANIM) {
1850 RuntimeException e = null;
1851 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
1852 e = new RuntimeException();
1853 e.fillInStackTrace();
1854 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001855 Slog.v(TAG, "Loaded animation " + a + " for " + this, e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001856 }
1857 setAnimation(a);
1858 mAnimationIsEntrance = isEntrance;
1859 }
1860 } else {
1861 clearAnimation();
1862 }
1863
1864 return mAnimation != null;
1865 }
1866
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001867 private void applyFadeoutDuringKeyguardExitAnimation() {
1868 long startTime = mAnimation.getStartTime();
1869 long duration = mAnimation.getDuration();
1870 long elapsed = mLastAnimationTime - startTime;
1871 long fadeDuration = duration - elapsed;
1872 if (fadeDuration <= 0) {
1873 // Never mind, this would be no visible animation, so abort the animation change.
1874 return;
1875 }
1876 AnimationSet newAnimation = new AnimationSet(false /* shareInterpolator */);
1877 newAnimation.setDuration(duration);
1878 newAnimation.setStartTime(startTime);
1879 newAnimation.addAnimation(mAnimation);
1880 Animation fadeOut = AnimationUtils.loadAnimation(
1881 mContext, com.android.internal.R.anim.app_starting_exit);
1882 fadeOut.setDuration(fadeDuration);
1883 fadeOut.setStartOffset(elapsed);
1884 newAnimation.addAnimation(fadeOut);
1885 newAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(), mAnimDw, mAnimDh);
1886 mAnimation = newAnimation;
1887 }
1888
Craig Mautnera2c77052012-03-26 12:14:43 -07001889 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1890 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
1891 || mAnimation != null) {
1892 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
1893 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
1894 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
1895 pw.print(" mAnimation="); pw.println(mAnimation);
1896 }
1897 if (mHasTransformation || mHasLocalTransformation) {
1898 pw.print(prefix); pw.print("XForm: has=");
1899 pw.print(mHasTransformation);
1900 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
1901 pw.print(" "); mTransformation.printShortString(pw);
1902 pw.println();
1903 }
Mathias Agopian29479eb2013-02-14 14:36:04 -08001904 if (mSurfaceControl != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001905 if (dumpAll) {
Mathias Agopian29479eb2013-02-14 14:36:04 -08001906 pw.print(prefix); pw.print("mSurface="); pw.println(mSurfaceControl);
Craig Mautner6fbda632012-07-03 09:26:39 -07001907 pw.print(prefix); pw.print("mDrawState=");
Craig Mautner276a6eb2014-11-04 15:32:57 -08001908 pw.print(drawStateToString());
Craig Mautner749a7bb2012-04-02 13:49:53 -07001909 pw.print(" mLastHidden="); pw.println(mLastHidden);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001910 }
1911 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
1912 pw.print(" layer="); pw.print(mSurfaceLayer);
1913 pw.print(" alpha="); pw.print(mSurfaceAlpha);
1914 pw.print(" rect=("); pw.print(mSurfaceX);
1915 pw.print(","); pw.print(mSurfaceY);
1916 pw.print(") "); pw.print(mSurfaceW);
1917 pw.print(" x "); pw.println(mSurfaceH);
1918 }
1919 if (mPendingDestroySurface != null) {
1920 pw.print(prefix); pw.print("mPendingDestroySurface=");
1921 pw.println(mPendingDestroySurface);
1922 }
1923 if (mSurfaceResized || mSurfaceDestroyDeferred) {
1924 pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized);
1925 pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred);
1926 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001927 if (mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND) {
1928 pw.print(prefix); pw.print("mUniverseTransform=");
1929 mUniverseTransform.printShortString(pw);
1930 pw.println();
1931 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001932 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
1933 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
1934 pw.print(" mAlpha="); pw.print(mAlpha);
1935 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
1936 }
1937 if (mHaveMatrix || mWin.mGlobalScale != 1) {
1938 pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale);
1939 pw.print(" mDsDx="); pw.print(mDsDx);
1940 pw.print(" mDtDx="); pw.print(mDtDx);
1941 pw.print(" mDsDy="); pw.print(mDsDy);
1942 pw.print(" mDtDy="); pw.println(mDtDy);
1943 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001944 }
1945
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001946 @Override
1947 public String toString() {
Dianne Hackborn529e7442012-11-01 14:22:28 -07001948 StringBuffer sb = new StringBuffer("WindowStateAnimator{");
1949 sb.append(Integer.toHexString(System.identityHashCode(this)));
1950 sb.append(' ');
1951 sb.append(mWin.mAttrs.getTitle());
1952 sb.append('}');
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001953 return sb.toString();
1954 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001955}