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