blob: 969ced43b942a6c8a94dff2e5449d5eb8ded4398 [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
Wale Ogunwalee7bf46b2015-09-30 09:19:28 -070019import static android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -080020import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Robert Carr132c9f52017-07-31 17:02:30 -070021import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070022import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Jorim Jaggieb88d832016-04-13 20:17:43 -070023import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
Robert Carrfbbde852016-10-18 11:02:28 -070024import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Jorim Jaggi0a1523d2018-04-19 17:48:38 +020025import static android.view.WindowManager.TRANSIT_NONE;
chaviw9c81e632018-07-31 11:17:52 -070026
Jorim Jaggia5e10572017-11-15 14:36:26 +010027import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
28import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +010029import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080030import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080031import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
32import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
33import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020034import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080035import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -080036import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_CROP;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080037import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
38import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
39import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
40import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
41import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang97782b42015-10-07 16:01:23 -070042import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080043import static com.android.server.wm.WindowManagerService.logWithStack;
Yi Jin6c6e9ca2018-03-20 16:53:35 -070044import static com.android.server.wm.WindowStateAnimatorProto.DRAW_STATE;
45import static com.android.server.wm.WindowStateAnimatorProto.LAST_CLIP_RECT;
46import static com.android.server.wm.WindowStateAnimatorProto.SURFACE;
47import static com.android.server.wm.WindowStateAnimatorProto.SYSTEM_DECOR_RECT;
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +020048import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070049
Craig Mautnerc2f9be02012-03-27 17:32:29 -070050import android.content.Context;
51import android.graphics.Matrix;
52import android.graphics.PixelFormat;
Craig Mautner7358fbf2012-04-12 21:06:33 -070053import android.graphics.Point;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070054import android.graphics.Rect;
Craig Mautner48ba1e72012-04-02 13:18:16 -070055import android.graphics.Region;
Craig Mautnera51a9562012-04-17 17:05:26 -070056import android.os.Debug;
Chong Zhang8784be62016-06-28 15:25:07 -070057import android.os.Trace;
Craig Mautnera2c77052012-03-26 12:14:43 -070058import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -070059import android.util.proto.ProtoOutputStream;
Craig Mautner59c00972012-07-30 12:10:24 -070060import android.view.DisplayInfo;
Igor Murashkina86ab6402013-08-30 12:58:36 -070061import android.view.Surface.OutOfResourcesException;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080062import android.view.SurfaceControl;
Craig Mautnera2c77052012-03-26 12:14:43 -070063import android.view.WindowManager;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070064import android.view.WindowManager.LayoutParams;
Craig Mautnera2c77052012-03-26 12:14:43 -070065import android.view.animation.Animation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070066import android.view.animation.AnimationUtils;
Craig Mautnera2c77052012-03-26 12:14:43 -070067
Adrian Roose99bc052017-11-20 17:55:31 +010068import com.android.server.policy.WindowManagerPolicy;
69
Jorim Jaggia5e10572017-11-15 14:36:26 +010070import java.io.PrintWriter;
Craig Mautnera2c77052012-03-26 12:14:43 -070071
72/**
Craig Mautnerc2f9be02012-03-27 17:32:29 -070073 * Keep track of animations and surface operations for a single WindowState.
74 **/
Craig Mautnera2c77052012-03-26 12:14:43 -070075class WindowStateAnimator {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080076 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowStateAnimator" : TAG_WM;
Chong Zhang97782b42015-10-07 16:01:23 -070077 static final int WINDOW_FREEZE_LAYER = TYPE_LAYER_MULTIPLIER * 200;
Tiger Huang9c8ee262019-02-19 20:44:27 +080078 static final int PRESERVED_SURFACE_LAYER = 1;
Craig Mautnera2c77052012-03-26 12:14:43 -070079
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010080 /**
81 * Mode how the window gets clipped by the stack bounds during an animation: The clipping should
82 * be applied after applying the animation transformation, i.e. the stack bounds don't move
83 * during the animation.
84 */
85 static final int STACK_CLIP_AFTER_ANIM = 0;
86
87 /**
88 * Mode how the window gets clipped by the stack bounds: The clipping should be applied before
89 * applying the animation transformation, i.e. the stack bounds move with the window.
90 */
91 static final int STACK_CLIP_BEFORE_ANIM = 1;
92
93 /**
94 * Mode how window gets clipped by the stack bounds during an animation: Don't clip the window
95 * by the stack bounds.
96 */
97 static final int STACK_CLIP_NONE = 2;
98
Craig Mautner918b53b2012-07-09 14:15:54 -070099 // Unchanging local convenience fields.
Craig Mautnera2c77052012-03-26 12:14:43 -0700100 final WindowManagerService mService;
101 final WindowState mWin;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700102 final WindowAnimator mAnimator;
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 Ogunwalee4da0c12016-07-29 12:47:02 -0700107 private final WallpaperController mWallpaperControllerLocked;
Craig Mautnera2c77052012-03-26 12:14:43 -0700108
Craig Mautnera2c77052012-03-26 12:14:43 -0700109 boolean mAnimationIsEntrance;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700110
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700111 /**
112 * Set when we have changed the size of the surface, to know that
113 * we must tell them application to resize (and thus redraw itself).
114 */
115 boolean mSurfaceResized;
Chong Zhang5b2f1992015-11-13 15:40:36 -0800116 /**
117 * Whether we should inform the client on next relayoutWindow that
118 * the surface has been resized since last time.
119 */
120 boolean mReportSurfaceResized;
Robert Carre6a83512015-11-03 16:09:21 -0800121 WindowSurfaceController mSurfaceController;
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800122 private WindowSurfaceController mPendingDestroySurface;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700123
124 /**
125 * Set if the client has asked that the destroy of its surface be delayed
126 * until it explicitly says it is okay.
127 */
128 boolean mSurfaceDestroyDeferred;
129
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800130 private boolean mDestroyPreservedSurfaceUponRedraw;
Craig Mautner7d8df392012-04-06 15:26:23 -0700131 float mShownAlpha = 0;
132 float mAlpha = 0;
133 float mLastAlpha = 0;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700134
Winson Chung399f6202014-03-19 10:47:20 -0700135 Rect mTmpClipRect = new Rect();
136 Rect mLastClipRect = new Rect();
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100137 Rect mLastFinalClipRect = new Rect();
Filip Gruszczynski4b8eea72015-09-14 18:16:19 -0700138 Rect mTmpStackBounds = new Rect();
Winson Chung08f81892017-03-02 15:40:51 -0800139 private Rect mTmpAnimatingBounds = new Rect();
140 private Rect mTmpSourceBounds = new Rect();
Winson Chung399f6202014-03-19 10:47:20 -0700141
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -0800142 /**
143 * This is rectangle of the window's surface that is not covered by
144 * system decorations.
145 */
146 private final Rect mSystemDecorRect = new Rect();
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -0800147
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700148 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
Robert Carr0edf18f2017-02-21 20:01:47 -0800149 private float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700150
151 boolean mHaveMatrix;
152
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700153 // Set to true if, when the window gets displayed, it should perform
154 // an enter animation.
155 boolean mEnterAnimationPending;
Craig Mautnera2c77052012-03-26 12:14:43 -0700156
Craig Mautner9c795042014-10-28 19:59:59 -0700157 /** Used to indicate that this window is undergoing an enter animation. Used for system
158 * windows to make the callback to View.dispatchOnWindowShownCallback(). Set when the
159 * window is first added or shown, cleared when the callback has been made. */
160 boolean mEnteringAnimation;
161
Chavi Weingartenb736e322018-02-23 00:27:54 +0000162 private final SurfaceControl.Transaction mTmpTransaction = new SurfaceControl.Transaction();
163
John Reck80181b92015-05-19 11:09:32 -0700164 /** The pixel format of the underlying SurfaceControl */
165 int mSurfaceFormat;
166
Craig Mautner749a7bb2012-04-02 13:49:53 -0700167 /** This is set when there is no Surface */
168 static final int NO_SURFACE = 0;
169 /** This is set after the Surface has been created but before the window has been drawn. During
170 * this time the surface is hidden. */
171 static final int DRAW_PENDING = 1;
172 /** This is set after the window has finished drawing for the first time but before its surface
173 * is shown. The surface will be displayed when the next layout is run. */
174 static final int COMMIT_DRAW_PENDING = 2;
175 /** This is set during the time after the window's drawing has been committed, and before its
176 * surface is actually shown. It is used to delay showing the surface until all windows in a
177 * token are ready to be shown. */
178 static final int READY_TO_SHOW = 3;
179 /** Set when the window has been shown in the screen the first time. */
180 static final int HAS_DRAWN = 4;
Adrian Roos3eeb4e62014-05-19 12:43:26 +0200181
Craig Mautner276a6eb2014-11-04 15:32:57 -0800182 String drawStateToString() {
183 switch (mDrawState) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700184 case NO_SURFACE: return "NO_SURFACE";
185 case DRAW_PENDING: return "DRAW_PENDING";
186 case COMMIT_DRAW_PENDING: return "COMMIT_DRAW_PENDING";
187 case READY_TO_SHOW: return "READY_TO_SHOW";
188 case HAS_DRAWN: return "HAS_DRAWN";
Craig Mautner276a6eb2014-11-04 15:32:57 -0800189 default: return Integer.toString(mDrawState);
Craig Mautner6fbda632012-07-03 09:26:39 -0700190 }
191 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700192 int mDrawState;
Craig Mautnera608b882012-03-30 13:03:49 -0700193
Craig Mautner749a7bb2012-04-02 13:49:53 -0700194 /** Was this window last hidden? */
195 boolean mLastHidden;
Craig Mautnera608b882012-03-30 13:03:49 -0700196
Craig Mautnerbec53f72012-04-05 11:49:05 -0700197 int mAttrType;
198
Robert Carrc7294602016-05-13 11:32:05 -0700199 boolean mForceScaleUntilResize;
200
Robert Carr04092112016-06-02 12:56:12 -0700201 // WindowState.mHScale and WindowState.mVScale contain the
202 // scale according to client specified layout parameters (e.g.
203 // one layout size, with another surface size, creates such scaling).
204 // Here we track an additional scaling factor used to follow stack
205 // scaling (as in the case of the Pinned stack animation).
206 float mExtraHScale = (float) 1.0;
207 float mExtraVScale = (float) 1.0;
208
Robert Carr217e7cc2018-01-31 18:08:39 -0800209 // An offset in pixel of the surface contents from the window position. Used for Wallpaper
210 // to provide the effect of scrolling within a large surface. We just use these values as
211 // a cache.
212 int mXOffset = 0;
213 int mYOffset = 0;
214
chaviwbe43ac82018-04-04 15:14:49 -0700215 /**
216 * A flag to determine if the WSA needs to offset its position to compensate for the stack's
217 * position update before the WSA surface has resized.
218 */
219 private boolean mOffsetPositionForStackResize;
220
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800221 private final Rect mTmpSize = new Rect();
222
Robert Carrca4c5a62018-02-05 16:07:55 -0800223 private final SurfaceControl.Transaction mReparentTransaction = new SurfaceControl.Transaction();
224
Robert Carr7b3d11d2018-03-15 14:34:45 -0700225 // Used to track whether we have called detach children on the way to invisibility, in which
226 // case we need to give the client a new Surface if it lays back out to a visible state.
227 boolean mChildrenDetached = false;
228
Robert Carr2025bf842018-03-19 13:25:05 -0700229 // Set to true after the first frame of the Pinned stack animation
230 // and reset after the last to ensure we only reset mForceScaleUntilResize
231 // once per animation.
232 boolean mPipAnimationStarted = false;
233
chaviwbe43ac82018-04-04 15:14:49 -0700234 private final Point mTmpPos = new Point();
235
Craig Mautnerc431e892015-02-11 13:14:26 -0800236 WindowStateAnimator(final WindowState win) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800237 final WindowManagerService service = win.mWmService;
Craig Mautner918b53b2012-07-09 14:15:54 -0700238
Craig Mautnera2c77052012-03-26 12:14:43 -0700239 mService = service;
Craig Mautner918b53b2012-07-09 14:15:54 -0700240 mAnimator = service.mAnimator;
241 mPolicy = service.mPolicy;
242 mContext = service.mContext;
Craig Mautner918b53b2012-07-09 14:15:54 -0700243
244 mWin = win;
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;
wilsonshihc32538e2018-11-07 17:27:34 +0800248 mWallpaperControllerLocked = win.getDisplayContent().mWallpaperController;
Craig Mautnera2c77052012-03-26 12:14:43 -0700249 }
250
Jorim Jaggia5e10572017-11-15 14:36:26 +0100251 void onAnimationFinished() {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700252 // Done animating, clean up.
253 if (DEBUG_ANIM) Slog.v(
Jorim Jaggia5e10572017-11-15 14:36:26 +0100254 TAG, "Animation done in " + this + ": exiting=" + mWin.mAnimatingExit
255 + ", reportedVisible="
256 + (mWin.mAppToken != null ? mWin.mAppToken.reportedVisible : false));
Craig Mautnera2c77052012-03-26 12:14:43 -0700257
Filip Gruszczynski14b4e572015-11-03 15:53:55 -0800258 mWin.checkPolicyVisibilityChange();
Jorim Jaggia5e10572017-11-15 14:36:26 +0100259 final DisplayContent displayContent = mWin.getDisplayContent();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800260 if (mAttrType == LayoutParams.TYPE_STATUS_BAR && mWin.mPolicyVisibility) {
Craig Mautner81defc72013-10-29 11:10:42 -0700261 // Upon completion of a not-visible to visible status bar animation a relayout is
262 // required.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800263 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700264 displayContent.setLayoutNeeded();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800265 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700266 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700267 mWin.onExitAnimationDone();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800268 final int displayId = mWin.getDisplayId();
Jorim Jaggia5e10572017-11-15 14:36:26 +0100269 int pendingLayoutChanges = FINISH_LAYOUT_REDO_ANIM;
270 if (displayContent.mWallpaperController.isWallpaperTarget(mWin)) {
271 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
272 }
273 mAnimator.setPendingLayoutChanges(displayId, pendingLayoutChanges);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800274 if (DEBUG_LAYOUT_REPEATS)
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700275 mService.mWindowPlacerLocked.debugLayoutRepeats(
276 "WindowStateAnimator", mAnimator.getPendingLayoutChanges(displayId));
Craig Mautnera2c77052012-03-26 12:14:43 -0700277
278 if (mWin.mAppToken != null) {
279 mWin.mAppToken.updateReportedVisibilityLocked();
280 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700281 }
282
Chavi Weingartenb736e322018-02-23 00:27:54 +0000283 void hide(SurfaceControl.Transaction transaction, String reason) {
Craig Mautner0afddcb2012-05-08 15:38:00 -0700284 if (!mLastHidden) {
285 //dump();
286 mLastHidden = true;
Jorim Jaggi50575902018-04-10 17:49:30 +0200287
288 // We may have a preserved surface which we no longer need. If there was a quick
289 // VISIBLE, GONE, VISIBLE, GONE sequence, the surface may never draw, so we don't mark
290 // it to be destroyed in prepareSurfaceLocked.
291 markPreservedSurfaceForDestroy();
292
Wale Ogunwalef9e09782015-11-09 12:42:37 -0800293 if (mSurfaceController != null) {
Chavi Weingartenb736e322018-02-23 00:27:54 +0000294 mSurfaceController.hide(transaction, reason);
Wale Ogunwalef9e09782015-11-09 12:42:37 -0800295 }
Craig Mautner0afddcb2012-05-08 15:38:00 -0700296 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700297 }
298
Chavi Weingartenb736e322018-02-23 00:27:54 +0000299 void hide(String reason) {
300 hide(mTmpTransaction, reason);
301 SurfaceControl.mergeToGlobalTransaction(mTmpTransaction);
302 }
303
Craig Mautnera608b882012-03-30 13:03:49 -0700304 boolean finishDrawingLocked() {
Craig Mautner42d04db2014-11-06 12:13:23 -0800305 final boolean startingWindow =
306 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
307 if (DEBUG_STARTING_WINDOW && startingWindow) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700308 Slog.v(TAG, "Finishing drawing window " + mWin + ": mDrawState="
Craig Mautner276a6eb2014-11-04 15:32:57 -0800309 + drawStateToString());
Craig Mautner6fbda632012-07-03 09:26:39 -0700310 }
Robert Carr1ca6a332016-04-11 18:00:43 -0700311
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200312 boolean layoutNeeded = false;
Chong Zhang92147042016-05-09 12:47:11 -0700313
Craig Mautner749a7bb2012-04-02 13:49:53 -0700314 if (mDrawState == DRAW_PENDING) {
Robert Carre13b58e2017-08-31 14:50:44 -0700315 if (DEBUG_ANIM || SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
Chong Zhang5b2f1992015-11-13 15:40:36 -0800316 Slog.v(TAG, "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING " + mWin + " in "
Robert Carre6a83512015-11-03 16:09:21 -0800317 + mSurfaceController);
Craig Mautner42d04db2014-11-06 12:13:23 -0800318 if (DEBUG_STARTING_WINDOW && startingWindow) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700319 Slog.v(TAG, "Draw state now committed in " + mWin);
320 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700321 mDrawState = COMMIT_DRAW_PENDING;
Chong Zhangcbbcc0f2016-05-17 20:46:58 -0700322 layoutNeeded = true;
Craig Mautnera608b882012-03-30 13:03:49 -0700323 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700324
Chong Zhangcbbcc0f2016-05-17 20:46:58 -0700325 return layoutNeeded;
Craig Mautnera608b882012-03-30 13:03:49 -0700326 }
327
328 // This must be called while inside a transaction.
Craig Mautnerc431e892015-02-11 13:14:26 -0800329 boolean commitFinishDrawingLocked() {
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200330 if (DEBUG_STARTING_WINDOW_VERBOSE &&
Craig Mautner6fbda632012-07-03 09:26:39 -0700331 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
332 Slog.i(TAG, "commitFinishDrawingLocked: " + mWin + " cur mDrawState="
Craig Mautner276a6eb2014-11-04 15:32:57 -0800333 + drawStateToString());
Craig Mautner6fbda632012-07-03 09:26:39 -0700334 }
Craig Mautner276a6eb2014-11-04 15:32:57 -0800335 if (mDrawState != COMMIT_DRAW_PENDING && mDrawState != READY_TO_SHOW) {
Craig Mautnera608b882012-03-30 13:03:49 -0700336 return false;
337 }
Robert Carre13b58e2017-08-31 14:50:44 -0700338 if (DEBUG_ANIM) {
Robert Carre6a83512015-11-03 16:09:21 -0800339 Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurfaceController);
Craig Mautner6fbda632012-07-03 09:26:39 -0700340 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700341 mDrawState = READY_TO_SHOW;
Chong Zhang0275e392015-09-17 10:41:44 -0700342 boolean result = false;
Craig Mautnera608b882012-03-30 13:03:49 -0700343 final AppWindowToken atoken = mWin.mAppToken;
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +0200344 if (atoken == null || atoken.canShowWindows()
345 || mWin.mAttrs.type == TYPE_APPLICATION_STARTING) {
Wale Ogunwale9d147902016-07-16 11:58:55 -0700346 result = mWin.performShowLocked();
Chong Zhang0275e392015-09-17 10:41:44 -0700347 }
Chong Zhang97782b42015-10-07 16:01:23 -0700348 return result;
Craig Mautnera608b882012-03-30 13:03:49 -0700349 }
350
Chong Zhang97782b42015-10-07 16:01:23 -0700351 void preserveSurfaceLocked() {
352 if (mDestroyPreservedSurfaceUponRedraw) {
Chong Zhangb9b0fec2016-02-11 18:51:51 -0800353 // This could happen when switching the surface mode very fast. For example,
354 // we preserved a surface when dragResizing changed to true. Then before the
355 // preserved surface is removed, dragResizing changed to false again.
356 // In this case, we need to leave the preserved surface alone, and destroy
357 // the actual surface, so that the createSurface call could create a surface
358 // of the proper size. The preserved surface will still be removed when client
359 // finishes drawing to the new surface.
360 mSurfaceDestroyDeferred = false;
361 destroySurfaceLocked();
362 mSurfaceDestroyDeferred = true;
Chong Zhang97782b42015-10-07 16:01:23 -0700363 return;
364 }
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -0800365 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, "SET FREEZE LAYER", false);
Wale Ogunwalef9e09782015-11-09 12:42:37 -0800366 if (mSurfaceController != null) {
Robert Carrb1579c82017-09-05 14:54:47 -0700367 // Our SurfaceControl is always at layer 0 within the parent Surface managed by
368 // window-state. We want this old Surface to stay on top of the new one
Tiger Huang9c8ee262019-02-19 20:44:27 +0800369 // until we do the swap, so we place it at a positive layer.
370 mSurfaceController.mSurfaceControl.setLayer(PRESERVED_SURFACE_LAYER);
Wale Ogunwalef9e09782015-11-09 12:42:37 -0800371 }
Chong Zhang97782b42015-10-07 16:01:23 -0700372 mDestroyPreservedSurfaceUponRedraw = true;
373 mSurfaceDestroyDeferred = true;
374 destroySurfaceLocked();
375 }
376
377 void destroyPreservedSurfaceLocked() {
378 if (!mDestroyPreservedSurfaceUponRedraw) {
379 return;
380 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800381 if (mSurfaceController != null) {
382 if (mPendingDestroySurface != null) {
383 // If we are preserving a surface but we aren't relaunching that means
384 // we are just doing an in-place switch. In that case any SurfaceFlinger side
385 // child layers need to be reparented to the new surface to make this
386 // transparent to the app.
387 if (mWin.mAppToken == null || mWin.mAppToken.isRelaunching() == false) {
Robert Carrca4c5a62018-02-05 16:07:55 -0800388 mReparentTransaction.reparentChildren(mPendingDestroySurface.mSurfaceControl,
389 mSurfaceController.mSurfaceControl.getHandle())
390 .apply();
Robert Carrd5c7dd62017-03-08 10:39:30 -0800391 }
392 }
393 }
394
Chong Zhang97782b42015-10-07 16:01:23 -0700395 destroyDeferredSurfaceLocked();
396 mDestroyPreservedSurfaceUponRedraw = false;
397 }
398
Chong Zhangeb665572016-05-09 18:28:27 -0700399 void markPreservedSurfaceForDestroy() {
400 if (mDestroyPreservedSurfaceUponRedraw
401 && !mService.mDestroyPreservedSurface.contains(mWin)) {
402 mService.mDestroyPreservedSurface.add(mWin);
403 }
404 }
405
Robert Carrda61ba92017-03-29 15:52:23 -0700406 private int getLayerStack() {
407 return mWin.getDisplayContent().getDisplay().getLayerStack();
408 }
409
Robert Carrecc06b32017-04-18 14:25:10 -0700410 void resetDrawState() {
411 mDrawState = DRAW_PENDING;
412
413 if (mWin.mAppToken == null) {
414 return;
415 }
416
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200417 if (!mWin.mAppToken.isSelfAnimating()) {
Robert Carrecc06b32017-04-18 14:25:10 -0700418 mWin.mAppToken.clearAllDrawn();
419 } else {
420 // Currently animating, persist current state of allDrawn until animation
421 // is complete.
422 mWin.mAppToken.deferClearAllDrawn = true;
423 }
424 }
425
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500426 WindowSurfaceController createSurfaceLocked(int windowType, int ownerUid) {
Alan Viveretteccb11e12014-07-08 16:04:02 -0700427 final WindowState w = mWin;
Chong Zhanga8975bd2016-01-28 17:13:47 -0800428
Wale Ogunwale722ff892016-02-18 13:37:55 -0800429 if (mSurfaceController != null) {
430 return mSurfaceController;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700431 }
Robert Carr7b3d11d2018-03-15 14:34:45 -0700432 mChildrenDetached = false;
Wale Ogunwale722ff892016-02-18 13:37:55 -0800433
Robert Carr132c9f52017-07-31 17:02:30 -0700434 if ((mWin.mAttrs.privateFlags & PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY) != 0) {
435 windowType = SurfaceControl.WINDOW_TYPE_DONT_SCREENSHOT;
436 }
437
Wale Ogunwale722ff892016-02-18 13:37:55 -0800438 w.setHasSurface(false);
439
440 if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG,
441 "createSurface " + this + ": mDrawState=DRAW_PENDING");
442
Robert Carrecc06b32017-04-18 14:25:10 -0700443 resetDrawState();
Wale Ogunwale722ff892016-02-18 13:37:55 -0800444
445 mService.makeWindowFreezingScreenIfNeededLocked(w);
446
447 int flags = SurfaceControl.HIDDEN;
448 final WindowManager.LayoutParams attrs = w.mAttrs;
449
450 if (mService.isSecureLocked(w)) {
451 flags |= SurfaceControl.SECURE;
452 }
453
chaviw9c81e632018-07-31 11:17:52 -0700454 calculateSurfaceBounds(w, attrs, mTmpSize);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800455 final int width = mTmpSize.width();
456 final int height = mTmpSize.height();
457
458 if (DEBUG_VISIBILITY) {
459 Slog.v(TAG, "Creating surface in session "
460 + mSession.mSurfaceSession + " window " + this
461 + " w=" + width + " h=" + height
462 + " x=" + mTmpSize.left + " y=" + mTmpSize.top
463 + " format=" + attrs.format + " flags=" + flags);
464 }
465
466 // We may abort, so initialize to defaults.
Wale Ogunwale722ff892016-02-18 13:37:55 -0800467 mLastClipRect.set(0, 0, 0, 0);
468
469 // Set up surface control with initial size.
470 try {
471
472 final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0;
473 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
474 if (!PixelFormat.formatHasAlpha(attrs.format)
475 // Don't make surface with surfaceInsets opaque as they display a
476 // translucent shadow.
477 && attrs.surfaceInsets.left == 0
478 && attrs.surfaceInsets.top == 0
479 && attrs.surfaceInsets.right == 0
480 && attrs.surfaceInsets.bottom == 0
481 // Don't make surface opaque when resizing to reduce the amount of
482 // artifacts shown in areas the app isn't drawing content to.
483 && !w.isDragResizing()) {
484 flags |= SurfaceControl.OPAQUE;
485 }
486
487 mSurfaceController = new WindowSurfaceController(mSession.mSurfaceSession,
Jorim Jaggia5e10572017-11-15 14:36:26 +0100488 attrs.getTitle().toString(), width, height, format, flags, this,
489 windowType, ownerUid);
chaviwbe43ac82018-04-04 15:14:49 -0700490
491 setOffsetPositionForStackResize(false);
Robert Carr486bbb72017-05-30 11:25:22 -0700492 mSurfaceFormat = format;
Wale Ogunwale722ff892016-02-18 13:37:55 -0800493
494 w.setHasSurface(true);
495
496 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
497 Slog.i(TAG, " CREATE SURFACE "
498 + mSurfaceController + " IN SESSION "
499 + mSession.mSurfaceSession
500 + ": pid=" + mSession.mPid + " format="
501 + attrs.format + " flags=0x"
502 + Integer.toHexString(flags)
503 + " / " + this);
504 }
505 } catch (OutOfResourcesException e) {
506 Slog.w(TAG, "OutOfResourcesException creating surface");
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700507 mService.mRoot.reclaimSomeSurfaceMemory(this, "create", true);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800508 mDrawState = NO_SURFACE;
509 return null;
510 } catch (Exception e) {
Robert Carrb0f39362018-03-14 13:52:25 -0700511 Slog.e(TAG, "Exception creating surface (parent dead?)", e);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800512 mDrawState = NO_SURFACE;
513 return null;
514 }
515
516 if (WindowManagerService.localLOGV) Slog.v(TAG, "Got surface: " + mSurfaceController
Jorim Jaggi35d328a2018-08-14 17:00:20 +0200517 + ", set left=" + w.getFrameLw().left + " top=" + w.getFrameLw().top);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800518
519 if (SHOW_LIGHT_TRANSACTIONS) {
520 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
521 WindowManagerService.logSurface(w, "CREATE pos=("
chaviw492139a2018-07-16 16:07:35 -0700522 + w.getFrameLw().left + "," + w.getFrameLw().top + ") ("
Jorim Jaggi35d328a2018-08-14 17:00:20 +0200523 + width + "x" + height + ")" + " HIDE", false);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800524 }
525
Wale Ogunwale722ff892016-02-18 13:37:55 -0800526 mLastHidden = true;
527
528 if (WindowManagerService.localLOGV) Slog.v(TAG, "Created surface " + this);
Robert Carre6a83512015-11-03 16:09:21 -0800529 return mSurfaceController;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700530 }
531
chaviw9c81e632018-07-31 11:17:52 -0700532 private void calculateSurfaceBounds(WindowState w, LayoutParams attrs, Rect outSize) {
533 outSize.setEmpty();
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800534 if ((attrs.flags & FLAG_SCALED) != 0) {
535 // For a scaled surface, we always want the requested size.
chaviw9c81e632018-07-31 11:17:52 -0700536 outSize.right = w.mRequestedWidth;
537 outSize.bottom = w.mRequestedHeight;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800538 } else {
539 // When we're doing a drag-resizing, request a surface that's fullscreen size,
540 // so that we don't need to reallocate during the process. This also prevents
541 // buffer drops due to size mismatch.
542 if (w.isDragResizing()) {
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800543 final DisplayInfo displayInfo = w.getDisplayInfo();
chaviw9c81e632018-07-31 11:17:52 -0700544 outSize.right = displayInfo.logicalWidth;
545 outSize.bottom = displayInfo.logicalHeight;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800546 } else {
chaviw9c81e632018-07-31 11:17:52 -0700547 w.getCompatFrameSize(outSize);
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800548 }
549 }
550
551 // Something is wrong and SurfaceFlinger will not like this, try to revert to sane values.
Filip Gruszczynskie6ed1952015-12-21 09:34:16 -0800552 // This doesn't necessarily mean that there is an error in the system. The sizes might be
553 // incorrect, because it is before the first layout or draw.
chaviw9c81e632018-07-31 11:17:52 -0700554 if (outSize.width() < 1) {
555 outSize.right = 1;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800556 }
chaviw9c81e632018-07-31 11:17:52 -0700557 if (outSize.height() < 1) {
558 outSize.bottom = 1;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800559 }
560
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800561 // Adjust for surface insets.
chaviw9c81e632018-07-31 11:17:52 -0700562 outSize.inset(-attrs.surfaceInsets.left, -attrs.surfaceInsets.top,
563 -attrs.surfaceInsets.right, -attrs.surfaceInsets.bottom);
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800564 }
565
Chong Zhangeb22e8e2016-01-20 19:52:22 -0800566 boolean hasSurface() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200567 return mSurfaceController != null && mSurfaceController.hasSurface();
Chong Zhangeb22e8e2016-01-20 19:52:22 -0800568 }
569
Craig Mautner96868332012-12-04 14:29:11 -0800570 void destroySurfaceLocked() {
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700571 final AppWindowToken wtoken = mWin.mAppToken;
572 if (wtoken != null) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700573 if (mWin == wtoken.startingWindow) {
574 wtoken.startingDisplayed = false;
575 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700576 }
577
Wale Ogunwale722ff892016-02-18 13:37:55 -0800578 if (mSurfaceController == null) {
579 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700580 }
Wale Ogunwale722ff892016-02-18 13:37:55 -0800581
Wale Ogunwale722ff892016-02-18 13:37:55 -0800582 // When destroying a surface we want to make sure child windows are hidden. If we are
583 // preserving the surface until redraw though we intend to swap it out with another surface
584 // for resizing. In this case the window always remains visible to the user and the child
585 // windows should likewise remain visible.
Wale Ogunwale9d147902016-07-16 11:58:55 -0700586 if (!mDestroyPreservedSurfaceUponRedraw) {
587 mWin.mHidden = true;
Wale Ogunwale722ff892016-02-18 13:37:55 -0800588 }
589
590 try {
591 if (DEBUG_VISIBILITY) logWithStack(TAG, "Window " + this + " destroying surface "
592 + mSurfaceController + ", session " + mSession);
593 if (mSurfaceDestroyDeferred) {
594 if (mSurfaceController != null && mPendingDestroySurface != mSurfaceController) {
595 if (mPendingDestroySurface != null) {
596 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
597 WindowManagerService.logSurface(mWin, "DESTROY PENDING", true);
598 }
Robert Carra8828862018-02-05 16:17:36 -0800599 mPendingDestroySurface.destroyNotInTransaction();
Wale Ogunwale722ff892016-02-18 13:37:55 -0800600 }
601 mPendingDestroySurface = mSurfaceController;
602 }
603 } else {
604 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
605 WindowManagerService.logSurface(mWin, "DESTROY", true);
606 }
607 destroySurface();
608 }
609 // Don't hide wallpaper if we're deferring the surface destroy
610 // because of a surface change.
611 if (!mDestroyPreservedSurfaceUponRedraw) {
612 mWallpaperControllerLocked.hideWallpapers(mWin);
613 }
614 } catch (RuntimeException e) {
615 Slog.w(TAG, "Exception thrown when destroying Window " + this
616 + " surface " + mSurfaceController + " session " + mSession + ": " + e.toString());
617 }
618
619 // Whether the surface was preserved (and copied to mPendingDestroySurface) or not, it
620 // needs to be cleared to match the WindowState.mHasSurface state. It is also necessary
621 // so it can be recreated successfully in mPendingDestroySurface case.
622 mWin.setHasSurface(false);
623 if (mSurfaceController != null) {
624 mSurfaceController.setShown(false);
625 }
626 mSurfaceController = null;
627 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700628 }
629
Craig Mautner96868332012-12-04 14:29:11 -0800630 void destroyDeferredSurfaceLocked() {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700631 try {
632 if (mPendingDestroySurface != null) {
633 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -0800634 WindowManagerService.logSurface(mWin, "DESTROY PENDING", true);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700635 }
Robert Carra8828862018-02-05 16:17:36 -0800636 mPendingDestroySurface.destroyNotInTransaction();
Chong Zhang6e21cf42015-11-09 14:41:42 -0800637 // Don't hide wallpaper if we're destroying a deferred surface
638 // after a surface mode change.
639 if (!mDestroyPreservedSurfaceUponRedraw) {
640 mWallpaperControllerLocked.hideWallpapers(mWin);
641 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700642 }
643 } catch (RuntimeException e) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700644 Slog.w(TAG, "Exception thrown when destroying Window "
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700645 + this + " surface " + mPendingDestroySurface
646 + " session " + mSession + ": " + e.toString());
647 }
648 mSurfaceDestroyDeferred = false;
649 mPendingDestroySurface = null;
650 }
651
652 void computeShownFrameLocked() {
Craig Mautnera91f9e22012-09-14 16:22:08 -0700653 final int displayId = mWin.getDisplayId();
654 final ScreenRotationAnimation screenRotationAnimation =
655 mAnimator.getScreenRotationAnimationLocked(displayId);
Vishnu Nair83537a72018-07-19 21:27:48 -0700656 final boolean windowParticipatesInScreenRotationAnimation =
657 !mWin.mForceSeamlesslyRotate;
658 final boolean screenAnimation = screenRotationAnimation != null
659 && screenRotationAnimation.isAnimating()
660 && windowParticipatesInScreenRotationAnimation;
Robert Carr2f0fe622015-09-25 14:56:38 -0700661
Robert Carr44643c12017-09-27 14:57:38 -0700662 if (screenAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700663 // cache often used attributes locally
chaviw492139a2018-07-16 16:07:35 -0700664 final Rect frame = mWin.getFrameLw();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700665 final float tmpFloats[] = mService.mTmpFloats;
666 final Matrix tmpMatrix = mWin.mTmpMatrix;
667
668 // Compute the desired transformation.
Robert Carr44643c12017-09-27 14:57:38 -0700669 if (screenRotationAnimation.isRotating()) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700670 // If we are doing a screen animation, the global rotation
671 // applied to windows can result in windows that are carefully
672 // aligned with each other to slightly separate, allowing you
673 // to see what is behind them. An unsightly mess. This...
674 // thing... magically makes it call good: scale each window
675 // slightly (two pixels larger in each dimension, from the
676 // window's center).
677 final float w = frame.width();
678 final float h = frame.height();
679 if (w>=1 && h>=1) {
680 tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2);
681 } else {
682 tmpMatrix.reset();
683 }
684 } else {
685 tmpMatrix.reset();
686 }
Robert Carr44643c12017-09-27 14:57:38 -0700687
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700688 tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale);
Robert Carr29d196f2017-11-28 12:39:46 -0800689
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100690 // WindowState.prepareSurfaces expands for surface insets (in order they don't get
691 // clipped by the WindowState surface), so we need to go into the other direction here.
Robert Carr217e7cc2018-01-31 18:08:39 -0800692 tmpMatrix.postTranslate(mWin.mAttrs.surfaceInsets.left,
693 mWin.mAttrs.surfaceInsets.top);
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100694
Matthew Ng34a06d12017-02-03 11:56:08 -0800695
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700696 // "convert" it into SurfaceFlinger's format
697 // (a 2x2 matrix + an offset)
698 // Here we must not transform the position of the surface
699 // since it is already included in the transformation.
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800700 //Slog.i(TAG_WM, "Transform: " + matrix);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700701
702 mHaveMatrix = true;
703 tmpMatrix.getValues(tmpFloats);
704 mDsDx = tmpFloats[Matrix.MSCALE_X];
705 mDtDx = tmpFloats[Matrix.MSKEW_Y];
Robert Carr0edf18f2017-02-21 20:01:47 -0800706 mDtDy = tmpFloats[Matrix.MSKEW_X];
707 mDsDy = tmpFloats[Matrix.MSCALE_Y];
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700708
709 // Now set the alpha... but because our current hardware
710 // can't do alpha transformation on a non-opaque surface,
711 // turn it off if we are running an animation that is also
712 // transforming since it is more important to have that
713 // animation be smooth.
714 mShownAlpha = mAlpha;
715 if (!mService.mLimitedAlphaCompositing
716 || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format)
Robert Carr217e7cc2018-01-31 18:08:39 -0800717 || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDtDy, mDsDy)))) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800718 //Slog.i(TAG_WM, "Applying alpha transform");
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700719 if (screenAnimation) {
Craig Mautnera91f9e22012-09-14 16:22:08 -0700720 mShownAlpha *= screenRotationAnimation.getEnterTransformation().getAlpha();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700721 }
722 } else {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800723 //Slog.i(TAG_WM, "Not applying alpha transform");
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700724 }
725
Robert Carre13b58e2017-08-31 14:50:44 -0700726 if ((DEBUG_ANIM || WindowManagerService.localLOGV)
Craig Mautnera91f9e22012-09-14 16:22:08 -0700727 && (mShownAlpha == 1.0 || mShownAlpha == 0.0)) Slog.v(
728 TAG, "computeShownFrameLocked: Animating " + this + " mAlpha=" + mAlpha
Craig Mautnera91f9e22012-09-14 16:22:08 -0700729 + " screen=" + (screenAnimation ?
730 screenRotationAnimation.getEnterTransformation().getAlpha() : "null"));
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700731 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700732 } else if (mIsWallpaper && mService.mRoot.mWallpaperActionPending) {
Craig Mautner4d7349b2012-04-20 14:52:47 -0700733 return;
Chong Zhang3005e752015-09-18 18:46:28 -0700734 } else if (mWin.isDragResizeChanged()) {
735 // This window is awaiting a relayout because user just started (or ended)
736 // drag-resizing. The shown frame (which affects surface size and pos)
737 // should not be updated until we get next finished draw with the new surface.
738 // Otherwise one or two frames rendered with old settings would be displayed
739 // with new geometry.
740 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700741 }
742
Filip Gruszczynski19723a42015-11-25 15:01:48 -0800743 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautner4d7349b2012-04-20 14:52:47 -0700744 TAG, "computeShownFrameLocked: " + this +
745 " not attached, mAlpha=" + mAlpha);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700746
Robert Carrb1579c82017-09-05 14:54:47 -0700747 mShownAlpha = mAlpha;
748 mHaveMatrix = false;
749 mDsDx = mWin.mGlobalScale;
750 mDtDx = 0;
751 mDtDy = 0;
752 mDsDy = mWin.mGlobalScale;
Robert Carref090ac2017-05-15 16:45:50 -0700753 }
754
Robert Carrfbbde852016-10-18 11:02:28 -0700755 /**
Robert Carrfbbde852016-10-18 11:02:28 -0700756 * Calculate the window-space crop rect and fill clipRect.
Wale Ogunwaleca9e0612016-12-02 07:45:59 -0800757 * @return true if clipRect has been filled otherwise, no window space crop should be applied.
Robert Carrfbbde852016-10-18 11:02:28 -0700758 */
Wale Ogunwaleca9e0612016-12-02 07:45:59 -0800759 private boolean calculateCrop(Rect clipRect) {
Robert Carrfbbde852016-10-18 11:02:28 -0700760 final WindowState w = mWin;
761 final DisplayContent displayContent = w.getDisplayContent();
762 clipRect.setEmpty();
763
764 if (displayContent == null) {
765 return false;
766 }
767
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700768 if (w.inPinnedWindowingMode()) {
Robert Carrfbbde852016-10-18 11:02:28 -0700769 return false;
770 }
771
Vishnu Nair83537a72018-07-19 21:27:48 -0700772 // During forced seamless rotation, the surface bounds get updated with the crop in the
773 // new rotation, which is not compatible with showing the surface in the old rotation.
774 // To work around that we disable cropping for such windows, as it is not necessary anyways.
775 if (w.mForceSeamlesslyRotate) {
776 return false;
777 }
778
Robert Carrfbbde852016-10-18 11:02:28 -0700779 // If we're animating, the wallpaper should only
780 // be updated at the end of the animation.
781 if (w.mAttrs.type == TYPE_WALLPAPER) {
782 return false;
783 }
784
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -0700785 if (DEBUG_WINDOW_CROP) Slog.d(TAG,
786 "Updating crop win=" + w + " mLastCrop=" + mLastClipRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -0700787
Robert Carrfbbde852016-10-18 11:02:28 -0700788 w.calculatePolicyCrop(mSystemDecorRect);
789
790 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "Applying decor to crop win=" + w + " mDecorFrame="
chaviw553b0212018-07-12 13:37:01 -0700791 + w.getDecorFrame() + " mSystemDecorRect=" + mSystemDecorRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -0700792
Andrii Kulian283acd22017-08-03 04:03:51 -0700793 final Task task = w.getTask();
794 final boolean fullscreen = w.fillsDisplay() || (task != null && task.isFullscreen());
Jorim Jaggi253a20f2015-11-03 12:38:42 +0100795 final boolean isFreeformResizing =
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100796 w.isDragResizing() && w.getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
Robert Carr51a1b872015-12-08 14:03:13 -0800797
798 // We use the clip rect as provided by the tranformation for non-fullscreen windows to
799 // avoid premature clipping with the system decor rect.
Robert Carrf0586622018-01-29 13:03:43 -0800800 clipRect.set(mSystemDecorRect);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -0700801 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "win=" + w + " Initial clip rect: " + clipRect
Robert Carrf0586622018-01-29 13:03:43 -0800802 + " fullscreen=" + fullscreen);
Robert Carr51a1b872015-12-08 14:03:13 -0800803
Robert Carrfbbde852016-10-18 11:02:28 -0700804 w.expandForSurfaceInsets(clipRect);
Alan Viverette49a22e82014-07-12 20:01:27 -0700805
Alan Viverette49a22e82014-07-12 20:01:27 -0700806 // The clip rect was generated assuming (0,0) as the window origin,
807 // so we need to translate to match the actual surface coordinates.
Robert Carrfbbde852016-10-18 11:02:28 -0700808 clipRect.offset(w.mAttrs.surfaceInsets.left, w.mAttrs.surfaceInsets.top);
Robert Carr58f29132015-10-29 14:19:05 -0700809
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -0700810 if (DEBUG_WINDOW_CROP) Slog.d(TAG,
811 "win=" + w + " Clip rect after stack adjustment=" + clipRect);
Robert Carr58f29132015-10-29 14:19:05 -0700812
Chia-I Wue6bcaf12016-05-27 10:58:48 +0800813 w.transformClipRectFromScreenToSurfaceSpace(clipRect);
Robert Carr58f29132015-10-29 14:19:05 -0700814
Robert Carrfbbde852016-10-18 11:02:28 -0700815 return true;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800816 }
817
chaviw23012112017-12-20 15:29:04 -0800818 private void applyCrop(Rect clipRect, boolean recoveringMemory) {
Robert Carrfbbde852016-10-18 11:02:28 -0700819 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "applyCrop: win=" + mWin
chaviw23012112017-12-20 15:29:04 -0800820 + " clipRect=" + clipRect);
Robert Carr4320d332016-06-10 15:13:32 -0700821 if (clipRect != null) {
822 if (!clipRect.equals(mLastClipRect)) {
823 mLastClipRect.set(clipRect);
824 mSurfaceController.setCropInTransaction(clipRect, recoveringMemory);
825 }
826 } else {
827 mSurfaceController.clearCropInTransaction(recoveringMemory);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -0700828 }
Filip Gruszczynski4b8eea72015-09-14 18:16:19 -0700829 }
830
Wale Ogunwale4c8b7952015-04-07 10:49:40 -0700831 void setSurfaceBoundariesLocked(final boolean recoveringMemory) {
Wale Ogunwale027f4752017-05-12 10:37:16 -0700832 if (mSurfaceController == null) {
833 return;
834 }
835
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700836 final WindowState w = mWin;
Winson Chung08f81892017-03-02 15:40:51 -0800837 final LayoutParams attrs = mWin.getAttrs();
Robert Carr0d00c2e2016-02-29 17:45:02 -0800838 final Task task = w.getTask();
Alan Viveretteccb11e12014-07-08 16:04:02 -0700839
chaviw9c81e632018-07-31 11:17:52 -0700840 calculateSurfaceBounds(w, attrs, mTmpSize);
Chong Zhang0275e392015-09-17 10:41:44 -0700841
Robert Carr04092112016-06-02 12:56:12 -0700842 mExtraHScale = (float) 1.0;
843 mExtraVScale = (float) 1.0;
Robert Carre1034cc32016-02-01 13:08:15 -0800844
Robert Carr6da3cc02016-06-16 15:17:07 -0700845 boolean wasForceScaled = mForceScaleUntilResize;
Robert Carr6da3cc02016-06-16 15:17:07 -0700846
Robert Carrfed10072016-05-26 11:48:49 -0700847 // Once relayout has been called at least once, we need to make sure
848 // we only resize the client surface during calls to relayout. For
849 // clients which use indeterminate measure specs (MATCH_PARENT),
850 // we may try and change their window size without a call to relayout.
851 // However, this would be unsafe, as the client may be in the middle
852 // of producing a frame at the old size, having just completed layout
853 // to find the surface size changed underneath it.
chaviwbe43ac82018-04-04 15:14:49 -0700854 final boolean relayout = !w.mRelayoutCalled || w.mInRelayout;
855 if (relayout) {
Vishnu Naire86bd982018-11-28 13:23:17 -0800856 mSurfaceResized = mSurfaceController.setBufferSizeInTransaction(
Robert Carrfed10072016-05-26 11:48:49 -0700857 mTmpSize.width(), mTmpSize.height(), recoveringMemory);
858 } else {
859 mSurfaceResized = false;
860 }
Robert Carrc7294602016-05-13 11:32:05 -0700861 mForceScaleUntilResize = mForceScaleUntilResize && !mSurfaceResized;
Robert Carr6da3cc02016-06-16 15:17:07 -0700862 // If we are undergoing seamless rotation, the surface has already
863 // been set up to persist at it's old location. We need to freeze
864 // updates until a resize occurs.
Robert Carrc7294602016-05-13 11:32:05 -0700865
chaviw23012112017-12-20 15:29:04 -0800866 Rect clipRect = null;
Robert Carrfbbde852016-10-18 11:02:28 -0700867 if (calculateCrop(mTmpClipRect)) {
868 clipRect = mTmpClipRect;
869 }
Robert Carra9408d42016-06-03 13:28:48 -0700870
871 float surfaceWidth = mSurfaceController.getWidth();
872 float surfaceHeight = mSurfaceController.getHeight();
873
Robert Carr74a66a22018-02-23 12:17:51 -0800874 final Rect insets = attrs.surfaceInsets;
875
Robert Carr8f0a3ad2017-02-15 19:30:28 -0800876 if (isForceScaled()) {
Robert Carr74a66a22018-02-23 12:17:51 -0800877 int hInsets = insets.left + insets.right;
878 int vInsets = insets.top + insets.bottom;
Winson Chung08f81892017-03-02 15:40:51 -0800879 float surfaceContentWidth = surfaceWidth - hInsets;
880 float surfaceContentHeight = surfaceHeight - vInsets;
Robert Carra9408d42016-06-03 13:28:48 -0700881 if (!mForceScaleUntilResize) {
882 mSurfaceController.forceScaleableInTransaction(true);
883 }
Robert Carrfd4c9892017-02-01 10:28:28 -0800884
Robert Carr74a66a22018-02-23 12:17:51 -0800885 int posX = 0;
886 int posY = 0;
Robert Carrfd4c9892017-02-01 10:28:28 -0800887 task.mStack.getDimBounds(mTmpStackBounds);
Robert Carr18f622f2017-05-08 11:20:43 -0700888
889 boolean allowStretching = false;
Winson Chung8bca9e42017-04-16 15:59:43 -0700890 task.mStack.getFinalAnimationSourceHintBounds(mTmpSourceBounds);
Robert Carr18f622f2017-05-08 11:20:43 -0700891 // If we don't have source bounds, we can attempt to use the content insets
892 // in the following scenario:
893 // 1. We have content insets.
894 // 2. We are not transitioning to full screen
895 // We have to be careful to check "lastAnimatingBoundsWasToFullscreen" rather than
896 // the mBoundsAnimating state, as we may have already left it and only be here
897 // because of the force-scale until resize state.
898 if (mTmpSourceBounds.isEmpty() && (mWin.mLastRelayoutContentInsets.width() > 0
899 || mWin.mLastRelayoutContentInsets.height() > 0)
900 && !task.mStack.lastAnimatingBoundsWasToFullscreen()) {
901 mTmpSourceBounds.set(task.mStack.mPreAnimationBounds);
902 mTmpSourceBounds.inset(mWin.mLastRelayoutContentInsets);
903 allowStretching = true;
904 }
Adrian Roos604ef952018-05-15 20:13:13 +0200905
906 // Make sure that what we're animating to and from is actually the right size in case
907 // the window cannot take up the full screen.
chaviw553b0212018-07-12 13:37:01 -0700908 mTmpStackBounds.intersectUnchecked(w.getParentFrame());
909 mTmpSourceBounds.intersectUnchecked(w.getParentFrame());
910 mTmpAnimatingBounds.intersectUnchecked(w.getParentFrame());
Adrian Roos604ef952018-05-15 20:13:13 +0200911
Winson Chung08f81892017-03-02 15:40:51 -0800912 if (!mTmpSourceBounds.isEmpty()) {
913 // Get the final target stack bounds, if we are not animating, this is just the
914 // current stack bounds
Winson Chung40a5f932017-04-13 16:39:36 -0700915 task.mStack.getFinalAnimationBounds(mTmpAnimatingBounds);
Winson Chung08f81892017-03-02 15:40:51 -0800916
917 // Calculate the current progress and interpolate the difference between the target
918 // and source bounds
919 float finalWidth = mTmpAnimatingBounds.width();
920 float initialWidth = mTmpSourceBounds.width();
Robert Carr18f622f2017-05-08 11:20:43 -0700921 float tw = (surfaceContentWidth - mTmpStackBounds.width())
Winson Chung08f81892017-03-02 15:40:51 -0800922 / (surfaceContentWidth - mTmpAnimatingBounds.width());
Robert Carr18f622f2017-05-08 11:20:43 -0700923 float th = tw;
924 mExtraHScale = (initialWidth + tw * (finalWidth - initialWidth)) / initialWidth;
925 if (allowStretching) {
926 float finalHeight = mTmpAnimatingBounds.height();
927 float initialHeight = mTmpSourceBounds.height();
928 th = (surfaceContentHeight - mTmpStackBounds.height())
929 / (surfaceContentHeight - mTmpAnimatingBounds.height());
930 mExtraVScale = (initialHeight + tw * (finalHeight - initialHeight))
931 / initialHeight;
932 } else {
933 mExtraVScale = mExtraHScale;
934 }
Winson Chung08f81892017-03-02 15:40:51 -0800935
936 // Adjust the position to account for the inset bounds
Robert Carr18f622f2017-05-08 11:20:43 -0700937 posX -= (int) (tw * mExtraHScale * mTmpSourceBounds.left);
938 posY -= (int) (th * mExtraVScale * mTmpSourceBounds.top);
Winson Chung08f81892017-03-02 15:40:51 -0800939
Robert Carr74a66a22018-02-23 12:17:51 -0800940 // In pinned mode the clip rectangle applied to us by our stack has been
941 // expanded outwards to allow for shadows. However in case of source bounds set
942 // we need to crop to within the surface. The code above has scaled and positioned
943 // the surface to fit the unexpanded stack bounds, but now we need to reapply
944 // the cropping that the stack would have applied if it weren't expanded. This
945 // can be different in each direction based on the source bounds.
946 clipRect = mTmpClipRect;
947 clipRect.set((int)((insets.left + mTmpSourceBounds.left) * tw),
948 (int)((insets.top + mTmpSourceBounds.top) * th),
949 insets.left + (int)(surfaceWidth
950 - (tw* (surfaceWidth - mTmpSourceBounds.right))),
951 insets.top + (int)(surfaceHeight
952 - (th * (surfaceHeight - mTmpSourceBounds.bottom))));
Winson Chung08f81892017-03-02 15:40:51 -0800953 } else {
954 // We want to calculate the scaling based on the content area, not based on
955 // the entire surface, so that we scale in sync with windows that don't have insets.
956 mExtraHScale = mTmpStackBounds.width() / surfaceContentWidth;
957 mExtraVScale = mTmpStackBounds.height() / surfaceContentHeight;
958
959 // Since we are scaled to fit in our previously desired crop, we can now
960 // expose the whole window in buffer space, and not risk extending
961 // past where the system would have cropped us
962 clipRect = null;
Winson Chung08f81892017-03-02 15:40:51 -0800963 }
Robert Carr0d00c2e2016-02-29 17:45:02 -0800964
Robert Carrfd4c9892017-02-01 10:28:28 -0800965 // In the case of ForceScaleToStack we scale entire tasks together,
Robert Carr0d00c2e2016-02-29 17:45:02 -0800966 // and so we need to scale our offsets relative to the task bounds
967 // or parent and child windows would fall out of alignment.
Winson Chung08f81892017-03-02 15:40:51 -0800968 posX -= (int) (attrs.x * (1 - mExtraHScale));
969 posY -= (int) (attrs.y * (1 - mExtraVScale));
970
Robert Carrbc133762016-05-12 14:04:38 -0700971 // Imagine we are scaling down. As we scale the buffer down, we decrease the
972 // distance between the surface top left, and the start of the surface contents
973 // (previously it was surfaceInsets.left pixels in screen space but now it
Robert Carr04092112016-06-02 12:56:12 -0700974 // will be surfaceInsets.left*mExtraHScale). This means in order to keep the
Robert Carrbc133762016-05-12 14:04:38 -0700975 // non inset content at the same position, we have to shift the whole window
976 // forward. Likewise for scaling up, we've increased this distance, and we need
977 // to shift by a negative number to compensate.
Robert Carr74a66a22018-02-23 12:17:51 -0800978 posX += insets.left * (1 - mExtraHScale);
979 posY += insets.top * (1 - mExtraVScale);
Robert Carrbc133762016-05-12 14:04:38 -0700980
Winson Chung08f81892017-03-02 15:40:51 -0800981 mSurfaceController.setPositionInTransaction((float) Math.floor(posX),
982 (float) Math.floor(posY), recoveringMemory);
Robert Carrc7294602016-05-13 11:32:05 -0700983
984 // Various surfaces in the scaled stack may resize at different times.
985 // We need to ensure for each surface, that we disable transformation matrix
986 // scaling in the same transaction which we resize the surface in.
987 // As we are in SCALING_MODE_SCALE_TO_WINDOW, SurfaceFlinger will
Robert Carra9408d42016-06-03 13:28:48 -0700988 // then take over the scaling until the new buffer arrives, and things
Robert Carrc7294602016-05-13 11:32:05 -0700989 // will be seamless.
Robert Carr2025bf842018-03-19 13:25:05 -0700990 if (mPipAnimationStarted == false) {
991 mForceScaleUntilResize = true;
992 mPipAnimationStarted = true;
993 }
Rob Carr06be6bb2018-02-06 16:26:06 +0000994 } else {
Robert Carr2025bf842018-03-19 13:25:05 -0700995 mPipAnimationStarted = false;
996
Rob Carr06be6bb2018-02-06 16:26:06 +0000997 if (!w.mSeamlesslyRotated) {
chaviwbe43ac82018-04-04 15:14:49 -0700998 // Used to offset the WSA when stack position changes before a resize.
999 int xOffset = mXOffset;
1000 int yOffset = mYOffset;
1001 if (mOffsetPositionForStackResize) {
1002 if (relayout) {
1003 // Once a relayout is called, reset the offset back to 0 and defer
1004 // setting it until a new frame with the updated size. This ensures that
1005 // the WS position is reset (so the stack position is shown) at the same
1006 // time that the buffer size changes.
1007 setOffsetPositionForStackResize(false);
1008 mSurfaceController.deferTransactionUntil(mSurfaceController.getHandle(),
1009 mWin.getFrameNumber());
1010 } else {
1011 final TaskStack stack = mWin.getStack();
1012 mTmpPos.x = 0;
1013 mTmpPos.y = 0;
1014 if (stack != null) {
Evan Roskyed6767f2018-10-26 17:21:06 -07001015 stack.getRelativeDisplayedPosition(mTmpPos);
chaviwbe43ac82018-04-04 15:14:49 -07001016 }
1017
1018 xOffset = -mTmpPos.x;
1019 yOffset = -mTmpPos.y;
1020
1021 // Crop also needs to be extended so the bottom isn't cut off when the WSA
1022 // position is moved.
1023 if (clipRect != null) {
1024 clipRect.right += mTmpPos.x;
1025 clipRect.bottom += mTmpPos.y;
1026 }
1027 }
1028 }
1029 mSurfaceController.setPositionInTransaction(xOffset, yOffset, recoveringMemory);
Rob Carr06be6bb2018-02-06 16:26:06 +00001030 }
Robert Carr0d00c2e2016-02-29 17:45:02 -08001031 }
1032
Robert Carra9408d42016-06-03 13:28:48 -07001033 // If we are ending the scaling mode. We switch to SCALING_MODE_FREEZE
Robert Carr6da3cc02016-06-16 15:17:07 -07001034 // to prevent further updates until buffer latch.
Vishnu Nairddd80742018-08-21 14:12:46 -07001035 // We also need to freeze the Surface geometry until a buffer
1036 // comes in at the new size (normally position and crop are unfrozen).
1037 // setGeometryAppliesWithResizeInTransaction accomplishes this for us.
1038 if (wasForceScaled && !mForceScaleUntilResize) {
Vishnu Nairb040c012018-09-07 11:38:32 -07001039 mSurfaceController.deferTransactionUntil(mSurfaceController.getHandle(),
1040 mWin.getFrameNumber());
Robert Carra9408d42016-06-03 13:28:48 -07001041 mSurfaceController.forceScaleableInTransaction(false);
1042 }
Robert Carr4320d332016-06-10 15:13:32 -07001043
Vishnu Nairddd80742018-08-21 14:12:46 -07001044
Robert Carr6da3cc02016-06-16 15:17:07 -07001045 if (!w.mSeamlesslyRotated) {
chaviw23012112017-12-20 15:29:04 -08001046 applyCrop(clipRect, recoveringMemory);
Robert Carr6da3cc02016-06-16 15:17:07 -07001047 mSurfaceController.setMatrixInTransaction(mDsDx * w.mHScale * mExtraHScale,
1048 mDtDx * w.mVScale * mExtraVScale,
Robert Carr0edf18f2017-02-21 20:01:47 -08001049 mDtDy * w.mHScale * mExtraHScale,
1050 mDsDy * w.mVScale * mExtraVScale, recoveringMemory);
Robert Carr6da3cc02016-06-16 15:17:07 -07001051 }
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001052
Robert Carre6a83512015-11-03 16:09:21 -08001053 if (mSurfaceResized) {
Chong Zhang5b2f1992015-11-13 15:40:36 -08001054 mReportSurfaceResized = true;
Robert Carre6a83512015-11-03 16:09:21 -08001055 mAnimator.setPendingLayoutChanges(w.getDisplayId(),
Jorim Jaggia5e10572017-11-15 14:36:26 +01001056 FINISH_LAYOUT_REDO_WALLPAPER);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001057 }
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001058 }
1059
Andrii Kulian283acd22017-08-03 04:03:51 -07001060 /**
1061 * Get rect of the task this window is currently in. If there is no task, rect will be set to
1062 * empty.
1063 */
1064 void getContainerRect(Rect rect) {
1065 final Task task = mWin.getTask();
1066 if (task != null) {
1067 task.getDimBounds(rect);
1068 } else {
1069 rect.left = rect.top = rect.right = rect.bottom = 0;
1070 }
1071 }
1072
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001073 void prepareSurfaceLocked(final boolean recoveringMemory) {
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001074 final WindowState w = mWin;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001075 if (!hasSurface()) {
Jorim Jaggi38d44ec2017-06-14 16:04:59 -07001076
1077 // There is no need to wait for an animation change if our window is gone for layout
1078 // already as we'll never be visible.
Bryce Lee8c3cf382017-07-06 19:47:10 -07001079 if (w.getOrientationChanging() && w.isGoneForLayoutLw()) {
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001080 if (DEBUG_ORIENTATION) {
1081 Slog.v(TAG, "Orientation change skips hidden " + w);
1082 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001083 w.setOrientationChanging(false);
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001084 }
1085 return;
1086 }
1087
1088 boolean displayed = false;
1089
1090 computeShownFrameLocked();
1091
Craig Mautnera91f9e22012-09-14 16:22:08 -07001092 setSurfaceBoundariesLocked(recoveringMemory);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001093
Tiger Huang50d45462018-05-25 22:57:52 +08001094 if (mIsWallpaper && !w.mWallpaperVisible) {
Craig Mautner0fa77c12012-06-11 15:57:19 -07001095 // Wallpaper is no longer visible and there is no wp target => hide it.
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001096 hide("prepareSurfaceLocked");
Wale Ogunwale9d147902016-07-16 11:58:55 -07001097 } else if (w.isParentWindowHidden() || !w.isOnScreen()) {
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001098 hide("prepareSurfaceLocked");
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001099 mWallpaperControllerLocked.hideWallpapers(w);
Craig Mautnerb9836b92012-06-11 11:40:09 -07001100
Jorim Jaggi38d44ec2017-06-14 16:04:59 -07001101 // If we are waiting for this window to handle an orientation change. If this window is
1102 // really hidden (gone for layout), there is no point in still waiting for it.
1103 // Note that this does introduce a potential glitch if the window becomes unhidden
1104 // before it has drawn for the new orientation.
Bryce Lee8c3cf382017-07-06 19:47:10 -07001105 if (w.getOrientationChanging() && w.isGoneForLayoutLw()) {
1106 w.setOrientationChanging(false);
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001107 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001108 "Orientation change skips hidden " + w);
1109 }
Jorim Jaggi35d328a2018-08-14 17:00:20 +02001110 } else if (mLastAlpha != mShownAlpha
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001111 || mLastDsDx != mDsDx
1112 || mLastDtDx != mDtDx
1113 || mLastDsDy != mDsDy
1114 || mLastDtDy != mDtDy
1115 || w.mLastHScale != w.mHScale
1116 || w.mLastVScale != w.mVScale
Craig Mautner749a7bb2012-04-02 13:49:53 -07001117 || mLastHidden) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001118 displayed = true;
1119 mLastAlpha = mShownAlpha;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001120 mLastDsDx = mDsDx;
1121 mLastDtDx = mDtDx;
1122 mLastDsDy = mDsDy;
1123 mLastDtDy = mDtDy;
1124 w.mLastHScale = w.mHScale;
1125 w.mLastVScale = w.mVScale;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001126 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
Robert Carre6a83512015-11-03 16:09:21 -08001127 "controller=" + mSurfaceController +
Jorim Jaggi35d328a2018-08-14 17:00:20 +02001128 "alpha=" + mShownAlpha
Craig Mautner78505d82014-09-02 14:36:31 -07001129 + " matrix=[" + mDsDx + "*" + w.mHScale
1130 + "," + mDtDx + "*" + w.mVScale
Robert Carr0edf18f2017-02-21 20:01:47 -08001131 + "][" + mDtDy + "*" + w.mHScale
1132 + "," + mDsDy + "*" + w.mVScale + "]", false);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001133
Robert Carre6a83512015-11-03 16:09:21 -08001134 boolean prepared =
Robert Carraf422a82017-04-10 18:34:33 -07001135 mSurfaceController.prepareToShowInTransaction(mShownAlpha,
Robert Carr04092112016-06-02 12:56:12 -07001136 mDsDx * w.mHScale * mExtraHScale,
1137 mDtDx * w.mVScale * mExtraVScale,
Robert Carr0edf18f2017-02-21 20:01:47 -08001138 mDtDy * w.mHScale * mExtraHScale,
1139 mDsDy * w.mVScale * mExtraVScale,
Robert Carre6a83512015-11-03 16:09:21 -08001140 recoveringMemory);
1141
Robert Carr03206af2017-07-10 18:24:21 -07001142 if (prepared && mDrawState == HAS_DRAWN) {
1143 if (mLastHidden) {
1144 if (showSurfaceRobustlyLocked()) {
1145 markPreservedSurfaceForDestroy();
1146 mAnimator.requestRemovalOfReplacedWindows(w);
1147 mLastHidden = false;
1148 if (mIsWallpaper) {
1149 w.dispatchWallpaperVisibility(true);
1150 }
Jorim Jaggif1292892018-09-10 11:58:13 +02001151 if (!w.getDisplayContent().getLastHasContent()) {
1152 // This draw means the difference between unique content and mirroring.
1153 // Run another pass through performLayout to set mHasContent in the
1154 // LogicalDisplay.
1155 mAnimator.setPendingLayoutChanges(w.getDisplayId(),
1156 FINISH_LAYOUT_REDO_ANIM);
1157 if (DEBUG_LAYOUT_REPEATS) {
1158 mService.mWindowPlacerLocked.debugLayoutRepeats(
1159 "showSurfaceRobustlyLocked " + w,
1160 mAnimator.getPendingLayoutChanges(w.getDisplayId()));
1161 }
Tiger Huang50d45462018-05-25 22:57:52 +08001162 }
Robert Carr03206af2017-07-10 18:24:21 -07001163 } else {
1164 w.setOrientationChanging(false);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001165 }
Robert Carr03206af2017-07-10 18:24:21 -07001166 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001167 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001168 if (hasSurface()) {
Robert Carre6a83512015-11-03 16:09:21 -08001169 w.mToken.hasVisible = true;
1170 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001171 } else {
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001172 if (DEBUG_ANIM && mWin.isAnimating()) {
Chong Zhange05db742016-02-16 16:58:37 -08001173 Slog.v(TAG, "prepareSurface: No changes in animation for " + this);
Craig Mautner83339b42012-05-01 22:13:23 -07001174 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001175 displayed = true;
1176 }
1177
Bryce Lee8c3cf382017-07-06 19:47:10 -07001178 if (w.getOrientationChanging()) {
Jorim Jaggi38d44ec2017-06-14 16:04:59 -07001179 if (!w.isDrawnLw()) {
1180 mAnimator.mBulkUpdateParams &= ~SET_ORIENTATION_CHANGE_COMPLETE;
1181 mAnimator.mLastWindowFreezeSource = w;
1182 if (DEBUG_ORIENTATION) Slog.v(TAG,
1183 "Orientation continue waiting for draw in " + w);
1184 } else {
Bryce Lee8c3cf382017-07-06 19:47:10 -07001185 w.setOrientationChanging(false);
Jorim Jaggi38d44ec2017-06-14 16:04:59 -07001186 if (DEBUG_ORIENTATION) Slog.v(TAG, "Orientation change complete in " + w);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001187 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -07001188 }
1189
1190 if (displayed) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001191 w.mToken.hasVisible = true;
1192 }
1193 }
1194
Craig Mautneref655012013-01-03 11:20:24 -08001195 void setTransparentRegionHintLocked(final Region region) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001196 if (mSurfaceController == null) {
1197 Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true");
1198 return;
1199 }
Robert Carre6a83512015-11-03 16:09:21 -08001200 mSurfaceController.setTransparentRegionHint(region);
Craig Mautner48ba1e72012-04-02 13:18:16 -07001201 }
1202
Robert Carr217e7cc2018-01-31 18:08:39 -08001203 boolean setWallpaperOffset(int dx, int dy) {
1204 if (mXOffset == dx && mYOffset == dy) {
1205 return false;
1206 }
1207 mXOffset = dx;
1208 mYOffset = dy;
Robert Carre6a83512015-11-03 16:09:21 -08001209
1210 try {
Craig Mautner71dd1b62014-02-18 15:48:52 -08001211 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setWallpaperOffset");
Robert Carr68e5c9e2016-09-14 10:50:09 -07001212 mService.openSurfaceTransaction();
Robert Carr217e7cc2018-01-31 18:08:39 -08001213 mSurfaceController.setPositionInTransaction(dx, dy, false);
chaviw23012112017-12-20 15:29:04 -08001214 applyCrop(null, false);
Robert Carre6a83512015-11-03 16:09:21 -08001215 } catch (RuntimeException e) {
1216 Slog.w(TAG, "Error positioning surface of " + mWin
Robert Carr217e7cc2018-01-31 18:08:39 -08001217 + " pos=(" + dx + "," + dy + ")", e);
Robert Carre6a83512015-11-03 16:09:21 -08001218 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +02001219 mService.closeSurfaceTransaction("setWallpaperOffset");
Robert Carre6a83512015-11-03 16:09:21 -08001220 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1221 "<<< CLOSE TRANSACTION setWallpaperOffset");
Robert Carr217e7cc2018-01-31 18:08:39 -08001222 return true;
Craig Mautner48ba1e72012-04-02 13:18:16 -07001223 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001224 }
1225
John Reck80181b92015-05-19 11:09:32 -07001226 /**
1227 * Try to change the pixel format without recreating the surface. This
1228 * will be common in the case of changing from PixelFormat.OPAQUE to
1229 * PixelFormat.TRANSLUCENT in the hardware-accelerated case as both
1230 * requested formats resolve to the same underlying SurfaceControl format
1231 * @return True if format was succesfully changed, false otherwise
1232 */
1233 boolean tryChangeFormatInPlaceLocked() {
Robert Carre6a83512015-11-03 16:09:21 -08001234 if (mSurfaceController == null) {
John Reck80181b92015-05-19 11:09:32 -07001235 return false;
1236 }
1237 final LayoutParams attrs = mWin.getAttrs();
Wale Ogunwalee7bf46b2015-09-30 09:19:28 -07001238 final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0;
John Reck80181b92015-05-19 11:09:32 -07001239 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
1240 if (format == mSurfaceFormat) {
1241 setOpaqueLocked(!PixelFormat.formatHasAlpha(attrs.format));
1242 return true;
1243 }
1244 return false;
1245 }
1246
Craig Mautner6f612042014-09-07 13:13:23 -07001247 void setOpaqueLocked(boolean isOpaque) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001248 if (mSurfaceController == null) {
1249 return;
1250 }
Robert Carre6a83512015-11-03 16:09:21 -08001251 mSurfaceController.setOpaque(isOpaque);
Craig Mautner71dd1b62014-02-18 15:48:52 -08001252 }
1253
Wale Ogunwalef5ad42f2015-06-12 13:59:03 -07001254 void setSecureLocked(boolean isSecure) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001255 if (mSurfaceController == null) {
1256 return;
1257 }
Robert Carre6a83512015-11-03 16:09:21 -08001258 mSurfaceController.setSecure(isSecure);
Wale Ogunwalef5ad42f2015-06-12 13:59:03 -07001259 }
1260
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001261 /**
1262 * Have the surface flinger show a surface, robustly dealing with
1263 * error conditions. In particular, if there is not enough memory
1264 * to show the surface, then we will try to get rid of other surfaces
1265 * in order to succeed.
1266 *
1267 * @return Returns true if the surface was successfully shown.
1268 */
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001269 private boolean showSurfaceRobustlyLocked() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001270 if (mWin.getWindowConfiguration().windowsAreScaleable()) {
Robert Carr1b5ea722016-04-20 13:23:28 -07001271 mSurfaceController.forceScaleableInTransaction(true);
1272 }
1273
Robert Carre6a83512015-11-03 16:09:21 -08001274 boolean shown = mSurfaceController.showRobustlyInTransaction();
1275 if (!shown)
1276 return false;
1277
Robert Carr849d2932018-05-01 12:14:48 -07001278 // If we had a preserved surface it's no longer needed, and it may be harmful
1279 // if we are transparent.
1280 if (mPendingDestroySurface != null && mDestroyPreservedSurfaceUponRedraw) {
1281 mPendingDestroySurface.mSurfaceControl.hide();
Robert Carrba993782018-05-15 15:16:40 -07001282 mPendingDestroySurface.reparentChildrenInTransaction(mSurfaceController);
Robert Carr849d2932018-05-01 12:14:48 -07001283 }
1284
Robert Carre6a83512015-11-03 16:09:21 -08001285 return true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001286 }
1287
1288 void applyEnterAnimationLocked() {
Robert Carrb439a632016-04-07 22:52:10 -07001289 // If we are the new part of a window replacement transition and we have requested
1290 // not to animate, we instead want to make it seamless, so we don't want to apply
1291 // an enter transition.
1292 if (mWin.mSkipEnterAnimationForSeamlessReplacement) {
1293 return;
1294 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001295 final int transit;
1296 if (mEnterAnimationPending) {
1297 mEnterAnimationPending = false;
1298 transit = WindowManagerPolicy.TRANSIT_ENTER;
1299 } else {
1300 transit = WindowManagerPolicy.TRANSIT_SHOW;
1301 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001302 applyAnimationLocked(transit, true);
Rhed Jao02655dc2018-10-30 20:44:52 +08001303 if (mService.mAccessibilityController != null) {
Svetoslav8e3feb12014-02-24 13:46:47 -08001304 mService.mAccessibilityController.onWindowTransitionLocked(mWin, transit);
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -07001305 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001306 }
1307
1308 /**
1309 * Choose the correct animation and set it to the passed WindowState.
Craig Mautner4b71aa12012-12-27 17:20:01 -08001310 * @param transit If AppTransition.TRANSIT_PREVIEW_DONE and the app window has been drawn
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001311 * then the animation will be app_starting_exit. Any other value loads the animation from
1312 * the switch statement below.
1313 * @param isEntrance The animation type the last time this was called. Used to keep from
1314 * loading the same animation twice.
1315 * @return true if an animation has been loaded.
1316 */
1317 boolean applyAnimationLocked(int transit, boolean isEntrance) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01001318 if (mWin.isSelfAnimating() && mAnimationIsEntrance == isEntrance) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001319 // If we are trying to apply an animation, but already running
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001320 // an animation of the same type, then just leave that one alone.
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001321 return true;
1322 }
1323
Jorim Jaggia5e10572017-11-15 14:36:26 +01001324 if (isEntrance && mWin.mAttrs.type == TYPE_INPUT_METHOD) {
1325 mWin.getDisplayContent().adjustForImeIfNeeded();
1326 mWin.setDisplayLayoutNeeded();
1327 mService.mWindowPlacerLocked.requestTraversal();
1328 }
1329
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001330 // Only apply an animation if the display isn't frozen. If it is
1331 // frozen, there is no reason to animate and it can cause strange
1332 // artifacts when we unfreeze the display if some different animation
1333 // is running.
Chong Zhang8784be62016-06-28 15:25:07 -07001334 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "WSA#applyAnimationLocked");
David Stevens9440dc82017-03-16 19:00:20 -07001335 if (mWin.mToken.okToAnimate()) {
Tiger Huang7c610aa2018-10-27 00:01:01 +08001336 int anim = mWin.getDisplayContent().getDisplayPolicy().selectAnimationLw(mWin, transit);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001337 int attr = -1;
1338 Animation a = null;
1339 if (anim != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001340 a = anim != -1 ? AnimationUtils.loadAnimation(mContext, anim) : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001341 } else {
1342 switch (transit) {
1343 case WindowManagerPolicy.TRANSIT_ENTER:
1344 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
1345 break;
1346 case WindowManagerPolicy.TRANSIT_EXIT:
1347 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
1348 break;
1349 case WindowManagerPolicy.TRANSIT_SHOW:
1350 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
1351 break;
1352 case WindowManagerPolicy.TRANSIT_HIDE:
1353 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
1354 break;
1355 }
1356 if (attr >= 0) {
lumark588a3e82018-07-20 18:53:54 +08001357 a = mWin.getDisplayContent().mAppTransition.loadAnimationAttr(
1358 mWin.mAttrs, attr, TRANSIT_NONE);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001359 }
1360 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001361 if (DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001362 "applyAnimation: win=" + this
1363 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
Craig Mautner4d7349b2012-04-20 14:52:47 -07001364 + " a=" + a
Craig Mautner8863cca2012-09-18 15:04:34 -07001365 + " transit=" + transit
Craig Mautner83339b42012-05-01 22:13:23 -07001366 + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001367 if (a != null) {
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -08001368 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
Jorim Jaggia5e10572017-11-15 14:36:26 +01001369 mWin.startAnimation(a);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001370 mAnimationIsEntrance = isEntrance;
1371 }
1372 } else {
Jorim Jaggia5e10572017-11-15 14:36:26 +01001373 mWin.cancelAnimation();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001374 }
Chong Zhang8784be62016-06-28 15:25:07 -07001375
Jorim Jaggia5e10572017-11-15 14:36:26 +01001376 if (!isEntrance && mWin.mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001377 mWin.getDisplayContent().adjustForImeIfNeeded();
Jorim Jaggieb88d832016-04-13 20:17:43 -07001378 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001379
Jorim Jaggia5e10572017-11-15 14:36:26 +01001380 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001381 return mWin.isAnimating();
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001382 }
1383
Steven Timotiusaf03df62017-07-18 16:56:43 -07001384 void writeToProto(ProtoOutputStream proto, long fieldId) {
1385 final long token = proto.start(fieldId);
1386 mLastClipRect.writeToProto(proto, LAST_CLIP_RECT);
1387 if (mSurfaceController != null) {
1388 mSurfaceController.writeToProto(proto, SURFACE);
1389 }
Vishnu Nair1d0fa072018-01-04 07:53:00 -08001390 proto.write(DRAW_STATE, mDrawState);
1391 mSystemDecorRect.writeToProto(proto, SYSTEM_DECOR_RECT);
Steven Timotiusaf03df62017-07-18 16:56:43 -07001392 proto.end(token);
1393 }
1394
Craig Mautnera2c77052012-03-26 12:14:43 -07001395 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01001396 if (mAnimationIsEntrance) {
1397 pw.print(prefix); pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
Craig Mautnera2c77052012-03-26 12:14:43 -07001398 }
Robert Carre6a83512015-11-03 16:09:21 -08001399 if (mSurfaceController != null) {
1400 mSurfaceController.dump(pw, prefix, dumpAll);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001401 }
Robert Carre6a83512015-11-03 16:09:21 -08001402 if (dumpAll) {
1403 pw.print(prefix); pw.print("mDrawState="); pw.print(drawStateToString());
1404 pw.print(prefix); pw.print(" mLastHidden="); pw.println(mLastHidden);
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001405 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001406 pw.print(" mLastClipRect="); mLastClipRect.printShortString(pw);
1407
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001408 if (!mLastFinalClipRect.isEmpty()) {
1409 pw.print(" mLastFinalClipRect="); mLastFinalClipRect.printShortString(pw);
1410 }
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001411 pw.println();
Robert Carre6a83512015-11-03 16:09:21 -08001412 }
1413
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001414 if (mPendingDestroySurface != null) {
1415 pw.print(prefix); pw.print("mPendingDestroySurface=");
1416 pw.println(mPendingDestroySurface);
1417 }
1418 if (mSurfaceResized || mSurfaceDestroyDeferred) {
1419 pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized);
1420 pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred);
1421 }
1422 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
1423 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
1424 pw.print(" mAlpha="); pw.print(mAlpha);
1425 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
1426 }
1427 if (mHaveMatrix || mWin.mGlobalScale != 1) {
1428 pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale);
1429 pw.print(" mDsDx="); pw.print(mDsDx);
1430 pw.print(" mDtDx="); pw.print(mDtDx);
Robert Carr0edf18f2017-02-21 20:01:47 -08001431 pw.print(" mDtDy="); pw.print(mDtDy);
1432 pw.print(" mDsDy="); pw.println(mDsDy);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001433 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001434 }
1435
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001436 @Override
1437 public String toString() {
Dianne Hackborn529e7442012-11-01 14:22:28 -07001438 StringBuffer sb = new StringBuffer("WindowStateAnimator{");
1439 sb.append(Integer.toHexString(System.identityHashCode(this)));
1440 sb.append(' ');
1441 sb.append(mWin.mAttrs.getTitle());
1442 sb.append('}');
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001443 return sb.toString();
1444 }
Robert Carre6a83512015-11-03 16:09:21 -08001445
1446 void reclaimSomeSurfaceMemory(String operation, boolean secure) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001447 mService.mRoot.reclaimSomeSurfaceMemory(this, operation, secure);
Robert Carre6a83512015-11-03 16:09:21 -08001448 }
1449
1450 boolean getShown() {
1451 if (mSurfaceController != null) {
1452 return mSurfaceController.getShown();
1453 }
1454 return false;
1455 }
1456
1457 void destroySurface() {
Wale Ogunwale722ff892016-02-18 13:37:55 -08001458 try {
1459 if (mSurfaceController != null) {
Robert Carra8828862018-02-05 16:17:36 -08001460 mSurfaceController.destroyNotInTransaction();
Wale Ogunwale722ff892016-02-18 13:37:55 -08001461 }
1462 } catch (RuntimeException e) {
1463 Slog.w(TAG, "Exception thrown when destroying surface " + this
1464 + " surface " + mSurfaceController + " session " + mSession + ": " + e);
1465 } finally {
1466 mWin.setHasSurface(false);
1467 mSurfaceController = null;
1468 mDrawState = NO_SURFACE;
1469 }
Robert Carre6a83512015-11-03 16:09:21 -08001470 }
Filip Gruszczynskif52dd202015-11-15 20:36:38 -08001471
Robert Carr8f0a3ad2017-02-15 19:30:28 -08001472 /** The force-scaled state for a given window can persist past
1473 * the state for it's stack as the windows complete resizing
1474 * independently of one another.
1475 */
1476 boolean isForceScaled() {
1477 final Task task = mWin.getTask();
1478 if (task != null && task.mStack.isForceScaled()) {
1479 return true;
1480 }
1481 return mForceScaleUntilResize;
1482 }
Robert Carrd5c7dd62017-03-08 10:39:30 -08001483
1484 void detachChildren() {
1485 if (mSurfaceController != null) {
1486 mSurfaceController.detachChildren();
1487 }
Robert Carr7b3d11d2018-03-15 14:34:45 -07001488 mChildrenDetached = true;
Robert Carrd5c7dd62017-03-08 10:39:30 -08001489 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01001490
chaviwbe43ac82018-04-04 15:14:49 -07001491 void setOffsetPositionForStackResize(boolean offsetPositionForStackResize) {
1492 mOffsetPositionForStackResize = offsetPositionForStackResize;
1493 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001494}