Craig Mautner | c2c0a61 | 2014-02-20 20:25:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 19 | import static android.view.Display.DEFAULT_DISPLAY; |
Wale Ogunwale | e7bf46b | 2015-09-30 09:19:28 -0700 | [diff] [blame] | 20 | import static android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 21 | import static android.view.WindowManager.LayoutParams.FLAG_SCALED; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 22 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 23 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
| 24 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS; |
| 25 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS; |
| 26 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
| 27 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW; |
| 28 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE; |
| 29 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
| 30 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER; |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 31 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_CROP; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 32 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS; |
| 33 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC; |
| 34 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS; |
| 35 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 36 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 37 | import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER; |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 38 | import static com.android.server.wm.WindowManagerService.localLOGV; |
Filip Gruszczynski | 198dcbf | 2016-01-18 10:02:00 -0800 | [diff] [blame] | 39 | import static com.android.server.wm.WindowManagerService.logWithStack; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 40 | import static com.android.server.wm.WindowState.DRAG_RESIZE_MODE_DOCKED_DIVIDER; |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 41 | import static com.android.server.wm.WindowState.DRAG_RESIZE_MODE_FREEFORM; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 42 | import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE; |
| 43 | import static com.android.server.wm.WindowSurfacePlacer.SET_TURN_ON_SCREEN; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 44 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 45 | import android.content.Context; |
| 46 | import android.graphics.Matrix; |
| 47 | import android.graphics.PixelFormat; |
Craig Mautner | 7358fbf | 2012-04-12 21:06:33 -0700 | [diff] [blame] | 48 | import android.graphics.Point; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 49 | import android.graphics.Rect; |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 50 | import android.graphics.Region; |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 51 | import android.os.Debug; |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 52 | import android.os.RemoteException; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 53 | import android.util.Slog; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 54 | import android.view.DisplayInfo; |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 55 | import android.view.MagnificationSpec; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 56 | import android.view.Surface.OutOfResourcesException; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 57 | import android.view.SurfaceControl; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 58 | import android.view.WindowManager; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 59 | import android.view.WindowManager.LayoutParams; |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 60 | import android.view.WindowManagerPolicy; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 61 | import android.view.animation.Animation; |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 62 | import android.view.animation.AnimationSet; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 63 | import android.view.animation.AnimationUtils; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 64 | import android.view.animation.Transformation; |
| 65 | |
| 66 | import com.android.server.wm.WindowManagerService.H; |
| 67 | |
| 68 | import java.io.PrintWriter; |
| 69 | |
| 70 | /** |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 71 | * Keep track of animations and surface operations for a single WindowState. |
| 72 | **/ |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 73 | class WindowStateAnimator { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 74 | static final String TAG = TAG_WITH_CLASS_NAME ? "WindowStateAnimator" : TAG_WM; |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 75 | static final int WINDOW_FREEZE_LAYER = TYPE_LAYER_MULTIPLIER * 200; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 76 | |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 77 | // Unchanging local convenience fields. |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 78 | final WindowManagerService mService; |
| 79 | final WindowState mWin; |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 80 | final WindowStateAnimator mAttachedWinAnimator; |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 81 | final WindowAnimator mAnimator; |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 82 | AppWindowAnimator mAppAnimator; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 83 | final Session mSession; |
| 84 | final WindowManagerPolicy mPolicy; |
| 85 | final Context mContext; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 86 | final boolean mIsWallpaper; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 87 | final WallpaperController mWallpaperControllerLocked; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 88 | |
| 89 | // Currently running animation. |
| 90 | boolean mAnimating; |
| 91 | boolean mLocalAnimating; |
| 92 | Animation mAnimation; |
| 93 | boolean mAnimationIsEntrance; |
| 94 | boolean mHasTransformation; |
| 95 | boolean mHasLocalTransformation; |
| 96 | final Transformation mTransformation = new Transformation(); |
| 97 | boolean mWasAnimating; // Were we animating going into the most recent animation step? |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 98 | int mAnimLayer; |
| 99 | int mLastLayer; |
Jorim Jaggi | 44f60cc | 2014-11-07 20:33:51 +0100 | [diff] [blame] | 100 | long mAnimationStartTime; |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 101 | long mLastAnimationTime; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 102 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 103 | /** |
| 104 | * Set when we have changed the size of the surface, to know that |
| 105 | * we must tell them application to resize (and thus redraw itself). |
| 106 | */ |
| 107 | boolean mSurfaceResized; |
Chong Zhang | 5b2f199 | 2015-11-13 15:40:36 -0800 | [diff] [blame] | 108 | /** |
| 109 | * Whether we should inform the client on next relayoutWindow that |
| 110 | * the surface has been resized since last time. |
| 111 | */ |
| 112 | boolean mReportSurfaceResized; |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 113 | WindowSurfaceController mSurfaceController; |
Filip Gruszczynski | 10a80e0 | 2015-11-06 09:21:17 -0800 | [diff] [blame] | 114 | private WindowSurfaceController mPendingDestroySurface; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 115 | |
| 116 | /** |
| 117 | * Set if the client has asked that the destroy of its surface be delayed |
| 118 | * until it explicitly says it is okay. |
| 119 | */ |
| 120 | boolean mSurfaceDestroyDeferred; |
| 121 | |
Filip Gruszczynski | 10a80e0 | 2015-11-06 09:21:17 -0800 | [diff] [blame] | 122 | private boolean mDestroyPreservedSurfaceUponRedraw; |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 123 | float mShownAlpha = 0; |
| 124 | float mAlpha = 0; |
| 125 | float mLastAlpha = 0; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 126 | |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 127 | boolean mHasClipRect; |
| 128 | Rect mClipRect = new Rect(); |
| 129 | Rect mTmpClipRect = new Rect(); |
| 130 | Rect mLastClipRect = new Rect(); |
Filip Gruszczynski | 4b8eea7 | 2015-09-14 18:16:19 -0700 | [diff] [blame] | 131 | Rect mTmpStackBounds = new Rect(); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 132 | |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 133 | /** |
| 134 | * This is rectangle of the window's surface that is not covered by |
| 135 | * system decorations. |
| 136 | */ |
| 137 | private final Rect mSystemDecorRect = new Rect(); |
| 138 | private final Rect mLastSystemDecorRect = new Rect(); |
| 139 | |
Filip Gruszczynski | f52dd20 | 2015-11-15 20:36:38 -0800 | [diff] [blame] | 140 | // Used to save animation distances between the time they are calculated and when they are used. |
| 141 | private int mAnimDx; |
| 142 | private int mAnimDy; |
Jorim Jaggi | c5af4f8 | 2015-07-01 17:16:27 -0700 | [diff] [blame] | 143 | |
| 144 | /** Is the next animation to be started a window move animation? */ |
Filip Gruszczynski | f52dd20 | 2015-11-15 20:36:38 -0800 | [diff] [blame] | 145 | private boolean mAnimateMove = false; |
Jorim Jaggi | c5af4f8 | 2015-07-01 17:16:27 -0700 | [diff] [blame] | 146 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 147 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 148 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 149 | |
| 150 | boolean mHaveMatrix; |
| 151 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 152 | // Set to true if, when the window gets displayed, it should perform |
| 153 | // an enter animation. |
| 154 | boolean mEnterAnimationPending; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 155 | |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 156 | /** Used to indicate that this window is undergoing an enter animation. Used for system |
| 157 | * windows to make the callback to View.dispatchOnWindowShownCallback(). Set when the |
| 158 | * window is first added or shown, cleared when the callback has been made. */ |
| 159 | boolean mEnteringAnimation; |
| 160 | |
Jorim Jaggi | 44f60cc | 2014-11-07 20:33:51 +0100 | [diff] [blame] | 161 | boolean mKeyguardGoingAwayAnimation; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 162 | |
John Reck | 80181b9 | 2015-05-19 11:09:32 -0700 | [diff] [blame] | 163 | /** The pixel format of the underlying SurfaceControl */ |
| 164 | int mSurfaceFormat; |
| 165 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 166 | /** This is set when there is no Surface */ |
| 167 | static final int NO_SURFACE = 0; |
| 168 | /** This is set after the Surface has been created but before the window has been drawn. During |
| 169 | * this time the surface is hidden. */ |
| 170 | static final int DRAW_PENDING = 1; |
| 171 | /** This is set after the window has finished drawing for the first time but before its surface |
| 172 | * is shown. The surface will be displayed when the next layout is run. */ |
| 173 | static final int COMMIT_DRAW_PENDING = 2; |
| 174 | /** This is set during the time after the window's drawing has been committed, and before its |
| 175 | * surface is actually shown. It is used to delay showing the surface until all windows in a |
| 176 | * token are ready to be shown. */ |
| 177 | static final int READY_TO_SHOW = 3; |
| 178 | /** Set when the window has been shown in the screen the first time. */ |
| 179 | static final int HAS_DRAWN = 4; |
Adrian Roos | 3eeb4e6 | 2014-05-19 12:43:26 +0200 | [diff] [blame] | 180 | |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 181 | String drawStateToString() { |
| 182 | switch (mDrawState) { |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 183 | case NO_SURFACE: return "NO_SURFACE"; |
| 184 | case DRAW_PENDING: return "DRAW_PENDING"; |
| 185 | case COMMIT_DRAW_PENDING: return "COMMIT_DRAW_PENDING"; |
| 186 | case READY_TO_SHOW: return "READY_TO_SHOW"; |
| 187 | case HAS_DRAWN: return "HAS_DRAWN"; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 188 | default: return Integer.toString(mDrawState); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 189 | } |
| 190 | } |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 191 | int mDrawState; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 192 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 193 | /** Was this window last hidden? */ |
| 194 | boolean mLastHidden; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 195 | |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 196 | int mAttrType; |
| 197 | |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 198 | private final Rect mTmpSize = new Rect(); |
| 199 | |
Craig Mautner | c431e89 | 2015-02-11 13:14:26 -0800 | [diff] [blame] | 200 | WindowStateAnimator(final WindowState win) { |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 201 | final WindowManagerService service = win.mService; |
| 202 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 203 | mService = service; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 204 | mAnimator = service.mAnimator; |
| 205 | mPolicy = service.mPolicy; |
| 206 | mContext = service.mContext; |
Craig Mautner | d3849f5 | 2014-03-27 13:19:29 -0700 | [diff] [blame] | 207 | final DisplayContent displayContent = win.getDisplayContent(); |
| 208 | if (displayContent != null) { |
| 209 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
Filip Gruszczynski | f52dd20 | 2015-11-15 20:36:38 -0800 | [diff] [blame] | 210 | mAnimDx = displayInfo.appWidth; |
| 211 | mAnimDy = displayInfo.appHeight; |
Craig Mautner | d3849f5 | 2014-03-27 13:19:29 -0700 | [diff] [blame] | 212 | } else { |
| 213 | Slog.w(TAG, "WindowStateAnimator ctor: Display has been removed"); |
| 214 | // This is checked on return and dealt with. |
| 215 | } |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 216 | |
| 217 | mWin = win; |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 218 | mAttachedWinAnimator = win.mAttachedWindow == null |
| 219 | ? null : win.mAttachedWindow.mWinAnimator; |
| 220 | mAppAnimator = win.mAppToken == null ? null : win.mAppToken.mAppAnimator; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 221 | mSession = win.mSession; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 222 | mAttrType = win.mAttrs.type; |
| 223 | mIsWallpaper = win.mIsWallpaper; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 224 | mWallpaperControllerLocked = mService.mWallpaperControllerLocked; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Jorim Jaggi | 44f60cc | 2014-11-07 20:33:51 +0100 | [diff] [blame] | 227 | public void setAnimation(Animation anim, long startTime) { |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 228 | if (localLOGV) Slog.v(TAG, "Setting animation in " + this + ": " + anim); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 229 | mAnimating = false; |
| 230 | mLocalAnimating = false; |
| 231 | mAnimation = anim; |
| 232 | mAnimation.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION); |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 233 | mAnimation.scaleCurrentDuration(mService.getWindowAnimationScaleLocked()); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 234 | // Start out animation gone if window is gone, or visible if window is visible. |
| 235 | mTransformation.clear(); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 236 | mTransformation.setAlpha(mLastHidden ? 0 : 1); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 237 | mHasLocalTransformation = true; |
Jorim Jaggi | 44f60cc | 2014-11-07 20:33:51 +0100 | [diff] [blame] | 238 | mAnimationStartTime = startTime; |
| 239 | } |
| 240 | |
| 241 | public void setAnimation(Animation anim) { |
| 242 | setAnimation(anim, -1); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | public void clearAnimation() { |
| 246 | if (mAnimation != null) { |
| 247 | mAnimating = true; |
| 248 | mLocalAnimating = false; |
| 249 | mAnimation.cancel(); |
| 250 | mAnimation = null; |
Jorim Jaggi | 44f60cc | 2014-11-07 20:33:51 +0100 | [diff] [blame] | 251 | mKeyguardGoingAwayAnimation = false; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | |
| 255 | /** Is the window or its container currently animating? */ |
| 256 | boolean isAnimating() { |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 257 | return mAnimation != null |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 258 | || (mAttachedWinAnimator != null && mAttachedWinAnimator.mAnimation != null) |
Jorim Jaggi | 3787561 | 2015-02-19 21:05:31 +0100 | [diff] [blame] | 259 | || (mAppAnimator != null && mAppAnimator.isAnimating()); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 262 | /** Is the window animating the DummyAnimation? */ |
| 263 | boolean isDummyAnimation() { |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 264 | return mAppAnimator != null |
| 265 | && mAppAnimator.animation == AppWindowAnimator.sDummyAnimation; |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Stefan Kuhne | 7dcf08c | 2015-06-05 16:25:10 -0700 | [diff] [blame] | 268 | /** Is this window currently set to animate or currently animating? */ |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 269 | boolean isWindowAnimating() { |
| 270 | return mAnimation != null; |
| 271 | } |
| 272 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 273 | void cancelExitAnimationForNextAnimationLocked() { |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 274 | if (DEBUG_ANIM) Slog.d(TAG, |
| 275 | "cancelExitAnimationForNextAnimationLocked: " + mWin); |
| 276 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 277 | if (mAnimation != null) { |
| 278 | mAnimation.cancel(); |
| 279 | mAnimation = null; |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 280 | mLocalAnimating = false; |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 281 | mWin.destroyOrSaveSurface(); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 282 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | private boolean stepAnimation(long currentTime) { |
| 286 | if ((mAnimation == null) || !mLocalAnimating) { |
| 287 | return false; |
| 288 | } |
| 289 | mTransformation.clear(); |
| 290 | final boolean more = mAnimation.getTransformation(currentTime, mTransformation); |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 291 | if (false && DEBUG_ANIM) Slog.v(TAG, "Stepped animation in " + this + ": more=" + more |
| 292 | + ", xform=" + mTransformation); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 293 | return more; |
| 294 | } |
| 295 | |
| 296 | // This must be called while inside a transaction. Returns true if |
| 297 | // there is more animation to run. |
| 298 | boolean stepAnimationLocked(long currentTime) { |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 299 | // Save the animation state as it was before this step so WindowManagerService can tell if |
| 300 | // we just started or just stopped animating by comparing mWasAnimating with isAnimating(). |
| 301 | mWasAnimating = mAnimating; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 302 | final DisplayContent displayContent = mWin.getDisplayContent(); |
| 303 | if (displayContent != null && mService.okToDisplay()) { |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 304 | // We will run animations as long as the display isn't frozen. |
| 305 | |
| 306 | if (mWin.isDrawnLw() && mAnimation != null) { |
| 307 | mHasTransformation = true; |
| 308 | mHasLocalTransformation = true; |
| 309 | if (!mLocalAnimating) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 310 | if (DEBUG_ANIM) Slog.v( |
| 311 | TAG, "Starting animation in " + this + |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 312 | " @ " + currentTime + ": ww=" + mWin.mFrame.width() + |
| 313 | " wh=" + mWin.mFrame.height() + |
Filip Gruszczynski | f52dd20 | 2015-11-15 20:36:38 -0800 | [diff] [blame] | 314 | " dx=" + mAnimDx + " dy=" + mAnimDy + |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 315 | " scale=" + mService.getWindowAnimationScaleLocked()); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 316 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
tiger_huang | b7f3f92 | 2015-04-27 20:36:46 +0800 | [diff] [blame] | 317 | if (mAnimateMove) { |
| 318 | mAnimateMove = false; |
| 319 | mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(), |
Filip Gruszczynski | f52dd20 | 2015-11-15 20:36:38 -0800 | [diff] [blame] | 320 | mAnimDx, mAnimDy); |
tiger_huang | b7f3f92 | 2015-04-27 20:36:46 +0800 | [diff] [blame] | 321 | } else { |
| 322 | mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(), |
| 323 | displayInfo.appWidth, displayInfo.appHeight); |
| 324 | } |
Filip Gruszczynski | f52dd20 | 2015-11-15 20:36:38 -0800 | [diff] [blame] | 325 | mAnimDx = displayInfo.appWidth; |
| 326 | mAnimDy = displayInfo.appHeight; |
Jorim Jaggi | 44f60cc | 2014-11-07 20:33:51 +0100 | [diff] [blame] | 327 | mAnimation.setStartTime(mAnimationStartTime != -1 |
| 328 | ? mAnimationStartTime |
| 329 | : currentTime); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 330 | mLocalAnimating = true; |
| 331 | mAnimating = true; |
| 332 | } |
| 333 | if ((mAnimation != null) && mLocalAnimating) { |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 334 | mLastAnimationTime = currentTime; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 335 | if (stepAnimation(currentTime)) { |
| 336 | return true; |
| 337 | } |
| 338 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 339 | if (DEBUG_ANIM) Slog.v( |
| 340 | TAG, "Finished animation in " + this + |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 341 | " @ " + currentTime); |
| 342 | //WindowManagerService.this.dump(); |
| 343 | } |
| 344 | mHasLocalTransformation = false; |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 345 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppAnimator != null |
| 346 | && mAppAnimator.animation != null) { |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 347 | // When our app token is animating, we kind-of pretend like |
| 348 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 349 | // part of this check means that we will only do this if |
| 350 | // our window is not currently exiting, or it is not |
| 351 | // locally animating itself. The idea being that one that |
| 352 | // is exiting and doing a local animation should be removed |
| 353 | // once that animation is done. |
| 354 | mAnimating = true; |
| 355 | mHasTransformation = true; |
| 356 | mTransformation.clear(); |
| 357 | return false; |
| 358 | } else if (mHasTransformation) { |
| 359 | // Little trick to get through the path below to act like |
| 360 | // we have finished an animation. |
| 361 | mAnimating = true; |
| 362 | } else if (isAnimating()) { |
| 363 | mAnimating = true; |
| 364 | } |
| 365 | } else if (mAnimation != null) { |
| 366 | // If the display is frozen, and there is a pending animation, |
| 367 | // clear it and make sure we run the cleanup code. |
| 368 | mAnimating = true; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | if (!mAnimating && !mLocalAnimating) { |
| 372 | return false; |
| 373 | } |
| 374 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 375 | // Done animating, clean up. |
| 376 | if (DEBUG_ANIM) Slog.v( |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 377 | TAG, "Animation done in " + this + ": exiting=" + mWin.mAnimatingExit |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 378 | + ", reportedVisible=" |
| 379 | + (mWin.mAppToken != null ? mWin.mAppToken.reportedVisible : false)); |
| 380 | |
| 381 | mAnimating = false; |
Jorim Jaggi | 44f60cc | 2014-11-07 20:33:51 +0100 | [diff] [blame] | 382 | mKeyguardGoingAwayAnimation = false; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 383 | mLocalAnimating = false; |
| 384 | if (mAnimation != null) { |
| 385 | mAnimation.cancel(); |
| 386 | mAnimation = null; |
| 387 | } |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 388 | if (mAnimator.mWindowDetachedWallpaper == mWin) { |
| 389 | mAnimator.mWindowDetachedWallpaper = null; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 390 | } |
Filip Gruszczynski | 92e432c | 2015-12-15 19:17:09 -0800 | [diff] [blame] | 391 | mAnimLayer = mWin.mLayer |
| 392 | + mService.mLayersController.getSpecialWindowAnimLayerAdjustment(mWin); |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 393 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this + " anim layer: " + mAnimLayer); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 394 | mHasTransformation = false; |
| 395 | mHasLocalTransformation = false; |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 396 | mWin.checkPolicyVisibilityChange(); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 397 | mTransformation.clear(); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 398 | if (mDrawState == HAS_DRAWN |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 399 | && mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 400 | && mWin.mAppToken != null |
| 401 | && mWin.mAppToken.firstWindowDrawn |
| 402 | && mWin.mAppToken.startingData != null) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 403 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 404 | + mWin.mToken + ": first real window done animating"); |
| 405 | mService.mFinishedStarting.add(mWin.mAppToken); |
| 406 | mService.mH.sendEmptyMessage(H.FINISHED_STARTING); |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 407 | } else if (mAttrType == LayoutParams.TYPE_STATUS_BAR && mWin.mPolicyVisibility) { |
| 408 | // Upon completion of a not-visible to visible status bar animation a relayout is |
| 409 | // required. |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 410 | if (displayContent != null) { |
| 411 | displayContent.layoutNeeded = true; |
| 412 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | finishExit(); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 416 | final int displayId = mWin.getDisplayId(); |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 417 | mAnimator.setPendingLayoutChanges(displayId, WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM); |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 418 | if (DEBUG_LAYOUT_REPEATS) |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 419 | mService.mWindowPlacerLocked.debugLayoutRepeats( |
| 420 | "WindowStateAnimator", mAnimator.getPendingLayoutChanges(displayId)); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 421 | |
| 422 | if (mWin.mAppToken != null) { |
| 423 | mWin.mAppToken.updateReportedVisibilityLocked(); |
| 424 | } |
| 425 | |
| 426 | return false; |
| 427 | } |
| 428 | |
| 429 | void finishExit() { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 430 | if (DEBUG_ANIM) Slog.v( |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 431 | TAG, "finishExit in " + this |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 432 | + ": exiting=" + mWin.mAnimatingExit |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 433 | + " remove=" + mWin.mRemoveOnExit |
| 434 | + " windowAnimating=" + isWindowAnimating()); |
| 435 | |
| 436 | final int N = mWin.mChildWindows.size(); |
| 437 | for (int i=0; i<N; i++) { |
| 438 | mWin.mChildWindows.get(i).mWinAnimator.finishExit(); |
| 439 | } |
| 440 | |
Filip Gruszczynski | 57f76f1 | 2015-11-04 16:10:54 -0800 | [diff] [blame] | 441 | if (mEnteringAnimation) { |
| 442 | mEnteringAnimation = false; |
| 443 | mService.requestTraversal(); |
| 444 | // System windows don't have an activity and an app token as a result, but need a way |
| 445 | // to be informed about their entrance animation end. |
| 446 | if (mWin.mAppToken == null) { |
| 447 | try { |
| 448 | mWin.mClient.dispatchWindowShown(); |
| 449 | } catch (RemoteException e) { |
| 450 | } |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 451 | } |
| 452 | } |
| 453 | |
Svetoslav | 75b55d0 | 2014-12-03 16:26:35 -0800 | [diff] [blame] | 454 | if (!isWindowAnimating()) { |
| 455 | //TODO (multidisplay): Accessibility is supported only for the default display. |
| 456 | if (mService.mAccessibilityController != null |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 457 | && mWin.getDisplayId() == DEFAULT_DISPLAY) { |
Svetoslav | 75b55d0 | 2014-12-03 16:26:35 -0800 | [diff] [blame] | 458 | mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(); |
| 459 | } |
| 460 | } |
| 461 | |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 462 | if (!mWin.mAnimatingExit) { |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 463 | return; |
| 464 | } |
| 465 | |
| 466 | if (isWindowAnimating()) { |
| 467 | return; |
| 468 | } |
| 469 | |
Filip Gruszczynski | 19723a4 | 2015-11-25 15:01:48 -0800 | [diff] [blame] | 470 | if (WindowManagerService.localLOGV) Slog.v( |
| 471 | TAG, "Exit animation finished in " + this |
| 472 | + ": remove=" + mWin.mRemoveOnExit); |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 473 | |
| 474 | |
| 475 | mWin.mDestroying = true; |
| 476 | |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 477 | final boolean hasSurface = hasSurface(); |
| 478 | if (hasSurface) { |
| 479 | hide("finishExit"); |
| 480 | } |
| 481 | |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 482 | // If we have an app token, we ask it to destroy the surface for us, |
| 483 | // so that it can take care to ensure the activity has actually stopped |
| 484 | // and the surface is not still in use. Otherwise we add the service to |
| 485 | // mDestroySurface and allow it to be processed in our next transaction. |
| 486 | if (mWin.mAppToken != null) { |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 487 | mWin.mAppToken.destroySurfaces(); |
| 488 | } else { |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 489 | if (hasSurface) { |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 490 | mService.mDestroySurface.add(mWin); |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 491 | } |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 492 | if (mWin.mRemoveOnExit) { |
| 493 | mService.mPendingRemove.add(mWin); |
| 494 | mWin.mRemoveOnExit = false; |
| 495 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 496 | } |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 497 | mWin.mAnimatingExit = false; |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 498 | mWallpaperControllerLocked.hideWallpapers(mWin); |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Filip Gruszczynski | 63a35e2 | 2015-11-05 15:38:59 -0800 | [diff] [blame] | 501 | void hide(String reason) { |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 502 | if (!mLastHidden) { |
| 503 | //dump(); |
| 504 | mLastHidden = true; |
Wale Ogunwale | f9e0978 | 2015-11-09 12:42:37 -0800 | [diff] [blame] | 505 | if (mSurfaceController != null) { |
| 506 | mSurfaceController.hideInTransaction(reason); |
| 507 | } |
Craig Mautner | 0afddcb | 2012-05-08 15:38:00 -0700 | [diff] [blame] | 508 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 511 | boolean finishDrawingLocked() { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 512 | final boolean startingWindow = |
| 513 | mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 514 | if (DEBUG_STARTING_WINDOW && startingWindow) { |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 515 | Slog.v(TAG, "Finishing drawing window " + mWin + ": mDrawState=" |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 516 | + drawStateToString()); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 517 | } |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 518 | if (mWin.mAppToken != null && mWin.mAppToken.mAnimatingWithSavedSurface) { |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 519 | // App has drawn something to its windows, we're no longer animating with |
| 520 | // the saved surfaces. If the user exits now, we only want to save again |
| 521 | // if allDrawn is true. |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 522 | if (DEBUG_ANIM) Slog.d(TAG, |
| 523 | "finishDrawingLocked: mAnimatingWithSavedSurface=false " + mWin); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 524 | mWin.mAppToken.mAnimatingWithSavedSurface = false; |
| 525 | } |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 526 | if (mDrawState == DRAW_PENDING) { |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 527 | if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || SHOW_TRANSACTIONS || DEBUG_ORIENTATION) |
Chong Zhang | 5b2f199 | 2015-11-13 15:40:36 -0800 | [diff] [blame] | 528 | Slog.v(TAG, "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING " + mWin + " in " |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 529 | + mSurfaceController); |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 530 | if (DEBUG_STARTING_WINDOW && startingWindow) { |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 531 | Slog.v(TAG, "Draw state now committed in " + mWin); |
| 532 | } |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 533 | mDrawState = COMMIT_DRAW_PENDING; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 534 | return true; |
| 535 | } |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 536 | |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 537 | return false; |
| 538 | } |
| 539 | |
| 540 | // This must be called while inside a transaction. |
Craig Mautner | c431e89 | 2015-02-11 13:14:26 -0800 | [diff] [blame] | 541 | boolean commitFinishDrawingLocked() { |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 542 | if (DEBUG_STARTING_WINDOW && |
| 543 | mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 544 | Slog.i(TAG, "commitFinishDrawingLocked: " + mWin + " cur mDrawState=" |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 545 | + drawStateToString()); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 546 | } |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 547 | if (mDrawState != COMMIT_DRAW_PENDING && mDrawState != READY_TO_SHOW) { |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 548 | return false; |
| 549 | } |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 550 | if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) { |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 551 | Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurfaceController); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 552 | } |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 553 | mDrawState = READY_TO_SHOW; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 554 | boolean result = false; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 555 | final AppWindowToken atoken = mWin.mAppToken; |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 556 | if (atoken == null || atoken.allDrawn || mWin.mAttrs.type == TYPE_APPLICATION_STARTING) { |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 557 | result = performShowLocked(); |
| 558 | } |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 559 | return result; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 562 | void preserveSurfaceLocked() { |
| 563 | if (mDestroyPreservedSurfaceUponRedraw) { |
Chong Zhang | b9b0fec | 2016-02-11 18:51:51 -0800 | [diff] [blame] | 564 | // This could happen when switching the surface mode very fast. For example, |
| 565 | // we preserved a surface when dragResizing changed to true. Then before the |
| 566 | // preserved surface is removed, dragResizing changed to false again. |
| 567 | // In this case, we need to leave the preserved surface alone, and destroy |
| 568 | // the actual surface, so that the createSurface call could create a surface |
| 569 | // of the proper size. The preserved surface will still be removed when client |
| 570 | // finishes drawing to the new surface. |
| 571 | mSurfaceDestroyDeferred = false; |
| 572 | destroySurfaceLocked(); |
| 573 | mSurfaceDestroyDeferred = true; |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 574 | return; |
| 575 | } |
Filip Gruszczynski | 198dcbf | 2016-01-18 10:02:00 -0800 | [diff] [blame] | 576 | if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, "SET FREEZE LAYER", false); |
Wale Ogunwale | f9e0978 | 2015-11-09 12:42:37 -0800 | [diff] [blame] | 577 | if (mSurfaceController != null) { |
| 578 | mSurfaceController.setLayer(mAnimLayer + 1); |
| 579 | } |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 580 | mDestroyPreservedSurfaceUponRedraw = true; |
| 581 | mSurfaceDestroyDeferred = true; |
| 582 | destroySurfaceLocked(); |
| 583 | } |
| 584 | |
| 585 | void destroyPreservedSurfaceLocked() { |
| 586 | if (!mDestroyPreservedSurfaceUponRedraw) { |
| 587 | return; |
| 588 | } |
| 589 | destroyDeferredSurfaceLocked(); |
| 590 | mDestroyPreservedSurfaceUponRedraw = false; |
| 591 | } |
| 592 | |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 593 | WindowSurfaceController createSurfaceLocked() { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 594 | final WindowState w = mWin; |
Chong Zhang | a8975bd | 2016-01-28 17:13:47 -0800 | [diff] [blame] | 595 | if (w.hasSavedSurface()) { |
Chong Zhang | 0464a93 | 2016-02-03 11:47:16 -0800 | [diff] [blame] | 596 | if (DEBUG_ANIM) Slog.i(TAG, |
| 597 | "createSurface: " + this + ": called when we had a saved surface"); |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 598 | w.restoreSavedSurface(); |
| 599 | return mSurfaceController; |
Chong Zhang | a8975bd | 2016-01-28 17:13:47 -0800 | [diff] [blame] | 600 | } |
| 601 | |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 602 | if (mSurfaceController != null) { |
| 603 | return mSurfaceController; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 604 | } |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 605 | |
| 606 | w.setHasSurface(false); |
| 607 | |
| 608 | if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG, |
| 609 | "createSurface " + this + ": mDrawState=DRAW_PENDING"); |
| 610 | |
| 611 | mDrawState = DRAW_PENDING; |
| 612 | if (w.mAppToken != null) { |
| 613 | if (w.mAppToken.mAppAnimator.animation == null) { |
| 614 | w.mAppToken.allDrawn = false; |
| 615 | w.mAppToken.deferClearAllDrawn = false; |
| 616 | } else { |
| 617 | // Currently animating, persist current state of allDrawn until animation |
| 618 | // is complete. |
| 619 | w.mAppToken.deferClearAllDrawn = true; |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | mService.makeWindowFreezingScreenIfNeededLocked(w); |
| 624 | |
| 625 | int flags = SurfaceControl.HIDDEN; |
| 626 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 627 | |
| 628 | if (mService.isSecureLocked(w)) { |
| 629 | flags |= SurfaceControl.SECURE; |
| 630 | } |
| 631 | |
| 632 | mTmpSize.set(w.mFrame.left + w.mXOffset, w.mFrame.top + w.mYOffset, 0, 0); |
| 633 | calculateSurfaceBounds(w, attrs); |
| 634 | final int width = mTmpSize.width(); |
| 635 | final int height = mTmpSize.height(); |
| 636 | |
| 637 | if (DEBUG_VISIBILITY) { |
| 638 | Slog.v(TAG, "Creating surface in session " |
| 639 | + mSession.mSurfaceSession + " window " + this |
| 640 | + " w=" + width + " h=" + height |
| 641 | + " x=" + mTmpSize.left + " y=" + mTmpSize.top |
| 642 | + " format=" + attrs.format + " flags=" + flags); |
| 643 | } |
| 644 | |
| 645 | // We may abort, so initialize to defaults. |
| 646 | mLastSystemDecorRect.set(0, 0, 0, 0); |
| 647 | mHasClipRect = false; |
| 648 | mClipRect.set(0, 0, 0, 0); |
| 649 | mLastClipRect.set(0, 0, 0, 0); |
| 650 | |
| 651 | // Set up surface control with initial size. |
| 652 | try { |
| 653 | |
| 654 | final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0; |
| 655 | final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format; |
| 656 | if (!PixelFormat.formatHasAlpha(attrs.format) |
| 657 | // Don't make surface with surfaceInsets opaque as they display a |
| 658 | // translucent shadow. |
| 659 | && attrs.surfaceInsets.left == 0 |
| 660 | && attrs.surfaceInsets.top == 0 |
| 661 | && attrs.surfaceInsets.right == 0 |
| 662 | && attrs.surfaceInsets.bottom == 0 |
| 663 | // Don't make surface opaque when resizing to reduce the amount of |
| 664 | // artifacts shown in areas the app isn't drawing content to. |
| 665 | && !w.isDragResizing()) { |
| 666 | flags |= SurfaceControl.OPAQUE; |
| 667 | } |
| 668 | |
| 669 | mSurfaceController = new WindowSurfaceController(mSession.mSurfaceSession, |
| 670 | attrs.getTitle().toString(), |
| 671 | width, height, format, flags, this); |
| 672 | |
| 673 | w.setHasSurface(true); |
| 674 | |
| 675 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) { |
| 676 | Slog.i(TAG, " CREATE SURFACE " |
| 677 | + mSurfaceController + " IN SESSION " |
| 678 | + mSession.mSurfaceSession |
| 679 | + ": pid=" + mSession.mPid + " format=" |
| 680 | + attrs.format + " flags=0x" |
| 681 | + Integer.toHexString(flags) |
| 682 | + " / " + this); |
| 683 | } |
| 684 | } catch (OutOfResourcesException e) { |
| 685 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
| 686 | mService.reclaimSomeSurfaceMemoryLocked(this, "create", true); |
| 687 | mDrawState = NO_SURFACE; |
| 688 | return null; |
| 689 | } catch (Exception e) { |
| 690 | Slog.e(TAG, "Exception creating surface", e); |
| 691 | mDrawState = NO_SURFACE; |
| 692 | return null; |
| 693 | } |
| 694 | |
| 695 | if (WindowManagerService.localLOGV) Slog.v(TAG, "Got surface: " + mSurfaceController |
| 696 | + ", set left=" + w.mFrame.left + " top=" + w.mFrame.top |
| 697 | + ", animLayer=" + mAnimLayer); |
| 698 | |
| 699 | if (SHOW_LIGHT_TRANSACTIONS) { |
| 700 | Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked"); |
| 701 | WindowManagerService.logSurface(w, "CREATE pos=(" |
| 702 | + w.mFrame.left + "," + w.mFrame.top + ") (" |
| 703 | + width + "x" + height + "), layer=" + mAnimLayer + " HIDE", false); |
| 704 | } |
| 705 | |
| 706 | // Start a new transaction and apply position & offset. |
| 707 | final int layerStack = w.getDisplayContent().getDisplay().getLayerStack(); |
| 708 | if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(w, |
| 709 | "POS " + mTmpSize.left + ", " + mTmpSize.top, false); |
| 710 | mSurfaceController.setPositionAndLayer(mTmpSize.left, mTmpSize.top, layerStack, mAnimLayer); |
| 711 | mLastHidden = true; |
| 712 | |
| 713 | if (WindowManagerService.localLOGV) Slog.v(TAG, "Created surface " + this); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 714 | return mSurfaceController; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 717 | private void calculateSurfaceBounds(WindowState w, LayoutParams attrs) { |
| 718 | if ((attrs.flags & FLAG_SCALED) != 0) { |
| 719 | // For a scaled surface, we always want the requested size. |
| 720 | mTmpSize.right = mTmpSize.left + w.mRequestedWidth; |
| 721 | mTmpSize.bottom = mTmpSize.top + w.mRequestedHeight; |
| 722 | } else { |
| 723 | // When we're doing a drag-resizing, request a surface that's fullscreen size, |
| 724 | // so that we don't need to reallocate during the process. This also prevents |
| 725 | // buffer drops due to size mismatch. |
| 726 | if (w.isDragResizing()) { |
| 727 | if (w.getResizeMode() == DRAG_RESIZE_MODE_FREEFORM) { |
| 728 | mTmpSize.left = 0; |
| 729 | mTmpSize.top = 0; |
| 730 | } |
| 731 | final DisplayInfo displayInfo = w.getDisplayInfo(); |
| 732 | mTmpSize.right = mTmpSize.left + displayInfo.logicalWidth; |
| 733 | mTmpSize.bottom = mTmpSize.top + displayInfo.logicalHeight; |
| 734 | } else { |
| 735 | mTmpSize.right = mTmpSize.left + w.mCompatFrame.width(); |
| 736 | mTmpSize.bottom = mTmpSize.top + w.mCompatFrame.height(); |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | // 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] | 741 | // This doesn't necessarily mean that there is an error in the system. The sizes might be |
| 742 | // incorrect, because it is before the first layout or draw. |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 743 | if (mTmpSize.width() < 1) { |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 744 | mTmpSize.right = mTmpSize.left + 1; |
| 745 | } |
| 746 | if (mTmpSize.height() < 1) { |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 747 | mTmpSize.bottom = mTmpSize.top + 1; |
| 748 | } |
| 749 | |
| 750 | final int displayId = w.getDisplayId(); |
| 751 | float scale = 1.0f; |
| 752 | // Magnification is supported only for the default display. |
| 753 | if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) { |
| 754 | final MagnificationSpec spec = |
| 755 | mService.mAccessibilityController.getMagnificationSpecForWindowLocked(w); |
| 756 | if (spec != null && !spec.isNop()) { |
| 757 | scale = spec.scale; |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | // Adjust for surface insets. |
| 762 | mTmpSize.left -= scale * attrs.surfaceInsets.left; |
| 763 | mTmpSize.top -= scale * attrs.surfaceInsets.top; |
| 764 | mTmpSize.right += scale * (attrs.surfaceInsets.left + attrs.surfaceInsets.right); |
| 765 | mTmpSize.bottom += scale * (attrs.surfaceInsets.top + attrs.surfaceInsets.bottom); |
| 766 | } |
| 767 | |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 768 | boolean hasSurface() { |
| 769 | return !mWin.mSurfaceSaved |
| 770 | && mSurfaceController != null && mSurfaceController.hasSurface(); |
| 771 | } |
| 772 | |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 773 | void destroySurfaceLocked() { |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 774 | final AppWindowToken wtoken = mWin.mAppToken; |
| 775 | if (wtoken != null) { |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 776 | wtoken.mAnimatingWithSavedSurface = false; |
| 777 | if (mWin == wtoken.startingWindow) { |
| 778 | wtoken.startingDisplayed = false; |
| 779 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 782 | mWin.mSurfaceSaved = false; |
| 783 | |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 784 | if (mSurfaceController == null) { |
| 785 | return; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 786 | } |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 787 | |
| 788 | int i = mWin.mChildWindows.size(); |
| 789 | // When destroying a surface we want to make sure child windows are hidden. If we are |
| 790 | // preserving the surface until redraw though we intend to swap it out with another surface |
| 791 | // for resizing. In this case the window always remains visible to the user and the child |
| 792 | // windows should likewise remain visible. |
| 793 | while (!mDestroyPreservedSurfaceUponRedraw && i > 0) { |
| 794 | i--; |
| 795 | WindowState c = mWin.mChildWindows.get(i); |
| 796 | c.mAttachedHidden = true; |
| 797 | } |
| 798 | |
| 799 | try { |
| 800 | if (DEBUG_VISIBILITY) logWithStack(TAG, "Window " + this + " destroying surface " |
| 801 | + mSurfaceController + ", session " + mSession); |
| 802 | if (mSurfaceDestroyDeferred) { |
| 803 | if (mSurfaceController != null && mPendingDestroySurface != mSurfaceController) { |
| 804 | if (mPendingDestroySurface != null) { |
| 805 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) { |
| 806 | WindowManagerService.logSurface(mWin, "DESTROY PENDING", true); |
| 807 | } |
| 808 | mPendingDestroySurface.destroyInTransaction(); |
| 809 | } |
| 810 | mPendingDestroySurface = mSurfaceController; |
| 811 | } |
| 812 | } else { |
| 813 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) { |
| 814 | WindowManagerService.logSurface(mWin, "DESTROY", true); |
| 815 | } |
| 816 | destroySurface(); |
| 817 | } |
| 818 | // Don't hide wallpaper if we're deferring the surface destroy |
| 819 | // because of a surface change. |
| 820 | if (!mDestroyPreservedSurfaceUponRedraw) { |
| 821 | mWallpaperControllerLocked.hideWallpapers(mWin); |
| 822 | } |
| 823 | } catch (RuntimeException e) { |
| 824 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
| 825 | + " surface " + mSurfaceController + " session " + mSession + ": " + e.toString()); |
| 826 | } |
| 827 | |
| 828 | // Whether the surface was preserved (and copied to mPendingDestroySurface) or not, it |
| 829 | // needs to be cleared to match the WindowState.mHasSurface state. It is also necessary |
| 830 | // so it can be recreated successfully in mPendingDestroySurface case. |
| 831 | mWin.setHasSurface(false); |
| 832 | if (mSurfaceController != null) { |
| 833 | mSurfaceController.setShown(false); |
| 834 | } |
| 835 | mSurfaceController = null; |
| 836 | mDrawState = NO_SURFACE; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 837 | } |
| 838 | |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 839 | void destroyDeferredSurfaceLocked() { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 840 | try { |
| 841 | if (mPendingDestroySurface != null) { |
| 842 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) { |
Filip Gruszczynski | 198dcbf | 2016-01-18 10:02:00 -0800 | [diff] [blame] | 843 | WindowManagerService.logSurface(mWin, "DESTROY PENDING", true); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 844 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 845 | mPendingDestroySurface.destroyInTransaction(); |
Chong Zhang | 6e21cf4 | 2015-11-09 14:41:42 -0800 | [diff] [blame] | 846 | // Don't hide wallpaper if we're destroying a deferred surface |
| 847 | // after a surface mode change. |
| 848 | if (!mDestroyPreservedSurfaceUponRedraw) { |
| 849 | mWallpaperControllerLocked.hideWallpapers(mWin); |
| 850 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 851 | } |
| 852 | } catch (RuntimeException e) { |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 853 | Slog.w(TAG, "Exception thrown when destroying Window " |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 854 | + this + " surface " + mPendingDestroySurface |
| 855 | + " session " + mSession + ": " + e.toString()); |
| 856 | } |
| 857 | mSurfaceDestroyDeferred = false; |
| 858 | mPendingDestroySurface = null; |
| 859 | } |
| 860 | |
| 861 | void computeShownFrameLocked() { |
| 862 | final boolean selfTransformation = mHasLocalTransformation; |
| 863 | Transformation attachedTransformation = |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 864 | (mAttachedWinAnimator != null && mAttachedWinAnimator.mHasLocalTransformation) |
| 865 | ? mAttachedWinAnimator.mTransformation : null; |
| 866 | Transformation appTransformation = (mAppAnimator != null && mAppAnimator.hasTransformation) |
| 867 | ? mAppAnimator.transformation : null; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 868 | |
| 869 | // Wallpapers are animated based on the "real" window they |
| 870 | // are currently targeting. |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 871 | final WindowState wallpaperTarget = mWallpaperControllerLocked.getWallpaperTarget(); |
Craig Mautner | 798adef | 2013-10-22 14:29:01 -0700 | [diff] [blame] | 872 | if (mIsWallpaper && wallpaperTarget != null && mService.mAnimateWallpaperWithTarget) { |
| 873 | final WindowStateAnimator wallpaperAnimator = wallpaperTarget.mWinAnimator; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 874 | if (wallpaperAnimator.mHasLocalTransformation && |
| 875 | wallpaperAnimator.mAnimation != null && |
| 876 | !wallpaperAnimator.mAnimation.getDetachWallpaper()) { |
| 877 | attachedTransformation = wallpaperAnimator.mTransformation; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 878 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 879 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
| 880 | } |
| 881 | } |
Craig Mautner | 798adef | 2013-10-22 14:29:01 -0700 | [diff] [blame] | 882 | final AppWindowAnimator wpAppAnimator = wallpaperTarget.mAppToken == null ? |
| 883 | null : wallpaperTarget.mAppToken.mAppAnimator; |
| 884 | if (wpAppAnimator != null && wpAppAnimator.hasTransformation |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 885 | && wpAppAnimator.animation != null |
| 886 | && !wpAppAnimator.animation.getDetachWallpaper()) { |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 887 | appTransformation = wpAppAnimator.transformation; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 888 | if (DEBUG_WALLPAPER && appTransformation != null) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 889 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
| 890 | } |
| 891 | } |
| 892 | } |
| 893 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 894 | final int displayId = mWin.getDisplayId(); |
| 895 | final ScreenRotationAnimation screenRotationAnimation = |
| 896 | mAnimator.getScreenRotationAnimationLocked(displayId); |
| 897 | final boolean screenAnimation = |
| 898 | screenRotationAnimation != null && screenRotationAnimation.isAnimating(); |
Robert Carr | 2f0fe62 | 2015-09-25 14:56:38 -0700 | [diff] [blame] | 899 | |
| 900 | mHasClipRect = false; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 901 | if (selfTransformation || attachedTransformation != null |
| 902 | || appTransformation != null || screenAnimation) { |
| 903 | // cache often used attributes locally |
| 904 | final Rect frame = mWin.mFrame; |
| 905 | final float tmpFloats[] = mService.mTmpFloats; |
| 906 | final Matrix tmpMatrix = mWin.mTmpMatrix; |
| 907 | |
| 908 | // Compute the desired transformation. |
Dianne Hackborn | 4b16969 | 2012-11-29 17:51:24 -0800 | [diff] [blame] | 909 | if (screenAnimation && screenRotationAnimation.isRotating()) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 910 | // If we are doing a screen animation, the global rotation |
| 911 | // applied to windows can result in windows that are carefully |
| 912 | // aligned with each other to slightly separate, allowing you |
| 913 | // to see what is behind them. An unsightly mess. This... |
| 914 | // thing... magically makes it call good: scale each window |
| 915 | // slightly (two pixels larger in each dimension, from the |
| 916 | // window's center). |
| 917 | final float w = frame.width(); |
| 918 | final float h = frame.height(); |
| 919 | if (w>=1 && h>=1) { |
| 920 | tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2); |
| 921 | } else { |
| 922 | tmpMatrix.reset(); |
| 923 | } |
| 924 | } else { |
| 925 | tmpMatrix.reset(); |
| 926 | } |
| 927 | tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale); |
| 928 | if (selfTransformation) { |
| 929 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
| 930 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 931 | if (attachedTransformation != null) { |
| 932 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
| 933 | } |
| 934 | if (appTransformation != null) { |
| 935 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
| 936 | } |
| 937 | if (screenAnimation) { |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 938 | tmpMatrix.postConcat(screenRotationAnimation.getEnterTransformation().getMatrix()); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 939 | } |
Filip Gruszczynski | 9ca40b7 | 2015-08-13 13:35:25 -0700 | [diff] [blame] | 940 | // The translation that applies the position of the window needs to be applied at the |
| 941 | // end in case that other translations include scaling. Otherwise the scaling will |
| 942 | // affect this translation. |
| 943 | tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 944 | |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 945 | //TODO (multidisplay): Magnification is supported only for the default display. |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 946 | if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 947 | MagnificationSpec spec = mService.mAccessibilityController |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 948 | .getMagnificationSpecForWindowLocked(mWin); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 949 | if (spec != null && !spec.isNop()) { |
| 950 | tmpMatrix.postScale(spec.scale, spec.scale); |
| 951 | tmpMatrix.postTranslate(spec.offsetX, spec.offsetY); |
| 952 | } |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 953 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 954 | |
| 955 | // "convert" it into SurfaceFlinger's format |
| 956 | // (a 2x2 matrix + an offset) |
| 957 | // Here we must not transform the position of the surface |
| 958 | // since it is already included in the transformation. |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 959 | //Slog.i(TAG_WM, "Transform: " + matrix); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 960 | |
| 961 | mHaveMatrix = true; |
| 962 | tmpMatrix.getValues(tmpFloats); |
| 963 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 964 | mDtDx = tmpFloats[Matrix.MSKEW_Y]; |
| 965 | mDsDy = tmpFloats[Matrix.MSKEW_X]; |
| 966 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| 967 | float x = tmpFloats[Matrix.MTRANS_X]; |
| 968 | float y = tmpFloats[Matrix.MTRANS_Y]; |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 969 | mWin.mShownPosition.set((int) x, (int) y); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 970 | |
| 971 | // Now set the alpha... but because our current hardware |
| 972 | // can't do alpha transformation on a non-opaque surface, |
| 973 | // turn it off if we are running an animation that is also |
| 974 | // transforming since it is more important to have that |
| 975 | // animation be smooth. |
| 976 | mShownAlpha = mAlpha; |
| 977 | if (!mService.mLimitedAlphaCompositing |
| 978 | || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format) |
| 979 | || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 980 | && x == frame.left && y == frame.top))) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 981 | //Slog.i(TAG_WM, "Applying alpha transform"); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 982 | if (selfTransformation) { |
| 983 | mShownAlpha *= mTransformation.getAlpha(); |
| 984 | } |
| 985 | if (attachedTransformation != null) { |
| 986 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 987 | } |
| 988 | if (appTransformation != null) { |
| 989 | mShownAlpha *= appTransformation.getAlpha(); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 990 | if (appTransformation.hasClipRect()) { |
| 991 | mClipRect.set(appTransformation.getClipRect()); |
| 992 | mHasClipRect = true; |
| 993 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 994 | } |
| 995 | if (screenAnimation) { |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 996 | mShownAlpha *= screenRotationAnimation.getEnterTransformation().getAlpha(); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 997 | } |
| 998 | } else { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 999 | //Slog.i(TAG_WM, "Not applying alpha transform"); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1000 | } |
| 1001 | |
Filip Gruszczynski | 19723a4 | 2015-11-25 15:01:48 -0800 | [diff] [blame] | 1002 | if ((DEBUG_SURFACE_TRACE || WindowManagerService.localLOGV) |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 1003 | && (mShownAlpha == 1.0 || mShownAlpha == 0.0)) Slog.v( |
| 1004 | TAG, "computeShownFrameLocked: Animating " + this + " mAlpha=" + mAlpha |
| 1005 | + " self=" + (selfTransformation ? mTransformation.getAlpha() : "null") |
| 1006 | + " attached=" + (attachedTransformation == null ? |
| 1007 | "null" : attachedTransformation.getAlpha()) |
| 1008 | + " app=" + (appTransformation == null ? "null" : appTransformation.getAlpha()) |
| 1009 | + " screen=" + (screenAnimation ? |
| 1010 | screenRotationAnimation.getEnterTransformation().getAlpha() : "null")); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1011 | return; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1012 | } else if (mIsWallpaper && mService.mWindowPlacerLocked.mWallpaperActionPending) { |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 1013 | return; |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 1014 | } else if (mWin.isDragResizeChanged()) { |
| 1015 | // This window is awaiting a relayout because user just started (or ended) |
| 1016 | // drag-resizing. The shown frame (which affects surface size and pos) |
| 1017 | // should not be updated until we get next finished draw with the new surface. |
| 1018 | // Otherwise one or two frames rendered with old settings would be displayed |
| 1019 | // with new geometry. |
| 1020 | return; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
Filip Gruszczynski | 19723a4 | 2015-11-25 15:01:48 -0800 | [diff] [blame] | 1023 | if (WindowManagerService.localLOGV) Slog.v( |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 1024 | TAG, "computeShownFrameLocked: " + this + |
| 1025 | " not attached, mAlpha=" + mAlpha); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 1026 | |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 1027 | MagnificationSpec spec = null; |
| 1028 | //TODO (multidisplay): Magnification is supported only for the default display. |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 1029 | if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1030 | spec = mService.mAccessibilityController.getMagnificationSpecForWindowLocked(mWin); |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 1031 | } |
Craig Mautner | 165be0c | 2015-01-27 15:16:58 -0800 | [diff] [blame] | 1032 | if (spec != null) { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1033 | final Rect frame = mWin.mFrame; |
| 1034 | final float tmpFloats[] = mService.mTmpFloats; |
| 1035 | final Matrix tmpMatrix = mWin.mTmpMatrix; |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 1036 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1037 | tmpMatrix.setScale(mWin.mGlobalScale, mWin.mGlobalScale); |
| 1038 | tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 1039 | |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 1040 | if (spec != null && !spec.isNop()) { |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 1041 | tmpMatrix.postScale(spec.scale, spec.scale); |
| 1042 | tmpMatrix.postTranslate(spec.offsetX, spec.offsetY); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 1043 | } |
| 1044 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1045 | tmpMatrix.getValues(tmpFloats); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 1046 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1047 | mHaveMatrix = true; |
| 1048 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 1049 | mDtDx = tmpFloats[Matrix.MSKEW_Y]; |
| 1050 | mDsDy = tmpFloats[Matrix.MSKEW_X]; |
| 1051 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| 1052 | float x = tmpFloats[Matrix.MTRANS_X]; |
| 1053 | float y = tmpFloats[Matrix.MTRANS_Y]; |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 1054 | mWin.mShownPosition.set((int) x, (int) y); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 1055 | |
| 1056 | mShownAlpha = mAlpha; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1057 | } else { |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 1058 | mWin.mShownPosition.set(mWin.mFrame.left, mWin.mFrame.top); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1059 | if (mWin.mXOffset != 0 || mWin.mYOffset != 0) { |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 1060 | mWin.mShownPosition.offset(mWin.mXOffset, mWin.mYOffset); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1061 | } |
| 1062 | mShownAlpha = mAlpha; |
| 1063 | mHaveMatrix = false; |
| 1064 | mDsDx = mWin.mGlobalScale; |
| 1065 | mDtDx = 0; |
| 1066 | mDsDy = 0; |
| 1067 | mDtDy = mWin.mGlobalScale; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1068 | } |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 1071 | private void calculateSystemDecorRect() { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1072 | final WindowState w = mWin; |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 1073 | final Rect decorRect = w.mDecorFrame; |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 1074 | final int width = w.mFrame.width(); |
| 1075 | final int height = w.mFrame.height(); |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 1076 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1077 | // Compute the offset of the window in relation to the decor rect. |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 1078 | final int left = w.mXOffset + w.mFrame.left; |
| 1079 | final int top = w.mYOffset + w.mFrame.top; |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 1080 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1081 | // Initialize the decor rect to the entire frame. |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1082 | if (w.isDragResizing() && w.getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER) { |
| 1083 | |
| 1084 | // If we are resizing with the divider, the task bounds might be smaller than the |
| 1085 | // stack bounds. The system decor is used to clip to the task bounds, which we don't |
| 1086 | // want in this case in order to avoid holes. |
| 1087 | final DisplayInfo displayInfo = w.getDisplayContent().getDisplayInfo(); |
| 1088 | mSystemDecorRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight); |
| 1089 | } else { |
| 1090 | mSystemDecorRect.set(0, 0, width, height); |
| 1091 | } |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 1092 | |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 1093 | // If a freeform window is animating from a position where it would be cutoff, it would be |
| 1094 | // cutoff during the animation. We don't want that, so for the duration of the animation |
| 1095 | // we ignore the decor cropping and depend on layering to position windows correctly. |
| 1096 | final boolean cropToDecor = !(w.inFreeformWorkspace() && w.isAnimatingLw()); |
| 1097 | if (cropToDecor) { |
| 1098 | // Intersect with the decor rect, offsetted by window position. |
| 1099 | mSystemDecorRect.intersect(decorRect.left - left, decorRect.top - top, |
| 1100 | decorRect.right - left, decorRect.bottom - top); |
| 1101 | } |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 1102 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1103 | // If size compatibility is being applied to the window, the |
| 1104 | // surface is scaled relative to the screen. Also apply this |
| 1105 | // scaling to the crop rect. We aren't using the standard rect |
| 1106 | // scale function because we want to round things to make the crop |
| 1107 | // always round to a larger rect to ensure we don't crop too |
| 1108 | // much and hide part of the window that should be seen. |
| 1109 | if (w.mEnforceSizeCompat && w.mInvGlobalScale != 1.0f) { |
| 1110 | final float scale = w.mInvGlobalScale; |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 1111 | mSystemDecorRect.left = (int) (mSystemDecorRect.left * scale - 0.5f); |
| 1112 | mSystemDecorRect.top = (int) (mSystemDecorRect.top * scale - 0.5f); |
| 1113 | mSystemDecorRect.right = (int) ((mSystemDecorRect.right+1) * scale - 0.5f); |
| 1114 | mSystemDecorRect.bottom = (int) ((mSystemDecorRect.bottom+1) * scale - 0.5f); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1115 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1116 | } |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 1117 | |
Dianne Hackborn | 3e52fc2 | 2012-05-15 17:58:02 -0700 | [diff] [blame] | 1118 | void updateSurfaceWindowCrop(final boolean recoveringMemory) { |
| 1119 | final WindowState w = mWin; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1120 | final DisplayContent displayContent = w.getDisplayContent(); |
| 1121 | if (displayContent == null) { |
| 1122 | return; |
| 1123 | } |
Wale Ogunwale | b3eba81 | 2015-07-30 20:20:16 -0700 | [diff] [blame] | 1124 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 1125 | if (DEBUG_WINDOW_CROP) Slog.d(TAG, "Updating crop for window: " + w + ", " + "mLastCrop=" + |
| 1126 | mLastClipRect); |
Dianne Hackborn | 3e52fc2 | 2012-05-15 17:58:02 -0700 | [diff] [blame] | 1127 | |
| 1128 | // Need to recompute a new system decor rect each time. |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 1129 | if (!w.isDefaultDisplay()) { |
Jeff Brown | 28e0b09 | 2012-09-25 11:31:28 -0700 | [diff] [blame] | 1130 | // On a different display there is no system decor. Crop the window |
| 1131 | // by the screen boundaries. |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 1132 | mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height()); |
| 1133 | mSystemDecorRect.intersect(-w.mCompatFrame.left, -w.mCompatFrame.top, |
Jeff Brown | 28e0b09 | 2012-09-25 11:31:28 -0700 | [diff] [blame] | 1134 | displayInfo.logicalWidth - w.mCompatFrame.left, |
| 1135 | displayInfo.logicalHeight - w.mCompatFrame.top); |
Dianne Hackborn | 3e52fc2 | 2012-05-15 17:58:02 -0700 | [diff] [blame] | 1136 | } else if (w.mLayer >= mService.mSystemDecorLayer) { |
| 1137 | // Above the decor layer is easy, just use the entire window. |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 1138 | mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height()); |
Craig Mautner | 165be0c | 2015-01-27 15:16:58 -0800 | [diff] [blame] | 1139 | } else if (w.mDecorFrame.isEmpty()) { |
| 1140 | // Windows without policy decor aren't cropped. |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 1141 | mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height()); |
Wale Ogunwale | 69cf50f | 2015-11-13 11:08:36 -0800 | [diff] [blame] | 1142 | } else if (w.mAttrs.type == LayoutParams.TYPE_WALLPAPER && mAnimator.isAnimating()) { |
Adrian Roos | d47ad03 | 2014-08-15 23:17:05 +0200 | [diff] [blame] | 1143 | // If we're animating, the wallpaper crop should only be updated at the end of the |
| 1144 | // animation. |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 1145 | mTmpClipRect.set(mSystemDecorRect); |
| 1146 | calculateSystemDecorRect(); |
| 1147 | mSystemDecorRect.union(mTmpClipRect); |
Dianne Hackborn | 3e52fc2 | 2012-05-15 17:58:02 -0700 | [diff] [blame] | 1148 | } else { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 1149 | // Crop to the system decor specified by policy. |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 1150 | calculateSystemDecorRect(); |
| 1151 | if (DEBUG_WINDOW_CROP) Slog.d(TAG, "Applying decor to crop for " + w + ", mDecorFrame=" |
| 1152 | + w.mDecorFrame + ", mSystemDecorRect=" + mSystemDecorRect); |
Dianne Hackborn | 3e52fc2 | 2012-05-15 17:58:02 -0700 | [diff] [blame] | 1153 | } |
| 1154 | |
Chong Zhang | 0abb20f | 2015-11-19 14:17:31 -0800 | [diff] [blame] | 1155 | final boolean fullscreen = w.isFrameFullscreen(displayInfo); |
Jorim Jaggi | 253a20f | 2015-11-03 12:38:42 +0100 | [diff] [blame] | 1156 | final boolean isFreeformResizing = |
Jorim Jaggi | dcf467c | 2015-11-05 13:59:32 +0100 | [diff] [blame] | 1157 | w.isDragResizing() && w.getResizeMode() == DRAG_RESIZE_MODE_FREEFORM; |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 1158 | final Rect clipRect = mTmpClipRect; |
Robert Carr | 51a1b87 | 2015-12-08 14:03:13 -0800 | [diff] [blame] | 1159 | |
| 1160 | // We use the clip rect as provided by the tranformation for non-fullscreen windows to |
| 1161 | // avoid premature clipping with the system decor rect. |
| 1162 | clipRect.set((mHasClipRect && !fullscreen) ? mClipRect : mSystemDecorRect); |
| 1163 | if (DEBUG_WINDOW_CROP) Slog.d(TAG, "Initial clip rect: " + clipRect + ", mHasClipRect=" |
| 1164 | + mHasClipRect + ", fullscreen=" + fullscreen); |
| 1165 | |
| 1166 | if (isFreeformResizing && !w.isChildWindow()) { |
| 1167 | // For freeform resizing non child windows, we are using the big surface positioned |
| 1168 | // at 0,0. Thus we must express the crop in that coordinate space. |
| 1169 | clipRect.offset(w.mShownPosition.x, w.mShownPosition.y); |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 1170 | } |
Robert Carr | 51a1b87 | 2015-12-08 14:03:13 -0800 | [diff] [blame] | 1171 | |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 1172 | // Expand the clip rect for surface insets. |
| 1173 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 1174 | clipRect.left -= attrs.surfaceInsets.left; |
| 1175 | clipRect.top -= attrs.surfaceInsets.top; |
| 1176 | clipRect.right += attrs.surfaceInsets.right; |
| 1177 | clipRect.bottom += attrs.surfaceInsets.bottom; |
| 1178 | |
Wale Ogunwale | b3eba81 | 2015-07-30 20:20:16 -0700 | [diff] [blame] | 1179 | if (mHasClipRect && fullscreen) { |
| 1180 | // We intersect the clip rect specified by the transformation with the expanded system |
| 1181 | // decor rect to prevent artifacts from drawing during animation if the transformation |
| 1182 | // clip rect extends outside the system decor rect. |
| 1183 | clipRect.intersect(mClipRect); |
| 1184 | } |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 1185 | // The clip rect was generated assuming (0,0) as the window origin, |
| 1186 | // so we need to translate to match the actual surface coordinates. |
| 1187 | clipRect.offset(attrs.surfaceInsets.left, attrs.surfaceInsets.top); |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 1188 | |
Wale Ogunwale | 69cf50f | 2015-11-13 11:08:36 -0800 | [diff] [blame] | 1189 | adjustCropToStackBounds(w, clipRect, isFreeformResizing); |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 1190 | if (DEBUG_WINDOW_CROP) Slog.d(TAG, "Clip rect after stack adjustment=" + mClipRect); |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 1191 | |
| 1192 | w.transformFromScreenToSurfaceSpace(clipRect); |
| 1193 | |
Jorim Jaggi | 5e6968d | 2016-02-19 18:02:13 -0800 | [diff] [blame] | 1194 | // See {@link WindowState#notifyMovedInStack} for why this is necessary. |
| 1195 | if (w.hasJustMovedInStack() && mLastClipRect.isEmpty() && !clipRect.isEmpty()) { |
| 1196 | clipRect.setEmpty(); |
| 1197 | } |
| 1198 | |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1199 | if (!clipRect.equals(mLastClipRect)) { |
| 1200 | mLastClipRect.set(clipRect); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1201 | mSurfaceController.setCropInTransaction(clipRect, recoveringMemory); |
Dianne Hackborn | 3e52fc2 | 2012-05-15 17:58:02 -0700 | [diff] [blame] | 1202 | } |
| 1203 | } |
| 1204 | |
Jorim Jaggi | 253a20f | 2015-11-03 12:38:42 +0100 | [diff] [blame] | 1205 | private void adjustCropToStackBounds(WindowState w, Rect clipRect, boolean isFreeformResizing) { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 1206 | final Task task = w.getTask(); |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1207 | if (task == null || !task.cropWindowsToStackBounds()) { |
Wale Ogunwale | 69cf50f | 2015-11-13 11:08:36 -0800 | [diff] [blame] | 1208 | return; |
Filip Gruszczynski | 4b8eea7 | 2015-09-14 18:16:19 -0700 | [diff] [blame] | 1209 | } |
Wale Ogunwale | 69cf50f | 2015-11-13 11:08:36 -0800 | [diff] [blame] | 1210 | |
| 1211 | // We don't apply the stack bounds crop if: |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 1212 | // 1. The window is currently animating docked mode or in freeform mode, otherwise the |
| 1213 | // animating window will be suddenly (docked) or for whole animation (freeform) cut off. |
Chong Zhang | 50bf96b | 2015-12-28 11:09:01 -0800 | [diff] [blame] | 1214 | // (Note that we still need to apply the crop if the task being docked is non-resizeable, |
| 1215 | // in which case the task is running in fullscreen size but cropped to stack bounds.) |
Wale Ogunwale | 69cf50f | 2015-11-13 11:08:36 -0800 | [diff] [blame] | 1216 | // 2. The window that is being replaced during animation, because it was living in a |
| 1217 | // different stack. If we suddenly crop it to the new stack bounds, it might get cut off. |
| 1218 | // We don't want it to happen, so we let it ignore the stack bounds until it gets removed. |
| 1219 | // The window that will replace it will abide them. |
Chong Zhang | 50bf96b | 2015-12-28 11:09:01 -0800 | [diff] [blame] | 1220 | if (isAnimating() && (w.mWillReplaceWindow |
| 1221 | || (w.inDockedWorkspace() && task.isResizeable()) |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 1222 | || w.inFreeformWorkspace())) { |
Wale Ogunwale | 69cf50f | 2015-11-13 11:08:36 -0800 | [diff] [blame] | 1223 | return; |
| 1224 | } |
| 1225 | |
Chong Zhang | bcb8d82 | 2016-02-26 16:21:02 -0800 | [diff] [blame] | 1226 | final WindowState winShowWhenLocked = (WindowState) mPolicy.getWinShowWhenLockedLw(); |
| 1227 | if (w == winShowWhenLocked) { |
| 1228 | return; |
| 1229 | } |
| 1230 | |
Wale Ogunwale | 69cf50f | 2015-11-13 11:08:36 -0800 | [diff] [blame] | 1231 | final TaskStack stack = task.mStack; |
| 1232 | stack.getDimBounds(mTmpStackBounds); |
| 1233 | // When we resize we use the big surface approach, which means we can't trust the |
| 1234 | // window frame bounds anymore. Instead, the window will be placed at 0, 0, but to avoid |
| 1235 | // hardcoding it, we use surface coordinates. |
| 1236 | final int frameX = isFreeformResizing ? (int) mSurfaceController.getX() : |
| 1237 | w.mFrame.left + mWin.mXOffset - w.getAttrs().surfaceInsets.left; |
| 1238 | final int frameY = isFreeformResizing ? (int) mSurfaceController.getY() : |
| 1239 | w.mFrame.top + mWin.mYOffset - w.getAttrs().surfaceInsets.top; |
| 1240 | // We need to do some acrobatics with surface position, because their clip region is |
| 1241 | // relative to the inside of the surface, but the stack bounds aren't. |
| 1242 | clipRect.left = Math.max(0, |
| 1243 | Math.max(mTmpStackBounds.left, frameX + clipRect.left) - frameX); |
| 1244 | clipRect.top = Math.max(0, |
| 1245 | Math.max(mTmpStackBounds.top, frameY + clipRect.top) - frameY); |
| 1246 | clipRect.right = Math.max(0, |
| 1247 | Math.min(mTmpStackBounds.right, frameX + clipRect.right) - frameX); |
| 1248 | clipRect.bottom = Math.max(0, |
| 1249 | Math.min(mTmpStackBounds.bottom, frameY + clipRect.bottom) - frameY); |
Filip Gruszczynski | 4b8eea7 | 2015-09-14 18:16:19 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
Wale Ogunwale | 4c8b795 | 2015-04-07 10:49:40 -0700 | [diff] [blame] | 1252 | void setSurfaceBoundariesLocked(final boolean recoveringMemory) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1253 | final WindowState w = mWin; |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 1254 | |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 1255 | mTmpSize.set(w.mShownPosition.x, w.mShownPosition.y, 0, 0); |
| 1256 | calculateSurfaceBounds(w, w.getAttrs()); |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 1257 | |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 1258 | mSurfaceController.setPositionInTransaction(mTmpSize.left, mTmpSize.top, recoveringMemory); |
Robert Carr | e1034cc3 | 2016-02-01 13:08:15 -0800 | [diff] [blame] | 1259 | |
| 1260 | mSurfaceController.setMatrixInTransaction(mDsDx * w.mHScale, mDtDx * w.mVScale, |
| 1261 | mDsDy * w.mHScale, mDtDy * w.mVScale, recoveringMemory); |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 1262 | mSurfaceResized = mSurfaceController.setSizeInTransaction( |
| 1263 | mTmpSize.width(), mTmpSize.height(), |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1264 | recoveringMemory); |
Filip Gruszczynski | 63a35e2 | 2015-11-05 15:38:59 -0800 | [diff] [blame] | 1265 | |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1266 | if (mSurfaceResized) { |
Chong Zhang | 5b2f199 | 2015-11-13 15:40:36 -0800 | [diff] [blame] | 1267 | mReportSurfaceResized = true; |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1268 | mAnimator.setPendingLayoutChanges(w.getDisplayId(), |
| 1269 | WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER); |
| 1270 | w.applyDimLayerIfNeeded(); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1271 | } |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 1272 | |
Dianne Hackborn | 3e52fc2 | 2012-05-15 17:58:02 -0700 | [diff] [blame] | 1273 | updateSurfaceWindowCrop(recoveringMemory); |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 1274 | } |
| 1275 | |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 1276 | void prepareSurfaceLocked(final boolean recoveringMemory) { |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 1277 | final WindowState w = mWin; |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 1278 | if (!hasSurface()) { |
Craig Mautner | acaf9cc | 2012-04-17 11:45:25 -0700 | [diff] [blame] | 1279 | if (w.mOrientationChanging) { |
| 1280 | if (DEBUG_ORIENTATION) { |
| 1281 | Slog.v(TAG, "Orientation change skips hidden " + w); |
| 1282 | } |
| 1283 | w.mOrientationChanging = false; |
| 1284 | } |
| 1285 | return; |
| 1286 | } |
| 1287 | |
| 1288 | boolean displayed = false; |
| 1289 | |
| 1290 | computeShownFrameLocked(); |
| 1291 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 1292 | setSurfaceBoundariesLocked(recoveringMemory); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1293 | |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 1294 | if (mIsWallpaper && !mWin.mWallpaperVisible) { |
Craig Mautner | 0fa77c1 | 2012-06-11 15:57:19 -0700 | [diff] [blame] | 1295 | // 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] | 1296 | hide("prepareSurfaceLocked"); |
Craig Mautner | 72669d1 | 2012-12-18 17:23:54 -0800 | [diff] [blame] | 1297 | } else if (w.mAttachedHidden || !w.isOnScreen()) { |
Filip Gruszczynski | 63a35e2 | 2015-11-05 15:38:59 -0800 | [diff] [blame] | 1298 | hide("prepareSurfaceLocked"); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 1299 | mWallpaperControllerLocked.hideWallpapers(w); |
Craig Mautner | b9836b9 | 2012-06-11 11:40:09 -0700 | [diff] [blame] | 1300 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1301 | // If we are waiting for this window to handle an |
| 1302 | // orientation change, well, it is hidden, so |
| 1303 | // doesn't really matter. Note that this does |
| 1304 | // introduce a potential glitch if the window |
| 1305 | // becomes unhidden before it has drawn for the |
| 1306 | // new orientation. |
| 1307 | if (w.mOrientationChanging) { |
| 1308 | w.mOrientationChanging = false; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1309 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1310 | "Orientation change skips hidden " + w); |
| 1311 | } |
| 1312 | } else if (mLastLayer != mAnimLayer |
| 1313 | || mLastAlpha != mShownAlpha |
| 1314 | || mLastDsDx != mDsDx |
| 1315 | || mLastDtDx != mDtDx |
| 1316 | || mLastDsDy != mDsDy |
| 1317 | || mLastDtDy != mDtDy |
| 1318 | || w.mLastHScale != w.mHScale |
| 1319 | || w.mLastVScale != w.mVScale |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1320 | || mLastHidden) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1321 | displayed = true; |
| 1322 | mLastAlpha = mShownAlpha; |
| 1323 | mLastLayer = mAnimLayer; |
| 1324 | mLastDsDx = mDsDx; |
| 1325 | mLastDtDx = mDtDx; |
| 1326 | mLastDsDy = mDsDy; |
| 1327 | mLastDtDy = mDtDy; |
| 1328 | w.mLastHScale = w.mHScale; |
| 1329 | w.mLastVScale = w.mVScale; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 1330 | if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(w, |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1331 | "controller=" + mSurfaceController + |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1332 | "alpha=" + mShownAlpha + " layer=" + mAnimLayer |
Craig Mautner | 78505d8 | 2014-09-02 14:36:31 -0700 | [diff] [blame] | 1333 | + " matrix=[" + mDsDx + "*" + w.mHScale |
| 1334 | + "," + mDtDx + "*" + w.mVScale |
| 1335 | + "][" + mDsDy + "*" + w.mHScale |
Filip Gruszczynski | 198dcbf | 2016-01-18 10:02:00 -0800 | [diff] [blame] | 1336 | + "," + mDtDy + "*" + w.mVScale + "]", false); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1337 | |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1338 | boolean prepared = |
| 1339 | mSurfaceController.prepareToShowInTransaction(mShownAlpha, mAnimLayer, |
| 1340 | mDsDx * w.mHScale, mDtDx * w.mVScale, |
| 1341 | mDsDy * w.mHScale, mDtDy * w.mVScale, |
| 1342 | recoveringMemory); |
| 1343 | |
| 1344 | if (prepared && mLastHidden && mDrawState == HAS_DRAWN) { |
| 1345 | if (showSurfaceRobustlyLocked()) { |
Chong Zhang | b9b0fec | 2016-02-11 18:51:51 -0800 | [diff] [blame] | 1346 | if (mDestroyPreservedSurfaceUponRedraw) { |
| 1347 | mService.mDestroyPreservedSurface.add(mWin); |
| 1348 | } |
Filip Gruszczynski | 78a08ee | 2015-11-08 18:04:32 -0800 | [diff] [blame] | 1349 | mAnimator.requestRemovalOfReplacedWindows(w); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1350 | mLastHidden = false; |
| 1351 | if (mIsWallpaper) { |
| 1352 | mWallpaperControllerLocked.dispatchWallpaperVisibility(w, true); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1353 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1354 | // This draw means the difference between unique content and mirroring. |
| 1355 | // Run another pass through performLayout to set mHasContent in the |
| 1356 | // LogicalDisplay. |
| 1357 | mAnimator.setPendingLayoutChanges(w.getDisplayId(), |
| 1358 | WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM); |
| 1359 | } else { |
| 1360 | w.mOrientationChanging = false; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1361 | } |
| 1362 | } |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 1363 | if (hasSurface()) { |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1364 | w.mToken.hasVisible = true; |
| 1365 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1366 | } else { |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 1367 | if (DEBUG_ANIM && isAnimating()) { |
Chong Zhang | e05db74 | 2016-02-16 16:58:37 -0800 | [diff] [blame] | 1368 | Slog.v(TAG, "prepareSurface: No changes in animation for " + this); |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 1369 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1370 | displayed = true; |
| 1371 | } |
| 1372 | |
| 1373 | if (displayed) { |
| 1374 | if (w.mOrientationChanging) { |
| 1375 | if (!w.isDrawnLw()) { |
Craig Mautner | 2639da5 | 2012-07-09 09:39:06 -0700 | [diff] [blame] | 1376 | mAnimator.mBulkUpdateParams &= ~SET_ORIENTATION_CHANGE_COMPLETE; |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 1377 | mAnimator.mLastWindowFreezeSource = w; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1378 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1379 | "Orientation continue waiting for draw in " + w); |
| 1380 | } else { |
| 1381 | w.mOrientationChanging = false; |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1382 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Orientation change complete in " + w); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1383 | } |
| 1384 | } |
| 1385 | w.mToken.hasVisible = true; |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 1386 | |
| 1387 | final Task task = w.getTask(); |
| 1388 | if (task != null) { |
| 1389 | task.scheduleShowNonResizeableDockToastIfNeeded(); |
| 1390 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1391 | } |
| 1392 | } |
| 1393 | |
Craig Mautner | ef65501 | 2013-01-03 11:20:24 -0800 | [diff] [blame] | 1394 | void setTransparentRegionHintLocked(final Region region) { |
Wale Ogunwale | f9e0978 | 2015-11-09 12:42:37 -0800 | [diff] [blame] | 1395 | if (mSurfaceController == null) { |
| 1396 | Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true"); |
| 1397 | return; |
| 1398 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1399 | mSurfaceController.setTransparentRegionHint(region); |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 1402 | void setWallpaperOffset(Point shownPosition) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1403 | final LayoutParams attrs = mWin.getAttrs(); |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 1404 | final int left = shownPosition.x - attrs.surfaceInsets.left; |
| 1405 | final int top = shownPosition.y - attrs.surfaceInsets.top; |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1406 | |
| 1407 | try { |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 1408 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setWallpaperOffset"); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 1409 | SurfaceControl.openTransaction(); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1410 | mSurfaceController.setPositionInTransaction(mWin.mFrame.left + left, |
| 1411 | mWin.mFrame.top + top, false); |
| 1412 | updateSurfaceWindowCrop(false); |
| 1413 | } catch (RuntimeException e) { |
| 1414 | Slog.w(TAG, "Error positioning surface of " + mWin |
| 1415 | + " pos=(" + left + "," + top + ")", e); |
| 1416 | } finally { |
| 1417 | SurfaceControl.closeTransaction(); |
| 1418 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 1419 | "<<< CLOSE TRANSACTION setWallpaperOffset"); |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 1420 | } |
Craig Mautner | 48ba1e7 | 2012-04-02 13:18:16 -0700 | [diff] [blame] | 1421 | } |
| 1422 | |
John Reck | 80181b9 | 2015-05-19 11:09:32 -0700 | [diff] [blame] | 1423 | /** |
| 1424 | * Try to change the pixel format without recreating the surface. This |
| 1425 | * will be common in the case of changing from PixelFormat.OPAQUE to |
| 1426 | * PixelFormat.TRANSLUCENT in the hardware-accelerated case as both |
| 1427 | * requested formats resolve to the same underlying SurfaceControl format |
| 1428 | * @return True if format was succesfully changed, false otherwise |
| 1429 | */ |
| 1430 | boolean tryChangeFormatInPlaceLocked() { |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1431 | if (mSurfaceController == null) { |
John Reck | 80181b9 | 2015-05-19 11:09:32 -0700 | [diff] [blame] | 1432 | return false; |
| 1433 | } |
| 1434 | final LayoutParams attrs = mWin.getAttrs(); |
Wale Ogunwale | e7bf46b | 2015-09-30 09:19:28 -0700 | [diff] [blame] | 1435 | final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0; |
John Reck | 80181b9 | 2015-05-19 11:09:32 -0700 | [diff] [blame] | 1436 | final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format; |
| 1437 | if (format == mSurfaceFormat) { |
| 1438 | setOpaqueLocked(!PixelFormat.formatHasAlpha(attrs.format)); |
| 1439 | return true; |
| 1440 | } |
| 1441 | return false; |
| 1442 | } |
| 1443 | |
Craig Mautner | 6f61204 | 2014-09-07 13:13:23 -0700 | [diff] [blame] | 1444 | void setOpaqueLocked(boolean isOpaque) { |
Wale Ogunwale | f9e0978 | 2015-11-09 12:42:37 -0800 | [diff] [blame] | 1445 | if (mSurfaceController == null) { |
| 1446 | return; |
| 1447 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1448 | mSurfaceController.setOpaque(isOpaque); |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 1449 | } |
| 1450 | |
Wale Ogunwale | f5ad42f | 2015-06-12 13:59:03 -0700 | [diff] [blame] | 1451 | void setSecureLocked(boolean isSecure) { |
Wale Ogunwale | f9e0978 | 2015-11-09 12:42:37 -0800 | [diff] [blame] | 1452 | if (mSurfaceController == null) { |
| 1453 | return; |
| 1454 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1455 | mSurfaceController.setSecure(isSecure); |
Wale Ogunwale | f5ad42f | 2015-06-12 13:59:03 -0700 | [diff] [blame] | 1456 | } |
| 1457 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1458 | // This must be called while inside a transaction. |
| 1459 | boolean performShowLocked() { |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 1460 | if (mWin.isHiddenFromUserLocked()) { |
Wale Ogunwale | 4eef94f | 2015-07-17 22:29:54 -0700 | [diff] [blame] | 1461 | if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + mWin + ", belonging to " + mWin.mOwnerUid); |
| 1462 | mWin.hideLw(false); |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 1463 | return false; |
| 1464 | } |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1465 | if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW && |
| 1466 | mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) { |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 1467 | Slog.v(TAG, "performShow on " + this |
Craig Mautner | c431e89 | 2015-02-11 13:14:26 -0800 | [diff] [blame] | 1468 | + ": mDrawState=" + drawStateToString() + " readyForDisplay=" |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 1469 | + mWin.isReadyForDisplayIgnoringKeyguard() |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1470 | + " starting=" + (mWin.mAttrs.type == TYPE_APPLICATION_STARTING) |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1471 | + " during animation: policyVis=" + mWin.mPolicyVisibility |
| 1472 | + " attHidden=" + mWin.mAttachedHidden |
| 1473 | + " tok.hiddenRequested=" |
| 1474 | + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false) |
| 1475 | + " tok.hidden=" |
| 1476 | + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false) |
| 1477 | + " animating=" + mAnimating |
| 1478 | + " tok animating=" |
Craig Mautner | c431e89 | 2015-02-11 13:14:26 -0800 | [diff] [blame] | 1479 | + (mAppAnimator != null ? mAppAnimator.animating : false) + " Callers=" |
| 1480 | + Debug.getCallers(3)); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1481 | } |
| 1482 | if (mDrawState == READY_TO_SHOW && mWin.isReadyForDisplayIgnoringKeyguard()) { |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1483 | if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW && |
| 1484 | mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) { |
| 1485 | Slog.v(TAG, "Showing " + this |
| 1486 | + " during animation: policyVis=" + mWin.mPolicyVisibility |
| 1487 | + " attHidden=" + mWin.mAttachedHidden |
| 1488 | + " tok.hiddenRequested=" |
| 1489 | + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false) |
| 1490 | + " tok.hidden=" |
| 1491 | + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false) |
| 1492 | + " animating=" + mAnimating |
| 1493 | + " tok animating=" |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 1494 | + (mAppAnimator != null ? mAppAnimator.animating : false)); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1495 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1496 | |
| 1497 | mService.enableScreenIfNeededLocked(); |
| 1498 | |
| 1499 | applyEnterAnimationLocked(); |
| 1500 | |
Craig Mautner | de6198e | 2012-04-19 09:59:31 -0700 | [diff] [blame] | 1501 | // Force the show in the next prepareSurfaceLocked() call. |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1502 | mLastAlpha = -1; |
Craig Mautner | ef25d7a | 2012-05-15 23:01:47 -0700 | [diff] [blame] | 1503 | if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) |
Chong Zhang | 5b2f199 | 2015-11-13 15:40:36 -0800 | [diff] [blame] | 1504 | Slog.v(TAG, "performShowLocked: mDrawState=HAS_DRAWN in " + mWin); |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1505 | mDrawState = HAS_DRAWN; |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 1506 | mService.scheduleAnimationLocked(); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1507 | |
| 1508 | int i = mWin.mChildWindows.size(); |
| 1509 | while (i > 0) { |
| 1510 | i--; |
| 1511 | WindowState c = mWin.mChildWindows.get(i); |
| 1512 | if (c.mAttachedHidden) { |
| 1513 | c.mAttachedHidden = false; |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1514 | if (c.mWinAnimator.mSurfaceController != null) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1515 | c.mWinAnimator.performShowLocked(); |
Filip Gruszczynski | 921171a | 2015-09-30 22:02:57 +0000 | [diff] [blame] | 1516 | // It hadn't been shown, which means layout not |
| 1517 | // performed on it, so now we want to make sure to |
| 1518 | // do a layout. If called from within the transaction |
| 1519 | // loop, this will cause it to restart with a new |
| 1520 | // layout. |
| 1521 | final DisplayContent displayContent = c.getDisplayContent(); |
| 1522 | if (displayContent != null) { |
| 1523 | displayContent.layoutNeeded = true; |
| 1524 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1525 | } |
| 1526 | } |
| 1527 | } |
| 1528 | |
Filip Gruszczynski | b6e6662 | 2015-10-25 16:05:27 -0700 | [diff] [blame] | 1529 | if (mWin.mAttrs.type != TYPE_APPLICATION_STARTING && mWin.mAppToken != null) { |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 1530 | mWin.mAppToken.onFirstWindowDrawn(mWin, this); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1531 | } |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 1532 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1533 | return true; |
| 1534 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1535 | return false; |
| 1536 | } |
| 1537 | |
| 1538 | /** |
| 1539 | * Have the surface flinger show a surface, robustly dealing with |
| 1540 | * error conditions. In particular, if there is not enough memory |
| 1541 | * to show the surface, then we will try to get rid of other surfaces |
| 1542 | * in order to succeed. |
| 1543 | * |
| 1544 | * @return Returns true if the surface was successfully shown. |
| 1545 | */ |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 1546 | private boolean showSurfaceRobustlyLocked() { |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1547 | boolean shown = mSurfaceController.showRobustlyInTransaction(); |
| 1548 | if (!shown) |
| 1549 | return false; |
| 1550 | |
| 1551 | if (mWin.mTurnOnScreen) { |
| 1552 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Show surface turning screen on: " + mWin); |
| 1553 | mWin.mTurnOnScreen = false; |
| 1554 | mAnimator.mBulkUpdateParams |= SET_TURN_ON_SCREEN; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1555 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1556 | return true; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | void applyEnterAnimationLocked() { |
| 1560 | final int transit; |
| 1561 | if (mEnterAnimationPending) { |
| 1562 | mEnterAnimationPending = false; |
| 1563 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 1564 | } else { |
| 1565 | transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 1566 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1567 | applyAnimationLocked(transit, true); |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 1568 | //TODO (multidisplay): Magnification is supported only for the default display. |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1569 | if (mService.mAccessibilityController != null |
Filip Gruszczynski | 69cbc35 | 2015-11-11 13:46:04 -0800 | [diff] [blame] | 1570 | && mWin.getDisplayId() == DEFAULT_DISPLAY) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1571 | mService.mAccessibilityController.onWindowTransitionLocked(mWin, transit); |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 1572 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | /** |
| 1576 | * Choose the correct animation and set it to the passed WindowState. |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1577 | * @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] | 1578 | * then the animation will be app_starting_exit. Any other value loads the animation from |
| 1579 | * the switch statement below. |
| 1580 | * @param isEntrance The animation type the last time this was called. Used to keep from |
| 1581 | * loading the same animation twice. |
| 1582 | * @return true if an animation has been loaded. |
| 1583 | */ |
| 1584 | boolean applyAnimationLocked(int transit, boolean isEntrance) { |
Jorim Jaggi | 44f60cc | 2014-11-07 20:33:51 +0100 | [diff] [blame] | 1585 | if ((mLocalAnimating && mAnimationIsEntrance == isEntrance) |
| 1586 | || mKeyguardGoingAwayAnimation) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1587 | // If we are trying to apply an animation, but already running |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 1588 | // an animation of the same type, then just leave that one alone. |
Jorim Jaggi | 44f60cc | 2014-11-07 20:33:51 +0100 | [diff] [blame] | 1589 | |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 1590 | // If we are in a keyguard exit animation, and the window should animate away, modify |
| 1591 | // keyguard exit animation such that it also fades out. |
| 1592 | if (mAnimation != null && mKeyguardGoingAwayAnimation |
| 1593 | && transit == WindowManagerPolicy.TRANSIT_PREVIEW_DONE) { |
| 1594 | applyFadeoutDuringKeyguardExitAnimation(); |
| 1595 | } |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1596 | return true; |
| 1597 | } |
| 1598 | |
| 1599 | // Only apply an animation if the display isn't frozen. If it is |
| 1600 | // frozen, there is no reason to animate and it can cause strange |
| 1601 | // artifacts when we unfreeze the display if some different animation |
| 1602 | // is running. |
| 1603 | if (mService.okToDisplay()) { |
| 1604 | int anim = mPolicy.selectAnimationLw(mWin, transit); |
| 1605 | int attr = -1; |
| 1606 | Animation a = null; |
| 1607 | if (anim != 0) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1608 | a = anim != -1 ? AnimationUtils.loadAnimation(mContext, anim) : null; |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1609 | } else { |
| 1610 | switch (transit) { |
| 1611 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 1612 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 1613 | break; |
| 1614 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 1615 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 1616 | break; |
| 1617 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 1618 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 1619 | break; |
| 1620 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 1621 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 1622 | break; |
| 1623 | } |
| 1624 | if (attr >= 0) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1625 | a = mService.mAppTransition.loadAnimationAttr(mWin.mAttrs, attr); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1626 | } |
| 1627 | } |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 1628 | if (DEBUG_ANIM) Slog.v(TAG, |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1629 | "applyAnimation: win=" + this |
| 1630 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
Craig Mautner | 4d7349b | 2012-04-20 14:52:47 -0700 | [diff] [blame] | 1631 | + " a=" + a |
Craig Mautner | 8863cca | 2012-09-18 15:04:34 -0700 | [diff] [blame] | 1632 | + " transit=" + transit |
Craig Mautner | 83339b4 | 2012-05-01 22:13:23 -0700 | [diff] [blame] | 1633 | + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3)); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1634 | if (a != null) { |
Filip Gruszczynski | 198dcbf | 2016-01-18 10:02:00 -0800 | [diff] [blame] | 1635 | if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1636 | setAnimation(a); |
| 1637 | mAnimationIsEntrance = isEntrance; |
| 1638 | } |
| 1639 | } else { |
| 1640 | clearAnimation(); |
| 1641 | } |
| 1642 | |
| 1643 | return mAnimation != null; |
| 1644 | } |
| 1645 | |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 1646 | private void applyFadeoutDuringKeyguardExitAnimation() { |
| 1647 | long startTime = mAnimation.getStartTime(); |
| 1648 | long duration = mAnimation.getDuration(); |
| 1649 | long elapsed = mLastAnimationTime - startTime; |
| 1650 | long fadeDuration = duration - elapsed; |
| 1651 | if (fadeDuration <= 0) { |
| 1652 | // Never mind, this would be no visible animation, so abort the animation change. |
| 1653 | return; |
| 1654 | } |
| 1655 | AnimationSet newAnimation = new AnimationSet(false /* shareInterpolator */); |
| 1656 | newAnimation.setDuration(duration); |
| 1657 | newAnimation.setStartTime(startTime); |
| 1658 | newAnimation.addAnimation(mAnimation); |
| 1659 | Animation fadeOut = AnimationUtils.loadAnimation( |
| 1660 | mContext, com.android.internal.R.anim.app_starting_exit); |
| 1661 | fadeOut.setDuration(fadeDuration); |
| 1662 | fadeOut.setStartOffset(elapsed); |
| 1663 | newAnimation.addAnimation(fadeOut); |
Filip Gruszczynski | f52dd20 | 2015-11-15 20:36:38 -0800 | [diff] [blame] | 1664 | newAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(), mAnimDx, mAnimDy); |
Jorim Jaggi | f8d77da | 2014-11-11 16:59:12 +0100 | [diff] [blame] | 1665 | mAnimation = newAnimation; |
| 1666 | } |
| 1667 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1668 | public void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
| 1669 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 1670 | || mAnimation != null) { |
| 1671 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 1672 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 1673 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 1674 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 1675 | } |
| 1676 | if (mHasTransformation || mHasLocalTransformation) { |
| 1677 | pw.print(prefix); pw.print("XForm: has="); |
| 1678 | pw.print(mHasTransformation); |
| 1679 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 1680 | pw.print(" "); mTransformation.printShortString(pw); |
| 1681 | pw.println(); |
| 1682 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1683 | if (mSurfaceController != null) { |
| 1684 | mSurfaceController.dump(pw, prefix, dumpAll); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1685 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1686 | if (dumpAll) { |
| 1687 | pw.print(prefix); pw.print("mDrawState="); pw.print(drawStateToString()); |
| 1688 | pw.print(prefix); pw.print(" mLastHidden="); pw.println(mLastHidden); |
Filip Gruszczynski | f34a04c | 2015-12-07 15:05:49 -0800 | [diff] [blame] | 1689 | pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw); |
| 1690 | pw.print(" last="); mLastSystemDecorRect.printShortString(pw); |
| 1691 | if (mHasClipRect) { |
| 1692 | pw.print(" mLastClipRect="); mLastClipRect.printShortString(pw); |
| 1693 | } |
| 1694 | pw.println(); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1695 | } |
| 1696 | |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1697 | if (mPendingDestroySurface != null) { |
| 1698 | pw.print(prefix); pw.print("mPendingDestroySurface="); |
| 1699 | pw.println(mPendingDestroySurface); |
| 1700 | } |
| 1701 | if (mSurfaceResized || mSurfaceDestroyDeferred) { |
| 1702 | pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized); |
| 1703 | pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred); |
| 1704 | } |
| 1705 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 1706 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 1707 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 1708 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 1709 | } |
| 1710 | if (mHaveMatrix || mWin.mGlobalScale != 1) { |
| 1711 | pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale); |
| 1712 | pw.print(" mDsDx="); pw.print(mDsDx); |
| 1713 | pw.print(" mDtDx="); pw.print(mDtDx); |
| 1714 | pw.print(" mDsDy="); pw.print(mDsDy); |
| 1715 | pw.print(" mDtDy="); pw.println(mDtDy); |
| 1716 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1717 | } |
| 1718 | |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1719 | @Override |
| 1720 | public String toString() { |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 1721 | StringBuffer sb = new StringBuffer("WindowStateAnimator{"); |
| 1722 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 1723 | sb.append(' '); |
| 1724 | sb.append(mWin.mAttrs.getTitle()); |
| 1725 | sb.append('}'); |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1726 | return sb.toString(); |
| 1727 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1728 | |
| 1729 | void reclaimSomeSurfaceMemory(String operation, boolean secure) { |
| 1730 | mService.reclaimSomeSurfaceMemoryLocked(this, operation, secure); |
| 1731 | } |
| 1732 | |
| 1733 | boolean getShown() { |
| 1734 | if (mSurfaceController != null) { |
| 1735 | return mSurfaceController.getShown(); |
| 1736 | } |
| 1737 | return false; |
| 1738 | } |
| 1739 | |
| 1740 | void destroySurface() { |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 1741 | try { |
| 1742 | if (mSurfaceController != null) { |
| 1743 | mSurfaceController.destroyInTransaction(); |
| 1744 | } |
| 1745 | } catch (RuntimeException e) { |
| 1746 | Slog.w(TAG, "Exception thrown when destroying surface " + this |
| 1747 | + " surface " + mSurfaceController + " session " + mSession + ": " + e); |
| 1748 | } finally { |
| 1749 | mWin.setHasSurface(false); |
| 1750 | mSurfaceController = null; |
| 1751 | mDrawState = NO_SURFACE; |
| 1752 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1753 | } |
Filip Gruszczynski | f52dd20 | 2015-11-15 20:36:38 -0800 | [diff] [blame] | 1754 | |
| 1755 | void setMoveAnimation(int left, int top) { |
| 1756 | final Animation a = AnimationUtils.loadAnimation(mContext, |
| 1757 | com.android.internal.R.anim.window_move_from_decor); |
| 1758 | setAnimation(a); |
| 1759 | mAnimDx = mWin.mLastFrame.left - left; |
| 1760 | mAnimDy = mWin.mLastFrame.top - top; |
| 1761 | mAnimateMove = true; |
| 1762 | } |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1763 | } |