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 | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 26 | import static com.android.server.wm.AppWindowAnimator.sDummyAnimation; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 27 | import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 28 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
| 29 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS; |
| 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; |
| 35 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER; |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 36 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_CROP; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 37 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS; |
| 38 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC; |
| 39 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS; |
| 40 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 41 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 42 | import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER; |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 43 | import static com.android.server.wm.WindowManagerService.localLOGV; |
Filip Gruszczynski | 198dcbf | 2016-01-18 10:02:00 -0800 | [diff] [blame] | 44 | import static com.android.server.wm.WindowManagerService.logWithStack; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 45 | import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE; |
| 46 | import static com.android.server.wm.WindowSurfacePlacer.SET_TURN_ON_SCREEN; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 47 | import static com.android.server.wm.proto.WindowStateAnimatorProto.LAST_CLIP_RECT; |
| 48 | import static com.android.server.wm.proto.WindowStateAnimatorProto.SURFACE; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 49 | |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 50 | import android.app.WindowConfiguration; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 51 | import android.content.Context; |
| 52 | import android.graphics.Matrix; |
| 53 | import android.graphics.PixelFormat; |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 54 | import android.graphics.Point; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 55 | import android.graphics.Rect; |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 56 | import android.graphics.RectF; |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 57 | import android.graphics.Region; |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 58 | import android.os.Debug; |
Chong Zhang | 8784be6 | 2016-06-28 15:25:07 -0700 | [diff] [blame] | 59 | import android.os.Trace; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 60 | import android.util.Slog; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 61 | import android.util.proto.ProtoOutputStream; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 62 | import android.view.DisplayInfo; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 63 | import android.view.Surface.OutOfResourcesException; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 64 | import android.view.SurfaceControl; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 65 | import android.view.WindowManager; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 66 | import android.view.WindowManager.LayoutParams; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 67 | import android.view.animation.Animation; |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 68 | import android.view.animation.AnimationSet; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 69 | import android.view.animation.AnimationUtils; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 70 | import android.view.animation.Transformation; |
| 71 | |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 72 | import com.android.server.policy.WindowManagerPolicy; |
| 73 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 74 | import java.io.PrintWriter; |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 75 | import java.io.FileDescriptor; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 76 | |
| 77 | /** |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 78 | * Keep track of animations and surface operations for a single WindowState. |
| 79 | **/ |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 80 | class WindowStateAnimator { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 81 | static final String TAG = TAG_WITH_CLASS_NAME ? "WindowStateAnimator" : TAG_WM; |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 82 | static final int WINDOW_FREEZE_LAYER = TYPE_LAYER_MULTIPLIER * 200; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 83 | |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 84 | /** |
| 85 | * Mode how the window gets clipped by the stack bounds during an animation: The clipping should |
| 86 | * be applied after applying the animation transformation, i.e. the stack bounds don't move |
| 87 | * during the animation. |
| 88 | */ |
| 89 | static final int STACK_CLIP_AFTER_ANIM = 0; |
| 90 | |
| 91 | /** |
| 92 | * Mode how the window gets clipped by the stack bounds: The clipping should be applied before |
| 93 | * applying the animation transformation, i.e. the stack bounds move with the window. |
| 94 | */ |
| 95 | static final int STACK_CLIP_BEFORE_ANIM = 1; |
| 96 | |
| 97 | /** |
| 98 | * Mode how window gets clipped by the stack bounds during an animation: Don't clip the window |
| 99 | * by the stack bounds. |
| 100 | */ |
| 101 | static final int STACK_CLIP_NONE = 2; |
| 102 | |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 103 | // Unchanging local convenience fields. |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 104 | final WindowManagerService mService; |
| 105 | final WindowState mWin; |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 106 | private final WindowStateAnimator mParentWinAnimator; |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 107 | final WindowAnimator mAnimator; |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 108 | AppWindowAnimator mAppAnimator; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 109 | final Session mSession; |
| 110 | final WindowManagerPolicy mPolicy; |
| 111 | final Context mContext; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 112 | final boolean mIsWallpaper; |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 113 | private final WallpaperController mWallpaperControllerLocked; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 114 | |
| 115 | // Currently running animation. |
| 116 | boolean mAnimating; |
| 117 | boolean mLocalAnimating; |
| 118 | Animation mAnimation; |
| 119 | boolean mAnimationIsEntrance; |
| 120 | boolean mHasTransformation; |
| 121 | boolean mHasLocalTransformation; |
| 122 | final Transformation mTransformation = new Transformation(); |
| 123 | boolean mWasAnimating; // Were we animating going into the most recent animation step? |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 124 | int mAnimLayer; |
| 125 | int mLastLayer; |
Jorim Jaggi | 44f60cc | 2014-11-07 20:33:51 +0100 | [diff] [blame] | 126 | long mAnimationStartTime; |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 127 | long mLastAnimationTime; |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 128 | int mStackClip = STACK_CLIP_BEFORE_ANIM; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 129 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 130 | /** |
| 131 | * Set when we have changed the size of the surface, to know that |
| 132 | * we must tell them application to resize (and thus redraw itself). |
| 133 | */ |
| 134 | boolean mSurfaceResized; |
Chong Zhang | 5b2f199 | 2015-11-13 15:40:36 -0800 | [diff] [blame] | 135 | /** |
| 136 | * Whether we should inform the client on next relayoutWindow that |
| 137 | * the surface has been resized since last time. |
| 138 | */ |
| 139 | boolean mReportSurfaceResized; |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 140 | WindowSurfaceController mSurfaceController; |
Filip Gruszczynski | 10a80e0 | 2015-11-06 09:21:17 -0800 | [diff] [blame] | 141 | private WindowSurfaceController mPendingDestroySurface; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 142 | |
| 143 | /** |
| 144 | * Set if the client has asked that the destroy of its surface be delayed |
| 145 | * until it explicitly says it is okay. |
| 146 | */ |
| 147 | boolean mSurfaceDestroyDeferred; |
| 148 | |
Filip Gruszczynski | 10a80e0 | 2015-11-06 09:21:17 -0800 | [diff] [blame] | 149 | private boolean mDestroyPreservedSurfaceUponRedraw; |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 150 | float mShownAlpha = 0; |
| 151 | float mAlpha = 0; |
| 152 | float mLastAlpha = 0; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 153 | |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 154 | boolean mHasClipRect; |
| 155 | Rect mClipRect = new Rect(); |
| 156 | Rect mTmpClipRect = new Rect(); |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 157 | Rect mTmpFinalClipRect = new Rect(); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 158 | Rect mLastClipRect = new Rect(); |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 159 | Rect mLastFinalClipRect = new Rect(); |
Filip Gruszczynski | 4b8eea7 | 2015-09-14 18:16:19 -0700 | [diff] [blame] | 160 | Rect mTmpStackBounds = new Rect(); |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 161 | private Rect mTmpAnimatingBounds = new Rect(); |
| 162 | private Rect mTmpSourceBounds = new Rect(); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 163 | |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 164 | /** |
| 165 | * This is rectangle of the window's surface that is not covered by |
| 166 | * system decorations. |
| 167 | */ |
| 168 | private final Rect mSystemDecorRect = new Rect(); |
| 169 | private final Rect mLastSystemDecorRect = new Rect(); |
| 170 | |
Filip Gruszczynski | f52dd20 | 2015-11-15 20:36:38 -0800 | [diff] [blame] | 171 | // Used to save animation distances between the time they are calculated and when they are used. |
| 172 | private int mAnimDx; |
| 173 | private int mAnimDy; |
Jorim Jaggi | c5af4f8 | 2015-07-01 17:16:27 -0700 | [diff] [blame] | 174 | |
| 175 | /** Is the next animation to be started a window move animation? */ |
Filip Gruszczynski | f52dd20 | 2015-11-15 20:36:38 -0800 | [diff] [blame] | 176 | private boolean mAnimateMove = false; |
Jorim Jaggi | c5af4f8 | 2015-07-01 17:16:27 -0700 | [diff] [blame] | 177 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 178 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
Robert Carr | 0edf18f | 2017-02-21 20:01:47 -0800 | [diff] [blame] | 179 | private float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 180 | |
| 181 | boolean mHaveMatrix; |
| 182 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 183 | // Set to true if, when the window gets displayed, it should perform |
| 184 | // an enter animation. |
| 185 | boolean mEnterAnimationPending; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 186 | |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 187 | /** Used to indicate that this window is undergoing an enter animation. Used for system |
| 188 | * windows to make the callback to View.dispatchOnWindowShownCallback(). Set when the |
| 189 | * window is first added or shown, cleared when the callback has been made. */ |
| 190 | boolean mEnteringAnimation; |
| 191 | |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 192 | private boolean mAnimationStartDelayed; |
| 193 | |
John Reck | 80181b9 | 2015-05-19 11:09:32 -0700 | [diff] [blame] | 194 | /** The pixel format of the underlying SurfaceControl */ |
| 195 | int mSurfaceFormat; |
| 196 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 197 | /** This is set when there is no Surface */ |
| 198 | static final int NO_SURFACE = 0; |
| 199 | /** This is set after the Surface has been created but before the window has been drawn. During |
| 200 | * this time the surface is hidden. */ |
| 201 | static final int DRAW_PENDING = 1; |
| 202 | /** This is set after the window has finished drawing for the first time but before its surface |
| 203 | * is shown. The surface will be displayed when the next layout is run. */ |
| 204 | static final int COMMIT_DRAW_PENDING = 2; |
| 205 | /** This is set during the time after the window's drawing has been committed, and before its |
| 206 | * surface is actually shown. It is used to delay showing the surface until all windows in a |
| 207 | * token are ready to be shown. */ |
| 208 | static final int READY_TO_SHOW = 3; |
| 209 | /** Set when the window has been shown in the screen the first time. */ |
| 210 | static final int HAS_DRAWN = 4; |
Adrian Roos | 3eeb4e6 | 2014-05-19 12:43:26 +0200 | [diff] [blame] | 211 | |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 212 | String drawStateToString() { |
| 213 | switch (mDrawState) { |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 214 | case NO_SURFACE: return "NO_SURFACE"; |
| 215 | case DRAW_PENDING: return "DRAW_PENDING"; |
| 216 | case COMMIT_DRAW_PENDING: return "COMMIT_DRAW_PENDING"; |
| 217 | case READY_TO_SHOW: return "READY_TO_SHOW"; |
| 218 | case HAS_DRAWN: return "HAS_DRAWN"; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 219 | default: return Integer.toString(mDrawState); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 220 | } |
| 221 | } |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 222 | int mDrawState; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 223 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 224 | /** Was this window last hidden? */ |
| 225 | boolean mLastHidden; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 226 | |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 227 | int mAttrType; |
| 228 | |
Robert Carr | 679c807 | 2016-04-07 15:51:48 -0700 | [diff] [blame] | 229 | static final long PENDING_TRANSACTION_FINISH_WAIT_TIME = 100; |
Robert Carr | 679c807 | 2016-04-07 15:51:48 -0700 | [diff] [blame] | 230 | |
Robert Carr | c729460 | 2016-05-13 11:32:05 -0700 | [diff] [blame] | 231 | boolean mForceScaleUntilResize; |
| 232 | |
Robert Carr | 0409211 | 2016-06-02 12:56:12 -0700 | [diff] [blame] | 233 | // WindowState.mHScale and WindowState.mVScale contain the |
| 234 | // scale according to client specified layout parameters (e.g. |
| 235 | // one layout size, with another surface size, creates such scaling). |
| 236 | // Here we track an additional scaling factor used to follow stack |
| 237 | // scaling (as in the case of the Pinned stack animation). |
| 238 | float mExtraHScale = (float) 1.0; |
| 239 | float mExtraVScale = (float) 1.0; |
| 240 | |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 241 | private final Rect mTmpSize = new Rect(); |
| 242 | |
Craig Mautner | c431e89 | 2015-02-11 13:14:26 -0800 | [diff] [blame] | 243 | WindowStateAnimator(final WindowState win) { |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 244 | final WindowManagerService service = win.mService; |
| 245 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 246 | mService = service; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 247 | mAnimator = service.mAnimator; |
| 248 | mPolicy = service.mPolicy; |
| 249 | mContext = service.mContext; |
Craig Mautner | d3849f5 | 2014-03-27 13:19:29 -0700 | [diff] [blame] | 250 | final DisplayContent displayContent = win.getDisplayContent(); |
| 251 | if (displayContent != null) { |
| 252 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
Filip Gruszczynski | f52dd20 | 2015-11-15 20:36:38 -0800 | [diff] [blame] | 253 | mAnimDx = displayInfo.appWidth; |
| 254 | mAnimDy = displayInfo.appHeight; |
Craig Mautner | d3849f5 | 2014-03-27 13:19:29 -0700 | [diff] [blame] | 255 | } else { |
| 256 | Slog.w(TAG, "WindowStateAnimator ctor: Display has been removed"); |
| 257 | // This is checked on return and dealt with. |
| 258 | } |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 259 | |
| 260 | mWin = win; |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 261 | mParentWinAnimator = !win.isChildWindow() ? null : win.getParentWindow().mWinAnimator; |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 262 | mAppAnimator = win.mAppToken == null ? null : win.mAppToken.mAppAnimator; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 263 | mSession = win.mSession; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 264 | mAttrType = win.mAttrs.type; |
| 265 | mIsWallpaper = win.mIsWallpaper; |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 266 | mWallpaperControllerLocked = mService.mRoot.mWallpaperController; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 269 | public void setAnimation(Animation anim, long startTime, int stackClip) { |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 270 | if (localLOGV) Slog.v(TAG, "Setting animation in " + this + ": " + anim); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 271 | mAnimating = false; |
| 272 | mLocalAnimating = false; |
| 273 | mAnimation = anim; |
| 274 | mAnimation.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION); |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 275 | mAnimation.scaleCurrentDuration(mService.getWindowAnimationScaleLocked()); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 276 | // Start out animation gone if window is gone, or visible if window is visible. |
| 277 | mTransformation.clear(); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 278 | mTransformation.setAlpha(mLastHidden ? 0 : 1); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 279 | mHasLocalTransformation = true; |
Jorim Jaggi | 44f60cc | 2014-11-07 20:33:51 +0100 | [diff] [blame] | 280 | mAnimationStartTime = startTime; |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 281 | mStackClip = stackClip; |
| 282 | } |
| 283 | |
| 284 | public void setAnimation(Animation anim, int stackClip) { |
| 285 | setAnimation(anim, -1, stackClip); |
Jorim Jaggi | 44f60cc | 2014-11-07 20:33:51 +0100 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | public void setAnimation(Animation anim) { |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 289 | setAnimation(anim, -1, STACK_CLIP_AFTER_ANIM); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | public void clearAnimation() { |
| 293 | if (mAnimation != null) { |
| 294 | mAnimating = true; |
| 295 | mLocalAnimating = false; |
| 296 | mAnimation.cancel(); |
| 297 | mAnimation = null; |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 298 | mStackClip = STACK_CLIP_BEFORE_ANIM; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | |
Jorim Jaggi | 5c80c41 | 2016-04-19 20:03:47 -0700 | [diff] [blame] | 302 | /** |
| 303 | * Is the window or its container currently set to animate or currently animating? |
| 304 | */ |
| 305 | boolean isAnimationSet() { |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 306 | return mAnimation != null |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 307 | || (mParentWinAnimator != null && mParentWinAnimator.mAnimation != null) |
Jorim Jaggi | 3787561 | 2015-02-19 21:05:31 +0100 | [diff] [blame] | 308 | || (mAppAnimator != null && mAppAnimator.isAnimating()); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Jorim Jaggi | 5c80c41 | 2016-04-19 20:03:47 -0700 | [diff] [blame] | 311 | /** |
| 312 | * @return whether an animation is about to start, i.e. the animation is set already but we |
| 313 | * haven't processed the first frame yet. |
| 314 | */ |
| 315 | boolean isAnimationStarting() { |
| 316 | return isAnimationSet() && !mAnimating; |
| 317 | } |
| 318 | |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 319 | /** Is the window animating the DummyAnimation? */ |
| 320 | boolean isDummyAnimation() { |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 321 | return mAppAnimator != null |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 322 | && mAppAnimator.animation == sDummyAnimation; |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Jorim Jaggi | 5c80c41 | 2016-04-19 20:03:47 -0700 | [diff] [blame] | 325 | /** |
| 326 | * Is this window currently set to animate or currently animating? |
| 327 | */ |
| 328 | boolean isWindowAnimationSet() { |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 329 | return mAnimation != null; |
| 330 | } |
| 331 | |
Chong Zhang | e22006d | 2016-05-09 10:59:59 -0700 | [diff] [blame] | 332 | /** |
| 333 | * Is this window currently waiting to run an opening animation? |
| 334 | */ |
| 335 | boolean isWaitingForOpening() { |
| 336 | return mService.mAppTransition.isTransitionSet() && isDummyAnimation() |
| 337 | && mService.mOpeningApps.contains(mWin.mAppToken); |
| 338 | } |
| 339 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 340 | void cancelExitAnimationForNextAnimationLocked() { |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 341 | if (DEBUG_ANIM) Slog.d(TAG, |
| 342 | "cancelExitAnimationForNextAnimationLocked: " + mWin); |
| 343 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 344 | if (mAnimation != null) { |
| 345 | mAnimation.cancel(); |
| 346 | mAnimation = null; |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 347 | mLocalAnimating = false; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 348 | mWin.destroySurfaceUnchecked(); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 349 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | private boolean stepAnimation(long currentTime) { |
| 353 | if ((mAnimation == null) || !mLocalAnimating) { |
| 354 | return false; |
| 355 | } |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 356 | currentTime = getAnimationFrameTime(mAnimation, currentTime); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 357 | mTransformation.clear(); |
| 358 | final boolean more = mAnimation.getTransformation(currentTime, mTransformation); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 359 | if (mAnimationStartDelayed && mAnimationIsEntrance) { |
| 360 | mTransformation.setAlpha(0f); |
| 361 | } |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 362 | if (false && DEBUG_ANIM) Slog.v(TAG, "Stepped animation in " + this + ": more=" + more |
| 363 | + ", xform=" + mTransformation); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 364 | return more; |
| 365 | } |
| 366 | |
| 367 | // This must be called while inside a transaction. Returns true if |
| 368 | // there is more animation to run. |
| 369 | boolean stepAnimationLocked(long currentTime) { |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 370 | // Save the animation state as it was before this step so WindowManagerService can tell if |
Jorim Jaggi | 5c80c41 | 2016-04-19 20:03:47 -0700 | [diff] [blame] | 371 | // we just started or just stopped animating by comparing mWasAnimating with isAnimationSet(). |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 372 | mWasAnimating = mAnimating; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 373 | final DisplayContent displayContent = mWin.getDisplayContent(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 374 | if (mWin.mToken.okToAnimate()) { |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 375 | // We will run animations as long as the display isn't frozen. |
| 376 | |
| 377 | if (mWin.isDrawnLw() && mAnimation != null) { |
| 378 | mHasTransformation = true; |
| 379 | mHasLocalTransformation = true; |
| 380 | if (!mLocalAnimating) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 381 | if (DEBUG_ANIM) Slog.v( |
| 382 | TAG, "Starting animation in " + this + |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 383 | " @ " + currentTime + ": ww=" + mWin.mFrame.width() + |
| 384 | " wh=" + mWin.mFrame.height() + |
Filip Gruszczynski | f52dd20 | 2015-11-15 20:36:38 -0800 | [diff] [blame] | 385 | " dx=" + mAnimDx + " dy=" + mAnimDy + |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 386 | " scale=" + mService.getWindowAnimationScaleLocked()); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 387 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
tiger_huang | b7f3f92 | 2015-04-27 20:36:46 +0800 | [diff] [blame] | 388 | if (mAnimateMove) { |
| 389 | mAnimateMove = false; |
| 390 | mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(), |
Filip Gruszczynski | f52dd20 | 2015-11-15 20:36:38 -0800 | [diff] [blame] | 391 | mAnimDx, mAnimDy); |
tiger_huang | b7f3f92 | 2015-04-27 20:36:46 +0800 | [diff] [blame] | 392 | } else { |
| 393 | mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(), |
| 394 | displayInfo.appWidth, displayInfo.appHeight); |
| 395 | } |
Filip Gruszczynski | f52dd20 | 2015-11-15 20:36:38 -0800 | [diff] [blame] | 396 | mAnimDx = displayInfo.appWidth; |
| 397 | mAnimDy = displayInfo.appHeight; |
Jorim Jaggi | 44f60cc | 2014-11-07 20:33:51 +0100 | [diff] [blame] | 398 | mAnimation.setStartTime(mAnimationStartTime != -1 |
| 399 | ? mAnimationStartTime |
| 400 | : currentTime); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 401 | mLocalAnimating = true; |
| 402 | mAnimating = true; |
| 403 | } |
| 404 | if ((mAnimation != null) && mLocalAnimating) { |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 405 | mLastAnimationTime = currentTime; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 406 | if (stepAnimation(currentTime)) { |
| 407 | return true; |
| 408 | } |
| 409 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 410 | if (DEBUG_ANIM) Slog.v( |
| 411 | TAG, "Finished animation in " + this + |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 412 | " @ " + currentTime); |
| 413 | //WindowManagerService.this.dump(); |
| 414 | } |
| 415 | mHasLocalTransformation = false; |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 416 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppAnimator != null |
| 417 | && mAppAnimator.animation != null) { |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 418 | // When our app token is animating, we kind-of pretend like |
| 419 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 420 | // part of this check means that we will only do this if |
| 421 | // our window is not currently exiting, or it is not |
| 422 | // locally animating itself. The idea being that one that |
| 423 | // is exiting and doing a local animation should be removed |
| 424 | // once that animation is done. |
| 425 | mAnimating = true; |
| 426 | mHasTransformation = true; |
| 427 | mTransformation.clear(); |
| 428 | return false; |
| 429 | } else if (mHasTransformation) { |
| 430 | // Little trick to get through the path below to act like |
| 431 | // we have finished an animation. |
| 432 | mAnimating = true; |
Jorim Jaggi | 5c80c41 | 2016-04-19 20:03:47 -0700 | [diff] [blame] | 433 | } else if (isAnimationSet()) { |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 434 | mAnimating = true; |
| 435 | } |
| 436 | } else if (mAnimation != null) { |
| 437 | // If the display is frozen, and there is a pending animation, |
| 438 | // clear it and make sure we run the cleanup code. |
| 439 | mAnimating = true; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | if (!mAnimating && !mLocalAnimating) { |
| 443 | return false; |
| 444 | } |
| 445 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 446 | // Done animating, clean up. |
| 447 | if (DEBUG_ANIM) Slog.v( |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 448 | TAG, "Animation done in " + this + ": exiting=" + mWin.mAnimatingExit |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 449 | + ", reportedVisible=" |
| 450 | + (mWin.mAppToken != null ? mWin.mAppToken.reportedVisible : false)); |
| 451 | |
| 452 | mAnimating = false; |
| 453 | mLocalAnimating = false; |
| 454 | if (mAnimation != null) { |
| 455 | mAnimation.cancel(); |
| 456 | mAnimation = null; |
| 457 | } |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 458 | if (mAnimator.mWindowDetachedWallpaper == mWin) { |
| 459 | mAnimator.mWindowDetachedWallpaper = null; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 460 | } |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 461 | mAnimLayer = mWin.getSpecialWindowAnimLayerAdjustment(); |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 462 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this + " anim layer: " + mAnimLayer); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 463 | mHasTransformation = false; |
| 464 | mHasLocalTransformation = false; |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 465 | mStackClip = STACK_CLIP_BEFORE_ANIM; |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 466 | mWin.checkPolicyVisibilityChange(); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 467 | mTransformation.clear(); |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 468 | if (mAttrType == LayoutParams.TYPE_STATUS_BAR && mWin.mPolicyVisibility) { |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 469 | // Upon completion of a not-visible to visible status bar animation a relayout is |
| 470 | // required. |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 471 | if (displayContent != null) { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 472 | displayContent.setLayoutNeeded(); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 473 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 476 | mWin.onExitAnimationDone(); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 477 | final int displayId = mWin.getDisplayId(); |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 478 | mAnimator.setPendingLayoutChanges(displayId, WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM); |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 479 | if (DEBUG_LAYOUT_REPEATS) |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 480 | mService.mWindowPlacerLocked.debugLayoutRepeats( |
| 481 | "WindowStateAnimator", mAnimator.getPendingLayoutChanges(displayId)); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 482 | |
| 483 | if (mWin.mAppToken != null) { |
| 484 | mWin.mAppToken.updateReportedVisibilityLocked(); |
| 485 | } |
| 486 | |
| 487 | return false; |
| 488 | } |
| 489 | |
Filip Gruszczynski | 63a35e2 | 2015-11-05 15:38:59 -0800 | [diff] [blame] | 490 | void hide(String reason) { |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 491 | if (!mLastHidden) { |
| 492 | //dump(); |
| 493 | mLastHidden = true; |
Wale Ogunwale | f9e0978 | 2015-11-09 12:42:37 -0800 | [diff] [blame] | 494 | if (mSurfaceController != null) { |
| 495 | mSurfaceController.hideInTransaction(reason); |
| 496 | } |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 497 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 500 | boolean finishDrawingLocked() { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 501 | final boolean startingWindow = |
| 502 | mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 503 | if (DEBUG_STARTING_WINDOW && startingWindow) { |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 504 | Slog.v(TAG, "Finishing drawing window " + mWin + ": mDrawState=" |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 505 | + drawStateToString()); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 506 | } |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 507 | |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 508 | boolean layoutNeeded = false; |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 509 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 510 | if (mDrawState == DRAW_PENDING) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 511 | if (DEBUG_ANIM || SHOW_TRANSACTIONS || DEBUG_ORIENTATION) |
Chong Zhang | 5b2f199 | 2015-11-13 15:40:36 -0800 | [diff] [blame] | 512 | Slog.v(TAG, "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING " + mWin + " in " |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 513 | + mSurfaceController); |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 514 | if (DEBUG_STARTING_WINDOW && startingWindow) { |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 515 | Slog.v(TAG, "Draw state now committed in " + mWin); |
| 516 | } |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 517 | mDrawState = COMMIT_DRAW_PENDING; |
Chong Zhang | cbbcc0f | 2016-05-17 20:46:58 -0700 | [diff] [blame] | 518 | layoutNeeded = true; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 519 | } |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 520 | |
Chong Zhang | cbbcc0f | 2016-05-17 20:46:58 -0700 | [diff] [blame] | 521 | return layoutNeeded; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | // This must be called while inside a transaction. |
Craig Mautner | c431e89 | 2015-02-11 13:14:26 -0800 | [diff] [blame] | 525 | boolean commitFinishDrawingLocked() { |
Jorim Jaggi | e4b0f28 | 2017-05-17 15:10:29 +0200 | [diff] [blame] | 526 | if (DEBUG_STARTING_WINDOW_VERBOSE && |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 527 | mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 528 | Slog.i(TAG, "commitFinishDrawingLocked: " + mWin + " cur mDrawState=" |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 529 | + drawStateToString()); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 530 | } |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 531 | if (mDrawState != COMMIT_DRAW_PENDING && mDrawState != READY_TO_SHOW) { |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 532 | return false; |
| 533 | } |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 534 | if (DEBUG_ANIM) { |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 535 | Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurfaceController); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 536 | } |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 537 | mDrawState = READY_TO_SHOW; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 538 | boolean result = false; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 539 | final AppWindowToken atoken = mWin.mAppToken; |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 540 | if (atoken == null || atoken.allDrawn || mWin.mAttrs.type == TYPE_APPLICATION_STARTING) { |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 541 | result = mWin.performShowLocked(); |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 542 | } |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 543 | return result; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 546 | void preserveSurfaceLocked() { |
| 547 | if (mDestroyPreservedSurfaceUponRedraw) { |
Chong Zhang | b9b0fec | 2016-02-11 18:51:51 -0800 | [diff] [blame] | 548 | // This could happen when switching the surface mode very fast. For example, |
| 549 | // we preserved a surface when dragResizing changed to true. Then before the |
| 550 | // preserved surface is removed, dragResizing changed to false again. |
| 551 | // In this case, we need to leave the preserved surface alone, and destroy |
| 552 | // the actual surface, so that the createSurface call could create a surface |
| 553 | // of the proper size. The preserved surface will still be removed when client |
| 554 | // finishes drawing to the new surface. |
| 555 | mSurfaceDestroyDeferred = false; |
| 556 | destroySurfaceLocked(); |
| 557 | mSurfaceDestroyDeferred = true; |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 558 | return; |
| 559 | } |
Filip Gruszczynski | 198dcbf | 2016-01-18 10:02:00 -0800 | [diff] [blame] | 560 | if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, "SET FREEZE LAYER", false); |
Wale Ogunwale | f9e0978 | 2015-11-09 12:42:37 -0800 | [diff] [blame] | 561 | if (mSurfaceController != null) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 562 | // Our SurfaceControl is always at layer 0 within the parent Surface managed by |
| 563 | // window-state. We want this old Surface to stay on top of the new one |
| 564 | // until we do the swap, so we place it at layer 1. |
| 565 | mSurfaceController.mSurfaceControl.setLayer(1); |
Wale Ogunwale | f9e0978 | 2015-11-09 12:42:37 -0800 | [diff] [blame] | 566 | } |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 567 | mDestroyPreservedSurfaceUponRedraw = true; |
| 568 | mSurfaceDestroyDeferred = true; |
| 569 | destroySurfaceLocked(); |
| 570 | } |
| 571 | |
| 572 | void destroyPreservedSurfaceLocked() { |
| 573 | if (!mDestroyPreservedSurfaceUponRedraw) { |
| 574 | return; |
| 575 | } |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 576 | if (mSurfaceController != null) { |
| 577 | if (mPendingDestroySurface != null) { |
| 578 | // If we are preserving a surface but we aren't relaunching that means |
| 579 | // we are just doing an in-place switch. In that case any SurfaceFlinger side |
| 580 | // child layers need to be reparented to the new surface to make this |
| 581 | // transparent to the app. |
| 582 | if (mWin.mAppToken == null || mWin.mAppToken.isRelaunching() == false) { |
| 583 | SurfaceControl.openTransaction(); |
| 584 | mPendingDestroySurface.reparentChildrenInTransaction(mSurfaceController); |
| 585 | SurfaceControl.closeTransaction(); |
| 586 | } |
| 587 | } |
| 588 | } |
| 589 | |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 590 | destroyDeferredSurfaceLocked(); |
| 591 | mDestroyPreservedSurfaceUponRedraw = false; |
| 592 | } |
| 593 | |
Chong Zhang | eb66557 | 2016-05-09 18:28:27 -0700 | [diff] [blame] | 594 | void markPreservedSurfaceForDestroy() { |
| 595 | if (mDestroyPreservedSurfaceUponRedraw |
| 596 | && !mService.mDestroyPreservedSurface.contains(mWin)) { |
| 597 | mService.mDestroyPreservedSurface.add(mWin); |
| 598 | } |
| 599 | } |
| 600 | |
Robert Carr | da61ba9 | 2017-03-29 15:52:23 -0700 | [diff] [blame] | 601 | private int getLayerStack() { |
| 602 | return mWin.getDisplayContent().getDisplay().getLayerStack(); |
| 603 | } |
| 604 | |
Robert Carr | ecc06b3 | 2017-04-18 14:25:10 -0700 | [diff] [blame] | 605 | void resetDrawState() { |
| 606 | mDrawState = DRAW_PENDING; |
| 607 | |
| 608 | if (mWin.mAppToken == null) { |
| 609 | return; |
| 610 | } |
| 611 | |
| 612 | if (mWin.mAppToken.mAppAnimator.animation == null) { |
| 613 | mWin.mAppToken.clearAllDrawn(); |
| 614 | } else { |
| 615 | // Currently animating, persist current state of allDrawn until animation |
| 616 | // is complete. |
| 617 | mWin.mAppToken.deferClearAllDrawn = true; |
| 618 | } |
| 619 | } |
| 620 | |
Albert Chaulk | 3bf2e57 | 2016-11-22 13:59:19 -0500 | [diff] [blame] | 621 | WindowSurfaceController createSurfaceLocked(int windowType, int ownerUid) { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 622 | final WindowState w = mWin; |
Chong Zhang | a8975bd | 2016-01-28 17:13:47 -0800 | [diff] [blame] | 623 | |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 624 | if (mSurfaceController != null) { |
| 625 | return mSurfaceController; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 626 | } |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 627 | |
Robert Carr | 132c9f5 | 2017-07-31 17:02:30 -0700 | [diff] [blame] | 628 | if ((mWin.mAttrs.privateFlags & PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY) != 0) { |
| 629 | windowType = SurfaceControl.WINDOW_TYPE_DONT_SCREENSHOT; |
| 630 | } |
| 631 | |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 632 | w.setHasSurface(false); |
| 633 | |
| 634 | if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG, |
| 635 | "createSurface " + this + ": mDrawState=DRAW_PENDING"); |
| 636 | |
Robert Carr | ecc06b3 | 2017-04-18 14:25:10 -0700 | [diff] [blame] | 637 | resetDrawState(); |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 638 | |
| 639 | mService.makeWindowFreezingScreenIfNeededLocked(w); |
| 640 | |
| 641 | int flags = SurfaceControl.HIDDEN; |
| 642 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 643 | |
| 644 | if (mService.isSecureLocked(w)) { |
| 645 | flags |= SurfaceControl.SECURE; |
| 646 | } |
| 647 | |
| 648 | mTmpSize.set(w.mFrame.left + w.mXOffset, w.mFrame.top + w.mYOffset, 0, 0); |
| 649 | calculateSurfaceBounds(w, attrs); |
| 650 | final int width = mTmpSize.width(); |
| 651 | final int height = mTmpSize.height(); |
| 652 | |
| 653 | if (DEBUG_VISIBILITY) { |
| 654 | Slog.v(TAG, "Creating surface in session " |
| 655 | + mSession.mSurfaceSession + " window " + this |
| 656 | + " w=" + width + " h=" + height |
| 657 | + " x=" + mTmpSize.left + " y=" + mTmpSize.top |
| 658 | + " format=" + attrs.format + " flags=" + flags); |
| 659 | } |
| 660 | |
| 661 | // We may abort, so initialize to defaults. |
| 662 | mLastSystemDecorRect.set(0, 0, 0, 0); |
| 663 | mHasClipRect = false; |
| 664 | mClipRect.set(0, 0, 0, 0); |
| 665 | mLastClipRect.set(0, 0, 0, 0); |
| 666 | |
| 667 | // Set up surface control with initial size. |
| 668 | try { |
| 669 | |
| 670 | final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0; |
| 671 | final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format; |
| 672 | if (!PixelFormat.formatHasAlpha(attrs.format) |
| 673 | // Don't make surface with surfaceInsets opaque as they display a |
| 674 | // translucent shadow. |
| 675 | && attrs.surfaceInsets.left == 0 |
| 676 | && attrs.surfaceInsets.top == 0 |
| 677 | && attrs.surfaceInsets.right == 0 |
| 678 | && attrs.surfaceInsets.bottom == 0 |
| 679 | // Don't make surface opaque when resizing to reduce the amount of |
| 680 | // artifacts shown in areas the app isn't drawing content to. |
| 681 | && !w.isDragResizing()) { |
| 682 | flags |= SurfaceControl.OPAQUE; |
| 683 | } |
| 684 | |
| 685 | mSurfaceController = new WindowSurfaceController(mSession.mSurfaceSession, |
| 686 | attrs.getTitle().toString(), |
Albert Chaulk | 3bf2e57 | 2016-11-22 13:59:19 -0500 | [diff] [blame] | 687 | width, height, format, flags, this, windowType, ownerUid); |
Robert Carr | 486bbb7 | 2017-05-30 11:25:22 -0700 | [diff] [blame] | 688 | mSurfaceFormat = format; |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 689 | |
| 690 | w.setHasSurface(true); |
| 691 | |
| 692 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) { |
| 693 | Slog.i(TAG, " CREATE SURFACE " |
| 694 | + mSurfaceController + " IN SESSION " |
| 695 | + mSession.mSurfaceSession |
| 696 | + ": pid=" + mSession.mPid + " format=" |
| 697 | + attrs.format + " flags=0x" |
| 698 | + Integer.toHexString(flags) |
| 699 | + " / " + this); |
| 700 | } |
| 701 | } catch (OutOfResourcesException e) { |
| 702 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 703 | mService.mRoot.reclaimSomeSurfaceMemory(this, "create", true); |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 704 | mDrawState = NO_SURFACE; |
| 705 | return null; |
| 706 | } catch (Exception e) { |
| 707 | Slog.e(TAG, "Exception creating surface", e); |
| 708 | mDrawState = NO_SURFACE; |
| 709 | return null; |
| 710 | } |
| 711 | |
| 712 | if (WindowManagerService.localLOGV) Slog.v(TAG, "Got surface: " + mSurfaceController |
| 713 | + ", set left=" + w.mFrame.left + " top=" + w.mFrame.top |
| 714 | + ", animLayer=" + mAnimLayer); |
| 715 | |
| 716 | if (SHOW_LIGHT_TRANSACTIONS) { |
| 717 | Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked"); |
| 718 | WindowManagerService.logSurface(w, "CREATE pos=(" |
| 719 | + w.mFrame.left + "," + w.mFrame.top + ") (" |
| 720 | + width + "x" + height + "), layer=" + mAnimLayer + " HIDE", false); |
| 721 | } |
| 722 | |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 723 | mLastHidden = true; |
| 724 | |
| 725 | if (WindowManagerService.localLOGV) Slog.v(TAG, "Created surface " + this); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 726 | return mSurfaceController; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 727 | } |
| 728 | |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 729 | private void calculateSurfaceBounds(WindowState w, LayoutParams attrs) { |
| 730 | if ((attrs.flags & FLAG_SCALED) != 0) { |
| 731 | // For a scaled surface, we always want the requested size. |
| 732 | mTmpSize.right = mTmpSize.left + w.mRequestedWidth; |
| 733 | mTmpSize.bottom = mTmpSize.top + w.mRequestedHeight; |
| 734 | } else { |
| 735 | // When we're doing a drag-resizing, request a surface that's fullscreen size, |
| 736 | // so that we don't need to reallocate during the process. This also prevents |
| 737 | // buffer drops due to size mismatch. |
| 738 | if (w.isDragResizing()) { |
| 739 | if (w.getResizeMode() == DRAG_RESIZE_MODE_FREEFORM) { |
| 740 | mTmpSize.left = 0; |
| 741 | mTmpSize.top = 0; |
| 742 | } |
| 743 | final DisplayInfo displayInfo = w.getDisplayInfo(); |
| 744 | mTmpSize.right = mTmpSize.left + displayInfo.logicalWidth; |
| 745 | mTmpSize.bottom = mTmpSize.top + displayInfo.logicalHeight; |
| 746 | } else { |
| 747 | mTmpSize.right = mTmpSize.left + w.mCompatFrame.width(); |
| 748 | mTmpSize.bottom = mTmpSize.top + w.mCompatFrame.height(); |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | // 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] | 753 | // This doesn't necessarily mean that there is an error in the system. The sizes might be |
| 754 | // incorrect, because it is before the first layout or draw. |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 755 | if (mTmpSize.width() < 1) { |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 756 | mTmpSize.right = mTmpSize.left + 1; |
| 757 | } |
| 758 | if (mTmpSize.height() < 1) { |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 759 | mTmpSize.bottom = mTmpSize.top + 1; |
| 760 | } |
| 761 | |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 762 | // Adjust for surface insets. |
Phil Weaver | a4b32b9 | 2016-06-02 13:55:39 -0700 | [diff] [blame] | 763 | mTmpSize.left -= attrs.surfaceInsets.left; |
| 764 | mTmpSize.top -= attrs.surfaceInsets.top; |
| 765 | mTmpSize.right += attrs.surfaceInsets.right; |
| 766 | mTmpSize.bottom += attrs.surfaceInsets.bottom; |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 767 | } |
| 768 | |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 769 | boolean hasSurface() { |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 770 | return mSurfaceController != null && mSurfaceController.hasSurface(); |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 771 | } |
| 772 | |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 773 | void destroySurfaceLocked() { |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 774 | final AppWindowToken wtoken = mWin.mAppToken; |
| 775 | if (wtoken != null) { |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 776 | if (mWin == wtoken.startingWindow) { |
| 777 | wtoken.startingDisplayed = false; |
| 778 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 779 | } |
| 780 | |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 781 | if (mSurfaceController == null) { |
| 782 | return; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 783 | } |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 784 | |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 785 | // When destroying a surface we want to make sure child windows are hidden. If we are |
| 786 | // preserving the surface until redraw though we intend to swap it out with another surface |
| 787 | // for resizing. In this case the window always remains visible to the user and the child |
| 788 | // windows should likewise remain visible. |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 789 | if (!mDestroyPreservedSurfaceUponRedraw) { |
| 790 | mWin.mHidden = true; |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | try { |
| 794 | if (DEBUG_VISIBILITY) logWithStack(TAG, "Window " + this + " destroying surface " |
| 795 | + mSurfaceController + ", session " + mSession); |
| 796 | if (mSurfaceDestroyDeferred) { |
| 797 | if (mSurfaceController != null && mPendingDestroySurface != mSurfaceController) { |
| 798 | if (mPendingDestroySurface != null) { |
| 799 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) { |
| 800 | WindowManagerService.logSurface(mWin, "DESTROY PENDING", true); |
| 801 | } |
| 802 | mPendingDestroySurface.destroyInTransaction(); |
| 803 | } |
| 804 | mPendingDestroySurface = mSurfaceController; |
| 805 | } |
| 806 | } else { |
| 807 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) { |
| 808 | WindowManagerService.logSurface(mWin, "DESTROY", true); |
| 809 | } |
| 810 | destroySurface(); |
| 811 | } |
| 812 | // Don't hide wallpaper if we're deferring the surface destroy |
| 813 | // because of a surface change. |
| 814 | if (!mDestroyPreservedSurfaceUponRedraw) { |
| 815 | mWallpaperControllerLocked.hideWallpapers(mWin); |
| 816 | } |
| 817 | } catch (RuntimeException e) { |
| 818 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
| 819 | + " surface " + mSurfaceController + " session " + mSession + ": " + e.toString()); |
| 820 | } |
| 821 | |
| 822 | // Whether the surface was preserved (and copied to mPendingDestroySurface) or not, it |
| 823 | // needs to be cleared to match the WindowState.mHasSurface state. It is also necessary |
| 824 | // so it can be recreated successfully in mPendingDestroySurface case. |
| 825 | mWin.setHasSurface(false); |
| 826 | if (mSurfaceController != null) { |
| 827 | mSurfaceController.setShown(false); |
| 828 | } |
| 829 | mSurfaceController = null; |
| 830 | mDrawState = NO_SURFACE; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 833 | void destroyDeferredSurfaceLocked() { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 834 | try { |
| 835 | if (mPendingDestroySurface != null) { |
| 836 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) { |
Filip Gruszczynski | 198dcbf | 2016-01-18 10:02:00 -0800 | [diff] [blame] | 837 | WindowManagerService.logSurface(mWin, "DESTROY PENDING", true); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 838 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 839 | mPendingDestroySurface.destroyInTransaction(); |
Chong Zhang | 6e21cf4 | 2015-11-09 14:41:42 -0800 | [diff] [blame] | 840 | // Don't hide wallpaper if we're destroying a deferred surface |
| 841 | // after a surface mode change. |
| 842 | if (!mDestroyPreservedSurfaceUponRedraw) { |
| 843 | mWallpaperControllerLocked.hideWallpapers(mWin); |
| 844 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 845 | } |
| 846 | } catch (RuntimeException e) { |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 847 | Slog.w(TAG, "Exception thrown when destroying Window " |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 848 | + this + " surface " + mPendingDestroySurface |
| 849 | + " session " + mSession + ": " + e.toString()); |
| 850 | } |
| 851 | mSurfaceDestroyDeferred = false; |
| 852 | mPendingDestroySurface = null; |
| 853 | } |
| 854 | |
| 855 | void computeShownFrameLocked() { |
| 856 | final boolean selfTransformation = mHasLocalTransformation; |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 857 | Transformation appTransformation = (mAppAnimator != null && mAppAnimator.hasTransformation) |
| 858 | ? mAppAnimator.transformation : null; |
Robert Carr | 29d196f | 2017-11-28 12:39:46 -0800 | [diff] [blame] | 859 | Transformation wallpaperTargetTransformation = null; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 860 | |
| 861 | // Wallpapers are animated based on the "real" window they |
| 862 | // are currently targeting. |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 863 | final WindowState wallpaperTarget = mWallpaperControllerLocked.getWallpaperTarget(); |
Craig Mautner | 798adef | 2013-10-22 14:29:01 -0700 | [diff] [blame] | 864 | if (mIsWallpaper && wallpaperTarget != null && mService.mAnimateWallpaperWithTarget) { |
| 865 | final WindowStateAnimator wallpaperAnimator = wallpaperTarget.mWinAnimator; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 866 | if (wallpaperAnimator.mHasLocalTransformation && |
| 867 | wallpaperAnimator.mAnimation != null && |
| 868 | !wallpaperAnimator.mAnimation.getDetachWallpaper()) { |
Robert Carr | 29d196f | 2017-11-28 12:39:46 -0800 | [diff] [blame] | 869 | wallpaperTargetTransformation = wallpaperAnimator.mTransformation; |
| 870 | if (DEBUG_WALLPAPER && wallpaperTargetTransformation != null) { |
| 871 | Slog.v(TAG, "WP target attached xform: " + wallpaperTargetTransformation); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 872 | } |
| 873 | } |
Craig Mautner | 798adef | 2013-10-22 14:29:01 -0700 | [diff] [blame] | 874 | final AppWindowAnimator wpAppAnimator = wallpaperTarget.mAppToken == null ? |
| 875 | null : wallpaperTarget.mAppToken.mAppAnimator; |
| 876 | if (wpAppAnimator != null && wpAppAnimator.hasTransformation |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 877 | && wpAppAnimator.animation != null |
| 878 | && !wpAppAnimator.animation.getDetachWallpaper()) { |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 879 | appTransformation = wpAppAnimator.transformation; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 880 | if (DEBUG_WALLPAPER && appTransformation != null) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 881 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
| 882 | } |
| 883 | } |
| 884 | } |
| 885 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 886 | final int displayId = mWin.getDisplayId(); |
| 887 | final ScreenRotationAnimation screenRotationAnimation = |
| 888 | mAnimator.getScreenRotationAnimationLocked(displayId); |
| 889 | final boolean screenAnimation = |
| 890 | screenRotationAnimation != null && screenRotationAnimation.isAnimating(); |
Robert Carr | 2f0fe62 | 2015-09-25 14:56:38 -0700 | [diff] [blame] | 891 | |
| 892 | mHasClipRect = false; |
Robert Carr | 29d196f | 2017-11-28 12:39:46 -0800 | [diff] [blame] | 893 | if (selfTransformation || wallpaperTargetTransformation != null |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 894 | || appTransformation != null || screenAnimation) { |
| 895 | // cache often used attributes locally |
| 896 | final Rect frame = mWin.mFrame; |
| 897 | final float tmpFloats[] = mService.mTmpFloats; |
| 898 | final Matrix tmpMatrix = mWin.mTmpMatrix; |
| 899 | |
| 900 | // Compute the desired transformation. |
Dianne Hackborn | 4b16969 | 2012-11-29 17:51:24 -0800 | [diff] [blame] | 901 | if (screenAnimation && screenRotationAnimation.isRotating()) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 902 | // If we are doing a screen animation, the global rotation |
| 903 | // applied to windows can result in windows that are carefully |
| 904 | // aligned with each other to slightly separate, allowing you |
| 905 | // to see what is behind them. An unsightly mess. This... |
| 906 | // thing... magically makes it call good: scale each window |
| 907 | // slightly (two pixels larger in each dimension, from the |
| 908 | // window's center). |
| 909 | final float w = frame.width(); |
| 910 | final float h = frame.height(); |
| 911 | if (w>=1 && h>=1) { |
| 912 | tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2); |
| 913 | } else { |
| 914 | tmpMatrix.reset(); |
| 915 | } |
| 916 | } else { |
| 917 | tmpMatrix.reset(); |
| 918 | } |
| 919 | tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale); |
| 920 | if (selfTransformation) { |
| 921 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
| 922 | } |
Robert Carr | 29d196f | 2017-11-28 12:39:46 -0800 | [diff] [blame] | 923 | |
| 924 | if (wallpaperTargetTransformation != null) { |
| 925 | tmpMatrix.postConcat(wallpaperTargetTransformation.getMatrix()); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 926 | } |
| 927 | if (appTransformation != null) { |
| 928 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
| 929 | } |
Matthew Ng | 34a06d1 | 2017-02-03 11:56:08 -0800 | [diff] [blame] | 930 | |
Robert Carr | 29d196f | 2017-11-28 12:39:46 -0800 | [diff] [blame] | 931 | int left = frame.left; |
| 932 | int top = frame.top; |
| 933 | if (mWin.isChildWindow()) { |
| 934 | WindowState parent = mWin.getParentWindow(); |
| 935 | left -= parent.mFrame.left; |
| 936 | top -= parent.mFrame.top; |
| 937 | } |
| 938 | |
Matthew Ng | 34a06d1 | 2017-02-03 11:56:08 -0800 | [diff] [blame] | 939 | // The translation that applies the position of the window needs to be applied at the |
| 940 | // end in case that other translations include scaling. Otherwise the scaling will |
| 941 | // affect this translation. But it needs to be set before the screen rotation animation |
| 942 | // so the pivot point is at the center of the screen for all windows. |
Robert Carr | 29d196f | 2017-11-28 12:39:46 -0800 | [diff] [blame] | 943 | tmpMatrix.postTranslate(left + mWin.mXOffset, top + mWin.mYOffset); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 944 | if (screenAnimation) { |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 945 | tmpMatrix.postConcat(screenRotationAnimation.getEnterTransformation().getMatrix()); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 946 | } |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 947 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 948 | // "convert" it into SurfaceFlinger's format |
| 949 | // (a 2x2 matrix + an offset) |
| 950 | // Here we must not transform the position of the surface |
| 951 | // since it is already included in the transformation. |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 952 | //Slog.i(TAG_WM, "Transform: " + matrix); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 953 | |
| 954 | mHaveMatrix = true; |
| 955 | tmpMatrix.getValues(tmpFloats); |
| 956 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 957 | mDtDx = tmpFloats[Matrix.MSKEW_Y]; |
Robert Carr | 0edf18f | 2017-02-21 20:01:47 -0800 | [diff] [blame] | 958 | mDtDy = tmpFloats[Matrix.MSKEW_X]; |
| 959 | mDsDy = tmpFloats[Matrix.MSCALE_Y]; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 960 | float x = tmpFloats[Matrix.MTRANS_X]; |
| 961 | float y = tmpFloats[Matrix.MTRANS_Y]; |
Qiushi Han | 32fed96 | 2016-10-01 17:06:49 +0800 | [diff] [blame] | 962 | mWin.mShownPosition.set(Math.round(x), Math.round(y)); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 963 | |
| 964 | // Now set the alpha... but because our current hardware |
| 965 | // can't do alpha transformation on a non-opaque surface, |
| 966 | // turn it off if we are running an animation that is also |
| 967 | // transforming since it is more important to have that |
| 968 | // animation be smooth. |
| 969 | mShownAlpha = mAlpha; |
| 970 | if (!mService.mLimitedAlphaCompositing |
| 971 | || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format) |
Robert Carr | 0edf18f | 2017-02-21 20:01:47 -0800 | [diff] [blame] | 972 | || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDtDy, mDsDy) |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 973 | && x == frame.left && y == frame.top))) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 974 | //Slog.i(TAG_WM, "Applying alpha transform"); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 975 | if (selfTransformation) { |
| 976 | mShownAlpha *= mTransformation.getAlpha(); |
| 977 | } |
Robert Carr | 29d196f | 2017-11-28 12:39:46 -0800 | [diff] [blame] | 978 | if (wallpaperTargetTransformation != null) { |
| 979 | mShownAlpha *= wallpaperTargetTransformation.getAlpha(); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 980 | } |
| 981 | if (appTransformation != null) { |
| 982 | mShownAlpha *= appTransformation.getAlpha(); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 983 | if (appTransformation.hasClipRect()) { |
| 984 | mClipRect.set(appTransformation.getClipRect()); |
| 985 | mHasClipRect = true; |
Robert Carr | f3b72c7 | 2016-03-21 18:16:39 -0700 | [diff] [blame] | 986 | // The app transformation clip will be in the coordinate space of the main |
| 987 | // activity window, which the animation correctly assumes will be placed at |
| 988 | // (0,0)+(insets) relative to the containing frame. This isn't necessarily |
| 989 | // true for child windows though which can have an arbitrary frame position |
| 990 | // relative to their containing frame. We need to offset the difference |
| 991 | // between the containing frame as used to calculate the crop and our |
| 992 | // bounds to compensate for this. |
Wale Ogunwale | 246c209 | 2016-04-07 14:12:44 -0700 | [diff] [blame] | 993 | if (mWin.layoutInParentFrame()) { |
Robert Carr | f3b72c7 | 2016-03-21 18:16:39 -0700 | [diff] [blame] | 994 | mClipRect.offset( (mWin.mContainingFrame.left - mWin.mFrame.left), |
| 995 | mWin.mContainingFrame.top - mWin.mFrame.top ); |
| 996 | } |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 997 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 998 | } |
| 999 | if (screenAnimation) { |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 1000 | mShownAlpha *= screenRotationAnimation.getEnterTransformation().getAlpha(); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1001 | } |
| 1002 | } else { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 1003 | //Slog.i(TAG_WM, "Not applying alpha transform"); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1006 | if ((DEBUG_ANIM || WindowManagerService.localLOGV) |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 1007 | && (mShownAlpha == 1.0 || mShownAlpha == 0.0)) Slog.v( |
| 1008 | TAG, "computeShownFrameLocked: Animating " + this + " mAlpha=" + mAlpha |
| 1009 | + " self=" + (selfTransformation ? mTransformation.getAlpha() : "null") |
Robert Carr | 29d196f | 2017-11-28 12:39:46 -0800 | [diff] [blame] | 1010 | + " attached=" + (wallpaperTargetTransformation == null ? |
| 1011 | "null" : wallpaperTargetTransformation.getAlpha()) |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 1012 | + " app=" + (appTransformation == null ? "null" : appTransformation.getAlpha()) |
| 1013 | + " screen=" + (screenAnimation ? |
| 1014 | screenRotationAnimation.getEnterTransformation().getAlpha() : "null")); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1015 | return; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1016 | } else if (mIsWallpaper && mService.mRoot.mWallpaperActionPending) { |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 1017 | return; |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 1018 | } else if (mWin.isDragResizeChanged()) { |
| 1019 | // This window is awaiting a relayout because user just started (or ended) |
| 1020 | // drag-resizing. The shown frame (which affects surface size and pos) |
| 1021 | // should not be updated until we get next finished draw with the new surface. |
| 1022 | // Otherwise one or two frames rendered with old settings would be displayed |
| 1023 | // with new geometry. |
| 1024 | return; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Filip Gruszczynski | 19723a4 | 2015-11-25 15:01:48 -0800 | [diff] [blame] | 1027 | if (WindowManagerService.localLOGV) Slog.v( |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 1028 | TAG, "computeShownFrameLocked: " + this + |
| 1029 | " not attached, mAlpha=" + mAlpha); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 1030 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1031 | mWin.mShownPosition.set(mWin.mFrame.left, mWin.mFrame.top); |
| 1032 | if (mWin.mXOffset != 0 || mWin.mYOffset != 0) { |
| 1033 | mWin.mShownPosition.offset(mWin.mXOffset, mWin.mYOffset); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1034 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1035 | mShownAlpha = mAlpha; |
| 1036 | mHaveMatrix = false; |
| 1037 | mDsDx = mWin.mGlobalScale; |
| 1038 | mDtDx = 0; |
| 1039 | mDtDy = 0; |
| 1040 | mDsDy = mWin.mGlobalScale; |
Robert Carr | ef090ac | 2017-05-15 16:45:50 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1043 | /** |
| 1044 | * In some scenarios we use a screen space clip rect (so called, final clip rect) |
| 1045 | * to crop to stack bounds. Generally because it's easier to deal with while |
| 1046 | * animating. |
| 1047 | * |
| 1048 | * @return True in scenarios where we use the final clip rect for stack clipping. |
| 1049 | */ |
| 1050 | private boolean useFinalClipRect() { |
| 1051 | return (isAnimationSet() && resolveStackClip() == STACK_CLIP_AFTER_ANIM) |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1052 | || mDestroyPreservedSurfaceUponRedraw || mWin.inPinnedWindowingMode(); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1053 | } |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 1054 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1055 | /** |
| 1056 | * Calculate the screen-space crop rect and fill finalClipRect. |
| 1057 | * @return true if finalClipRect has been filled, otherwise, |
| 1058 | * no screen space crop should be applied. |
| 1059 | */ |
| 1060 | private boolean calculateFinalCrop(Rect finalClipRect) { |
Dianne Hackborn | 3e52fc2 | 2012-05-15 17:58:02 -0700 | [diff] [blame] | 1061 | final WindowState w = mWin; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1062 | final DisplayContent displayContent = w.getDisplayContent(); |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1063 | finalClipRect.setEmpty(); |
| 1064 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1065 | if (displayContent == null) { |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1066 | return false; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1067 | } |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1068 | |
| 1069 | if (!shouldCropToStackBounds() || !useFinalClipRect()) { |
| 1070 | return false; |
| 1071 | } |
| 1072 | |
| 1073 | // Task is non-null per shouldCropToStackBounds |
| 1074 | final TaskStack stack = w.getTask().mStack; |
| 1075 | stack.getDimBounds(finalClipRect); |
Robert Carr | 002c8e1 | 2017-04-27 15:32:22 -0700 | [diff] [blame] | 1076 | |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 1077 | if (stack.getWindowConfiguration().tasksAreFloating()) { |
Robert Carr | 002c8e1 | 2017-04-27 15:32:22 -0700 | [diff] [blame] | 1078 | w.expandForSurfaceInsets(finalClipRect); |
| 1079 | } |
Robert Carr | ef090ac | 2017-05-15 16:45:50 -0700 | [diff] [blame] | 1080 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1081 | return true; |
| 1082 | } |
| 1083 | |
| 1084 | /** |
| 1085 | * Calculate the window-space crop rect and fill clipRect. |
Wale Ogunwale | ca9e061 | 2016-12-02 07:45:59 -0800 | [diff] [blame] | 1086 | * @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] | 1087 | */ |
Wale Ogunwale | ca9e061 | 2016-12-02 07:45:59 -0800 | [diff] [blame] | 1088 | private boolean calculateCrop(Rect clipRect) { |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1089 | final WindowState w = mWin; |
| 1090 | final DisplayContent displayContent = w.getDisplayContent(); |
| 1091 | clipRect.setEmpty(); |
| 1092 | |
| 1093 | if (displayContent == null) { |
| 1094 | return false; |
| 1095 | } |
| 1096 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1097 | if (w.inPinnedWindowingMode()) { |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1098 | return false; |
| 1099 | } |
| 1100 | |
| 1101 | // If we're animating, the wallpaper should only |
| 1102 | // be updated at the end of the animation. |
| 1103 | if (w.mAttrs.type == TYPE_WALLPAPER) { |
| 1104 | return false; |
| 1105 | } |
| 1106 | |
Wale Ogunwale | 6bab4cf | 2016-04-07 12:23:08 -0700 | [diff] [blame] | 1107 | if (DEBUG_WINDOW_CROP) Slog.d(TAG, |
| 1108 | "Updating crop win=" + w + " mLastCrop=" + mLastClipRect); |
Dianne Hackborn | 3e52fc2 | 2012-05-15 17:58:02 -0700 | [diff] [blame] | 1109 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1110 | w.calculatePolicyCrop(mSystemDecorRect); |
| 1111 | |
| 1112 | if (DEBUG_WINDOW_CROP) Slog.d(TAG, "Applying decor to crop win=" + w + " mDecorFrame=" |
| 1113 | + w.mDecorFrame + " mSystemDecorRect=" + mSystemDecorRect); |
Dianne Hackborn | 3e52fc2 | 2012-05-15 17:58:02 -0700 | [diff] [blame] | 1114 | |
Andrii Kulian | 283acd2 | 2017-08-03 04:03:51 -0700 | [diff] [blame] | 1115 | final Task task = w.getTask(); |
| 1116 | final boolean fullscreen = w.fillsDisplay() || (task != null && task.isFullscreen()); |
Jorim Jaggi | 253a20f | 2015-11-03 12:38:42 +0100 | [diff] [blame] | 1117 | final boolean isFreeformResizing = |
Jorim Jaggi | dcf467c | 2015-11-05 13:59:32 +0100 | [diff] [blame] | 1118 | w.isDragResizing() && w.getResizeMode() == DRAG_RESIZE_MODE_FREEFORM; |
Robert Carr | 51a1b87 | 2015-12-08 14:03:13 -0800 | [diff] [blame] | 1119 | |
| 1120 | // We use the clip rect as provided by the tranformation for non-fullscreen windows to |
| 1121 | // avoid premature clipping with the system decor rect. |
| 1122 | clipRect.set((mHasClipRect && !fullscreen) ? mClipRect : mSystemDecorRect); |
Wale Ogunwale | 6bab4cf | 2016-04-07 12:23:08 -0700 | [diff] [blame] | 1123 | if (DEBUG_WINDOW_CROP) Slog.d(TAG, "win=" + w + " Initial clip rect: " + clipRect |
| 1124 | + " mHasClipRect=" + mHasClipRect + " fullscreen=" + fullscreen); |
Robert Carr | 51a1b87 | 2015-12-08 14:03:13 -0800 | [diff] [blame] | 1125 | |
| 1126 | if (isFreeformResizing && !w.isChildWindow()) { |
| 1127 | // For freeform resizing non child windows, we are using the big surface positioned |
| 1128 | // at 0,0. Thus we must express the crop in that coordinate space. |
| 1129 | clipRect.offset(w.mShownPosition.x, w.mShownPosition.y); |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 1130 | } |
Robert Carr | 51a1b87 | 2015-12-08 14:03:13 -0800 | [diff] [blame] | 1131 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1132 | w.expandForSurfaceInsets(clipRect); |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 1133 | |
Wale Ogunwale | b3eba81 | 2015-07-30 20:20:16 -0700 | [diff] [blame] | 1134 | if (mHasClipRect && fullscreen) { |
| 1135 | // We intersect the clip rect specified by the transformation with the expanded system |
| 1136 | // decor rect to prevent artifacts from drawing during animation if the transformation |
| 1137 | // clip rect extends outside the system decor rect. |
| 1138 | clipRect.intersect(mClipRect); |
| 1139 | } |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 1140 | // The clip rect was generated assuming (0,0) as the window origin, |
| 1141 | // so we need to translate to match the actual surface coordinates. |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1142 | clipRect.offset(w.mAttrs.surfaceInsets.left, w.mAttrs.surfaceInsets.top); |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 1143 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1144 | if (!useFinalClipRect()) { |
| 1145 | adjustCropToStackBounds(clipRect, isFreeformResizing); |
| 1146 | } |
Wale Ogunwale | 6bab4cf | 2016-04-07 12:23:08 -0700 | [diff] [blame] | 1147 | if (DEBUG_WINDOW_CROP) Slog.d(TAG, |
| 1148 | "win=" + w + " Clip rect after stack adjustment=" + clipRect); |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 1149 | |
Chia-I Wu | e6bcaf1 | 2016-05-27 10:58:48 +0800 | [diff] [blame] | 1150 | w.transformClipRectFromScreenToSurfaceSpace(clipRect); |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 1151 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1152 | return true; |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1153 | } |
| 1154 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1155 | private void applyCrop(Rect clipRect, Rect finalClipRect, boolean recoveringMemory) { |
| 1156 | if (DEBUG_WINDOW_CROP) Slog.d(TAG, "applyCrop: win=" + mWin |
Wale Ogunwale | 6bab4cf | 2016-04-07 12:23:08 -0700 | [diff] [blame] | 1157 | + " clipRect=" + clipRect + " finalClipRect=" + finalClipRect); |
Robert Carr | 4320d33 | 2016-06-10 15:13:32 -0700 | [diff] [blame] | 1158 | if (clipRect != null) { |
| 1159 | if (!clipRect.equals(mLastClipRect)) { |
| 1160 | mLastClipRect.set(clipRect); |
| 1161 | mSurfaceController.setCropInTransaction(clipRect, recoveringMemory); |
| 1162 | } |
| 1163 | } else { |
| 1164 | mSurfaceController.clearCropInTransaction(recoveringMemory); |
Dianne Hackborn | 3e52fc2 | 2012-05-15 17:58:02 -0700 | [diff] [blame] | 1165 | } |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1166 | |
| 1167 | if (finalClipRect == null) { |
| 1168 | finalClipRect = mService.mTmpRect; |
| 1169 | finalClipRect.setEmpty(); |
| 1170 | } |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 1171 | if (!finalClipRect.equals(mLastFinalClipRect)) { |
| 1172 | mLastFinalClipRect.set(finalClipRect); |
| 1173 | mSurfaceController.setFinalCropInTransaction(finalClipRect); |
Chong Zhang | cc3eccf | 2016-05-16 18:25:45 -0700 | [diff] [blame] | 1174 | if (mDestroyPreservedSurfaceUponRedraw && mPendingDestroySurface != null) { |
| 1175 | mPendingDestroySurface.setFinalCropInTransaction(finalClipRect); |
| 1176 | } |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 1177 | } |
Dianne Hackborn | 3e52fc2 | 2012-05-15 17:58:02 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 1180 | private int resolveStackClip() { |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 1181 | // App animation overrides window animation stack clip mode. |
| 1182 | if (mAppAnimator != null && mAppAnimator.animation != null) { |
| 1183 | return mAppAnimator.getStackClip(); |
| 1184 | } else { |
| 1185 | return mStackClip; |
| 1186 | } |
| 1187 | } |
Wale Ogunwale | 4c5aa517 | 2016-04-19 11:29:05 -0700 | [diff] [blame] | 1188 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1189 | private boolean shouldCropToStackBounds() { |
| 1190 | final WindowState w = mWin; |
Wale Ogunwale | 4c5aa517 | 2016-04-19 11:29:05 -0700 | [diff] [blame] | 1191 | final DisplayContent displayContent = w.getDisplayContent(); |
| 1192 | if (displayContent != null && !displayContent.isDefaultDisplay) { |
| 1193 | // There are some windows that live on other displays while their app and main window |
| 1194 | // live on the default display (e.g. casting...). We don't want to crop this windows |
| 1195 | // to the stack bounds which is only currently supported on the default display. |
| 1196 | // TODO(multi-display): Need to support cropping to stack bounds on other displays |
| 1197 | // when we have stacks on other displays. |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1198 | return false; |
Wale Ogunwale | 4c5aa517 | 2016-04-19 11:29:05 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 1201 | final Task task = w.getTask(); |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1202 | if (task == null || !task.cropWindowsToStackBounds()) { |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1203 | return false; |
Filip Gruszczynski | 4b8eea7 | 2015-09-14 18:16:19 -0700 | [diff] [blame] | 1204 | } |
Wale Ogunwale | 69cf50f | 2015-11-13 11:08:36 -0800 | [diff] [blame] | 1205 | |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 1206 | final int stackClip = resolveStackClip(); |
| 1207 | |
| 1208 | // It's animating and we don't want to clip it to stack bounds during animation - abort. |
Jorim Jaggi | 5c80c41 | 2016-04-19 20:03:47 -0700 | [diff] [blame] | 1209 | if (isAnimationSet() && stackClip == STACK_CLIP_NONE) { |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1210 | return false; |
| 1211 | } |
| 1212 | return true; |
| 1213 | } |
| 1214 | |
| 1215 | private void adjustCropToStackBounds(Rect clipRect, |
| 1216 | boolean isFreeformResizing) { |
| 1217 | final WindowState w = mWin; |
| 1218 | |
| 1219 | if (!shouldCropToStackBounds()) { |
Wale Ogunwale | 69cf50f | 2015-11-13 11:08:36 -0800 | [diff] [blame] | 1220 | return; |
| 1221 | } |
| 1222 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1223 | final TaskStack stack = w.getTask().mStack; |
Wale Ogunwale | 69cf50f | 2015-11-13 11:08:36 -0800 | [diff] [blame] | 1224 | stack.getDimBounds(mTmpStackBounds); |
Wale Ogunwale | 6bab4cf | 2016-04-07 12:23:08 -0700 | [diff] [blame] | 1225 | final Rect surfaceInsets = w.getAttrs().surfaceInsets; |
Wale Ogunwale | 69cf50f | 2015-11-13 11:08:36 -0800 | [diff] [blame] | 1226 | // When we resize we use the big surface approach, which means we can't trust the |
| 1227 | // window frame bounds anymore. Instead, the window will be placed at 0, 0, but to avoid |
| 1228 | // hardcoding it, we use surface coordinates. |
| 1229 | final int frameX = isFreeformResizing ? (int) mSurfaceController.getX() : |
Wale Ogunwale | 6bab4cf | 2016-04-07 12:23:08 -0700 | [diff] [blame] | 1230 | w.mFrame.left + mWin.mXOffset - surfaceInsets.left; |
Wale Ogunwale | 69cf50f | 2015-11-13 11:08:36 -0800 | [diff] [blame] | 1231 | final int frameY = isFreeformResizing ? (int) mSurfaceController.getY() : |
Wale Ogunwale | 6bab4cf | 2016-04-07 12:23:08 -0700 | [diff] [blame] | 1232 | w.mFrame.top + mWin.mYOffset - surfaceInsets.top; |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1233 | |
Wale Ogunwale | 69cf50f | 2015-11-13 11:08:36 -0800 | [diff] [blame] | 1234 | // We need to do some acrobatics with surface position, because their clip region is |
| 1235 | // relative to the inside of the surface, but the stack bounds aren't. |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 1236 | final WindowConfiguration winConfig = w.getWindowConfiguration(); |
| 1237 | if (winConfig.hasWindowShadow() && !winConfig.canResizeTask()) { |
Wale Ogunwale | 6bab4cf | 2016-04-07 12:23:08 -0700 | [diff] [blame] | 1238 | // The windows in this stack display drop shadows and the fill the entire stack |
| 1239 | // area. Adjust the stack bounds we will use to cropping take into account the |
| 1240 | // offsets we use to display the drop shadow so it doesn't get cropped. |
| 1241 | mTmpStackBounds.inset(-surfaceInsets.left, -surfaceInsets.top, |
| 1242 | -surfaceInsets.right, -surfaceInsets.bottom); |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 1243 | } |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1244 | |
| 1245 | clipRect.left = Math.max(0, |
| 1246 | Math.max(mTmpStackBounds.left, frameX + clipRect.left) - frameX); |
| 1247 | clipRect.top = Math.max(0, |
| 1248 | Math.max(mTmpStackBounds.top, frameY + clipRect.top) - frameY); |
| 1249 | clipRect.right = Math.max(0, |
| 1250 | Math.min(mTmpStackBounds.right, frameX + clipRect.right) - frameX); |
| 1251 | clipRect.bottom = Math.max(0, |
| 1252 | Math.min(mTmpStackBounds.bottom, frameY + clipRect.bottom) - frameY); |
Filip Gruszczynski | 4b8eea7 | 2015-09-14 18:16:19 -0700 | [diff] [blame] | 1253 | } |
| 1254 | |
Wale Ogunwale | 4c8b795 | 2015-04-07 10:49:40 -0700 | [diff] [blame] | 1255 | void setSurfaceBoundariesLocked(final boolean recoveringMemory) { |
Wale Ogunwale | 027f475 | 2017-05-12 10:37:16 -0700 | [diff] [blame] | 1256 | if (mSurfaceController == null) { |
| 1257 | return; |
| 1258 | } |
| 1259 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1260 | final WindowState w = mWin; |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 1261 | final LayoutParams attrs = mWin.getAttrs(); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1262 | final Task task = w.getTask(); |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 1263 | |
Jorim Jaggi | f3df0aa | 2016-04-06 15:56:33 -0700 | [diff] [blame] | 1264 | // 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] | 1265 | if (w.isResizedWhileNotDragResizing() && !w.isGoneForLayoutLw()) { |
Jorim Jaggi | f3df0aa | 2016-04-06 15:56:33 -0700 | [diff] [blame] | 1266 | return; |
| 1267 | } |
| 1268 | |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 1269 | mTmpSize.set(w.mShownPosition.x, w.mShownPosition.y, 0, 0); |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 1270 | calculateSurfaceBounds(w, attrs); |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 1271 | |
Robert Carr | 0409211 | 2016-06-02 12:56:12 -0700 | [diff] [blame] | 1272 | mExtraHScale = (float) 1.0; |
| 1273 | mExtraVScale = (float) 1.0; |
Robert Carr | e1034cc3 | 2016-02-01 13:08:15 -0800 | [diff] [blame] | 1274 | |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 1275 | boolean wasForceScaled = mForceScaleUntilResize; |
| 1276 | boolean wasSeamlesslyRotated = w.mSeamlesslyRotated; |
| 1277 | |
Robert Carr | fed1007 | 2016-05-26 11:48:49 -0700 | [diff] [blame] | 1278 | // Once relayout has been called at least once, we need to make sure |
| 1279 | // we only resize the client surface during calls to relayout. For |
| 1280 | // clients which use indeterminate measure specs (MATCH_PARENT), |
| 1281 | // we may try and change their window size without a call to relayout. |
| 1282 | // However, this would be unsafe, as the client may be in the middle |
| 1283 | // of producing a frame at the old size, having just completed layout |
| 1284 | // to find the surface size changed underneath it. |
Robert Carr | 3ccc527 | 2016-06-20 22:06:32 -0700 | [diff] [blame] | 1285 | if (!w.mRelayoutCalled || w.mInRelayout) { |
Robert Carr | fed1007 | 2016-05-26 11:48:49 -0700 | [diff] [blame] | 1286 | mSurfaceResized = mSurfaceController.setSizeInTransaction( |
| 1287 | mTmpSize.width(), mTmpSize.height(), recoveringMemory); |
| 1288 | } else { |
| 1289 | mSurfaceResized = false; |
| 1290 | } |
Robert Carr | c729460 | 2016-05-13 11:32:05 -0700 | [diff] [blame] | 1291 | mForceScaleUntilResize = mForceScaleUntilResize && !mSurfaceResized; |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 1292 | // If we are undergoing seamless rotation, the surface has already |
| 1293 | // been set up to persist at it's old location. We need to freeze |
| 1294 | // updates until a resize occurs. |
Robert Carr | b14d4abc | 2016-10-03 18:13:33 -0700 | [diff] [blame] | 1295 | mService.markForSeamlessRotation(w, w.mSeamlesslyRotated && !mSurfaceResized); |
Robert Carr | c729460 | 2016-05-13 11:32:05 -0700 | [diff] [blame] | 1296 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1297 | Rect clipRect = null, finalClipRect = null; |
| 1298 | if (calculateCrop(mTmpClipRect)) { |
| 1299 | clipRect = mTmpClipRect; |
| 1300 | } |
| 1301 | if (calculateFinalCrop(mTmpFinalClipRect)) { |
| 1302 | finalClipRect = mTmpFinalClipRect; |
| 1303 | } |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 1304 | |
| 1305 | float surfaceWidth = mSurfaceController.getWidth(); |
| 1306 | float surfaceHeight = mSurfaceController.getHeight(); |
| 1307 | |
Robert Carr | 8f0a3ad | 2017-02-15 19:30:28 -0800 | [diff] [blame] | 1308 | if (isForceScaled()) { |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 1309 | int hInsets = attrs.surfaceInsets.left + attrs.surfaceInsets.right; |
| 1310 | int vInsets = attrs.surfaceInsets.top + attrs.surfaceInsets.bottom; |
| 1311 | float surfaceContentWidth = surfaceWidth - hInsets; |
| 1312 | float surfaceContentHeight = surfaceHeight - vInsets; |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 1313 | if (!mForceScaleUntilResize) { |
| 1314 | mSurfaceController.forceScaleableInTransaction(true); |
| 1315 | } |
Robert Carr | fd4c989 | 2017-02-01 10:28:28 -0800 | [diff] [blame] | 1316 | |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 1317 | int posX = mTmpSize.left; |
| 1318 | int posY = mTmpSize.top; |
Robert Carr | fd4c989 | 2017-02-01 10:28:28 -0800 | [diff] [blame] | 1319 | task.mStack.getDimBounds(mTmpStackBounds); |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 1320 | |
| 1321 | boolean allowStretching = false; |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1322 | task.mStack.getFinalAnimationSourceHintBounds(mTmpSourceBounds); |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 1323 | // If we don't have source bounds, we can attempt to use the content insets |
| 1324 | // in the following scenario: |
| 1325 | // 1. We have content insets. |
| 1326 | // 2. We are not transitioning to full screen |
| 1327 | // We have to be careful to check "lastAnimatingBoundsWasToFullscreen" rather than |
| 1328 | // the mBoundsAnimating state, as we may have already left it and only be here |
| 1329 | // because of the force-scale until resize state. |
| 1330 | if (mTmpSourceBounds.isEmpty() && (mWin.mLastRelayoutContentInsets.width() > 0 |
| 1331 | || mWin.mLastRelayoutContentInsets.height() > 0) |
| 1332 | && !task.mStack.lastAnimatingBoundsWasToFullscreen()) { |
| 1333 | mTmpSourceBounds.set(task.mStack.mPreAnimationBounds); |
| 1334 | mTmpSourceBounds.inset(mWin.mLastRelayoutContentInsets); |
| 1335 | allowStretching = true; |
| 1336 | } |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 1337 | if (!mTmpSourceBounds.isEmpty()) { |
| 1338 | // Get the final target stack bounds, if we are not animating, this is just the |
| 1339 | // current stack bounds |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 1340 | task.mStack.getFinalAnimationBounds(mTmpAnimatingBounds); |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 1341 | |
| 1342 | // Calculate the current progress and interpolate the difference between the target |
| 1343 | // and source bounds |
| 1344 | float finalWidth = mTmpAnimatingBounds.width(); |
| 1345 | float initialWidth = mTmpSourceBounds.width(); |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 1346 | float tw = (surfaceContentWidth - mTmpStackBounds.width()) |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 1347 | / (surfaceContentWidth - mTmpAnimatingBounds.width()); |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 1348 | float th = tw; |
| 1349 | mExtraHScale = (initialWidth + tw * (finalWidth - initialWidth)) / initialWidth; |
| 1350 | if (allowStretching) { |
| 1351 | float finalHeight = mTmpAnimatingBounds.height(); |
| 1352 | float initialHeight = mTmpSourceBounds.height(); |
| 1353 | th = (surfaceContentHeight - mTmpStackBounds.height()) |
| 1354 | / (surfaceContentHeight - mTmpAnimatingBounds.height()); |
| 1355 | mExtraVScale = (initialHeight + tw * (finalHeight - initialHeight)) |
| 1356 | / initialHeight; |
| 1357 | } else { |
| 1358 | mExtraVScale = mExtraHScale; |
| 1359 | } |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 1360 | |
| 1361 | // Adjust the position to account for the inset bounds |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 1362 | posX -= (int) (tw * mExtraHScale * mTmpSourceBounds.left); |
| 1363 | posY -= (int) (th * mExtraVScale * mTmpSourceBounds.top); |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 1364 | |
| 1365 | // Always clip to the stack bounds since the surface can be larger with the current |
| 1366 | // scale |
| 1367 | clipRect = null; |
| 1368 | finalClipRect = mTmpStackBounds; |
| 1369 | } else { |
| 1370 | // We want to calculate the scaling based on the content area, not based on |
| 1371 | // the entire surface, so that we scale in sync with windows that don't have insets. |
| 1372 | mExtraHScale = mTmpStackBounds.width() / surfaceContentWidth; |
| 1373 | mExtraVScale = mTmpStackBounds.height() / surfaceContentHeight; |
| 1374 | |
| 1375 | // Since we are scaled to fit in our previously desired crop, we can now |
| 1376 | // expose the whole window in buffer space, and not risk extending |
| 1377 | // past where the system would have cropped us |
| 1378 | clipRect = null; |
| 1379 | finalClipRect = null; |
| 1380 | } |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1381 | |
Robert Carr | fd4c989 | 2017-02-01 10:28:28 -0800 | [diff] [blame] | 1382 | // In the case of ForceScaleToStack we scale entire tasks together, |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1383 | // and so we need to scale our offsets relative to the task bounds |
| 1384 | // or parent and child windows would fall out of alignment. |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 1385 | posX -= (int) (attrs.x * (1 - mExtraHScale)); |
| 1386 | posY -= (int) (attrs.y * (1 - mExtraVScale)); |
| 1387 | |
Robert Carr | bc13376 | 2016-05-12 14:04:38 -0700 | [diff] [blame] | 1388 | // Imagine we are scaling down. As we scale the buffer down, we decrease the |
| 1389 | // distance between the surface top left, and the start of the surface contents |
| 1390 | // (previously it was surfaceInsets.left pixels in screen space but now it |
Robert Carr | 0409211 | 2016-06-02 12:56:12 -0700 | [diff] [blame] | 1391 | // will be surfaceInsets.left*mExtraHScale). This means in order to keep the |
Robert Carr | bc13376 | 2016-05-12 14:04:38 -0700 | [diff] [blame] | 1392 | // non inset content at the same position, we have to shift the whole window |
| 1393 | // forward. Likewise for scaling up, we've increased this distance, and we need |
| 1394 | // to shift by a negative number to compensate. |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 1395 | posX += attrs.surfaceInsets.left * (1 - mExtraHScale); |
| 1396 | posY += attrs.surfaceInsets.top * (1 - mExtraVScale); |
Robert Carr | bc13376 | 2016-05-12 14:04:38 -0700 | [diff] [blame] | 1397 | |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 1398 | mSurfaceController.setPositionInTransaction((float) Math.floor(posX), |
| 1399 | (float) Math.floor(posY), recoveringMemory); |
Robert Carr | c729460 | 2016-05-13 11:32:05 -0700 | [diff] [blame] | 1400 | |
| 1401 | // Various surfaces in the scaled stack may resize at different times. |
| 1402 | // We need to ensure for each surface, that we disable transformation matrix |
| 1403 | // scaling in the same transaction which we resize the surface in. |
| 1404 | // As we are in SCALING_MODE_SCALE_TO_WINDOW, SurfaceFlinger will |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 1405 | // then take over the scaling until the new buffer arrives, and things |
Robert Carr | c729460 | 2016-05-13 11:32:05 -0700 | [diff] [blame] | 1406 | // will be seamless. |
| 1407 | mForceScaleUntilResize = true; |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1408 | } else { |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 1409 | if (!w.mSeamlesslyRotated) { |
| 1410 | mSurfaceController.setPositionInTransaction(mTmpSize.left, mTmpSize.top, |
| 1411 | recoveringMemory); |
| 1412 | } |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1413 | } |
| 1414 | |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 1415 | // 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] | 1416 | // to prevent further updates until buffer latch. |
| 1417 | // When ending both force scaling, and seamless rotation, we need to freeze |
| 1418 | // the Surface geometry until a buffer comes in at the new size (normally position and crop |
| 1419 | // are unfrozen). setGeometryAppliesWithResizeInTransaction accomplishes this for us. |
| 1420 | if ((wasForceScaled && !mForceScaleUntilResize) || |
| 1421 | (wasSeamlesslyRotated && !w.mSeamlesslyRotated)) { |
| 1422 | mSurfaceController.setGeometryAppliesWithResizeInTransaction(true); |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 1423 | mSurfaceController.forceScaleableInTransaction(false); |
| 1424 | } |
Robert Carr | 4320d33 | 2016-06-10 15:13:32 -0700 | [diff] [blame] | 1425 | |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 1426 | if (!w.mSeamlesslyRotated) { |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1427 | applyCrop(clipRect, finalClipRect, recoveringMemory); |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 1428 | mSurfaceController.setMatrixInTransaction(mDsDx * w.mHScale * mExtraHScale, |
| 1429 | mDtDx * w.mVScale * mExtraVScale, |
Robert Carr | 0edf18f | 2017-02-21 20:01:47 -0800 | [diff] [blame] | 1430 | mDtDy * w.mHScale * mExtraHScale, |
| 1431 | mDsDy * w.mVScale * mExtraVScale, recoveringMemory); |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 1432 | } |
Filip Gruszczynski | 63a35e2 | 2015-11-05 15:38:59 -0800 | [diff] [blame] | 1433 | |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1434 | if (mSurfaceResized) { |
Chong Zhang | 5b2f199 | 2015-11-13 15:40:36 -0800 | [diff] [blame] | 1435 | mReportSurfaceResized = true; |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1436 | mAnimator.setPendingLayoutChanges(w.getDisplayId(), |
| 1437 | WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1438 | } |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 1439 | } |
| 1440 | |
Andrii Kulian | 283acd2 | 2017-08-03 04:03:51 -0700 | [diff] [blame] | 1441 | /** |
| 1442 | * Get rect of the task this window is currently in. If there is no task, rect will be set to |
| 1443 | * empty. |
| 1444 | */ |
| 1445 | void getContainerRect(Rect rect) { |
| 1446 | final Task task = mWin.getTask(); |
| 1447 | if (task != null) { |
| 1448 | task.getDimBounds(rect); |
| 1449 | } else { |
| 1450 | rect.left = rect.top = rect.right = rect.bottom = 0; |
| 1451 | } |
| 1452 | } |
| 1453 | |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 1454 | void prepareSurfaceLocked(final boolean recoveringMemory) { |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 1455 | final WindowState w = mWin; |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 1456 | if (!hasSurface()) { |
Jorim Jaggi | 38d44ec | 2017-06-14 16:04:59 -0700 | [diff] [blame] | 1457 | |
| 1458 | // There is no need to wait for an animation change if our window is gone for layout |
| 1459 | // already as we'll never be visible. |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1460 | if (w.getOrientationChanging() && w.isGoneForLayoutLw()) { |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 1461 | if (DEBUG_ORIENTATION) { |
| 1462 | Slog.v(TAG, "Orientation change skips hidden " + w); |
| 1463 | } |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1464 | w.setOrientationChanging(false); |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 1465 | } |
| 1466 | return; |
| 1467 | } |
| 1468 | |
Chong Zhang | 7021174 | 2016-04-28 18:27:53 -0700 | [diff] [blame] | 1469 | // Do not change surface properties of opening apps if we are waiting for the |
| 1470 | // transition to be ready. transitionGoodToGo could be not ready even after all |
| 1471 | // opening apps are drawn. It's only waiting on isFetchingAppTransitionsSpecs() |
| 1472 | // to get the animation spec. (For example, go into Recents and immediately open |
| 1473 | // the same app again before the app's surface is destroyed or saved, the surface |
| 1474 | // is always ready in the whole process.) If we go ahead here, the opening app |
| 1475 | // 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] | 1476 | if (isWaitingForOpening()) { |
Chong Zhang | 7021174 | 2016-04-28 18:27:53 -0700 | [diff] [blame] | 1477 | return; |
| 1478 | } |
| 1479 | |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 1480 | boolean displayed = false; |
| 1481 | |
| 1482 | computeShownFrameLocked(); |
| 1483 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 1484 | setSurfaceBoundariesLocked(recoveringMemory); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1485 | |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 1486 | if (mIsWallpaper && !mWin.mWallpaperVisible) { |
Craig Mautner | 0fa77c1 | 2012-06-11 15:57:19 -0700 | [diff] [blame] | 1487 | // 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] | 1488 | hide("prepareSurfaceLocked"); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 1489 | } else if (w.isParentWindowHidden() || !w.isOnScreen()) { |
Filip Gruszczynski | 63a35e2 | 2015-11-05 15:38:59 -0800 | [diff] [blame] | 1490 | hide("prepareSurfaceLocked"); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 1491 | mWallpaperControllerLocked.hideWallpapers(w); |
Craig Mautner | b9836b9 | 2012-06-11 11:40:09 -0700 | [diff] [blame] | 1492 | |
Jorim Jaggi | 38d44ec | 2017-06-14 16:04:59 -0700 | [diff] [blame] | 1493 | // If we are waiting for this window to handle an orientation change. If this window is |
| 1494 | // really hidden (gone for layout), there is no point in still waiting for it. |
| 1495 | // Note that this does introduce a potential glitch if the window becomes unhidden |
| 1496 | // before it has drawn for the new orientation. |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1497 | if (w.getOrientationChanging() && w.isGoneForLayoutLw()) { |
| 1498 | w.setOrientationChanging(false); |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1499 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1500 | "Orientation change skips hidden " + w); |
| 1501 | } |
| 1502 | } else if (mLastLayer != mAnimLayer |
| 1503 | || mLastAlpha != mShownAlpha |
| 1504 | || mLastDsDx != mDsDx |
| 1505 | || mLastDtDx != mDtDx |
| 1506 | || mLastDsDy != mDsDy |
| 1507 | || mLastDtDy != mDtDy |
| 1508 | || w.mLastHScale != w.mHScale |
| 1509 | || w.mLastVScale != w.mVScale |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1510 | || mLastHidden) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1511 | displayed = true; |
| 1512 | mLastAlpha = mShownAlpha; |
| 1513 | mLastLayer = mAnimLayer; |
| 1514 | mLastDsDx = mDsDx; |
| 1515 | mLastDtDx = mDtDx; |
| 1516 | mLastDsDy = mDsDy; |
| 1517 | mLastDtDy = mDtDy; |
| 1518 | w.mLastHScale = w.mHScale; |
| 1519 | w.mLastVScale = w.mVScale; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 1520 | if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(w, |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1521 | "controller=" + mSurfaceController + |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1522 | "alpha=" + mShownAlpha + " layer=" + mAnimLayer |
Craig Mautner | 78505d8 | 2014-09-02 14:36:31 -0700 | [diff] [blame] | 1523 | + " matrix=[" + mDsDx + "*" + w.mHScale |
| 1524 | + "," + mDtDx + "*" + w.mVScale |
Robert Carr | 0edf18f | 2017-02-21 20:01:47 -0800 | [diff] [blame] | 1525 | + "][" + mDtDy + "*" + w.mHScale |
| 1526 | + "," + mDsDy + "*" + w.mVScale + "]", false); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1527 | |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1528 | boolean prepared = |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 1529 | mSurfaceController.prepareToShowInTransaction(mShownAlpha, |
Robert Carr | 0409211 | 2016-06-02 12:56:12 -0700 | [diff] [blame] | 1530 | mDsDx * w.mHScale * mExtraHScale, |
| 1531 | mDtDx * w.mVScale * mExtraVScale, |
Robert Carr | 0edf18f | 2017-02-21 20:01:47 -0800 | [diff] [blame] | 1532 | mDtDy * w.mHScale * mExtraHScale, |
| 1533 | mDsDy * w.mVScale * mExtraVScale, |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1534 | recoveringMemory); |
| 1535 | |
Robert Carr | 03206af | 2017-07-10 18:24:21 -0700 | [diff] [blame] | 1536 | if (prepared && mDrawState == HAS_DRAWN) { |
| 1537 | if (mLastHidden) { |
| 1538 | if (showSurfaceRobustlyLocked()) { |
| 1539 | markPreservedSurfaceForDestroy(); |
| 1540 | mAnimator.requestRemovalOfReplacedWindows(w); |
| 1541 | mLastHidden = false; |
| 1542 | if (mIsWallpaper) { |
| 1543 | w.dispatchWallpaperVisibility(true); |
| 1544 | } |
| 1545 | // This draw means the difference between unique content and mirroring. |
| 1546 | // Run another pass through performLayout to set mHasContent in the |
| 1547 | // LogicalDisplay. |
| 1548 | mAnimator.setPendingLayoutChanges(w.getDisplayId(), |
| 1549 | WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM); |
| 1550 | } else { |
| 1551 | w.setOrientationChanging(false); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1552 | } |
Robert Carr | 03206af | 2017-07-10 18:24:21 -0700 | [diff] [blame] | 1553 | } |
| 1554 | // We process mTurnOnScreen even for windows which have already |
| 1555 | // been shown, to handle cases where windows are not necessarily |
| 1556 | // hidden while the screen is turning off. |
| 1557 | // TODO(b/63773439): These cases should be eliminated, though we probably still |
| 1558 | // want to process mTurnOnScreen in this way for clarity. |
chaviw | 35d7de0 | 2017-08-23 12:29:02 -0700 | [diff] [blame] | 1559 | if (mWin.mTurnOnScreen && |
| 1560 | (mWin.mAppToken == null || mWin.mAppToken.canTurnScreenOn())) { |
Robert Carr | 03206af | 2017-07-10 18:24:21 -0700 | [diff] [blame] | 1561 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Show surface turning screen on: " + mWin); |
| 1562 | mWin.mTurnOnScreen = false; |
chaviw | d3bf08d | 2017-08-01 17:24:59 -0700 | [diff] [blame] | 1563 | |
| 1564 | // The window should only turn the screen on once per resume, but |
| 1565 | // prepareSurfaceLocked can be called multiple times. Set canTurnScreenOn to |
| 1566 | // 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] | 1567 | if (mWin.mAppToken != null) { |
| 1568 | mWin.mAppToken.setCanTurnScreenOn(false); |
| 1569 | } |
Bryce Lee | c4c8baa | 2017-09-06 14:55:48 -0700 | [diff] [blame] | 1570 | |
| 1571 | // We do not add {@code SET_TURN_ON_SCREEN} when the screen is already |
| 1572 | // interactive as the value may persist until the next animation, which could |
| 1573 | // potentially occurring while turning off the screen. This would lead to the |
| 1574 | // screen incorrectly turning back on. |
| 1575 | if (!mService.mPowerManager.isInteractive()) { |
| 1576 | mAnimator.mBulkUpdateParams |= SET_TURN_ON_SCREEN; |
| 1577 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1578 | } |
| 1579 | } |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 1580 | if (hasSurface()) { |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1581 | w.mToken.hasVisible = true; |
| 1582 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1583 | } else { |
Jorim Jaggi | 5c80c41 | 2016-04-19 20:03:47 -0700 | [diff] [blame] | 1584 | if (DEBUG_ANIM && isAnimationSet()) { |
Chong Zhang | e05db74 | 2016-02-16 16:58:37 -0800 | [diff] [blame] | 1585 | Slog.v(TAG, "prepareSurface: No changes in animation for " + this); |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 1586 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1587 | displayed = true; |
| 1588 | } |
| 1589 | |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1590 | if (w.getOrientationChanging()) { |
Jorim Jaggi | 38d44ec | 2017-06-14 16:04:59 -0700 | [diff] [blame] | 1591 | if (!w.isDrawnLw()) { |
| 1592 | mAnimator.mBulkUpdateParams &= ~SET_ORIENTATION_CHANGE_COMPLETE; |
| 1593 | mAnimator.mLastWindowFreezeSource = w; |
| 1594 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| 1595 | "Orientation continue waiting for draw in " + w); |
| 1596 | } else { |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1597 | w.setOrientationChanging(false); |
Jorim Jaggi | 38d44ec | 2017-06-14 16:04:59 -0700 | [diff] [blame] | 1598 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Orientation change complete in " + w); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1599 | } |
Jorim Jaggi | 38d44ec | 2017-06-14 16:04:59 -0700 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | if (displayed) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1603 | w.mToken.hasVisible = true; |
| 1604 | } |
| 1605 | } |
| 1606 | |
Craig Mautner | ef65501 | 2013-01-03 11:20:24 -0800 | [diff] [blame] | 1607 | void setTransparentRegionHintLocked(final Region region) { |
Wale Ogunwale | f9e0978 | 2015-11-09 12:42:37 -0800 | [diff] [blame] | 1608 | if (mSurfaceController == null) { |
| 1609 | Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true"); |
| 1610 | return; |
| 1611 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1612 | mSurfaceController.setTransparentRegionHint(region); |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 1613 | } |
| 1614 | |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 1615 | void setWallpaperOffset(Point shownPosition) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1616 | final LayoutParams attrs = mWin.getAttrs(); |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 1617 | final int left = shownPosition.x - attrs.surfaceInsets.left; |
| 1618 | final int top = shownPosition.y - attrs.surfaceInsets.top; |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1619 | |
| 1620 | try { |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 1621 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setWallpaperOffset"); |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 1622 | mService.openSurfaceTransaction(); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1623 | mSurfaceController.setPositionInTransaction(mWin.mFrame.left + left, |
| 1624 | mWin.mFrame.top + top, false); |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 1625 | applyCrop(null, null, false); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1626 | } catch (RuntimeException e) { |
| 1627 | Slog.w(TAG, "Error positioning surface of " + mWin |
| 1628 | + " pos=(" + left + "," + top + ")", e); |
| 1629 | } finally { |
Adrian Roos | 111aff9 | 2017-09-27 18:11:46 +0200 | [diff] [blame] | 1630 | mService.closeSurfaceTransaction("setWallpaperOffset"); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1631 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 1632 | "<<< CLOSE TRANSACTION setWallpaperOffset"); |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 1633 | } |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
John Reck | 80181b9 | 2015-05-19 11:09:32 -0700 | [diff] [blame] | 1636 | /** |
| 1637 | * Try to change the pixel format without recreating the surface. This |
| 1638 | * will be common in the case of changing from PixelFormat.OPAQUE to |
| 1639 | * PixelFormat.TRANSLUCENT in the hardware-accelerated case as both |
| 1640 | * requested formats resolve to the same underlying SurfaceControl format |
| 1641 | * @return True if format was succesfully changed, false otherwise |
| 1642 | */ |
| 1643 | boolean tryChangeFormatInPlaceLocked() { |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1644 | if (mSurfaceController == null) { |
John Reck | 80181b9 | 2015-05-19 11:09:32 -0700 | [diff] [blame] | 1645 | return false; |
| 1646 | } |
| 1647 | final LayoutParams attrs = mWin.getAttrs(); |
Wale Ogunwale | e7bf46b | 2015-09-30 09:19:28 -0700 | [diff] [blame] | 1648 | final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0; |
John Reck | 80181b9 | 2015-05-19 11:09:32 -0700 | [diff] [blame] | 1649 | final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format; |
| 1650 | if (format == mSurfaceFormat) { |
| 1651 | setOpaqueLocked(!PixelFormat.formatHasAlpha(attrs.format)); |
| 1652 | return true; |
| 1653 | } |
| 1654 | return false; |
| 1655 | } |
| 1656 | |
Craig Mautner | 6f61204 | 2014-09-07 13:13:23 -0700 | [diff] [blame] | 1657 | void setOpaqueLocked(boolean isOpaque) { |
Wale Ogunwale | f9e0978 | 2015-11-09 12:42:37 -0800 | [diff] [blame] | 1658 | if (mSurfaceController == null) { |
| 1659 | return; |
| 1660 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1661 | mSurfaceController.setOpaque(isOpaque); |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 1662 | } |
| 1663 | |
Wale Ogunwale | f5ad42f | 2015-06-12 13:59:03 -0700 | [diff] [blame] | 1664 | void setSecureLocked(boolean isSecure) { |
Wale Ogunwale | f9e0978 | 2015-11-09 12:42:37 -0800 | [diff] [blame] | 1665 | if (mSurfaceController == null) { |
| 1666 | return; |
| 1667 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1668 | mSurfaceController.setSecure(isSecure); |
Wale Ogunwale | f5ad42f | 2015-06-12 13:59:03 -0700 | [diff] [blame] | 1669 | } |
| 1670 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1671 | /** |
| 1672 | * Have the surface flinger show a surface, robustly dealing with |
| 1673 | * error conditions. In particular, if there is not enough memory |
| 1674 | * to show the surface, then we will try to get rid of other surfaces |
| 1675 | * in order to succeed. |
| 1676 | * |
| 1677 | * @return Returns true if the surface was successfully shown. |
| 1678 | */ |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 1679 | private boolean showSurfaceRobustlyLocked() { |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 1680 | if (mWin.getWindowConfiguration().windowsAreScaleable()) { |
Robert Carr | 1b5ea72 | 2016-04-20 13:23:28 -0700 | [diff] [blame] | 1681 | mSurfaceController.forceScaleableInTransaction(true); |
| 1682 | } |
| 1683 | |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1684 | boolean shown = mSurfaceController.showRobustlyInTransaction(); |
| 1685 | if (!shown) |
| 1686 | return false; |
| 1687 | |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1688 | return true; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1689 | } |
| 1690 | |
| 1691 | void applyEnterAnimationLocked() { |
Robert Carr | b439a63 | 2016-04-07 22:52:10 -0700 | [diff] [blame] | 1692 | // If we are the new part of a window replacement transition and we have requested |
| 1693 | // not to animate, we instead want to make it seamless, so we don't want to apply |
| 1694 | // an enter transition. |
| 1695 | if (mWin.mSkipEnterAnimationForSeamlessReplacement) { |
| 1696 | return; |
| 1697 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1698 | final int transit; |
| 1699 | if (mEnterAnimationPending) { |
| 1700 | mEnterAnimationPending = false; |
| 1701 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 1702 | } else { |
| 1703 | transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 1704 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1705 | applyAnimationLocked(transit, true); |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 1706 | //TODO (multidisplay): Magnification is supported only for the default display. |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1707 | if (mService.mAccessibilityController != null |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 1708 | && mWin.getDisplayId() == DEFAULT_DISPLAY) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1709 | mService.mAccessibilityController.onWindowTransitionLocked(mWin, transit); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 1710 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | /** |
| 1714 | * Choose the correct animation and set it to the passed WindowState. |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1715 | * @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] | 1716 | * then the animation will be app_starting_exit. Any other value loads the animation from |
| 1717 | * the switch statement below. |
| 1718 | * @param isEntrance The animation type the last time this was called. Used to keep from |
| 1719 | * loading the same animation twice. |
| 1720 | * @return true if an animation has been loaded. |
| 1721 | */ |
| 1722 | boolean applyAnimationLocked(int transit, boolean isEntrance) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1723 | if (mLocalAnimating && mAnimationIsEntrance == isEntrance) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1724 | // If we are trying to apply an animation, but already running |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 1725 | // an animation of the same type, then just leave that one alone. |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1726 | return true; |
| 1727 | } |
| 1728 | |
| 1729 | // Only apply an animation if the display isn't frozen. If it is |
| 1730 | // frozen, there is no reason to animate and it can cause strange |
| 1731 | // artifacts when we unfreeze the display if some different animation |
| 1732 | // is running. |
Chong Zhang | 8784be6 | 2016-06-28 15:25:07 -0700 | [diff] [blame] | 1733 | Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "WSA#applyAnimationLocked"); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1734 | if (mWin.mToken.okToAnimate()) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1735 | int anim = mPolicy.selectAnimationLw(mWin, transit); |
| 1736 | int attr = -1; |
| 1737 | Animation a = null; |
| 1738 | if (anim != 0) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1739 | a = anim != -1 ? AnimationUtils.loadAnimation(mContext, anim) : null; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1740 | } else { |
| 1741 | switch (transit) { |
| 1742 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 1743 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 1744 | break; |
| 1745 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 1746 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 1747 | break; |
| 1748 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 1749 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 1750 | break; |
| 1751 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 1752 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 1753 | break; |
| 1754 | } |
| 1755 | if (attr >= 0) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1756 | a = mService.mAppTransition.loadAnimationAttr(mWin.mAttrs, attr); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1757 | } |
| 1758 | } |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 1759 | if (DEBUG_ANIM) Slog.v(TAG, |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1760 | "applyAnimation: win=" + this |
| 1761 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 1762 | + " a=" + a |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 1763 | + " transit=" + transit |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 1764 | + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3)); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1765 | if (a != null) { |
Filip Gruszczynski | 198dcbf | 2016-01-18 10:02:00 -0800 | [diff] [blame] | 1766 | if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1767 | setAnimation(a); |
| 1768 | mAnimationIsEntrance = isEntrance; |
| 1769 | } |
| 1770 | } else { |
| 1771 | clearAnimation(); |
| 1772 | } |
Chong Zhang | 8784be6 | 2016-06-28 15:25:07 -0700 | [diff] [blame] | 1773 | Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); |
| 1774 | |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1775 | if (mWin.mAttrs.type == TYPE_INPUT_METHOD) { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 1776 | mWin.getDisplayContent().adjustForImeIfNeeded(); |
Jorim Jaggi | 7a4fd5e | 2016-04-14 19:55:35 -0700 | [diff] [blame] | 1777 | if (isEntrance) { |
| 1778 | mWin.setDisplayLayoutNeeded(); |
| 1779 | mService.mWindowPlacerLocked.requestTraversal(); |
| 1780 | } |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 1781 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1782 | return mAnimation != null; |
| 1783 | } |
| 1784 | |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 1785 | private void applyFadeoutDuringKeyguardExitAnimation() { |
| 1786 | long startTime = mAnimation.getStartTime(); |
| 1787 | long duration = mAnimation.getDuration(); |
| 1788 | long elapsed = mLastAnimationTime - startTime; |
| 1789 | long fadeDuration = duration - elapsed; |
| 1790 | if (fadeDuration <= 0) { |
| 1791 | // Never mind, this would be no visible animation, so abort the animation change. |
| 1792 | return; |
| 1793 | } |
| 1794 | AnimationSet newAnimation = new AnimationSet(false /* shareInterpolator */); |
| 1795 | newAnimation.setDuration(duration); |
| 1796 | newAnimation.setStartTime(startTime); |
| 1797 | newAnimation.addAnimation(mAnimation); |
| 1798 | Animation fadeOut = AnimationUtils.loadAnimation( |
| 1799 | mContext, com.android.internal.R.anim.app_starting_exit); |
| 1800 | fadeOut.setDuration(fadeDuration); |
| 1801 | fadeOut.setStartOffset(elapsed); |
| 1802 | newAnimation.addAnimation(fadeOut); |
Filip Gruszczynski | f52dd20 | 2015-11-15 20:36:38 -0800 | [diff] [blame] | 1803 | newAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(), mAnimDx, mAnimDy); |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 1804 | mAnimation = newAnimation; |
| 1805 | } |
| 1806 | |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 1807 | void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 1808 | final long token = proto.start(fieldId); |
| 1809 | mLastClipRect.writeToProto(proto, LAST_CLIP_RECT); |
| 1810 | if (mSurfaceController != null) { |
| 1811 | mSurfaceController.writeToProto(proto, SURFACE); |
| 1812 | } |
| 1813 | proto.end(token); |
| 1814 | } |
| 1815 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1816 | public void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
| 1817 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 1818 | || mAnimation != null) { |
| 1819 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 1820 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 1821 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
Wale Ogunwale | 6bab4cf | 2016-04-07 12:23:08 -0700 | [diff] [blame] | 1822 | pw.print(" mAnimation="); pw.print(mAnimation); |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 1823 | pw.print(" mStackClip="); pw.println(mStackClip); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1824 | } |
| 1825 | if (mHasTransformation || mHasLocalTransformation) { |
| 1826 | pw.print(prefix); pw.print("XForm: has="); |
| 1827 | pw.print(mHasTransformation); |
| 1828 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 1829 | pw.print(" "); mTransformation.printShortString(pw); |
| 1830 | pw.println(); |
| 1831 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1832 | if (mSurfaceController != null) { |
| 1833 | mSurfaceController.dump(pw, prefix, dumpAll); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1834 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1835 | if (dumpAll) { |
| 1836 | pw.print(prefix); pw.print("mDrawState="); pw.print(drawStateToString()); |
| 1837 | pw.print(prefix); pw.print(" mLastHidden="); pw.println(mLastHidden); |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 1838 | pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw); |
| 1839 | pw.print(" last="); mLastSystemDecorRect.printShortString(pw); |
Wale Ogunwale | 6bab4cf | 2016-04-07 12:23:08 -0700 | [diff] [blame] | 1840 | pw.print(" mHasClipRect="); pw.print(mHasClipRect); |
| 1841 | pw.print(" mLastClipRect="); mLastClipRect.printShortString(pw); |
| 1842 | |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 1843 | if (!mLastFinalClipRect.isEmpty()) { |
| 1844 | pw.print(" mLastFinalClipRect="); mLastFinalClipRect.printShortString(pw); |
| 1845 | } |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 1846 | pw.println(); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1847 | } |
| 1848 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1849 | if (mPendingDestroySurface != null) { |
| 1850 | pw.print(prefix); pw.print("mPendingDestroySurface="); |
| 1851 | pw.println(mPendingDestroySurface); |
| 1852 | } |
| 1853 | if (mSurfaceResized || mSurfaceDestroyDeferred) { |
| 1854 | pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized); |
| 1855 | pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred); |
| 1856 | } |
| 1857 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 1858 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 1859 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 1860 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 1861 | } |
| 1862 | if (mHaveMatrix || mWin.mGlobalScale != 1) { |
| 1863 | pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale); |
| 1864 | pw.print(" mDsDx="); pw.print(mDsDx); |
| 1865 | pw.print(" mDtDx="); pw.print(mDtDx); |
Robert Carr | 0edf18f | 2017-02-21 20:01:47 -0800 | [diff] [blame] | 1866 | pw.print(" mDtDy="); pw.print(mDtDy); |
| 1867 | pw.print(" mDsDy="); pw.println(mDsDy); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1868 | } |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 1869 | if (mAnimationStartDelayed) { |
| 1870 | pw.print(prefix); pw.print("mAnimationStartDelayed="); pw.print(mAnimationStartDelayed); |
| 1871 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1872 | } |
| 1873 | |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1874 | @Override |
| 1875 | public String toString() { |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 1876 | StringBuffer sb = new StringBuffer("WindowStateAnimator{"); |
| 1877 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 1878 | sb.append(' '); |
| 1879 | sb.append(mWin.mAttrs.getTitle()); |
| 1880 | sb.append('}'); |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1881 | return sb.toString(); |
| 1882 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1883 | |
| 1884 | void reclaimSomeSurfaceMemory(String operation, boolean secure) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1885 | mService.mRoot.reclaimSomeSurfaceMemory(this, operation, secure); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | boolean getShown() { |
| 1889 | if (mSurfaceController != null) { |
| 1890 | return mSurfaceController.getShown(); |
| 1891 | } |
| 1892 | return false; |
| 1893 | } |
| 1894 | |
| 1895 | void destroySurface() { |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 1896 | try { |
| 1897 | if (mSurfaceController != null) { |
| 1898 | mSurfaceController.destroyInTransaction(); |
| 1899 | } |
| 1900 | } catch (RuntimeException e) { |
| 1901 | Slog.w(TAG, "Exception thrown when destroying surface " + this |
| 1902 | + " surface " + mSurfaceController + " session " + mSession + ": " + e); |
| 1903 | } finally { |
| 1904 | mWin.setHasSurface(false); |
| 1905 | mSurfaceController = null; |
| 1906 | mDrawState = NO_SURFACE; |
| 1907 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1908 | } |
Filip Gruszczynski | f52dd20 | 2015-11-15 20:36:38 -0800 | [diff] [blame] | 1909 | |
| 1910 | void setMoveAnimation(int left, int top) { |
| 1911 | final Animation a = AnimationUtils.loadAnimation(mContext, |
| 1912 | com.android.internal.R.anim.window_move_from_decor); |
| 1913 | setAnimation(a); |
| 1914 | mAnimDx = mWin.mLastFrame.left - left; |
| 1915 | mAnimDy = mWin.mLastFrame.top - top; |
| 1916 | mAnimateMove = true; |
| 1917 | } |
Robert Carr | 679c807 | 2016-04-07 15:51:48 -0700 | [diff] [blame] | 1918 | |
| 1919 | void deferTransactionUntilParentFrame(long frameNumber) { |
| 1920 | if (!mWin.isChildWindow()) { |
| 1921 | return; |
| 1922 | } |
Robert Carr | 679c807 | 2016-04-07 15:51:48 -0700 | [diff] [blame] | 1923 | mSurfaceController.deferTransactionUntil( |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 1924 | mWin.getParentWindow().mWinAnimator.mSurfaceController.getHandle(), frameNumber); |
Robert Carr | 679c807 | 2016-04-07 15:51:48 -0700 | [diff] [blame] | 1925 | } |
| 1926 | |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 1927 | /** |
| 1928 | * Sometimes we need to synchronize the first frame of animation with some external event. |
| 1929 | * To achieve this, we prolong the start of the animation and keep producing the first frame of |
| 1930 | * the animation. |
| 1931 | */ |
| 1932 | private long getAnimationFrameTime(Animation animation, long currentTime) { |
| 1933 | if (mAnimationStartDelayed) { |
| 1934 | animation.setStartTime(currentTime); |
| 1935 | return currentTime + 1; |
| 1936 | } |
| 1937 | return currentTime; |
| 1938 | } |
| 1939 | |
| 1940 | void startDelayingAnimationStart() { |
| 1941 | mAnimationStartDelayed = true; |
| 1942 | } |
| 1943 | |
| 1944 | void endDelayingAnimationStart() { |
| 1945 | mAnimationStartDelayed = false; |
| 1946 | } |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 1947 | |
| 1948 | void seamlesslyRotateWindow(int oldRotation, int newRotation) { |
| 1949 | final WindowState w = mWin; |
| 1950 | if (!w.isVisibleNow() || w.mIsWallpaper) { |
| 1951 | return; |
| 1952 | } |
| 1953 | |
| 1954 | final Rect cropRect = mService.mTmpRect; |
| 1955 | final Rect displayRect = mService.mTmpRect2; |
| 1956 | final RectF frameRect = mService.mTmpRectF; |
| 1957 | final Matrix transform = mService.mTmpTransform; |
| 1958 | |
| 1959 | final float x = w.mFrame.left; |
| 1960 | final float y = w.mFrame.top; |
| 1961 | final float width = w.mFrame.width(); |
| 1962 | final float height = w.mFrame.height(); |
| 1963 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1964 | mService.getDefaultDisplayContentLocked().getBounds(displayRect); |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 1965 | final float displayWidth = displayRect.width(); |
| 1966 | final float displayHeight = displayRect.height(); |
| 1967 | |
| 1968 | // Compute a transform matrix to undo the coordinate space transformation, |
| 1969 | // and present the window at the same physical position it previously occupied. |
| 1970 | final int deltaRotation = DisplayContent.deltaRotation(newRotation, oldRotation); |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 1971 | DisplayContent.createRotationMatrix(deltaRotation, x, y, displayWidth, displayHeight, |
| 1972 | transform); |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 1973 | |
Robert Carr | 897215d | 2017-03-29 12:25:50 -0700 | [diff] [blame] | 1974 | // We just need to apply a rotation matrix to the window. For example |
| 1975 | // if we have a portrait window and rotate to landscape, the window is still portrait |
| 1976 | // and now extends off the bottom of the screen (and only halfway across). Essentially we |
| 1977 | // apply a transform to display the current buffer at it's old position |
| 1978 | // (in the new coordinate space). We then freeze layer updates until the resize |
| 1979 | // occurs, at which point we undo, them. |
| 1980 | mService.markForSeamlessRotation(w, true); |
| 1981 | transform.getValues(mService.mTmpFloats); |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 1982 | |
Robert Carr | 897215d | 2017-03-29 12:25:50 -0700 | [diff] [blame] | 1983 | float DsDx = mService.mTmpFloats[Matrix.MSCALE_X]; |
| 1984 | float DtDx = mService.mTmpFloats[Matrix.MSKEW_Y]; |
| 1985 | float DtDy = mService.mTmpFloats[Matrix.MSKEW_X]; |
| 1986 | float DsDy = mService.mTmpFloats[Matrix.MSCALE_Y]; |
| 1987 | float nx = mService.mTmpFloats[Matrix.MTRANS_X]; |
| 1988 | float ny = mService.mTmpFloats[Matrix.MTRANS_Y]; |
| 1989 | mSurfaceController.setPositionInTransaction(nx, ny, false); |
| 1990 | mSurfaceController.setMatrixInTransaction(DsDx * w.mHScale, |
| 1991 | DtDx * w.mVScale, |
| 1992 | DtDy * w.mHScale, |
| 1993 | DsDy * w.mVScale, false); |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 1994 | } |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 1995 | |
| 1996 | void enableSurfaceTrace(FileDescriptor fd) { |
| 1997 | if (mSurfaceController != null) { |
| 1998 | mSurfaceController.installRemoteTrace(fd); |
| 1999 | } |
| 2000 | } |
| 2001 | |
| 2002 | void disableSurfaceTrace() { |
| 2003 | if (mSurfaceController != null) { |
| 2004 | try { |
| 2005 | mSurfaceController.removeRemoteTrace(); |
| 2006 | } catch (ClassCastException e) { |
| 2007 | Slog.e(TAG, "Disable surface trace for " + this + " but its not enabled"); |
| 2008 | } |
| 2009 | } |
| 2010 | } |
Robert Carr | 8f0a3ad | 2017-02-15 19:30:28 -0800 | [diff] [blame] | 2011 | |
| 2012 | /** The force-scaled state for a given window can persist past |
| 2013 | * the state for it's stack as the windows complete resizing |
| 2014 | * independently of one another. |
| 2015 | */ |
| 2016 | boolean isForceScaled() { |
| 2017 | final Task task = mWin.getTask(); |
| 2018 | if (task != null && task.mStack.isForceScaled()) { |
| 2019 | return true; |
| 2020 | } |
| 2021 | return mForceScaleUntilResize; |
| 2022 | } |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 2023 | |
| 2024 | void detachChildren() { |
| 2025 | if (mSurfaceController != null) { |
| 2026 | mSurfaceController.detachChildren(); |
| 2027 | } |
| 2028 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 2029 | } |