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 | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 19 | import static android.view.Display.DEFAULT_DISPLAY; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 20 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE; |
| 21 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS; |
| 22 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 23 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 24 | import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE; |
Filip Gruszczynski | 78a08ee | 2015-11-08 18:04:32 -0800 | [diff] [blame] | 25 | import static com.android.server.wm.WindowSurfacePlacer.SET_UPDATE_ROTATION; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 26 | |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 27 | import android.content.Context; |
Jorim Jaggi | d9cabc5 | 2015-10-27 09:38:16 -0700 | [diff] [blame] | 28 | import android.os.Trace; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 29 | import android.util.Slog; |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 30 | import android.util.SparseArray; |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 31 | import android.util.TimeUtils; |
Filip Gruszczynski | 78a08ee | 2015-11-08 18:04:32 -0800 | [diff] [blame] | 32 | import android.view.Choreographer; |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 33 | import android.view.SurfaceControl; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 34 | |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 35 | import com.android.server.AnimationThread; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 36 | import com.android.server.policy.WindowManagerPolicy; |
Jorim Jaggi | d6d6de6 | 2017-03-31 15:05:13 +0200 | [diff] [blame] | 37 | |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 38 | import java.io.PrintWriter; |
Jorim Jaggi | a384403 | 2018-01-03 15:54:43 +0100 | [diff] [blame] | 39 | import java.util.ArrayList; |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 40 | |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 41 | /** |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 42 | * Singleton class that carries out the animations and Surface operations in a separate task |
| 43 | * on behalf of WindowManagerService. |
| 44 | */ |
| 45 | public class WindowAnimator { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 46 | private static final String TAG = TAG_WITH_CLASS_NAME ? "WindowAnimator" : TAG_WM; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 47 | |
| 48 | final WindowManagerService mService; |
| 49 | final Context mContext; |
| 50 | final WindowManagerPolicy mPolicy; |
| 51 | |
Jorim Jaggi | 3787561 | 2015-02-19 21:05:31 +0100 | [diff] [blame] | 52 | /** Is any window animating? */ |
Wale Ogunwale | 69cf50f | 2015-11-13 11:08:36 -0800 | [diff] [blame] | 53 | private boolean mAnimating; |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 54 | private boolean mLastRootAnimating; |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 55 | |
Riley Andrews | 6d35416 | 2014-11-19 15:21:52 -0800 | [diff] [blame] | 56 | final Choreographer.FrameCallback mAnimationFrameCallback; |
Craig Mautner | 1caa399 | 2012-06-22 09:46:48 -0700 | [diff] [blame] | 57 | |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 58 | /** Time of current animation step. Reset on each iteration */ |
| 59 | long mCurrentTime; |
| 60 | |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 61 | boolean mAppWindowAnimating; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 62 | /** Skip repeated AppWindowTokens initialization. Note that AppWindowsToken's version of this |
| 63 | * is a long initialized to Long.MIN_VALUE so that it doesn't match this value on startup. */ |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 64 | int mAnimTransactionSequence; |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 65 | |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 66 | /** Window currently running an animation that has requested it be detached |
| 67 | * from the wallpaper. This means we need to ensure the wallpaper is |
| 68 | * visible behind it in case it animates in a way that would allow it to be |
| 69 | * seen. If multiple windows satisfy this, use the lowest window. */ |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 70 | WindowState mWindowDetachedWallpaper = null; |
Craig Mautner | 01cd0e7 | 2012-06-18 10:19:11 -0700 | [diff] [blame] | 71 | |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 72 | int mBulkUpdateParams = 0; |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 73 | Object mLastWindowFreezeSource; |
Craig Mautner | a608b88 | 2012-03-30 13:03:49 -0700 | [diff] [blame] | 74 | |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 75 | SparseArray<DisplayContentsAnimator> mDisplayContentsAnimators = new SparseArray<>(2); |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 76 | |
Jorim Jaggi | 4130a68 | 2018-01-09 14:28:44 +0100 | [diff] [blame] | 77 | private boolean mInitialized = false; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 78 | |
Filip Gruszczynski | 78a08ee | 2015-11-08 18:04:32 -0800 | [diff] [blame] | 79 | // When set to true the animator will go over all windows after an animation frame is posted and |
| 80 | // check if some got replaced and can be removed. |
| 81 | private boolean mRemoveReplacedWindows = false; |
| 82 | |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 83 | private Choreographer mChoreographer; |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 84 | |
Jorim Jaggi | 561eeb5 | 2017-04-28 16:39:19 +0200 | [diff] [blame] | 85 | /** |
| 86 | * Indicates whether we have an animation frame callback scheduled, which will happen at |
| 87 | * vsync-app and then schedule the animation tick at the right time (vsync-sf). |
| 88 | */ |
| 89 | private boolean mAnimationFrameCallbackScheduled; |
| 90 | |
Jorim Jaggi | a384403 | 2018-01-03 15:54:43 +0100 | [diff] [blame] | 91 | /** |
| 92 | * A list of runnable that need to be run after {@link WindowContainer#prepareSurfaces} is |
| 93 | * executed and the corresponding transaction is closed and applied. |
| 94 | */ |
| 95 | private final ArrayList<Runnable> mAfterPrepareSurfacesRunnables = new ArrayList<>(); |
Chavi Weingarten | 16d0d07 | 2018-02-12 23:50:28 +0000 | [diff] [blame] | 96 | private boolean mInExecuteAfterPrepareSurfacesRunnables; |
Jorim Jaggi | a384403 | 2018-01-03 15:54:43 +0100 | [diff] [blame] | 97 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 98 | private final SurfaceControl.Transaction mTransaction = new SurfaceControl.Transaction(); |
| 99 | |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 100 | WindowAnimator(final WindowManagerService service) { |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 101 | mService = service; |
Craig Mautner | 918b53b | 2012-07-09 14:15:54 -0700 | [diff] [blame] | 102 | mContext = service.mContext; |
| 103 | mPolicy = service.mPolicy; |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 104 | AnimationThread.getHandler().runWithScissors( |
Jorim Jaggi | 34a0cdb | 2017-06-08 15:40:38 -0700 | [diff] [blame] | 105 | () -> mChoreographer = Choreographer.getSfInstance(), 0 /* timeout */); |
Craig Mautner | 1caa399 | 2012-06-22 09:46:48 -0700 | [diff] [blame] | 106 | |
Jorim Jaggi | d6d6de6 | 2017-03-31 15:05:13 +0200 | [diff] [blame] | 107 | mAnimationFrameCallback = frameTimeNs -> { |
Jorim Jaggi | 561eeb5 | 2017-04-28 16:39:19 +0200 | [diff] [blame] | 108 | synchronized (mService.mWindowMap) { |
Jorim Jaggi | 561eeb5 | 2017-04-28 16:39:19 +0200 | [diff] [blame] | 109 | mAnimationFrameCallbackScheduled = false; |
Jorim Jaggi | 561eeb5 | 2017-04-28 16:39:19 +0200 | [diff] [blame] | 110 | } |
Jorim Jaggi | 34a0cdb | 2017-06-08 15:40:38 -0700 | [diff] [blame] | 111 | animate(frameTimeNs); |
Jorim Jaggi | d6d6de6 | 2017-03-31 15:05:13 +0200 | [diff] [blame] | 112 | }; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 113 | } |
Craig Mautner | 9e80944 | 2012-06-22 17:13:04 -0700 | [diff] [blame] | 114 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 115 | void addDisplayLocked(final int displayId) { |
Bryce Lee | d187126 | 2017-06-12 14:12:29 -0700 | [diff] [blame] | 116 | // Create the DisplayContentsAnimator object by retrieving it if the associated |
| 117 | // {@link DisplayContent} exists. |
Craig Mautner | ac439e5 | 2012-09-21 08:58:34 -0700 | [diff] [blame] | 118 | getDisplayContentsAnimatorLocked(displayId); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 119 | if (displayId == DEFAULT_DISPLAY) { |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 120 | mInitialized = true; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | void removeDisplayLocked(final int displayId) { |
Craig Mautner | d5523dc | 2012-10-02 13:49:22 -0700 | [diff] [blame] | 125 | final DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.get(displayId); |
| 126 | if (displayAnimator != null) { |
Craig Mautner | d5523dc | 2012-10-02 13:49:22 -0700 | [diff] [blame] | 127 | if (displayAnimator.mScreenRotationAnimation != null) { |
| 128 | displayAnimator.mScreenRotationAnimation.kill(); |
| 129 | displayAnimator.mScreenRotationAnimation = null; |
| 130 | } |
Craig Mautner | d5523dc | 2012-10-02 13:49:22 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 133 | mDisplayContentsAnimators.delete(displayId); |
Craig Mautner | 1caa399 | 2012-06-22 09:46:48 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 136 | /** |
| 137 | * DO NOT HOLD THE WINDOW MANAGER LOCK WHILE CALLING THIS METHOD. Reason: the method closes |
| 138 | * an animation transaction, that might be blocking until the next sf-vsync, so we want to make |
| 139 | * sure other threads can make progress if this happens. |
| 140 | */ |
| 141 | private void animate(long frameTimeNs) { |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 142 | |
Jorim Jaggi | 836dac4 | 2017-08-08 15:12:20 +0200 | [diff] [blame] | 143 | synchronized (mService.mWindowMap) { |
| 144 | if (!mInitialized) { |
| 145 | return; |
| 146 | } |
Svetoslav | b180d77 | 2014-09-10 22:07:19 -0700 | [diff] [blame] | 147 | |
Jorim Jaggi | 836dac4 | 2017-08-08 15:12:20 +0200 | [diff] [blame] | 148 | // Schedule next frame already such that back-pressure happens continuously |
| 149 | scheduleAnimation(); |
| 150 | } |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 151 | |
Jorim Jaggi | 836dac4 | 2017-08-08 15:12:20 +0200 | [diff] [blame] | 152 | synchronized (mService.mWindowMap) { |
| 153 | mCurrentTime = frameTimeNs / TimeUtils.NANOS_PER_MS; |
| 154 | mBulkUpdateParams = SET_ORIENTATION_CHANGE_COMPLETE; |
| 155 | mAnimating = false; |
Jorim Jaggi | 836dac4 | 2017-08-08 15:12:20 +0200 | [diff] [blame] | 156 | if (DEBUG_WINDOW_TRACE) { |
| 157 | Slog.i(TAG, "!!! animate: entry time=" + mCurrentTime); |
| 158 | } |
| 159 | |
| 160 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION animate"); |
| 161 | mService.openSurfaceTransaction(); |
| 162 | try { |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 163 | final AccessibilityController accessibilityController = |
| 164 | mService.mAccessibilityController; |
| 165 | final int numDisplays = mDisplayContentsAnimators.size(); |
| 166 | for (int i = 0; i < numDisplays; i++) { |
| 167 | final int displayId = mDisplayContentsAnimators.keyAt(i); |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame] | 168 | final DisplayContent dc = mService.mRoot.getDisplayContent(displayId); |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 169 | DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.valueAt(i); |
| 170 | |
| 171 | final ScreenRotationAnimation screenRotationAnimation = |
| 172 | displayAnimator.mScreenRotationAnimation; |
| 173 | if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) { |
| 174 | if (screenRotationAnimation.stepAnimationLocked(mCurrentTime)) { |
| 175 | setAnimating(true); |
| 176 | } else { |
| 177 | mBulkUpdateParams |= SET_UPDATE_ROTATION; |
| 178 | screenRotationAnimation.kill(); |
| 179 | displayAnimator.mScreenRotationAnimation = null; |
| 180 | |
| 181 | //TODO (multidisplay): Accessibility supported only for the default |
| 182 | // display. |
| 183 | if (accessibilityController != null && dc.isDefaultDisplay) { |
| 184 | // We just finished rotation animation which means we did not |
| 185 | // announce the rotation and waited for it to end, announce now. |
| 186 | accessibilityController.onRotationChangedLocked( |
| 187 | mService.getDefaultDisplayContentLocked()); |
| 188 | } |
Svetoslav | b180d77 | 2014-09-10 22:07:19 -0700 | [diff] [blame] | 189 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 190 | } |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 191 | |
| 192 | // Update animations of all applications, including those |
| 193 | // associated with exiting/removed apps |
| 194 | ++mAnimTransactionSequence; |
| 195 | dc.updateWindowsForAnimator(this); |
| 196 | dc.updateWallpaperForAnimator(this); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 197 | dc.prepareSurfaces(); |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | for (int i = 0; i < numDisplays; i++) { |
| 201 | final int displayId = mDisplayContentsAnimators.keyAt(i); |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame] | 202 | final DisplayContent dc = mService.mRoot.getDisplayContent(displayId); |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 203 | |
| 204 | dc.checkAppWindowsReadyToShow(); |
| 205 | |
| 206 | final ScreenRotationAnimation screenRotationAnimation = |
| 207 | mDisplayContentsAnimators.valueAt(i).mScreenRotationAnimation; |
| 208 | if (screenRotationAnimation != null) { |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 209 | screenRotationAnimation.updateSurfaces(mTransaction); |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 210 | } |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 211 | orAnimating(dc.getDockedDividerController().animate(mCurrentTime)); |
| 212 | //TODO (multidisplay): Magnification is supported only for the default display. |
| 213 | if (accessibilityController != null && dc.isDefaultDisplay) { |
| 214 | accessibilityController.drawMagnifiedRegionBorderIfNeededLocked(); |
| 215 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 216 | } |
Craig Mautner | ea3a09a | 2012-09-04 09:49:35 -0700 | [diff] [blame] | 217 | |
Jorim Jaggi | 836dac4 | 2017-08-08 15:12:20 +0200 | [diff] [blame] | 218 | if (!mAnimating) { |
| 219 | cancelAnimation(); |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 220 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 221 | |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 222 | if (mService.mWatermark != null) { |
| 223 | mService.mWatermark.drawIfNeeded(); |
| 224 | } |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 225 | |
| 226 | SurfaceControl.mergeToGlobalTransaction(mTransaction); |
Jorim Jaggi | 836dac4 | 2017-08-08 15:12:20 +0200 | [diff] [blame] | 227 | } catch (RuntimeException e) { |
| 228 | Slog.wtf(TAG, "Unhandled exception in Window Manager", e); |
| 229 | } finally { |
Adrian Roos | 111aff9 | 2017-09-27 18:11:46 +0200 | [diff] [blame] | 230 | mService.closeSurfaceTransaction("WindowAnimator"); |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 231 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION animate"); |
Jorim Jaggi | a41b729 | 2017-05-11 23:50:34 +0200 | [diff] [blame] | 232 | } |
Jorim Jaggi | d9cabc5 | 2015-10-27 09:38:16 -0700 | [diff] [blame] | 233 | |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 234 | boolean hasPendingLayoutChanges = mService.mRoot.hasPendingLayoutChanges(this); |
| 235 | boolean doRequest = false; |
| 236 | if (mBulkUpdateParams != 0) { |
| 237 | doRequest = mService.mRoot.copyAnimToLayoutParams(); |
Jorim Jaggi | d9cabc5 | 2015-10-27 09:38:16 -0700 | [diff] [blame] | 238 | } |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 239 | |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 240 | if (hasPendingLayoutChanges || doRequest) { |
Jorim Jaggi | 4130a68 | 2018-01-09 14:28:44 +0100 | [diff] [blame] | 241 | mService.mWindowPlacerLocked.requestTraversal(); |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 242 | } |
Filip Gruszczynski | 78a08ee | 2015-11-08 18:04:32 -0800 | [diff] [blame] | 243 | |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 244 | final boolean rootAnimating = mService.mRoot.isSelfOrChildAnimating(); |
| 245 | if (rootAnimating && !mLastRootAnimating) { |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 246 | |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 247 | // Usually app transitions but quite a load onto the system already (with all the |
| 248 | // things happening in app), so pause task snapshot persisting to not increase the |
| 249 | // load. |
| 250 | mService.mTaskSnapshotController.setPersisterPaused(true); |
Jorim Jaggi | dc9385a | 2017-05-13 02:00:31 +0200 | [diff] [blame] | 251 | Trace.asyncTraceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "animating", 0); |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 252 | } |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 253 | if (!rootAnimating && mLastRootAnimating) { |
Jorim Jaggi | 4130a68 | 2018-01-09 14:28:44 +0100 | [diff] [blame] | 254 | mService.mWindowPlacerLocked.requestTraversal(); |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 255 | mService.mTaskSnapshotController.setPersisterPaused(false); |
Jorim Jaggi | dc9385a | 2017-05-13 02:00:31 +0200 | [diff] [blame] | 256 | Trace.asyncTraceEnd(Trace.TRACE_TAG_WINDOW_MANAGER, "animating", 0); |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 257 | } |
| 258 | |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 259 | mLastRootAnimating = rootAnimating; |
Jorim Jaggi | dc9385a | 2017-05-13 02:00:31 +0200 | [diff] [blame] | 260 | |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 261 | if (mRemoveReplacedWindows) { |
| 262 | mService.mRoot.removeReplacedWindows(); |
| 263 | mRemoveReplacedWindows = false; |
| 264 | } |
| 265 | |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 266 | mService.destroyPreservedSurfaceLocked(); |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 267 | |
Jorim Jaggi | a384403 | 2018-01-03 15:54:43 +0100 | [diff] [blame] | 268 | executeAfterPrepareSurfacesRunnables(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 269 | |
Jorim Jaggi | 9b19fd4 | 2017-05-11 16:27:06 +0200 | [diff] [blame] | 270 | if (DEBUG_WINDOW_TRACE) { |
| 271 | Slog.i(TAG, "!!! animate: exit mAnimating=" + mAnimating |
| 272 | + " mBulkUpdateParams=" + Integer.toHexString(mBulkUpdateParams) |
| 273 | + " mPendingLayoutChanges(DEFAULT_DISPLAY)=" |
| 274 | + Integer.toHexString(getPendingLayoutChanges(DEFAULT_DISPLAY))); |
| 275 | } |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 276 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 279 | private static String bulkUpdateParamsToString(int bulkUpdateParams) { |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 280 | StringBuilder builder = new StringBuilder(128); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 281 | if ((bulkUpdateParams & WindowSurfacePlacer.SET_UPDATE_ROTATION) != 0) { |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 282 | builder.append(" UPDATE_ROTATION"); |
| 283 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 284 | if ((bulkUpdateParams & WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE) != 0) { |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 285 | builder.append(" WALLPAPER_MAY_CHANGE"); |
| 286 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 287 | if ((bulkUpdateParams & WindowSurfacePlacer.SET_FORCE_HIDING_CHANGED) != 0) { |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 288 | builder.append(" FORCE_HIDING_CHANGED"); |
| 289 | } |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 290 | if ((bulkUpdateParams & WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE) != 0) { |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 291 | builder.append(" ORIENTATION_CHANGE_COMPLETE"); |
| 292 | } |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 293 | return builder.toString(); |
| 294 | } |
| 295 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 296 | public void dumpLocked(PrintWriter pw, String prefix, boolean dumpAll) { |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 297 | final String subPrefix = " " + prefix; |
| 298 | final String subSubPrefix = " " + subPrefix; |
| 299 | |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 300 | for (int i = 0; i < mDisplayContentsAnimators.size(); i++) { |
| 301 | pw.print(prefix); pw.print("DisplayContentsAnimator #"); |
| 302 | pw.print(mDisplayContentsAnimators.keyAt(i)); |
| 303 | pw.println(":"); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 304 | final DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.valueAt(i); |
| 305 | final DisplayContent dc = |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame] | 306 | mService.mRoot.getDisplayContent(mDisplayContentsAnimators.keyAt(i)); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 307 | dc.dumpWindowAnimators(pw, subPrefix); |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 308 | if (displayAnimator.mScreenRotationAnimation != null) { |
| 309 | pw.print(subPrefix); pw.println("mScreenRotationAnimation:"); |
| 310 | displayAnimator.mScreenRotationAnimation.printTo(subSubPrefix, pw); |
| 311 | } else if (dumpAll) { |
| 312 | pw.print(subPrefix); pw.println("no ScreenRotationAnimation "); |
| 313 | } |
Craig Mautner | e7cfceb | 2015-02-04 15:57:06 -0800 | [diff] [blame] | 314 | pw.println(); |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | pw.println(); |
| 318 | |
| 319 | if (dumpAll) { |
| 320 | pw.print(prefix); pw.print("mAnimTransactionSequence="); |
| 321 | pw.print(mAnimTransactionSequence); |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 322 | pw.print(prefix); pw.print("mCurrentTime="); |
| 323 | pw.println(TimeUtils.formatUptime(mCurrentTime)); |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 324 | } |
| 325 | if (mBulkUpdateParams != 0) { |
| 326 | pw.print(prefix); pw.print("mBulkUpdateParams=0x"); |
| 327 | pw.print(Integer.toHexString(mBulkUpdateParams)); |
| 328 | pw.println(bulkUpdateParamsToString(mBulkUpdateParams)); |
| 329 | } |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 330 | if (mWindowDetachedWallpaper != null) { |
| 331 | pw.print(prefix); pw.print("mWindowDetachedWallpaper="); |
| 332 | pw.println(mWindowDetachedWallpaper); |
| 333 | } |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 334 | } |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 335 | |
Craig Mautner | 66f78d7 | 2012-12-04 16:46:50 -0800 | [diff] [blame] | 336 | int getPendingLayoutChanges(final int displayId) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 337 | if (displayId < 0) { |
| 338 | return 0; |
| 339 | } |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame] | 340 | final DisplayContent displayContent = mService.mRoot.getDisplayContent(displayId); |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 341 | return (displayContent != null) ? displayContent.pendingLayoutChanges : 0; |
Craig Mautner | 66f78d7 | 2012-12-04 16:46:50 -0800 | [diff] [blame] | 342 | } |
| 343 | |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 344 | void setPendingLayoutChanges(final int displayId, final int changes) { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 345 | if (displayId < 0) { |
| 346 | return; |
| 347 | } |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame] | 348 | final DisplayContent displayContent = mService.mRoot.getDisplayContent(displayId); |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 349 | if (displayContent != null) { |
| 350 | displayContent.pendingLayoutChanges |= changes; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 351 | } |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 354 | private DisplayContentsAnimator getDisplayContentsAnimatorLocked(int displayId) { |
Bryce Lee | d187126 | 2017-06-12 14:12:29 -0700 | [diff] [blame] | 355 | if (displayId < 0) { |
| 356 | return null; |
| 357 | } |
| 358 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 359 | DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.get(displayId); |
Bryce Lee | d187126 | 2017-06-12 14:12:29 -0700 | [diff] [blame] | 360 | |
| 361 | // It is possible that this underlying {@link DisplayContent} has been removed. In this |
| 362 | // case, we do not want to create an animator associated with it as {link #animate} will |
| 363 | // fail. |
| 364 | if (displayAnimator == null && mService.mRoot.getDisplayContent(displayId) != null) { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 365 | displayAnimator = new DisplayContentsAnimator(); |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 366 | mDisplayContentsAnimators.put(displayId, displayAnimator); |
| 367 | } |
| 368 | return displayAnimator; |
| 369 | } |
| 370 | |
| 371 | void setScreenRotationAnimationLocked(int displayId, ScreenRotationAnimation animation) { |
Bryce Lee | d187126 | 2017-06-12 14:12:29 -0700 | [diff] [blame] | 372 | final DisplayContentsAnimator animator = getDisplayContentsAnimatorLocked(displayId); |
| 373 | |
| 374 | if (animator != null) { |
| 375 | animator.mScreenRotationAnimation = animation; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 376 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | ScreenRotationAnimation getScreenRotationAnimationLocked(int displayId) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 380 | if (displayId < 0) { |
| 381 | return null; |
| 382 | } |
Bryce Lee | d187126 | 2017-06-12 14:12:29 -0700 | [diff] [blame] | 383 | |
| 384 | DisplayContentsAnimator animator = getDisplayContentsAnimatorLocked(displayId); |
| 385 | return animator != null? animator.mScreenRotationAnimation : null; |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Filip Gruszczynski | 78a08ee | 2015-11-08 18:04:32 -0800 | [diff] [blame] | 388 | void requestRemovalOfReplacedWindows(WindowState win) { |
Filip Gruszczynski | 78a08ee | 2015-11-08 18:04:32 -0800 | [diff] [blame] | 389 | mRemoveReplacedWindows = true; |
| 390 | } |
| 391 | |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 392 | void scheduleAnimation() { |
Jorim Jaggi | 561eeb5 | 2017-04-28 16:39:19 +0200 | [diff] [blame] | 393 | if (!mAnimationFrameCallbackScheduled) { |
| 394 | mAnimationFrameCallbackScheduled = true; |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 395 | mChoreographer.postFrameCallback(mAnimationFrameCallback); |
| 396 | } |
| 397 | } |
| 398 | |
Jorim Jaggi | 836dac4 | 2017-08-08 15:12:20 +0200 | [diff] [blame] | 399 | private void cancelAnimation() { |
| 400 | if (mAnimationFrameCallbackScheduled) { |
| 401 | mAnimationFrameCallbackScheduled = false; |
| 402 | mChoreographer.removeFrameCallback(mAnimationFrameCallback); |
| 403 | } |
| 404 | } |
| 405 | |
Craig Mautner | ac439e5 | 2012-09-21 08:58:34 -0700 | [diff] [blame] | 406 | private class DisplayContentsAnimator { |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 407 | ScreenRotationAnimation mScreenRotationAnimation = null; |
| 408 | } |
Wale Ogunwale | 69cf50f | 2015-11-13 11:08:36 -0800 | [diff] [blame] | 409 | |
| 410 | boolean isAnimating() { |
| 411 | return mAnimating; |
| 412 | } |
| 413 | |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 414 | boolean isAnimationScheduled() { |
Jorim Jaggi | 34a0cdb | 2017-06-08 15:40:38 -0700 | [diff] [blame] | 415 | return mAnimationFrameCallbackScheduled; |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | Choreographer getChoreographer() { |
| 419 | return mChoreographer; |
| 420 | } |
| 421 | |
Wale Ogunwale | 69cf50f | 2015-11-13 11:08:36 -0800 | [diff] [blame] | 422 | void setAnimating(boolean animating) { |
| 423 | mAnimating = animating; |
| 424 | } |
| 425 | |
| 426 | void orAnimating(boolean animating) { |
| 427 | mAnimating |= animating; |
| 428 | } |
Jorim Jaggi | a384403 | 2018-01-03 15:54:43 +0100 | [diff] [blame] | 429 | |
| 430 | /** |
| 431 | * Adds a runnable to be executed after {@link WindowContainer#prepareSurfaces} is called and |
| 432 | * the corresponding transaction is closed and applied. |
| 433 | */ |
| 434 | void addAfterPrepareSurfacesRunnable(Runnable r) { |
Chavi Weingarten | 16d0d07 | 2018-02-12 23:50:28 +0000 | [diff] [blame] | 435 | // If runnables are already being handled in executeAfterPrepareSurfacesRunnable, then just |
| 436 | // immediately execute the runnable passed in. |
| 437 | if (mInExecuteAfterPrepareSurfacesRunnables) { |
| 438 | r.run(); |
| 439 | return; |
| 440 | } |
| 441 | |
Jorim Jaggi | a384403 | 2018-01-03 15:54:43 +0100 | [diff] [blame] | 442 | mAfterPrepareSurfacesRunnables.add(r); |
| 443 | scheduleAnimation(); |
| 444 | } |
| 445 | |
Chavi Weingarten | 16d0d07 | 2018-02-12 23:50:28 +0000 | [diff] [blame] | 446 | void executeAfterPrepareSurfacesRunnables() { |
| 447 | |
| 448 | // Don't even think about to start recursing! |
| 449 | if (mInExecuteAfterPrepareSurfacesRunnables) { |
| 450 | return; |
| 451 | } |
| 452 | mInExecuteAfterPrepareSurfacesRunnables = true; |
Jorim Jaggi | a384403 | 2018-01-03 15:54:43 +0100 | [diff] [blame] | 453 | |
| 454 | // Traverse in order they were added. |
| 455 | final int size = mAfterPrepareSurfacesRunnables.size(); |
| 456 | for (int i = 0; i < size; i++) { |
| 457 | mAfterPrepareSurfacesRunnables.get(i).run(); |
| 458 | } |
| 459 | mAfterPrepareSurfacesRunnables.clear(); |
Chavi Weingarten | 16d0d07 | 2018-02-12 23:50:28 +0000 | [diff] [blame] | 460 | mInExecuteAfterPrepareSurfacesRunnables = false; |
Jorim Jaggi | a384403 | 2018-01-03 15:54:43 +0100 | [diff] [blame] | 461 | } |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 462 | } |