blob: 793ffce2466ecfcc3ef88a7563c9a928e35616dc [file] [log] [blame]
Craig Mautnerc2c0a612014-02-20 20:25:41 -08001/*
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 Mautner764983d2012-03-22 11:37:36 -070016
17package com.android.server.wm;
18
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070019import static android.view.Display.DEFAULT_DISPLAY;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080020import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE;
21import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
22import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
23import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070024import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -080025import static com.android.server.wm.WindowSurfacePlacer.SET_UPDATE_ROTATION;
Craig Mautnera608b882012-03-30 13:03:49 -070026
Craig Mautner764983d2012-03-22 11:37:36 -070027import android.content.Context;
Jorim Jaggid9cabc52015-10-27 09:38:16 -070028import android.os.Trace;
Craig Mautner764983d2012-03-22 11:37:36 -070029import android.util.Slog;
Craig Mautnera91f9e22012-09-14 16:22:08 -070030import android.util.SparseArray;
Dianne Hackborn529e7442012-11-01 14:22:28 -070031import android.util.TimeUtils;
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -080032import android.view.Choreographer;
Robert Carrae606b42018-02-15 15:36:23 -080033import android.view.SurfaceControl;
Craig Mautner764983d2012-03-22 11:37:36 -070034
Jorim Jaggied7993b2017-03-28 18:50:01 +010035import com.android.server.AnimationThread;
Adrian Roose99bc052017-11-20 17:55:31 +010036import com.android.server.policy.WindowManagerPolicy;
Jorim Jaggid6d6de62017-03-31 15:05:13 +020037
Craig Mautnere7ae2502012-03-26 17:11:19 -070038import java.io.PrintWriter;
Jorim Jaggia3844032018-01-03 15:54:43 +010039import java.util.ArrayList;
Craig Mautnere7ae2502012-03-26 17:11:19 -070040
Craig Mautner764983d2012-03-22 11:37:36 -070041/**
Craig Mautner764983d2012-03-22 11:37:36 -070042 * Singleton class that carries out the animations and Surface operations in a separate task
43 * on behalf of WindowManagerService.
44 */
45public class WindowAnimator {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080046 private static final String TAG = TAG_WITH_CLASS_NAME ? "WindowAnimator" : TAG_WM;
Craig Mautner764983d2012-03-22 11:37:36 -070047
48 final WindowManagerService mService;
49 final Context mContext;
50 final WindowManagerPolicy mPolicy;
51
Jorim Jaggi37875612015-02-19 21:05:31 +010052 /** Is any window animating? */
Wale Ogunwale69cf50f2015-11-13 11:08:36 -080053 private boolean mAnimating;
Jorim Jaggib0fc8172017-11-23 17:04:08 +000054 private boolean mLastRootAnimating;
Craig Mautner01cd0e72012-06-18 10:19:11 -070055
Riley Andrews6d354162014-11-19 15:21:52 -080056 final Choreographer.FrameCallback mAnimationFrameCallback;
Craig Mautner1caa3992012-06-22 09:46:48 -070057
Craig Mautner764983d2012-03-22 11:37:36 -070058 /** Time of current animation step. Reset on each iteration */
59 long mCurrentTime;
60
Jorim Jaggif5f9e122017-10-24 18:21:09 +020061 boolean mAppWindowAnimating;
Craig Mautner764983d2012-03-22 11:37:36 -070062 /** 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 Ogunwale824ab5c2016-10-20 09:31:56 -070064 int mAnimTransactionSequence;
Craig Mautner764983d2012-03-22 11:37:36 -070065
Craig Mautnerae446592012-12-06 19:05:05 -080066 /** 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 Mautnere7ae2502012-03-26 17:11:19 -070070 WindowState mWindowDetachedWallpaper = null;
Craig Mautner01cd0e72012-06-18 10:19:11 -070071
Craig Mautnera608b882012-03-30 13:03:49 -070072 int mBulkUpdateParams = 0;
Dianne Hackborna57c6952013-03-29 14:46:40 -070073 Object mLastWindowFreezeSource;
Craig Mautnera608b882012-03-30 13:03:49 -070074
Filip Gruszczynski4501d232015-09-02 13:00:02 -070075 SparseArray<DisplayContentsAnimator> mDisplayContentsAnimators = new SparseArray<>(2);
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070076
Jorim Jaggi4130a682018-01-09 14:28:44 +010077 private boolean mInitialized = false;
Craig Mautnerb47bbc32012-08-22 17:41:48 -070078
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -080079 // 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 Jaggied7993b2017-03-28 18:50:01 +010083 private Choreographer mChoreographer;
Jorim Jaggied7993b2017-03-28 18:50:01 +010084
Jorim Jaggi561eeb52017-04-28 16:39:19 +020085 /**
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 Jaggia3844032018-01-03 15:54:43 +010091 /**
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 Weingarten16d0d072018-02-12 23:50:28 +000096 private boolean mInExecuteAfterPrepareSurfacesRunnables;
Jorim Jaggia3844032018-01-03 15:54:43 +010097
Robert Carrae606b42018-02-15 15:36:23 -080098 private final SurfaceControl.Transaction mTransaction = new SurfaceControl.Transaction();
99
Craig Mautner918b53b2012-07-09 14:15:54 -0700100 WindowAnimator(final WindowManagerService service) {
Craig Mautner764983d2012-03-22 11:37:36 -0700101 mService = service;
Craig Mautner918b53b2012-07-09 14:15:54 -0700102 mContext = service.mContext;
103 mPolicy = service.mPolicy;
Jorim Jaggied7993b2017-03-28 18:50:01 +0100104 AnimationThread.getHandler().runWithScissors(
Jorim Jaggi34a0cdb2017-06-08 15:40:38 -0700105 () -> mChoreographer = Choreographer.getSfInstance(), 0 /* timeout */);
Craig Mautner1caa3992012-06-22 09:46:48 -0700106
Jorim Jaggid6d6de62017-03-31 15:05:13 +0200107 mAnimationFrameCallback = frameTimeNs -> {
Jorim Jaggi561eeb52017-04-28 16:39:19 +0200108 synchronized (mService.mWindowMap) {
Jorim Jaggi561eeb52017-04-28 16:39:19 +0200109 mAnimationFrameCallbackScheduled = false;
Jorim Jaggi561eeb52017-04-28 16:39:19 +0200110 }
Jorim Jaggi34a0cdb2017-06-08 15:40:38 -0700111 animate(frameTimeNs);
Jorim Jaggid6d6de62017-03-31 15:05:13 +0200112 };
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700113 }
Craig Mautner9e809442012-06-22 17:13:04 -0700114
Craig Mautnera91f9e22012-09-14 16:22:08 -0700115 void addDisplayLocked(final int displayId) {
Bryce Leed1871262017-06-12 14:12:29 -0700116 // Create the DisplayContentsAnimator object by retrieving it if the associated
117 // {@link DisplayContent} exists.
Craig Mautnerac439e52012-09-21 08:58:34 -0700118 getDisplayContentsAnimatorLocked(displayId);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700119 if (displayId == DEFAULT_DISPLAY) {
Craig Mautnera91f9e22012-09-14 16:22:08 -0700120 mInitialized = true;
121 }
122 }
123
124 void removeDisplayLocked(final int displayId) {
Craig Mautnerd5523dc2012-10-02 13:49:22 -0700125 final DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.get(displayId);
126 if (displayAnimator != null) {
Craig Mautnerd5523dc2012-10-02 13:49:22 -0700127 if (displayAnimator.mScreenRotationAnimation != null) {
128 displayAnimator.mScreenRotationAnimation.kill();
129 displayAnimator.mScreenRotationAnimation = null;
130 }
Craig Mautnerd5523dc2012-10-02 13:49:22 -0700131 }
132
Craig Mautnera91f9e22012-09-14 16:22:08 -0700133 mDisplayContentsAnimators.delete(displayId);
Craig Mautner1caa3992012-06-22 09:46:48 -0700134 }
135
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200136 /**
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 Mautnera91f9e22012-09-14 16:22:08 -0700142
Jorim Jaggi836dac42017-08-08 15:12:20 +0200143 synchronized (mService.mWindowMap) {
144 if (!mInitialized) {
145 return;
146 }
Svetoslavb180d772014-09-10 22:07:19 -0700147
Jorim Jaggi836dac42017-08-08 15:12:20 +0200148 // Schedule next frame already such that back-pressure happens continuously
149 scheduleAnimation();
150 }
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200151
Jorim Jaggi836dac42017-08-08 15:12:20 +0200152 synchronized (mService.mWindowMap) {
153 mCurrentTime = frameTimeNs / TimeUtils.NANOS_PER_MS;
154 mBulkUpdateParams = SET_ORIENTATION_CHANGE_COMPLETE;
155 mAnimating = false;
Jorim Jaggi836dac42017-08-08 15:12:20 +0200156 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 Jaggi9b19fd42017-05-11 16:27:06 +0200163 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 Leef19cbe22018-02-02 15:09:21 -0800168 final DisplayContent dc = mService.mRoot.getDisplayContent(displayId);
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200169 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 }
Svetoslavb180d772014-09-10 22:07:19 -0700189 }
Craig Mautnera91f9e22012-09-14 16:22:08 -0700190 }
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200191
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 Carrb1579c82017-09-05 14:54:47 -0700197 dc.prepareSurfaces();
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200198 }
199
200 for (int i = 0; i < numDisplays; i++) {
201 final int displayId = mDisplayContentsAnimators.keyAt(i);
Bryce Leef19cbe22018-02-02 15:09:21 -0800202 final DisplayContent dc = mService.mRoot.getDisplayContent(displayId);
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200203
204 dc.checkAppWindowsReadyToShow();
205
206 final ScreenRotationAnimation screenRotationAnimation =
207 mDisplayContentsAnimators.valueAt(i).mScreenRotationAnimation;
208 if (screenRotationAnimation != null) {
Robert Carrae606b42018-02-15 15:36:23 -0800209 screenRotationAnimation.updateSurfaces(mTransaction);
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200210 }
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200211 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 Mautnera91f9e22012-09-14 16:22:08 -0700216 }
Craig Mautnerea3a09a2012-09-04 09:49:35 -0700217
Jorim Jaggi836dac42017-08-08 15:12:20 +0200218 if (!mAnimating) {
219 cancelAnimation();
Svetoslav Ganov545252f2012-12-10 18:29:24 -0800220 }
Craig Mautner764983d2012-03-22 11:37:36 -0700221
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200222 if (mService.mWatermark != null) {
223 mService.mWatermark.drawIfNeeded();
224 }
Robert Carrae606b42018-02-15 15:36:23 -0800225
226 SurfaceControl.mergeToGlobalTransaction(mTransaction);
Jorim Jaggi836dac42017-08-08 15:12:20 +0200227 } catch (RuntimeException e) {
228 Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
229 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200230 mService.closeSurfaceTransaction("WindowAnimator");
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200231 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION animate");
Jorim Jaggia41b7292017-05-11 23:50:34 +0200232 }
Jorim Jaggid9cabc52015-10-27 09:38:16 -0700233
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200234 boolean hasPendingLayoutChanges = mService.mRoot.hasPendingLayoutChanges(this);
235 boolean doRequest = false;
236 if (mBulkUpdateParams != 0) {
237 doRequest = mService.mRoot.copyAnimToLayoutParams();
Jorim Jaggid9cabc52015-10-27 09:38:16 -0700238 }
Chong Zhang97782b42015-10-07 16:01:23 -0700239
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200240 if (hasPendingLayoutChanges || doRequest) {
Jorim Jaggi4130a682018-01-09 14:28:44 +0100241 mService.mWindowPlacerLocked.requestTraversal();
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200242 }
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -0800243
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000244 final boolean rootAnimating = mService.mRoot.isSelfOrChildAnimating();
245 if (rootAnimating && !mLastRootAnimating) {
Chong Zhang97782b42015-10-07 16:01:23 -0700246
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200247 // 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 Jaggidc9385a2017-05-13 02:00:31 +0200251 Trace.asyncTraceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "animating", 0);
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200252 }
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000253 if (!rootAnimating && mLastRootAnimating) {
Jorim Jaggi4130a682018-01-09 14:28:44 +0100254 mService.mWindowPlacerLocked.requestTraversal();
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200255 mService.mTaskSnapshotController.setPersisterPaused(false);
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200256 Trace.asyncTraceEnd(Trace.TRACE_TAG_WINDOW_MANAGER, "animating", 0);
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200257 }
258
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000259 mLastRootAnimating = rootAnimating;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200260
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200261 if (mRemoveReplacedWindows) {
262 mService.mRoot.removeReplacedWindows();
263 mRemoveReplacedWindows = false;
264 }
265
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200266 mService.destroyPreservedSurfaceLocked();
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200267
Jorim Jaggia3844032018-01-03 15:54:43 +0100268 executeAfterPrepareSurfacesRunnables();
Robert Carrb1579c82017-09-05 14:54:47 -0700269
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200270 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 Mautner7d8df392012-04-06 15:26:23 -0700276 }
Craig Mautner764983d2012-03-22 11:37:36 -0700277 }
278
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700279 private static String bulkUpdateParamsToString(int bulkUpdateParams) {
Dianne Hackborn529e7442012-11-01 14:22:28 -0700280 StringBuilder builder = new StringBuilder(128);
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700281 if ((bulkUpdateParams & WindowSurfacePlacer.SET_UPDATE_ROTATION) != 0) {
Dianne Hackborn529e7442012-11-01 14:22:28 -0700282 builder.append(" UPDATE_ROTATION");
283 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700284 if ((bulkUpdateParams & WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE) != 0) {
Dianne Hackborn529e7442012-11-01 14:22:28 -0700285 builder.append(" WALLPAPER_MAY_CHANGE");
286 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700287 if ((bulkUpdateParams & WindowSurfacePlacer.SET_FORCE_HIDING_CHANGED) != 0) {
Dianne Hackborn529e7442012-11-01 14:22:28 -0700288 builder.append(" FORCE_HIDING_CHANGED");
289 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700290 if ((bulkUpdateParams & WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE) != 0) {
Dianne Hackborn529e7442012-11-01 14:22:28 -0700291 builder.append(" ORIENTATION_CHANGE_COMPLETE");
292 }
Dianne Hackborn529e7442012-11-01 14:22:28 -0700293 return builder.toString();
294 }
295
Craig Mautnera91f9e22012-09-14 16:22:08 -0700296 public void dumpLocked(PrintWriter pw, String prefix, boolean dumpAll) {
Dianne Hackborn529e7442012-11-01 14:22:28 -0700297 final String subPrefix = " " + prefix;
298 final String subSubPrefix = " " + subPrefix;
299
Dianne Hackborn529e7442012-11-01 14:22:28 -0700300 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 Ogunwale824ab5c2016-10-20 09:31:56 -0700304 final DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.valueAt(i);
305 final DisplayContent dc =
Bryce Leef19cbe22018-02-02 15:09:21 -0800306 mService.mRoot.getDisplayContent(mDisplayContentsAnimators.keyAt(i));
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700307 dc.dumpWindowAnimators(pw, subPrefix);
Dianne Hackborn529e7442012-11-01 14:22:28 -0700308 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 Mautnere7cfceb2015-02-04 15:57:06 -0800314 pw.println();
Dianne Hackborn529e7442012-11-01 14:22:28 -0700315 }
316
317 pw.println();
318
319 if (dumpAll) {
320 pw.print(prefix); pw.print("mAnimTransactionSequence=");
321 pw.print(mAnimTransactionSequence);
Dianne Hackborn529e7442012-11-01 14:22:28 -0700322 pw.print(prefix); pw.print("mCurrentTime=");
323 pw.println(TimeUtils.formatUptime(mCurrentTime));
Dianne Hackborn529e7442012-11-01 14:22:28 -0700324 }
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 Hackborn529e7442012-11-01 14:22:28 -0700330 if (mWindowDetachedWallpaper != null) {
331 pw.print(prefix); pw.print("mWindowDetachedWallpaper=");
332 pw.println(mWindowDetachedWallpaper);
333 }
Craig Mautnere7ae2502012-03-26 17:11:19 -0700334 }
Craig Mautnerbec53f72012-04-05 11:49:05 -0700335
Craig Mautner66f78d72012-12-04 16:46:50 -0800336 int getPendingLayoutChanges(final int displayId) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800337 if (displayId < 0) {
338 return 0;
339 }
Bryce Leef19cbe22018-02-02 15:09:21 -0800340 final DisplayContent displayContent = mService.mRoot.getDisplayContent(displayId);
Wale Ogunwalef16a2812015-04-01 11:23:15 -0700341 return (displayContent != null) ? displayContent.pendingLayoutChanges : 0;
Craig Mautner66f78d72012-12-04 16:46:50 -0800342 }
343
Craig Mautner76a71652012-09-03 23:23:58 -0700344 void setPendingLayoutChanges(final int displayId, final int changes) {
Wale Ogunwalef16a2812015-04-01 11:23:15 -0700345 if (displayId < 0) {
346 return;
347 }
Bryce Leef19cbe22018-02-02 15:09:21 -0800348 final DisplayContent displayContent = mService.mRoot.getDisplayContent(displayId);
Wale Ogunwalef16a2812015-04-01 11:23:15 -0700349 if (displayContent != null) {
350 displayContent.pendingLayoutChanges |= changes;
Craig Mautnerdf88d732014-01-27 09:21:32 -0800351 }
Craig Mautner76a71652012-09-03 23:23:58 -0700352 }
353
Craig Mautnera91f9e22012-09-14 16:22:08 -0700354 private DisplayContentsAnimator getDisplayContentsAnimatorLocked(int displayId) {
Bryce Leed1871262017-06-12 14:12:29 -0700355 if (displayId < 0) {
356 return null;
357 }
358
Craig Mautnera91f9e22012-09-14 16:22:08 -0700359 DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.get(displayId);
Bryce Leed1871262017-06-12 14:12:29 -0700360
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 Mautner05d29032013-05-03 13:40:13 -0700365 displayAnimator = new DisplayContentsAnimator();
Craig Mautnera91f9e22012-09-14 16:22:08 -0700366 mDisplayContentsAnimators.put(displayId, displayAnimator);
367 }
368 return displayAnimator;
369 }
370
371 void setScreenRotationAnimationLocked(int displayId, ScreenRotationAnimation animation) {
Bryce Leed1871262017-06-12 14:12:29 -0700372 final DisplayContentsAnimator animator = getDisplayContentsAnimatorLocked(displayId);
373
374 if (animator != null) {
375 animator.mScreenRotationAnimation = animation;
Craig Mautnerdf88d732014-01-27 09:21:32 -0800376 }
Craig Mautnera91f9e22012-09-14 16:22:08 -0700377 }
378
379 ScreenRotationAnimation getScreenRotationAnimationLocked(int displayId) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800380 if (displayId < 0) {
381 return null;
382 }
Bryce Leed1871262017-06-12 14:12:29 -0700383
384 DisplayContentsAnimator animator = getDisplayContentsAnimatorLocked(displayId);
385 return animator != null? animator.mScreenRotationAnimation : null;
Craig Mautnera91f9e22012-09-14 16:22:08 -0700386 }
387
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -0800388 void requestRemovalOfReplacedWindows(WindowState win) {
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -0800389 mRemoveReplacedWindows = true;
390 }
391
Jorim Jaggied7993b2017-03-28 18:50:01 +0100392 void scheduleAnimation() {
Jorim Jaggi561eeb52017-04-28 16:39:19 +0200393 if (!mAnimationFrameCallbackScheduled) {
394 mAnimationFrameCallbackScheduled = true;
Jorim Jaggied7993b2017-03-28 18:50:01 +0100395 mChoreographer.postFrameCallback(mAnimationFrameCallback);
396 }
397 }
398
Jorim Jaggi836dac42017-08-08 15:12:20 +0200399 private void cancelAnimation() {
400 if (mAnimationFrameCallbackScheduled) {
401 mAnimationFrameCallbackScheduled = false;
402 mChoreographer.removeFrameCallback(mAnimationFrameCallback);
403 }
404 }
405
Craig Mautnerac439e52012-09-21 08:58:34 -0700406 private class DisplayContentsAnimator {
Craig Mautnera91f9e22012-09-14 16:22:08 -0700407 ScreenRotationAnimation mScreenRotationAnimation = null;
408 }
Wale Ogunwale69cf50f2015-11-13 11:08:36 -0800409
410 boolean isAnimating() {
411 return mAnimating;
412 }
413
Jorim Jaggied7993b2017-03-28 18:50:01 +0100414 boolean isAnimationScheduled() {
Jorim Jaggi34a0cdb2017-06-08 15:40:38 -0700415 return mAnimationFrameCallbackScheduled;
Jorim Jaggied7993b2017-03-28 18:50:01 +0100416 }
417
418 Choreographer getChoreographer() {
419 return mChoreographer;
420 }
421
Wale Ogunwale69cf50f2015-11-13 11:08:36 -0800422 void setAnimating(boolean animating) {
423 mAnimating = animating;
424 }
425
426 void orAnimating(boolean animating) {
427 mAnimating |= animating;
428 }
Jorim Jaggia3844032018-01-03 15:54:43 +0100429
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 Weingarten16d0d072018-02-12 23:50:28 +0000435 // 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 Jaggia3844032018-01-03 15:54:43 +0100442 mAfterPrepareSurfacesRunnables.add(r);
443 scheduleAnimation();
444 }
445
Chavi Weingarten16d0d072018-02-12 23:50:28 +0000446 void executeAfterPrepareSurfacesRunnables() {
447
448 // Don't even think about to start recursing!
449 if (mInExecuteAfterPrepareSurfacesRunnables) {
450 return;
451 }
452 mInExecuteAfterPrepareSurfacesRunnables = true;
Jorim Jaggia3844032018-01-03 15:54:43 +0100453
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 Weingarten16d0d072018-02-12 23:50:28 +0000460 mInExecuteAfterPrepareSurfacesRunnables = false;
Jorim Jaggia3844032018-01-03 15:54:43 +0100461 }
Craig Mautner764983d2012-03-22 11:37:36 -0700462}