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