blob: 1e103f0573e06fad433b8010d8be441649257829 [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
Filip Gruszczynski69cbc352015-11-11 13:46:04 -080019import static android.view.Display.DEFAULT_DISPLAY;
Wale Ogunwalee7bf46b2015-09-30 09:19:28 -070020import static android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -080021import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070022import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +010023import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
24import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
Wale Ogunwale2728bf42016-03-03 11:03:26 -080025import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080026import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
27import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
28import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
29import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
30import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
31import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE;
32import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
33import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -080034import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_CROP;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080035import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
36import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
37import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
38import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
39import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang97782b42015-10-07 16:01:23 -070040import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -080041import static com.android.server.wm.WindowManagerService.localLOGV;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080042import static com.android.server.wm.WindowManagerService.logWithStack;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070043import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
44import static com.android.server.wm.WindowSurfacePlacer.SET_TURN_ON_SCREEN;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070045
Craig Mautnerc2f9be02012-03-27 17:32:29 -070046import android.content.Context;
47import android.graphics.Matrix;
48import android.graphics.PixelFormat;
Craig Mautner7358fbf2012-04-12 21:06:33 -070049import android.graphics.Point;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070050import android.graphics.Rect;
Craig Mautner48ba1e72012-04-02 13:18:16 -070051import android.graphics.Region;
Craig Mautnera51a9562012-04-17 17:05:26 -070052import android.os.Debug;
Craig Mautner9c795042014-10-28 19:59:59 -070053import android.os.RemoteException;
Craig Mautnera2c77052012-03-26 12:14:43 -070054import android.util.Slog;
Craig Mautner59c00972012-07-30 12:10:24 -070055import android.view.DisplayInfo;
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -070056import android.view.MagnificationSpec;
Igor Murashkina86ab6402013-08-30 12:58:36 -070057import android.view.Surface.OutOfResourcesException;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080058import android.view.SurfaceControl;
Craig Mautnera2c77052012-03-26 12:14:43 -070059import android.view.WindowManager;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070060import android.view.WindowManager.LayoutParams;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -080061import android.view.WindowManagerPolicy;
Craig Mautnera2c77052012-03-26 12:14:43 -070062import android.view.animation.Animation;
Jorim Jaggif8d77da2014-11-11 16:59:12 +010063import android.view.animation.AnimationSet;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070064import android.view.animation.AnimationUtils;
Craig Mautnera2c77052012-03-26 12:14:43 -070065import android.view.animation.Transformation;
66
67import com.android.server.wm.WindowManagerService.H;
68
69import java.io.PrintWriter;
70
71/**
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 {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080075 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowStateAnimator" : TAG_WM;
Chong Zhang97782b42015-10-07 16:01:23 -070076 static final int WINDOW_FREEZE_LAYER = TYPE_LAYER_MULTIPLIER * 200;
Craig Mautnera2c77052012-03-26 12:14:43 -070077
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010078 /**
79 * Mode how the window gets clipped by the stack bounds during an animation: The clipping should
80 * be applied after applying the animation transformation, i.e. the stack bounds don't move
81 * during the animation.
82 */
83 static final int STACK_CLIP_AFTER_ANIM = 0;
84
85 /**
86 * Mode how the window gets clipped by the stack bounds: The clipping should be applied before
87 * applying the animation transformation, i.e. the stack bounds move with the window.
88 */
89 static final int STACK_CLIP_BEFORE_ANIM = 1;
90
91 /**
92 * Mode how window gets clipped by the stack bounds during an animation: Don't clip the window
93 * by the stack bounds.
94 */
95 static final int STACK_CLIP_NONE = 2;
96
Craig Mautner918b53b2012-07-09 14:15:54 -070097 // Unchanging local convenience fields.
Craig Mautnera2c77052012-03-26 12:14:43 -070098 final WindowManagerService mService;
99 final WindowState mWin;
Craig Mautner322e4032012-07-13 13:35:20 -0700100 final WindowStateAnimator mAttachedWinAnimator;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700101 final WindowAnimator mAnimator;
Craig Mautner8863cca2012-09-18 15:04:34 -0700102 AppWindowAnimator mAppAnimator;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700103 final Session mSession;
104 final WindowManagerPolicy mPolicy;
105 final Context mContext;
Craig Mautner918b53b2012-07-09 14:15:54 -0700106 final boolean mIsWallpaper;
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700107 final WallpaperController mWallpaperControllerLocked;
Craig Mautnera2c77052012-03-26 12:14:43 -0700108
109 // Currently running animation.
110 boolean mAnimating;
111 boolean mLocalAnimating;
112 Animation mAnimation;
113 boolean mAnimationIsEntrance;
114 boolean mHasTransformation;
115 boolean mHasLocalTransformation;
116 final Transformation mTransformation = new Transformation();
117 boolean mWasAnimating; // Were we animating going into the most recent animation step?
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700118 int mAnimLayer;
119 int mLastLayer;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100120 long mAnimationStartTime;
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100121 long mLastAnimationTime;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100122 int mStackClip = STACK_CLIP_BEFORE_ANIM;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700123
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700124 /**
125 * Set when we have changed the size of the surface, to know that
126 * we must tell them application to resize (and thus redraw itself).
127 */
128 boolean mSurfaceResized;
Chong Zhang5b2f1992015-11-13 15:40:36 -0800129 /**
130 * Whether we should inform the client on next relayoutWindow that
131 * the surface has been resized since last time.
132 */
133 boolean mReportSurfaceResized;
Robert Carre6a83512015-11-03 16:09:21 -0800134 WindowSurfaceController mSurfaceController;
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800135 private WindowSurfaceController mPendingDestroySurface;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700136
137 /**
138 * Set if the client has asked that the destroy of its surface be delayed
139 * until it explicitly says it is okay.
140 */
141 boolean mSurfaceDestroyDeferred;
142
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800143 private boolean mDestroyPreservedSurfaceUponRedraw;
Craig Mautner7d8df392012-04-06 15:26:23 -0700144 float mShownAlpha = 0;
145 float mAlpha = 0;
146 float mLastAlpha = 0;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700147
Winson Chung399f6202014-03-19 10:47:20 -0700148 boolean mHasClipRect;
149 Rect mClipRect = new Rect();
150 Rect mTmpClipRect = new Rect();
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100151 Rect mTmpFinalClipRect = new Rect();
Winson Chung399f6202014-03-19 10:47:20 -0700152 Rect mLastClipRect = new Rect();
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100153 Rect mLastFinalClipRect = new Rect();
Filip Gruszczynski4b8eea72015-09-14 18:16:19 -0700154 Rect mTmpStackBounds = new Rect();
Winson Chung399f6202014-03-19 10:47:20 -0700155
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -0800156 /**
157 * This is rectangle of the window's surface that is not covered by
158 * system decorations.
159 */
160 private final Rect mSystemDecorRect = new Rect();
161 private final Rect mLastSystemDecorRect = new Rect();
162
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800163 // Used to save animation distances between the time they are calculated and when they are used.
164 private int mAnimDx;
165 private int mAnimDy;
Jorim Jaggic5af4f82015-07-01 17:16:27 -0700166
167 /** Is the next animation to be started a window move animation? */
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800168 private boolean mAnimateMove = false;
Jorim Jaggic5af4f82015-07-01 17:16:27 -0700169
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700170 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
171 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
172
173 boolean mHaveMatrix;
174
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700175 // Set to true if, when the window gets displayed, it should perform
176 // an enter animation.
177 boolean mEnterAnimationPending;
Craig Mautnera2c77052012-03-26 12:14:43 -0700178
Craig Mautner9c795042014-10-28 19:59:59 -0700179 /** Used to indicate that this window is undergoing an enter animation. Used for system
180 * windows to make the callback to View.dispatchOnWindowShownCallback(). Set when the
181 * window is first added or shown, cleared when the callback has been made. */
182 boolean mEnteringAnimation;
183
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100184 boolean mKeyguardGoingAwayAnimation;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800185 boolean mKeyguardGoingAwayWithWallpaper;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200186
John Reck80181b92015-05-19 11:09:32 -0700187 /** The pixel format of the underlying SurfaceControl */
188 int mSurfaceFormat;
189
Craig Mautner749a7bb2012-04-02 13:49:53 -0700190 /** This is set when there is no Surface */
191 static final int NO_SURFACE = 0;
192 /** This is set after the Surface has been created but before the window has been drawn. During
193 * this time the surface is hidden. */
194 static final int DRAW_PENDING = 1;
195 /** This is set after the window has finished drawing for the first time but before its surface
196 * is shown. The surface will be displayed when the next layout is run. */
197 static final int COMMIT_DRAW_PENDING = 2;
198 /** This is set during the time after the window's drawing has been committed, and before its
199 * surface is actually shown. It is used to delay showing the surface until all windows in a
200 * token are ready to be shown. */
201 static final int READY_TO_SHOW = 3;
202 /** Set when the window has been shown in the screen the first time. */
203 static final int HAS_DRAWN = 4;
Adrian Roos3eeb4e62014-05-19 12:43:26 +0200204
Craig Mautner276a6eb2014-11-04 15:32:57 -0800205 String drawStateToString() {
206 switch (mDrawState) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700207 case NO_SURFACE: return "NO_SURFACE";
208 case DRAW_PENDING: return "DRAW_PENDING";
209 case COMMIT_DRAW_PENDING: return "COMMIT_DRAW_PENDING";
210 case READY_TO_SHOW: return "READY_TO_SHOW";
211 case HAS_DRAWN: return "HAS_DRAWN";
Craig Mautner276a6eb2014-11-04 15:32:57 -0800212 default: return Integer.toString(mDrawState);
Craig Mautner6fbda632012-07-03 09:26:39 -0700213 }
214 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700215 int mDrawState;
Craig Mautnera608b882012-03-30 13:03:49 -0700216
Craig Mautner749a7bb2012-04-02 13:49:53 -0700217 /** Was this window last hidden? */
218 boolean mLastHidden;
Craig Mautnera608b882012-03-30 13:03:49 -0700219
Craig Mautnerbec53f72012-04-05 11:49:05 -0700220 int mAttrType;
221
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800222 private final Rect mTmpSize = new Rect();
223
Craig Mautnerc431e892015-02-11 13:14:26 -0800224 WindowStateAnimator(final WindowState win) {
Craig Mautner918b53b2012-07-09 14:15:54 -0700225 final WindowManagerService service = win.mService;
226
Craig Mautnera2c77052012-03-26 12:14:43 -0700227 mService = service;
Craig Mautner918b53b2012-07-09 14:15:54 -0700228 mAnimator = service.mAnimator;
229 mPolicy = service.mPolicy;
230 mContext = service.mContext;
Craig Mautnerd3849f52014-03-27 13:19:29 -0700231 final DisplayContent displayContent = win.getDisplayContent();
232 if (displayContent != null) {
233 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800234 mAnimDx = displayInfo.appWidth;
235 mAnimDy = displayInfo.appHeight;
Craig Mautnerd3849f52014-03-27 13:19:29 -0700236 } else {
237 Slog.w(TAG, "WindowStateAnimator ctor: Display has been removed");
238 // This is checked on return and dealt with.
239 }
Craig Mautner918b53b2012-07-09 14:15:54 -0700240
241 mWin = win;
Craig Mautner322e4032012-07-13 13:35:20 -0700242 mAttachedWinAnimator = win.mAttachedWindow == null
243 ? null : win.mAttachedWindow.mWinAnimator;
244 mAppAnimator = win.mAppToken == null ? null : win.mAppToken.mAppAnimator;
Craig Mautner918b53b2012-07-09 14:15:54 -0700245 mSession = win.mSession;
Craig Mautner918b53b2012-07-09 14:15:54 -0700246 mAttrType = win.mAttrs.type;
247 mIsWallpaper = win.mIsWallpaper;
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700248 mWallpaperControllerLocked = mService.mWallpaperControllerLocked;
Craig Mautnera2c77052012-03-26 12:14:43 -0700249 }
250
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100251 public void setAnimation(Animation anim, long startTime, int stackClip) {
Craig Mautnerbec53f72012-04-05 11:49:05 -0700252 if (localLOGV) Slog.v(TAG, "Setting animation in " + this + ": " + anim);
Craig Mautnera2c77052012-03-26 12:14:43 -0700253 mAnimating = false;
254 mLocalAnimating = false;
255 mAnimation = anim;
256 mAnimation.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION);
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700257 mAnimation.scaleCurrentDuration(mService.getWindowAnimationScaleLocked());
Craig Mautnera2c77052012-03-26 12:14:43 -0700258 // Start out animation gone if window is gone, or visible if window is visible.
259 mTransformation.clear();
Craig Mautner749a7bb2012-04-02 13:49:53 -0700260 mTransformation.setAlpha(mLastHidden ? 0 : 1);
Craig Mautnera2c77052012-03-26 12:14:43 -0700261 mHasLocalTransformation = true;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100262 mAnimationStartTime = startTime;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100263 mStackClip = stackClip;
264 }
265
266 public void setAnimation(Animation anim, int stackClip) {
267 setAnimation(anim, -1, stackClip);
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100268 }
269
270 public void setAnimation(Animation anim) {
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100271 setAnimation(anim, -1, STACK_CLIP_AFTER_ANIM);
Craig Mautnera2c77052012-03-26 12:14:43 -0700272 }
273
274 public void clearAnimation() {
275 if (mAnimation != null) {
276 mAnimating = true;
277 mLocalAnimating = false;
278 mAnimation.cancel();
279 mAnimation = null;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100280 mKeyguardGoingAwayAnimation = false;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800281 mKeyguardGoingAwayWithWallpaper = false;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100282 mStackClip = STACK_CLIP_BEFORE_ANIM;
Craig Mautnera2c77052012-03-26 12:14:43 -0700283 }
284 }
285
286 /** Is the window or its container currently animating? */
287 boolean isAnimating() {
Craig Mautnera2c77052012-03-26 12:14:43 -0700288 return mAnimation != null
Craig Mautner322e4032012-07-13 13:35:20 -0700289 || (mAttachedWinAnimator != null && mAttachedWinAnimator.mAnimation != null)
Jorim Jaggi37875612015-02-19 21:05:31 +0100290 || (mAppAnimator != null && mAppAnimator.isAnimating());
Craig Mautnera2c77052012-03-26 12:14:43 -0700291 }
292
Craig Mautner0afddcb2012-05-08 15:38:00 -0700293 /** Is the window animating the DummyAnimation? */
294 boolean isDummyAnimation() {
Craig Mautner322e4032012-07-13 13:35:20 -0700295 return mAppAnimator != null
296 && mAppAnimator.animation == AppWindowAnimator.sDummyAnimation;
Craig Mautner0afddcb2012-05-08 15:38:00 -0700297 }
298
Stefan Kuhne7dcf08c2015-06-05 16:25:10 -0700299 /** Is this window currently set to animate or currently animating? */
Craig Mautnera2c77052012-03-26 12:14:43 -0700300 boolean isWindowAnimating() {
301 return mAnimation != null;
302 }
303
Craig Mautnera2c77052012-03-26 12:14:43 -0700304 void cancelExitAnimationForNextAnimationLocked() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800305 if (DEBUG_ANIM) Slog.d(TAG,
306 "cancelExitAnimationForNextAnimationLocked: " + mWin);
307
Craig Mautnera2c77052012-03-26 12:14:43 -0700308 if (mAnimation != null) {
309 mAnimation.cancel();
310 mAnimation = null;
Craig Mautner4d7349b2012-04-20 14:52:47 -0700311 mLocalAnimating = false;
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800312 mWin.destroyOrSaveSurface();
Craig Mautnera2c77052012-03-26 12:14:43 -0700313 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700314 }
315
316 private boolean stepAnimation(long currentTime) {
317 if ((mAnimation == null) || !mLocalAnimating) {
318 return false;
319 }
320 mTransformation.clear();
321 final boolean more = mAnimation.getTransformation(currentTime, mTransformation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700322 if (false && DEBUG_ANIM) Slog.v(TAG, "Stepped animation in " + this + ": more=" + more
323 + ", xform=" + mTransformation);
Craig Mautnera2c77052012-03-26 12:14:43 -0700324 return more;
325 }
326
327 // This must be called while inside a transaction. Returns true if
328 // there is more animation to run.
329 boolean stepAnimationLocked(long currentTime) {
Chet Haase9c450412015-10-01 13:25:58 -0700330 // Save the animation state as it was before this step so WindowManagerService can tell if
331 // we just started or just stopped animating by comparing mWasAnimating with isAnimating().
332 mWasAnimating = mAnimating;
Craig Mautnerdf88d732014-01-27 09:21:32 -0800333 final DisplayContent displayContent = mWin.getDisplayContent();
334 if (displayContent != null && mService.okToDisplay()) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700335 // We will run animations as long as the display isn't frozen.
336
337 if (mWin.isDrawnLw() && mAnimation != null) {
338 mHasTransformation = true;
339 mHasLocalTransformation = true;
340 if (!mLocalAnimating) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700341 if (DEBUG_ANIM) Slog.v(
342 TAG, "Starting animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700343 " @ " + currentTime + ": ww=" + mWin.mFrame.width() +
344 " wh=" + mWin.mFrame.height() +
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800345 " dx=" + mAnimDx + " dy=" + mAnimDy +
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700346 " scale=" + mService.getWindowAnimationScaleLocked());
Craig Mautnerdf88d732014-01-27 09:21:32 -0800347 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
tiger_huangb7f3f922015-04-27 20:36:46 +0800348 if (mAnimateMove) {
349 mAnimateMove = false;
350 mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(),
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800351 mAnimDx, mAnimDy);
tiger_huangb7f3f922015-04-27 20:36:46 +0800352 } else {
353 mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(),
354 displayInfo.appWidth, displayInfo.appHeight);
355 }
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800356 mAnimDx = displayInfo.appWidth;
357 mAnimDy = displayInfo.appHeight;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100358 mAnimation.setStartTime(mAnimationStartTime != -1
359 ? mAnimationStartTime
360 : currentTime);
Craig Mautnera2c77052012-03-26 12:14:43 -0700361 mLocalAnimating = true;
362 mAnimating = true;
363 }
364 if ((mAnimation != null) && mLocalAnimating) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100365 mLastAnimationTime = currentTime;
Craig Mautnera2c77052012-03-26 12:14:43 -0700366 if (stepAnimation(currentTime)) {
367 return true;
368 }
369 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700370 if (DEBUG_ANIM) Slog.v(
371 TAG, "Finished animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700372 " @ " + currentTime);
373 //WindowManagerService.this.dump();
374 }
375 mHasLocalTransformation = false;
Craig Mautner322e4032012-07-13 13:35:20 -0700376 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppAnimator != null
377 && mAppAnimator.animation != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700378 // When our app token is animating, we kind-of pretend like
379 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
380 // part of this check means that we will only do this if
381 // our window is not currently exiting, or it is not
382 // locally animating itself. The idea being that one that
383 // is exiting and doing a local animation should be removed
384 // once that animation is done.
385 mAnimating = true;
386 mHasTransformation = true;
387 mTransformation.clear();
388 return false;
389 } else if (mHasTransformation) {
390 // Little trick to get through the path below to act like
391 // we have finished an animation.
392 mAnimating = true;
393 } else if (isAnimating()) {
394 mAnimating = true;
395 }
396 } else if (mAnimation != null) {
397 // If the display is frozen, and there is a pending animation,
398 // clear it and make sure we run the cleanup code.
399 mAnimating = true;
Craig Mautnera2c77052012-03-26 12:14:43 -0700400 }
401
402 if (!mAnimating && !mLocalAnimating) {
403 return false;
404 }
405
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700406 // Done animating, clean up.
407 if (DEBUG_ANIM) Slog.v(
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800408 TAG, "Animation done in " + this + ": exiting=" + mWin.mAnimatingExit
Craig Mautnera2c77052012-03-26 12:14:43 -0700409 + ", reportedVisible="
410 + (mWin.mAppToken != null ? mWin.mAppToken.reportedVisible : false));
411
412 mAnimating = false;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100413 mKeyguardGoingAwayAnimation = false;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800414 mKeyguardGoingAwayWithWallpaper = false;
Craig Mautnera2c77052012-03-26 12:14:43 -0700415 mLocalAnimating = false;
416 if (mAnimation != null) {
417 mAnimation.cancel();
418 mAnimation = null;
419 }
Craig Mautnere7ae2502012-03-26 17:11:19 -0700420 if (mAnimator.mWindowDetachedWallpaper == mWin) {
421 mAnimator.mWindowDetachedWallpaper = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700422 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -0800423 mAnimLayer = mWin.mLayer
424 + mService.mLayersController.getSpecialWindowAnimLayerAdjustment(mWin);
Filip Gruszczynski14b4e572015-11-03 15:53:55 -0800425 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this + " anim layer: " + mAnimLayer);
Craig Mautnera2c77052012-03-26 12:14:43 -0700426 mHasTransformation = false;
427 mHasLocalTransformation = false;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100428 mStackClip = STACK_CLIP_BEFORE_ANIM;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -0800429 mWin.checkPolicyVisibilityChange();
Craig Mautnera2c77052012-03-26 12:14:43 -0700430 mTransformation.clear();
Craig Mautner749a7bb2012-04-02 13:49:53 -0700431 if (mDrawState == HAS_DRAWN
Craig Mautnera2c77052012-03-26 12:14:43 -0700432 && mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
433 && mWin.mAppToken != null
434 && mWin.mAppToken.firstWindowDrawn
435 && mWin.mAppToken.startingData != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700436 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
Craig Mautnera2c77052012-03-26 12:14:43 -0700437 + mWin.mToken + ": first real window done animating");
438 mService.mFinishedStarting.add(mWin.mAppToken);
439 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
Craig Mautner81defc72013-10-29 11:10:42 -0700440 } else if (mAttrType == LayoutParams.TYPE_STATUS_BAR && mWin.mPolicyVisibility) {
441 // Upon completion of a not-visible to visible status bar animation a relayout is
442 // required.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800443 if (displayContent != null) {
444 displayContent.layoutNeeded = true;
445 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700446 }
447
448 finishExit();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800449 final int displayId = mWin.getDisplayId();
Craig Mautner76a71652012-09-03 23:23:58 -0700450 mAnimator.setPendingLayoutChanges(displayId, WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800451 if (DEBUG_LAYOUT_REPEATS)
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700452 mService.mWindowPlacerLocked.debugLayoutRepeats(
453 "WindowStateAnimator", mAnimator.getPendingLayoutChanges(displayId));
Craig Mautnera2c77052012-03-26 12:14:43 -0700454
455 if (mWin.mAppToken != null) {
456 mWin.mAppToken.updateReportedVisibilityLocked();
457 }
458
459 return false;
460 }
461
462 void finishExit() {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800463 if (DEBUG_ANIM) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700464 TAG, "finishExit in " + this
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800465 + ": exiting=" + mWin.mAnimatingExit
Craig Mautnera2c77052012-03-26 12:14:43 -0700466 + " remove=" + mWin.mRemoveOnExit
467 + " windowAnimating=" + isWindowAnimating());
468
Wale Ogunwale33fde7d2016-03-05 22:38:51 -0800469 if (!mWin.mChildWindows.isEmpty()) {
470 // Copying to a different list as multiple children can be removed.
471 final WindowList childWindows = new WindowList(mWin.mChildWindows);
472 for (int i = childWindows.size() - 1; i >= 0; i--) {
473 childWindows.get(i).mWinAnimator.finishExit();
474 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700475 }
476
Filip Gruszczynski57f76f12015-11-04 16:10:54 -0800477 if (mEnteringAnimation) {
478 mEnteringAnimation = false;
479 mService.requestTraversal();
480 // System windows don't have an activity and an app token as a result, but need a way
481 // to be informed about their entrance animation end.
482 if (mWin.mAppToken == null) {
483 try {
484 mWin.mClient.dispatchWindowShown();
485 } catch (RemoteException e) {
486 }
Craig Mautner9c795042014-10-28 19:59:59 -0700487 }
488 }
489
Svetoslav75b55d02014-12-03 16:26:35 -0800490 if (!isWindowAnimating()) {
491 //TODO (multidisplay): Accessibility is supported only for the default display.
492 if (mService.mAccessibilityController != null
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800493 && mWin.getDisplayId() == DEFAULT_DISPLAY) {
Svetoslav75b55d02014-12-03 16:26:35 -0800494 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
495 }
496 }
497
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800498 if (!mWin.mAnimatingExit) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700499 return;
500 }
501
502 if (isWindowAnimating()) {
503 return;
504 }
505
Wale Ogunwale2728bf42016-03-03 11:03:26 -0800506 if (WindowManagerService.localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
507 "Exit animation finished in " + this + ": remove=" + mWin.mRemoveOnExit);
Robert Carre12aece2016-02-02 22:43:27 -0800508
509
510 mWin.mDestroying = true;
511
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800512 final boolean hasSurface = hasSurface();
513 if (hasSurface) {
514 hide("finishExit");
515 }
516
Robert Carre12aece2016-02-02 22:43:27 -0800517 // If we have an app token, we ask it to destroy the surface for us,
518 // so that it can take care to ensure the activity has actually stopped
519 // and the surface is not still in use. Otherwise we add the service to
520 // mDestroySurface and allow it to be processed in our next transaction.
521 if (mWin.mAppToken != null) {
Robert Carre12aece2016-02-02 22:43:27 -0800522 mWin.mAppToken.destroySurfaces();
523 } else {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800524 if (hasSurface) {
Robert Carre12aece2016-02-02 22:43:27 -0800525 mService.mDestroySurface.add(mWin);
Robert Carre12aece2016-02-02 22:43:27 -0800526 }
Robert Carre12aece2016-02-02 22:43:27 -0800527 if (mWin.mRemoveOnExit) {
528 mService.mPendingRemove.add(mWin);
529 mWin.mRemoveOnExit = false;
530 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700531 }
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800532 mWin.mAnimatingExit = false;
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700533 mWallpaperControllerLocked.hideWallpapers(mWin);
Craig Mautner0afddcb2012-05-08 15:38:00 -0700534 }
535
Filip Gruszczynski63a35e22015-11-05 15:38:59 -0800536 void hide(String reason) {
Craig Mautner0afddcb2012-05-08 15:38:00 -0700537 if (!mLastHidden) {
538 //dump();
539 mLastHidden = true;
Wale Ogunwalef9e09782015-11-09 12:42:37 -0800540 if (mSurfaceController != null) {
541 mSurfaceController.hideInTransaction(reason);
542 }
Craig Mautner0afddcb2012-05-08 15:38:00 -0700543 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700544 }
545
Craig Mautnera608b882012-03-30 13:03:49 -0700546 boolean finishDrawingLocked() {
Craig Mautner42d04db2014-11-06 12:13:23 -0800547 final boolean startingWindow =
548 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
549 if (DEBUG_STARTING_WINDOW && startingWindow) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700550 Slog.v(TAG, "Finishing drawing window " + mWin + ": mDrawState="
Craig Mautner276a6eb2014-11-04 15:32:57 -0800551 + drawStateToString());
Craig Mautner6fbda632012-07-03 09:26:39 -0700552 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800553 if (mWin.mAppToken != null && mWin.mAppToken.mAnimatingWithSavedSurface) {
Chong Zhangbef461f2015-10-27 11:38:24 -0700554 // App has drawn something to its windows, we're no longer animating with
555 // the saved surfaces. If the user exits now, we only want to save again
556 // if allDrawn is true.
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800557 if (DEBUG_ANIM) Slog.d(TAG,
558 "finishDrawingLocked: mAnimatingWithSavedSurface=false " + mWin);
Chong Zhangbef461f2015-10-27 11:38:24 -0700559 mWin.mAppToken.mAnimatingWithSavedSurface = false;
560 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700561 if (mDrawState == DRAW_PENDING) {
Craig Mautneref25d7a2012-05-15 23:01:47 -0700562 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
Chong Zhang5b2f1992015-11-13 15:40:36 -0800563 Slog.v(TAG, "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING " + mWin + " in "
Robert Carre6a83512015-11-03 16:09:21 -0800564 + mSurfaceController);
Craig Mautner42d04db2014-11-06 12:13:23 -0800565 if (DEBUG_STARTING_WINDOW && startingWindow) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700566 Slog.v(TAG, "Draw state now committed in " + mWin);
567 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700568 mDrawState = COMMIT_DRAW_PENDING;
Craig Mautnera608b882012-03-30 13:03:49 -0700569 return true;
570 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700571
Craig Mautnera608b882012-03-30 13:03:49 -0700572 return false;
573 }
574
575 // This must be called while inside a transaction.
Craig Mautnerc431e892015-02-11 13:14:26 -0800576 boolean commitFinishDrawingLocked() {
Craig Mautner6fbda632012-07-03 09:26:39 -0700577 if (DEBUG_STARTING_WINDOW &&
578 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
579 Slog.i(TAG, "commitFinishDrawingLocked: " + mWin + " cur mDrawState="
Craig Mautner276a6eb2014-11-04 15:32:57 -0800580 + drawStateToString());
Craig Mautner6fbda632012-07-03 09:26:39 -0700581 }
Craig Mautner276a6eb2014-11-04 15:32:57 -0800582 if (mDrawState != COMMIT_DRAW_PENDING && mDrawState != READY_TO_SHOW) {
Craig Mautnera608b882012-03-30 13:03:49 -0700583 return false;
584 }
Craig Mautner6fbda632012-07-03 09:26:39 -0700585 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) {
Robert Carre6a83512015-11-03 16:09:21 -0800586 Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurfaceController);
Craig Mautner6fbda632012-07-03 09:26:39 -0700587 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700588 mDrawState = READY_TO_SHOW;
Chong Zhang0275e392015-09-17 10:41:44 -0700589 boolean result = false;
Craig Mautnera608b882012-03-30 13:03:49 -0700590 final AppWindowToken atoken = mWin.mAppToken;
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800591 if (atoken == null || atoken.allDrawn || mWin.mAttrs.type == TYPE_APPLICATION_STARTING) {
Chong Zhang0275e392015-09-17 10:41:44 -0700592 result = performShowLocked();
593 }
Chong Zhang97782b42015-10-07 16:01:23 -0700594 return result;
Craig Mautnera608b882012-03-30 13:03:49 -0700595 }
596
Chong Zhang97782b42015-10-07 16:01:23 -0700597 void preserveSurfaceLocked() {
598 if (mDestroyPreservedSurfaceUponRedraw) {
Chong Zhangb9b0fec2016-02-11 18:51:51 -0800599 // This could happen when switching the surface mode very fast. For example,
600 // we preserved a surface when dragResizing changed to true. Then before the
601 // preserved surface is removed, dragResizing changed to false again.
602 // In this case, we need to leave the preserved surface alone, and destroy
603 // the actual surface, so that the createSurface call could create a surface
604 // of the proper size. The preserved surface will still be removed when client
605 // finishes drawing to the new surface.
606 mSurfaceDestroyDeferred = false;
607 destroySurfaceLocked();
608 mSurfaceDestroyDeferred = true;
Chong Zhang97782b42015-10-07 16:01:23 -0700609 return;
610 }
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -0800611 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, "SET FREEZE LAYER", false);
Wale Ogunwalef9e09782015-11-09 12:42:37 -0800612 if (mSurfaceController != null) {
613 mSurfaceController.setLayer(mAnimLayer + 1);
614 }
Chong Zhang97782b42015-10-07 16:01:23 -0700615 mDestroyPreservedSurfaceUponRedraw = true;
616 mSurfaceDestroyDeferred = true;
617 destroySurfaceLocked();
618 }
619
620 void destroyPreservedSurfaceLocked() {
621 if (!mDestroyPreservedSurfaceUponRedraw) {
622 return;
623 }
624 destroyDeferredSurfaceLocked();
625 mDestroyPreservedSurfaceUponRedraw = false;
626 }
627
Robert Carre6a83512015-11-03 16:09:21 -0800628 WindowSurfaceController createSurfaceLocked() {
Alan Viveretteccb11e12014-07-08 16:04:02 -0700629 final WindowState w = mWin;
Chong Zhanga8975bd2016-01-28 17:13:47 -0800630 if (w.hasSavedSurface()) {
Chong Zhang0464a932016-02-03 11:47:16 -0800631 if (DEBUG_ANIM) Slog.i(TAG,
632 "createSurface: " + this + ": called when we had a saved surface");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800633 w.restoreSavedSurface();
634 return mSurfaceController;
Chong Zhanga8975bd2016-01-28 17:13:47 -0800635 }
636
Wale Ogunwale722ff892016-02-18 13:37:55 -0800637 if (mSurfaceController != null) {
638 return mSurfaceController;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700639 }
Wale Ogunwale722ff892016-02-18 13:37:55 -0800640
641 w.setHasSurface(false);
642
643 if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG,
644 "createSurface " + this + ": mDrawState=DRAW_PENDING");
645
646 mDrawState = DRAW_PENDING;
647 if (w.mAppToken != null) {
648 if (w.mAppToken.mAppAnimator.animation == null) {
649 w.mAppToken.allDrawn = false;
650 w.mAppToken.deferClearAllDrawn = false;
651 } else {
652 // Currently animating, persist current state of allDrawn until animation
653 // is complete.
654 w.mAppToken.deferClearAllDrawn = true;
655 }
656 }
657
658 mService.makeWindowFreezingScreenIfNeededLocked(w);
659
660 int flags = SurfaceControl.HIDDEN;
661 final WindowManager.LayoutParams attrs = w.mAttrs;
662
663 if (mService.isSecureLocked(w)) {
664 flags |= SurfaceControl.SECURE;
665 }
666
667 mTmpSize.set(w.mFrame.left + w.mXOffset, w.mFrame.top + w.mYOffset, 0, 0);
668 calculateSurfaceBounds(w, attrs);
669 final int width = mTmpSize.width();
670 final int height = mTmpSize.height();
671
672 if (DEBUG_VISIBILITY) {
673 Slog.v(TAG, "Creating surface in session "
674 + mSession.mSurfaceSession + " window " + this
675 + " w=" + width + " h=" + height
676 + " x=" + mTmpSize.left + " y=" + mTmpSize.top
677 + " format=" + attrs.format + " flags=" + flags);
678 }
679
680 // We may abort, so initialize to defaults.
681 mLastSystemDecorRect.set(0, 0, 0, 0);
682 mHasClipRect = false;
683 mClipRect.set(0, 0, 0, 0);
684 mLastClipRect.set(0, 0, 0, 0);
685
686 // Set up surface control with initial size.
687 try {
688
689 final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0;
690 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
691 if (!PixelFormat.formatHasAlpha(attrs.format)
692 // Don't make surface with surfaceInsets opaque as they display a
693 // translucent shadow.
694 && attrs.surfaceInsets.left == 0
695 && attrs.surfaceInsets.top == 0
696 && attrs.surfaceInsets.right == 0
697 && attrs.surfaceInsets.bottom == 0
698 // Don't make surface opaque when resizing to reduce the amount of
699 // artifacts shown in areas the app isn't drawing content to.
700 && !w.isDragResizing()) {
701 flags |= SurfaceControl.OPAQUE;
702 }
703
704 mSurfaceController = new WindowSurfaceController(mSession.mSurfaceSession,
705 attrs.getTitle().toString(),
706 width, height, format, flags, this);
707
708 w.setHasSurface(true);
709
710 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
711 Slog.i(TAG, " CREATE SURFACE "
712 + mSurfaceController + " IN SESSION "
713 + mSession.mSurfaceSession
714 + ": pid=" + mSession.mPid + " format="
715 + attrs.format + " flags=0x"
716 + Integer.toHexString(flags)
717 + " / " + this);
718 }
719 } catch (OutOfResourcesException e) {
720 Slog.w(TAG, "OutOfResourcesException creating surface");
721 mService.reclaimSomeSurfaceMemoryLocked(this, "create", true);
722 mDrawState = NO_SURFACE;
723 return null;
724 } catch (Exception e) {
725 Slog.e(TAG, "Exception creating surface", e);
726 mDrawState = NO_SURFACE;
727 return null;
728 }
729
730 if (WindowManagerService.localLOGV) Slog.v(TAG, "Got surface: " + mSurfaceController
731 + ", set left=" + w.mFrame.left + " top=" + w.mFrame.top
732 + ", animLayer=" + mAnimLayer);
733
734 if (SHOW_LIGHT_TRANSACTIONS) {
735 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
736 WindowManagerService.logSurface(w, "CREATE pos=("
737 + w.mFrame.left + "," + w.mFrame.top + ") ("
738 + width + "x" + height + "), layer=" + mAnimLayer + " HIDE", false);
739 }
740
741 // Start a new transaction and apply position & offset.
742 final int layerStack = w.getDisplayContent().getDisplay().getLayerStack();
Wale Ogunwale722ff892016-02-18 13:37:55 -0800743 mSurfaceController.setPositionAndLayer(mTmpSize.left, mTmpSize.top, layerStack, mAnimLayer);
744 mLastHidden = true;
745
746 if (WindowManagerService.localLOGV) Slog.v(TAG, "Created surface " + this);
Robert Carre6a83512015-11-03 16:09:21 -0800747 return mSurfaceController;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700748 }
749
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800750 private void calculateSurfaceBounds(WindowState w, LayoutParams attrs) {
751 if ((attrs.flags & FLAG_SCALED) != 0) {
752 // For a scaled surface, we always want the requested size.
753 mTmpSize.right = mTmpSize.left + w.mRequestedWidth;
754 mTmpSize.bottom = mTmpSize.top + w.mRequestedHeight;
755 } else {
756 // When we're doing a drag-resizing, request a surface that's fullscreen size,
757 // so that we don't need to reallocate during the process. This also prevents
758 // buffer drops due to size mismatch.
759 if (w.isDragResizing()) {
760 if (w.getResizeMode() == DRAG_RESIZE_MODE_FREEFORM) {
761 mTmpSize.left = 0;
762 mTmpSize.top = 0;
763 }
764 final DisplayInfo displayInfo = w.getDisplayInfo();
765 mTmpSize.right = mTmpSize.left + displayInfo.logicalWidth;
766 mTmpSize.bottom = mTmpSize.top + displayInfo.logicalHeight;
767 } else {
768 mTmpSize.right = mTmpSize.left + w.mCompatFrame.width();
769 mTmpSize.bottom = mTmpSize.top + w.mCompatFrame.height();
770 }
771 }
772
773 // Something is wrong and SurfaceFlinger will not like this, try to revert to sane values.
Filip Gruszczynskie6ed1952015-12-21 09:34:16 -0800774 // This doesn't necessarily mean that there is an error in the system. The sizes might be
775 // incorrect, because it is before the first layout or draw.
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800776 if (mTmpSize.width() < 1) {
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800777 mTmpSize.right = mTmpSize.left + 1;
778 }
779 if (mTmpSize.height() < 1) {
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800780 mTmpSize.bottom = mTmpSize.top + 1;
781 }
782
783 final int displayId = w.getDisplayId();
784 float scale = 1.0f;
785 // Magnification is supported only for the default display.
786 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
787 final MagnificationSpec spec =
788 mService.mAccessibilityController.getMagnificationSpecForWindowLocked(w);
789 if (spec != null && !spec.isNop()) {
790 scale = spec.scale;
791 }
792 }
793
794 // Adjust for surface insets.
795 mTmpSize.left -= scale * attrs.surfaceInsets.left;
796 mTmpSize.top -= scale * attrs.surfaceInsets.top;
797 mTmpSize.right += scale * (attrs.surfaceInsets.left + attrs.surfaceInsets.right);
798 mTmpSize.bottom += scale * (attrs.surfaceInsets.top + attrs.surfaceInsets.bottom);
799 }
800
Chong Zhangeb22e8e2016-01-20 19:52:22 -0800801 boolean hasSurface() {
802 return !mWin.mSurfaceSaved
803 && mSurfaceController != null && mSurfaceController.hasSurface();
804 }
805
Craig Mautner96868332012-12-04 14:29:11 -0800806 void destroySurfaceLocked() {
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700807 final AppWindowToken wtoken = mWin.mAppToken;
808 if (wtoken != null) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700809 wtoken.mAnimatingWithSavedSurface = false;
810 if (mWin == wtoken.startingWindow) {
811 wtoken.startingDisplayed = false;
812 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700813 }
814
Robert Carr13f7be9e2015-12-02 18:39:45 -0800815 mWin.mSurfaceSaved = false;
816
Wale Ogunwale722ff892016-02-18 13:37:55 -0800817 if (mSurfaceController == null) {
818 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700819 }
Wale Ogunwale722ff892016-02-18 13:37:55 -0800820
821 int i = mWin.mChildWindows.size();
822 // When destroying a surface we want to make sure child windows are hidden. If we are
823 // preserving the surface until redraw though we intend to swap it out with another surface
824 // for resizing. In this case the window always remains visible to the user and the child
825 // windows should likewise remain visible.
826 while (!mDestroyPreservedSurfaceUponRedraw && i > 0) {
827 i--;
828 WindowState c = mWin.mChildWindows.get(i);
829 c.mAttachedHidden = true;
830 }
831
832 try {
833 if (DEBUG_VISIBILITY) logWithStack(TAG, "Window " + this + " destroying surface "
834 + mSurfaceController + ", session " + mSession);
835 if (mSurfaceDestroyDeferred) {
836 if (mSurfaceController != null && mPendingDestroySurface != mSurfaceController) {
837 if (mPendingDestroySurface != null) {
838 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
839 WindowManagerService.logSurface(mWin, "DESTROY PENDING", true);
840 }
841 mPendingDestroySurface.destroyInTransaction();
842 }
843 mPendingDestroySurface = mSurfaceController;
844 }
845 } else {
846 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
847 WindowManagerService.logSurface(mWin, "DESTROY", true);
848 }
849 destroySurface();
850 }
851 // Don't hide wallpaper if we're deferring the surface destroy
852 // because of a surface change.
853 if (!mDestroyPreservedSurfaceUponRedraw) {
854 mWallpaperControllerLocked.hideWallpapers(mWin);
855 }
856 } catch (RuntimeException e) {
857 Slog.w(TAG, "Exception thrown when destroying Window " + this
858 + " surface " + mSurfaceController + " session " + mSession + ": " + e.toString());
859 }
860
861 // Whether the surface was preserved (and copied to mPendingDestroySurface) or not, it
862 // needs to be cleared to match the WindowState.mHasSurface state. It is also necessary
863 // so it can be recreated successfully in mPendingDestroySurface case.
864 mWin.setHasSurface(false);
865 if (mSurfaceController != null) {
866 mSurfaceController.setShown(false);
867 }
868 mSurfaceController = null;
869 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700870 }
871
Craig Mautner96868332012-12-04 14:29:11 -0800872 void destroyDeferredSurfaceLocked() {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700873 try {
874 if (mPendingDestroySurface != null) {
875 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -0800876 WindowManagerService.logSurface(mWin, "DESTROY PENDING", true);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700877 }
Robert Carre6a83512015-11-03 16:09:21 -0800878 mPendingDestroySurface.destroyInTransaction();
Chong Zhang6e21cf42015-11-09 14:41:42 -0800879 // Don't hide wallpaper if we're destroying a deferred surface
880 // after a surface mode change.
881 if (!mDestroyPreservedSurfaceUponRedraw) {
882 mWallpaperControllerLocked.hideWallpapers(mWin);
883 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700884 }
885 } catch (RuntimeException e) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700886 Slog.w(TAG, "Exception thrown when destroying Window "
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700887 + this + " surface " + mPendingDestroySurface
888 + " session " + mSession + ": " + e.toString());
889 }
890 mSurfaceDestroyDeferred = false;
891 mPendingDestroySurface = null;
892 }
893
894 void computeShownFrameLocked() {
895 final boolean selfTransformation = mHasLocalTransformation;
896 Transformation attachedTransformation =
Craig Mautner322e4032012-07-13 13:35:20 -0700897 (mAttachedWinAnimator != null && mAttachedWinAnimator.mHasLocalTransformation)
898 ? mAttachedWinAnimator.mTransformation : null;
899 Transformation appTransformation = (mAppAnimator != null && mAppAnimator.hasTransformation)
900 ? mAppAnimator.transformation : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700901
902 // Wallpapers are animated based on the "real" window they
903 // are currently targeting.
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700904 final WindowState wallpaperTarget = mWallpaperControllerLocked.getWallpaperTarget();
Craig Mautner798adef2013-10-22 14:29:01 -0700905 if (mIsWallpaper && wallpaperTarget != null && mService.mAnimateWallpaperWithTarget) {
906 final WindowStateAnimator wallpaperAnimator = wallpaperTarget.mWinAnimator;
Craig Mautner918b53b2012-07-09 14:15:54 -0700907 if (wallpaperAnimator.mHasLocalTransformation &&
908 wallpaperAnimator.mAnimation != null &&
909 !wallpaperAnimator.mAnimation.getDetachWallpaper()) {
910 attachedTransformation = wallpaperAnimator.mTransformation;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800911 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700912 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
913 }
914 }
Craig Mautner798adef2013-10-22 14:29:01 -0700915 final AppWindowAnimator wpAppAnimator = wallpaperTarget.mAppToken == null ?
916 null : wallpaperTarget.mAppToken.mAppAnimator;
917 if (wpAppAnimator != null && wpAppAnimator.hasTransformation
Craig Mautner918b53b2012-07-09 14:15:54 -0700918 && wpAppAnimator.animation != null
919 && !wpAppAnimator.animation.getDetachWallpaper()) {
Craig Mautner59431632012-04-04 11:56:44 -0700920 appTransformation = wpAppAnimator.transformation;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800921 if (DEBUG_WALLPAPER && appTransformation != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700922 Slog.v(TAG, "WP target app xform: " + appTransformation);
923 }
924 }
925 }
926
Craig Mautnera91f9e22012-09-14 16:22:08 -0700927 final int displayId = mWin.getDisplayId();
928 final ScreenRotationAnimation screenRotationAnimation =
929 mAnimator.getScreenRotationAnimationLocked(displayId);
930 final boolean screenAnimation =
931 screenRotationAnimation != null && screenRotationAnimation.isAnimating();
Robert Carr2f0fe622015-09-25 14:56:38 -0700932
933 mHasClipRect = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700934 if (selfTransformation || attachedTransformation != null
935 || appTransformation != null || screenAnimation) {
936 // cache often used attributes locally
937 final Rect frame = mWin.mFrame;
938 final float tmpFloats[] = mService.mTmpFloats;
939 final Matrix tmpMatrix = mWin.mTmpMatrix;
940
941 // Compute the desired transformation.
Dianne Hackborn4b169692012-11-29 17:51:24 -0800942 if (screenAnimation && screenRotationAnimation.isRotating()) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700943 // If we are doing a screen animation, the global rotation
944 // applied to windows can result in windows that are carefully
945 // aligned with each other to slightly separate, allowing you
946 // to see what is behind them. An unsightly mess. This...
947 // thing... magically makes it call good: scale each window
948 // slightly (two pixels larger in each dimension, from the
949 // window's center).
950 final float w = frame.width();
951 final float h = frame.height();
952 if (w>=1 && h>=1) {
953 tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2);
954 } else {
955 tmpMatrix.reset();
956 }
957 } else {
958 tmpMatrix.reset();
959 }
960 tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale);
961 if (selfTransformation) {
962 tmpMatrix.postConcat(mTransformation.getMatrix());
963 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700964 if (attachedTransformation != null) {
965 tmpMatrix.postConcat(attachedTransformation.getMatrix());
966 }
967 if (appTransformation != null) {
968 tmpMatrix.postConcat(appTransformation.getMatrix());
969 }
970 if (screenAnimation) {
Craig Mautnera91f9e22012-09-14 16:22:08 -0700971 tmpMatrix.postConcat(screenRotationAnimation.getEnterTransformation().getMatrix());
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700972 }
Filip Gruszczynski9ca40b72015-08-13 13:35:25 -0700973 // The translation that applies the position of the window needs to be applied at the
974 // end in case that other translations include scaling. Otherwise the scaling will
975 // affect this translation.
976 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
Winson Chung399f6202014-03-19 10:47:20 -0700977
Svetoslav Ganov545252f2012-12-10 18:29:24 -0800978 //TODO (multidisplay): Magnification is supported only for the default display.
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800979 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
Svetoslav8e3feb12014-02-24 13:46:47 -0800980 MagnificationSpec spec = mService.mAccessibilityController
Svetoslav Ganov545252f2012-12-10 18:29:24 -0800981 .getMagnificationSpecForWindowLocked(mWin);
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -0700982 if (spec != null && !spec.isNop()) {
983 tmpMatrix.postScale(spec.scale, spec.scale);
984 tmpMatrix.postTranslate(spec.offsetX, spec.offsetY);
985 }
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700986 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700987
988 // "convert" it into SurfaceFlinger's format
989 // (a 2x2 matrix + an offset)
990 // Here we must not transform the position of the surface
991 // since it is already included in the transformation.
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800992 //Slog.i(TAG_WM, "Transform: " + matrix);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700993
994 mHaveMatrix = true;
995 tmpMatrix.getValues(tmpFloats);
996 mDsDx = tmpFloats[Matrix.MSCALE_X];
997 mDtDx = tmpFloats[Matrix.MSKEW_Y];
998 mDsDy = tmpFloats[Matrix.MSKEW_X];
999 mDtDy = tmpFloats[Matrix.MSCALE_Y];
1000 float x = tmpFloats[Matrix.MTRANS_X];
1001 float y = tmpFloats[Matrix.MTRANS_Y];
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001002 mWin.mShownPosition.set((int) x, (int) y);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001003
1004 // Now set the alpha... but because our current hardware
1005 // can't do alpha transformation on a non-opaque surface,
1006 // turn it off if we are running an animation that is also
1007 // transforming since it is more important to have that
1008 // animation be smooth.
1009 mShownAlpha = mAlpha;
1010 if (!mService.mLimitedAlphaCompositing
1011 || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format)
1012 || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
1013 && x == frame.left && y == frame.top))) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001014 //Slog.i(TAG_WM, "Applying alpha transform");
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001015 if (selfTransformation) {
1016 mShownAlpha *= mTransformation.getAlpha();
1017 }
1018 if (attachedTransformation != null) {
1019 mShownAlpha *= attachedTransformation.getAlpha();
1020 }
1021 if (appTransformation != null) {
1022 mShownAlpha *= appTransformation.getAlpha();
Winson Chung399f6202014-03-19 10:47:20 -07001023 if (appTransformation.hasClipRect()) {
1024 mClipRect.set(appTransformation.getClipRect());
1025 mHasClipRect = true;
Robert Carrf3b72c72016-03-21 18:16:39 -07001026 // The app transformation clip will be in the coordinate space of the main
1027 // activity window, which the animation correctly assumes will be placed at
1028 // (0,0)+(insets) relative to the containing frame. This isn't necessarily
1029 // true for child windows though which can have an arbitrary frame position
1030 // relative to their containing frame. We need to offset the difference
1031 // between the containing frame as used to calculate the crop and our
1032 // bounds to compensate for this.
1033 if (mWin.isChildWindow() && mWin.layoutInParentFrame()) {
1034 mClipRect.offset( (mWin.mContainingFrame.left - mWin.mFrame.left),
1035 mWin.mContainingFrame.top - mWin.mFrame.top );
1036 }
Winson Chung399f6202014-03-19 10:47:20 -07001037 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001038 }
1039 if (screenAnimation) {
Craig Mautnera91f9e22012-09-14 16:22:08 -07001040 mShownAlpha *= screenRotationAnimation.getEnterTransformation().getAlpha();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001041 }
1042 } else {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001043 //Slog.i(TAG_WM, "Not applying alpha transform");
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001044 }
1045
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001046 if ((DEBUG_SURFACE_TRACE || WindowManagerService.localLOGV)
Craig Mautnera91f9e22012-09-14 16:22:08 -07001047 && (mShownAlpha == 1.0 || mShownAlpha == 0.0)) Slog.v(
1048 TAG, "computeShownFrameLocked: Animating " + this + " mAlpha=" + mAlpha
1049 + " self=" + (selfTransformation ? mTransformation.getAlpha() : "null")
1050 + " attached=" + (attachedTransformation == null ?
1051 "null" : attachedTransformation.getAlpha())
1052 + " app=" + (appTransformation == null ? "null" : appTransformation.getAlpha())
1053 + " screen=" + (screenAnimation ?
1054 screenRotationAnimation.getEnterTransformation().getAlpha() : "null"));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001055 return;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001056 } else if (mIsWallpaper && mService.mWindowPlacerLocked.mWallpaperActionPending) {
Craig Mautner4d7349b2012-04-20 14:52:47 -07001057 return;
Chong Zhang3005e752015-09-18 18:46:28 -07001058 } else if (mWin.isDragResizeChanged()) {
1059 // This window is awaiting a relayout because user just started (or ended)
1060 // drag-resizing. The shown frame (which affects surface size and pos)
1061 // should not be updated until we get next finished draw with the new surface.
1062 // Otherwise one or two frames rendered with old settings would be displayed
1063 // with new geometry.
1064 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001065 }
1066
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001067 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautner4d7349b2012-04-20 14:52:47 -07001068 TAG, "computeShownFrameLocked: " + this +
1069 " not attached, mAlpha=" + mAlpha);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001070
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001071 MagnificationSpec spec = null;
1072 //TODO (multidisplay): Magnification is supported only for the default display.
Filip Gruszczynski69cbc352015-11-11 13:46:04 -08001073 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
Svetoslav8e3feb12014-02-24 13:46:47 -08001074 spec = mService.mAccessibilityController.getMagnificationSpecForWindowLocked(mWin);
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001075 }
Craig Mautner165be0c2015-01-27 15:16:58 -08001076 if (spec != null) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001077 final Rect frame = mWin.mFrame;
1078 final float tmpFloats[] = mService.mTmpFloats;
1079 final Matrix tmpMatrix = mWin.mTmpMatrix;
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001080
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001081 tmpMatrix.setScale(mWin.mGlobalScale, mWin.mGlobalScale);
1082 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001083
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001084 if (spec != null && !spec.isNop()) {
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -07001085 tmpMatrix.postScale(spec.scale, spec.scale);
1086 tmpMatrix.postTranslate(spec.offsetX, spec.offsetY);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001087 }
1088
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001089 tmpMatrix.getValues(tmpFloats);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001090
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001091 mHaveMatrix = true;
1092 mDsDx = tmpFloats[Matrix.MSCALE_X];
1093 mDtDx = tmpFloats[Matrix.MSKEW_Y];
1094 mDsDy = tmpFloats[Matrix.MSKEW_X];
1095 mDtDy = tmpFloats[Matrix.MSCALE_Y];
1096 float x = tmpFloats[Matrix.MTRANS_X];
1097 float y = tmpFloats[Matrix.MTRANS_Y];
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001098 mWin.mShownPosition.set((int) x, (int) y);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001099
1100 mShownAlpha = mAlpha;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001101 } else {
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001102 mWin.mShownPosition.set(mWin.mFrame.left, mWin.mFrame.top);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001103 if (mWin.mXOffset != 0 || mWin.mYOffset != 0) {
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001104 mWin.mShownPosition.offset(mWin.mXOffset, mWin.mYOffset);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001105 }
1106 mShownAlpha = mAlpha;
1107 mHaveMatrix = false;
1108 mDsDx = mWin.mGlobalScale;
1109 mDtDx = 0;
1110 mDsDy = 0;
1111 mDtDy = mWin.mGlobalScale;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001112 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001113 }
1114
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001115 private void calculateSystemDecorRect() {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001116 final WindowState w = mWin;
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001117 final Rect decorRect = w.mDecorFrame;
Alan Viverette49a22e82014-07-12 20:01:27 -07001118 final int width = w.mFrame.width();
1119 final int height = w.mFrame.height();
Alan Viveretteccb11e12014-07-08 16:04:02 -07001120
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001121 // Compute the offset of the window in relation to the decor rect.
Alan Viverette49a22e82014-07-12 20:01:27 -07001122 final int left = w.mXOffset + w.mFrame.left;
1123 final int top = w.mYOffset + w.mFrame.top;
Alan Viveretteccb11e12014-07-08 16:04:02 -07001124
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001125 // Initialize the decor rect to the entire frame.
Jorim Jaggidc249c42015-12-15 14:57:31 -08001126 if (w.isDragResizing() && w.getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER) {
1127
1128 // If we are resizing with the divider, the task bounds might be smaller than the
1129 // stack bounds. The system decor is used to clip to the task bounds, which we don't
1130 // want in this case in order to avoid holes.
1131 final DisplayInfo displayInfo = w.getDisplayContent().getDisplayInfo();
1132 mSystemDecorRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
1133 } else {
1134 mSystemDecorRect.set(0, 0, width, height);
1135 }
Alan Viveretteccb11e12014-07-08 16:04:02 -07001136
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001137 // If a freeform window is animating from a position where it would be cutoff, it would be
1138 // cutoff during the animation. We don't want that, so for the duration of the animation
1139 // we ignore the decor cropping and depend on layering to position windows correctly.
1140 final boolean cropToDecor = !(w.inFreeformWorkspace() && w.isAnimatingLw());
1141 if (cropToDecor) {
1142 // Intersect with the decor rect, offsetted by window position.
1143 mSystemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
1144 decorRect.right - left, decorRect.bottom - top);
1145 }
Alan Viveretteccb11e12014-07-08 16:04:02 -07001146
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001147 // If size compatibility is being applied to the window, the
1148 // surface is scaled relative to the screen. Also apply this
1149 // scaling to the crop rect. We aren't using the standard rect
1150 // scale function because we want to round things to make the crop
1151 // always round to a larger rect to ensure we don't crop too
1152 // much and hide part of the window that should be seen.
1153 if (w.mEnforceSizeCompat && w.mInvGlobalScale != 1.0f) {
1154 final float scale = w.mInvGlobalScale;
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001155 mSystemDecorRect.left = (int) (mSystemDecorRect.left * scale - 0.5f);
1156 mSystemDecorRect.top = (int) (mSystemDecorRect.top * scale - 0.5f);
1157 mSystemDecorRect.right = (int) ((mSystemDecorRect.right+1) * scale - 0.5f);
1158 mSystemDecorRect.bottom = (int) ((mSystemDecorRect.bottom+1) * scale - 0.5f);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001159 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001160 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001161
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001162 void calculateSurfaceWindowCrop(Rect clipRect, Rect finalClipRect) {
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001163 final WindowState w = mWin;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001164 final DisplayContent displayContent = w.getDisplayContent();
1165 if (displayContent == null) {
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001166 clipRect.setEmpty();
1167 finalClipRect.setEmpty();
1168 return;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001169 }
Wale Ogunwaleb3eba812015-07-30 20:20:16 -07001170 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001171 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "Updating crop for window: " + w + ", " + "mLastCrop=" +
1172 mLastClipRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001173
1174 // Need to recompute a new system decor rect each time.
Robert Carr58f29132015-10-29 14:19:05 -07001175 if (!w.isDefaultDisplay()) {
Jeff Brown28e0b092012-09-25 11:31:28 -07001176 // On a different display there is no system decor. Crop the window
1177 // by the screen boundaries.
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001178 mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height());
1179 mSystemDecorRect.intersect(-w.mCompatFrame.left, -w.mCompatFrame.top,
Jeff Brown28e0b092012-09-25 11:31:28 -07001180 displayInfo.logicalWidth - w.mCompatFrame.left,
1181 displayInfo.logicalHeight - w.mCompatFrame.top);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001182 } else if (w.mLayer >= mService.mSystemDecorLayer) {
1183 // Above the decor layer is easy, just use the entire window.
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001184 mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height());
Craig Mautner165be0c2015-01-27 15:16:58 -08001185 } else if (w.mDecorFrame.isEmpty()) {
1186 // Windows without policy decor aren't cropped.
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001187 mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height());
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001188 } else if (w.mAttrs.type == LayoutParams.TYPE_WALLPAPER && mAnimator.isAnimating()) {
Adrian Roosd47ad032014-08-15 23:17:05 +02001189 // If we're animating, the wallpaper crop should only be updated at the end of the
1190 // animation.
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001191 mTmpClipRect.set(mSystemDecorRect);
1192 calculateSystemDecorRect();
1193 mSystemDecorRect.union(mTmpClipRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001194 } else {
John Spurlock46646232013-09-30 22:32:42 -04001195 // Crop to the system decor specified by policy.
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001196 calculateSystemDecorRect();
1197 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "Applying decor to crop for " + w + ", mDecorFrame="
1198 + w.mDecorFrame + ", mSystemDecorRect=" + mSystemDecorRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001199 }
1200
Chong Zhang0abb20f2015-11-19 14:17:31 -08001201 final boolean fullscreen = w.isFrameFullscreen(displayInfo);
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001202 final boolean isFreeformResizing =
Jorim Jaggidcf467c2015-11-05 13:59:32 +01001203 w.isDragResizing() && w.getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
Robert Carr51a1b872015-12-08 14:03:13 -08001204
1205 // We use the clip rect as provided by the tranformation for non-fullscreen windows to
1206 // avoid premature clipping with the system decor rect.
1207 clipRect.set((mHasClipRect && !fullscreen) ? mClipRect : mSystemDecorRect);
1208 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "Initial clip rect: " + clipRect + ", mHasClipRect="
1209 + mHasClipRect + ", fullscreen=" + fullscreen);
1210
1211 if (isFreeformResizing && !w.isChildWindow()) {
1212 // For freeform resizing non child windows, we are using the big surface positioned
1213 // at 0,0. Thus we must express the crop in that coordinate space.
1214 clipRect.offset(w.mShownPosition.x, w.mShownPosition.y);
Chong Zhang09b21ef2015-09-14 10:20:21 -07001215 }
Robert Carr51a1b872015-12-08 14:03:13 -08001216
Alan Viverette49a22e82014-07-12 20:01:27 -07001217 // Expand the clip rect for surface insets.
1218 final WindowManager.LayoutParams attrs = w.mAttrs;
1219 clipRect.left -= attrs.surfaceInsets.left;
1220 clipRect.top -= attrs.surfaceInsets.top;
1221 clipRect.right += attrs.surfaceInsets.right;
1222 clipRect.bottom += attrs.surfaceInsets.bottom;
1223
Wale Ogunwaleb3eba812015-07-30 20:20:16 -07001224 if (mHasClipRect && fullscreen) {
1225 // We intersect the clip rect specified by the transformation with the expanded system
1226 // decor rect to prevent artifacts from drawing during animation if the transformation
1227 // clip rect extends outside the system decor rect.
1228 clipRect.intersect(mClipRect);
1229 }
Alan Viverette49a22e82014-07-12 20:01:27 -07001230 // The clip rect was generated assuming (0,0) as the window origin,
1231 // so we need to translate to match the actual surface coordinates.
1232 clipRect.offset(attrs.surfaceInsets.left, attrs.surfaceInsets.top);
Robert Carr58f29132015-10-29 14:19:05 -07001233
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001234 finalClipRect.setEmpty();
1235 adjustCropToStackBounds(w, clipRect, finalClipRect, isFreeformResizing);
Robert Carr0d00c2e2016-02-29 17:45:02 -08001236 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "Clip rect after stack adjustment=" + clipRect);
Robert Carr58f29132015-10-29 14:19:05 -07001237
1238 w.transformFromScreenToSurfaceSpace(clipRect);
1239
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08001240 // See {@link WindowState#notifyMovedInStack} for why this is necessary.
1241 if (w.hasJustMovedInStack() && mLastClipRect.isEmpty() && !clipRect.isEmpty()) {
1242 clipRect.setEmpty();
1243 }
Robert Carr0d00c2e2016-02-29 17:45:02 -08001244 }
1245
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001246 void updateSurfaceWindowCrop(Rect clipRect, Rect finalClipRect, boolean recoveringMemory) {
Winson Chung399f6202014-03-19 10:47:20 -07001247 if (!clipRect.equals(mLastClipRect)) {
1248 mLastClipRect.set(clipRect);
Robert Carre6a83512015-11-03 16:09:21 -08001249 mSurfaceController.setCropInTransaction(clipRect, recoveringMemory);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001250 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001251 if (!finalClipRect.equals(mLastFinalClipRect)) {
1252 mLastFinalClipRect.set(finalClipRect);
1253 mSurfaceController.setFinalCropInTransaction(finalClipRect);
1254 }
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001255 }
1256
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001257 private int resolveStackClip() {
1258
1259 // App animation overrides window animation stack clip mode.
1260 if (mAppAnimator != null && mAppAnimator.animation != null) {
1261 return mAppAnimator.getStackClip();
1262 } else {
1263 return mStackClip;
1264 }
1265 }
1266 private void adjustCropToStackBounds(WindowState w, Rect clipRect, Rect finalClipRect,
1267 boolean isFreeformResizing) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001268 final Task task = w.getTask();
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001269 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001270 return;
Filip Gruszczynski4b8eea72015-09-14 18:16:19 -07001271 }
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001272
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001273 final int stackClip = resolveStackClip();
1274
1275 // It's animating and we don't want to clip it to stack bounds during animation - abort.
1276 if (isAnimating() && stackClip == STACK_CLIP_NONE) {
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001277 return;
1278 }
1279
Chong Zhangbcb8d822016-02-26 16:21:02 -08001280 final WindowState winShowWhenLocked = (WindowState) mPolicy.getWinShowWhenLockedLw();
1281 if (w == winShowWhenLocked) {
1282 return;
1283 }
1284
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001285 final TaskStack stack = task.mStack;
1286 stack.getDimBounds(mTmpStackBounds);
1287 // When we resize we use the big surface approach, which means we can't trust the
1288 // window frame bounds anymore. Instead, the window will be placed at 0, 0, but to avoid
1289 // hardcoding it, we use surface coordinates.
1290 final int frameX = isFreeformResizing ? (int) mSurfaceController.getX() :
1291 w.mFrame.left + mWin.mXOffset - w.getAttrs().surfaceInsets.left;
1292 final int frameY = isFreeformResizing ? (int) mSurfaceController.getY() :
1293 w.mFrame.top + mWin.mYOffset - w.getAttrs().surfaceInsets.top;
Robert Carr0d00c2e2016-02-29 17:45:02 -08001294
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001295 // If we are animating, we either apply the clip before applying all the animation
1296 // transformation or after all the transformation.
1297 final boolean useFinalClipRect = isAnimating() && stackClip == STACK_CLIP_AFTER_ANIM;
1298
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001299 // We need to do some acrobatics with surface position, because their clip region is
1300 // relative to the inside of the surface, but the stack bounds aren't.
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001301 if (useFinalClipRect) {
1302 finalClipRect.set(mTmpStackBounds);
1303 } else {
1304 clipRect.left = Math.max(0,
1305 Math.max(mTmpStackBounds.left, frameX + clipRect.left) - frameX);
1306 clipRect.top = Math.max(0,
1307 Math.max(mTmpStackBounds.top, frameY + clipRect.top) - frameY);
1308 clipRect.right = Math.max(0,
1309 Math.min(mTmpStackBounds.right, frameX + clipRect.right) - frameX);
1310 clipRect.bottom = Math.max(0,
1311 Math.min(mTmpStackBounds.bottom, frameY + clipRect.bottom) - frameY);
1312 }
Filip Gruszczynski4b8eea72015-09-14 18:16:19 -07001313 }
1314
Wale Ogunwale4c8b7952015-04-07 10:49:40 -07001315 void setSurfaceBoundariesLocked(final boolean recoveringMemory) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001316 final WindowState w = mWin;
Robert Carr0d00c2e2016-02-29 17:45:02 -08001317 final Task task = w.getTask();
Alan Viveretteccb11e12014-07-08 16:04:02 -07001318
Filip Gruszczynski69cbc352015-11-11 13:46:04 -08001319 mTmpSize.set(w.mShownPosition.x, w.mShownPosition.y, 0, 0);
1320 calculateSurfaceBounds(w, w.getAttrs());
Chong Zhang0275e392015-09-17 10:41:44 -07001321
Robert Carr0d00c2e2016-02-29 17:45:02 -08001322 float extraHScale = (float) 1.0;
1323 float extraVScale = (float) 1.0;
Robert Carre1034cc32016-02-01 13:08:15 -08001324
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001325 calculateSurfaceWindowCrop(mTmpClipRect, mTmpFinalClipRect);
Robert Carr0d00c2e2016-02-29 17:45:02 -08001326 if (task != null && task.mStack.getForceScaleToCrop()) {
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001327 extraHScale = mTmpClipRect.width() / (float)mTmpSize.width();
1328 extraVScale = mTmpClipRect.height() / (float)mTmpSize.height();
Robert Carr0d00c2e2016-02-29 17:45:02 -08001329
1330 // In the case of ForceScaleToCrop we scale entire tasks together,
1331 // and so we need to scale our offsets relative to the task bounds
1332 // or parent and child windows would fall out of alignment.
1333 int posX = (int) (mTmpSize.left - w.mAttrs.x * (1 - extraHScale));
1334 int posY = (int) (mTmpSize.top - w.mAttrs.y * (1 - extraVScale));
1335 posX += w.getAttrs().surfaceInsets.left * (1 - extraHScale);
1336 posY += w.getAttrs().surfaceInsets.top * (1 - extraVScale);
1337 mSurfaceController.setPositionInTransaction(posX, posY, recoveringMemory);
1338
1339 // Since we are scaled to fit in our previously desired crop, we can now
1340 // expose the whole window in buffer space, and not risk extending
1341 // past where the system would have cropped us
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001342 mTmpClipRect.set(0, 0, mTmpSize.width(), mTmpSize.height());
1343 mTmpFinalClipRect.setEmpty();
1344 updateSurfaceWindowCrop(mTmpClipRect, mTmpFinalClipRect, recoveringMemory);
Robert Carr0d00c2e2016-02-29 17:45:02 -08001345 } else {
1346 mSurfaceController.setPositionInTransaction(mTmpSize.left, mTmpSize.top,
1347 recoveringMemory);
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001348 updateSurfaceWindowCrop(mTmpClipRect, mTmpFinalClipRect, recoveringMemory);
Robert Carr0d00c2e2016-02-29 17:45:02 -08001349 }
1350
1351
1352 mSurfaceController.setMatrixInTransaction(mDsDx * w.mHScale * extraHScale,
1353 mDtDx * w.mVScale * extraVScale,
1354 mDsDy * w.mHScale * extraHScale,
1355 mDtDy * w.mVScale * extraVScale, recoveringMemory);
Filip Gruszczynski69cbc352015-11-11 13:46:04 -08001356 mSurfaceResized = mSurfaceController.setSizeInTransaction(
1357 mTmpSize.width(), mTmpSize.height(),
Robert Carre6a83512015-11-03 16:09:21 -08001358 recoveringMemory);
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001359
Robert Carre6a83512015-11-03 16:09:21 -08001360 if (mSurfaceResized) {
Chong Zhang5b2f1992015-11-13 15:40:36 -08001361 mReportSurfaceResized = true;
Robert Carre6a83512015-11-03 16:09:21 -08001362 mAnimator.setPendingLayoutChanges(w.getDisplayId(),
1363 WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
1364 w.applyDimLayerIfNeeded();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001365 }
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001366
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001367 }
1368
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001369 void prepareSurfaceLocked(final boolean recoveringMemory) {
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001370 final WindowState w = mWin;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001371 if (!hasSurface()) {
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001372 if (w.mOrientationChanging) {
1373 if (DEBUG_ORIENTATION) {
1374 Slog.v(TAG, "Orientation change skips hidden " + w);
1375 }
1376 w.mOrientationChanging = false;
1377 }
1378 return;
1379 }
1380
1381 boolean displayed = false;
1382
1383 computeShownFrameLocked();
1384
Craig Mautnera91f9e22012-09-14 16:22:08 -07001385 setSurfaceBoundariesLocked(recoveringMemory);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001386
Craig Mautner918b53b2012-07-09 14:15:54 -07001387 if (mIsWallpaper && !mWin.mWallpaperVisible) {
Craig Mautner0fa77c12012-06-11 15:57:19 -07001388 // Wallpaper is no longer visible and there is no wp target => hide it.
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001389 hide("prepareSurfaceLocked");
Craig Mautner72669d12012-12-18 17:23:54 -08001390 } else if (w.mAttachedHidden || !w.isOnScreen()) {
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001391 hide("prepareSurfaceLocked");
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001392 mWallpaperControllerLocked.hideWallpapers(w);
Craig Mautnerb9836b92012-06-11 11:40:09 -07001393
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001394 // If we are waiting for this window to handle an
1395 // orientation change, well, it is hidden, so
1396 // doesn't really matter. Note that this does
1397 // introduce a potential glitch if the window
1398 // becomes unhidden before it has drawn for the
1399 // new orientation.
1400 if (w.mOrientationChanging) {
1401 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001402 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001403 "Orientation change skips hidden " + w);
1404 }
1405 } else if (mLastLayer != mAnimLayer
1406 || mLastAlpha != mShownAlpha
1407 || mLastDsDx != mDsDx
1408 || mLastDtDx != mDtDx
1409 || mLastDsDy != mDsDy
1410 || mLastDtDy != mDtDy
1411 || w.mLastHScale != w.mHScale
1412 || w.mLastVScale != w.mVScale
Craig Mautner749a7bb2012-04-02 13:49:53 -07001413 || mLastHidden) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001414 displayed = true;
1415 mLastAlpha = mShownAlpha;
1416 mLastLayer = mAnimLayer;
1417 mLastDsDx = mDsDx;
1418 mLastDtDx = mDtDx;
1419 mLastDsDy = mDsDy;
1420 mLastDtDy = mDtDy;
1421 w.mLastHScale = w.mHScale;
1422 w.mLastVScale = w.mVScale;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001423 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
Robert Carre6a83512015-11-03 16:09:21 -08001424 "controller=" + mSurfaceController +
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001425 "alpha=" + mShownAlpha + " layer=" + mAnimLayer
Craig Mautner78505d82014-09-02 14:36:31 -07001426 + " matrix=[" + mDsDx + "*" + w.mHScale
1427 + "," + mDtDx + "*" + w.mVScale
1428 + "][" + mDsDy + "*" + w.mHScale
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -08001429 + "," + mDtDy + "*" + w.mVScale + "]", false);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001430
Robert Carre6a83512015-11-03 16:09:21 -08001431 boolean prepared =
1432 mSurfaceController.prepareToShowInTransaction(mShownAlpha, mAnimLayer,
1433 mDsDx * w.mHScale, mDtDx * w.mVScale,
1434 mDsDy * w.mHScale, mDtDy * w.mVScale,
1435 recoveringMemory);
1436
1437 if (prepared && mLastHidden && mDrawState == HAS_DRAWN) {
1438 if (showSurfaceRobustlyLocked()) {
Chong Zhangb9b0fec2016-02-11 18:51:51 -08001439 if (mDestroyPreservedSurfaceUponRedraw) {
1440 mService.mDestroyPreservedSurface.add(mWin);
1441 }
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -08001442 mAnimator.requestRemovalOfReplacedWindows(w);
Robert Carre6a83512015-11-03 16:09:21 -08001443 mLastHidden = false;
1444 if (mIsWallpaper) {
1445 mWallpaperControllerLocked.dispatchWallpaperVisibility(w, true);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001446 }
Robert Carre6a83512015-11-03 16:09:21 -08001447 // This draw means the difference between unique content and mirroring.
1448 // Run another pass through performLayout to set mHasContent in the
1449 // LogicalDisplay.
1450 mAnimator.setPendingLayoutChanges(w.getDisplayId(),
1451 WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
1452 } else {
1453 w.mOrientationChanging = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001454 }
1455 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001456 if (hasSurface()) {
Robert Carre6a83512015-11-03 16:09:21 -08001457 w.mToken.hasVisible = true;
1458 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001459 } else {
Craig Mautner9e809442012-06-22 17:13:04 -07001460 if (DEBUG_ANIM && isAnimating()) {
Chong Zhange05db742016-02-16 16:58:37 -08001461 Slog.v(TAG, "prepareSurface: No changes in animation for " + this);
Craig Mautner83339b42012-05-01 22:13:23 -07001462 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001463 displayed = true;
1464 }
1465
1466 if (displayed) {
1467 if (w.mOrientationChanging) {
1468 if (!w.isDrawnLw()) {
Craig Mautner2639da52012-07-09 09:39:06 -07001469 mAnimator.mBulkUpdateParams &= ~SET_ORIENTATION_CHANGE_COMPLETE;
Dianne Hackborna57c6952013-03-29 14:46:40 -07001470 mAnimator.mLastWindowFreezeSource = w;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001471 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001472 "Orientation continue waiting for draw in " + w);
1473 } else {
1474 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001475 if (DEBUG_ORIENTATION) Slog.v(TAG, "Orientation change complete in " + w);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001476 }
1477 }
1478 w.mToken.hasVisible = true;
Chong Zhangf66db432016-01-13 10:39:51 -08001479
1480 final Task task = w.getTask();
1481 if (task != null) {
1482 task.scheduleShowNonResizeableDockToastIfNeeded();
1483 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001484 }
1485 }
1486
Craig Mautneref655012013-01-03 11:20:24 -08001487 void setTransparentRegionHintLocked(final Region region) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001488 if (mSurfaceController == null) {
1489 Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true");
1490 return;
1491 }
Robert Carre6a83512015-11-03 16:09:21 -08001492 mSurfaceController.setTransparentRegionHint(region);
Craig Mautner48ba1e72012-04-02 13:18:16 -07001493 }
1494
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001495 void setWallpaperOffset(Point shownPosition) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07001496 final LayoutParams attrs = mWin.getAttrs();
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001497 final int left = shownPosition.x - attrs.surfaceInsets.left;
1498 final int top = shownPosition.y - attrs.surfaceInsets.top;
Robert Carre6a83512015-11-03 16:09:21 -08001499
1500 try {
Craig Mautner71dd1b62014-02-18 15:48:52 -08001501 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setWallpaperOffset");
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001502 SurfaceControl.openTransaction();
Robert Carre6a83512015-11-03 16:09:21 -08001503 mSurfaceController.setPositionInTransaction(mWin.mFrame.left + left,
1504 mWin.mFrame.top + top, false);
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001505 calculateSurfaceWindowCrop(mTmpClipRect, mTmpFinalClipRect);
1506 updateSurfaceWindowCrop(mTmpClipRect, mTmpFinalClipRect, false);
Robert Carre6a83512015-11-03 16:09:21 -08001507 } catch (RuntimeException e) {
1508 Slog.w(TAG, "Error positioning surface of " + mWin
1509 + " pos=(" + left + "," + top + ")", e);
1510 } finally {
1511 SurfaceControl.closeTransaction();
1512 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1513 "<<< CLOSE TRANSACTION setWallpaperOffset");
Craig Mautner48ba1e72012-04-02 13:18:16 -07001514 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001515 }
1516
John Reck80181b92015-05-19 11:09:32 -07001517 /**
1518 * Try to change the pixel format without recreating the surface. This
1519 * will be common in the case of changing from PixelFormat.OPAQUE to
1520 * PixelFormat.TRANSLUCENT in the hardware-accelerated case as both
1521 * requested formats resolve to the same underlying SurfaceControl format
1522 * @return True if format was succesfully changed, false otherwise
1523 */
1524 boolean tryChangeFormatInPlaceLocked() {
Robert Carre6a83512015-11-03 16:09:21 -08001525 if (mSurfaceController == null) {
John Reck80181b92015-05-19 11:09:32 -07001526 return false;
1527 }
1528 final LayoutParams attrs = mWin.getAttrs();
Wale Ogunwalee7bf46b2015-09-30 09:19:28 -07001529 final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0;
John Reck80181b92015-05-19 11:09:32 -07001530 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
1531 if (format == mSurfaceFormat) {
1532 setOpaqueLocked(!PixelFormat.formatHasAlpha(attrs.format));
1533 return true;
1534 }
1535 return false;
1536 }
1537
Craig Mautner6f612042014-09-07 13:13:23 -07001538 void setOpaqueLocked(boolean isOpaque) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001539 if (mSurfaceController == null) {
1540 return;
1541 }
Robert Carre6a83512015-11-03 16:09:21 -08001542 mSurfaceController.setOpaque(isOpaque);
Craig Mautner71dd1b62014-02-18 15:48:52 -08001543 }
1544
Wale Ogunwalef5ad42f2015-06-12 13:59:03 -07001545 void setSecureLocked(boolean isSecure) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001546 if (mSurfaceController == null) {
1547 return;
1548 }
Robert Carre6a83512015-11-03 16:09:21 -08001549 mSurfaceController.setSecure(isSecure);
Wale Ogunwalef5ad42f2015-06-12 13:59:03 -07001550 }
1551
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001552 // This must be called while inside a transaction.
1553 boolean performShowLocked() {
Craig Mautner5962b122012-10-05 14:45:52 -07001554 if (mWin.isHiddenFromUserLocked()) {
Wale Ogunwale4eef94f2015-07-17 22:29:54 -07001555 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + mWin + ", belonging to " + mWin.mOwnerUid);
1556 mWin.hideLw(false);
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001557 return false;
1558 }
Craig Mautner6fbda632012-07-03 09:26:39 -07001559 if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
1560 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001561 Slog.v(TAG, "performShow on " + this
Craig Mautnerc431e892015-02-11 13:14:26 -08001562 + ": mDrawState=" + drawStateToString() + " readyForDisplay="
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001563 + mWin.isReadyForDisplayIgnoringKeyguard()
Craig Mautner6fbda632012-07-03 09:26:39 -07001564 + " starting=" + (mWin.mAttrs.type == TYPE_APPLICATION_STARTING)
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001565 + " during animation: policyVis=" + mWin.mPolicyVisibility
1566 + " attHidden=" + mWin.mAttachedHidden
1567 + " tok.hiddenRequested="
1568 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
1569 + " tok.hidden="
1570 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
1571 + " animating=" + mAnimating
1572 + " tok animating="
Craig Mautnerc431e892015-02-11 13:14:26 -08001573 + (mAppAnimator != null ? mAppAnimator.animating : false) + " Callers="
1574 + Debug.getCallers(3));
Craig Mautner6fbda632012-07-03 09:26:39 -07001575 }
1576 if (mDrawState == READY_TO_SHOW && mWin.isReadyForDisplayIgnoringKeyguard()) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001577 if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
1578 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
1579 Slog.v(TAG, "Showing " + this
1580 + " during animation: policyVis=" + mWin.mPolicyVisibility
1581 + " attHidden=" + mWin.mAttachedHidden
1582 + " tok.hiddenRequested="
1583 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
1584 + " tok.hidden="
1585 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
1586 + " animating=" + mAnimating
1587 + " tok animating="
Craig Mautner322e4032012-07-13 13:35:20 -07001588 + (mAppAnimator != null ? mAppAnimator.animating : false));
Craig Mautner6fbda632012-07-03 09:26:39 -07001589 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001590
1591 mService.enableScreenIfNeededLocked();
1592
1593 applyEnterAnimationLocked();
1594
Craig Mautnerde6198e2012-04-19 09:59:31 -07001595 // Force the show in the next prepareSurfaceLocked() call.
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001596 mLastAlpha = -1;
Craig Mautneref25d7a2012-05-15 23:01:47 -07001597 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM)
Chong Zhang5b2f1992015-11-13 15:40:36 -08001598 Slog.v(TAG, "performShowLocked: mDrawState=HAS_DRAWN in " + mWin);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001599 mDrawState = HAS_DRAWN;
Craig Mautner96868332012-12-04 14:29:11 -08001600 mService.scheduleAnimationLocked();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001601
1602 int i = mWin.mChildWindows.size();
1603 while (i > 0) {
1604 i--;
1605 WindowState c = mWin.mChildWindows.get(i);
1606 if (c.mAttachedHidden) {
1607 c.mAttachedHidden = false;
Robert Carre6a83512015-11-03 16:09:21 -08001608 if (c.mWinAnimator.mSurfaceController != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001609 c.mWinAnimator.performShowLocked();
Filip Gruszczynski921171a2015-09-30 22:02:57 +00001610 // It hadn't been shown, which means layout not
1611 // performed on it, so now we want to make sure to
1612 // do a layout. If called from within the transaction
1613 // loop, this will cause it to restart with a new
1614 // layout.
1615 final DisplayContent displayContent = c.getDisplayContent();
1616 if (displayContent != null) {
1617 displayContent.layoutNeeded = true;
1618 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001619 }
1620 }
1621 }
1622
Filip Gruszczynskib6e66622015-10-25 16:05:27 -07001623 if (mWin.mAttrs.type != TYPE_APPLICATION_STARTING && mWin.mAppToken != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001624 mWin.mAppToken.onFirstWindowDrawn(mWin, this);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001625 }
Chong Zhangc806d902015-11-30 09:44:27 -08001626
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001627 return true;
1628 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001629 return false;
1630 }
1631
1632 /**
1633 * Have the surface flinger show a surface, robustly dealing with
1634 * error conditions. In particular, if there is not enough memory
1635 * to show the surface, then we will try to get rid of other surfaces
1636 * in order to succeed.
1637 *
1638 * @return Returns true if the surface was successfully shown.
1639 */
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001640 private boolean showSurfaceRobustlyLocked() {
Robert Carre6a83512015-11-03 16:09:21 -08001641 boolean shown = mSurfaceController.showRobustlyInTransaction();
1642 if (!shown)
1643 return false;
1644
1645 if (mWin.mTurnOnScreen) {
1646 if (DEBUG_VISIBILITY) Slog.v(TAG, "Show surface turning screen on: " + mWin);
1647 mWin.mTurnOnScreen = false;
1648 mAnimator.mBulkUpdateParams |= SET_TURN_ON_SCREEN;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001649 }
Robert Carre6a83512015-11-03 16:09:21 -08001650 return true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001651 }
1652
1653 void applyEnterAnimationLocked() {
1654 final int transit;
1655 if (mEnterAnimationPending) {
1656 mEnterAnimationPending = false;
1657 transit = WindowManagerPolicy.TRANSIT_ENTER;
1658 } else {
1659 transit = WindowManagerPolicy.TRANSIT_SHOW;
1660 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001661 applyAnimationLocked(transit, true);
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001662 //TODO (multidisplay): Magnification is supported only for the default display.
Svetoslav8e3feb12014-02-24 13:46:47 -08001663 if (mService.mAccessibilityController != null
Filip Gruszczynski69cbc352015-11-11 13:46:04 -08001664 && mWin.getDisplayId() == DEFAULT_DISPLAY) {
Svetoslav8e3feb12014-02-24 13:46:47 -08001665 mService.mAccessibilityController.onWindowTransitionLocked(mWin, transit);
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -07001666 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001667 }
1668
1669 /**
1670 * Choose the correct animation and set it to the passed WindowState.
Craig Mautner4b71aa12012-12-27 17:20:01 -08001671 * @param transit If AppTransition.TRANSIT_PREVIEW_DONE and the app window has been drawn
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001672 * then the animation will be app_starting_exit. Any other value loads the animation from
1673 * the switch statement below.
1674 * @param isEntrance The animation type the last time this was called. Used to keep from
1675 * loading the same animation twice.
1676 * @return true if an animation has been loaded.
1677 */
1678 boolean applyAnimationLocked(int transit, boolean isEntrance) {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001679 if ((mLocalAnimating && mAnimationIsEntrance == isEntrance)
1680 || mKeyguardGoingAwayAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001681 // If we are trying to apply an animation, but already running
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001682 // an animation of the same type, then just leave that one alone.
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001683
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001684 // If we are in a keyguard exit animation, and the window should animate away, modify
1685 // keyguard exit animation such that it also fades out.
1686 if (mAnimation != null && mKeyguardGoingAwayAnimation
1687 && transit == WindowManagerPolicy.TRANSIT_PREVIEW_DONE) {
1688 applyFadeoutDuringKeyguardExitAnimation();
1689 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001690 return true;
1691 }
1692
1693 // Only apply an animation if the display isn't frozen. If it is
1694 // frozen, there is no reason to animate and it can cause strange
1695 // artifacts when we unfreeze the display if some different animation
1696 // is running.
1697 if (mService.okToDisplay()) {
1698 int anim = mPolicy.selectAnimationLw(mWin, transit);
1699 int attr = -1;
1700 Animation a = null;
1701 if (anim != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001702 a = anim != -1 ? AnimationUtils.loadAnimation(mContext, anim) : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001703 } else {
1704 switch (transit) {
1705 case WindowManagerPolicy.TRANSIT_ENTER:
1706 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
1707 break;
1708 case WindowManagerPolicy.TRANSIT_EXIT:
1709 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
1710 break;
1711 case WindowManagerPolicy.TRANSIT_SHOW:
1712 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
1713 break;
1714 case WindowManagerPolicy.TRANSIT_HIDE:
1715 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
1716 break;
1717 }
1718 if (attr >= 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001719 a = mService.mAppTransition.loadAnimationAttr(mWin.mAttrs, attr);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001720 }
1721 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001722 if (DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001723 "applyAnimation: win=" + this
1724 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
Craig Mautner4d7349b2012-04-20 14:52:47 -07001725 + " a=" + a
Craig Mautner8863cca2012-09-18 15:04:34 -07001726 + " transit=" + transit
Craig Mautner83339b42012-05-01 22:13:23 -07001727 + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001728 if (a != null) {
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -08001729 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001730 setAnimation(a);
1731 mAnimationIsEntrance = isEntrance;
1732 }
1733 } else {
1734 clearAnimation();
1735 }
1736
1737 return mAnimation != null;
1738 }
1739
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001740 private void applyFadeoutDuringKeyguardExitAnimation() {
1741 long startTime = mAnimation.getStartTime();
1742 long duration = mAnimation.getDuration();
1743 long elapsed = mLastAnimationTime - startTime;
1744 long fadeDuration = duration - elapsed;
1745 if (fadeDuration <= 0) {
1746 // Never mind, this would be no visible animation, so abort the animation change.
1747 return;
1748 }
1749 AnimationSet newAnimation = new AnimationSet(false /* shareInterpolator */);
1750 newAnimation.setDuration(duration);
1751 newAnimation.setStartTime(startTime);
1752 newAnimation.addAnimation(mAnimation);
1753 Animation fadeOut = AnimationUtils.loadAnimation(
1754 mContext, com.android.internal.R.anim.app_starting_exit);
1755 fadeOut.setDuration(fadeDuration);
1756 fadeOut.setStartOffset(elapsed);
1757 newAnimation.addAnimation(fadeOut);
Filip Gruszczynskif52dd202015-11-15 20:36:38 -08001758 newAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(), mAnimDx, mAnimDy);
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001759 mAnimation = newAnimation;
1760 }
1761
Craig Mautnera2c77052012-03-26 12:14:43 -07001762 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1763 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
1764 || mAnimation != null) {
1765 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
1766 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
1767 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
1768 pw.print(" mAnimation="); pw.println(mAnimation);
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001769 pw.print(" mStackClip="); pw.println(mStackClip);
Craig Mautnera2c77052012-03-26 12:14:43 -07001770 }
1771 if (mHasTransformation || mHasLocalTransformation) {
1772 pw.print(prefix); pw.print("XForm: has=");
1773 pw.print(mHasTransformation);
1774 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
1775 pw.print(" "); mTransformation.printShortString(pw);
1776 pw.println();
1777 }
Robert Carre6a83512015-11-03 16:09:21 -08001778 if (mSurfaceController != null) {
1779 mSurfaceController.dump(pw, prefix, dumpAll);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001780 }
Robert Carre6a83512015-11-03 16:09:21 -08001781 if (dumpAll) {
1782 pw.print(prefix); pw.print("mDrawState="); pw.print(drawStateToString());
1783 pw.print(prefix); pw.print(" mLastHidden="); pw.println(mLastHidden);
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001784 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
1785 pw.print(" last="); mLastSystemDecorRect.printShortString(pw);
1786 if (mHasClipRect) {
1787 pw.print(" mLastClipRect="); mLastClipRect.printShortString(pw);
1788 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001789 if (!mLastFinalClipRect.isEmpty()) {
1790 pw.print(" mLastFinalClipRect="); mLastFinalClipRect.printShortString(pw);
1791 }
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001792 pw.println();
Robert Carre6a83512015-11-03 16:09:21 -08001793 }
1794
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001795 if (mPendingDestroySurface != null) {
1796 pw.print(prefix); pw.print("mPendingDestroySurface=");
1797 pw.println(mPendingDestroySurface);
1798 }
1799 if (mSurfaceResized || mSurfaceDestroyDeferred) {
1800 pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized);
1801 pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred);
1802 }
1803 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
1804 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
1805 pw.print(" mAlpha="); pw.print(mAlpha);
1806 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
1807 }
1808 if (mHaveMatrix || mWin.mGlobalScale != 1) {
1809 pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale);
1810 pw.print(" mDsDx="); pw.print(mDsDx);
1811 pw.print(" mDtDx="); pw.print(mDtDx);
1812 pw.print(" mDsDy="); pw.print(mDsDy);
1813 pw.print(" mDtDy="); pw.println(mDtDy);
1814 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001815 }
1816
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001817 @Override
1818 public String toString() {
Dianne Hackborn529e7442012-11-01 14:22:28 -07001819 StringBuffer sb = new StringBuffer("WindowStateAnimator{");
1820 sb.append(Integer.toHexString(System.identityHashCode(this)));
1821 sb.append(' ');
1822 sb.append(mWin.mAttrs.getTitle());
1823 sb.append('}');
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001824 return sb.toString();
1825 }
Robert Carre6a83512015-11-03 16:09:21 -08001826
1827 void reclaimSomeSurfaceMemory(String operation, boolean secure) {
1828 mService.reclaimSomeSurfaceMemoryLocked(this, operation, secure);
1829 }
1830
1831 boolean getShown() {
1832 if (mSurfaceController != null) {
1833 return mSurfaceController.getShown();
1834 }
1835 return false;
1836 }
1837
1838 void destroySurface() {
Wale Ogunwale722ff892016-02-18 13:37:55 -08001839 try {
1840 if (mSurfaceController != null) {
1841 mSurfaceController.destroyInTransaction();
1842 }
1843 } catch (RuntimeException e) {
1844 Slog.w(TAG, "Exception thrown when destroying surface " + this
1845 + " surface " + mSurfaceController + " session " + mSession + ": " + e);
1846 } finally {
1847 mWin.setHasSurface(false);
1848 mSurfaceController = null;
1849 mDrawState = NO_SURFACE;
1850 }
Robert Carre6a83512015-11-03 16:09:21 -08001851 }
Filip Gruszczynskif52dd202015-11-15 20:36:38 -08001852
1853 void setMoveAnimation(int left, int top) {
1854 final Animation a = AnimationUtils.loadAnimation(mContext,
1855 com.android.internal.R.anim.window_move_from_decor);
1856 setAnimation(a);
1857 mAnimDx = mWin.mLastFrame.left - left;
1858 mAnimDy = mWin.mLastFrame.top - top;
1859 mAnimateMove = true;
1860 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001861}