blob: b8db98b3c2f3e58ea8c2fb23f293fb91940c126a [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
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080019import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE;
20import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
21import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
22import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070023import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -080024import static com.android.server.wm.WindowSurfacePlacer.SET_UPDATE_ROTATION;
Craig Mautnera608b882012-03-30 13:03:49 -070025
Craig Mautner764983d2012-03-22 11:37:36 -070026import android.content.Context;
Jorim Jaggid9cabc52015-10-27 09:38:16 -070027import android.os.Trace;
Craig Mautner764983d2012-03-22 11:37:36 -070028import android.util.Slog;
Craig Mautnera91f9e22012-09-14 16:22:08 -070029import android.util.SparseArray;
Dianne Hackborn529e7442012-11-01 14:22:28 -070030import android.util.TimeUtils;
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -080031import android.view.Choreographer;
Robert Carrae606b42018-02-15 15:36:23 -080032import android.view.SurfaceControl;
Craig Mautner764983d2012-03-22 11:37:36 -070033
Jorim Jaggied7993b2017-03-28 18:50:01 +010034import com.android.server.AnimationThread;
Adrian Roose99bc052017-11-20 17:55:31 +010035import com.android.server.policy.WindowManagerPolicy;
Jorim Jaggid6d6de62017-03-31 15:05:13 +020036
Craig Mautnere7ae2502012-03-26 17:11:19 -070037import java.io.PrintWriter;
Jorim Jaggia3844032018-01-03 15:54:43 +010038import java.util.ArrayList;
Craig Mautnere7ae2502012-03-26 17:11:19 -070039
Craig Mautner764983d2012-03-22 11:37:36 -070040/**
Craig Mautner764983d2012-03-22 11:37:36 -070041 * Singleton class that carries out the animations and Surface operations in a separate task
42 * on behalf of WindowManagerService.
43 */
44public class WindowAnimator {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080045 private static final String TAG = TAG_WITH_CLASS_NAME ? "WindowAnimator" : TAG_WM;
Craig Mautner764983d2012-03-22 11:37:36 -070046
47 final WindowManagerService mService;
48 final Context mContext;
49 final WindowManagerPolicy mPolicy;
50
Jorim Jaggi37875612015-02-19 21:05:31 +010051 /** Is any window animating? */
Wale Ogunwale69cf50f2015-11-13 11:08:36 -080052 private boolean mAnimating;
Jorim Jaggib0fc8172017-11-23 17:04:08 +000053 private boolean mLastRootAnimating;
Craig Mautner01cd0e72012-06-18 10:19:11 -070054
Riley Andrews6d354162014-11-19 15:21:52 -080055 final Choreographer.FrameCallback mAnimationFrameCallback;
Craig Mautner1caa3992012-06-22 09:46:48 -070056
Craig Mautner764983d2012-03-22 11:37:36 -070057 /** Time of current animation step. Reset on each iteration */
58 long mCurrentTime;
59
Craig Mautnera608b882012-03-30 13:03:49 -070060 int mBulkUpdateParams = 0;
Dianne Hackborna57c6952013-03-29 14:46:40 -070061 Object mLastWindowFreezeSource;
Craig Mautnera608b882012-03-30 13:03:49 -070062
Filip Gruszczynski4501d232015-09-02 13:00:02 -070063 SparseArray<DisplayContentsAnimator> mDisplayContentsAnimators = new SparseArray<>(2);
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070064
Jorim Jaggi4130a682018-01-09 14:28:44 +010065 private boolean mInitialized = false;
Craig Mautnerb47bbc32012-08-22 17:41:48 -070066
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -080067 // When set to true the animator will go over all windows after an animation frame is posted and
68 // check if some got replaced and can be removed.
69 private boolean mRemoveReplacedWindows = false;
70
Jorim Jaggied7993b2017-03-28 18:50:01 +010071 private Choreographer mChoreographer;
Jorim Jaggied7993b2017-03-28 18:50:01 +010072
Jorim Jaggi561eeb52017-04-28 16:39:19 +020073 /**
74 * Indicates whether we have an animation frame callback scheduled, which will happen at
75 * vsync-app and then schedule the animation tick at the right time (vsync-sf).
76 */
77 private boolean mAnimationFrameCallbackScheduled;
78
Jorim Jaggia3844032018-01-03 15:54:43 +010079 /**
80 * A list of runnable that need to be run after {@link WindowContainer#prepareSurfaces} is
81 * executed and the corresponding transaction is closed and applied.
82 */
83 private final ArrayList<Runnable> mAfterPrepareSurfacesRunnables = new ArrayList<>();
Chavi Weingarten16d0d072018-02-12 23:50:28 +000084 private boolean mInExecuteAfterPrepareSurfacesRunnables;
Jorim Jaggia3844032018-01-03 15:54:43 +010085
Robert Carrae606b42018-02-15 15:36:23 -080086 private final SurfaceControl.Transaction mTransaction = new SurfaceControl.Transaction();
87
Craig Mautner918b53b2012-07-09 14:15:54 -070088 WindowAnimator(final WindowManagerService service) {
Craig Mautner764983d2012-03-22 11:37:36 -070089 mService = service;
Craig Mautner918b53b2012-07-09 14:15:54 -070090 mContext = service.mContext;
91 mPolicy = service.mPolicy;
Jorim Jaggied7993b2017-03-28 18:50:01 +010092 AnimationThread.getHandler().runWithScissors(
Jorim Jaggi34a0cdb2017-06-08 15:40:38 -070093 () -> mChoreographer = Choreographer.getSfInstance(), 0 /* timeout */);
Craig Mautner1caa3992012-06-22 09:46:48 -070094
Jorim Jaggid6d6de62017-03-31 15:05:13 +020095 mAnimationFrameCallback = frameTimeNs -> {
Wale Ogunwaledb485de2018-10-29 09:47:07 -070096 synchronized (mService.mGlobalLock) {
Jorim Jaggi561eeb52017-04-28 16:39:19 +020097 mAnimationFrameCallbackScheduled = false;
Jorim Jaggi561eeb52017-04-28 16:39:19 +020098 }
Jorim Jaggi34a0cdb2017-06-08 15:40:38 -070099 animate(frameTimeNs);
Jorim Jaggid6d6de62017-03-31 15:05:13 +0200100 };
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700101 }
Craig Mautner9e809442012-06-22 17:13:04 -0700102
Craig Mautnera91f9e22012-09-14 16:22:08 -0700103 void addDisplayLocked(final int displayId) {
Bryce Leed1871262017-06-12 14:12:29 -0700104 // Create the DisplayContentsAnimator object by retrieving it if the associated
105 // {@link DisplayContent} exists.
Craig Mautnerac439e52012-09-21 08:58:34 -0700106 getDisplayContentsAnimatorLocked(displayId);
Craig Mautnera91f9e22012-09-14 16:22:08 -0700107 }
108
109 void removeDisplayLocked(final int displayId) {
Craig Mautnerd5523dc2012-10-02 13:49:22 -0700110 final DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.get(displayId);
111 if (displayAnimator != null) {
Craig Mautnerd5523dc2012-10-02 13:49:22 -0700112 if (displayAnimator.mScreenRotationAnimation != null) {
113 displayAnimator.mScreenRotationAnimation.kill();
114 displayAnimator.mScreenRotationAnimation = null;
115 }
Craig Mautnerd5523dc2012-10-02 13:49:22 -0700116 }
117
Craig Mautnera91f9e22012-09-14 16:22:08 -0700118 mDisplayContentsAnimators.delete(displayId);
Craig Mautner1caa3992012-06-22 09:46:48 -0700119 }
120
Riddle Hsuf53da812018-08-15 22:00:27 +0800121 void ready() {
122 mInitialized = true;
123 }
124
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200125 /**
126 * DO NOT HOLD THE WINDOW MANAGER LOCK WHILE CALLING THIS METHOD. Reason: the method closes
127 * an animation transaction, that might be blocking until the next sf-vsync, so we want to make
128 * sure other threads can make progress if this happens.
129 */
130 private void animate(long frameTimeNs) {
Craig Mautnera91f9e22012-09-14 16:22:08 -0700131
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700132 synchronized (mService.mGlobalLock) {
Jorim Jaggi836dac42017-08-08 15:12:20 +0200133 if (!mInitialized) {
134 return;
135 }
Svetoslavb180d772014-09-10 22:07:19 -0700136
Jorim Jaggi836dac42017-08-08 15:12:20 +0200137 // Schedule next frame already such that back-pressure happens continuously
138 scheduleAnimation();
139 }
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200140
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700141 synchronized (mService.mGlobalLock) {
Jorim Jaggi836dac42017-08-08 15:12:20 +0200142 mCurrentTime = frameTimeNs / TimeUtils.NANOS_PER_MS;
143 mBulkUpdateParams = SET_ORIENTATION_CHANGE_COMPLETE;
144 mAnimating = false;
Jorim Jaggi836dac42017-08-08 15:12:20 +0200145 if (DEBUG_WINDOW_TRACE) {
146 Slog.i(TAG, "!!! animate: entry time=" + mCurrentTime);
147 }
148
149 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION animate");
150 mService.openSurfaceTransaction();
151 try {
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200152 final AccessibilityController accessibilityController =
153 mService.mAccessibilityController;
154 final int numDisplays = mDisplayContentsAnimators.size();
155 for (int i = 0; i < numDisplays; i++) {
156 final int displayId = mDisplayContentsAnimators.keyAt(i);
Bryce Leef19cbe22018-02-02 15:09:21 -0800157 final DisplayContent dc = mService.mRoot.getDisplayContent(displayId);
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200158 DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.valueAt(i);
159
160 final ScreenRotationAnimation screenRotationAnimation =
161 displayAnimator.mScreenRotationAnimation;
162 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
163 if (screenRotationAnimation.stepAnimationLocked(mCurrentTime)) {
164 setAnimating(true);
165 } else {
166 mBulkUpdateParams |= SET_UPDATE_ROTATION;
167 screenRotationAnimation.kill();
168 displayAnimator.mScreenRotationAnimation = null;
169
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200170 // display.
Rhed Jao02655dc2018-10-30 20:44:52 +0800171 if (accessibilityController != null) {
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200172 // We just finished rotation animation which means we did not
173 // announce the rotation and waited for it to end, announce now.
Rhed Jao02655dc2018-10-30 20:44:52 +0800174 accessibilityController.onRotationChangedLocked(dc);
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200175 }
Svetoslavb180d772014-09-10 22:07:19 -0700176 }
Craig Mautnera91f9e22012-09-14 16:22:08 -0700177 }
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200178
179 // Update animations of all applications, including those
180 // associated with exiting/removed apps
Jorim Jaggi8f520872018-08-14 17:00:20 +0200181 dc.updateWindowsForAnimator();
182 dc.updateBackgroundForAnimator();
Robert Carrb1579c82017-09-05 14:54:47 -0700183 dc.prepareSurfaces();
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200184 }
185
186 for (int i = 0; i < numDisplays; i++) {
187 final int displayId = mDisplayContentsAnimators.keyAt(i);
Bryce Leef19cbe22018-02-02 15:09:21 -0800188 final DisplayContent dc = mService.mRoot.getDisplayContent(displayId);
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200189
190 dc.checkAppWindowsReadyToShow();
191
192 final ScreenRotationAnimation screenRotationAnimation =
193 mDisplayContentsAnimators.valueAt(i).mScreenRotationAnimation;
194 if (screenRotationAnimation != null) {
Robert Carrae606b42018-02-15 15:36:23 -0800195 screenRotationAnimation.updateSurfaces(mTransaction);
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200196 }
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200197 orAnimating(dc.getDockedDividerController().animate(mCurrentTime));
Rhed Jao02655dc2018-10-30 20:44:52 +0800198 if (accessibilityController != null) {
199 accessibilityController.drawMagnifiedRegionBorderIfNeededLocked(displayId);
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200200 }
Craig Mautnera91f9e22012-09-14 16:22:08 -0700201 }
Craig Mautnerea3a09a2012-09-04 09:49:35 -0700202
Jorim Jaggi836dac42017-08-08 15:12:20 +0200203 if (!mAnimating) {
204 cancelAnimation();
Svetoslav Ganov545252f2012-12-10 18:29:24 -0800205 }
Craig Mautner764983d2012-03-22 11:37:36 -0700206
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200207 if (mService.mWatermark != null) {
208 mService.mWatermark.drawIfNeeded();
209 }
Robert Carrae606b42018-02-15 15:36:23 -0800210
211 SurfaceControl.mergeToGlobalTransaction(mTransaction);
Jorim Jaggi836dac42017-08-08 15:12:20 +0200212 } catch (RuntimeException e) {
213 Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
214 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200215 mService.closeSurfaceTransaction("WindowAnimator");
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200216 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION animate");
Jorim Jaggia41b7292017-05-11 23:50:34 +0200217 }
Jorim Jaggid9cabc52015-10-27 09:38:16 -0700218
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200219 boolean hasPendingLayoutChanges = mService.mRoot.hasPendingLayoutChanges(this);
220 boolean doRequest = false;
221 if (mBulkUpdateParams != 0) {
222 doRequest = mService.mRoot.copyAnimToLayoutParams();
Jorim Jaggid9cabc52015-10-27 09:38:16 -0700223 }
Chong Zhang97782b42015-10-07 16:01:23 -0700224
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200225 if (hasPendingLayoutChanges || doRequest) {
Jorim Jaggi4130a682018-01-09 14:28:44 +0100226 mService.mWindowPlacerLocked.requestTraversal();
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200227 }
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -0800228
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000229 final boolean rootAnimating = mService.mRoot.isSelfOrChildAnimating();
230 if (rootAnimating && !mLastRootAnimating) {
Chong Zhang97782b42015-10-07 16:01:23 -0700231
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200232 // Usually app transitions but quite a load onto the system already (with all the
233 // things happening in app), so pause task snapshot persisting to not increase the
234 // load.
235 mService.mTaskSnapshotController.setPersisterPaused(true);
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200236 Trace.asyncTraceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "animating", 0);
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200237 }
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000238 if (!rootAnimating && mLastRootAnimating) {
Jorim Jaggi4130a682018-01-09 14:28:44 +0100239 mService.mWindowPlacerLocked.requestTraversal();
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200240 mService.mTaskSnapshotController.setPersisterPaused(false);
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200241 Trace.asyncTraceEnd(Trace.TRACE_TAG_WINDOW_MANAGER, "animating", 0);
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200242 }
243
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000244 mLastRootAnimating = rootAnimating;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200245
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200246 if (mRemoveReplacedWindows) {
247 mService.mRoot.removeReplacedWindows();
248 mRemoveReplacedWindows = false;
249 }
250
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200251 mService.destroyPreservedSurfaceLocked();
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200252
Jorim Jaggia3844032018-01-03 15:54:43 +0100253 executeAfterPrepareSurfacesRunnables();
Robert Carrb1579c82017-09-05 14:54:47 -0700254
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200255 if (DEBUG_WINDOW_TRACE) {
256 Slog.i(TAG, "!!! animate: exit mAnimating=" + mAnimating
257 + " mBulkUpdateParams=" + Integer.toHexString(mBulkUpdateParams)
lumarka483f312018-11-20 15:24:05 +0800258 + " hasPendingLayoutChanges=" + hasPendingLayoutChanges);
Jorim Jaggi9b19fd42017-05-11 16:27:06 +0200259 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700260 }
Craig Mautner764983d2012-03-22 11:37:36 -0700261 }
262
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700263 private static String bulkUpdateParamsToString(int bulkUpdateParams) {
Dianne Hackborn529e7442012-11-01 14:22:28 -0700264 StringBuilder builder = new StringBuilder(128);
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700265 if ((bulkUpdateParams & WindowSurfacePlacer.SET_UPDATE_ROTATION) != 0) {
Dianne Hackborn529e7442012-11-01 14:22:28 -0700266 builder.append(" UPDATE_ROTATION");
267 }
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700268 if ((bulkUpdateParams & WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE) != 0) {
Dianne Hackborn529e7442012-11-01 14:22:28 -0700269 builder.append(" ORIENTATION_CHANGE_COMPLETE");
270 }
Dianne Hackborn529e7442012-11-01 14:22:28 -0700271 return builder.toString();
272 }
273
Craig Mautnera91f9e22012-09-14 16:22:08 -0700274 public void dumpLocked(PrintWriter pw, String prefix, boolean dumpAll) {
Dianne Hackborn529e7442012-11-01 14:22:28 -0700275 final String subPrefix = " " + prefix;
276 final String subSubPrefix = " " + subPrefix;
277
Dianne Hackborn529e7442012-11-01 14:22:28 -0700278 for (int i = 0; i < mDisplayContentsAnimators.size(); i++) {
279 pw.print(prefix); pw.print("DisplayContentsAnimator #");
280 pw.print(mDisplayContentsAnimators.keyAt(i));
281 pw.println(":");
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700282 final DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.valueAt(i);
283 final DisplayContent dc =
Bryce Leef19cbe22018-02-02 15:09:21 -0800284 mService.mRoot.getDisplayContent(mDisplayContentsAnimators.keyAt(i));
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700285 dc.dumpWindowAnimators(pw, subPrefix);
Dianne Hackborn529e7442012-11-01 14:22:28 -0700286 if (displayAnimator.mScreenRotationAnimation != null) {
287 pw.print(subPrefix); pw.println("mScreenRotationAnimation:");
288 displayAnimator.mScreenRotationAnimation.printTo(subSubPrefix, pw);
289 } else if (dumpAll) {
290 pw.print(subPrefix); pw.println("no ScreenRotationAnimation ");
291 }
Craig Mautnere7cfceb2015-02-04 15:57:06 -0800292 pw.println();
Dianne Hackborn529e7442012-11-01 14:22:28 -0700293 }
294
295 pw.println();
296
297 if (dumpAll) {
Dianne Hackborn529e7442012-11-01 14:22:28 -0700298 pw.print(prefix); pw.print("mCurrentTime=");
299 pw.println(TimeUtils.formatUptime(mCurrentTime));
Dianne Hackborn529e7442012-11-01 14:22:28 -0700300 }
301 if (mBulkUpdateParams != 0) {
302 pw.print(prefix); pw.print("mBulkUpdateParams=0x");
303 pw.print(Integer.toHexString(mBulkUpdateParams));
304 pw.println(bulkUpdateParamsToString(mBulkUpdateParams));
305 }
Craig Mautnere7ae2502012-03-26 17:11:19 -0700306 }
Craig Mautnerbec53f72012-04-05 11:49:05 -0700307
Craig Mautner66f78d72012-12-04 16:46:50 -0800308 int getPendingLayoutChanges(final int displayId) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800309 if (displayId < 0) {
310 return 0;
311 }
Bryce Leef19cbe22018-02-02 15:09:21 -0800312 final DisplayContent displayContent = mService.mRoot.getDisplayContent(displayId);
Wale Ogunwalef16a2812015-04-01 11:23:15 -0700313 return (displayContent != null) ? displayContent.pendingLayoutChanges : 0;
Craig Mautner66f78d72012-12-04 16:46:50 -0800314 }
315
Craig Mautner76a71652012-09-03 23:23:58 -0700316 void setPendingLayoutChanges(final int displayId, final int changes) {
Wale Ogunwalef16a2812015-04-01 11:23:15 -0700317 if (displayId < 0) {
318 return;
319 }
Bryce Leef19cbe22018-02-02 15:09:21 -0800320 final DisplayContent displayContent = mService.mRoot.getDisplayContent(displayId);
Wale Ogunwalef16a2812015-04-01 11:23:15 -0700321 if (displayContent != null) {
322 displayContent.pendingLayoutChanges |= changes;
Craig Mautnerdf88d732014-01-27 09:21:32 -0800323 }
Craig Mautner76a71652012-09-03 23:23:58 -0700324 }
325
Craig Mautnera91f9e22012-09-14 16:22:08 -0700326 private DisplayContentsAnimator getDisplayContentsAnimatorLocked(int displayId) {
Bryce Leed1871262017-06-12 14:12:29 -0700327 if (displayId < 0) {
328 return null;
329 }
330
Craig Mautnera91f9e22012-09-14 16:22:08 -0700331 DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.get(displayId);
Bryce Leed1871262017-06-12 14:12:29 -0700332
333 // It is possible that this underlying {@link DisplayContent} has been removed. In this
334 // case, we do not want to create an animator associated with it as {link #animate} will
335 // fail.
336 if (displayAnimator == null && mService.mRoot.getDisplayContent(displayId) != null) {
Craig Mautner05d29032013-05-03 13:40:13 -0700337 displayAnimator = new DisplayContentsAnimator();
Craig Mautnera91f9e22012-09-14 16:22:08 -0700338 mDisplayContentsAnimators.put(displayId, displayAnimator);
339 }
340 return displayAnimator;
341 }
342
343 void setScreenRotationAnimationLocked(int displayId, ScreenRotationAnimation animation) {
Bryce Leed1871262017-06-12 14:12:29 -0700344 final DisplayContentsAnimator animator = getDisplayContentsAnimatorLocked(displayId);
345
346 if (animator != null) {
347 animator.mScreenRotationAnimation = animation;
Craig Mautnerdf88d732014-01-27 09:21:32 -0800348 }
Craig Mautnera91f9e22012-09-14 16:22:08 -0700349 }
350
351 ScreenRotationAnimation getScreenRotationAnimationLocked(int displayId) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800352 if (displayId < 0) {
353 return null;
354 }
Bryce Leed1871262017-06-12 14:12:29 -0700355
356 DisplayContentsAnimator animator = getDisplayContentsAnimatorLocked(displayId);
357 return animator != null? animator.mScreenRotationAnimation : null;
Craig Mautnera91f9e22012-09-14 16:22:08 -0700358 }
359
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -0800360 void requestRemovalOfReplacedWindows(WindowState win) {
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -0800361 mRemoveReplacedWindows = true;
362 }
363
Jorim Jaggied7993b2017-03-28 18:50:01 +0100364 void scheduleAnimation() {
Jorim Jaggi561eeb52017-04-28 16:39:19 +0200365 if (!mAnimationFrameCallbackScheduled) {
366 mAnimationFrameCallbackScheduled = true;
Jorim Jaggied7993b2017-03-28 18:50:01 +0100367 mChoreographer.postFrameCallback(mAnimationFrameCallback);
368 }
369 }
370
Jorim Jaggi836dac42017-08-08 15:12:20 +0200371 private void cancelAnimation() {
372 if (mAnimationFrameCallbackScheduled) {
373 mAnimationFrameCallbackScheduled = false;
374 mChoreographer.removeFrameCallback(mAnimationFrameCallback);
375 }
376 }
377
Craig Mautnerac439e52012-09-21 08:58:34 -0700378 private class DisplayContentsAnimator {
Craig Mautnera91f9e22012-09-14 16:22:08 -0700379 ScreenRotationAnimation mScreenRotationAnimation = null;
380 }
Wale Ogunwale69cf50f2015-11-13 11:08:36 -0800381
382 boolean isAnimating() {
383 return mAnimating;
384 }
385
Jorim Jaggied7993b2017-03-28 18:50:01 +0100386 boolean isAnimationScheduled() {
Jorim Jaggi34a0cdb2017-06-08 15:40:38 -0700387 return mAnimationFrameCallbackScheduled;
Jorim Jaggied7993b2017-03-28 18:50:01 +0100388 }
389
390 Choreographer getChoreographer() {
391 return mChoreographer;
392 }
393
Wale Ogunwale69cf50f2015-11-13 11:08:36 -0800394 void setAnimating(boolean animating) {
395 mAnimating = animating;
396 }
397
398 void orAnimating(boolean animating) {
399 mAnimating |= animating;
400 }
Jorim Jaggia3844032018-01-03 15:54:43 +0100401
402 /**
403 * Adds a runnable to be executed after {@link WindowContainer#prepareSurfaces} is called and
404 * the corresponding transaction is closed and applied.
405 */
406 void addAfterPrepareSurfacesRunnable(Runnable r) {
Chavi Weingarten16d0d072018-02-12 23:50:28 +0000407 // If runnables are already being handled in executeAfterPrepareSurfacesRunnable, then just
408 // immediately execute the runnable passed in.
409 if (mInExecuteAfterPrepareSurfacesRunnables) {
410 r.run();
411 return;
412 }
413
Jorim Jaggia3844032018-01-03 15:54:43 +0100414 mAfterPrepareSurfacesRunnables.add(r);
415 scheduleAnimation();
416 }
417
Chavi Weingarten16d0d072018-02-12 23:50:28 +0000418 void executeAfterPrepareSurfacesRunnables() {
419
420 // Don't even think about to start recursing!
421 if (mInExecuteAfterPrepareSurfacesRunnables) {
422 return;
423 }
424 mInExecuteAfterPrepareSurfacesRunnables = true;
Jorim Jaggia3844032018-01-03 15:54:43 +0100425
426 // Traverse in order they were added.
427 final int size = mAfterPrepareSurfacesRunnables.size();
428 for (int i = 0; i < size; i++) {
429 mAfterPrepareSurfacesRunnables.get(i).run();
430 }
431 mAfterPrepareSurfacesRunnables.clear();
Chavi Weingarten16d0d072018-02-12 23:50:28 +0000432 mInExecuteAfterPrepareSurfacesRunnables = false;
Jorim Jaggia3844032018-01-03 15:54:43 +0100433 }
Craig Mautner764983d2012-03-22 11:37:36 -0700434}