blob: 9552df7b589937504578d9c0ad8f722cf2ba37b5 [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;
lumarkce596d32019-06-12 16:58:35 +080023import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Jorim Jaggieb88d832016-04-13 20:17:43 -070024import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
Robert Carrfbbde852016-10-18 11:02:28 -070025import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Jorim Jaggi0a1523d2018-04-19 17:48:38 +020026import static android.view.WindowManager.TRANSIT_NONE;
chaviw9c81e632018-07-31 11:17:52 -070027
Jorim Jaggia5e10572017-11-15 14:36:26 +010028import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
29import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Adrian Roosb125e0b2019-10-02 14:55:14 +020030import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_DRAW;
31import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ORIENTATION;
32import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_STARTING_WINDOW;
33import static com.android.server.wm.ProtoLogGroup.WM_SHOW_SURFACE_ALLOC;
34import static com.android.server.wm.ProtoLogGroup.WM_SHOW_TRANSACTIONS;
lumark9bca6b42019-10-17 18:35:22 +080035import static com.android.server.wm.WindowContainer.AnimationFlags.PARENTS;
36import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION;
Adam Pardyl8c2d19c2019-09-16 17:15:38 +020037import static com.android.server.wm.WindowManagerDebugConfig.DEBUG;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080038import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080039import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020040import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080041import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -080042import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_CROP;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080043import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080044import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
45import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang97782b42015-10-07 16:01:23 -070046import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080047import static com.android.server.wm.WindowManagerService.logWithStack;
Yi Jin6c6e9ca2018-03-20 16:53:35 -070048import static com.android.server.wm.WindowStateAnimatorProto.DRAW_STATE;
49import static com.android.server.wm.WindowStateAnimatorProto.LAST_CLIP_RECT;
50import static com.android.server.wm.WindowStateAnimatorProto.SURFACE;
51import static com.android.server.wm.WindowStateAnimatorProto.SYSTEM_DECOR_RECT;
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +020052import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070053
Craig Mautnerc2f9be02012-03-27 17:32:29 -070054import android.content.Context;
55import android.graphics.Matrix;
56import android.graphics.PixelFormat;
Craig Mautner7358fbf2012-04-12 21:06:33 -070057import android.graphics.Point;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070058import android.graphics.Rect;
Craig Mautner48ba1e72012-04-02 13:18:16 -070059import android.graphics.Region;
Craig Mautnera51a9562012-04-17 17:05:26 -070060import android.os.Debug;
Chong Zhang8784be62016-06-28 15:25:07 -070061import android.os.Trace;
Craig Mautnera2c77052012-03-26 12:14:43 -070062import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -070063import android.util.proto.ProtoOutputStream;
Craig Mautner59c00972012-07-30 12:10:24 -070064import android.view.DisplayInfo;
Igor Murashkina86ab6402013-08-30 12:58:36 -070065import android.view.Surface.OutOfResourcesException;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080066import android.view.SurfaceControl;
Craig Mautnera2c77052012-03-26 12:14:43 -070067import android.view.WindowManager;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070068import android.view.WindowManager.LayoutParams;
Craig Mautnera2c77052012-03-26 12:14:43 -070069import android.view.animation.Animation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070070import android.view.animation.AnimationUtils;
Craig Mautnera2c77052012-03-26 12:14:43 -070071
Adrian Roose99bc052017-11-20 17:55:31 +010072import com.android.server.policy.WindowManagerPolicy;
Adrian Roosb125e0b2019-10-02 14:55:14 +020073import com.android.server.protolog.common.ProtoLog;
Adrian Roose99bc052017-11-20 17:55:31 +010074
Jorim Jaggia5e10572017-11-15 14:36:26 +010075import java.io.PrintWriter;
Craig Mautnera2c77052012-03-26 12:14:43 -070076
77/**
Craig Mautnerc2f9be02012-03-27 17:32:29 -070078 * Keep track of animations and surface operations for a single WindowState.
79 **/
Craig Mautnera2c77052012-03-26 12:14:43 -070080class WindowStateAnimator {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080081 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowStateAnimator" : TAG_WM;
Chong Zhang97782b42015-10-07 16:01:23 -070082 static final int WINDOW_FREEZE_LAYER = TYPE_LAYER_MULTIPLIER * 200;
Tiger Huang9c8ee262019-02-19 20:44:27 +080083 static final int PRESERVED_SURFACE_LAYER = 1;
Craig Mautnera2c77052012-03-26 12:14:43 -070084
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010085 /**
86 * Mode how the window gets clipped by the stack bounds during an animation: The clipping should
87 * be applied after applying the animation transformation, i.e. the stack bounds don't move
88 * during the animation.
89 */
90 static final int STACK_CLIP_AFTER_ANIM = 0;
91
92 /**
93 * Mode how the window gets clipped by the stack bounds: The clipping should be applied before
94 * applying the animation transformation, i.e. the stack bounds move with the window.
95 */
96 static final int STACK_CLIP_BEFORE_ANIM = 1;
97
98 /**
99 * Mode how window gets clipped by the stack bounds during an animation: Don't clip the window
100 * by the stack bounds.
101 */
102 static final int STACK_CLIP_NONE = 2;
103
Craig Mautner918b53b2012-07-09 14:15:54 -0700104 // Unchanging local convenience fields.
Craig Mautnera2c77052012-03-26 12:14:43 -0700105 final WindowManagerService mService;
106 final WindowState mWin;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700107 final WindowAnimator mAnimator;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700108 final Session mSession;
109 final WindowManagerPolicy mPolicy;
110 final Context mContext;
Craig Mautner918b53b2012-07-09 14:15:54 -0700111 final boolean mIsWallpaper;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -0700112 private final WallpaperController mWallpaperControllerLocked;
Craig Mautnera2c77052012-03-26 12:14:43 -0700113
Craig Mautnera2c77052012-03-26 12:14:43 -0700114 boolean mAnimationIsEntrance;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700115
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700116 /**
117 * Set when we have changed the size of the surface, to know that
118 * we must tell them application to resize (and thus redraw itself).
119 */
120 boolean mSurfaceResized;
Chong Zhang5b2f1992015-11-13 15:40:36 -0800121 /**
122 * Whether we should inform the client on next relayoutWindow that
123 * the surface has been resized since last time.
124 */
125 boolean mReportSurfaceResized;
Robert Carre6a83512015-11-03 16:09:21 -0800126 WindowSurfaceController mSurfaceController;
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800127 private WindowSurfaceController mPendingDestroySurface;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700128
129 /**
130 * Set if the client has asked that the destroy of its surface be delayed
131 * until it explicitly says it is okay.
132 */
133 boolean mSurfaceDestroyDeferred;
134
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800135 private boolean mDestroyPreservedSurfaceUponRedraw;
Craig Mautner7d8df392012-04-06 15:26:23 -0700136 float mShownAlpha = 0;
137 float mAlpha = 0;
138 float mLastAlpha = 0;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700139
Winson Chung399f6202014-03-19 10:47:20 -0700140 Rect mTmpClipRect = new Rect();
141 Rect mLastClipRect = new Rect();
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100142 Rect mLastFinalClipRect = new Rect();
Filip Gruszczynski4b8eea72015-09-14 18:16:19 -0700143 Rect mTmpStackBounds = new Rect();
Winson Chung08f81892017-03-02 15:40:51 -0800144 private Rect mTmpAnimatingBounds = new Rect();
145 private Rect mTmpSourceBounds = new Rect();
Winson Chung399f6202014-03-19 10:47:20 -0700146
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -0800147 /**
148 * This is rectangle of the window's surface that is not covered by
149 * system decorations.
150 */
151 private final Rect mSystemDecorRect = new Rect();
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -0800152
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700153 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
Robert Carr0edf18f2017-02-21 20:01:47 -0800154 private float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700155
156 boolean mHaveMatrix;
157
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700158 // Set to true if, when the window gets displayed, it should perform
159 // an enter animation.
160 boolean mEnterAnimationPending;
Craig Mautnera2c77052012-03-26 12:14:43 -0700161
Craig Mautner9c795042014-10-28 19:59:59 -0700162 /** Used to indicate that this window is undergoing an enter animation. Used for system
163 * windows to make the callback to View.dispatchOnWindowShownCallback(). Set when the
164 * window is first added or shown, cleared when the callback has been made. */
165 boolean mEnteringAnimation;
166
Vishnu Nair33197392019-08-30 10:29:37 -0700167 private final SurfaceControl.Transaction mTmpTransaction;
Chavi Weingartenb736e322018-02-23 00:27:54 +0000168
John Reck80181b92015-05-19 11:09:32 -0700169 /** The pixel format of the underlying SurfaceControl */
170 int mSurfaceFormat;
171
Craig Mautner749a7bb2012-04-02 13:49:53 -0700172 /** This is set when there is no Surface */
173 static final int NO_SURFACE = 0;
174 /** This is set after the Surface has been created but before the window has been drawn. During
175 * this time the surface is hidden. */
176 static final int DRAW_PENDING = 1;
177 /** This is set after the window has finished drawing for the first time but before its surface
178 * is shown. The surface will be displayed when the next layout is run. */
179 static final int COMMIT_DRAW_PENDING = 2;
180 /** This is set during the time after the window's drawing has been committed, and before its
181 * surface is actually shown. It is used to delay showing the surface until all windows in a
182 * token are ready to be shown. */
183 static final int READY_TO_SHOW = 3;
184 /** Set when the window has been shown in the screen the first time. */
185 static final int HAS_DRAWN = 4;
Adrian Roos3eeb4e62014-05-19 12:43:26 +0200186
Craig Mautner276a6eb2014-11-04 15:32:57 -0800187 String drawStateToString() {
188 switch (mDrawState) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700189 case NO_SURFACE: return "NO_SURFACE";
190 case DRAW_PENDING: return "DRAW_PENDING";
191 case COMMIT_DRAW_PENDING: return "COMMIT_DRAW_PENDING";
192 case READY_TO_SHOW: return "READY_TO_SHOW";
193 case HAS_DRAWN: return "HAS_DRAWN";
Craig Mautner276a6eb2014-11-04 15:32:57 -0800194 default: return Integer.toString(mDrawState);
Craig Mautner6fbda632012-07-03 09:26:39 -0700195 }
196 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700197 int mDrawState;
Craig Mautnera608b882012-03-30 13:03:49 -0700198
Craig Mautner749a7bb2012-04-02 13:49:53 -0700199 /** Was this window last hidden? */
200 boolean mLastHidden;
Craig Mautnera608b882012-03-30 13:03:49 -0700201
Craig Mautnerbec53f72012-04-05 11:49:05 -0700202 int mAttrType;
203
Robert Carrc7294602016-05-13 11:32:05 -0700204 boolean mForceScaleUntilResize;
205
Robert Carr04092112016-06-02 12:56:12 -0700206 // WindowState.mHScale and WindowState.mVScale contain the
207 // scale according to client specified layout parameters (e.g.
208 // one layout size, with another surface size, creates such scaling).
209 // Here we track an additional scaling factor used to follow stack
210 // scaling (as in the case of the Pinned stack animation).
211 float mExtraHScale = (float) 1.0;
212 float mExtraVScale = (float) 1.0;
213
Robert Carr217e7cc2018-01-31 18:08:39 -0800214 // An offset in pixel of the surface contents from the window position. Used for Wallpaper
215 // to provide the effect of scrolling within a large surface. We just use these values as
216 // a cache.
217 int mXOffset = 0;
218 int mYOffset = 0;
219
chaviwbe43ac82018-04-04 15:14:49 -0700220 /**
221 * A flag to determine if the WSA needs to offset its position to compensate for the stack's
222 * position update before the WSA surface has resized.
223 */
224 private boolean mOffsetPositionForStackResize;
225
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800226 private final Rect mTmpSize = new Rect();
227
Vishnu Nairf7645aa2019-06-18 11:14:01 -0700228 /**
229 * Handles surface changes synchronized to after the client has drawn the surface. This
230 * transaction is currently used to reparent the old surface children to the new surface once
231 * the client has completed drawing to the new surface.
232 * This transaction is also used to merge transactions parceled in by the client. The client
233 * uses the transaction to update the relative z of its children from the old parent surface
234 * to the new parent surface once window manager reparents its children.
235 */
236 private final SurfaceControl.Transaction mPostDrawTransaction =
237 new SurfaceControl.Transaction();
Robert Carrca4c5a62018-02-05 16:07:55 -0800238
Robert Carr7b3d11d2018-03-15 14:34:45 -0700239 // Used to track whether we have called detach children on the way to invisibility, in which
240 // case we need to give the client a new Surface if it lays back out to a visible state.
241 boolean mChildrenDetached = false;
242
Robert Carr2025bf842018-03-19 13:25:05 -0700243 // Set to true after the first frame of the Pinned stack animation
244 // and reset after the last to ensure we only reset mForceScaleUntilResize
245 // once per animation.
246 boolean mPipAnimationStarted = false;
247
chaviwbe43ac82018-04-04 15:14:49 -0700248 private final Point mTmpPos = new Point();
249
Craig Mautnerc431e892015-02-11 13:14:26 -0800250 WindowStateAnimator(final WindowState win) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800251 final WindowManagerService service = win.mWmService;
Craig Mautner918b53b2012-07-09 14:15:54 -0700252
Craig Mautnera2c77052012-03-26 12:14:43 -0700253 mService = service;
Vishnu Nair33197392019-08-30 10:29:37 -0700254 mTmpTransaction = service.mTransactionFactory.get();
Craig Mautner918b53b2012-07-09 14:15:54 -0700255 mAnimator = service.mAnimator;
256 mPolicy = service.mPolicy;
257 mContext = service.mContext;
Craig Mautner918b53b2012-07-09 14:15:54 -0700258
259 mWin = win;
Craig Mautner918b53b2012-07-09 14:15:54 -0700260 mSession = win.mSession;
Craig Mautner918b53b2012-07-09 14:15:54 -0700261 mAttrType = win.mAttrs.type;
262 mIsWallpaper = win.mIsWallpaper;
wilsonshihc32538e2018-11-07 17:27:34 +0800263 mWallpaperControllerLocked = win.getDisplayContent().mWallpaperController;
Craig Mautnera2c77052012-03-26 12:14:43 -0700264 }
265
Jorim Jaggia5e10572017-11-15 14:36:26 +0100266 void onAnimationFinished() {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700267 // Done animating, clean up.
268 if (DEBUG_ANIM) Slog.v(
Jorim Jaggia5e10572017-11-15 14:36:26 +0100269 TAG, "Animation done in " + this + ": exiting=" + mWin.mAnimatingExit
270 + ", reportedVisible="
Garfield Tane8d84ab2019-10-11 09:49:40 -0700271 + (mWin.mActivityRecord != null ? mWin.mActivityRecord.reportedVisible : false));
Craig Mautnera2c77052012-03-26 12:14:43 -0700272
Filip Gruszczynski14b4e572015-11-03 15:53:55 -0800273 mWin.checkPolicyVisibilityChange();
Jorim Jaggia5e10572017-11-15 14:36:26 +0100274 final DisplayContent displayContent = mWin.getDisplayContent();
wilsonshihe8321942019-10-18 18:39:46 +0800275 if ((mAttrType == LayoutParams.TYPE_STATUS_BAR
276 || mAttrType == LayoutParams.TYPE_NOTIFICATION_SHADE) && mWin.isVisibleByPolicy()) {
Craig Mautner81defc72013-10-29 11:10:42 -0700277 // Upon completion of a not-visible to visible status bar animation a relayout is
278 // required.
Riddle Hsu8419e4b2019-09-18 23:28:01 +0800279 displayContent.setLayoutNeeded();
Craig Mautnera2c77052012-03-26 12:14:43 -0700280 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700281 mWin.onExitAnimationDone();
Riddle Hsu8419e4b2019-09-18 23:28:01 +0800282 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100283 if (displayContent.mWallpaperController.isWallpaperTarget(mWin)) {
Riddle Hsu8419e4b2019-09-18 23:28:01 +0800284 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100285 }
Riddle Hsu8419e4b2019-09-18 23:28:01 +0800286 if (DEBUG_LAYOUT_REPEATS) {
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700287 mService.mWindowPlacerLocked.debugLayoutRepeats(
Riddle Hsu8419e4b2019-09-18 23:28:01 +0800288 "WindowStateAnimator", displayContent.pendingLayoutChanges);
289 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700290
Garfield Tane8d84ab2019-10-11 09:49:40 -0700291 if (mWin.mActivityRecord != null) {
292 mWin.mActivityRecord.updateReportedVisibilityLocked();
Craig Mautnera2c77052012-03-26 12:14:43 -0700293 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700294 }
295
Chavi Weingartenb736e322018-02-23 00:27:54 +0000296 void hide(SurfaceControl.Transaction transaction, String reason) {
Craig Mautner0afddcb2012-05-08 15:38:00 -0700297 if (!mLastHidden) {
298 //dump();
299 mLastHidden = true;
Jorim Jaggi50575902018-04-10 17:49:30 +0200300
301 // We may have a preserved surface which we no longer need. If there was a quick
302 // VISIBLE, GONE, VISIBLE, GONE sequence, the surface may never draw, so we don't mark
303 // it to be destroyed in prepareSurfaceLocked.
304 markPreservedSurfaceForDestroy();
305
Wale Ogunwalef9e09782015-11-09 12:42:37 -0800306 if (mSurfaceController != null) {
Chavi Weingartenb736e322018-02-23 00:27:54 +0000307 mSurfaceController.hide(transaction, reason);
Wale Ogunwalef9e09782015-11-09 12:42:37 -0800308 }
Craig Mautner0afddcb2012-05-08 15:38:00 -0700309 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700310 }
311
Chavi Weingartenb736e322018-02-23 00:27:54 +0000312 void hide(String reason) {
313 hide(mTmpTransaction, reason);
314 SurfaceControl.mergeToGlobalTransaction(mTmpTransaction);
315 }
316
Vishnu Nairf7645aa2019-06-18 11:14:01 -0700317 boolean finishDrawingLocked(SurfaceControl.Transaction postDrawTransaction) {
Craig Mautner42d04db2014-11-06 12:13:23 -0800318 final boolean startingWindow =
319 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Adrian Roosb125e0b2019-10-02 14:55:14 +0200320 if (startingWindow) {
321 ProtoLog.v(WM_DEBUG_STARTING_WINDOW, "Finishing drawing window %s: mDrawState=%s",
322 mWin, drawStateToString());
Craig Mautner6fbda632012-07-03 09:26:39 -0700323 }
Robert Carr1ca6a332016-04-11 18:00:43 -0700324
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200325 boolean layoutNeeded = false;
Chong Zhang92147042016-05-09 12:47:11 -0700326
Craig Mautner749a7bb2012-04-02 13:49:53 -0700327 if (mDrawState == DRAW_PENDING) {
Adrian Roosb125e0b2019-10-02 14:55:14 +0200328 ProtoLog.v(WM_DEBUG_DRAW,
329 "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING %s in %s", mWin,
330 mSurfaceController);
331 if (startingWindow) {
332 ProtoLog.v(WM_DEBUG_STARTING_WINDOW, "Draw state now committed in %s", mWin);
Craig Mautner6fbda632012-07-03 09:26:39 -0700333 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700334 mDrawState = COMMIT_DRAW_PENDING;
Chong Zhangcbbcc0f2016-05-17 20:46:58 -0700335 layoutNeeded = true;
Vishnu Nair8cb00ae2019-08-02 15:20:29 -0700336
337 if (postDrawTransaction != null) {
338 mPostDrawTransaction.merge(postDrawTransaction);
339 }
340 } else if (postDrawTransaction != null) {
341 // If draw state is not pending we may delay applying this transaction from the client,
342 // so apply it now.
343 postDrawTransaction.apply();
Vishnu Nairf7645aa2019-06-18 11:14:01 -0700344 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700345
Chong Zhangcbbcc0f2016-05-17 20:46:58 -0700346 return layoutNeeded;
Craig Mautnera608b882012-03-30 13:03:49 -0700347 }
348
349 // This must be called while inside a transaction.
Craig Mautnerc431e892015-02-11 13:14:26 -0800350 boolean commitFinishDrawingLocked() {
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200351 if (DEBUG_STARTING_WINDOW_VERBOSE &&
Craig Mautner6fbda632012-07-03 09:26:39 -0700352 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
353 Slog.i(TAG, "commitFinishDrawingLocked: " + mWin + " cur mDrawState="
Craig Mautner276a6eb2014-11-04 15:32:57 -0800354 + drawStateToString());
Craig Mautner6fbda632012-07-03 09:26:39 -0700355 }
Craig Mautner276a6eb2014-11-04 15:32:57 -0800356 if (mDrawState != COMMIT_DRAW_PENDING && mDrawState != READY_TO_SHOW) {
Craig Mautnera608b882012-03-30 13:03:49 -0700357 return false;
358 }
Robert Carre13b58e2017-08-31 14:50:44 -0700359 if (DEBUG_ANIM) {
Robert Carre6a83512015-11-03 16:09:21 -0800360 Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurfaceController);
Craig Mautner6fbda632012-07-03 09:26:39 -0700361 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700362 mDrawState = READY_TO_SHOW;
Chong Zhang0275e392015-09-17 10:41:44 -0700363 boolean result = false;
Garfield Tane8d84ab2019-10-11 09:49:40 -0700364 final ActivityRecord activity = mWin.mActivityRecord;
365 if (activity == null || activity.canShowWindows()
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +0200366 || mWin.mAttrs.type == TYPE_APPLICATION_STARTING) {
Wale Ogunwale9d147902016-07-16 11:58:55 -0700367 result = mWin.performShowLocked();
Chong Zhang0275e392015-09-17 10:41:44 -0700368 }
Chong Zhang97782b42015-10-07 16:01:23 -0700369 return result;
Craig Mautnera608b882012-03-30 13:03:49 -0700370 }
371
Chong Zhang97782b42015-10-07 16:01:23 -0700372 void preserveSurfaceLocked() {
373 if (mDestroyPreservedSurfaceUponRedraw) {
Chong Zhangb9b0fec2016-02-11 18:51:51 -0800374 // This could happen when switching the surface mode very fast. For example,
375 // we preserved a surface when dragResizing changed to true. Then before the
376 // preserved surface is removed, dragResizing changed to false again.
377 // In this case, we need to leave the preserved surface alone, and destroy
378 // the actual surface, so that the createSurface call could create a surface
379 // of the proper size. The preserved surface will still be removed when client
380 // finishes drawing to the new surface.
381 mSurfaceDestroyDeferred = false;
Vishnu Nair7c861472019-07-25 09:57:12 -0700382
383 // Make sure to reparent any children of the new surface back to the preserved
384 // surface before destroying it.
385 if (mSurfaceController != null && mPendingDestroySurface != null) {
386 mPostDrawTransaction.reparentChildren(mSurfaceController.mSurfaceControl,
387 mPendingDestroySurface.mSurfaceControl).apply();
388 }
Chong Zhangb9b0fec2016-02-11 18:51:51 -0800389 destroySurfaceLocked();
390 mSurfaceDestroyDeferred = true;
Chong Zhang97782b42015-10-07 16:01:23 -0700391 return;
392 }
Adrian Roosb125e0b2019-10-02 14:55:14 +0200393 ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE SET FREEZE LAYER: %s", mWin);
Wale Ogunwalef9e09782015-11-09 12:42:37 -0800394 if (mSurfaceController != null) {
Robert Carrb1579c82017-09-05 14:54:47 -0700395 // Our SurfaceControl is always at layer 0 within the parent Surface managed by
396 // window-state. We want this old Surface to stay on top of the new one
Tiger Huang9c8ee262019-02-19 20:44:27 +0800397 // until we do the swap, so we place it at a positive layer.
398 mSurfaceController.mSurfaceControl.setLayer(PRESERVED_SURFACE_LAYER);
Wale Ogunwalef9e09782015-11-09 12:42:37 -0800399 }
Chong Zhang97782b42015-10-07 16:01:23 -0700400 mDestroyPreservedSurfaceUponRedraw = true;
401 mSurfaceDestroyDeferred = true;
402 destroySurfaceLocked();
403 }
404
405 void destroyPreservedSurfaceLocked() {
406 if (!mDestroyPreservedSurfaceUponRedraw) {
407 return;
408 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800409 if (mSurfaceController != null) {
410 if (mPendingDestroySurface != null) {
411 // If we are preserving a surface but we aren't relaunching that means
412 // we are just doing an in-place switch. In that case any SurfaceFlinger side
413 // child layers need to be reparented to the new surface to make this
414 // transparent to the app.
Garfield Tane8d84ab2019-10-11 09:49:40 -0700415 if (mWin.mActivityRecord == null || mWin.mActivityRecord.isRelaunching() == false) {
Vishnu Nairf7645aa2019-06-18 11:14:01 -0700416 mPostDrawTransaction.reparentChildren(mPendingDestroySurface.mSurfaceControl,
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700417 mSurfaceController.mSurfaceControl)
Robert Carrca4c5a62018-02-05 16:07:55 -0800418 .apply();
Robert Carrd5c7dd62017-03-08 10:39:30 -0800419 }
420 }
421 }
422
Chong Zhang97782b42015-10-07 16:01:23 -0700423 destroyDeferredSurfaceLocked();
424 mDestroyPreservedSurfaceUponRedraw = false;
425 }
426
Chong Zhangeb665572016-05-09 18:28:27 -0700427 void markPreservedSurfaceForDestroy() {
428 if (mDestroyPreservedSurfaceUponRedraw
429 && !mService.mDestroyPreservedSurface.contains(mWin)) {
430 mService.mDestroyPreservedSurface.add(mWin);
431 }
432 }
433
Robert Carrecc06b32017-04-18 14:25:10 -0700434 void resetDrawState() {
435 mDrawState = DRAW_PENDING;
436
Garfield Tane8d84ab2019-10-11 09:49:40 -0700437 if (mWin.mActivityRecord == null) {
Robert Carrecc06b32017-04-18 14:25:10 -0700438 return;
439 }
440
lumark9bca6b42019-10-17 18:35:22 +0800441 if (!mWin.mActivityRecord.isAnimating(TRANSITION)) {
Garfield Tane8d84ab2019-10-11 09:49:40 -0700442 mWin.mActivityRecord.clearAllDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -0700443 }
444 }
445
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500446 WindowSurfaceController createSurfaceLocked(int windowType, int ownerUid) {
Alan Viveretteccb11e12014-07-08 16:04:02 -0700447 final WindowState w = mWin;
Chong Zhanga8975bd2016-01-28 17:13:47 -0800448
Wale Ogunwale722ff892016-02-18 13:37:55 -0800449 if (mSurfaceController != null) {
450 return mSurfaceController;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700451 }
Robert Carr7b3d11d2018-03-15 14:34:45 -0700452 mChildrenDetached = false;
Wale Ogunwale722ff892016-02-18 13:37:55 -0800453
Robert Carr132c9f52017-07-31 17:02:30 -0700454 if ((mWin.mAttrs.privateFlags & PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY) != 0) {
455 windowType = SurfaceControl.WINDOW_TYPE_DONT_SCREENSHOT;
456 }
457
Wale Ogunwale722ff892016-02-18 13:37:55 -0800458 w.setHasSurface(false);
459
Adrian Roosb125e0b2019-10-02 14:55:14 +0200460 if (DEBUG_ANIM) {
461 Slog.i(TAG, "createSurface " + this + ": mDrawState=DRAW_PENDING");
462 }
Wale Ogunwale722ff892016-02-18 13:37:55 -0800463
Robert Carrecc06b32017-04-18 14:25:10 -0700464 resetDrawState();
Wale Ogunwale722ff892016-02-18 13:37:55 -0800465
466 mService.makeWindowFreezingScreenIfNeededLocked(w);
467
468 int flags = SurfaceControl.HIDDEN;
469 final WindowManager.LayoutParams attrs = w.mAttrs;
470
471 if (mService.isSecureLocked(w)) {
472 flags |= SurfaceControl.SECURE;
473 }
474
chaviw9c81e632018-07-31 11:17:52 -0700475 calculateSurfaceBounds(w, attrs, mTmpSize);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800476 final int width = mTmpSize.width();
477 final int height = mTmpSize.height();
478
479 if (DEBUG_VISIBILITY) {
480 Slog.v(TAG, "Creating surface in session "
481 + mSession.mSurfaceSession + " window " + this
482 + " w=" + width + " h=" + height
483 + " x=" + mTmpSize.left + " y=" + mTmpSize.top
484 + " format=" + attrs.format + " flags=" + flags);
485 }
486
487 // We may abort, so initialize to defaults.
Wale Ogunwale722ff892016-02-18 13:37:55 -0800488 mLastClipRect.set(0, 0, 0, 0);
489
490 // Set up surface control with initial size.
491 try {
492
493 final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0;
494 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
495 if (!PixelFormat.formatHasAlpha(attrs.format)
496 // Don't make surface with surfaceInsets opaque as they display a
497 // translucent shadow.
498 && attrs.surfaceInsets.left == 0
499 && attrs.surfaceInsets.top == 0
500 && attrs.surfaceInsets.right == 0
501 && attrs.surfaceInsets.bottom == 0
502 // Don't make surface opaque when resizing to reduce the amount of
503 // artifacts shown in areas the app isn't drawing content to.
504 && !w.isDragResizing()) {
505 flags |= SurfaceControl.OPAQUE;
506 }
507
chaviw619da692019-06-10 15:39:40 -0700508 mSurfaceController = new WindowSurfaceController(attrs.getTitle().toString(), width,
509 height, format, flags, this, windowType, ownerUid);
Peiyong Lin75045382019-03-04 19:22:33 -0800510 mSurfaceController.setColorSpaceAgnostic((attrs.privateFlags
511 & WindowManager.LayoutParams.PRIVATE_FLAG_COLOR_SPACE_AGNOSTIC) != 0);
chaviwbe43ac82018-04-04 15:14:49 -0700512
513 setOffsetPositionForStackResize(false);
Robert Carr486bbb72017-05-30 11:25:22 -0700514 mSurfaceFormat = format;
Wale Ogunwale722ff892016-02-18 13:37:55 -0800515
516 w.setHasSurface(true);
517
Adrian Roosb125e0b2019-10-02 14:55:14 +0200518 ProtoLog.i(WM_SHOW_SURFACE_ALLOC,
519 " CREATE SURFACE %s IN SESSION %s: pid=%d format=%d flags=0x%x / %s",
520 mSurfaceController, mSession.mSurfaceSession, mSession.mPid, attrs.format,
521 flags, this);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800522 } catch (OutOfResourcesException e) {
523 Slog.w(TAG, "OutOfResourcesException creating surface");
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700524 mService.mRoot.reclaimSomeSurfaceMemory(this, "create", true);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800525 mDrawState = NO_SURFACE;
526 return null;
527 } catch (Exception e) {
Robert Carrb0f39362018-03-14 13:52:25 -0700528 Slog.e(TAG, "Exception creating surface (parent dead?)", e);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800529 mDrawState = NO_SURFACE;
530 return null;
531 }
532
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200533 if (DEBUG) {
534 Slog.v(TAG, "Got surface: " + mSurfaceController
535 + ", set left=" + w.getFrameLw().left + " top=" + w.getFrameLw().top);
536 }
Wale Ogunwale722ff892016-02-18 13:37:55 -0800537
538 if (SHOW_LIGHT_TRANSACTIONS) {
539 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
540 WindowManagerService.logSurface(w, "CREATE pos=("
chaviw492139a2018-07-16 16:07:35 -0700541 + w.getFrameLw().left + "," + w.getFrameLw().top + ") ("
Jorim Jaggi35d328a2018-08-14 17:00:20 +0200542 + width + "x" + height + ")" + " HIDE", false);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800543 }
544
Wale Ogunwale722ff892016-02-18 13:37:55 -0800545 mLastHidden = true;
546
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200547 if (DEBUG) Slog.v(TAG, "Created surface " + this);
Robert Carre6a83512015-11-03 16:09:21 -0800548 return mSurfaceController;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700549 }
550
chaviw9c81e632018-07-31 11:17:52 -0700551 private void calculateSurfaceBounds(WindowState w, LayoutParams attrs, Rect outSize) {
552 outSize.setEmpty();
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800553 if ((attrs.flags & FLAG_SCALED) != 0) {
554 // For a scaled surface, we always want the requested size.
chaviw9c81e632018-07-31 11:17:52 -0700555 outSize.right = w.mRequestedWidth;
556 outSize.bottom = w.mRequestedHeight;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800557 } else {
558 // When we're doing a drag-resizing, request a surface that's fullscreen size,
559 // so that we don't need to reallocate during the process. This also prevents
560 // buffer drops due to size mismatch.
561 if (w.isDragResizing()) {
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800562 final DisplayInfo displayInfo = w.getDisplayInfo();
chaviw9c81e632018-07-31 11:17:52 -0700563 outSize.right = displayInfo.logicalWidth;
564 outSize.bottom = displayInfo.logicalHeight;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800565 } else {
chaviw9c81e632018-07-31 11:17:52 -0700566 w.getCompatFrameSize(outSize);
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800567 }
568 }
569
570 // Something is wrong and SurfaceFlinger will not like this, try to revert to sane values.
Filip Gruszczynskie6ed1952015-12-21 09:34:16 -0800571 // This doesn't necessarily mean that there is an error in the system. The sizes might be
572 // incorrect, because it is before the first layout or draw.
chaviw9c81e632018-07-31 11:17:52 -0700573 if (outSize.width() < 1) {
574 outSize.right = 1;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800575 }
chaviw9c81e632018-07-31 11:17:52 -0700576 if (outSize.height() < 1) {
577 outSize.bottom = 1;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800578 }
579
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800580 // Adjust for surface insets.
chaviw9c81e632018-07-31 11:17:52 -0700581 outSize.inset(-attrs.surfaceInsets.left, -attrs.surfaceInsets.top,
582 -attrs.surfaceInsets.right, -attrs.surfaceInsets.bottom);
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800583 }
584
Chong Zhangeb22e8e2016-01-20 19:52:22 -0800585 boolean hasSurface() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200586 return mSurfaceController != null && mSurfaceController.hasSurface();
Chong Zhangeb22e8e2016-01-20 19:52:22 -0800587 }
588
Craig Mautner96868332012-12-04 14:29:11 -0800589 void destroySurfaceLocked() {
Garfield Tane8d84ab2019-10-11 09:49:40 -0700590 final ActivityRecord activity = mWin.mActivityRecord;
591 if (activity != null) {
592 if (mWin == activity.startingWindow) {
593 activity.startingDisplayed = false;
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700594 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700595 }
596
Wale Ogunwale722ff892016-02-18 13:37:55 -0800597 if (mSurfaceController == null) {
598 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700599 }
Wale Ogunwale722ff892016-02-18 13:37:55 -0800600
Wale Ogunwale722ff892016-02-18 13:37:55 -0800601 // When destroying a surface we want to make sure child windows are hidden. If we are
602 // preserving the surface until redraw though we intend to swap it out with another surface
603 // for resizing. In this case the window always remains visible to the user and the child
604 // windows should likewise remain visible.
Wale Ogunwale9d147902016-07-16 11:58:55 -0700605 if (!mDestroyPreservedSurfaceUponRedraw) {
606 mWin.mHidden = true;
Wale Ogunwale722ff892016-02-18 13:37:55 -0800607 }
608
609 try {
610 if (DEBUG_VISIBILITY) logWithStack(TAG, "Window " + this + " destroying surface "
611 + mSurfaceController + ", session " + mSession);
612 if (mSurfaceDestroyDeferred) {
613 if (mSurfaceController != null && mPendingDestroySurface != mSurfaceController) {
614 if (mPendingDestroySurface != null) {
Adrian Roosb125e0b2019-10-02 14:55:14 +0200615 ProtoLog.i(WM_SHOW_SURFACE_ALLOC, "SURFACE DESTROY PENDING: %s. %s",
616 mWin, new RuntimeException().fillInStackTrace());
Robert Carra8828862018-02-05 16:17:36 -0800617 mPendingDestroySurface.destroyNotInTransaction();
Wale Ogunwale722ff892016-02-18 13:37:55 -0800618 }
619 mPendingDestroySurface = mSurfaceController;
620 }
621 } else {
Adrian Roosb125e0b2019-10-02 14:55:14 +0200622 ProtoLog.i(WM_SHOW_SURFACE_ALLOC, "SURFACE DESTROY: %s. %s",
623 mWin, new RuntimeException().fillInStackTrace());
Wale Ogunwale722ff892016-02-18 13:37:55 -0800624 destroySurface();
625 }
626 // Don't hide wallpaper if we're deferring the surface destroy
627 // because of a surface change.
628 if (!mDestroyPreservedSurfaceUponRedraw) {
629 mWallpaperControllerLocked.hideWallpapers(mWin);
630 }
631 } catch (RuntimeException e) {
632 Slog.w(TAG, "Exception thrown when destroying Window " + this
633 + " surface " + mSurfaceController + " session " + mSession + ": " + e.toString());
634 }
635
636 // Whether the surface was preserved (and copied to mPendingDestroySurface) or not, it
637 // needs to be cleared to match the WindowState.mHasSurface state. It is also necessary
638 // so it can be recreated successfully in mPendingDestroySurface case.
639 mWin.setHasSurface(false);
640 if (mSurfaceController != null) {
641 mSurfaceController.setShown(false);
642 }
643 mSurfaceController = null;
644 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700645 }
646
Craig Mautner96868332012-12-04 14:29:11 -0800647 void destroyDeferredSurfaceLocked() {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700648 try {
649 if (mPendingDestroySurface != null) {
Adrian Roosb125e0b2019-10-02 14:55:14 +0200650 ProtoLog.i(WM_SHOW_SURFACE_ALLOC, "SURFACE DESTROY PENDING: %s. %s",
651 mWin, new RuntimeException().fillInStackTrace());
Robert Carra8828862018-02-05 16:17:36 -0800652 mPendingDestroySurface.destroyNotInTransaction();
Chong Zhang6e21cf42015-11-09 14:41:42 -0800653 // Don't hide wallpaper if we're destroying a deferred surface
654 // after a surface mode change.
655 if (!mDestroyPreservedSurfaceUponRedraw) {
656 mWallpaperControllerLocked.hideWallpapers(mWin);
657 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700658 }
659 } catch (RuntimeException e) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700660 Slog.w(TAG, "Exception thrown when destroying Window "
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700661 + this + " surface " + mPendingDestroySurface
662 + " session " + mSession + ": " + e.toString());
663 }
664 mSurfaceDestroyDeferred = false;
665 mPendingDestroySurface = null;
666 }
667
668 void computeShownFrameLocked() {
Craig Mautnera91f9e22012-09-14 16:22:08 -0700669 final ScreenRotationAnimation screenRotationAnimation =
Vadim Caenb3715832019-08-13 17:06:38 +0200670 mWin.getDisplayContent().getRotationAnimation();
Vishnu Nair83537a72018-07-19 21:27:48 -0700671 final boolean windowParticipatesInScreenRotationAnimation =
672 !mWin.mForceSeamlesslyRotate;
673 final boolean screenAnimation = screenRotationAnimation != null
674 && screenRotationAnimation.isAnimating()
675 && windowParticipatesInScreenRotationAnimation;
Robert Carr2f0fe622015-09-25 14:56:38 -0700676
Robert Carr44643c12017-09-27 14:57:38 -0700677 if (screenAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700678 // cache often used attributes locally
chaviw492139a2018-07-16 16:07:35 -0700679 final Rect frame = mWin.getFrameLw();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700680 final float tmpFloats[] = mService.mTmpFloats;
681 final Matrix tmpMatrix = mWin.mTmpMatrix;
682
683 // Compute the desired transformation.
Robert Carr44643c12017-09-27 14:57:38 -0700684 if (screenRotationAnimation.isRotating()) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700685 // If we are doing a screen animation, the global rotation
686 // applied to windows can result in windows that are carefully
687 // aligned with each other to slightly separate, allowing you
688 // to see what is behind them. An unsightly mess. This...
689 // thing... magically makes it call good: scale each window
690 // slightly (two pixels larger in each dimension, from the
691 // window's center).
692 final float w = frame.width();
693 final float h = frame.height();
694 if (w>=1 && h>=1) {
695 tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2);
696 } else {
697 tmpMatrix.reset();
698 }
699 } else {
700 tmpMatrix.reset();
701 }
Robert Carr44643c12017-09-27 14:57:38 -0700702
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700703 tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale);
Robert Carr29d196f2017-11-28 12:39:46 -0800704
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100705 // WindowState.prepareSurfaces expands for surface insets (in order they don't get
706 // clipped by the WindowState surface), so we need to go into the other direction here.
Robert Carr217e7cc2018-01-31 18:08:39 -0800707 tmpMatrix.postTranslate(mWin.mAttrs.surfaceInsets.left,
708 mWin.mAttrs.surfaceInsets.top);
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100709
Matthew Ng34a06d12017-02-03 11:56:08 -0800710
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700711 // "convert" it into SurfaceFlinger's format
712 // (a 2x2 matrix + an offset)
713 // Here we must not transform the position of the surface
714 // since it is already included in the transformation.
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800715 //Slog.i(TAG_WM, "Transform: " + matrix);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700716
717 mHaveMatrix = true;
718 tmpMatrix.getValues(tmpFloats);
719 mDsDx = tmpFloats[Matrix.MSCALE_X];
720 mDtDx = tmpFloats[Matrix.MSKEW_Y];
Robert Carr0edf18f2017-02-21 20:01:47 -0800721 mDtDy = tmpFloats[Matrix.MSKEW_X];
722 mDsDy = tmpFloats[Matrix.MSCALE_Y];
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700723
724 // Now set the alpha... but because our current hardware
725 // can't do alpha transformation on a non-opaque surface,
726 // turn it off if we are running an animation that is also
727 // transforming since it is more important to have that
728 // animation be smooth.
729 mShownAlpha = mAlpha;
730 if (!mService.mLimitedAlphaCompositing
731 || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format)
Robert Carr217e7cc2018-01-31 18:08:39 -0800732 || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDtDy, mDsDy)))) {
Vadim Caen641d39d2019-07-23 11:29:45 +0200733 mShownAlpha *= screenRotationAnimation.getEnterTransformation().getAlpha();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700734 }
735
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200736 if ((DEBUG_ANIM || DEBUG) && (mShownAlpha == 1.0 || mShownAlpha == 0.0)) {
737 Slog.v(TAG, "computeShownFrameLocked: Animating " + this + " mAlpha=" + mAlpha
738 + " screen=" + (screenAnimation
739 ? screenRotationAnimation.getEnterTransformation().getAlpha() : "null"));
740 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700741 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700742 } else if (mIsWallpaper && mService.mRoot.mWallpaperActionPending) {
Craig Mautner4d7349b2012-04-20 14:52:47 -0700743 return;
Chong Zhang3005e752015-09-18 18:46:28 -0700744 } else if (mWin.isDragResizeChanged()) {
745 // This window is awaiting a relayout because user just started (or ended)
746 // drag-resizing. The shown frame (which affects surface size and pos)
747 // should not be updated until we get next finished draw with the new surface.
748 // Otherwise one or two frames rendered with old settings would be displayed
749 // with new geometry.
750 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700751 }
752
Adam Pardyl8c2d19c2019-09-16 17:15:38 +0200753 if (DEBUG) {
754 Slog.v(TAG, "computeShownFrameLocked: " + this
755 + " not attached, mAlpha=" + mAlpha);
756 }
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700757
Robert Carrb1579c82017-09-05 14:54:47 -0700758 mShownAlpha = mAlpha;
759 mHaveMatrix = false;
760 mDsDx = mWin.mGlobalScale;
761 mDtDx = 0;
762 mDtDy = 0;
763 mDsDy = mWin.mGlobalScale;
Robert Carref090ac2017-05-15 16:45:50 -0700764 }
765
Robert Carrfbbde852016-10-18 11:02:28 -0700766 /**
Robert Carrfbbde852016-10-18 11:02:28 -0700767 * Calculate the window-space crop rect and fill clipRect.
Wale Ogunwaleca9e0612016-12-02 07:45:59 -0800768 * @return true if clipRect has been filled otherwise, no window space crop should be applied.
Robert Carrfbbde852016-10-18 11:02:28 -0700769 */
Wale Ogunwaleca9e0612016-12-02 07:45:59 -0800770 private boolean calculateCrop(Rect clipRect) {
Robert Carrfbbde852016-10-18 11:02:28 -0700771 final WindowState w = mWin;
772 final DisplayContent displayContent = w.getDisplayContent();
773 clipRect.setEmpty();
774
775 if (displayContent == null) {
776 return false;
777 }
778
Evan Rosky1c66f442019-04-30 16:02:58 -0700779 if (w.getWindowConfiguration().tasksAreFloating()) {
Robert Carrfbbde852016-10-18 11:02:28 -0700780 return false;
781 }
782
Vishnu Nair83537a72018-07-19 21:27:48 -0700783 // During forced seamless rotation, the surface bounds get updated with the crop in the
784 // new rotation, which is not compatible with showing the surface in the old rotation.
785 // To work around that we disable cropping for such windows, as it is not necessary anyways.
786 if (w.mForceSeamlesslyRotate) {
787 return false;
788 }
789
Robert Carrfbbde852016-10-18 11:02:28 -0700790 // If we're animating, the wallpaper should only
791 // be updated at the end of the animation.
792 if (w.mAttrs.type == TYPE_WALLPAPER) {
793 return false;
794 }
795
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -0700796 if (DEBUG_WINDOW_CROP) Slog.d(TAG,
797 "Updating crop win=" + w + " mLastCrop=" + mLastClipRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -0700798
Robert Carrfbbde852016-10-18 11:02:28 -0700799 w.calculatePolicyCrop(mSystemDecorRect);
800
801 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "Applying decor to crop win=" + w + " mDecorFrame="
chaviw553b0212018-07-12 13:37:01 -0700802 + w.getDecorFrame() + " mSystemDecorRect=" + mSystemDecorRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -0700803
Robert Carr51a1b872015-12-08 14:03:13 -0800804 // We use the clip rect as provided by the tranformation for non-fullscreen windows to
805 // avoid premature clipping with the system decor rect.
Robert Carrf0586622018-01-29 13:03:43 -0800806 clipRect.set(mSystemDecorRect);
Evan Rosky4fb1e912019-03-06 13:54:43 -0800807 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "win=" + w + " Initial clip rect: " + clipRect);
Robert Carr51a1b872015-12-08 14:03:13 -0800808
Robert Carrfbbde852016-10-18 11:02:28 -0700809 w.expandForSurfaceInsets(clipRect);
Alan Viverette49a22e82014-07-12 20:01:27 -0700810
Alan Viverette49a22e82014-07-12 20:01:27 -0700811 // The clip rect was generated assuming (0,0) as the window origin,
812 // so we need to translate to match the actual surface coordinates.
Robert Carrfbbde852016-10-18 11:02:28 -0700813 clipRect.offset(w.mAttrs.surfaceInsets.left, w.mAttrs.surfaceInsets.top);
Robert Carr58f29132015-10-29 14:19:05 -0700814
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -0700815 if (DEBUG_WINDOW_CROP) Slog.d(TAG,
816 "win=" + w + " Clip rect after stack adjustment=" + clipRect);
Robert Carr58f29132015-10-29 14:19:05 -0700817
Chia-I Wue6bcaf12016-05-27 10:58:48 +0800818 w.transformClipRectFromScreenToSurfaceSpace(clipRect);
Robert Carr58f29132015-10-29 14:19:05 -0700819
Robert Carrfbbde852016-10-18 11:02:28 -0700820 return true;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800821 }
822
chaviw23012112017-12-20 15:29:04 -0800823 private void applyCrop(Rect clipRect, boolean recoveringMemory) {
Robert Carrfbbde852016-10-18 11:02:28 -0700824 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "applyCrop: win=" + mWin
chaviw23012112017-12-20 15:29:04 -0800825 + " clipRect=" + clipRect);
Robert Carr4320d332016-06-10 15:13:32 -0700826 if (clipRect != null) {
827 if (!clipRect.equals(mLastClipRect)) {
828 mLastClipRect.set(clipRect);
829 mSurfaceController.setCropInTransaction(clipRect, recoveringMemory);
830 }
831 } else {
832 mSurfaceController.clearCropInTransaction(recoveringMemory);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -0700833 }
Filip Gruszczynski4b8eea72015-09-14 18:16:19 -0700834 }
835
Wale Ogunwale4c8b7952015-04-07 10:49:40 -0700836 void setSurfaceBoundariesLocked(final boolean recoveringMemory) {
Wale Ogunwale027f4752017-05-12 10:37:16 -0700837 if (mSurfaceController == null) {
838 return;
839 }
840
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700841 final WindowState w = mWin;
Winson Chung08f81892017-03-02 15:40:51 -0800842 final LayoutParams attrs = mWin.getAttrs();
Robert Carr0d00c2e2016-02-29 17:45:02 -0800843 final Task task = w.getTask();
Alan Viveretteccb11e12014-07-08 16:04:02 -0700844
chaviw9c81e632018-07-31 11:17:52 -0700845 calculateSurfaceBounds(w, attrs, mTmpSize);
Chong Zhang0275e392015-09-17 10:41:44 -0700846
Robert Carr04092112016-06-02 12:56:12 -0700847 mExtraHScale = (float) 1.0;
848 mExtraVScale = (float) 1.0;
Robert Carre1034cc32016-02-01 13:08:15 -0800849
Robert Carr6da3cc02016-06-16 15:17:07 -0700850 boolean wasForceScaled = mForceScaleUntilResize;
Robert Carr6da3cc02016-06-16 15:17:07 -0700851
Robert Carrfed10072016-05-26 11:48:49 -0700852 // Once relayout has been called at least once, we need to make sure
853 // we only resize the client surface during calls to relayout. For
854 // clients which use indeterminate measure specs (MATCH_PARENT),
855 // we may try and change their window size without a call to relayout.
856 // However, this would be unsafe, as the client may be in the middle
857 // of producing a frame at the old size, having just completed layout
858 // to find the surface size changed underneath it.
chaviwbe43ac82018-04-04 15:14:49 -0700859 final boolean relayout = !w.mRelayoutCalled || w.mInRelayout;
860 if (relayout) {
Vishnu Naire86bd982018-11-28 13:23:17 -0800861 mSurfaceResized = mSurfaceController.setBufferSizeInTransaction(
Robert Carrfed10072016-05-26 11:48:49 -0700862 mTmpSize.width(), mTmpSize.height(), recoveringMemory);
863 } else {
864 mSurfaceResized = false;
865 }
Robert Carrc7294602016-05-13 11:32:05 -0700866 mForceScaleUntilResize = mForceScaleUntilResize && !mSurfaceResized;
Robert Carr6da3cc02016-06-16 15:17:07 -0700867 // If we are undergoing seamless rotation, the surface has already
868 // been set up to persist at it's old location. We need to freeze
869 // updates until a resize occurs.
Robert Carrc7294602016-05-13 11:32:05 -0700870
chaviw23012112017-12-20 15:29:04 -0800871 Rect clipRect = null;
Robert Carrfbbde852016-10-18 11:02:28 -0700872 if (calculateCrop(mTmpClipRect)) {
873 clipRect = mTmpClipRect;
874 }
Robert Carra9408d42016-06-03 13:28:48 -0700875
876 float surfaceWidth = mSurfaceController.getWidth();
877 float surfaceHeight = mSurfaceController.getHeight();
878
Robert Carr74a66a22018-02-23 12:17:51 -0800879 final Rect insets = attrs.surfaceInsets;
880
Robert Carr8f0a3ad2017-02-15 19:30:28 -0800881 if (isForceScaled()) {
Robert Carr74a66a22018-02-23 12:17:51 -0800882 int hInsets = insets.left + insets.right;
883 int vInsets = insets.top + insets.bottom;
Winson Chung08f81892017-03-02 15:40:51 -0800884 float surfaceContentWidth = surfaceWidth - hInsets;
885 float surfaceContentHeight = surfaceHeight - vInsets;
Robert Carra9408d42016-06-03 13:28:48 -0700886 if (!mForceScaleUntilResize) {
887 mSurfaceController.forceScaleableInTransaction(true);
888 }
Robert Carrfd4c9892017-02-01 10:28:28 -0800889
Robert Carr74a66a22018-02-23 12:17:51 -0800890 int posX = 0;
891 int posY = 0;
Wale Ogunwale0b3d2922019-12-30 08:55:07 -0800892 task.getStack().getDimBounds(mTmpStackBounds);
Robert Carr18f622f2017-05-08 11:20:43 -0700893
894 boolean allowStretching = false;
Wale Ogunwale0b3d2922019-12-30 08:55:07 -0800895 task.getStack().getFinalAnimationSourceHintBounds(mTmpSourceBounds);
Robert Carr18f622f2017-05-08 11:20:43 -0700896 // If we don't have source bounds, we can attempt to use the content insets
897 // in the following scenario:
898 // 1. We have content insets.
899 // 2. We are not transitioning to full screen
900 // We have to be careful to check "lastAnimatingBoundsWasToFullscreen" rather than
901 // the mBoundsAnimating state, as we may have already left it and only be here
902 // because of the force-scale until resize state.
903 if (mTmpSourceBounds.isEmpty() && (mWin.mLastRelayoutContentInsets.width() > 0
904 || mWin.mLastRelayoutContentInsets.height() > 0)
Wale Ogunwale0b3d2922019-12-30 08:55:07 -0800905 && !task.getStack().lastAnimatingBoundsWasToFullscreen()) {
906 mTmpSourceBounds.set(task.getStack().mPreAnimationBounds);
Robert Carr18f622f2017-05-08 11:20:43 -0700907 mTmpSourceBounds.inset(mWin.mLastRelayoutContentInsets);
908 allowStretching = true;
909 }
Adrian Roos604ef952018-05-15 20:13:13 +0200910
911 // Make sure that what we're animating to and from is actually the right size in case
912 // the window cannot take up the full screen.
chaviw553b0212018-07-12 13:37:01 -0700913 mTmpStackBounds.intersectUnchecked(w.getParentFrame());
914 mTmpSourceBounds.intersectUnchecked(w.getParentFrame());
915 mTmpAnimatingBounds.intersectUnchecked(w.getParentFrame());
Adrian Roos604ef952018-05-15 20:13:13 +0200916
Winson Chung08f81892017-03-02 15:40:51 -0800917 if (!mTmpSourceBounds.isEmpty()) {
918 // Get the final target stack bounds, if we are not animating, this is just the
919 // current stack bounds
Wale Ogunwale0b3d2922019-12-30 08:55:07 -0800920 task.getStack().getFinalAnimationBounds(mTmpAnimatingBounds);
Winson Chung08f81892017-03-02 15:40:51 -0800921
922 // Calculate the current progress and interpolate the difference between the target
923 // and source bounds
924 float finalWidth = mTmpAnimatingBounds.width();
925 float initialWidth = mTmpSourceBounds.width();
Robert Carr18f622f2017-05-08 11:20:43 -0700926 float tw = (surfaceContentWidth - mTmpStackBounds.width())
Winson Chung08f81892017-03-02 15:40:51 -0800927 / (surfaceContentWidth - mTmpAnimatingBounds.width());
Robert Carr18f622f2017-05-08 11:20:43 -0700928 float th = tw;
929 mExtraHScale = (initialWidth + tw * (finalWidth - initialWidth)) / initialWidth;
930 if (allowStretching) {
931 float finalHeight = mTmpAnimatingBounds.height();
932 float initialHeight = mTmpSourceBounds.height();
933 th = (surfaceContentHeight - mTmpStackBounds.height())
934 / (surfaceContentHeight - mTmpAnimatingBounds.height());
935 mExtraVScale = (initialHeight + tw * (finalHeight - initialHeight))
936 / initialHeight;
937 } else {
938 mExtraVScale = mExtraHScale;
939 }
Winson Chung08f81892017-03-02 15:40:51 -0800940
941 // Adjust the position to account for the inset bounds
Robert Carr18f622f2017-05-08 11:20:43 -0700942 posX -= (int) (tw * mExtraHScale * mTmpSourceBounds.left);
943 posY -= (int) (th * mExtraVScale * mTmpSourceBounds.top);
Winson Chung08f81892017-03-02 15:40:51 -0800944
Robert Carr74a66a22018-02-23 12:17:51 -0800945 // In pinned mode the clip rectangle applied to us by our stack has been
946 // expanded outwards to allow for shadows. However in case of source bounds set
947 // we need to crop to within the surface. The code above has scaled and positioned
948 // the surface to fit the unexpanded stack bounds, but now we need to reapply
949 // the cropping that the stack would have applied if it weren't expanded. This
950 // can be different in each direction based on the source bounds.
951 clipRect = mTmpClipRect;
952 clipRect.set((int)((insets.left + mTmpSourceBounds.left) * tw),
953 (int)((insets.top + mTmpSourceBounds.top) * th),
954 insets.left + (int)(surfaceWidth
955 - (tw* (surfaceWidth - mTmpSourceBounds.right))),
956 insets.top + (int)(surfaceHeight
957 - (th * (surfaceHeight - mTmpSourceBounds.bottom))));
Winson Chung08f81892017-03-02 15:40:51 -0800958 } else {
959 // We want to calculate the scaling based on the content area, not based on
960 // the entire surface, so that we scale in sync with windows that don't have insets.
961 mExtraHScale = mTmpStackBounds.width() / surfaceContentWidth;
962 mExtraVScale = mTmpStackBounds.height() / surfaceContentHeight;
963
964 // Since we are scaled to fit in our previously desired crop, we can now
965 // expose the whole window in buffer space, and not risk extending
966 // past where the system would have cropped us
967 clipRect = null;
Winson Chung08f81892017-03-02 15:40:51 -0800968 }
Robert Carr0d00c2e2016-02-29 17:45:02 -0800969
Robert Carrfd4c9892017-02-01 10:28:28 -0800970 // In the case of ForceScaleToStack we scale entire tasks together,
Robert Carr0d00c2e2016-02-29 17:45:02 -0800971 // and so we need to scale our offsets relative to the task bounds
972 // or parent and child windows would fall out of alignment.
Winson Chung08f81892017-03-02 15:40:51 -0800973 posX -= (int) (attrs.x * (1 - mExtraHScale));
974 posY -= (int) (attrs.y * (1 - mExtraVScale));
975
Robert Carrbc133762016-05-12 14:04:38 -0700976 // Imagine we are scaling down. As we scale the buffer down, we decrease the
977 // distance between the surface top left, and the start of the surface contents
978 // (previously it was surfaceInsets.left pixels in screen space but now it
Robert Carr04092112016-06-02 12:56:12 -0700979 // will be surfaceInsets.left*mExtraHScale). This means in order to keep the
Robert Carrbc133762016-05-12 14:04:38 -0700980 // non inset content at the same position, we have to shift the whole window
981 // forward. Likewise for scaling up, we've increased this distance, and we need
982 // to shift by a negative number to compensate.
Robert Carr74a66a22018-02-23 12:17:51 -0800983 posX += insets.left * (1 - mExtraHScale);
984 posY += insets.top * (1 - mExtraVScale);
Robert Carrbc133762016-05-12 14:04:38 -0700985
Winson Chung08f81892017-03-02 15:40:51 -0800986 mSurfaceController.setPositionInTransaction((float) Math.floor(posX),
987 (float) Math.floor(posY), recoveringMemory);
Robert Carrc7294602016-05-13 11:32:05 -0700988
989 // Various surfaces in the scaled stack may resize at different times.
990 // We need to ensure for each surface, that we disable transformation matrix
991 // scaling in the same transaction which we resize the surface in.
992 // As we are in SCALING_MODE_SCALE_TO_WINDOW, SurfaceFlinger will
Robert Carra9408d42016-06-03 13:28:48 -0700993 // then take over the scaling until the new buffer arrives, and things
Robert Carrc7294602016-05-13 11:32:05 -0700994 // will be seamless.
Robert Carr2025bf842018-03-19 13:25:05 -0700995 if (mPipAnimationStarted == false) {
996 mForceScaleUntilResize = true;
997 mPipAnimationStarted = true;
998 }
Rob Carr06be6bb2018-02-06 16:26:06 +0000999 } else {
Robert Carr2025bf842018-03-19 13:25:05 -07001000 mPipAnimationStarted = false;
1001
Rob Carr06be6bb2018-02-06 16:26:06 +00001002 if (!w.mSeamlesslyRotated) {
chaviwbe43ac82018-04-04 15:14:49 -07001003 // Used to offset the WSA when stack position changes before a resize.
1004 int xOffset = mXOffset;
1005 int yOffset = mYOffset;
1006 if (mOffsetPositionForStackResize) {
1007 if (relayout) {
1008 // Once a relayout is called, reset the offset back to 0 and defer
1009 // setting it until a new frame with the updated size. This ensures that
1010 // the WS position is reset (so the stack position is shown) at the same
1011 // time that the buffer size changes.
1012 setOffsetPositionForStackResize(false);
Robert Carr2e20bcd2020-01-22 13:32:38 -08001013 mSurfaceController.deferTransactionUntil(mWin.getDeferTransactionBarrier(),
chaviwbe43ac82018-04-04 15:14:49 -07001014 mWin.getFrameNumber());
1015 } else {
Wale Ogunwale1ebcd8e2020-01-21 11:27:03 -08001016 final ActivityStack stack = mWin.getRootTask();
chaviwbe43ac82018-04-04 15:14:49 -07001017 mTmpPos.x = 0;
1018 mTmpPos.y = 0;
1019 if (stack != null) {
Evan Roskyed6767f2018-10-26 17:21:06 -07001020 stack.getRelativeDisplayedPosition(mTmpPos);
chaviwbe43ac82018-04-04 15:14:49 -07001021 }
1022
1023 xOffset = -mTmpPos.x;
1024 yOffset = -mTmpPos.y;
1025
1026 // Crop also needs to be extended so the bottom isn't cut off when the WSA
1027 // position is moved.
1028 if (clipRect != null) {
1029 clipRect.right += mTmpPos.x;
1030 clipRect.bottom += mTmpPos.y;
1031 }
1032 }
1033 }
1034 mSurfaceController.setPositionInTransaction(xOffset, yOffset, recoveringMemory);
Rob Carr06be6bb2018-02-06 16:26:06 +00001035 }
Robert Carr0d00c2e2016-02-29 17:45:02 -08001036 }
1037
Robert Carra9408d42016-06-03 13:28:48 -07001038 // If we are ending the scaling mode. We switch to SCALING_MODE_FREEZE
Robert Carr6da3cc02016-06-16 15:17:07 -07001039 // to prevent further updates until buffer latch.
Vishnu Nairddd80742018-08-21 14:12:46 -07001040 // We also need to freeze the Surface geometry until a buffer
1041 // comes in at the new size (normally position and crop are unfrozen).
chaviw007340c2019-09-04 16:07:37 -07001042 // deferTransactionUntil accomplishes this for us.
Vishnu Nairddd80742018-08-21 14:12:46 -07001043 if (wasForceScaled && !mForceScaleUntilResize) {
Robert Carr2e20bcd2020-01-22 13:32:38 -08001044 mSurfaceController.deferTransactionUntil(mWin.getDeferTransactionBarrier(),
Vishnu Nairb040c012018-09-07 11:38:32 -07001045 mWin.getFrameNumber());
Robert Carra9408d42016-06-03 13:28:48 -07001046 mSurfaceController.forceScaleableInTransaction(false);
1047 }
Robert Carr4320d332016-06-10 15:13:32 -07001048
Vishnu Nairddd80742018-08-21 14:12:46 -07001049
Robert Carr6da3cc02016-06-16 15:17:07 -07001050 if (!w.mSeamlesslyRotated) {
chaviw23012112017-12-20 15:29:04 -08001051 applyCrop(clipRect, recoveringMemory);
Robert Carr6da3cc02016-06-16 15:17:07 -07001052 mSurfaceController.setMatrixInTransaction(mDsDx * w.mHScale * mExtraHScale,
1053 mDtDx * w.mVScale * mExtraVScale,
Robert Carr0edf18f2017-02-21 20:01:47 -08001054 mDtDy * w.mHScale * mExtraHScale,
1055 mDsDy * w.mVScale * mExtraVScale, recoveringMemory);
Robert Carr6da3cc02016-06-16 15:17:07 -07001056 }
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001057
Robert Carre6a83512015-11-03 16:09:21 -08001058 if (mSurfaceResized) {
Chong Zhang5b2f1992015-11-13 15:40:36 -08001059 mReportSurfaceResized = true;
Riddle Hsu8419e4b2019-09-18 23:28:01 +08001060 mWin.getDisplayContent().pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001061 }
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001062 }
1063
Andrii Kulian283acd22017-08-03 04:03:51 -07001064 /**
1065 * Get rect of the task this window is currently in. If there is no task, rect will be set to
1066 * empty.
1067 */
1068 void getContainerRect(Rect rect) {
1069 final Task task = mWin.getTask();
1070 if (task != null) {
1071 task.getDimBounds(rect);
1072 } else {
1073 rect.left = rect.top = rect.right = rect.bottom = 0;
1074 }
1075 }
1076
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001077 void prepareSurfaceLocked(final boolean recoveringMemory) {
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001078 final WindowState w = mWin;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001079 if (!hasSurface()) {
Jorim Jaggi38d44ec2017-06-14 16:04:59 -07001080
1081 // There is no need to wait for an animation change if our window is gone for layout
1082 // already as we'll never be visible.
Bryce Lee8c3cf382017-07-06 19:47:10 -07001083 if (w.getOrientationChanging() && w.isGoneForLayoutLw()) {
Adrian Roosb125e0b2019-10-02 14:55:14 +02001084 ProtoLog.v(WM_DEBUG_ORIENTATION, "Orientation change skips hidden %s", w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001085 w.setOrientationChanging(false);
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001086 }
1087 return;
1088 }
1089
1090 boolean displayed = false;
1091
1092 computeShownFrameLocked();
1093
Craig Mautnera91f9e22012-09-14 16:22:08 -07001094 setSurfaceBoundariesLocked(recoveringMemory);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001095
Tiger Huang50d45462018-05-25 22:57:52 +08001096 if (mIsWallpaper && !w.mWallpaperVisible) {
Craig Mautner0fa77c12012-06-11 15:57:19 -07001097 // Wallpaper is no longer visible and there is no wp target => hide it.
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001098 hide("prepareSurfaceLocked");
Wale Ogunwale9d147902016-07-16 11:58:55 -07001099 } else if (w.isParentWindowHidden() || !w.isOnScreen()) {
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001100 hide("prepareSurfaceLocked");
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001101 mWallpaperControllerLocked.hideWallpapers(w);
Craig Mautnerb9836b92012-06-11 11:40:09 -07001102
Jorim Jaggi38d44ec2017-06-14 16:04:59 -07001103 // If we are waiting for this window to handle an orientation change. If this window is
1104 // really hidden (gone for layout), there is no point in still waiting for it.
1105 // Note that this does introduce a potential glitch if the window becomes unhidden
1106 // before it has drawn for the new orientation.
Bryce Lee8c3cf382017-07-06 19:47:10 -07001107 if (w.getOrientationChanging() && w.isGoneForLayoutLw()) {
1108 w.setOrientationChanging(false);
Adrian Roosb125e0b2019-10-02 14:55:14 +02001109 ProtoLog.v(WM_DEBUG_ORIENTATION,
1110 "Orientation change skips hidden %s", w);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001111 }
Jorim Jaggi35d328a2018-08-14 17:00:20 +02001112 } else if (mLastAlpha != mShownAlpha
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001113 || mLastDsDx != mDsDx
1114 || mLastDtDx != mDtDx
1115 || mLastDsDy != mDsDy
1116 || mLastDtDy != mDtDy
1117 || w.mLastHScale != w.mHScale
1118 || w.mLastVScale != w.mVScale
Craig Mautner749a7bb2012-04-02 13:49:53 -07001119 || mLastHidden) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001120 displayed = true;
1121 mLastAlpha = mShownAlpha;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001122 mLastDsDx = mDsDx;
1123 mLastDtDx = mDtDx;
1124 mLastDsDy = mDsDy;
1125 mLastDtDy = mDtDy;
1126 w.mLastHScale = w.mHScale;
1127 w.mLastVScale = w.mVScale;
Adrian Roosb125e0b2019-10-02 14:55:14 +02001128 ProtoLog.i(WM_SHOW_TRANSACTIONS,
1129 "SURFACE controller=%s alpha=%f matrix=[%f*%f,%f*%f][%f*%f,%f*%f]: %s",
1130 mSurfaceController, mShownAlpha, mDsDx, w.mHScale, mDtDx, w.mVScale,
1131 mDtDy, w.mHScale, mDsDy, w.mVScale, w);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001132
Robert Carre6a83512015-11-03 16:09:21 -08001133 boolean prepared =
Robert Carraf422a82017-04-10 18:34:33 -07001134 mSurfaceController.prepareToShowInTransaction(mShownAlpha,
Robert Carr04092112016-06-02 12:56:12 -07001135 mDsDx * w.mHScale * mExtraHScale,
1136 mDtDx * w.mVScale * mExtraVScale,
Robert Carr0edf18f2017-02-21 20:01:47 -08001137 mDtDy * w.mHScale * mExtraHScale,
1138 mDsDy * w.mVScale * mExtraVScale,
Robert Carre6a83512015-11-03 16:09:21 -08001139 recoveringMemory);
1140
Robert Carr03206af2017-07-10 18:24:21 -07001141 if (prepared && mDrawState == HAS_DRAWN) {
1142 if (mLastHidden) {
1143 if (showSurfaceRobustlyLocked()) {
1144 markPreservedSurfaceForDestroy();
1145 mAnimator.requestRemovalOfReplacedWindows(w);
1146 mLastHidden = false;
1147 if (mIsWallpaper) {
1148 w.dispatchWallpaperVisibility(true);
1149 }
Riddle Hsu8419e4b2019-09-18 23:28:01 +08001150 final DisplayContent displayContent = w.getDisplayContent();
1151 if (!displayContent.getLastHasContent()) {
Jorim Jaggif1292892018-09-10 11:58:13 +02001152 // This draw means the difference between unique content and mirroring.
1153 // Run another pass through performLayout to set mHasContent in the
1154 // LogicalDisplay.
Riddle Hsu8419e4b2019-09-18 23:28:01 +08001155 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
Vishnu Nairf7645aa2019-06-18 11:14:01 -07001156 if (DEBUG_LAYOUT_REPEATS) {
Jorim Jaggif1292892018-09-10 11:58:13 +02001157 mService.mWindowPlacerLocked.debugLayoutRepeats(
1158 "showSurfaceRobustlyLocked " + w,
Riddle Hsu8419e4b2019-09-18 23:28:01 +08001159 displayContent.pendingLayoutChanges);
Jorim Jaggif1292892018-09-10 11:58:13 +02001160 }
Tiger Huang50d45462018-05-25 22:57:52 +08001161 }
Robert Carr03206af2017-07-10 18:24:21 -07001162 } else {
1163 w.setOrientationChanging(false);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001164 }
Robert Carr03206af2017-07-10 18:24:21 -07001165 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001166 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001167 if (hasSurface()) {
Robert Carre6a83512015-11-03 16:09:21 -08001168 w.mToken.hasVisible = true;
1169 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001170 } else {
lumark9bca6b42019-10-17 18:35:22 +08001171 if (DEBUG_ANIM && mWin.isAnimating(TRANSITION | PARENTS)) {
Chong Zhange05db742016-02-16 16:58:37 -08001172 Slog.v(TAG, "prepareSurface: No changes in animation for " + this);
Craig Mautner83339b42012-05-01 22:13:23 -07001173 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001174 displayed = true;
1175 }
1176
Bryce Lee8c3cf382017-07-06 19:47:10 -07001177 if (w.getOrientationChanging()) {
Jorim Jaggi38d44ec2017-06-14 16:04:59 -07001178 if (!w.isDrawnLw()) {
1179 mAnimator.mBulkUpdateParams &= ~SET_ORIENTATION_CHANGE_COMPLETE;
1180 mAnimator.mLastWindowFreezeSource = w;
Adrian Roosb125e0b2019-10-02 14:55:14 +02001181 ProtoLog.v(WM_DEBUG_ORIENTATION,
1182 "Orientation continue waiting for draw in %s", w);
Jorim Jaggi38d44ec2017-06-14 16:04:59 -07001183 } else {
Bryce Lee8c3cf382017-07-06 19:47:10 -07001184 w.setOrientationChanging(false);
Adrian Roosb125e0b2019-10-02 14:55:14 +02001185 ProtoLog.v(WM_DEBUG_ORIENTATION, "Orientation change complete in %s", w);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001186 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -07001187 }
1188
1189 if (displayed) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001190 w.mToken.hasVisible = true;
1191 }
1192 }
1193
Craig Mautneref655012013-01-03 11:20:24 -08001194 void setTransparentRegionHintLocked(final Region region) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001195 if (mSurfaceController == null) {
1196 Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true");
1197 return;
1198 }
Robert Carre6a83512015-11-03 16:09:21 -08001199 mSurfaceController.setTransparentRegionHint(region);
Craig Mautner48ba1e72012-04-02 13:18:16 -07001200 }
1201
Robert Carr217e7cc2018-01-31 18:08:39 -08001202 boolean setWallpaperOffset(int dx, int dy) {
1203 if (mXOffset == dx && mYOffset == dy) {
1204 return false;
1205 }
1206 mXOffset = dx;
1207 mYOffset = dy;
Robert Carre6a83512015-11-03 16:09:21 -08001208
1209 try {
Craig Mautner71dd1b62014-02-18 15:48:52 -08001210 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setWallpaperOffset");
Robert Carr68e5c9e2016-09-14 10:50:09 -07001211 mService.openSurfaceTransaction();
Robert Carr217e7cc2018-01-31 18:08:39 -08001212 mSurfaceController.setPositionInTransaction(dx, dy, false);
chaviw23012112017-12-20 15:29:04 -08001213 applyCrop(null, false);
Robert Carre6a83512015-11-03 16:09:21 -08001214 } catch (RuntimeException e) {
1215 Slog.w(TAG, "Error positioning surface of " + mWin
Robert Carr217e7cc2018-01-31 18:08:39 -08001216 + " pos=(" + dx + "," + dy + ")", e);
Robert Carre6a83512015-11-03 16:09:21 -08001217 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +02001218 mService.closeSurfaceTransaction("setWallpaperOffset");
Robert Carre6a83512015-11-03 16:09:21 -08001219 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1220 "<<< CLOSE TRANSACTION setWallpaperOffset");
Robert Carr217e7cc2018-01-31 18:08:39 -08001221 return true;
Craig Mautner48ba1e72012-04-02 13:18:16 -07001222 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001223 }
1224
John Reck80181b92015-05-19 11:09:32 -07001225 /**
1226 * Try to change the pixel format without recreating the surface. This
1227 * will be common in the case of changing from PixelFormat.OPAQUE to
1228 * PixelFormat.TRANSLUCENT in the hardware-accelerated case as both
1229 * requested formats resolve to the same underlying SurfaceControl format
1230 * @return True if format was succesfully changed, false otherwise
1231 */
1232 boolean tryChangeFormatInPlaceLocked() {
Robert Carre6a83512015-11-03 16:09:21 -08001233 if (mSurfaceController == null) {
John Reck80181b92015-05-19 11:09:32 -07001234 return false;
1235 }
1236 final LayoutParams attrs = mWin.getAttrs();
Wale Ogunwalee7bf46b2015-09-30 09:19:28 -07001237 final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0;
John Reck80181b92015-05-19 11:09:32 -07001238 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
1239 if (format == mSurfaceFormat) {
1240 setOpaqueLocked(!PixelFormat.formatHasAlpha(attrs.format));
1241 return true;
1242 }
1243 return false;
1244 }
1245
Craig Mautner6f612042014-09-07 13:13:23 -07001246 void setOpaqueLocked(boolean isOpaque) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001247 if (mSurfaceController == null) {
1248 return;
1249 }
Robert Carre6a83512015-11-03 16:09:21 -08001250 mSurfaceController.setOpaque(isOpaque);
Craig Mautner71dd1b62014-02-18 15:48:52 -08001251 }
1252
Wale Ogunwalef5ad42f2015-06-12 13:59:03 -07001253 void setSecureLocked(boolean isSecure) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001254 if (mSurfaceController == null) {
1255 return;
1256 }
Robert Carre6a83512015-11-03 16:09:21 -08001257 mSurfaceController.setSecure(isSecure);
Wale Ogunwalef5ad42f2015-06-12 13:59:03 -07001258 }
1259
Peiyong Lin75045382019-03-04 19:22:33 -08001260 void setColorSpaceAgnosticLocked(boolean agnostic) {
1261 if (mSurfaceController == null) {
1262 return;
1263 }
1264 mSurfaceController.setColorSpaceAgnostic(agnostic);
1265 }
1266
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001267 /**
1268 * Have the surface flinger show a surface, robustly dealing with
1269 * error conditions. In particular, if there is not enough memory
1270 * to show the surface, then we will try to get rid of other surfaces
1271 * in order to succeed.
1272 *
1273 * @return Returns true if the surface was successfully shown.
1274 */
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001275 private boolean showSurfaceRobustlyLocked() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001276 if (mWin.getWindowConfiguration().windowsAreScaleable()) {
Robert Carr1b5ea722016-04-20 13:23:28 -07001277 mSurfaceController.forceScaleableInTransaction(true);
1278 }
1279
Robert Carre6a83512015-11-03 16:09:21 -08001280 boolean shown = mSurfaceController.showRobustlyInTransaction();
1281 if (!shown)
1282 return false;
1283
Robert Carr849d2932018-05-01 12:14:48 -07001284 // If we had a preserved surface it's no longer needed, and it may be harmful
1285 // if we are transparent.
1286 if (mPendingDestroySurface != null && mDestroyPreservedSurfaceUponRedraw) {
Vishnu Nairf7645aa2019-06-18 11:14:01 -07001287 final SurfaceControl pendingSurfaceControl = mPendingDestroySurface.mSurfaceControl;
Vishnu Nair8cb00ae2019-08-02 15:20:29 -07001288 mPostDrawTransaction.reparent(pendingSurfaceControl, null);
Vishnu Nairf7645aa2019-06-18 11:14:01 -07001289 mPostDrawTransaction.reparentChildren(pendingSurfaceControl,
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001290 mSurfaceController.mSurfaceControl);
Robert Carr849d2932018-05-01 12:14:48 -07001291 }
1292
Vishnu Nair3b037f72019-07-22 12:55:58 -07001293 SurfaceControl.mergeToGlobalTransaction(mPostDrawTransaction);
Robert Carre6a83512015-11-03 16:09:21 -08001294 return true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001295 }
1296
1297 void applyEnterAnimationLocked() {
Robert Carrb439a632016-04-07 22:52:10 -07001298 // If we are the new part of a window replacement transition and we have requested
1299 // not to animate, we instead want to make it seamless, so we don't want to apply
1300 // an enter transition.
1301 if (mWin.mSkipEnterAnimationForSeamlessReplacement) {
1302 return;
1303 }
lumarkce596d32019-06-12 16:58:35 +08001304
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001305 final int transit;
1306 if (mEnterAnimationPending) {
1307 mEnterAnimationPending = false;
1308 transit = WindowManagerPolicy.TRANSIT_ENTER;
1309 } else {
1310 transit = WindowManagerPolicy.TRANSIT_SHOW;
1311 }
lumark2726eb62019-06-19 21:25:54 +08001312
1313 // We don't apply animation for application main window here since this window type
1314 // should be controlled by AppWindowToken in general.
1315 if (mAttrType != TYPE_BASE_APPLICATION) {
1316 applyAnimationLocked(transit, true);
1317 }
1318
Rhed Jao02655dc2018-10-30 20:44:52 +08001319 if (mService.mAccessibilityController != null) {
Svetoslav8e3feb12014-02-24 13:46:47 -08001320 mService.mAccessibilityController.onWindowTransitionLocked(mWin, transit);
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -07001321 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001322 }
1323
1324 /**
1325 * Choose the correct animation and set it to the passed WindowState.
Craig Mautner4b71aa12012-12-27 17:20:01 -08001326 * @param transit If AppTransition.TRANSIT_PREVIEW_DONE and the app window has been drawn
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001327 * then the animation will be app_starting_exit. Any other value loads the animation from
1328 * the switch statement below.
1329 * @param isEntrance The animation type the last time this was called. Used to keep from
1330 * loading the same animation twice.
1331 * @return true if an animation has been loaded.
1332 */
1333 boolean applyAnimationLocked(int transit, boolean isEntrance) {
lumark9bca6b42019-10-17 18:35:22 +08001334 if (mWin.isAnimating() && mAnimationIsEntrance == isEntrance) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001335 // If we are trying to apply an animation, but already running
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001336 // an animation of the same type, then just leave that one alone.
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001337 return true;
1338 }
1339
Jorim Jaggia5e10572017-11-15 14:36:26 +01001340 if (isEntrance && mWin.mAttrs.type == TYPE_INPUT_METHOD) {
1341 mWin.getDisplayContent().adjustForImeIfNeeded();
1342 mWin.setDisplayLayoutNeeded();
1343 mService.mWindowPlacerLocked.requestTraversal();
1344 }
1345
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001346 // Only apply an animation if the display isn't frozen. If it is
1347 // frozen, there is no reason to animate and it can cause strange
1348 // artifacts when we unfreeze the display if some different animation
1349 // is running.
David Stevens9440dc82017-03-16 19:00:20 -07001350 if (mWin.mToken.okToAnimate()) {
Riddle Hsu2ca561b2019-10-08 21:58:58 +08001351 int anim = mWin.getDisplayContent().getDisplayPolicy().selectAnimation(mWin, transit);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001352 int attr = -1;
1353 Animation a = null;
Riddle Hsu2ca561b2019-10-08 21:58:58 +08001354 if (anim != DisplayPolicy.ANIMATION_STYLEABLE) {
1355 if (anim != DisplayPolicy.ANIMATION_NONE) {
1356 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "WSA#loadAnimation");
1357 a = AnimationUtils.loadAnimation(mContext, anim);
1358 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
1359 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001360 } else {
1361 switch (transit) {
1362 case WindowManagerPolicy.TRANSIT_ENTER:
1363 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
1364 break;
1365 case WindowManagerPolicy.TRANSIT_EXIT:
1366 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
1367 break;
1368 case WindowManagerPolicy.TRANSIT_SHOW:
1369 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
1370 break;
1371 case WindowManagerPolicy.TRANSIT_HIDE:
1372 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
1373 break;
1374 }
1375 if (attr >= 0) {
lumark588a3e82018-07-20 18:53:54 +08001376 a = mWin.getDisplayContent().mAppTransition.loadAnimationAttr(
1377 mWin.mAttrs, attr, TRANSIT_NONE);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001378 }
1379 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001380 if (DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001381 "applyAnimation: win=" + this
1382 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
Craig Mautner4d7349b2012-04-20 14:52:47 -07001383 + " a=" + a
Craig Mautner8863cca2012-09-18 15:04:34 -07001384 + " transit=" + transit
lumarkce596d32019-06-12 16:58:35 +08001385 + " type=" + mAttrType
Craig Mautner83339b42012-05-01 22:13:23 -07001386 + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001387 if (a != null) {
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -08001388 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
Riddle Hsu2ca561b2019-10-08 21:58:58 +08001389 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "WSA#startAnimation");
Jorim Jaggia5e10572017-11-15 14:36:26 +01001390 mWin.startAnimation(a);
Riddle Hsu2ca561b2019-10-08 21:58:58 +08001391 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001392 mAnimationIsEntrance = isEntrance;
1393 }
1394 } else {
Jorim Jaggia5e10572017-11-15 14:36:26 +01001395 mWin.cancelAnimation();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001396 }
Chong Zhang8784be62016-06-28 15:25:07 -07001397
Jorim Jaggia5e10572017-11-15 14:36:26 +01001398 if (!isEntrance && mWin.mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001399 mWin.getDisplayContent().adjustForImeIfNeeded();
Jorim Jaggieb88d832016-04-13 20:17:43 -07001400 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001401
lumark5341d1c2019-12-14 01:54:02 +08001402 return mWin.isAnimating(PARENTS);
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001403 }
1404
Jeffrey Huangcb782852019-12-05 11:28:11 -08001405 void dumpDebug(ProtoOutputStream proto, long fieldId) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07001406 final long token = proto.start(fieldId);
Jeffrey Huangcb782852019-12-05 11:28:11 -08001407 mLastClipRect.dumpDebug(proto, LAST_CLIP_RECT);
Steven Timotiusaf03df62017-07-18 16:56:43 -07001408 if (mSurfaceController != null) {
Jeffrey Huangcb782852019-12-05 11:28:11 -08001409 mSurfaceController.dumpDebug(proto, SURFACE);
Steven Timotiusaf03df62017-07-18 16:56:43 -07001410 }
Vishnu Nair1d0fa072018-01-04 07:53:00 -08001411 proto.write(DRAW_STATE, mDrawState);
Jeffrey Huangcb782852019-12-05 11:28:11 -08001412 mSystemDecorRect.dumpDebug(proto, SYSTEM_DECOR_RECT);
Steven Timotiusaf03df62017-07-18 16:56:43 -07001413 proto.end(token);
1414 }
1415
Craig Mautnera2c77052012-03-26 12:14:43 -07001416 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01001417 if (mAnimationIsEntrance) {
1418 pw.print(prefix); pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
Craig Mautnera2c77052012-03-26 12:14:43 -07001419 }
Robert Carre6a83512015-11-03 16:09:21 -08001420 if (mSurfaceController != null) {
1421 mSurfaceController.dump(pw, prefix, dumpAll);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001422 }
Robert Carre6a83512015-11-03 16:09:21 -08001423 if (dumpAll) {
1424 pw.print(prefix); pw.print("mDrawState="); pw.print(drawStateToString());
1425 pw.print(prefix); pw.print(" mLastHidden="); pw.println(mLastHidden);
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001426 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001427 pw.print(" mLastClipRect="); mLastClipRect.printShortString(pw);
1428
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001429 if (!mLastFinalClipRect.isEmpty()) {
1430 pw.print(" mLastFinalClipRect="); mLastFinalClipRect.printShortString(pw);
1431 }
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001432 pw.println();
Robert Carre6a83512015-11-03 16:09:21 -08001433 }
1434
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001435 if (mPendingDestroySurface != null) {
1436 pw.print(prefix); pw.print("mPendingDestroySurface=");
1437 pw.println(mPendingDestroySurface);
1438 }
1439 if (mSurfaceResized || mSurfaceDestroyDeferred) {
1440 pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized);
1441 pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred);
1442 }
1443 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
1444 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
1445 pw.print(" mAlpha="); pw.print(mAlpha);
1446 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
1447 }
1448 if (mHaveMatrix || mWin.mGlobalScale != 1) {
1449 pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale);
1450 pw.print(" mDsDx="); pw.print(mDsDx);
1451 pw.print(" mDtDx="); pw.print(mDtDx);
Robert Carr0edf18f2017-02-21 20:01:47 -08001452 pw.print(" mDtDy="); pw.print(mDtDy);
1453 pw.print(" mDsDy="); pw.println(mDsDy);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001454 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001455 }
1456
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001457 @Override
1458 public String toString() {
Dianne Hackborn529e7442012-11-01 14:22:28 -07001459 StringBuffer sb = new StringBuffer("WindowStateAnimator{");
1460 sb.append(Integer.toHexString(System.identityHashCode(this)));
1461 sb.append(' ');
1462 sb.append(mWin.mAttrs.getTitle());
1463 sb.append('}');
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001464 return sb.toString();
1465 }
Robert Carre6a83512015-11-03 16:09:21 -08001466
1467 void reclaimSomeSurfaceMemory(String operation, boolean secure) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001468 mService.mRoot.reclaimSomeSurfaceMemory(this, operation, secure);
Robert Carre6a83512015-11-03 16:09:21 -08001469 }
1470
1471 boolean getShown() {
1472 if (mSurfaceController != null) {
1473 return mSurfaceController.getShown();
1474 }
1475 return false;
1476 }
1477
1478 void destroySurface() {
Wale Ogunwale722ff892016-02-18 13:37:55 -08001479 try {
1480 if (mSurfaceController != null) {
Robert Carra8828862018-02-05 16:17:36 -08001481 mSurfaceController.destroyNotInTransaction();
Wale Ogunwale722ff892016-02-18 13:37:55 -08001482 }
1483 } catch (RuntimeException e) {
1484 Slog.w(TAG, "Exception thrown when destroying surface " + this
1485 + " surface " + mSurfaceController + " session " + mSession + ": " + e);
1486 } finally {
1487 mWin.setHasSurface(false);
1488 mSurfaceController = null;
1489 mDrawState = NO_SURFACE;
1490 }
Robert Carre6a83512015-11-03 16:09:21 -08001491 }
Filip Gruszczynskif52dd202015-11-15 20:36:38 -08001492
Robert Carr8f0a3ad2017-02-15 19:30:28 -08001493 /** The force-scaled state for a given window can persist past
1494 * the state for it's stack as the windows complete resizing
1495 * independently of one another.
1496 */
1497 boolean isForceScaled() {
1498 final Task task = mWin.getTask();
Wale Ogunwale0b3d2922019-12-30 08:55:07 -08001499 if (task != null && task.getStack().isForceScaled()) {
Robert Carr8f0a3ad2017-02-15 19:30:28 -08001500 return true;
1501 }
1502 return mForceScaleUntilResize;
1503 }
Robert Carrd5c7dd62017-03-08 10:39:30 -08001504
1505 void detachChildren() {
Jorim Jaggi35e049a2019-07-16 15:03:14 +02001506
1507 // Do not detach children of starting windows, as their lifecycle is well under control and
1508 // it may lead to issues in case we relaunch when we just added the starting window.
1509 if (mWin.mAttrs.type == TYPE_APPLICATION_STARTING) {
1510 return;
1511 }
Robert Carrd5c7dd62017-03-08 10:39:30 -08001512 if (mSurfaceController != null) {
1513 mSurfaceController.detachChildren();
1514 }
Robert Carr7b3d11d2018-03-15 14:34:45 -07001515 mChildrenDetached = true;
Robert Carrd5c7dd62017-03-08 10:39:30 -08001516 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01001517
chaviwbe43ac82018-04-04 15:14:49 -07001518 void setOffsetPositionForStackResize(boolean offsetPositionForStackResize) {
1519 mOffsetPositionForStackResize = offsetPositionForStackResize;
1520 }
Robert Carr2e20bcd2020-01-22 13:32:38 -08001521
1522 SurfaceControl getDeferTransactionBarrier() {
1523 if (!hasSurface()) {
1524 return null;
1525 }
1526 return mSurfaceController.getDeferTransactionBarrier();
1527 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001528}