Craig Mautner | c2c0a61 | 2014-02-20 20:25:41 -0800 | [diff] [blame] | 1 | /* |
| 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 Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Lucas Dupin | 13f4b8a | 2020-02-19 13:41:52 -0800 | [diff] [blame] | 19 | import static android.graphics.Matrix.MSCALE_X; |
| 20 | import static android.graphics.Matrix.MSCALE_Y; |
| 21 | import static android.graphics.Matrix.MSKEW_X; |
| 22 | import static android.graphics.Matrix.MSKEW_Y; |
| 23 | import static android.graphics.Matrix.MTRANS_X; |
| 24 | import static android.graphics.Matrix.MTRANS_Y; |
Wale Ogunwale | e7bf46b | 2015-09-30 09:19:28 -0700 | [diff] [blame] | 25 | import static android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 26 | import static android.view.WindowManager.LayoutParams.FLAG_SCALED; |
Robert Carr | 132c9f5 | 2017-07-31 17:02:30 -0700 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
lumark | ce596d3 | 2019-06-12 16:58:35 +0800 | [diff] [blame] | 29 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 30 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 31 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Jorim Jaggi | 0a1523d | 2018-04-19 17:48:38 +0200 | [diff] [blame] | 32 | import static android.view.WindowManager.TRANSIT_NONE; |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 33 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 34 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; |
| 35 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 36 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_DRAW; |
| 37 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ORIENTATION; |
| 38 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_STARTING_WINDOW; |
| 39 | import static com.android.server.wm.ProtoLogGroup.WM_SHOW_SURFACE_ALLOC; |
| 40 | import static com.android.server.wm.ProtoLogGroup.WM_SHOW_TRANSACTIONS; |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 41 | import static com.android.server.wm.WindowContainer.AnimationFlags.PARENTS; |
| 42 | import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION; |
Adam Pardyl | 8c2d19c | 2019-09-16 17:15:38 +0200 | [diff] [blame] | 43 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 44 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 45 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS; |
Jorim Jaggi | e4b0f28 | 2017-05-17 15:10:29 +0200 | [diff] [blame] | 46 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 47 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 48 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_CROP; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 49 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 50 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 51 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 52 | import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER; |
Filip Gruszczynski | 198dcbf | 2016-01-18 10:02:00 -0800 | [diff] [blame] | 53 | import static com.android.server.wm.WindowManagerService.logWithStack; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 54 | import static com.android.server.wm.WindowStateAnimatorProto.DRAW_STATE; |
| 55 | import static com.android.server.wm.WindowStateAnimatorProto.LAST_CLIP_RECT; |
| 56 | import static com.android.server.wm.WindowStateAnimatorProto.SURFACE; |
| 57 | import static com.android.server.wm.WindowStateAnimatorProto.SYSTEM_DECOR_RECT; |
Jorim Jaggi | af0d6d2 | 2018-06-08 15:25:35 +0200 | [diff] [blame] | 58 | import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 59 | |
Evan Rosky | e067ddf | 2020-04-24 18:28:25 -0700 | [diff] [blame] | 60 | import android.app.WindowConfiguration; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 61 | import android.content.Context; |
| 62 | import android.graphics.Matrix; |
| 63 | import android.graphics.PixelFormat; |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 64 | import android.graphics.Point; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 65 | import android.graphics.Rect; |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 66 | import android.graphics.Region; |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 67 | import android.os.Debug; |
Chong Zhang | 8784be6 | 2016-06-28 15:25:07 -0700 | [diff] [blame] | 68 | import android.os.Trace; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 69 | import android.util.Slog; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 70 | import android.util.proto.ProtoOutputStream; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 71 | import android.view.DisplayInfo; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 72 | import android.view.Surface.OutOfResourcesException; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 73 | import android.view.SurfaceControl; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 74 | import android.view.WindowManager; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 75 | import android.view.WindowManager.LayoutParams; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 76 | import android.view.animation.Animation; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 77 | import android.view.animation.AnimationUtils; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 78 | |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 79 | import com.android.server.policy.WindowManagerPolicy; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 80 | import com.android.server.protolog.common.ProtoLog; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 81 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 82 | import java.io.PrintWriter; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 85 | * Keep track of animations and surface operations for a single WindowState. |
| 86 | **/ |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 87 | class WindowStateAnimator { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 88 | static final String TAG = TAG_WITH_CLASS_NAME ? "WindowStateAnimator" : TAG_WM; |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 89 | static final int WINDOW_FREEZE_LAYER = TYPE_LAYER_MULTIPLIER * 200; |
Tiger Huang | 9c8ee26 | 2019-02-19 20:44:27 +0800 | [diff] [blame] | 90 | static final int PRESERVED_SURFACE_LAYER = 1; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 91 | |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 92 | /** |
| 93 | * Mode how the window gets clipped by the stack bounds during an animation: The clipping should |
| 94 | * be applied after applying the animation transformation, i.e. the stack bounds don't move |
| 95 | * during the animation. |
| 96 | */ |
| 97 | static final int STACK_CLIP_AFTER_ANIM = 0; |
| 98 | |
| 99 | /** |
| 100 | * Mode how the window gets clipped by the stack bounds: The clipping should be applied before |
| 101 | * applying the animation transformation, i.e. the stack bounds move with the window. |
| 102 | */ |
| 103 | static final int STACK_CLIP_BEFORE_ANIM = 1; |
| 104 | |
| 105 | /** |
| 106 | * Mode how window gets clipped by the stack bounds during an animation: Don't clip the window |
| 107 | * by the stack bounds. |
| 108 | */ |
| 109 | static final int STACK_CLIP_NONE = 2; |
| 110 | |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 111 | // Unchanging local convenience fields. |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 112 | final WindowManagerService mService; |
| 113 | final WindowState mWin; |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 114 | final WindowAnimator mAnimator; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 115 | final Session mSession; |
| 116 | final WindowManagerPolicy mPolicy; |
| 117 | final Context mContext; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 118 | final boolean mIsWallpaper; |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 119 | private final WallpaperController mWallpaperControllerLocked; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 120 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 121 | boolean mAnimationIsEntrance; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 122 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 123 | /** |
| 124 | * Set when we have changed the size of the surface, to know that |
| 125 | * we must tell them application to resize (and thus redraw itself). |
| 126 | */ |
| 127 | boolean mSurfaceResized; |
Chong Zhang | 5b2f199 | 2015-11-13 15:40:36 -0800 | [diff] [blame] | 128 | /** |
| 129 | * Whether we should inform the client on next relayoutWindow that |
| 130 | * the surface has been resized since last time. |
| 131 | */ |
| 132 | boolean mReportSurfaceResized; |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 133 | WindowSurfaceController mSurfaceController; |
Filip Gruszczynski | 10a80e0 | 2015-11-06 09:21:17 -0800 | [diff] [blame] | 134 | private WindowSurfaceController mPendingDestroySurface; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 135 | |
| 136 | /** |
| 137 | * Set if the client has asked that the destroy of its surface be delayed |
| 138 | * until it explicitly says it is okay. |
| 139 | */ |
| 140 | boolean mSurfaceDestroyDeferred; |
| 141 | |
Filip Gruszczynski | 10a80e0 | 2015-11-06 09:21:17 -0800 | [diff] [blame] | 142 | private boolean mDestroyPreservedSurfaceUponRedraw; |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 143 | float mShownAlpha = 0; |
| 144 | float mAlpha = 0; |
| 145 | float mLastAlpha = 0; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 146 | |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 147 | Rect mTmpClipRect = new Rect(); |
| 148 | Rect mLastClipRect = new Rect(); |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 149 | Rect mLastFinalClipRect = new Rect(); |
Filip Gruszczynski | 4b8eea7 | 2015-09-14 18:16:19 -0700 | [diff] [blame] | 150 | Rect mTmpStackBounds = new Rect(); |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 151 | private Rect mTmpAnimatingBounds = new Rect(); |
| 152 | private Rect mTmpSourceBounds = new Rect(); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 153 | |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 154 | /** |
| 155 | * This is rectangle of the window's surface that is not covered by |
| 156 | * system decorations. |
| 157 | */ |
| 158 | private final Rect mSystemDecorRect = new Rect(); |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 159 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 160 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
Robert Carr | 0edf18f | 2017-02-21 20:01:47 -0800 | [diff] [blame] | 161 | private float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 162 | |
| 163 | boolean mHaveMatrix; |
| 164 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 165 | // Set to true if, when the window gets displayed, it should perform |
| 166 | // an enter animation. |
| 167 | boolean mEnterAnimationPending; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 168 | |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 169 | /** Used to indicate that this window is undergoing an enter animation. Used for system |
| 170 | * windows to make the callback to View.dispatchOnWindowShownCallback(). Set when the |
| 171 | * window is first added or shown, cleared when the callback has been made. */ |
| 172 | boolean mEnteringAnimation; |
| 173 | |
Vishnu Nair | 3319739 | 2019-08-30 10:29:37 -0700 | [diff] [blame] | 174 | private final SurfaceControl.Transaction mTmpTransaction; |
Chavi Weingarten | b736e32 | 2018-02-23 00:27:54 +0000 | [diff] [blame] | 175 | |
John Reck | 80181b9 | 2015-05-19 11:09:32 -0700 | [diff] [blame] | 176 | /** The pixel format of the underlying SurfaceControl */ |
| 177 | int mSurfaceFormat; |
| 178 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 179 | /** This is set when there is no Surface */ |
| 180 | static final int NO_SURFACE = 0; |
| 181 | /** This is set after the Surface has been created but before the window has been drawn. During |
| 182 | * this time the surface is hidden. */ |
| 183 | static final int DRAW_PENDING = 1; |
| 184 | /** This is set after the window has finished drawing for the first time but before its surface |
| 185 | * is shown. The surface will be displayed when the next layout is run. */ |
| 186 | static final int COMMIT_DRAW_PENDING = 2; |
| 187 | /** This is set during the time after the window's drawing has been committed, and before its |
| 188 | * surface is actually shown. It is used to delay showing the surface until all windows in a |
| 189 | * token are ready to be shown. */ |
| 190 | static final int READY_TO_SHOW = 3; |
| 191 | /** Set when the window has been shown in the screen the first time. */ |
| 192 | static final int HAS_DRAWN = 4; |
Adrian Roos | 3eeb4e6 | 2014-05-19 12:43:26 +0200 | [diff] [blame] | 193 | |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 194 | String drawStateToString() { |
| 195 | switch (mDrawState) { |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 196 | case NO_SURFACE: return "NO_SURFACE"; |
| 197 | case DRAW_PENDING: return "DRAW_PENDING"; |
| 198 | case COMMIT_DRAW_PENDING: return "COMMIT_DRAW_PENDING"; |
| 199 | case READY_TO_SHOW: return "READY_TO_SHOW"; |
| 200 | case HAS_DRAWN: return "HAS_DRAWN"; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 201 | default: return Integer.toString(mDrawState); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 202 | } |
| 203 | } |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 204 | int mDrawState; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 205 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 206 | /** Was this window last hidden? */ |
| 207 | boolean mLastHidden; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 208 | |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 209 | int mAttrType; |
| 210 | |
Robert Carr | c729460 | 2016-05-13 11:32:05 -0700 | [diff] [blame] | 211 | boolean mForceScaleUntilResize; |
| 212 | |
Robert Carr | 0409211 | 2016-06-02 12:56:12 -0700 | [diff] [blame] | 213 | // WindowState.mHScale and WindowState.mVScale contain the |
| 214 | // scale according to client specified layout parameters (e.g. |
| 215 | // one layout size, with another surface size, creates such scaling). |
| 216 | // Here we track an additional scaling factor used to follow stack |
| 217 | // scaling (as in the case of the Pinned stack animation). |
| 218 | float mExtraHScale = (float) 1.0; |
| 219 | float mExtraVScale = (float) 1.0; |
| 220 | |
Robert Carr | 217e7cc | 2018-01-31 18:08:39 -0800 | [diff] [blame] | 221 | // An offset in pixel of the surface contents from the window position. Used for Wallpaper |
| 222 | // to provide the effect of scrolling within a large surface. We just use these values as |
| 223 | // a cache. |
| 224 | int mXOffset = 0; |
| 225 | int mYOffset = 0; |
| 226 | |
Lucas Dupin | 13f4b8a | 2020-02-19 13:41:52 -0800 | [diff] [blame] | 227 | // A scale factor for the surface contents, that will be applied from the center of the visible |
| 228 | // region. |
| 229 | float mWallpaperScale = 1f; |
| 230 | |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 231 | /** |
| 232 | * A flag to determine if the WSA needs to offset its position to compensate for the stack's |
| 233 | * position update before the WSA surface has resized. |
| 234 | */ |
| 235 | private boolean mOffsetPositionForStackResize; |
| 236 | |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 237 | private final Rect mTmpSize = new Rect(); |
| 238 | |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 239 | /** |
| 240 | * Handles surface changes synchronized to after the client has drawn the surface. This |
| 241 | * transaction is currently used to reparent the old surface children to the new surface once |
| 242 | * the client has completed drawing to the new surface. |
| 243 | * This transaction is also used to merge transactions parceled in by the client. The client |
| 244 | * uses the transaction to update the relative z of its children from the old parent surface |
| 245 | * to the new parent surface once window manager reparents its children. |
| 246 | */ |
| 247 | private final SurfaceControl.Transaction mPostDrawTransaction = |
| 248 | new SurfaceControl.Transaction(); |
Robert Carr | ca4c5a6 | 2018-02-05 16:07:55 -0800 | [diff] [blame] | 249 | |
Robert Carr | 7b3d11d | 2018-03-15 14:34:45 -0700 | [diff] [blame] | 250 | // Used to track whether we have called detach children on the way to invisibility, in which |
| 251 | // case we need to give the client a new Surface if it lays back out to a visible state. |
| 252 | boolean mChildrenDetached = false; |
| 253 | |
Robert Carr | 2025bf84 | 2018-03-19 13:25:05 -0700 | [diff] [blame] | 254 | // Set to true after the first frame of the Pinned stack animation |
| 255 | // and reset after the last to ensure we only reset mForceScaleUntilResize |
| 256 | // once per animation. |
| 257 | boolean mPipAnimationStarted = false; |
| 258 | |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 259 | private final Point mTmpPos = new Point(); |
| 260 | |
Craig Mautner | c431e89 | 2015-02-11 13:14:26 -0800 | [diff] [blame] | 261 | WindowStateAnimator(final WindowState win) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 262 | final WindowManagerService service = win.mWmService; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 263 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 264 | mService = service; |
Vishnu Nair | 3319739 | 2019-08-30 10:29:37 -0700 | [diff] [blame] | 265 | mTmpTransaction = service.mTransactionFactory.get(); |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 266 | mAnimator = service.mAnimator; |
| 267 | mPolicy = service.mPolicy; |
| 268 | mContext = service.mContext; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 269 | |
| 270 | mWin = win; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 271 | mSession = win.mSession; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 272 | mAttrType = win.mAttrs.type; |
| 273 | mIsWallpaper = win.mIsWallpaper; |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 274 | mWallpaperControllerLocked = win.getDisplayContent().mWallpaperController; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 277 | void onAnimationFinished() { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 278 | // Done animating, clean up. |
| 279 | if (DEBUG_ANIM) Slog.v( |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 280 | TAG, "Animation done in " + this + ": exiting=" + mWin.mAnimatingExit |
| 281 | + ", reportedVisible=" |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 282 | + (mWin.mActivityRecord != null ? mWin.mActivityRecord.reportedVisible : false)); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 283 | |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 284 | mWin.checkPolicyVisibilityChange(); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 285 | final DisplayContent displayContent = mWin.getDisplayContent(); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 286 | if ((mAttrType == LayoutParams.TYPE_STATUS_BAR |
| 287 | || mAttrType == LayoutParams.TYPE_NOTIFICATION_SHADE) && mWin.isVisibleByPolicy()) { |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 288 | // Upon completion of a not-visible to visible status bar animation a relayout is |
| 289 | // required. |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 290 | displayContent.setLayoutNeeded(); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 291 | } |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 292 | mWin.onExitAnimationDone(); |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 293 | displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 294 | if (displayContent.mWallpaperController.isWallpaperTarget(mWin)) { |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 295 | displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 296 | } |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 297 | if (DEBUG_LAYOUT_REPEATS) { |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 298 | mService.mWindowPlacerLocked.debugLayoutRepeats( |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 299 | "WindowStateAnimator", displayContent.pendingLayoutChanges); |
| 300 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 301 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 302 | if (mWin.mActivityRecord != null) { |
| 303 | mWin.mActivityRecord.updateReportedVisibilityLocked(); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 304 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Chavi Weingarten | b736e32 | 2018-02-23 00:27:54 +0000 | [diff] [blame] | 307 | void hide(SurfaceControl.Transaction transaction, String reason) { |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 308 | if (!mLastHidden) { |
| 309 | //dump(); |
| 310 | mLastHidden = true; |
Jorim Jaggi | 5057590 | 2018-04-10 17:49:30 +0200 | [diff] [blame] | 311 | |
| 312 | // We may have a preserved surface which we no longer need. If there was a quick |
| 313 | // VISIBLE, GONE, VISIBLE, GONE sequence, the surface may never draw, so we don't mark |
| 314 | // it to be destroyed in prepareSurfaceLocked. |
| 315 | markPreservedSurfaceForDestroy(); |
| 316 | |
Wale Ogunwale | f9e0978 | 2015-11-09 12:42:37 -0800 | [diff] [blame] | 317 | if (mSurfaceController != null) { |
Chavi Weingarten | b736e32 | 2018-02-23 00:27:54 +0000 | [diff] [blame] | 318 | mSurfaceController.hide(transaction, reason); |
Wale Ogunwale | f9e0978 | 2015-11-09 12:42:37 -0800 | [diff] [blame] | 319 | } |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 320 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Chavi Weingarten | b736e32 | 2018-02-23 00:27:54 +0000 | [diff] [blame] | 323 | void hide(String reason) { |
| 324 | hide(mTmpTransaction, reason); |
| 325 | SurfaceControl.mergeToGlobalTransaction(mTmpTransaction); |
| 326 | } |
| 327 | |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 328 | boolean finishDrawingLocked(SurfaceControl.Transaction postDrawTransaction) { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 329 | final boolean startingWindow = |
| 330 | mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 331 | if (startingWindow) { |
| 332 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, "Finishing drawing window %s: mDrawState=%s", |
| 333 | mWin, drawStateToString()); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 334 | } |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 335 | |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 336 | boolean layoutNeeded = false; |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 337 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 338 | if (mDrawState == DRAW_PENDING) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 339 | ProtoLog.v(WM_DEBUG_DRAW, |
| 340 | "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING %s in %s", mWin, |
| 341 | mSurfaceController); |
| 342 | if (startingWindow) { |
| 343 | ProtoLog.v(WM_DEBUG_STARTING_WINDOW, "Draw state now committed in %s", mWin); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 344 | } |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 345 | mDrawState = COMMIT_DRAW_PENDING; |
Chong Zhang | cbbcc0f | 2016-05-17 20:46:58 -0700 | [diff] [blame] | 346 | layoutNeeded = true; |
Vishnu Nair | 8cb00ae | 2019-08-02 15:20:29 -0700 | [diff] [blame] | 347 | |
| 348 | if (postDrawTransaction != null) { |
| 349 | mPostDrawTransaction.merge(postDrawTransaction); |
| 350 | } |
| 351 | } else if (postDrawTransaction != null) { |
| 352 | // If draw state is not pending we may delay applying this transaction from the client, |
| 353 | // so apply it now. |
| 354 | postDrawTransaction.apply(); |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 355 | } |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 356 | |
Chong Zhang | cbbcc0f | 2016-05-17 20:46:58 -0700 | [diff] [blame] | 357 | return layoutNeeded; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | // This must be called while inside a transaction. |
Craig Mautner | c431e89 | 2015-02-11 13:14:26 -0800 | [diff] [blame] | 361 | boolean commitFinishDrawingLocked() { |
Jorim Jaggi | e4b0f28 | 2017-05-17 15:10:29 +0200 | [diff] [blame] | 362 | if (DEBUG_STARTING_WINDOW_VERBOSE && |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 363 | mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 364 | Slog.i(TAG, "commitFinishDrawingLocked: " + mWin + " cur mDrawState=" |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 365 | + drawStateToString()); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 366 | } |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 367 | if (mDrawState != COMMIT_DRAW_PENDING && mDrawState != READY_TO_SHOW) { |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 368 | return false; |
| 369 | } |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 370 | if (DEBUG_ANIM) { |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 371 | Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurfaceController); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 372 | } |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 373 | mDrawState = READY_TO_SHOW; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 374 | boolean result = false; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 375 | final ActivityRecord activity = mWin.mActivityRecord; |
| 376 | if (activity == null || activity.canShowWindows() |
Jorim Jaggi | af0d6d2 | 2018-06-08 15:25:35 +0200 | [diff] [blame] | 377 | || mWin.mAttrs.type == TYPE_APPLICATION_STARTING) { |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 378 | result = mWin.performShowLocked(); |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 379 | } |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 380 | return result; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 383 | void preserveSurfaceLocked() { |
| 384 | if (mDestroyPreservedSurfaceUponRedraw) { |
Chong Zhang | b9b0fec | 2016-02-11 18:51:51 -0800 | [diff] [blame] | 385 | // This could happen when switching the surface mode very fast. For example, |
| 386 | // we preserved a surface when dragResizing changed to true. Then before the |
| 387 | // preserved surface is removed, dragResizing changed to false again. |
| 388 | // In this case, we need to leave the preserved surface alone, and destroy |
| 389 | // the actual surface, so that the createSurface call could create a surface |
| 390 | // of the proper size. The preserved surface will still be removed when client |
| 391 | // finishes drawing to the new surface. |
| 392 | mSurfaceDestroyDeferred = false; |
Vishnu Nair | 7c86147 | 2019-07-25 09:57:12 -0700 | [diff] [blame] | 393 | |
| 394 | // Make sure to reparent any children of the new surface back to the preserved |
| 395 | // surface before destroying it. |
| 396 | if (mSurfaceController != null && mPendingDestroySurface != null) { |
Rob Carr | 698b684 | 2020-03-06 15:33:31 -0800 | [diff] [blame] | 397 | mPostDrawTransaction.reparentChildren( |
| 398 | mSurfaceController.getClientViewRootSurface(), |
| 399 | mPendingDestroySurface.mSurfaceControl).apply(); |
Vishnu Nair | 7c86147 | 2019-07-25 09:57:12 -0700 | [diff] [blame] | 400 | } |
Chong Zhang | b9b0fec | 2016-02-11 18:51:51 -0800 | [diff] [blame] | 401 | destroySurfaceLocked(); |
| 402 | mSurfaceDestroyDeferred = true; |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 403 | return; |
| 404 | } |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 405 | ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE SET FREEZE LAYER: %s", mWin); |
Wale Ogunwale | f9e0978 | 2015-11-09 12:42:37 -0800 | [diff] [blame] | 406 | if (mSurfaceController != null) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 407 | // Our SurfaceControl is always at layer 0 within the parent Surface managed by |
| 408 | // window-state. We want this old Surface to stay on top of the new one |
Tiger Huang | 9c8ee26 | 2019-02-19 20:44:27 +0800 | [diff] [blame] | 409 | // until we do the swap, so we place it at a positive layer. |
| 410 | mSurfaceController.mSurfaceControl.setLayer(PRESERVED_SURFACE_LAYER); |
Wale Ogunwale | f9e0978 | 2015-11-09 12:42:37 -0800 | [diff] [blame] | 411 | } |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 412 | mDestroyPreservedSurfaceUponRedraw = true; |
| 413 | mSurfaceDestroyDeferred = true; |
| 414 | destroySurfaceLocked(); |
| 415 | } |
| 416 | |
| 417 | void destroyPreservedSurfaceLocked() { |
| 418 | if (!mDestroyPreservedSurfaceUponRedraw) { |
| 419 | return; |
| 420 | } |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 421 | if (mSurfaceController != null) { |
| 422 | if (mPendingDestroySurface != null) { |
| 423 | // If we are preserving a surface but we aren't relaunching that means |
| 424 | // we are just doing an in-place switch. In that case any SurfaceFlinger side |
| 425 | // child layers need to be reparented to the new surface to make this |
| 426 | // transparent to the app. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 427 | if (mWin.mActivityRecord == null || mWin.mActivityRecord.isRelaunching() == false) { |
Rob Carr | 698b684 | 2020-03-06 15:33:31 -0800 | [diff] [blame] | 428 | mPostDrawTransaction.reparentChildren( |
| 429 | mPendingDestroySurface.getClientViewRootSurface(), |
| 430 | mSurfaceController.mSurfaceControl).apply(); |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | } |
| 434 | |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 435 | destroyDeferredSurfaceLocked(); |
| 436 | mDestroyPreservedSurfaceUponRedraw = false; |
| 437 | } |
| 438 | |
Chong Zhang | eb66557 | 2016-05-09 18:28:27 -0700 | [diff] [blame] | 439 | void markPreservedSurfaceForDestroy() { |
| 440 | if (mDestroyPreservedSurfaceUponRedraw |
| 441 | && !mService.mDestroyPreservedSurface.contains(mWin)) { |
| 442 | mService.mDestroyPreservedSurface.add(mWin); |
| 443 | } |
| 444 | } |
| 445 | |
Robert Carr | ecc06b3 | 2017-04-18 14:25:10 -0700 | [diff] [blame] | 446 | void resetDrawState() { |
| 447 | mDrawState = DRAW_PENDING; |
| 448 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 449 | if (mWin.mActivityRecord == null) { |
Robert Carr | ecc06b3 | 2017-04-18 14:25:10 -0700 | [diff] [blame] | 450 | return; |
| 451 | } |
| 452 | |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 453 | if (!mWin.mActivityRecord.isAnimating(TRANSITION)) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 454 | mWin.mActivityRecord.clearAllDrawn(); |
Robert Carr | ecc06b3 | 2017-04-18 14:25:10 -0700 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | |
Albert Chaulk | 3bf2e57 | 2016-11-22 13:59:19 -0500 | [diff] [blame] | 458 | WindowSurfaceController createSurfaceLocked(int windowType, int ownerUid) { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 459 | final WindowState w = mWin; |
Chong Zhang | a8975bd | 2016-01-28 17:13:47 -0800 | [diff] [blame] | 460 | |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 461 | if (mSurfaceController != null) { |
| 462 | return mSurfaceController; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 463 | } |
Robert Carr | 7b3d11d | 2018-03-15 14:34:45 -0700 | [diff] [blame] | 464 | mChildrenDetached = false; |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 465 | |
Robert Carr | 132c9f5 | 2017-07-31 17:02:30 -0700 | [diff] [blame] | 466 | if ((mWin.mAttrs.privateFlags & PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY) != 0) { |
| 467 | windowType = SurfaceControl.WINDOW_TYPE_DONT_SCREENSHOT; |
| 468 | } |
| 469 | |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 470 | w.setHasSurface(false); |
| 471 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 472 | if (DEBUG_ANIM) { |
| 473 | Slog.i(TAG, "createSurface " + this + ": mDrawState=DRAW_PENDING"); |
| 474 | } |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 475 | |
Robert Carr | ecc06b3 | 2017-04-18 14:25:10 -0700 | [diff] [blame] | 476 | resetDrawState(); |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 477 | |
| 478 | mService.makeWindowFreezingScreenIfNeededLocked(w); |
| 479 | |
| 480 | int flags = SurfaceControl.HIDDEN; |
| 481 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 482 | |
| 483 | if (mService.isSecureLocked(w)) { |
| 484 | flags |= SurfaceControl.SECURE; |
| 485 | } |
| 486 | |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 487 | calculateSurfaceBounds(w, attrs, mTmpSize); |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 488 | final int width = mTmpSize.width(); |
| 489 | final int height = mTmpSize.height(); |
| 490 | |
| 491 | if (DEBUG_VISIBILITY) { |
| 492 | Slog.v(TAG, "Creating surface in session " |
| 493 | + mSession.mSurfaceSession + " window " + this |
| 494 | + " w=" + width + " h=" + height |
| 495 | + " x=" + mTmpSize.left + " y=" + mTmpSize.top |
| 496 | + " format=" + attrs.format + " flags=" + flags); |
| 497 | } |
| 498 | |
| 499 | // We may abort, so initialize to defaults. |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 500 | mLastClipRect.set(0, 0, 0, 0); |
| 501 | |
| 502 | // Set up surface control with initial size. |
| 503 | try { |
| 504 | |
| 505 | final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0; |
| 506 | final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format; |
| 507 | if (!PixelFormat.formatHasAlpha(attrs.format) |
| 508 | // Don't make surface with surfaceInsets opaque as they display a |
| 509 | // translucent shadow. |
| 510 | && attrs.surfaceInsets.left == 0 |
| 511 | && attrs.surfaceInsets.top == 0 |
| 512 | && attrs.surfaceInsets.right == 0 |
| 513 | && attrs.surfaceInsets.bottom == 0 |
| 514 | // Don't make surface opaque when resizing to reduce the amount of |
| 515 | // artifacts shown in areas the app isn't drawing content to. |
| 516 | && !w.isDragResizing()) { |
| 517 | flags |= SurfaceControl.OPAQUE; |
| 518 | } |
| 519 | |
chaviw | 619da69 | 2019-06-10 15:39:40 -0700 | [diff] [blame] | 520 | mSurfaceController = new WindowSurfaceController(attrs.getTitle().toString(), width, |
| 521 | height, format, flags, this, windowType, ownerUid); |
Peiyong Lin | 7504538 | 2019-03-04 19:22:33 -0800 | [diff] [blame] | 522 | mSurfaceController.setColorSpaceAgnostic((attrs.privateFlags |
| 523 | & WindowManager.LayoutParams.PRIVATE_FLAG_COLOR_SPACE_AGNOSTIC) != 0); |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 524 | |
| 525 | setOffsetPositionForStackResize(false); |
Robert Carr | 486bbb7 | 2017-05-30 11:25:22 -0700 | [diff] [blame] | 526 | mSurfaceFormat = format; |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 527 | |
| 528 | w.setHasSurface(true); |
| 529 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 530 | ProtoLog.i(WM_SHOW_SURFACE_ALLOC, |
| 531 | " CREATE SURFACE %s IN SESSION %s: pid=%d format=%d flags=0x%x / %s", |
| 532 | mSurfaceController, mSession.mSurfaceSession, mSession.mPid, attrs.format, |
| 533 | flags, this); |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 534 | } catch (OutOfResourcesException e) { |
| 535 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 536 | mService.mRoot.reclaimSomeSurfaceMemory(this, "create", true); |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 537 | mDrawState = NO_SURFACE; |
| 538 | return null; |
| 539 | } catch (Exception e) { |
Robert Carr | b0f3936 | 2018-03-14 13:52:25 -0700 | [diff] [blame] | 540 | Slog.e(TAG, "Exception creating surface (parent dead?)", e); |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 541 | mDrawState = NO_SURFACE; |
| 542 | return null; |
| 543 | } |
| 544 | |
Adam Pardyl | 8c2d19c | 2019-09-16 17:15:38 +0200 | [diff] [blame] | 545 | if (DEBUG) { |
| 546 | Slog.v(TAG, "Got surface: " + mSurfaceController |
| 547 | + ", set left=" + w.getFrameLw().left + " top=" + w.getFrameLw().top); |
| 548 | } |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 549 | |
| 550 | if (SHOW_LIGHT_TRANSACTIONS) { |
| 551 | Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked"); |
| 552 | WindowManagerService.logSurface(w, "CREATE pos=(" |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 553 | + w.getFrameLw().left + "," + w.getFrameLw().top + ") (" |
Jorim Jaggi | 35d328a | 2018-08-14 17:00:20 +0200 | [diff] [blame] | 554 | + width + "x" + height + ")" + " HIDE", false); |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 555 | } |
| 556 | |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 557 | mLastHidden = true; |
| 558 | |
Adam Pardyl | 8c2d19c | 2019-09-16 17:15:38 +0200 | [diff] [blame] | 559 | if (DEBUG) Slog.v(TAG, "Created surface " + this); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 560 | return mSurfaceController; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 561 | } |
| 562 | |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 563 | private void calculateSurfaceBounds(WindowState w, LayoutParams attrs, Rect outSize) { |
| 564 | outSize.setEmpty(); |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 565 | if ((attrs.flags & FLAG_SCALED) != 0) { |
| 566 | // For a scaled surface, we always want the requested size. |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 567 | outSize.right = w.mRequestedWidth; |
| 568 | outSize.bottom = w.mRequestedHeight; |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 569 | } else { |
| 570 | // When we're doing a drag-resizing, request a surface that's fullscreen size, |
| 571 | // so that we don't need to reallocate during the process. This also prevents |
| 572 | // buffer drops due to size mismatch. |
| 573 | if (w.isDragResizing()) { |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 574 | final DisplayInfo displayInfo = w.getDisplayInfo(); |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 575 | outSize.right = displayInfo.logicalWidth; |
| 576 | outSize.bottom = displayInfo.logicalHeight; |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 577 | } else { |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 578 | w.getCompatFrameSize(outSize); |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | |
| 582 | // Something is wrong and SurfaceFlinger will not like this, try to revert to sane values. |
Filip Gruszczynski | e6ed195 | 2015-12-21 09:34:16 -0800 | [diff] [blame] | 583 | // This doesn't necessarily mean that there is an error in the system. The sizes might be |
| 584 | // incorrect, because it is before the first layout or draw. |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 585 | if (outSize.width() < 1) { |
| 586 | outSize.right = 1; |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 587 | } |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 588 | if (outSize.height() < 1) { |
| 589 | outSize.bottom = 1; |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 590 | } |
| 591 | |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 592 | // Adjust for surface insets. |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 593 | outSize.inset(-attrs.surfaceInsets.left, -attrs.surfaceInsets.top, |
| 594 | -attrs.surfaceInsets.right, -attrs.surfaceInsets.bottom); |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 595 | } |
| 596 | |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 597 | boolean hasSurface() { |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 598 | return mSurfaceController != null && mSurfaceController.hasSurface(); |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 599 | } |
| 600 | |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 601 | void destroySurfaceLocked() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 602 | final ActivityRecord activity = mWin.mActivityRecord; |
| 603 | if (activity != null) { |
| 604 | if (mWin == activity.startingWindow) { |
| 605 | activity.startingDisplayed = false; |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 606 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 609 | if (mSurfaceController == null) { |
| 610 | return; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 611 | } |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 612 | |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 613 | // When destroying a surface we want to make sure child windows are hidden. If we are |
| 614 | // preserving the surface until redraw though we intend to swap it out with another surface |
| 615 | // for resizing. In this case the window always remains visible to the user and the child |
| 616 | // windows should likewise remain visible. |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 617 | if (!mDestroyPreservedSurfaceUponRedraw) { |
| 618 | mWin.mHidden = true; |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | try { |
| 622 | if (DEBUG_VISIBILITY) logWithStack(TAG, "Window " + this + " destroying surface " |
| 623 | + mSurfaceController + ", session " + mSession); |
| 624 | if (mSurfaceDestroyDeferred) { |
| 625 | if (mSurfaceController != null && mPendingDestroySurface != mSurfaceController) { |
| 626 | if (mPendingDestroySurface != null) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 627 | ProtoLog.i(WM_SHOW_SURFACE_ALLOC, "SURFACE DESTROY PENDING: %s. %s", |
| 628 | mWin, new RuntimeException().fillInStackTrace()); |
Robert Carr | a882886 | 2018-02-05 16:17:36 -0800 | [diff] [blame] | 629 | mPendingDestroySurface.destroyNotInTransaction(); |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 630 | } |
| 631 | mPendingDestroySurface = mSurfaceController; |
| 632 | } |
| 633 | } else { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 634 | ProtoLog.i(WM_SHOW_SURFACE_ALLOC, "SURFACE DESTROY: %s. %s", |
| 635 | mWin, new RuntimeException().fillInStackTrace()); |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 636 | destroySurface(); |
| 637 | } |
| 638 | // Don't hide wallpaper if we're deferring the surface destroy |
| 639 | // because of a surface change. |
| 640 | if (!mDestroyPreservedSurfaceUponRedraw) { |
| 641 | mWallpaperControllerLocked.hideWallpapers(mWin); |
| 642 | } |
| 643 | } catch (RuntimeException e) { |
| 644 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
| 645 | + " surface " + mSurfaceController + " session " + mSession + ": " + e.toString()); |
| 646 | } |
| 647 | |
| 648 | // Whether the surface was preserved (and copied to mPendingDestroySurface) or not, it |
| 649 | // needs to be cleared to match the WindowState.mHasSurface state. It is also necessary |
| 650 | // so it can be recreated successfully in mPendingDestroySurface case. |
| 651 | mWin.setHasSurface(false); |
| 652 | if (mSurfaceController != null) { |
| 653 | mSurfaceController.setShown(false); |
| 654 | } |
| 655 | mSurfaceController = null; |
| 656 | mDrawState = NO_SURFACE; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 659 | void destroyDeferredSurfaceLocked() { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 660 | try { |
| 661 | if (mPendingDestroySurface != null) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 662 | ProtoLog.i(WM_SHOW_SURFACE_ALLOC, "SURFACE DESTROY PENDING: %s. %s", |
| 663 | mWin, new RuntimeException().fillInStackTrace()); |
Robert Carr | a882886 | 2018-02-05 16:17:36 -0800 | [diff] [blame] | 664 | mPendingDestroySurface.destroyNotInTransaction(); |
Chong Zhang | 6e21cf4 | 2015-11-09 14:41:42 -0800 | [diff] [blame] | 665 | // Don't hide wallpaper if we're destroying a deferred surface |
| 666 | // after a surface mode change. |
| 667 | if (!mDestroyPreservedSurfaceUponRedraw) { |
| 668 | mWallpaperControllerLocked.hideWallpapers(mWin); |
| 669 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 670 | } |
| 671 | } catch (RuntimeException e) { |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 672 | Slog.w(TAG, "Exception thrown when destroying Window " |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 673 | + this + " surface " + mPendingDestroySurface |
| 674 | + " session " + mSession + ": " + e.toString()); |
| 675 | } |
| 676 | mSurfaceDestroyDeferred = false; |
| 677 | mPendingDestroySurface = null; |
| 678 | } |
| 679 | |
| 680 | void computeShownFrameLocked() { |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 681 | final ScreenRotationAnimation screenRotationAnimation = |
Vadim Caen | b371583 | 2019-08-13 17:06:38 +0200 | [diff] [blame] | 682 | mWin.getDisplayContent().getRotationAnimation(); |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 683 | final boolean windowParticipatesInScreenRotationAnimation = |
| 684 | !mWin.mForceSeamlesslyRotate; |
| 685 | final boolean screenAnimation = screenRotationAnimation != null |
| 686 | && screenRotationAnimation.isAnimating() |
| 687 | && windowParticipatesInScreenRotationAnimation; |
Robert Carr | 2f0fe62 | 2015-09-25 14:56:38 -0700 | [diff] [blame] | 688 | |
Robert Carr | 44643c1 | 2017-09-27 14:57:38 -0700 | [diff] [blame] | 689 | if (screenAnimation) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 690 | // cache often used attributes locally |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 691 | final Rect frame = mWin.getFrameLw(); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 692 | final float tmpFloats[] = mService.mTmpFloats; |
| 693 | final Matrix tmpMatrix = mWin.mTmpMatrix; |
| 694 | |
| 695 | // Compute the desired transformation. |
Robert Carr | 44643c1 | 2017-09-27 14:57:38 -0700 | [diff] [blame] | 696 | if (screenRotationAnimation.isRotating()) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 697 | // If we are doing a screen animation, the global rotation |
| 698 | // applied to windows can result in windows that are carefully |
| 699 | // aligned with each other to slightly separate, allowing you |
| 700 | // to see what is behind them. An unsightly mess. This... |
| 701 | // thing... magically makes it call good: scale each window |
| 702 | // slightly (two pixels larger in each dimension, from the |
| 703 | // window's center). |
| 704 | final float w = frame.width(); |
| 705 | final float h = frame.height(); |
| 706 | if (w>=1 && h>=1) { |
| 707 | tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2); |
| 708 | } else { |
| 709 | tmpMatrix.reset(); |
| 710 | } |
| 711 | } else { |
| 712 | tmpMatrix.reset(); |
| 713 | } |
Robert Carr | 44643c1 | 2017-09-27 14:57:38 -0700 | [diff] [blame] | 714 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 715 | tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale); |
Robert Carr | 29d196f | 2017-11-28 12:39:46 -0800 | [diff] [blame] | 716 | |
Jorim Jaggi | 9af095b | 2017-12-12 17:18:57 +0100 | [diff] [blame] | 717 | // WindowState.prepareSurfaces expands for surface insets (in order they don't get |
| 718 | // clipped by the WindowState surface), so we need to go into the other direction here. |
Robert Carr | 217e7cc | 2018-01-31 18:08:39 -0800 | [diff] [blame] | 719 | tmpMatrix.postTranslate(mWin.mAttrs.surfaceInsets.left, |
| 720 | mWin.mAttrs.surfaceInsets.top); |
Jorim Jaggi | 9af095b | 2017-12-12 17:18:57 +0100 | [diff] [blame] | 721 | |
Matthew Ng | 34a06d1 | 2017-02-03 11:56:08 -0800 | [diff] [blame] | 722 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 723 | // "convert" it into SurfaceFlinger's format |
| 724 | // (a 2x2 matrix + an offset) |
| 725 | // Here we must not transform the position of the surface |
| 726 | // since it is already included in the transformation. |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 727 | //Slog.i(TAG_WM, "Transform: " + matrix); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 728 | |
| 729 | mHaveMatrix = true; |
| 730 | tmpMatrix.getValues(tmpFloats); |
| 731 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 732 | mDtDx = tmpFloats[Matrix.MSKEW_Y]; |
Robert Carr | 0edf18f | 2017-02-21 20:01:47 -0800 | [diff] [blame] | 733 | mDtDy = tmpFloats[Matrix.MSKEW_X]; |
| 734 | mDsDy = tmpFloats[Matrix.MSCALE_Y]; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 735 | |
| 736 | // Now set the alpha... but because our current hardware |
| 737 | // can't do alpha transformation on a non-opaque surface, |
| 738 | // turn it off if we are running an animation that is also |
| 739 | // transforming since it is more important to have that |
| 740 | // animation be smooth. |
| 741 | mShownAlpha = mAlpha; |
| 742 | if (!mService.mLimitedAlphaCompositing |
| 743 | || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format) |
Robert Carr | 217e7cc | 2018-01-31 18:08:39 -0800 | [diff] [blame] | 744 | || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDtDy, mDsDy)))) { |
Vadim Caen | 641d39d | 2019-07-23 11:29:45 +0200 | [diff] [blame] | 745 | mShownAlpha *= screenRotationAnimation.getEnterTransformation().getAlpha(); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 746 | } |
| 747 | |
Adam Pardyl | 8c2d19c | 2019-09-16 17:15:38 +0200 | [diff] [blame] | 748 | if ((DEBUG_ANIM || DEBUG) && (mShownAlpha == 1.0 || mShownAlpha == 0.0)) { |
| 749 | Slog.v(TAG, "computeShownFrameLocked: Animating " + this + " mAlpha=" + mAlpha |
| 750 | + " screen=" + (screenAnimation |
| 751 | ? screenRotationAnimation.getEnterTransformation().getAlpha() : "null")); |
| 752 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 753 | return; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 754 | } else if (mIsWallpaper && mService.mRoot.mWallpaperActionPending) { |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 755 | return; |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 756 | } else if (mWin.isDragResizeChanged()) { |
| 757 | // This window is awaiting a relayout because user just started (or ended) |
| 758 | // drag-resizing. The shown frame (which affects surface size and pos) |
| 759 | // should not be updated until we get next finished draw with the new surface. |
| 760 | // Otherwise one or two frames rendered with old settings would be displayed |
| 761 | // with new geometry. |
| 762 | return; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 763 | } |
| 764 | |
Adam Pardyl | 8c2d19c | 2019-09-16 17:15:38 +0200 | [diff] [blame] | 765 | if (DEBUG) { |
| 766 | Slog.v(TAG, "computeShownFrameLocked: " + this |
| 767 | + " not attached, mAlpha=" + mAlpha); |
| 768 | } |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 769 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 770 | mShownAlpha = mAlpha; |
| 771 | mHaveMatrix = false; |
| 772 | mDsDx = mWin.mGlobalScale; |
| 773 | mDtDx = 0; |
| 774 | mDtDy = 0; |
| 775 | mDsDy = mWin.mGlobalScale; |
Robert Carr | ef090ac | 2017-05-15 16:45:50 -0700 | [diff] [blame] | 776 | } |
| 777 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 778 | /** |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 779 | * Calculate the window-space crop rect and fill clipRect. |
Wale Ogunwale | ca9e061 | 2016-12-02 07:45:59 -0800 | [diff] [blame] | 780 | * @return true if clipRect has been filled otherwise, no window space crop should be applied. |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 781 | */ |
Wale Ogunwale | ca9e061 | 2016-12-02 07:45:59 -0800 | [diff] [blame] | 782 | private boolean calculateCrop(Rect clipRect) { |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 783 | final WindowState w = mWin; |
| 784 | final DisplayContent displayContent = w.getDisplayContent(); |
| 785 | clipRect.setEmpty(); |
| 786 | |
| 787 | if (displayContent == null) { |
| 788 | return false; |
| 789 | } |
| 790 | |
Evan Rosky | e067ddf | 2020-04-24 18:28:25 -0700 | [diff] [blame] | 791 | if (w.getWindowConfiguration().tasksAreFloating() |
| 792 | || WindowConfiguration.isSplitScreenWindowingMode(w.getWindowingMode())) { |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 793 | return false; |
| 794 | } |
| 795 | |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 796 | // During forced seamless rotation, the surface bounds get updated with the crop in the |
| 797 | // new rotation, which is not compatible with showing the surface in the old rotation. |
| 798 | // To work around that we disable cropping for such windows, as it is not necessary anyways. |
| 799 | if (w.mForceSeamlesslyRotate) { |
| 800 | return false; |
| 801 | } |
| 802 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 803 | // If we're animating, the wallpaper should only |
| 804 | // be updated at the end of the animation. |
| 805 | if (w.mAttrs.type == TYPE_WALLPAPER) { |
| 806 | return false; |
| 807 | } |
| 808 | |
Wale Ogunwale | 6bab4cf | 2016-04-07 12:23:08 -0700 | [diff] [blame] | 809 | if (DEBUG_WINDOW_CROP) Slog.d(TAG, |
| 810 | "Updating crop win=" + w + " mLastCrop=" + mLastClipRect); |
Dianne Hackborn | 3e52fc2 | 2012-05-15 17:58:02 -0700 | [diff] [blame] | 811 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 812 | w.calculatePolicyCrop(mSystemDecorRect); |
| 813 | |
| 814 | if (DEBUG_WINDOW_CROP) Slog.d(TAG, "Applying decor to crop win=" + w + " mDecorFrame=" |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 815 | + w.getDecorFrame() + " mSystemDecorRect=" + mSystemDecorRect); |
Dianne Hackborn | 3e52fc2 | 2012-05-15 17:58:02 -0700 | [diff] [blame] | 816 | |
Robert Carr | 51a1b87 | 2015-12-08 14:03:13 -0800 | [diff] [blame] | 817 | // We use the clip rect as provided by the tranformation for non-fullscreen windows to |
| 818 | // avoid premature clipping with the system decor rect. |
Robert Carr | f058662 | 2018-01-29 13:03:43 -0800 | [diff] [blame] | 819 | clipRect.set(mSystemDecorRect); |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 820 | if (DEBUG_WINDOW_CROP) Slog.d(TAG, "win=" + w + " Initial clip rect: " + clipRect); |
Robert Carr | 51a1b87 | 2015-12-08 14:03:13 -0800 | [diff] [blame] | 821 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 822 | w.expandForSurfaceInsets(clipRect); |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 823 | |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 824 | // The clip rect was generated assuming (0,0) as the window origin, |
| 825 | // so we need to translate to match the actual surface coordinates. |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 826 | clipRect.offset(w.mAttrs.surfaceInsets.left, w.mAttrs.surfaceInsets.top); |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 827 | |
Wale Ogunwale | 6bab4cf | 2016-04-07 12:23:08 -0700 | [diff] [blame] | 828 | if (DEBUG_WINDOW_CROP) Slog.d(TAG, |
| 829 | "win=" + w + " Clip rect after stack adjustment=" + clipRect); |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 830 | |
Chia-I Wu | e6bcaf1 | 2016-05-27 10:58:48 +0800 | [diff] [blame] | 831 | w.transformClipRectFromScreenToSurfaceSpace(clipRect); |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 832 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 833 | return true; |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 834 | } |
| 835 | |
chaviw | 2301211 | 2017-12-20 15:29:04 -0800 | [diff] [blame] | 836 | private void applyCrop(Rect clipRect, boolean recoveringMemory) { |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 837 | if (DEBUG_WINDOW_CROP) Slog.d(TAG, "applyCrop: win=" + mWin |
chaviw | 2301211 | 2017-12-20 15:29:04 -0800 | [diff] [blame] | 838 | + " clipRect=" + clipRect); |
Robert Carr | 4320d33 | 2016-06-10 15:13:32 -0700 | [diff] [blame] | 839 | if (clipRect != null) { |
| 840 | if (!clipRect.equals(mLastClipRect)) { |
| 841 | mLastClipRect.set(clipRect); |
| 842 | mSurfaceController.setCropInTransaction(clipRect, recoveringMemory); |
| 843 | } |
| 844 | } else { |
| 845 | mSurfaceController.clearCropInTransaction(recoveringMemory); |
Dianne Hackborn | 3e52fc2 | 2012-05-15 17:58:02 -0700 | [diff] [blame] | 846 | } |
Filip Gruszczynski | 4b8eea7 | 2015-09-14 18:16:19 -0700 | [diff] [blame] | 847 | } |
| 848 | |
Robert Carr | 2162a2f | 2020-05-05 13:46:48 -0700 | [diff] [blame] | 849 | private boolean shouldConsumeMainWindowSizeTransaction() { |
| 850 | // We only consume the transaction when the client is calling relayout |
| 851 | // because this is the only time we know the frameNumber will be valid |
| 852 | // due to the client renderer being paused. Put otherwise, only when |
| 853 | // mInRelayout is true can we guarantee the next frame will contain |
| 854 | // the most recent configuration. |
| 855 | if (!mWin.mInRelayout) return false; |
| 856 | // Since we can only do this for one window, we focus on the main application window |
| 857 | if (mAttrType != TYPE_BASE_APPLICATION) return false; |
| 858 | final Task task = mWin.getTask(); |
| 859 | if (task == null) return false; |
| 860 | if (task.getMainWindowSizeChangeTransaction() == null) return false; |
| 861 | // Likewise we only focus on the task root, since we can only use one window |
| 862 | if (!mWin.mActivityRecord.isRootOfTask()) return false; |
| 863 | return true; |
| 864 | } |
| 865 | |
Wale Ogunwale | 4c8b795 | 2015-04-07 10:49:40 -0700 | [diff] [blame] | 866 | void setSurfaceBoundariesLocked(final boolean recoveringMemory) { |
Wale Ogunwale | 027f475 | 2017-05-12 10:37:16 -0700 | [diff] [blame] | 867 | if (mSurfaceController == null) { |
| 868 | return; |
| 869 | } |
| 870 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 871 | final WindowState w = mWin; |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 872 | final LayoutParams attrs = mWin.getAttrs(); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 873 | final Task task = w.getTask(); |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 874 | |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 875 | calculateSurfaceBounds(w, attrs, mTmpSize); |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 876 | |
Robert Carr | 0409211 | 2016-06-02 12:56:12 -0700 | [diff] [blame] | 877 | mExtraHScale = (float) 1.0; |
| 878 | mExtraVScale = (float) 1.0; |
Robert Carr | e1034cc3 | 2016-02-01 13:08:15 -0800 | [diff] [blame] | 879 | |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 880 | boolean wasForceScaled = mForceScaleUntilResize; |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 881 | |
Robert Carr | fed1007 | 2016-05-26 11:48:49 -0700 | [diff] [blame] | 882 | // Once relayout has been called at least once, we need to make sure |
| 883 | // we only resize the client surface during calls to relayout. For |
| 884 | // clients which use indeterminate measure specs (MATCH_PARENT), |
| 885 | // we may try and change their window size without a call to relayout. |
| 886 | // However, this would be unsafe, as the client may be in the middle |
| 887 | // of producing a frame at the old size, having just completed layout |
| 888 | // to find the surface size changed underneath it. |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 889 | final boolean relayout = !w.mRelayoutCalled || w.mInRelayout; |
| 890 | if (relayout) { |
Vishnu Nair | e86bd98 | 2018-11-28 13:23:17 -0800 | [diff] [blame] | 891 | mSurfaceResized = mSurfaceController.setBufferSizeInTransaction( |
Robert Carr | fed1007 | 2016-05-26 11:48:49 -0700 | [diff] [blame] | 892 | mTmpSize.width(), mTmpSize.height(), recoveringMemory); |
| 893 | } else { |
| 894 | mSurfaceResized = false; |
| 895 | } |
Robert Carr | c729460 | 2016-05-13 11:32:05 -0700 | [diff] [blame] | 896 | mForceScaleUntilResize = mForceScaleUntilResize && !mSurfaceResized; |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 897 | // If we are undergoing seamless rotation, the surface has already |
| 898 | // been set up to persist at it's old location. We need to freeze |
| 899 | // updates until a resize occurs. |
Robert Carr | c729460 | 2016-05-13 11:32:05 -0700 | [diff] [blame] | 900 | |
chaviw | 2301211 | 2017-12-20 15:29:04 -0800 | [diff] [blame] | 901 | Rect clipRect = null; |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 902 | if (calculateCrop(mTmpClipRect)) { |
| 903 | clipRect = mTmpClipRect; |
| 904 | } |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 905 | |
Robert Carr | 2162a2f | 2020-05-05 13:46:48 -0700 | [diff] [blame] | 906 | if (shouldConsumeMainWindowSizeTransaction()) { |
| 907 | task.getSurfaceControl().deferTransactionUntil(mWin.getClientViewRootSurface(), |
| 908 | mWin.getFrameNumber()); |
Rob Carr | 698b684 | 2020-03-06 15:33:31 -0800 | [diff] [blame] | 909 | mSurfaceController.deferTransactionUntil(mWin.getClientViewRootSurface(), |
Robert Carr | 711e705 | 2020-02-19 11:14:33 -0800 | [diff] [blame] | 910 | mWin.getFrameNumber()); |
| 911 | SurfaceControl.mergeToGlobalTransaction(task.getMainWindowSizeChangeTransaction()); |
| 912 | task.setMainWindowSizeChangeTransaction(null); |
| 913 | } |
| 914 | |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 915 | float surfaceWidth = mSurfaceController.getWidth(); |
| 916 | float surfaceHeight = mSurfaceController.getHeight(); |
| 917 | |
Robert Carr | 74a66a2 | 2018-02-23 12:17:51 -0800 | [diff] [blame] | 918 | final Rect insets = attrs.surfaceInsets; |
| 919 | |
Robert Carr | 8f0a3ad | 2017-02-15 19:30:28 -0800 | [diff] [blame] | 920 | if (isForceScaled()) { |
Robert Carr | 74a66a2 | 2018-02-23 12:17:51 -0800 | [diff] [blame] | 921 | int hInsets = insets.left + insets.right; |
| 922 | int vInsets = insets.top + insets.bottom; |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 923 | float surfaceContentWidth = surfaceWidth - hInsets; |
| 924 | float surfaceContentHeight = surfaceHeight - vInsets; |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 925 | if (!mForceScaleUntilResize) { |
| 926 | mSurfaceController.forceScaleableInTransaction(true); |
| 927 | } |
Robert Carr | fd4c989 | 2017-02-01 10:28:28 -0800 | [diff] [blame] | 928 | |
Robert Carr | 74a66a2 | 2018-02-23 12:17:51 -0800 | [diff] [blame] | 929 | int posX = 0; |
| 930 | int posY = 0; |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 931 | task.getStack().getDimBounds(mTmpStackBounds); |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 932 | |
| 933 | boolean allowStretching = false; |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 934 | task.getStack().getFinalAnimationSourceHintBounds(mTmpSourceBounds); |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 935 | // If we don't have source bounds, we can attempt to use the content insets |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 936 | // if we have content insets. |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 937 | if (mTmpSourceBounds.isEmpty() && (mWin.mLastRelayoutContentInsets.width() > 0 |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 938 | || mWin.mLastRelayoutContentInsets.height() > 0)) { |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 939 | mTmpSourceBounds.set(task.getStack().mPreAnimationBounds); |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 940 | mTmpSourceBounds.inset(mWin.mLastRelayoutContentInsets); |
| 941 | allowStretching = true; |
| 942 | } |
Adrian Roos | 604ef95 | 2018-05-15 20:13:13 +0200 | [diff] [blame] | 943 | |
| 944 | // Make sure that what we're animating to and from is actually the right size in case |
| 945 | // the window cannot take up the full screen. |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 946 | mTmpStackBounds.intersectUnchecked(w.getParentFrame()); |
| 947 | mTmpSourceBounds.intersectUnchecked(w.getParentFrame()); |
| 948 | mTmpAnimatingBounds.intersectUnchecked(w.getParentFrame()); |
Adrian Roos | 604ef95 | 2018-05-15 20:13:13 +0200 | [diff] [blame] | 949 | |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 950 | if (!mTmpSourceBounds.isEmpty()) { |
| 951 | // Get the final target stack bounds, if we are not animating, this is just the |
| 952 | // current stack bounds |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 953 | task.getStack().getFinalAnimationBounds(mTmpAnimatingBounds); |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 954 | |
| 955 | // Calculate the current progress and interpolate the difference between the target |
| 956 | // and source bounds |
| 957 | float finalWidth = mTmpAnimatingBounds.width(); |
| 958 | float initialWidth = mTmpSourceBounds.width(); |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 959 | float tw = (surfaceContentWidth - mTmpStackBounds.width()) |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 960 | / (surfaceContentWidth - mTmpAnimatingBounds.width()); |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 961 | float th = tw; |
| 962 | mExtraHScale = (initialWidth + tw * (finalWidth - initialWidth)) / initialWidth; |
| 963 | if (allowStretching) { |
| 964 | float finalHeight = mTmpAnimatingBounds.height(); |
| 965 | float initialHeight = mTmpSourceBounds.height(); |
| 966 | th = (surfaceContentHeight - mTmpStackBounds.height()) |
| 967 | / (surfaceContentHeight - mTmpAnimatingBounds.height()); |
| 968 | mExtraVScale = (initialHeight + tw * (finalHeight - initialHeight)) |
| 969 | / initialHeight; |
| 970 | } else { |
| 971 | mExtraVScale = mExtraHScale; |
| 972 | } |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 973 | |
| 974 | // Adjust the position to account for the inset bounds |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 975 | posX -= (int) (tw * mExtraHScale * mTmpSourceBounds.left); |
| 976 | posY -= (int) (th * mExtraVScale * mTmpSourceBounds.top); |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 977 | |
Robert Carr | 74a66a2 | 2018-02-23 12:17:51 -0800 | [diff] [blame] | 978 | // In pinned mode the clip rectangle applied to us by our stack has been |
| 979 | // expanded outwards to allow for shadows. However in case of source bounds set |
| 980 | // we need to crop to within the surface. The code above has scaled and positioned |
| 981 | // the surface to fit the unexpanded stack bounds, but now we need to reapply |
| 982 | // the cropping that the stack would have applied if it weren't expanded. This |
| 983 | // can be different in each direction based on the source bounds. |
| 984 | clipRect = mTmpClipRect; |
| 985 | clipRect.set((int)((insets.left + mTmpSourceBounds.left) * tw), |
| 986 | (int)((insets.top + mTmpSourceBounds.top) * th), |
| 987 | insets.left + (int)(surfaceWidth |
| 988 | - (tw* (surfaceWidth - mTmpSourceBounds.right))), |
| 989 | insets.top + (int)(surfaceHeight |
| 990 | - (th * (surfaceHeight - mTmpSourceBounds.bottom)))); |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 991 | } else { |
| 992 | // We want to calculate the scaling based on the content area, not based on |
| 993 | // the entire surface, so that we scale in sync with windows that don't have insets. |
| 994 | mExtraHScale = mTmpStackBounds.width() / surfaceContentWidth; |
| 995 | mExtraVScale = mTmpStackBounds.height() / surfaceContentHeight; |
| 996 | |
| 997 | // Since we are scaled to fit in our previously desired crop, we can now |
| 998 | // expose the whole window in buffer space, and not risk extending |
| 999 | // past where the system would have cropped us |
| 1000 | clipRect = null; |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 1001 | } |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1002 | |
Robert Carr | fd4c989 | 2017-02-01 10:28:28 -0800 | [diff] [blame] | 1003 | // In the case of ForceScaleToStack we scale entire tasks together, |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1004 | // and so we need to scale our offsets relative to the task bounds |
| 1005 | // or parent and child windows would fall out of alignment. |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 1006 | posX -= (int) (attrs.x * (1 - mExtraHScale)); |
| 1007 | posY -= (int) (attrs.y * (1 - mExtraVScale)); |
| 1008 | |
Robert Carr | bc13376 | 2016-05-12 14:04:38 -0700 | [diff] [blame] | 1009 | // Imagine we are scaling down. As we scale the buffer down, we decrease the |
| 1010 | // distance between the surface top left, and the start of the surface contents |
| 1011 | // (previously it was surfaceInsets.left pixels in screen space but now it |
Robert Carr | 0409211 | 2016-06-02 12:56:12 -0700 | [diff] [blame] | 1012 | // will be surfaceInsets.left*mExtraHScale). This means in order to keep the |
Robert Carr | bc13376 | 2016-05-12 14:04:38 -0700 | [diff] [blame] | 1013 | // non inset content at the same position, we have to shift the whole window |
| 1014 | // forward. Likewise for scaling up, we've increased this distance, and we need |
| 1015 | // to shift by a negative number to compensate. |
Robert Carr | 74a66a2 | 2018-02-23 12:17:51 -0800 | [diff] [blame] | 1016 | posX += insets.left * (1 - mExtraHScale); |
| 1017 | posY += insets.top * (1 - mExtraVScale); |
Robert Carr | bc13376 | 2016-05-12 14:04:38 -0700 | [diff] [blame] | 1018 | |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 1019 | mSurfaceController.setPositionInTransaction((float) Math.floor(posX), |
| 1020 | (float) Math.floor(posY), recoveringMemory); |
Robert Carr | c729460 | 2016-05-13 11:32:05 -0700 | [diff] [blame] | 1021 | |
| 1022 | // Various surfaces in the scaled stack may resize at different times. |
| 1023 | // We need to ensure for each surface, that we disable transformation matrix |
| 1024 | // scaling in the same transaction which we resize the surface in. |
| 1025 | // As we are in SCALING_MODE_SCALE_TO_WINDOW, SurfaceFlinger will |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 1026 | // then take over the scaling until the new buffer arrives, and things |
Robert Carr | c729460 | 2016-05-13 11:32:05 -0700 | [diff] [blame] | 1027 | // will be seamless. |
Robert Carr | 2025bf84 | 2018-03-19 13:25:05 -0700 | [diff] [blame] | 1028 | if (mPipAnimationStarted == false) { |
| 1029 | mForceScaleUntilResize = true; |
| 1030 | mPipAnimationStarted = true; |
| 1031 | } |
Rob Carr | 06be6bb | 2018-02-06 16:26:06 +0000 | [diff] [blame] | 1032 | } else { |
Robert Carr | 2025bf84 | 2018-03-19 13:25:05 -0700 | [diff] [blame] | 1033 | mPipAnimationStarted = false; |
| 1034 | |
Rob Carr | 06be6bb | 2018-02-06 16:26:06 +0000 | [diff] [blame] | 1035 | if (!w.mSeamlesslyRotated) { |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 1036 | // Used to offset the WSA when stack position changes before a resize. |
| 1037 | int xOffset = mXOffset; |
| 1038 | int yOffset = mYOffset; |
| 1039 | if (mOffsetPositionForStackResize) { |
| 1040 | if (relayout) { |
| 1041 | // Once a relayout is called, reset the offset back to 0 and defer |
| 1042 | // setting it until a new frame with the updated size. This ensures that |
| 1043 | // the WS position is reset (so the stack position is shown) at the same |
| 1044 | // time that the buffer size changes. |
| 1045 | setOffsetPositionForStackResize(false); |
Rob Carr | 698b684 | 2020-03-06 15:33:31 -0800 | [diff] [blame] | 1046 | mSurfaceController.deferTransactionUntil(mWin.getClientViewRootSurface(), |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 1047 | mWin.getFrameNumber()); |
| 1048 | } else { |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 1049 | final ActivityStack stack = mWin.getRootTask(); |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 1050 | mTmpPos.x = 0; |
| 1051 | mTmpPos.y = 0; |
| 1052 | if (stack != null) { |
Evan Rosky | 6ecd67c | 2020-04-14 11:50:43 -0700 | [diff] [blame] | 1053 | stack.getRelativePosition(mTmpPos); |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | xOffset = -mTmpPos.x; |
| 1057 | yOffset = -mTmpPos.y; |
| 1058 | |
| 1059 | // Crop also needs to be extended so the bottom isn't cut off when the WSA |
| 1060 | // position is moved. |
| 1061 | if (clipRect != null) { |
| 1062 | clipRect.right += mTmpPos.x; |
| 1063 | clipRect.bottom += mTmpPos.y; |
| 1064 | } |
| 1065 | } |
| 1066 | } |
Lucas Dupin | 13f4b8a | 2020-02-19 13:41:52 -0800 | [diff] [blame] | 1067 | if (!mIsWallpaper) { |
| 1068 | mSurfaceController.setPositionInTransaction(xOffset, yOffset, recoveringMemory); |
| 1069 | } else { |
| 1070 | setWallpaperPositionAndScale( |
| 1071 | xOffset, yOffset, mWallpaperScale, recoveringMemory); |
| 1072 | } |
Rob Carr | 06be6bb | 2018-02-06 16:26:06 +0000 | [diff] [blame] | 1073 | } |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1074 | } |
| 1075 | |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 1076 | // If we are ending the scaling mode. We switch to SCALING_MODE_FREEZE |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 1077 | // to prevent further updates until buffer latch. |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 1078 | // We also need to freeze the Surface geometry until a buffer |
| 1079 | // comes in at the new size (normally position and crop are unfrozen). |
chaviw | 007340c | 2019-09-04 16:07:37 -0700 | [diff] [blame] | 1080 | // deferTransactionUntil accomplishes this for us. |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 1081 | if (wasForceScaled && !mForceScaleUntilResize) { |
Rob Carr | 698b684 | 2020-03-06 15:33:31 -0800 | [diff] [blame] | 1082 | mSurfaceController.deferTransactionUntil(mWin.getClientViewRootSurface(), |
Vishnu Nair | b040c01 | 2018-09-07 11:38:32 -0700 | [diff] [blame] | 1083 | mWin.getFrameNumber()); |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 1084 | mSurfaceController.forceScaleableInTransaction(false); |
| 1085 | } |
Robert Carr | 4320d33 | 2016-06-10 15:13:32 -0700 | [diff] [blame] | 1086 | |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 1087 | |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 1088 | if (!w.mSeamlesslyRotated) { |
Santiago Etchebehere | a087664 | 2020-03-30 11:28:49 -0700 | [diff] [blame] | 1089 | // Wallpaper is already updated above when calling setWallpaperPositionAndScale so |
| 1090 | // we only need to consider the non-wallpaper case here. |
Lucas Dupin | 13f4b8a | 2020-02-19 13:41:52 -0800 | [diff] [blame] | 1091 | if (!mIsWallpaper) { |
| 1092 | applyCrop(clipRect, recoveringMemory); |
Santiago Etchebehere | a087664 | 2020-03-30 11:28:49 -0700 | [diff] [blame] | 1093 | mSurfaceController.setMatrixInTransaction( |
| 1094 | mDsDx * w.mHScale * mExtraHScale, |
Lucas Dupin | 13f4b8a | 2020-02-19 13:41:52 -0800 | [diff] [blame] | 1095 | mDtDx * w.mVScale * mExtraVScale, |
| 1096 | mDtDy * w.mHScale * mExtraHScale, |
| 1097 | mDsDy * w.mVScale * mExtraVScale, recoveringMemory); |
Lucas Dupin | 13f4b8a | 2020-02-19 13:41:52 -0800 | [diff] [blame] | 1098 | } |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 1099 | } |
Filip Gruszczynski | 63a35e2 | 2015-11-05 15:38:59 -0800 | [diff] [blame] | 1100 | |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1101 | if (mSurfaceResized) { |
Chong Zhang | 5b2f199 | 2015-11-13 15:40:36 -0800 | [diff] [blame] | 1102 | mReportSurfaceResized = true; |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 1103 | mWin.getDisplayContent().pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1104 | } |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 1105 | } |
| 1106 | |
Andrii Kulian | 283acd2 | 2017-08-03 04:03:51 -0700 | [diff] [blame] | 1107 | /** |
| 1108 | * Get rect of the task this window is currently in. If there is no task, rect will be set to |
| 1109 | * empty. |
| 1110 | */ |
| 1111 | void getContainerRect(Rect rect) { |
| 1112 | final Task task = mWin.getTask(); |
| 1113 | if (task != null) { |
| 1114 | task.getDimBounds(rect); |
| 1115 | } else { |
| 1116 | rect.left = rect.top = rect.right = rect.bottom = 0; |
| 1117 | } |
| 1118 | } |
| 1119 | |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 1120 | void prepareSurfaceLocked(final boolean recoveringMemory) { |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 1121 | final WindowState w = mWin; |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 1122 | if (!hasSurface()) { |
Jorim Jaggi | 38d44ec | 2017-06-14 16:04:59 -0700 | [diff] [blame] | 1123 | |
| 1124 | // There is no need to wait for an animation change if our window is gone for layout |
| 1125 | // already as we'll never be visible. |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1126 | if (w.getOrientationChanging() && w.isGoneForLayoutLw()) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 1127 | ProtoLog.v(WM_DEBUG_ORIENTATION, "Orientation change skips hidden %s", w); |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1128 | w.setOrientationChanging(false); |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 1129 | } |
| 1130 | return; |
| 1131 | } |
| 1132 | |
| 1133 | boolean displayed = false; |
| 1134 | |
| 1135 | computeShownFrameLocked(); |
| 1136 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 1137 | setSurfaceBoundariesLocked(recoveringMemory); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1138 | |
Tiger Huang | 50d4546 | 2018-05-25 22:57:52 +0800 | [diff] [blame] | 1139 | if (mIsWallpaper && !w.mWallpaperVisible) { |
Craig Mautner | 0fa77c1 | 2012-06-11 15:57:19 -0700 | [diff] [blame] | 1140 | // Wallpaper is no longer visible and there is no wp target => hide it. |
Filip Gruszczynski | 63a35e2 | 2015-11-05 15:38:59 -0800 | [diff] [blame] | 1141 | hide("prepareSurfaceLocked"); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 1142 | } else if (w.isParentWindowHidden() || !w.isOnScreen()) { |
Filip Gruszczynski | 63a35e2 | 2015-11-05 15:38:59 -0800 | [diff] [blame] | 1143 | hide("prepareSurfaceLocked"); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 1144 | mWallpaperControllerLocked.hideWallpapers(w); |
Craig Mautner | b9836b9 | 2012-06-11 11:40:09 -0700 | [diff] [blame] | 1145 | |
Jorim Jaggi | 38d44ec | 2017-06-14 16:04:59 -0700 | [diff] [blame] | 1146 | // If we are waiting for this window to handle an orientation change. If this window is |
| 1147 | // really hidden (gone for layout), there is no point in still waiting for it. |
| 1148 | // Note that this does introduce a potential glitch if the window becomes unhidden |
| 1149 | // before it has drawn for the new orientation. |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1150 | if (w.getOrientationChanging() && w.isGoneForLayoutLw()) { |
| 1151 | w.setOrientationChanging(false); |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 1152 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
| 1153 | "Orientation change skips hidden %s", w); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1154 | } |
Jorim Jaggi | 35d328a | 2018-08-14 17:00:20 +0200 | [diff] [blame] | 1155 | } else if (mLastAlpha != mShownAlpha |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1156 | || mLastDsDx != mDsDx |
| 1157 | || mLastDtDx != mDtDx |
| 1158 | || mLastDsDy != mDsDy |
| 1159 | || mLastDtDy != mDtDy |
| 1160 | || w.mLastHScale != w.mHScale |
| 1161 | || w.mLastVScale != w.mVScale |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1162 | || mLastHidden) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1163 | displayed = true; |
| 1164 | mLastAlpha = mShownAlpha; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1165 | mLastDsDx = mDsDx; |
| 1166 | mLastDtDx = mDtDx; |
| 1167 | mLastDsDy = mDsDy; |
| 1168 | mLastDtDy = mDtDy; |
| 1169 | w.mLastHScale = w.mHScale; |
| 1170 | w.mLastVScale = w.mVScale; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 1171 | ProtoLog.i(WM_SHOW_TRANSACTIONS, |
| 1172 | "SURFACE controller=%s alpha=%f matrix=[%f*%f,%f*%f][%f*%f,%f*%f]: %s", |
| 1173 | mSurfaceController, mShownAlpha, mDsDx, w.mHScale, mDtDx, w.mVScale, |
| 1174 | mDtDy, w.mHScale, mDsDy, w.mVScale, w); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1175 | |
Santiago Etchebehere | a087664 | 2020-03-30 11:28:49 -0700 | [diff] [blame] | 1176 | boolean prepared = true; |
| 1177 | |
| 1178 | if (mIsWallpaper) { |
| 1179 | setWallpaperPositionAndScale( |
| 1180 | mXOffset, mYOffset, mWallpaperScale, recoveringMemory); |
| 1181 | } else { |
| 1182 | prepared = |
| 1183 | mSurfaceController.prepareToShowInTransaction(mShownAlpha, |
Robert Carr | 0409211 | 2016-06-02 12:56:12 -0700 | [diff] [blame] | 1184 | mDsDx * w.mHScale * mExtraHScale, |
| 1185 | mDtDx * w.mVScale * mExtraVScale, |
Robert Carr | 0edf18f | 2017-02-21 20:01:47 -0800 | [diff] [blame] | 1186 | mDtDy * w.mHScale * mExtraHScale, |
| 1187 | mDsDy * w.mVScale * mExtraVScale, |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1188 | recoveringMemory); |
Santiago Etchebehere | a087664 | 2020-03-30 11:28:49 -0700 | [diff] [blame] | 1189 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1190 | |
Robert Carr | 03206af | 2017-07-10 18:24:21 -0700 | [diff] [blame] | 1191 | if (prepared && mDrawState == HAS_DRAWN) { |
| 1192 | if (mLastHidden) { |
| 1193 | if (showSurfaceRobustlyLocked()) { |
| 1194 | markPreservedSurfaceForDestroy(); |
| 1195 | mAnimator.requestRemovalOfReplacedWindows(w); |
| 1196 | mLastHidden = false; |
| 1197 | if (mIsWallpaper) { |
| 1198 | w.dispatchWallpaperVisibility(true); |
| 1199 | } |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 1200 | final DisplayContent displayContent = w.getDisplayContent(); |
| 1201 | if (!displayContent.getLastHasContent()) { |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 1202 | // This draw means the difference between unique content and mirroring. |
| 1203 | // Run another pass through performLayout to set mHasContent in the |
| 1204 | // LogicalDisplay. |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 1205 | displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM; |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 1206 | if (DEBUG_LAYOUT_REPEATS) { |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 1207 | mService.mWindowPlacerLocked.debugLayoutRepeats( |
| 1208 | "showSurfaceRobustlyLocked " + w, |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 1209 | displayContent.pendingLayoutChanges); |
Jorim Jaggi | f129289 | 2018-09-10 11:58:13 +0200 | [diff] [blame] | 1210 | } |
Tiger Huang | 50d4546 | 2018-05-25 22:57:52 +0800 | [diff] [blame] | 1211 | } |
Robert Carr | 03206af | 2017-07-10 18:24:21 -0700 | [diff] [blame] | 1212 | } else { |
| 1213 | w.setOrientationChanging(false); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1214 | } |
Robert Carr | 03206af | 2017-07-10 18:24:21 -0700 | [diff] [blame] | 1215 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1216 | } |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 1217 | if (hasSurface()) { |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1218 | w.mToken.hasVisible = true; |
| 1219 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1220 | } else { |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 1221 | if (DEBUG_ANIM && mWin.isAnimating(TRANSITION | PARENTS)) { |
Chong Zhang | e05db74 | 2016-02-16 16:58:37 -0800 | [diff] [blame] | 1222 | Slog.v(TAG, "prepareSurface: No changes in animation for " + this); |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 1223 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1224 | displayed = true; |
| 1225 | } |
| 1226 | |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1227 | if (w.getOrientationChanging()) { |
Jorim Jaggi | 38d44ec | 2017-06-14 16:04:59 -0700 | [diff] [blame] | 1228 | if (!w.isDrawnLw()) { |
| 1229 | mAnimator.mBulkUpdateParams &= ~SET_ORIENTATION_CHANGE_COMPLETE; |
| 1230 | mAnimator.mLastWindowFreezeSource = w; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 1231 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
| 1232 | "Orientation continue waiting for draw in %s", w); |
Jorim Jaggi | 38d44ec | 2017-06-14 16:04:59 -0700 | [diff] [blame] | 1233 | } else { |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1234 | w.setOrientationChanging(false); |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 1235 | ProtoLog.v(WM_DEBUG_ORIENTATION, "Orientation change complete in %s", w); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1236 | } |
Jorim Jaggi | 38d44ec | 2017-06-14 16:04:59 -0700 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | if (displayed) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1240 | w.mToken.hasVisible = true; |
| 1241 | } |
| 1242 | } |
| 1243 | |
Craig Mautner | ef65501 | 2013-01-03 11:20:24 -0800 | [diff] [blame] | 1244 | void setTransparentRegionHintLocked(final Region region) { |
Wale Ogunwale | f9e0978 | 2015-11-09 12:42:37 -0800 | [diff] [blame] | 1245 | if (mSurfaceController == null) { |
| 1246 | Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true"); |
| 1247 | return; |
| 1248 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1249 | mSurfaceController.setTransparentRegionHint(region); |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
Lucas Dupin | 13f4b8a | 2020-02-19 13:41:52 -0800 | [diff] [blame] | 1252 | boolean setWallpaperOffset(int dx, int dy, float scale) { |
| 1253 | if (mXOffset == dx && mYOffset == dy && Float.compare(mWallpaperScale, scale) == 0) { |
Robert Carr | 217e7cc | 2018-01-31 18:08:39 -0800 | [diff] [blame] | 1254 | return false; |
| 1255 | } |
| 1256 | mXOffset = dx; |
| 1257 | mYOffset = dy; |
Lucas Dupin | 13f4b8a | 2020-02-19 13:41:52 -0800 | [diff] [blame] | 1258 | mWallpaperScale = scale; |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1259 | |
| 1260 | try { |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 1261 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setWallpaperOffset"); |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 1262 | mService.openSurfaceTransaction(); |
Lucas Dupin | 13f4b8a | 2020-02-19 13:41:52 -0800 | [diff] [blame] | 1263 | setWallpaperPositionAndScale(dx, dy, scale, false); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1264 | } catch (RuntimeException e) { |
| 1265 | Slog.w(TAG, "Error positioning surface of " + mWin |
Robert Carr | 217e7cc | 2018-01-31 18:08:39 -0800 | [diff] [blame] | 1266 | + " pos=(" + dx + "," + dy + ")", e); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1267 | } finally { |
Adrian Roos | 111aff9 | 2017-09-27 18:11:46 +0200 | [diff] [blame] | 1268 | mService.closeSurfaceTransaction("setWallpaperOffset"); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1269 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 1270 | "<<< CLOSE TRANSACTION setWallpaperOffset"); |
Robert Carr | 217e7cc | 2018-01-31 18:08:39 -0800 | [diff] [blame] | 1271 | return true; |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 1272 | } |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 1273 | } |
| 1274 | |
Lucas Dupin | 13f4b8a | 2020-02-19 13:41:52 -0800 | [diff] [blame] | 1275 | private void setWallpaperPositionAndScale(int dx, int dy, float scale, |
| 1276 | boolean recoveringMemory) { |
| 1277 | DisplayInfo displayInfo = mWin.getDisplayInfo(); |
| 1278 | Matrix matrix = mWin.mTmpMatrix; |
| 1279 | matrix.setTranslate(dx, dy); |
| 1280 | matrix.postScale(scale, scale, displayInfo.logicalWidth / 2f, |
| 1281 | displayInfo.logicalHeight / 2f); |
| 1282 | matrix.getValues(mWin.mTmpMatrixArray); |
| 1283 | matrix.reset(); |
| 1284 | |
| 1285 | mSurfaceController.setPositionInTransaction(mWin.mTmpMatrixArray[MTRANS_X], |
| 1286 | mWin.mTmpMatrixArray[MTRANS_Y], recoveringMemory); |
| 1287 | mSurfaceController.setMatrixInTransaction( |
| 1288 | mDsDx * mWin.mTmpMatrixArray[MSCALE_X] * mWin.mHScale * mExtraHScale, |
| 1289 | mDtDx * mWin.mTmpMatrixArray[MSKEW_Y] * mWin.mVScale * mExtraVScale, |
| 1290 | mDtDy * mWin.mTmpMatrixArray[MSKEW_X] * mWin.mHScale * mExtraHScale, |
| 1291 | mDsDy * mWin.mTmpMatrixArray[MSCALE_Y] * mWin.mVScale * mExtraVScale, |
| 1292 | recoveringMemory); |
| 1293 | applyCrop(null, recoveringMemory); |
| 1294 | } |
| 1295 | |
John Reck | 80181b9 | 2015-05-19 11:09:32 -0700 | [diff] [blame] | 1296 | /** |
| 1297 | * Try to change the pixel format without recreating the surface. This |
| 1298 | * will be common in the case of changing from PixelFormat.OPAQUE to |
| 1299 | * PixelFormat.TRANSLUCENT in the hardware-accelerated case as both |
| 1300 | * requested formats resolve to the same underlying SurfaceControl format |
| 1301 | * @return True if format was succesfully changed, false otherwise |
| 1302 | */ |
| 1303 | boolean tryChangeFormatInPlaceLocked() { |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1304 | if (mSurfaceController == null) { |
John Reck | 80181b9 | 2015-05-19 11:09:32 -0700 | [diff] [blame] | 1305 | return false; |
| 1306 | } |
| 1307 | final LayoutParams attrs = mWin.getAttrs(); |
Wale Ogunwale | e7bf46b | 2015-09-30 09:19:28 -0700 | [diff] [blame] | 1308 | final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0; |
John Reck | 80181b9 | 2015-05-19 11:09:32 -0700 | [diff] [blame] | 1309 | final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format; |
| 1310 | if (format == mSurfaceFormat) { |
| 1311 | setOpaqueLocked(!PixelFormat.formatHasAlpha(attrs.format)); |
| 1312 | return true; |
| 1313 | } |
| 1314 | return false; |
| 1315 | } |
| 1316 | |
Craig Mautner | 6f61204 | 2014-09-07 13:13:23 -0700 | [diff] [blame] | 1317 | void setOpaqueLocked(boolean isOpaque) { |
Wale Ogunwale | f9e0978 | 2015-11-09 12:42:37 -0800 | [diff] [blame] | 1318 | if (mSurfaceController == null) { |
| 1319 | return; |
| 1320 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1321 | mSurfaceController.setOpaque(isOpaque); |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 1322 | } |
| 1323 | |
Wale Ogunwale | f5ad42f | 2015-06-12 13:59:03 -0700 | [diff] [blame] | 1324 | void setSecureLocked(boolean isSecure) { |
Wale Ogunwale | f9e0978 | 2015-11-09 12:42:37 -0800 | [diff] [blame] | 1325 | if (mSurfaceController == null) { |
| 1326 | return; |
| 1327 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1328 | mSurfaceController.setSecure(isSecure); |
Wale Ogunwale | f5ad42f | 2015-06-12 13:59:03 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
Peiyong Lin | 7504538 | 2019-03-04 19:22:33 -0800 | [diff] [blame] | 1331 | void setColorSpaceAgnosticLocked(boolean agnostic) { |
| 1332 | if (mSurfaceController == null) { |
| 1333 | return; |
| 1334 | } |
| 1335 | mSurfaceController.setColorSpaceAgnostic(agnostic); |
| 1336 | } |
| 1337 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1338 | /** |
| 1339 | * Have the surface flinger show a surface, robustly dealing with |
| 1340 | * error conditions. In particular, if there is not enough memory |
| 1341 | * to show the surface, then we will try to get rid of other surfaces |
| 1342 | * in order to succeed. |
| 1343 | * |
| 1344 | * @return Returns true if the surface was successfully shown. |
| 1345 | */ |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 1346 | private boolean showSurfaceRobustlyLocked() { |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 1347 | if (mWin.getWindowConfiguration().windowsAreScaleable()) { |
Robert Carr | 1b5ea72 | 2016-04-20 13:23:28 -0700 | [diff] [blame] | 1348 | mSurfaceController.forceScaleableInTransaction(true); |
| 1349 | } |
| 1350 | |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1351 | boolean shown = mSurfaceController.showRobustlyInTransaction(); |
| 1352 | if (!shown) |
| 1353 | return false; |
| 1354 | |
Robert Carr | 849d293 | 2018-05-01 12:14:48 -0700 | [diff] [blame] | 1355 | // If we had a preserved surface it's no longer needed, and it may be harmful |
| 1356 | // if we are transparent. |
| 1357 | if (mPendingDestroySurface != null && mDestroyPreservedSurfaceUponRedraw) { |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 1358 | final SurfaceControl pendingSurfaceControl = mPendingDestroySurface.mSurfaceControl; |
Vishnu Nair | 8cb00ae | 2019-08-02 15:20:29 -0700 | [diff] [blame] | 1359 | mPostDrawTransaction.reparent(pendingSurfaceControl, null); |
Rob Carr | 698b684 | 2020-03-06 15:33:31 -0800 | [diff] [blame] | 1360 | mPostDrawTransaction.reparentChildren( |
| 1361 | mPendingDestroySurface.getClientViewRootSurface(), |
| 1362 | mSurfaceController.mSurfaceControl); |
Robert Carr | 849d293 | 2018-05-01 12:14:48 -0700 | [diff] [blame] | 1363 | } |
| 1364 | |
Vishnu Nair | 3b037f7 | 2019-07-22 12:55:58 -0700 | [diff] [blame] | 1365 | SurfaceControl.mergeToGlobalTransaction(mPostDrawTransaction); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1366 | return true; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1367 | } |
| 1368 | |
| 1369 | void applyEnterAnimationLocked() { |
Robert Carr | b439a63 | 2016-04-07 22:52:10 -0700 | [diff] [blame] | 1370 | // If we are the new part of a window replacement transition and we have requested |
| 1371 | // not to animate, we instead want to make it seamless, so we don't want to apply |
| 1372 | // an enter transition. |
| 1373 | if (mWin.mSkipEnterAnimationForSeamlessReplacement) { |
| 1374 | return; |
| 1375 | } |
lumark | ce596d3 | 2019-06-12 16:58:35 +0800 | [diff] [blame] | 1376 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1377 | final int transit; |
| 1378 | if (mEnterAnimationPending) { |
| 1379 | mEnterAnimationPending = false; |
| 1380 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 1381 | } else { |
| 1382 | transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 1383 | } |
lumark | 2726eb6 | 2019-06-19 21:25:54 +0800 | [diff] [blame] | 1384 | |
| 1385 | // We don't apply animation for application main window here since this window type |
| 1386 | // should be controlled by AppWindowToken in general. |
| 1387 | if (mAttrType != TYPE_BASE_APPLICATION) { |
| 1388 | applyAnimationLocked(transit, true); |
| 1389 | } |
| 1390 | |
Rhed Jao | 02655dc | 2018-10-30 20:44:52 +0800 | [diff] [blame] | 1391 | if (mService.mAccessibilityController != null) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1392 | mService.mAccessibilityController.onWindowTransitionLocked(mWin, transit); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 1393 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | /** |
| 1397 | * Choose the correct animation and set it to the passed WindowState. |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1398 | * @param transit If AppTransition.TRANSIT_PREVIEW_DONE and the app window has been drawn |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1399 | * then the animation will be app_starting_exit. Any other value loads the animation from |
| 1400 | * the switch statement below. |
| 1401 | * @param isEntrance The animation type the last time this was called. Used to keep from |
| 1402 | * loading the same animation twice. |
| 1403 | * @return true if an animation has been loaded. |
| 1404 | */ |
| 1405 | boolean applyAnimationLocked(int transit, boolean isEntrance) { |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 1406 | if (mWin.isAnimating() && mAnimationIsEntrance == isEntrance) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1407 | // If we are trying to apply an animation, but already running |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 1408 | // an animation of the same type, then just leave that one alone. |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1409 | return true; |
| 1410 | } |
| 1411 | |
Taran Singh | f69425e | 2020-04-01 16:57:50 -0700 | [diff] [blame] | 1412 | final boolean isImeWindow = mWin.mAttrs.type == TYPE_INPUT_METHOD; |
| 1413 | if (isEntrance && isImeWindow) { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1414 | mWin.getDisplayContent().adjustForImeIfNeeded(); |
| 1415 | mWin.setDisplayLayoutNeeded(); |
| 1416 | mService.mWindowPlacerLocked.requestTraversal(); |
| 1417 | } |
| 1418 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1419 | // Only apply an animation if the display isn't frozen. If it is |
| 1420 | // frozen, there is no reason to animate and it can cause strange |
| 1421 | // artifacts when we unfreeze the display if some different animation |
| 1422 | // is running. |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1423 | if (mWin.mToken.okToAnimate()) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1424 | int anim = mWin.getDisplayContent().getDisplayPolicy().selectAnimation(mWin, transit); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1425 | int attr = -1; |
| 1426 | Animation a = null; |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1427 | if (anim != DisplayPolicy.ANIMATION_STYLEABLE) { |
| 1428 | if (anim != DisplayPolicy.ANIMATION_NONE) { |
| 1429 | Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "WSA#loadAnimation"); |
| 1430 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 1431 | Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); |
| 1432 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1433 | } else { |
| 1434 | switch (transit) { |
| 1435 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 1436 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 1437 | break; |
| 1438 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 1439 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 1440 | break; |
| 1441 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 1442 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 1443 | break; |
| 1444 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 1445 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 1446 | break; |
| 1447 | } |
| 1448 | if (attr >= 0) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1449 | a = mWin.getDisplayContent().mAppTransition.loadAnimationAttr( |
| 1450 | mWin.mAttrs, attr, TRANSIT_NONE); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1451 | } |
| 1452 | } |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 1453 | if (DEBUG_ANIM) Slog.v(TAG, |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1454 | "applyAnimation: win=" + this |
| 1455 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 1456 | + " a=" + a |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 1457 | + " transit=" + transit |
lumark | ce596d3 | 2019-06-12 16:58:35 +0800 | [diff] [blame] | 1458 | + " type=" + mAttrType |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 1459 | + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3)); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1460 | if (a != null) { |
Filip Gruszczynski | 198dcbf | 2016-01-18 10:02:00 -0800 | [diff] [blame] | 1461 | if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1462 | Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "WSA#startAnimation"); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1463 | mWin.startAnimation(a); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1464 | Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1465 | mAnimationIsEntrance = isEntrance; |
| 1466 | } |
Taran Singh | f69425e | 2020-04-01 16:57:50 -0700 | [diff] [blame] | 1467 | } else if (!isImeWindow) { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1468 | mWin.cancelAnimation(); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1469 | } |
Chong Zhang | 8784be6 | 2016-06-28 15:25:07 -0700 | [diff] [blame] | 1470 | |
Taran Singh | f69425e | 2020-04-01 16:57:50 -0700 | [diff] [blame] | 1471 | if (!isEntrance && isImeWindow) { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 1472 | mWin.getDisplayContent().adjustForImeIfNeeded(); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1473 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1474 | |
lumark | 5341d1c | 2019-12-14 01:54:02 +0800 | [diff] [blame] | 1475 | return mWin.isAnimating(PARENTS); |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 1476 | } |
| 1477 | |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 1478 | void dumpDebug(ProtoOutputStream proto, long fieldId) { |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 1479 | final long token = proto.start(fieldId); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 1480 | mLastClipRect.dumpDebug(proto, LAST_CLIP_RECT); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 1481 | if (mSurfaceController != null) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 1482 | mSurfaceController.dumpDebug(proto, SURFACE); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 1483 | } |
Vishnu Nair | 1d0fa07 | 2018-01-04 07:53:00 -0800 | [diff] [blame] | 1484 | proto.write(DRAW_STATE, mDrawState); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 1485 | mSystemDecorRect.dumpDebug(proto, SYSTEM_DECOR_RECT); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 1486 | proto.end(token); |
| 1487 | } |
| 1488 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1489 | public void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1490 | if (mAnimationIsEntrance) { |
| 1491 | pw.print(prefix); pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1492 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1493 | if (mSurfaceController != null) { |
| 1494 | mSurfaceController.dump(pw, prefix, dumpAll); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1495 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1496 | if (dumpAll) { |
| 1497 | pw.print(prefix); pw.print("mDrawState="); pw.print(drawStateToString()); |
| 1498 | pw.print(prefix); pw.print(" mLastHidden="); pw.println(mLastHidden); |
mincheli | a873309 | 2020-04-16 14:52:27 +0800 | [diff] [blame] | 1499 | pw.print(prefix); pw.print("mEnterAnimationPending=" + mEnterAnimationPending); |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 1500 | pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw); |
Wale Ogunwale | 6bab4cf | 2016-04-07 12:23:08 -0700 | [diff] [blame] | 1501 | pw.print(" mLastClipRect="); mLastClipRect.printShortString(pw); |
| 1502 | |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 1503 | if (!mLastFinalClipRect.isEmpty()) { |
| 1504 | pw.print(" mLastFinalClipRect="); mLastFinalClipRect.printShortString(pw); |
| 1505 | } |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 1506 | pw.println(); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1507 | } |
| 1508 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1509 | if (mPendingDestroySurface != null) { |
| 1510 | pw.print(prefix); pw.print("mPendingDestroySurface="); |
| 1511 | pw.println(mPendingDestroySurface); |
| 1512 | } |
| 1513 | if (mSurfaceResized || mSurfaceDestroyDeferred) { |
| 1514 | pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized); |
| 1515 | pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred); |
| 1516 | } |
| 1517 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 1518 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 1519 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 1520 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 1521 | } |
| 1522 | if (mHaveMatrix || mWin.mGlobalScale != 1) { |
| 1523 | pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale); |
| 1524 | pw.print(" mDsDx="); pw.print(mDsDx); |
| 1525 | pw.print(" mDtDx="); pw.print(mDtDx); |
Robert Carr | 0edf18f | 2017-02-21 20:01:47 -0800 | [diff] [blame] | 1526 | pw.print(" mDtDy="); pw.print(mDtDy); |
| 1527 | pw.print(" mDsDy="); pw.println(mDsDy); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1528 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1529 | } |
| 1530 | |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1531 | @Override |
| 1532 | public String toString() { |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 1533 | StringBuffer sb = new StringBuffer("WindowStateAnimator{"); |
| 1534 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 1535 | sb.append(' '); |
| 1536 | sb.append(mWin.mAttrs.getTitle()); |
| 1537 | sb.append('}'); |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1538 | return sb.toString(); |
| 1539 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1540 | |
| 1541 | void reclaimSomeSurfaceMemory(String operation, boolean secure) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1542 | mService.mRoot.reclaimSomeSurfaceMemory(this, operation, secure); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | boolean getShown() { |
| 1546 | if (mSurfaceController != null) { |
| 1547 | return mSurfaceController.getShown(); |
| 1548 | } |
| 1549 | return false; |
| 1550 | } |
| 1551 | |
| 1552 | void destroySurface() { |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 1553 | try { |
| 1554 | if (mSurfaceController != null) { |
Robert Carr | a882886 | 2018-02-05 16:17:36 -0800 | [diff] [blame] | 1555 | mSurfaceController.destroyNotInTransaction(); |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 1556 | } |
| 1557 | } catch (RuntimeException e) { |
| 1558 | Slog.w(TAG, "Exception thrown when destroying surface " + this |
| 1559 | + " surface " + mSurfaceController + " session " + mSession + ": " + e); |
| 1560 | } finally { |
| 1561 | mWin.setHasSurface(false); |
| 1562 | mSurfaceController = null; |
| 1563 | mDrawState = NO_SURFACE; |
| 1564 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1565 | } |
Filip Gruszczynski | f52dd20 | 2015-11-15 20:36:38 -0800 | [diff] [blame] | 1566 | |
Robert Carr | 8f0a3ad | 2017-02-15 19:30:28 -0800 | [diff] [blame] | 1567 | /** The force-scaled state for a given window can persist past |
| 1568 | * the state for it's stack as the windows complete resizing |
| 1569 | * independently of one another. |
| 1570 | */ |
| 1571 | boolean isForceScaled() { |
| 1572 | final Task task = mWin.getTask(); |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 1573 | if (task != null && task.getStack().isForceScaled()) { |
Robert Carr | 8f0a3ad | 2017-02-15 19:30:28 -0800 | [diff] [blame] | 1574 | return true; |
| 1575 | } |
| 1576 | return mForceScaleUntilResize; |
| 1577 | } |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 1578 | |
| 1579 | void detachChildren() { |
Jorim Jaggi | 35e049a | 2019-07-16 15:03:14 +0200 | [diff] [blame] | 1580 | |
| 1581 | // Do not detach children of starting windows, as their lifecycle is well under control and |
| 1582 | // it may lead to issues in case we relaunch when we just added the starting window. |
| 1583 | if (mWin.mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 1584 | return; |
| 1585 | } |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 1586 | if (mSurfaceController != null) { |
| 1587 | mSurfaceController.detachChildren(); |
| 1588 | } |
Robert Carr | 7b3d11d | 2018-03-15 14:34:45 -0700 | [diff] [blame] | 1589 | mChildrenDetached = true; |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 1590 | } |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1591 | |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 1592 | void setOffsetPositionForStackResize(boolean offsetPositionForStackResize) { |
| 1593 | mOffsetPositionForStackResize = offsetPositionForStackResize; |
| 1594 | } |
Robert Carr | 2e20bcd | 2020-01-22 13:32:38 -0800 | [diff] [blame] | 1595 | |
Rob Carr | 698b684 | 2020-03-06 15:33:31 -0800 | [diff] [blame] | 1596 | SurfaceControl getClientViewRootSurface() { |
Robert Carr | 2e20bcd | 2020-01-22 13:32:38 -0800 | [diff] [blame] | 1597 | if (!hasSurface()) { |
| 1598 | return null; |
| 1599 | } |
Rob Carr | 698b684 | 2020-03-06 15:33:31 -0800 | [diff] [blame] | 1600 | return mSurfaceController.getClientViewRootSurface(); |
Robert Carr | 2e20bcd | 2020-01-22 13:32:38 -0800 | [diff] [blame] | 1601 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1602 | } |