blob: 780d4714275b683589512398ab714260e95ce65e [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;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080029import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080030import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
31import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
32import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020033import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080034import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -080035import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_CROP;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080036import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
37import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
38import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
39import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
40import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang97782b42015-10-07 16:01:23 -070041import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080042import static com.android.server.wm.WindowManagerService.logWithStack;
Yi Jin6c6e9ca2018-03-20 16:53:35 -070043import static com.android.server.wm.WindowStateAnimatorProto.DRAW_STATE;
44import static com.android.server.wm.WindowStateAnimatorProto.LAST_CLIP_RECT;
45import static com.android.server.wm.WindowStateAnimatorProto.SURFACE;
46import static com.android.server.wm.WindowStateAnimatorProto.SYSTEM_DECOR_RECT;
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +020047import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070048
Craig Mautnerc2f9be02012-03-27 17:32:29 -070049import android.content.Context;
50import android.graphics.Matrix;
51import android.graphics.PixelFormat;
Craig Mautner7358fbf2012-04-12 21:06:33 -070052import android.graphics.Point;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070053import android.graphics.Rect;
Craig Mautner48ba1e72012-04-02 13:18:16 -070054import android.graphics.Region;
Craig Mautnera51a9562012-04-17 17:05:26 -070055import android.os.Debug;
Chong Zhang8784be62016-06-28 15:25:07 -070056import android.os.Trace;
Craig Mautnera2c77052012-03-26 12:14:43 -070057import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -070058import android.util.proto.ProtoOutputStream;
Craig Mautner59c00972012-07-30 12:10:24 -070059import android.view.DisplayInfo;
Igor Murashkina86ab6402013-08-30 12:58:36 -070060import android.view.Surface.OutOfResourcesException;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080061import android.view.SurfaceControl;
Craig Mautnera2c77052012-03-26 12:14:43 -070062import android.view.WindowManager;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070063import android.view.WindowManager.LayoutParams;
Craig Mautnera2c77052012-03-26 12:14:43 -070064import android.view.animation.Animation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070065import android.view.animation.AnimationUtils;
Craig Mautnera2c77052012-03-26 12:14:43 -070066
Adrian Roose99bc052017-11-20 17:55:31 +010067import com.android.server.policy.WindowManagerPolicy;
68
Jorim Jaggia5e10572017-11-15 14:36:26 +010069import java.io.PrintWriter;
Craig Mautnera2c77052012-03-26 12:14:43 -070070
71/**
Craig Mautnerc2f9be02012-03-27 17:32:29 -070072 * Keep track of animations and surface operations for a single WindowState.
73 **/
Craig Mautnera2c77052012-03-26 12:14:43 -070074class WindowStateAnimator {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080075 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowStateAnimator" : TAG_WM;
Chong Zhang97782b42015-10-07 16:01:23 -070076 static final int WINDOW_FREEZE_LAYER = TYPE_LAYER_MULTIPLIER * 200;
Tiger Huang9c8ee262019-02-19 20:44:27 +080077 static final int PRESERVED_SURFACE_LAYER = 1;
Craig Mautnera2c77052012-03-26 12:14:43 -070078
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010079 /**
80 * Mode how the window gets clipped by the stack bounds during an animation: The clipping should
81 * be applied after applying the animation transformation, i.e. the stack bounds don't move
82 * during the animation.
83 */
84 static final int STACK_CLIP_AFTER_ANIM = 0;
85
86 /**
87 * Mode how the window gets clipped by the stack bounds: The clipping should be applied before
88 * applying the animation transformation, i.e. the stack bounds move with the window.
89 */
90 static final int STACK_CLIP_BEFORE_ANIM = 1;
91
92 /**
93 * Mode how window gets clipped by the stack bounds during an animation: Don't clip the window
94 * by the stack bounds.
95 */
96 static final int STACK_CLIP_NONE = 2;
97
Craig Mautner918b53b2012-07-09 14:15:54 -070098 // Unchanging local convenience fields.
Craig Mautnera2c77052012-03-26 12:14:43 -070099 final WindowManagerService mService;
100 final WindowState mWin;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700101 final WindowAnimator mAnimator;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700102 final Session mSession;
103 final WindowManagerPolicy mPolicy;
104 final Context mContext;
Craig Mautner918b53b2012-07-09 14:15:54 -0700105 final boolean mIsWallpaper;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -0700106 private final WallpaperController mWallpaperControllerLocked;
Craig Mautnera2c77052012-03-26 12:14:43 -0700107
Craig Mautnera2c77052012-03-26 12:14:43 -0700108 boolean mAnimationIsEntrance;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700109
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700110 /**
111 * Set when we have changed the size of the surface, to know that
112 * we must tell them application to resize (and thus redraw itself).
113 */
114 boolean mSurfaceResized;
Chong Zhang5b2f1992015-11-13 15:40:36 -0800115 /**
116 * Whether we should inform the client on next relayoutWindow that
117 * the surface has been resized since last time.
118 */
119 boolean mReportSurfaceResized;
Robert Carre6a83512015-11-03 16:09:21 -0800120 WindowSurfaceController mSurfaceController;
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800121 private WindowSurfaceController mPendingDestroySurface;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700122
123 /**
124 * Set if the client has asked that the destroy of its surface be delayed
125 * until it explicitly says it is okay.
126 */
127 boolean mSurfaceDestroyDeferred;
128
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800129 private boolean mDestroyPreservedSurfaceUponRedraw;
Craig Mautner7d8df392012-04-06 15:26:23 -0700130 float mShownAlpha = 0;
131 float mAlpha = 0;
132 float mLastAlpha = 0;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700133
Winson Chung399f6202014-03-19 10:47:20 -0700134 Rect mTmpClipRect = new Rect();
135 Rect mLastClipRect = new Rect();
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100136 Rect mLastFinalClipRect = new Rect();
Filip Gruszczynski4b8eea72015-09-14 18:16:19 -0700137 Rect mTmpStackBounds = new Rect();
Winson Chung08f81892017-03-02 15:40:51 -0800138 private Rect mTmpAnimatingBounds = new Rect();
139 private Rect mTmpSourceBounds = new Rect();
Winson Chung399f6202014-03-19 10:47:20 -0700140
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -0800141 /**
142 * This is rectangle of the window's surface that is not covered by
143 * system decorations.
144 */
145 private final Rect mSystemDecorRect = new Rect();
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -0800146
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700147 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
Robert Carr0edf18f2017-02-21 20:01:47 -0800148 private float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700149
150 boolean mHaveMatrix;
151
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700152 // Set to true if, when the window gets displayed, it should perform
153 // an enter animation.
154 boolean mEnterAnimationPending;
Craig Mautnera2c77052012-03-26 12:14:43 -0700155
Craig Mautner9c795042014-10-28 19:59:59 -0700156 /** Used to indicate that this window is undergoing an enter animation. Used for system
157 * windows to make the callback to View.dispatchOnWindowShownCallback(). Set when the
158 * window is first added or shown, cleared when the callback has been made. */
159 boolean mEnteringAnimation;
160
Chavi Weingartenb736e322018-02-23 00:27:54 +0000161 private final SurfaceControl.Transaction mTmpTransaction = new SurfaceControl.Transaction();
162
John Reck80181b92015-05-19 11:09:32 -0700163 /** The pixel format of the underlying SurfaceControl */
164 int mSurfaceFormat;
165
Craig Mautner749a7bb2012-04-02 13:49:53 -0700166 /** This is set when there is no Surface */
167 static final int NO_SURFACE = 0;
168 /** This is set after the Surface has been created but before the window has been drawn. During
169 * this time the surface is hidden. */
170 static final int DRAW_PENDING = 1;
171 /** This is set after the window has finished drawing for the first time but before its surface
172 * is shown. The surface will be displayed when the next layout is run. */
173 static final int COMMIT_DRAW_PENDING = 2;
174 /** This is set during the time after the window's drawing has been committed, and before its
175 * surface is actually shown. It is used to delay showing the surface until all windows in a
176 * token are ready to be shown. */
177 static final int READY_TO_SHOW = 3;
178 /** Set when the window has been shown in the screen the first time. */
179 static final int HAS_DRAWN = 4;
Adrian Roos3eeb4e62014-05-19 12:43:26 +0200180
Craig Mautner276a6eb2014-11-04 15:32:57 -0800181 String drawStateToString() {
182 switch (mDrawState) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700183 case NO_SURFACE: return "NO_SURFACE";
184 case DRAW_PENDING: return "DRAW_PENDING";
185 case COMMIT_DRAW_PENDING: return "COMMIT_DRAW_PENDING";
186 case READY_TO_SHOW: return "READY_TO_SHOW";
187 case HAS_DRAWN: return "HAS_DRAWN";
Craig Mautner276a6eb2014-11-04 15:32:57 -0800188 default: return Integer.toString(mDrawState);
Craig Mautner6fbda632012-07-03 09:26:39 -0700189 }
190 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700191 int mDrawState;
Craig Mautnera608b882012-03-30 13:03:49 -0700192
Craig Mautner749a7bb2012-04-02 13:49:53 -0700193 /** Was this window last hidden? */
194 boolean mLastHidden;
Craig Mautnera608b882012-03-30 13:03:49 -0700195
Craig Mautnerbec53f72012-04-05 11:49:05 -0700196 int mAttrType;
197
Robert Carrc7294602016-05-13 11:32:05 -0700198 boolean mForceScaleUntilResize;
199
Robert Carr04092112016-06-02 12:56:12 -0700200 // WindowState.mHScale and WindowState.mVScale contain the
201 // scale according to client specified layout parameters (e.g.
202 // one layout size, with another surface size, creates such scaling).
203 // Here we track an additional scaling factor used to follow stack
204 // scaling (as in the case of the Pinned stack animation).
205 float mExtraHScale = (float) 1.0;
206 float mExtraVScale = (float) 1.0;
207
Robert Carr217e7cc2018-01-31 18:08:39 -0800208 // An offset in pixel of the surface contents from the window position. Used for Wallpaper
209 // to provide the effect of scrolling within a large surface. We just use these values as
210 // a cache.
211 int mXOffset = 0;
212 int mYOffset = 0;
213
chaviwbe43ac82018-04-04 15:14:49 -0700214 /**
215 * A flag to determine if the WSA needs to offset its position to compensate for the stack's
216 * position update before the WSA surface has resized.
217 */
218 private boolean mOffsetPositionForStackResize;
219
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800220 private final Rect mTmpSize = new Rect();
221
Robert Carrca4c5a62018-02-05 16:07:55 -0800222 private final SurfaceControl.Transaction mReparentTransaction = new SurfaceControl.Transaction();
223
Robert Carr7b3d11d2018-03-15 14:34:45 -0700224 // Used to track whether we have called detach children on the way to invisibility, in which
225 // case we need to give the client a new Surface if it lays back out to a visible state.
226 boolean mChildrenDetached = false;
227
Robert Carr2025bf842018-03-19 13:25:05 -0700228 // Set to true after the first frame of the Pinned stack animation
229 // and reset after the last to ensure we only reset mForceScaleUntilResize
230 // once per animation.
231 boolean mPipAnimationStarted = false;
232
chaviwbe43ac82018-04-04 15:14:49 -0700233 private final Point mTmpPos = new Point();
234
Craig Mautnerc431e892015-02-11 13:14:26 -0800235 WindowStateAnimator(final WindowState win) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800236 final WindowManagerService service = win.mWmService;
Craig Mautner918b53b2012-07-09 14:15:54 -0700237
Craig Mautnera2c77052012-03-26 12:14:43 -0700238 mService = service;
Craig Mautner918b53b2012-07-09 14:15:54 -0700239 mAnimator = service.mAnimator;
240 mPolicy = service.mPolicy;
241 mContext = service.mContext;
Craig Mautner918b53b2012-07-09 14:15:54 -0700242
243 mWin = win;
Craig Mautner918b53b2012-07-09 14:15:54 -0700244 mSession = win.mSession;
Craig Mautner918b53b2012-07-09 14:15:54 -0700245 mAttrType = win.mAttrs.type;
246 mIsWallpaper = win.mIsWallpaper;
wilsonshihc32538e2018-11-07 17:27:34 +0800247 mWallpaperControllerLocked = win.getDisplayContent().mWallpaperController;
Craig Mautnera2c77052012-03-26 12:14:43 -0700248 }
249
Jorim Jaggia5e10572017-11-15 14:36:26 +0100250 void onAnimationFinished() {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700251 // Done animating, clean up.
252 if (DEBUG_ANIM) Slog.v(
Jorim Jaggia5e10572017-11-15 14:36:26 +0100253 TAG, "Animation done in " + this + ": exiting=" + mWin.mAnimatingExit
254 + ", reportedVisible="
255 + (mWin.mAppToken != null ? mWin.mAppToken.reportedVisible : false));
Craig Mautnera2c77052012-03-26 12:14:43 -0700256
Filip Gruszczynski14b4e572015-11-03 15:53:55 -0800257 mWin.checkPolicyVisibilityChange();
Jorim Jaggia5e10572017-11-15 14:36:26 +0100258 final DisplayContent displayContent = mWin.getDisplayContent();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800259 if (mAttrType == LayoutParams.TYPE_STATUS_BAR && mWin.mPolicyVisibility) {
Craig Mautner81defc72013-10-29 11:10:42 -0700260 // Upon completion of a not-visible to visible status bar animation a relayout is
261 // required.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800262 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700263 displayContent.setLayoutNeeded();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800264 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700265 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700266 mWin.onExitAnimationDone();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800267 final int displayId = mWin.getDisplayId();
Jorim Jaggia5e10572017-11-15 14:36:26 +0100268 int pendingLayoutChanges = FINISH_LAYOUT_REDO_ANIM;
269 if (displayContent.mWallpaperController.isWallpaperTarget(mWin)) {
270 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
271 }
272 mAnimator.setPendingLayoutChanges(displayId, pendingLayoutChanges);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800273 if (DEBUG_LAYOUT_REPEATS)
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700274 mService.mWindowPlacerLocked.debugLayoutRepeats(
275 "WindowStateAnimator", mAnimator.getPendingLayoutChanges(displayId));
Craig Mautnera2c77052012-03-26 12:14:43 -0700276
277 if (mWin.mAppToken != null) {
278 mWin.mAppToken.updateReportedVisibilityLocked();
279 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700280 }
281
Chavi Weingartenb736e322018-02-23 00:27:54 +0000282 void hide(SurfaceControl.Transaction transaction, String reason) {
Craig Mautner0afddcb2012-05-08 15:38:00 -0700283 if (!mLastHidden) {
284 //dump();
285 mLastHidden = true;
Jorim Jaggi50575902018-04-10 17:49:30 +0200286
287 // We may have a preserved surface which we no longer need. If there was a quick
288 // VISIBLE, GONE, VISIBLE, GONE sequence, the surface may never draw, so we don't mark
289 // it to be destroyed in prepareSurfaceLocked.
290 markPreservedSurfaceForDestroy();
291
Wale Ogunwalef9e09782015-11-09 12:42:37 -0800292 if (mSurfaceController != null) {
Chavi Weingartenb736e322018-02-23 00:27:54 +0000293 mSurfaceController.hide(transaction, reason);
Wale Ogunwalef9e09782015-11-09 12:42:37 -0800294 }
Craig Mautner0afddcb2012-05-08 15:38:00 -0700295 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700296 }
297
Chavi Weingartenb736e322018-02-23 00:27:54 +0000298 void hide(String reason) {
299 hide(mTmpTransaction, reason);
300 SurfaceControl.mergeToGlobalTransaction(mTmpTransaction);
301 }
302
Craig Mautnera608b882012-03-30 13:03:49 -0700303 boolean finishDrawingLocked() {
Craig Mautner42d04db2014-11-06 12:13:23 -0800304 final boolean startingWindow =
305 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
306 if (DEBUG_STARTING_WINDOW && startingWindow) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700307 Slog.v(TAG, "Finishing drawing window " + mWin + ": mDrawState="
Craig Mautner276a6eb2014-11-04 15:32:57 -0800308 + drawStateToString());
Craig Mautner6fbda632012-07-03 09:26:39 -0700309 }
Robert Carr1ca6a332016-04-11 18:00:43 -0700310
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200311 boolean layoutNeeded = false;
Chong Zhang92147042016-05-09 12:47:11 -0700312
Craig Mautner749a7bb2012-04-02 13:49:53 -0700313 if (mDrawState == DRAW_PENDING) {
Robert Carre13b58e2017-08-31 14:50:44 -0700314 if (DEBUG_ANIM || SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
Chong Zhang5b2f1992015-11-13 15:40:36 -0800315 Slog.v(TAG, "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING " + mWin + " in "
Robert Carre6a83512015-11-03 16:09:21 -0800316 + mSurfaceController);
Craig Mautner42d04db2014-11-06 12:13:23 -0800317 if (DEBUG_STARTING_WINDOW && startingWindow) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700318 Slog.v(TAG, "Draw state now committed in " + mWin);
319 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700320 mDrawState = COMMIT_DRAW_PENDING;
Chong Zhangcbbcc0f2016-05-17 20:46:58 -0700321 layoutNeeded = true;
Craig Mautnera608b882012-03-30 13:03:49 -0700322 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700323
Chong Zhangcbbcc0f2016-05-17 20:46:58 -0700324 return layoutNeeded;
Craig Mautnera608b882012-03-30 13:03:49 -0700325 }
326
327 // This must be called while inside a transaction.
Craig Mautnerc431e892015-02-11 13:14:26 -0800328 boolean commitFinishDrawingLocked() {
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200329 if (DEBUG_STARTING_WINDOW_VERBOSE &&
Craig Mautner6fbda632012-07-03 09:26:39 -0700330 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
331 Slog.i(TAG, "commitFinishDrawingLocked: " + mWin + " cur mDrawState="
Craig Mautner276a6eb2014-11-04 15:32:57 -0800332 + drawStateToString());
Craig Mautner6fbda632012-07-03 09:26:39 -0700333 }
Craig Mautner276a6eb2014-11-04 15:32:57 -0800334 if (mDrawState != COMMIT_DRAW_PENDING && mDrawState != READY_TO_SHOW) {
Craig Mautnera608b882012-03-30 13:03:49 -0700335 return false;
336 }
Robert Carre13b58e2017-08-31 14:50:44 -0700337 if (DEBUG_ANIM) {
Robert Carre6a83512015-11-03 16:09:21 -0800338 Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurfaceController);
Craig Mautner6fbda632012-07-03 09:26:39 -0700339 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700340 mDrawState = READY_TO_SHOW;
Chong Zhang0275e392015-09-17 10:41:44 -0700341 boolean result = false;
Craig Mautnera608b882012-03-30 13:03:49 -0700342 final AppWindowToken atoken = mWin.mAppToken;
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +0200343 if (atoken == null || atoken.canShowWindows()
344 || mWin.mAttrs.type == TYPE_APPLICATION_STARTING) {
Wale Ogunwale9d147902016-07-16 11:58:55 -0700345 result = mWin.performShowLocked();
Chong Zhang0275e392015-09-17 10:41:44 -0700346 }
Chong Zhang97782b42015-10-07 16:01:23 -0700347 return result;
Craig Mautnera608b882012-03-30 13:03:49 -0700348 }
349
Chong Zhang97782b42015-10-07 16:01:23 -0700350 void preserveSurfaceLocked() {
351 if (mDestroyPreservedSurfaceUponRedraw) {
Chong Zhangb9b0fec2016-02-11 18:51:51 -0800352 // This could happen when switching the surface mode very fast. For example,
353 // we preserved a surface when dragResizing changed to true. Then before the
354 // preserved surface is removed, dragResizing changed to false again.
355 // In this case, we need to leave the preserved surface alone, and destroy
356 // the actual surface, so that the createSurface call could create a surface
357 // of the proper size. The preserved surface will still be removed when client
358 // finishes drawing to the new surface.
359 mSurfaceDestroyDeferred = false;
360 destroySurfaceLocked();
361 mSurfaceDestroyDeferred = true;
Chong Zhang97782b42015-10-07 16:01:23 -0700362 return;
363 }
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -0800364 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, "SET FREEZE LAYER", false);
Wale Ogunwalef9e09782015-11-09 12:42:37 -0800365 if (mSurfaceController != null) {
Robert Carrb1579c82017-09-05 14:54:47 -0700366 // Our SurfaceControl is always at layer 0 within the parent Surface managed by
367 // window-state. We want this old Surface to stay on top of the new one
Tiger Huang9c8ee262019-02-19 20:44:27 +0800368 // until we do the swap, so we place it at a positive layer.
369 mSurfaceController.mSurfaceControl.setLayer(PRESERVED_SURFACE_LAYER);
Wale Ogunwalef9e09782015-11-09 12:42:37 -0800370 }
Chong Zhang97782b42015-10-07 16:01:23 -0700371 mDestroyPreservedSurfaceUponRedraw = true;
372 mSurfaceDestroyDeferred = true;
373 destroySurfaceLocked();
374 }
375
376 void destroyPreservedSurfaceLocked() {
377 if (!mDestroyPreservedSurfaceUponRedraw) {
378 return;
379 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800380 if (mSurfaceController != null) {
381 if (mPendingDestroySurface != null) {
382 // If we are preserving a surface but we aren't relaunching that means
383 // we are just doing an in-place switch. In that case any SurfaceFlinger side
384 // child layers need to be reparented to the new surface to make this
385 // transparent to the app.
386 if (mWin.mAppToken == null || mWin.mAppToken.isRelaunching() == false) {
Robert Carrca4c5a62018-02-05 16:07:55 -0800387 mReparentTransaction.reparentChildren(mPendingDestroySurface.mSurfaceControl,
388 mSurfaceController.mSurfaceControl.getHandle())
389 .apply();
Robert Carrd5c7dd62017-03-08 10:39:30 -0800390 }
391 }
392 }
393
Chong Zhang97782b42015-10-07 16:01:23 -0700394 destroyDeferredSurfaceLocked();
395 mDestroyPreservedSurfaceUponRedraw = false;
396 }
397
Chong Zhangeb665572016-05-09 18:28:27 -0700398 void markPreservedSurfaceForDestroy() {
399 if (mDestroyPreservedSurfaceUponRedraw
400 && !mService.mDestroyPreservedSurface.contains(mWin)) {
401 mService.mDestroyPreservedSurface.add(mWin);
402 }
403 }
404
Robert Carrda61ba92017-03-29 15:52:23 -0700405 private int getLayerStack() {
406 return mWin.getDisplayContent().getDisplay().getLayerStack();
407 }
408
Robert Carrecc06b32017-04-18 14:25:10 -0700409 void resetDrawState() {
410 mDrawState = DRAW_PENDING;
411
412 if (mWin.mAppToken == null) {
413 return;
414 }
415
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200416 if (!mWin.mAppToken.isSelfAnimating()) {
Robert Carrecc06b32017-04-18 14:25:10 -0700417 mWin.mAppToken.clearAllDrawn();
418 } else {
419 // Currently animating, persist current state of allDrawn until animation
420 // is complete.
421 mWin.mAppToken.deferClearAllDrawn = true;
422 }
423 }
424
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500425 WindowSurfaceController createSurfaceLocked(int windowType, int ownerUid) {
Alan Viveretteccb11e12014-07-08 16:04:02 -0700426 final WindowState w = mWin;
Chong Zhanga8975bd2016-01-28 17:13:47 -0800427
Wale Ogunwale722ff892016-02-18 13:37:55 -0800428 if (mSurfaceController != null) {
429 return mSurfaceController;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700430 }
Robert Carr7b3d11d2018-03-15 14:34:45 -0700431 mChildrenDetached = false;
Wale Ogunwale722ff892016-02-18 13:37:55 -0800432
Robert Carr132c9f52017-07-31 17:02:30 -0700433 if ((mWin.mAttrs.privateFlags & PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY) != 0) {
434 windowType = SurfaceControl.WINDOW_TYPE_DONT_SCREENSHOT;
435 }
436
Wale Ogunwale722ff892016-02-18 13:37:55 -0800437 w.setHasSurface(false);
438
439 if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG,
440 "createSurface " + this + ": mDrawState=DRAW_PENDING");
441
Robert Carrecc06b32017-04-18 14:25:10 -0700442 resetDrawState();
Wale Ogunwale722ff892016-02-18 13:37:55 -0800443
444 mService.makeWindowFreezingScreenIfNeededLocked(w);
445
446 int flags = SurfaceControl.HIDDEN;
447 final WindowManager.LayoutParams attrs = w.mAttrs;
448
449 if (mService.isSecureLocked(w)) {
450 flags |= SurfaceControl.SECURE;
451 }
452
chaviw9c81e632018-07-31 11:17:52 -0700453 calculateSurfaceBounds(w, attrs, mTmpSize);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800454 final int width = mTmpSize.width();
455 final int height = mTmpSize.height();
456
457 if (DEBUG_VISIBILITY) {
458 Slog.v(TAG, "Creating surface in session "
459 + mSession.mSurfaceSession + " window " + this
460 + " w=" + width + " h=" + height
461 + " x=" + mTmpSize.left + " y=" + mTmpSize.top
462 + " format=" + attrs.format + " flags=" + flags);
463 }
464
465 // We may abort, so initialize to defaults.
Wale Ogunwale722ff892016-02-18 13:37:55 -0800466 mLastClipRect.set(0, 0, 0, 0);
467
468 // Set up surface control with initial size.
469 try {
470
471 final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0;
472 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
473 if (!PixelFormat.formatHasAlpha(attrs.format)
474 // Don't make surface with surfaceInsets opaque as they display a
475 // translucent shadow.
476 && attrs.surfaceInsets.left == 0
477 && attrs.surfaceInsets.top == 0
478 && attrs.surfaceInsets.right == 0
479 && attrs.surfaceInsets.bottom == 0
480 // Don't make surface opaque when resizing to reduce the amount of
481 // artifacts shown in areas the app isn't drawing content to.
482 && !w.isDragResizing()) {
483 flags |= SurfaceControl.OPAQUE;
484 }
485
486 mSurfaceController = new WindowSurfaceController(mSession.mSurfaceSession,
Jorim Jaggia5e10572017-11-15 14:36:26 +0100487 attrs.getTitle().toString(), width, height, format, flags, this,
488 windowType, ownerUid);
Peiyong Lin75045382019-03-04 19:22:33 -0800489 mSurfaceController.setColorSpaceAgnostic((attrs.privateFlags
490 & WindowManager.LayoutParams.PRIVATE_FLAG_COLOR_SPACE_AGNOSTIC) != 0);
chaviwbe43ac82018-04-04 15:14:49 -0700491
492 setOffsetPositionForStackResize(false);
Robert Carr486bbb72017-05-30 11:25:22 -0700493 mSurfaceFormat = format;
Wale Ogunwale722ff892016-02-18 13:37:55 -0800494
495 w.setHasSurface(true);
496
497 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
498 Slog.i(TAG, " CREATE SURFACE "
499 + mSurfaceController + " IN SESSION "
500 + mSession.mSurfaceSession
501 + ": pid=" + mSession.mPid + " format="
502 + attrs.format + " flags=0x"
503 + Integer.toHexString(flags)
504 + " / " + this);
505 }
506 } catch (OutOfResourcesException e) {
507 Slog.w(TAG, "OutOfResourcesException creating surface");
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700508 mService.mRoot.reclaimSomeSurfaceMemory(this, "create", true);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800509 mDrawState = NO_SURFACE;
510 return null;
511 } catch (Exception e) {
Robert Carrb0f39362018-03-14 13:52:25 -0700512 Slog.e(TAG, "Exception creating surface (parent dead?)", e);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800513 mDrawState = NO_SURFACE;
514 return null;
515 }
516
517 if (WindowManagerService.localLOGV) Slog.v(TAG, "Got surface: " + mSurfaceController
Jorim Jaggi35d328a2018-08-14 17:00:20 +0200518 + ", set left=" + w.getFrameLw().left + " top=" + w.getFrameLw().top);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800519
520 if (SHOW_LIGHT_TRANSACTIONS) {
521 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
522 WindowManagerService.logSurface(w, "CREATE pos=("
chaviw492139a2018-07-16 16:07:35 -0700523 + w.getFrameLw().left + "," + w.getFrameLw().top + ") ("
Jorim Jaggi35d328a2018-08-14 17:00:20 +0200524 + width + "x" + height + ")" + " HIDE", false);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800525 }
526
Wale Ogunwale722ff892016-02-18 13:37:55 -0800527 mLastHidden = true;
528
529 if (WindowManagerService.localLOGV) Slog.v(TAG, "Created surface " + this);
Robert Carre6a83512015-11-03 16:09:21 -0800530 return mSurfaceController;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700531 }
532
chaviw9c81e632018-07-31 11:17:52 -0700533 private void calculateSurfaceBounds(WindowState w, LayoutParams attrs, Rect outSize) {
534 outSize.setEmpty();
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800535 if ((attrs.flags & FLAG_SCALED) != 0) {
536 // For a scaled surface, we always want the requested size.
chaviw9c81e632018-07-31 11:17:52 -0700537 outSize.right = w.mRequestedWidth;
538 outSize.bottom = w.mRequestedHeight;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800539 } else {
540 // When we're doing a drag-resizing, request a surface that's fullscreen size,
541 // so that we don't need to reallocate during the process. This also prevents
542 // buffer drops due to size mismatch.
543 if (w.isDragResizing()) {
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800544 final DisplayInfo displayInfo = w.getDisplayInfo();
chaviw9c81e632018-07-31 11:17:52 -0700545 outSize.right = displayInfo.logicalWidth;
546 outSize.bottom = displayInfo.logicalHeight;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800547 } else {
chaviw9c81e632018-07-31 11:17:52 -0700548 w.getCompatFrameSize(outSize);
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800549 }
550 }
551
552 // Something is wrong and SurfaceFlinger will not like this, try to revert to sane values.
Filip Gruszczynskie6ed1952015-12-21 09:34:16 -0800553 // This doesn't necessarily mean that there is an error in the system. The sizes might be
554 // incorrect, because it is before the first layout or draw.
chaviw9c81e632018-07-31 11:17:52 -0700555 if (outSize.width() < 1) {
556 outSize.right = 1;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800557 }
chaviw9c81e632018-07-31 11:17:52 -0700558 if (outSize.height() < 1) {
559 outSize.bottom = 1;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800560 }
561
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800562 // Adjust for surface insets.
chaviw9c81e632018-07-31 11:17:52 -0700563 outSize.inset(-attrs.surfaceInsets.left, -attrs.surfaceInsets.top,
564 -attrs.surfaceInsets.right, -attrs.surfaceInsets.bottom);
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800565 }
566
Chong Zhangeb22e8e2016-01-20 19:52:22 -0800567 boolean hasSurface() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200568 return mSurfaceController != null && mSurfaceController.hasSurface();
Chong Zhangeb22e8e2016-01-20 19:52:22 -0800569 }
570
Craig Mautner96868332012-12-04 14:29:11 -0800571 void destroySurfaceLocked() {
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700572 final AppWindowToken wtoken = mWin.mAppToken;
573 if (wtoken != null) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700574 if (mWin == wtoken.startingWindow) {
575 wtoken.startingDisplayed = false;
576 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700577 }
578
Wale Ogunwale722ff892016-02-18 13:37:55 -0800579 if (mSurfaceController == null) {
580 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700581 }
Wale Ogunwale722ff892016-02-18 13:37:55 -0800582
Wale Ogunwale722ff892016-02-18 13:37:55 -0800583 // When destroying a surface we want to make sure child windows are hidden. If we are
584 // preserving the surface until redraw though we intend to swap it out with another surface
585 // for resizing. In this case the window always remains visible to the user and the child
586 // windows should likewise remain visible.
Wale Ogunwale9d147902016-07-16 11:58:55 -0700587 if (!mDestroyPreservedSurfaceUponRedraw) {
588 mWin.mHidden = true;
Wale Ogunwale722ff892016-02-18 13:37:55 -0800589 }
590
591 try {
592 if (DEBUG_VISIBILITY) logWithStack(TAG, "Window " + this + " destroying surface "
593 + mSurfaceController + ", session " + mSession);
594 if (mSurfaceDestroyDeferred) {
595 if (mSurfaceController != null && mPendingDestroySurface != mSurfaceController) {
596 if (mPendingDestroySurface != null) {
597 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
598 WindowManagerService.logSurface(mWin, "DESTROY PENDING", true);
599 }
Robert Carra8828862018-02-05 16:17:36 -0800600 mPendingDestroySurface.destroyNotInTransaction();
Wale Ogunwale722ff892016-02-18 13:37:55 -0800601 }
602 mPendingDestroySurface = mSurfaceController;
603 }
604 } else {
605 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
606 WindowManagerService.logSurface(mWin, "DESTROY", true);
607 }
608 destroySurface();
609 }
610 // Don't hide wallpaper if we're deferring the surface destroy
611 // because of a surface change.
612 if (!mDestroyPreservedSurfaceUponRedraw) {
613 mWallpaperControllerLocked.hideWallpapers(mWin);
614 }
615 } catch (RuntimeException e) {
616 Slog.w(TAG, "Exception thrown when destroying Window " + this
617 + " surface " + mSurfaceController + " session " + mSession + ": " + e.toString());
618 }
619
620 // Whether the surface was preserved (and copied to mPendingDestroySurface) or not, it
621 // needs to be cleared to match the WindowState.mHasSurface state. It is also necessary
622 // so it can be recreated successfully in mPendingDestroySurface case.
623 mWin.setHasSurface(false);
624 if (mSurfaceController != null) {
625 mSurfaceController.setShown(false);
626 }
627 mSurfaceController = null;
628 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700629 }
630
Craig Mautner96868332012-12-04 14:29:11 -0800631 void destroyDeferredSurfaceLocked() {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700632 try {
633 if (mPendingDestroySurface != null) {
634 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -0800635 WindowManagerService.logSurface(mWin, "DESTROY PENDING", true);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700636 }
Robert Carra8828862018-02-05 16:17:36 -0800637 mPendingDestroySurface.destroyNotInTransaction();
Chong Zhang6e21cf42015-11-09 14:41:42 -0800638 // Don't hide wallpaper if we're destroying a deferred surface
639 // after a surface mode change.
640 if (!mDestroyPreservedSurfaceUponRedraw) {
641 mWallpaperControllerLocked.hideWallpapers(mWin);
642 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700643 }
644 } catch (RuntimeException e) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700645 Slog.w(TAG, "Exception thrown when destroying Window "
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700646 + this + " surface " + mPendingDestroySurface
647 + " session " + mSession + ": " + e.toString());
648 }
649 mSurfaceDestroyDeferred = false;
650 mPendingDestroySurface = null;
651 }
652
653 void computeShownFrameLocked() {
Craig Mautnera91f9e22012-09-14 16:22:08 -0700654 final int displayId = mWin.getDisplayId();
655 final ScreenRotationAnimation screenRotationAnimation =
656 mAnimator.getScreenRotationAnimationLocked(displayId);
Vishnu Nair83537a72018-07-19 21:27:48 -0700657 final boolean windowParticipatesInScreenRotationAnimation =
658 !mWin.mForceSeamlesslyRotate;
659 final boolean screenAnimation = screenRotationAnimation != null
660 && screenRotationAnimation.isAnimating()
661 && windowParticipatesInScreenRotationAnimation;
Robert Carr2f0fe622015-09-25 14:56:38 -0700662
Robert Carr44643c12017-09-27 14:57:38 -0700663 if (screenAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700664 // cache often used attributes locally
chaviw492139a2018-07-16 16:07:35 -0700665 final Rect frame = mWin.getFrameLw();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700666 final float tmpFloats[] = mService.mTmpFloats;
667 final Matrix tmpMatrix = mWin.mTmpMatrix;
668
669 // Compute the desired transformation.
Robert Carr44643c12017-09-27 14:57:38 -0700670 if (screenRotationAnimation.isRotating()) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700671 // If we are doing a screen animation, the global rotation
672 // applied to windows can result in windows that are carefully
673 // aligned with each other to slightly separate, allowing you
674 // to see what is behind them. An unsightly mess. This...
675 // thing... magically makes it call good: scale each window
676 // slightly (two pixels larger in each dimension, from the
677 // window's center).
678 final float w = frame.width();
679 final float h = frame.height();
680 if (w>=1 && h>=1) {
681 tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2);
682 } else {
683 tmpMatrix.reset();
684 }
685 } else {
686 tmpMatrix.reset();
687 }
Robert Carr44643c12017-09-27 14:57:38 -0700688
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700689 tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale);
Robert Carr29d196f2017-11-28 12:39:46 -0800690
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100691 // WindowState.prepareSurfaces expands for surface insets (in order they don't get
692 // clipped by the WindowState surface), so we need to go into the other direction here.
Robert Carr217e7cc2018-01-31 18:08:39 -0800693 tmpMatrix.postTranslate(mWin.mAttrs.surfaceInsets.left,
694 mWin.mAttrs.surfaceInsets.top);
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100695
Matthew Ng34a06d12017-02-03 11:56:08 -0800696
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700697 // "convert" it into SurfaceFlinger's format
698 // (a 2x2 matrix + an offset)
699 // Here we must not transform the position of the surface
700 // since it is already included in the transformation.
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800701 //Slog.i(TAG_WM, "Transform: " + matrix);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700702
703 mHaveMatrix = true;
704 tmpMatrix.getValues(tmpFloats);
705 mDsDx = tmpFloats[Matrix.MSCALE_X];
706 mDtDx = tmpFloats[Matrix.MSKEW_Y];
Robert Carr0edf18f2017-02-21 20:01:47 -0800707 mDtDy = tmpFloats[Matrix.MSKEW_X];
708 mDsDy = tmpFloats[Matrix.MSCALE_Y];
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700709
710 // Now set the alpha... but because our current hardware
711 // can't do alpha transformation on a non-opaque surface,
712 // turn it off if we are running an animation that is also
713 // transforming since it is more important to have that
714 // animation be smooth.
715 mShownAlpha = mAlpha;
716 if (!mService.mLimitedAlphaCompositing
717 || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format)
Robert Carr217e7cc2018-01-31 18:08:39 -0800718 || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDtDy, mDsDy)))) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800719 //Slog.i(TAG_WM, "Applying alpha transform");
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700720 if (screenAnimation) {
Craig Mautnera91f9e22012-09-14 16:22:08 -0700721 mShownAlpha *= screenRotationAnimation.getEnterTransformation().getAlpha();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700722 }
723 } else {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800724 //Slog.i(TAG_WM, "Not applying alpha transform");
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700725 }
726
Robert Carre13b58e2017-08-31 14:50:44 -0700727 if ((DEBUG_ANIM || WindowManagerService.localLOGV)
Craig Mautnera91f9e22012-09-14 16:22:08 -0700728 && (mShownAlpha == 1.0 || mShownAlpha == 0.0)) Slog.v(
729 TAG, "computeShownFrameLocked: Animating " + this + " mAlpha=" + mAlpha
Craig Mautnera91f9e22012-09-14 16:22:08 -0700730 + " screen=" + (screenAnimation ?
731 screenRotationAnimation.getEnterTransformation().getAlpha() : "null"));
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700732 return;
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700733 } else if (mIsWallpaper && mService.mRoot.mWallpaperActionPending) {
Craig Mautner4d7349b2012-04-20 14:52:47 -0700734 return;
Chong Zhang3005e752015-09-18 18:46:28 -0700735 } else if (mWin.isDragResizeChanged()) {
736 // This window is awaiting a relayout because user just started (or ended)
737 // drag-resizing. The shown frame (which affects surface size and pos)
738 // should not be updated until we get next finished draw with the new surface.
739 // Otherwise one or two frames rendered with old settings would be displayed
740 // with new geometry.
741 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700742 }
743
Filip Gruszczynski19723a42015-11-25 15:01:48 -0800744 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautner4d7349b2012-04-20 14:52:47 -0700745 TAG, "computeShownFrameLocked: " + this +
746 " not attached, mAlpha=" + mAlpha);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700747
Robert Carrb1579c82017-09-05 14:54:47 -0700748 mShownAlpha = mAlpha;
749 mHaveMatrix = false;
750 mDsDx = mWin.mGlobalScale;
751 mDtDx = 0;
752 mDtDy = 0;
753 mDsDy = mWin.mGlobalScale;
Robert Carref090ac2017-05-15 16:45:50 -0700754 }
755
Robert Carrfbbde852016-10-18 11:02:28 -0700756 /**
Robert Carrfbbde852016-10-18 11:02:28 -0700757 * Calculate the window-space crop rect and fill clipRect.
Wale Ogunwaleca9e0612016-12-02 07:45:59 -0800758 * @return true if clipRect has been filled otherwise, no window space crop should be applied.
Robert Carrfbbde852016-10-18 11:02:28 -0700759 */
Wale Ogunwaleca9e0612016-12-02 07:45:59 -0800760 private boolean calculateCrop(Rect clipRect) {
Robert Carrfbbde852016-10-18 11:02:28 -0700761 final WindowState w = mWin;
762 final DisplayContent displayContent = w.getDisplayContent();
763 clipRect.setEmpty();
764
765 if (displayContent == null) {
766 return false;
767 }
768
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700769 if (w.inPinnedWindowingMode()) {
Robert Carrfbbde852016-10-18 11:02:28 -0700770 return false;
771 }
772
Vishnu Nair83537a72018-07-19 21:27:48 -0700773 // During forced seamless rotation, the surface bounds get updated with the crop in the
774 // new rotation, which is not compatible with showing the surface in the old rotation.
775 // To work around that we disable cropping for such windows, as it is not necessary anyways.
776 if (w.mForceSeamlesslyRotate) {
777 return false;
778 }
779
Robert Carrfbbde852016-10-18 11:02:28 -0700780 // If we're animating, the wallpaper should only
781 // be updated at the end of the animation.
782 if (w.mAttrs.type == TYPE_WALLPAPER) {
783 return false;
784 }
785
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -0700786 if (DEBUG_WINDOW_CROP) Slog.d(TAG,
787 "Updating crop win=" + w + " mLastCrop=" + mLastClipRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -0700788
Robert Carrfbbde852016-10-18 11:02:28 -0700789 w.calculatePolicyCrop(mSystemDecorRect);
790
791 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "Applying decor to crop win=" + w + " mDecorFrame="
chaviw553b0212018-07-12 13:37:01 -0700792 + w.getDecorFrame() + " mSystemDecorRect=" + mSystemDecorRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -0700793
Robert Carr51a1b872015-12-08 14:03:13 -0800794 // We use the clip rect as provided by the tranformation for non-fullscreen windows to
795 // avoid premature clipping with the system decor rect.
Robert Carrf0586622018-01-29 13:03:43 -0800796 clipRect.set(mSystemDecorRect);
Evan Rosky4fb1e912019-03-06 13:54:43 -0800797 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "win=" + w + " Initial clip rect: " + clipRect);
Robert Carr51a1b872015-12-08 14:03:13 -0800798
Robert Carrfbbde852016-10-18 11:02:28 -0700799 w.expandForSurfaceInsets(clipRect);
Alan Viverette49a22e82014-07-12 20:01:27 -0700800
Alan Viverette49a22e82014-07-12 20:01:27 -0700801 // The clip rect was generated assuming (0,0) as the window origin,
802 // so we need to translate to match the actual surface coordinates.
Robert Carrfbbde852016-10-18 11:02:28 -0700803 clipRect.offset(w.mAttrs.surfaceInsets.left, w.mAttrs.surfaceInsets.top);
Robert Carr58f29132015-10-29 14:19:05 -0700804
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -0700805 if (DEBUG_WINDOW_CROP) Slog.d(TAG,
806 "win=" + w + " Clip rect after stack adjustment=" + clipRect);
Robert Carr58f29132015-10-29 14:19:05 -0700807
Chia-I Wue6bcaf12016-05-27 10:58:48 +0800808 w.transformClipRectFromScreenToSurfaceSpace(clipRect);
Robert Carr58f29132015-10-29 14:19:05 -0700809
Robert Carrfbbde852016-10-18 11:02:28 -0700810 return true;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800811 }
812
chaviw23012112017-12-20 15:29:04 -0800813 private void applyCrop(Rect clipRect, boolean recoveringMemory) {
Robert Carrfbbde852016-10-18 11:02:28 -0700814 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "applyCrop: win=" + mWin
chaviw23012112017-12-20 15:29:04 -0800815 + " clipRect=" + clipRect);
Robert Carr4320d332016-06-10 15:13:32 -0700816 if (clipRect != null) {
817 if (!clipRect.equals(mLastClipRect)) {
818 mLastClipRect.set(clipRect);
819 mSurfaceController.setCropInTransaction(clipRect, recoveringMemory);
820 }
821 } else {
822 mSurfaceController.clearCropInTransaction(recoveringMemory);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -0700823 }
Filip Gruszczynski4b8eea72015-09-14 18:16:19 -0700824 }
825
Wale Ogunwale4c8b7952015-04-07 10:49:40 -0700826 void setSurfaceBoundariesLocked(final boolean recoveringMemory) {
Wale Ogunwale027f4752017-05-12 10:37:16 -0700827 if (mSurfaceController == null) {
828 return;
829 }
830
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700831 final WindowState w = mWin;
Winson Chung08f81892017-03-02 15:40:51 -0800832 final LayoutParams attrs = mWin.getAttrs();
Robert Carr0d00c2e2016-02-29 17:45:02 -0800833 final Task task = w.getTask();
Alan Viveretteccb11e12014-07-08 16:04:02 -0700834
chaviw9c81e632018-07-31 11:17:52 -0700835 calculateSurfaceBounds(w, attrs, mTmpSize);
Chong Zhang0275e392015-09-17 10:41:44 -0700836
Robert Carr04092112016-06-02 12:56:12 -0700837 mExtraHScale = (float) 1.0;
838 mExtraVScale = (float) 1.0;
Robert Carre1034cc32016-02-01 13:08:15 -0800839
Robert Carr6da3cc02016-06-16 15:17:07 -0700840 boolean wasForceScaled = mForceScaleUntilResize;
Robert Carr6da3cc02016-06-16 15:17:07 -0700841
Robert Carrfed10072016-05-26 11:48:49 -0700842 // Once relayout has been called at least once, we need to make sure
843 // we only resize the client surface during calls to relayout. For
844 // clients which use indeterminate measure specs (MATCH_PARENT),
845 // we may try and change their window size without a call to relayout.
846 // However, this would be unsafe, as the client may be in the middle
847 // of producing a frame at the old size, having just completed layout
848 // to find the surface size changed underneath it.
chaviwbe43ac82018-04-04 15:14:49 -0700849 final boolean relayout = !w.mRelayoutCalled || w.mInRelayout;
850 if (relayout) {
Vishnu Naire86bd982018-11-28 13:23:17 -0800851 mSurfaceResized = mSurfaceController.setBufferSizeInTransaction(
Robert Carrfed10072016-05-26 11:48:49 -0700852 mTmpSize.width(), mTmpSize.height(), recoveringMemory);
853 } else {
854 mSurfaceResized = false;
855 }
Robert Carrc7294602016-05-13 11:32:05 -0700856 mForceScaleUntilResize = mForceScaleUntilResize && !mSurfaceResized;
Robert Carr6da3cc02016-06-16 15:17:07 -0700857 // If we are undergoing seamless rotation, the surface has already
858 // been set up to persist at it's old location. We need to freeze
859 // updates until a resize occurs.
Robert Carrc7294602016-05-13 11:32:05 -0700860
chaviw23012112017-12-20 15:29:04 -0800861 Rect clipRect = null;
Robert Carrfbbde852016-10-18 11:02:28 -0700862 if (calculateCrop(mTmpClipRect)) {
863 clipRect = mTmpClipRect;
864 }
Robert Carra9408d42016-06-03 13:28:48 -0700865
866 float surfaceWidth = mSurfaceController.getWidth();
867 float surfaceHeight = mSurfaceController.getHeight();
868
Robert Carr74a66a22018-02-23 12:17:51 -0800869 final Rect insets = attrs.surfaceInsets;
870
Robert Carr8f0a3ad2017-02-15 19:30:28 -0800871 if (isForceScaled()) {
Robert Carr74a66a22018-02-23 12:17:51 -0800872 int hInsets = insets.left + insets.right;
873 int vInsets = insets.top + insets.bottom;
Winson Chung08f81892017-03-02 15:40:51 -0800874 float surfaceContentWidth = surfaceWidth - hInsets;
875 float surfaceContentHeight = surfaceHeight - vInsets;
Robert Carra9408d42016-06-03 13:28:48 -0700876 if (!mForceScaleUntilResize) {
877 mSurfaceController.forceScaleableInTransaction(true);
878 }
Robert Carrfd4c9892017-02-01 10:28:28 -0800879
Robert Carr74a66a22018-02-23 12:17:51 -0800880 int posX = 0;
881 int posY = 0;
Robert Carrfd4c9892017-02-01 10:28:28 -0800882 task.mStack.getDimBounds(mTmpStackBounds);
Robert Carr18f622f2017-05-08 11:20:43 -0700883
884 boolean allowStretching = false;
Winson Chung8bca9e42017-04-16 15:59:43 -0700885 task.mStack.getFinalAnimationSourceHintBounds(mTmpSourceBounds);
Robert Carr18f622f2017-05-08 11:20:43 -0700886 // If we don't have source bounds, we can attempt to use the content insets
887 // in the following scenario:
888 // 1. We have content insets.
889 // 2. We are not transitioning to full screen
890 // We have to be careful to check "lastAnimatingBoundsWasToFullscreen" rather than
891 // the mBoundsAnimating state, as we may have already left it and only be here
892 // because of the force-scale until resize state.
893 if (mTmpSourceBounds.isEmpty() && (mWin.mLastRelayoutContentInsets.width() > 0
894 || mWin.mLastRelayoutContentInsets.height() > 0)
895 && !task.mStack.lastAnimatingBoundsWasToFullscreen()) {
896 mTmpSourceBounds.set(task.mStack.mPreAnimationBounds);
897 mTmpSourceBounds.inset(mWin.mLastRelayoutContentInsets);
898 allowStretching = true;
899 }
Adrian Roos604ef952018-05-15 20:13:13 +0200900
901 // Make sure that what we're animating to and from is actually the right size in case
902 // the window cannot take up the full screen.
chaviw553b0212018-07-12 13:37:01 -0700903 mTmpStackBounds.intersectUnchecked(w.getParentFrame());
904 mTmpSourceBounds.intersectUnchecked(w.getParentFrame());
905 mTmpAnimatingBounds.intersectUnchecked(w.getParentFrame());
Adrian Roos604ef952018-05-15 20:13:13 +0200906
Winson Chung08f81892017-03-02 15:40:51 -0800907 if (!mTmpSourceBounds.isEmpty()) {
908 // Get the final target stack bounds, if we are not animating, this is just the
909 // current stack bounds
Winson Chung40a5f932017-04-13 16:39:36 -0700910 task.mStack.getFinalAnimationBounds(mTmpAnimatingBounds);
Winson Chung08f81892017-03-02 15:40:51 -0800911
912 // Calculate the current progress and interpolate the difference between the target
913 // and source bounds
914 float finalWidth = mTmpAnimatingBounds.width();
915 float initialWidth = mTmpSourceBounds.width();
Robert Carr18f622f2017-05-08 11:20:43 -0700916 float tw = (surfaceContentWidth - mTmpStackBounds.width())
Winson Chung08f81892017-03-02 15:40:51 -0800917 / (surfaceContentWidth - mTmpAnimatingBounds.width());
Robert Carr18f622f2017-05-08 11:20:43 -0700918 float th = tw;
919 mExtraHScale = (initialWidth + tw * (finalWidth - initialWidth)) / initialWidth;
920 if (allowStretching) {
921 float finalHeight = mTmpAnimatingBounds.height();
922 float initialHeight = mTmpSourceBounds.height();
923 th = (surfaceContentHeight - mTmpStackBounds.height())
924 / (surfaceContentHeight - mTmpAnimatingBounds.height());
925 mExtraVScale = (initialHeight + tw * (finalHeight - initialHeight))
926 / initialHeight;
927 } else {
928 mExtraVScale = mExtraHScale;
929 }
Winson Chung08f81892017-03-02 15:40:51 -0800930
931 // Adjust the position to account for the inset bounds
Robert Carr18f622f2017-05-08 11:20:43 -0700932 posX -= (int) (tw * mExtraHScale * mTmpSourceBounds.left);
933 posY -= (int) (th * mExtraVScale * mTmpSourceBounds.top);
Winson Chung08f81892017-03-02 15:40:51 -0800934
Robert Carr74a66a22018-02-23 12:17:51 -0800935 // In pinned mode the clip rectangle applied to us by our stack has been
936 // expanded outwards to allow for shadows. However in case of source bounds set
937 // we need to crop to within the surface. The code above has scaled and positioned
938 // the surface to fit the unexpanded stack bounds, but now we need to reapply
939 // the cropping that the stack would have applied if it weren't expanded. This
940 // can be different in each direction based on the source bounds.
941 clipRect = mTmpClipRect;
942 clipRect.set((int)((insets.left + mTmpSourceBounds.left) * tw),
943 (int)((insets.top + mTmpSourceBounds.top) * th),
944 insets.left + (int)(surfaceWidth
945 - (tw* (surfaceWidth - mTmpSourceBounds.right))),
946 insets.top + (int)(surfaceHeight
947 - (th * (surfaceHeight - mTmpSourceBounds.bottom))));
Winson Chung08f81892017-03-02 15:40:51 -0800948 } else {
949 // We want to calculate the scaling based on the content area, not based on
950 // the entire surface, so that we scale in sync with windows that don't have insets.
951 mExtraHScale = mTmpStackBounds.width() / surfaceContentWidth;
952 mExtraVScale = mTmpStackBounds.height() / surfaceContentHeight;
953
954 // Since we are scaled to fit in our previously desired crop, we can now
955 // expose the whole window in buffer space, and not risk extending
956 // past where the system would have cropped us
957 clipRect = null;
Winson Chung08f81892017-03-02 15:40:51 -0800958 }
Robert Carr0d00c2e2016-02-29 17:45:02 -0800959
Robert Carrfd4c9892017-02-01 10:28:28 -0800960 // In the case of ForceScaleToStack we scale entire tasks together,
Robert Carr0d00c2e2016-02-29 17:45:02 -0800961 // and so we need to scale our offsets relative to the task bounds
962 // or parent and child windows would fall out of alignment.
Winson Chung08f81892017-03-02 15:40:51 -0800963 posX -= (int) (attrs.x * (1 - mExtraHScale));
964 posY -= (int) (attrs.y * (1 - mExtraVScale));
965
Robert Carrbc133762016-05-12 14:04:38 -0700966 // Imagine we are scaling down. As we scale the buffer down, we decrease the
967 // distance between the surface top left, and the start of the surface contents
968 // (previously it was surfaceInsets.left pixels in screen space but now it
Robert Carr04092112016-06-02 12:56:12 -0700969 // will be surfaceInsets.left*mExtraHScale). This means in order to keep the
Robert Carrbc133762016-05-12 14:04:38 -0700970 // non inset content at the same position, we have to shift the whole window
971 // forward. Likewise for scaling up, we've increased this distance, and we need
972 // to shift by a negative number to compensate.
Robert Carr74a66a22018-02-23 12:17:51 -0800973 posX += insets.left * (1 - mExtraHScale);
974 posY += insets.top * (1 - mExtraVScale);
Robert Carrbc133762016-05-12 14:04:38 -0700975
Winson Chung08f81892017-03-02 15:40:51 -0800976 mSurfaceController.setPositionInTransaction((float) Math.floor(posX),
977 (float) Math.floor(posY), recoveringMemory);
Robert Carrc7294602016-05-13 11:32:05 -0700978
979 // Various surfaces in the scaled stack may resize at different times.
980 // We need to ensure for each surface, that we disable transformation matrix
981 // scaling in the same transaction which we resize the surface in.
982 // As we are in SCALING_MODE_SCALE_TO_WINDOW, SurfaceFlinger will
Robert Carra9408d42016-06-03 13:28:48 -0700983 // then take over the scaling until the new buffer arrives, and things
Robert Carrc7294602016-05-13 11:32:05 -0700984 // will be seamless.
Robert Carr2025bf842018-03-19 13:25:05 -0700985 if (mPipAnimationStarted == false) {
986 mForceScaleUntilResize = true;
987 mPipAnimationStarted = true;
988 }
Rob Carr06be6bb2018-02-06 16:26:06 +0000989 } else {
Robert Carr2025bf842018-03-19 13:25:05 -0700990 mPipAnimationStarted = false;
991
Rob Carr06be6bb2018-02-06 16:26:06 +0000992 if (!w.mSeamlesslyRotated) {
chaviwbe43ac82018-04-04 15:14:49 -0700993 // Used to offset the WSA when stack position changes before a resize.
994 int xOffset = mXOffset;
995 int yOffset = mYOffset;
996 if (mOffsetPositionForStackResize) {
997 if (relayout) {
998 // Once a relayout is called, reset the offset back to 0 and defer
999 // setting it until a new frame with the updated size. This ensures that
1000 // the WS position is reset (so the stack position is shown) at the same
1001 // time that the buffer size changes.
1002 setOffsetPositionForStackResize(false);
1003 mSurfaceController.deferTransactionUntil(mSurfaceController.getHandle(),
1004 mWin.getFrameNumber());
1005 } else {
1006 final TaskStack stack = mWin.getStack();
1007 mTmpPos.x = 0;
1008 mTmpPos.y = 0;
1009 if (stack != null) {
Evan Roskyed6767f2018-10-26 17:21:06 -07001010 stack.getRelativeDisplayedPosition(mTmpPos);
chaviwbe43ac82018-04-04 15:14:49 -07001011 }
1012
1013 xOffset = -mTmpPos.x;
1014 yOffset = -mTmpPos.y;
1015
1016 // Crop also needs to be extended so the bottom isn't cut off when the WSA
1017 // position is moved.
1018 if (clipRect != null) {
1019 clipRect.right += mTmpPos.x;
1020 clipRect.bottom += mTmpPos.y;
1021 }
1022 }
1023 }
1024 mSurfaceController.setPositionInTransaction(xOffset, yOffset, recoveringMemory);
Rob Carr06be6bb2018-02-06 16:26:06 +00001025 }
Robert Carr0d00c2e2016-02-29 17:45:02 -08001026 }
1027
Robert Carra9408d42016-06-03 13:28:48 -07001028 // If we are ending the scaling mode. We switch to SCALING_MODE_FREEZE
Robert Carr6da3cc02016-06-16 15:17:07 -07001029 // to prevent further updates until buffer latch.
Vishnu Nairddd80742018-08-21 14:12:46 -07001030 // We also need to freeze the Surface geometry until a buffer
1031 // comes in at the new size (normally position and crop are unfrozen).
1032 // setGeometryAppliesWithResizeInTransaction accomplishes this for us.
1033 if (wasForceScaled && !mForceScaleUntilResize) {
Vishnu Nairb040c012018-09-07 11:38:32 -07001034 mSurfaceController.deferTransactionUntil(mSurfaceController.getHandle(),
1035 mWin.getFrameNumber());
Robert Carra9408d42016-06-03 13:28:48 -07001036 mSurfaceController.forceScaleableInTransaction(false);
1037 }
Robert Carr4320d332016-06-10 15:13:32 -07001038
Vishnu Nairddd80742018-08-21 14:12:46 -07001039
Robert Carr6da3cc02016-06-16 15:17:07 -07001040 if (!w.mSeamlesslyRotated) {
chaviw23012112017-12-20 15:29:04 -08001041 applyCrop(clipRect, recoveringMemory);
Robert Carr6da3cc02016-06-16 15:17:07 -07001042 mSurfaceController.setMatrixInTransaction(mDsDx * w.mHScale * mExtraHScale,
1043 mDtDx * w.mVScale * mExtraVScale,
Robert Carr0edf18f2017-02-21 20:01:47 -08001044 mDtDy * w.mHScale * mExtraHScale,
1045 mDsDy * w.mVScale * mExtraVScale, recoveringMemory);
Robert Carr6da3cc02016-06-16 15:17:07 -07001046 }
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001047
Robert Carre6a83512015-11-03 16:09:21 -08001048 if (mSurfaceResized) {
Chong Zhang5b2f1992015-11-13 15:40:36 -08001049 mReportSurfaceResized = true;
Robert Carre6a83512015-11-03 16:09:21 -08001050 mAnimator.setPendingLayoutChanges(w.getDisplayId(),
Jorim Jaggia5e10572017-11-15 14:36:26 +01001051 FINISH_LAYOUT_REDO_WALLPAPER);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001052 }
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001053 }
1054
Andrii Kulian283acd22017-08-03 04:03:51 -07001055 /**
1056 * Get rect of the task this window is currently in. If there is no task, rect will be set to
1057 * empty.
1058 */
1059 void getContainerRect(Rect rect) {
1060 final Task task = mWin.getTask();
1061 if (task != null) {
1062 task.getDimBounds(rect);
1063 } else {
1064 rect.left = rect.top = rect.right = rect.bottom = 0;
1065 }
1066 }
1067
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001068 void prepareSurfaceLocked(final boolean recoveringMemory) {
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001069 final WindowState w = mWin;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001070 if (!hasSurface()) {
Jorim Jaggi38d44ec2017-06-14 16:04:59 -07001071
1072 // There is no need to wait for an animation change if our window is gone for layout
1073 // already as we'll never be visible.
Bryce Lee8c3cf382017-07-06 19:47:10 -07001074 if (w.getOrientationChanging() && w.isGoneForLayoutLw()) {
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001075 if (DEBUG_ORIENTATION) {
1076 Slog.v(TAG, "Orientation change skips hidden " + w);
1077 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001078 w.setOrientationChanging(false);
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001079 }
1080 return;
1081 }
1082
1083 boolean displayed = false;
1084
1085 computeShownFrameLocked();
1086
Craig Mautnera91f9e22012-09-14 16:22:08 -07001087 setSurfaceBoundariesLocked(recoveringMemory);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001088
Tiger Huang50d45462018-05-25 22:57:52 +08001089 if (mIsWallpaper && !w.mWallpaperVisible) {
Craig Mautner0fa77c12012-06-11 15:57:19 -07001090 // Wallpaper is no longer visible and there is no wp target => hide it.
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001091 hide("prepareSurfaceLocked");
Wale Ogunwale9d147902016-07-16 11:58:55 -07001092 } else if (w.isParentWindowHidden() || !w.isOnScreen()) {
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001093 hide("prepareSurfaceLocked");
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001094 mWallpaperControllerLocked.hideWallpapers(w);
Craig Mautnerb9836b92012-06-11 11:40:09 -07001095
Jorim Jaggi38d44ec2017-06-14 16:04:59 -07001096 // If we are waiting for this window to handle an orientation change. If this window is
1097 // really hidden (gone for layout), there is no point in still waiting for it.
1098 // Note that this does introduce a potential glitch if the window becomes unhidden
1099 // before it has drawn for the new orientation.
Bryce Lee8c3cf382017-07-06 19:47:10 -07001100 if (w.getOrientationChanging() && w.isGoneForLayoutLw()) {
1101 w.setOrientationChanging(false);
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001102 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001103 "Orientation change skips hidden " + w);
1104 }
Jorim Jaggi35d328a2018-08-14 17:00:20 +02001105 } else if (mLastAlpha != mShownAlpha
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001106 || mLastDsDx != mDsDx
1107 || mLastDtDx != mDtDx
1108 || mLastDsDy != mDsDy
1109 || mLastDtDy != mDtDy
1110 || w.mLastHScale != w.mHScale
1111 || w.mLastVScale != w.mVScale
Craig Mautner749a7bb2012-04-02 13:49:53 -07001112 || mLastHidden) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001113 displayed = true;
1114 mLastAlpha = mShownAlpha;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001115 mLastDsDx = mDsDx;
1116 mLastDtDx = mDtDx;
1117 mLastDsDy = mDsDy;
1118 mLastDtDy = mDtDy;
1119 w.mLastHScale = w.mHScale;
1120 w.mLastVScale = w.mVScale;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001121 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
Robert Carre6a83512015-11-03 16:09:21 -08001122 "controller=" + mSurfaceController +
Jorim Jaggi35d328a2018-08-14 17:00:20 +02001123 "alpha=" + mShownAlpha
Craig Mautner78505d82014-09-02 14:36:31 -07001124 + " matrix=[" + mDsDx + "*" + w.mHScale
1125 + "," + mDtDx + "*" + w.mVScale
Robert Carr0edf18f2017-02-21 20:01:47 -08001126 + "][" + mDtDy + "*" + w.mHScale
1127 + "," + mDsDy + "*" + w.mVScale + "]", false);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001128
Robert Carre6a83512015-11-03 16:09:21 -08001129 boolean prepared =
Robert Carraf422a82017-04-10 18:34:33 -07001130 mSurfaceController.prepareToShowInTransaction(mShownAlpha,
Robert Carr04092112016-06-02 12:56:12 -07001131 mDsDx * w.mHScale * mExtraHScale,
1132 mDtDx * w.mVScale * mExtraVScale,
Robert Carr0edf18f2017-02-21 20:01:47 -08001133 mDtDy * w.mHScale * mExtraHScale,
1134 mDsDy * w.mVScale * mExtraVScale,
Robert Carre6a83512015-11-03 16:09:21 -08001135 recoveringMemory);
1136
Robert Carr03206af2017-07-10 18:24:21 -07001137 if (prepared && mDrawState == HAS_DRAWN) {
1138 if (mLastHidden) {
1139 if (showSurfaceRobustlyLocked()) {
1140 markPreservedSurfaceForDestroy();
1141 mAnimator.requestRemovalOfReplacedWindows(w);
1142 mLastHidden = false;
1143 if (mIsWallpaper) {
1144 w.dispatchWallpaperVisibility(true);
1145 }
Jorim Jaggif1292892018-09-10 11:58:13 +02001146 if (!w.getDisplayContent().getLastHasContent()) {
1147 // This draw means the difference between unique content and mirroring.
1148 // Run another pass through performLayout to set mHasContent in the
1149 // LogicalDisplay.
1150 mAnimator.setPendingLayoutChanges(w.getDisplayId(),
1151 FINISH_LAYOUT_REDO_ANIM);
1152 if (DEBUG_LAYOUT_REPEATS) {
1153 mService.mWindowPlacerLocked.debugLayoutRepeats(
1154 "showSurfaceRobustlyLocked " + w,
1155 mAnimator.getPendingLayoutChanges(w.getDisplayId()));
1156 }
Tiger Huang50d45462018-05-25 22:57:52 +08001157 }
Robert Carr03206af2017-07-10 18:24:21 -07001158 } else {
1159 w.setOrientationChanging(false);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001160 }
Robert Carr03206af2017-07-10 18:24:21 -07001161 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001162 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001163 if (hasSurface()) {
Robert Carre6a83512015-11-03 16:09:21 -08001164 w.mToken.hasVisible = true;
1165 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001166 } else {
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001167 if (DEBUG_ANIM && mWin.isAnimating()) {
Chong Zhange05db742016-02-16 16:58:37 -08001168 Slog.v(TAG, "prepareSurface: No changes in animation for " + this);
Craig Mautner83339b42012-05-01 22:13:23 -07001169 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001170 displayed = true;
1171 }
1172
Bryce Lee8c3cf382017-07-06 19:47:10 -07001173 if (w.getOrientationChanging()) {
Jorim Jaggi38d44ec2017-06-14 16:04:59 -07001174 if (!w.isDrawnLw()) {
1175 mAnimator.mBulkUpdateParams &= ~SET_ORIENTATION_CHANGE_COMPLETE;
1176 mAnimator.mLastWindowFreezeSource = w;
1177 if (DEBUG_ORIENTATION) Slog.v(TAG,
1178 "Orientation continue waiting for draw in " + w);
1179 } else {
Bryce Lee8c3cf382017-07-06 19:47:10 -07001180 w.setOrientationChanging(false);
Jorim Jaggi38d44ec2017-06-14 16:04:59 -07001181 if (DEBUG_ORIENTATION) Slog.v(TAG, "Orientation change complete in " + w);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001182 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -07001183 }
1184
1185 if (displayed) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001186 w.mToken.hasVisible = true;
1187 }
1188 }
1189
Craig Mautneref655012013-01-03 11:20:24 -08001190 void setTransparentRegionHintLocked(final Region region) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001191 if (mSurfaceController == null) {
1192 Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true");
1193 return;
1194 }
Robert Carre6a83512015-11-03 16:09:21 -08001195 mSurfaceController.setTransparentRegionHint(region);
Craig Mautner48ba1e72012-04-02 13:18:16 -07001196 }
1197
Robert Carr217e7cc2018-01-31 18:08:39 -08001198 boolean setWallpaperOffset(int dx, int dy) {
1199 if (mXOffset == dx && mYOffset == dy) {
1200 return false;
1201 }
1202 mXOffset = dx;
1203 mYOffset = dy;
Robert Carre6a83512015-11-03 16:09:21 -08001204
1205 try {
Craig Mautner71dd1b62014-02-18 15:48:52 -08001206 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setWallpaperOffset");
Robert Carr68e5c9e2016-09-14 10:50:09 -07001207 mService.openSurfaceTransaction();
Robert Carr217e7cc2018-01-31 18:08:39 -08001208 mSurfaceController.setPositionInTransaction(dx, dy, false);
chaviw23012112017-12-20 15:29:04 -08001209 applyCrop(null, false);
Robert Carre6a83512015-11-03 16:09:21 -08001210 } catch (RuntimeException e) {
1211 Slog.w(TAG, "Error positioning surface of " + mWin
Robert Carr217e7cc2018-01-31 18:08:39 -08001212 + " pos=(" + dx + "," + dy + ")", e);
Robert Carre6a83512015-11-03 16:09:21 -08001213 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +02001214 mService.closeSurfaceTransaction("setWallpaperOffset");
Robert Carre6a83512015-11-03 16:09:21 -08001215 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1216 "<<< CLOSE TRANSACTION setWallpaperOffset");
Robert Carr217e7cc2018-01-31 18:08:39 -08001217 return true;
Craig Mautner48ba1e72012-04-02 13:18:16 -07001218 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001219 }
1220
John Reck80181b92015-05-19 11:09:32 -07001221 /**
1222 * Try to change the pixel format without recreating the surface. This
1223 * will be common in the case of changing from PixelFormat.OPAQUE to
1224 * PixelFormat.TRANSLUCENT in the hardware-accelerated case as both
1225 * requested formats resolve to the same underlying SurfaceControl format
1226 * @return True if format was succesfully changed, false otherwise
1227 */
1228 boolean tryChangeFormatInPlaceLocked() {
Robert Carre6a83512015-11-03 16:09:21 -08001229 if (mSurfaceController == null) {
John Reck80181b92015-05-19 11:09:32 -07001230 return false;
1231 }
1232 final LayoutParams attrs = mWin.getAttrs();
Wale Ogunwalee7bf46b2015-09-30 09:19:28 -07001233 final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0;
John Reck80181b92015-05-19 11:09:32 -07001234 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
1235 if (format == mSurfaceFormat) {
1236 setOpaqueLocked(!PixelFormat.formatHasAlpha(attrs.format));
1237 return true;
1238 }
1239 return false;
1240 }
1241
Craig Mautner6f612042014-09-07 13:13:23 -07001242 void setOpaqueLocked(boolean isOpaque) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001243 if (mSurfaceController == null) {
1244 return;
1245 }
Robert Carre6a83512015-11-03 16:09:21 -08001246 mSurfaceController.setOpaque(isOpaque);
Craig Mautner71dd1b62014-02-18 15:48:52 -08001247 }
1248
Wale Ogunwalef5ad42f2015-06-12 13:59:03 -07001249 void setSecureLocked(boolean isSecure) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001250 if (mSurfaceController == null) {
1251 return;
1252 }
Robert Carre6a83512015-11-03 16:09:21 -08001253 mSurfaceController.setSecure(isSecure);
Wale Ogunwalef5ad42f2015-06-12 13:59:03 -07001254 }
1255
Peiyong Lin75045382019-03-04 19:22:33 -08001256 void setColorSpaceAgnosticLocked(boolean agnostic) {
1257 if (mSurfaceController == null) {
1258 return;
1259 }
1260 mSurfaceController.setColorSpaceAgnostic(agnostic);
1261 }
1262
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001263 /**
1264 * Have the surface flinger show a surface, robustly dealing with
1265 * error conditions. In particular, if there is not enough memory
1266 * to show the surface, then we will try to get rid of other surfaces
1267 * in order to succeed.
1268 *
1269 * @return Returns true if the surface was successfully shown.
1270 */
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001271 private boolean showSurfaceRobustlyLocked() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001272 if (mWin.getWindowConfiguration().windowsAreScaleable()) {
Robert Carr1b5ea722016-04-20 13:23:28 -07001273 mSurfaceController.forceScaleableInTransaction(true);
1274 }
1275
Robert Carre6a83512015-11-03 16:09:21 -08001276 boolean shown = mSurfaceController.showRobustlyInTransaction();
1277 if (!shown)
1278 return false;
1279
Robert Carr849d2932018-05-01 12:14:48 -07001280 // If we had a preserved surface it's no longer needed, and it may be harmful
1281 // if we are transparent.
1282 if (mPendingDestroySurface != null && mDestroyPreservedSurfaceUponRedraw) {
1283 mPendingDestroySurface.mSurfaceControl.hide();
Robert Carrba993782018-05-15 15:16:40 -07001284 mPendingDestroySurface.reparentChildrenInTransaction(mSurfaceController);
Robert Carr849d2932018-05-01 12:14:48 -07001285 }
1286
Robert Carre6a83512015-11-03 16:09:21 -08001287 return true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001288 }
1289
1290 void applyEnterAnimationLocked() {
Robert Carrb439a632016-04-07 22:52:10 -07001291 // If we are the new part of a window replacement transition and we have requested
1292 // not to animate, we instead want to make it seamless, so we don't want to apply
1293 // an enter transition.
1294 if (mWin.mSkipEnterAnimationForSeamlessReplacement) {
1295 return;
1296 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001297 final int transit;
1298 if (mEnterAnimationPending) {
1299 mEnterAnimationPending = false;
1300 transit = WindowManagerPolicy.TRANSIT_ENTER;
1301 } else {
1302 transit = WindowManagerPolicy.TRANSIT_SHOW;
1303 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001304 applyAnimationLocked(transit, true);
Rhed Jao02655dc2018-10-30 20:44:52 +08001305 if (mService.mAccessibilityController != null) {
Svetoslav8e3feb12014-02-24 13:46:47 -08001306 mService.mAccessibilityController.onWindowTransitionLocked(mWin, transit);
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -07001307 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001308 }
1309
1310 /**
1311 * Choose the correct animation and set it to the passed WindowState.
Craig Mautner4b71aa12012-12-27 17:20:01 -08001312 * @param transit If AppTransition.TRANSIT_PREVIEW_DONE and the app window has been drawn
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001313 * then the animation will be app_starting_exit. Any other value loads the animation from
1314 * the switch statement below.
1315 * @param isEntrance The animation type the last time this was called. Used to keep from
1316 * loading the same animation twice.
1317 * @return true if an animation has been loaded.
1318 */
1319 boolean applyAnimationLocked(int transit, boolean isEntrance) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01001320 if (mWin.isSelfAnimating() && mAnimationIsEntrance == isEntrance) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001321 // If we are trying to apply an animation, but already running
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001322 // an animation of the same type, then just leave that one alone.
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001323 return true;
1324 }
1325
Jorim Jaggia5e10572017-11-15 14:36:26 +01001326 if (isEntrance && mWin.mAttrs.type == TYPE_INPUT_METHOD) {
1327 mWin.getDisplayContent().adjustForImeIfNeeded();
1328 mWin.setDisplayLayoutNeeded();
1329 mService.mWindowPlacerLocked.requestTraversal();
1330 }
1331
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001332 // Only apply an animation if the display isn't frozen. If it is
1333 // frozen, there is no reason to animate and it can cause strange
1334 // artifacts when we unfreeze the display if some different animation
1335 // is running.
Chong Zhang8784be62016-06-28 15:25:07 -07001336 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "WSA#applyAnimationLocked");
David Stevens9440dc82017-03-16 19:00:20 -07001337 if (mWin.mToken.okToAnimate()) {
Tiger Huang7c610aa2018-10-27 00:01:01 +08001338 int anim = mWin.getDisplayContent().getDisplayPolicy().selectAnimationLw(mWin, transit);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001339 int attr = -1;
1340 Animation a = null;
1341 if (anim != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001342 a = anim != -1 ? AnimationUtils.loadAnimation(mContext, anim) : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001343 } else {
1344 switch (transit) {
1345 case WindowManagerPolicy.TRANSIT_ENTER:
1346 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
1347 break;
1348 case WindowManagerPolicy.TRANSIT_EXIT:
1349 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
1350 break;
1351 case WindowManagerPolicy.TRANSIT_SHOW:
1352 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
1353 break;
1354 case WindowManagerPolicy.TRANSIT_HIDE:
1355 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
1356 break;
1357 }
1358 if (attr >= 0) {
lumark588a3e82018-07-20 18:53:54 +08001359 a = mWin.getDisplayContent().mAppTransition.loadAnimationAttr(
1360 mWin.mAttrs, attr, TRANSIT_NONE);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001361 }
1362 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001363 if (DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001364 "applyAnimation: win=" + this
1365 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
Craig Mautner4d7349b2012-04-20 14:52:47 -07001366 + " a=" + a
Craig Mautner8863cca2012-09-18 15:04:34 -07001367 + " transit=" + transit
Craig Mautner83339b42012-05-01 22:13:23 -07001368 + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001369 if (a != null) {
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -08001370 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
Jorim Jaggia5e10572017-11-15 14:36:26 +01001371 mWin.startAnimation(a);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001372 mAnimationIsEntrance = isEntrance;
1373 }
1374 } else {
Jorim Jaggia5e10572017-11-15 14:36:26 +01001375 mWin.cancelAnimation();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001376 }
Chong Zhang8784be62016-06-28 15:25:07 -07001377
Jorim Jaggia5e10572017-11-15 14:36:26 +01001378 if (!isEntrance && mWin.mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001379 mWin.getDisplayContent().adjustForImeIfNeeded();
Jorim Jaggieb88d832016-04-13 20:17:43 -07001380 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001381
Jorim Jaggia5e10572017-11-15 14:36:26 +01001382 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001383 return mWin.isAnimating();
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001384 }
1385
Steven Timotiusaf03df62017-07-18 16:56:43 -07001386 void writeToProto(ProtoOutputStream proto, long fieldId) {
1387 final long token = proto.start(fieldId);
1388 mLastClipRect.writeToProto(proto, LAST_CLIP_RECT);
1389 if (mSurfaceController != null) {
1390 mSurfaceController.writeToProto(proto, SURFACE);
1391 }
Vishnu Nair1d0fa072018-01-04 07:53:00 -08001392 proto.write(DRAW_STATE, mDrawState);
1393 mSystemDecorRect.writeToProto(proto, SYSTEM_DECOR_RECT);
Steven Timotiusaf03df62017-07-18 16:56:43 -07001394 proto.end(token);
1395 }
1396
Craig Mautnera2c77052012-03-26 12:14:43 -07001397 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01001398 if (mAnimationIsEntrance) {
1399 pw.print(prefix); pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
Craig Mautnera2c77052012-03-26 12:14:43 -07001400 }
Robert Carre6a83512015-11-03 16:09:21 -08001401 if (mSurfaceController != null) {
1402 mSurfaceController.dump(pw, prefix, dumpAll);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001403 }
Robert Carre6a83512015-11-03 16:09:21 -08001404 if (dumpAll) {
1405 pw.print(prefix); pw.print("mDrawState="); pw.print(drawStateToString());
1406 pw.print(prefix); pw.print(" mLastHidden="); pw.println(mLastHidden);
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001407 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001408 pw.print(" mLastClipRect="); mLastClipRect.printShortString(pw);
1409
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001410 if (!mLastFinalClipRect.isEmpty()) {
1411 pw.print(" mLastFinalClipRect="); mLastFinalClipRect.printShortString(pw);
1412 }
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001413 pw.println();
Robert Carre6a83512015-11-03 16:09:21 -08001414 }
1415
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001416 if (mPendingDestroySurface != null) {
1417 pw.print(prefix); pw.print("mPendingDestroySurface=");
1418 pw.println(mPendingDestroySurface);
1419 }
1420 if (mSurfaceResized || mSurfaceDestroyDeferred) {
1421 pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized);
1422 pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred);
1423 }
1424 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
1425 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
1426 pw.print(" mAlpha="); pw.print(mAlpha);
1427 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
1428 }
1429 if (mHaveMatrix || mWin.mGlobalScale != 1) {
1430 pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale);
1431 pw.print(" mDsDx="); pw.print(mDsDx);
1432 pw.print(" mDtDx="); pw.print(mDtDx);
Robert Carr0edf18f2017-02-21 20:01:47 -08001433 pw.print(" mDtDy="); pw.print(mDtDy);
1434 pw.print(" mDsDy="); pw.println(mDsDy);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001435 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001436 }
1437
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001438 @Override
1439 public String toString() {
Dianne Hackborn529e7442012-11-01 14:22:28 -07001440 StringBuffer sb = new StringBuffer("WindowStateAnimator{");
1441 sb.append(Integer.toHexString(System.identityHashCode(this)));
1442 sb.append(' ');
1443 sb.append(mWin.mAttrs.getTitle());
1444 sb.append('}');
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001445 return sb.toString();
1446 }
Robert Carre6a83512015-11-03 16:09:21 -08001447
1448 void reclaimSomeSurfaceMemory(String operation, boolean secure) {
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001449 mService.mRoot.reclaimSomeSurfaceMemory(this, operation, secure);
Robert Carre6a83512015-11-03 16:09:21 -08001450 }
1451
1452 boolean getShown() {
1453 if (mSurfaceController != null) {
1454 return mSurfaceController.getShown();
1455 }
1456 return false;
1457 }
1458
1459 void destroySurface() {
Wale Ogunwale722ff892016-02-18 13:37:55 -08001460 try {
1461 if (mSurfaceController != null) {
Robert Carra8828862018-02-05 16:17:36 -08001462 mSurfaceController.destroyNotInTransaction();
Wale Ogunwale722ff892016-02-18 13:37:55 -08001463 }
1464 } catch (RuntimeException e) {
1465 Slog.w(TAG, "Exception thrown when destroying surface " + this
1466 + " surface " + mSurfaceController + " session " + mSession + ": " + e);
1467 } finally {
1468 mWin.setHasSurface(false);
1469 mSurfaceController = null;
1470 mDrawState = NO_SURFACE;
1471 }
Robert Carre6a83512015-11-03 16:09:21 -08001472 }
Filip Gruszczynskif52dd202015-11-15 20:36:38 -08001473
Robert Carr8f0a3ad2017-02-15 19:30:28 -08001474 /** The force-scaled state for a given window can persist past
1475 * the state for it's stack as the windows complete resizing
1476 * independently of one another.
1477 */
1478 boolean isForceScaled() {
1479 final Task task = mWin.getTask();
1480 if (task != null && task.mStack.isForceScaled()) {
1481 return true;
1482 }
1483 return mForceScaleUntilResize;
1484 }
Robert Carrd5c7dd62017-03-08 10:39:30 -08001485
1486 void detachChildren() {
1487 if (mSurfaceController != null) {
1488 mSurfaceController.detachChildren();
1489 }
Robert Carr7b3d11d2018-03-15 14:34:45 -07001490 mChildrenDetached = true;
Robert Carrd5c7dd62017-03-08 10:39:30 -08001491 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01001492
chaviwbe43ac82018-04-04 15:14:49 -07001493 void setOffsetPositionForStackResize(boolean offsetPositionForStackResize) {
1494 mOffsetPositionForStackResize = offsetPositionForStackResize;
1495 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001496}