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