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