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 | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 19 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 20 | |
| 21 | import static com.android.server.wm.AppTransition.TRANSIT_UNSET; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 22 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 23 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
| 24 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS; |
| 25 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 26 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 27 | import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET; |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 28 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM; |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 29 | |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 30 | import android.graphics.Matrix; |
| 31 | import android.util.Slog; |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 32 | import android.util.TimeUtils; |
Jorim Jaggi | c554b77 | 2015-06-04 16:07:57 -0700 | [diff] [blame] | 33 | import android.view.Choreographer; |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 34 | import android.view.Display; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 35 | import android.view.SurfaceControl; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 36 | import android.view.animation.Animation; |
| 37 | import android.view.animation.Transformation; |
| 38 | |
| 39 | import java.io.PrintWriter; |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 40 | import java.util.ArrayList; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 41 | |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 42 | public class AppWindowAnimator { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 43 | static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowAnimator" : TAG_WM; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 44 | |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 45 | private static final int PROLONG_ANIMATION_DISABLED = 0; |
| 46 | static final int PROLONG_ANIMATION_AT_END = 1; |
| 47 | static final int PROLONG_ANIMATION_AT_START = 2; |
| 48 | |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 49 | final AppWindowToken mAppToken; |
| 50 | final WindowManagerService mService; |
| 51 | final WindowAnimator mAnimator; |
| 52 | |
| 53 | boolean animating; |
Jorim Jaggi | 827e0fa | 2015-05-07 11:41:41 -0700 | [diff] [blame] | 54 | boolean wasAnimating; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 55 | Animation animation; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 56 | boolean hasTransformation; |
| 57 | final Transformation transformation = new Transformation(); |
| 58 | |
| 59 | // Have we been asked to have this token keep the screen frozen? |
| 60 | // Protect with mAnimator. |
| 61 | boolean freezingScreen; |
| 62 | |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 63 | /** |
| 64 | * How long we last kept the screen frozen. |
| 65 | */ |
| 66 | int lastFreezeDuration; |
| 67 | |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 68 | // Offset to the window of all layers in the token, for use by |
| 69 | // AppWindowToken animations. |
| 70 | int animLayerAdjustment; |
| 71 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 72 | // Propagated from AppWindowToken.allDrawn, to determine when |
| 73 | // the state changes. |
| 74 | boolean allDrawn; |
| 75 | |
Winson Chung | ab79fce | 2014-11-04 16:15:22 -0800 | [diff] [blame] | 76 | // Special surface for thumbnail animation. If deferThumbnailDestruction is enabled, then we |
| 77 | // will make sure that the thumbnail is destroyed after the other surface is completed. This |
| 78 | // requires that the duration of the two animations are the same. |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 79 | SurfaceControl thumbnail; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 80 | int thumbnailTransactionSeq; |
Matthew Ng | 7c70647 | 2017-05-05 17:12:18 -0700 | [diff] [blame] | 81 | // TODO(b/62029108): combine both members into a private one. Create a member function to set |
| 82 | // the thumbnail layer to +1 to the highest layer position and replace all setter instances |
| 83 | // with this function. Remove all unnecessary calls to both variables in other classes. |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 84 | int thumbnailLayer; |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 85 | int thumbnailForceAboveLayer; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 86 | Animation thumbnailAnimation; |
| 87 | final Transformation thumbnailTransformation = new Transformation(); |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 88 | // This flag indicates that the destruction of the thumbnail surface is synchronized with |
Winson Chung | ab79fce | 2014-11-04 16:15:22 -0800 | [diff] [blame] | 89 | // another animation, so defer the destruction of this thumbnail surface for a single frame |
| 90 | // after the secondary animation completes. |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 91 | boolean deferThumbnailDestruction; |
Winson Chung | ab79fce | 2014-11-04 16:15:22 -0800 | [diff] [blame] | 92 | // This flag is set if the animator has deferThumbnailDestruction set and has reached the final |
| 93 | // frame of animation. It will extend the animation by one frame and then clean up afterwards. |
| 94 | boolean deferFinalFrameCleanup; |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 95 | // If true when the animation hits the last frame, it will keep running on that last frame. |
| 96 | // This is used to synchronize animation with Recents and we wait for Recents to tell us to |
| 97 | // finish or for a new animation be set as fail-safe mechanism. |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 98 | private int mProlongAnimation; |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 99 | // Whether the prolong animation can be removed when animation is set. The purpose of this is |
| 100 | // that if recents doesn't tell us to remove the prolonged animation, we will get rid of it |
| 101 | // when new animation is set. |
| 102 | private boolean mClearProlongedAnimation; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 103 | private int mTransit; |
| 104 | private int mTransitFlags; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 105 | |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 106 | /** WindowStateAnimator from mAppAnimator.allAppWindows as of last performLayout */ |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 107 | ArrayList<WindowStateAnimator> mAllAppWinAnimators = new ArrayList<>(); |
| 108 | |
| 109 | /** True if the current animation was transferred from another AppWindowAnimator. |
| 110 | * See {@link #transferCurrentAnimation}*/ |
| 111 | boolean usingTransferredAnimation = false; |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 112 | |
Jorim Jaggi | c554b77 | 2015-06-04 16:07:57 -0700 | [diff] [blame] | 113 | private boolean mSkipFirstFrame = false; |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 114 | private int mStackClip = STACK_CLIP_BEFORE_ANIM; |
Jorim Jaggi | c554b77 | 2015-06-04 16:07:57 -0700 | [diff] [blame] | 115 | |
Craig Mautner | fbf378c | 2012-04-23 17:24:21 -0700 | [diff] [blame] | 116 | static final Animation sDummyAnimation = new DummyAnimation(); |
| 117 | |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 118 | public AppWindowAnimator(final AppWindowToken atoken, WindowManagerService service) { |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 119 | mAppToken = atoken; |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 120 | mService = service; |
Filip Gruszczynski | a590c99 | 2015-11-25 16:45:26 -0800 | [diff] [blame] | 121 | mAnimator = mService.mAnimator; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 124 | public void setAnimation(Animation anim, int width, int height, int parentWidth, |
| 125 | int parentHeight, boolean skipFirstFrame, int stackClip, int transit, |
| 126 | int transitFlags) { |
Craig Mautner | 72669d1 | 2012-12-18 17:23:54 -0800 | [diff] [blame] | 127 | if (WindowManagerService.localLOGV) Slog.v(TAG, "Setting animation in " + mAppToken |
| 128 | + ": " + anim + " wxh=" + width + "x" + height |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 129 | + " hasContentToDisplay=" + mAppToken.hasContentToDisplay()); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 130 | animation = anim; |
| 131 | animating = false; |
Craig Mautner | 9339c40 | 2012-11-30 11:23:56 -0800 | [diff] [blame] | 132 | if (!anim.isInitialized()) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 133 | anim.initialize(width, height, parentWidth, parentHeight); |
Craig Mautner | 9339c40 | 2012-11-30 11:23:56 -0800 | [diff] [blame] | 134 | } |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 135 | anim.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION); |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 136 | anim.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked()); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 137 | int zorder = anim.getZAdjustment(); |
| 138 | int adj = 0; |
| 139 | if (zorder == Animation.ZORDER_TOP) { |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 140 | adj = TYPE_LAYER_OFFSET; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 141 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 142 | adj = -TYPE_LAYER_OFFSET; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | if (animLayerAdjustment != adj) { |
| 146 | animLayerAdjustment = adj; |
| 147 | updateLayers(); |
| 148 | } |
| 149 | // Start out animation gone if window is gone, or visible if window is visible. |
| 150 | transformation.clear(); |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 151 | transformation.setAlpha(mAppToken.hasContentToDisplay() ? 1 : 0); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 152 | hasTransformation = true; |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 153 | mStackClip = stackClip; |
Craig Mautner | 1ad9915 | 2014-08-28 15:47:13 -0700 | [diff] [blame] | 154 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 155 | mSkipFirstFrame = skipFirstFrame; |
| 156 | mTransit = transit; |
| 157 | mTransitFlags = transitFlags; |
Jorim Jaggi | c554b77 | 2015-06-04 16:07:57 -0700 | [diff] [blame] | 158 | |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 159 | if (!mAppToken.fillsParent()) { |
Craig Mautner | 1ad9915 | 2014-08-28 15:47:13 -0700 | [diff] [blame] | 160 | anim.setBackgroundColor(0); |
| 161 | } |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 162 | if (mClearProlongedAnimation) { |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 163 | mProlongAnimation = PROLONG_ANIMATION_DISABLED; |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 164 | } else { |
| 165 | mClearProlongedAnimation = true; |
| 166 | } |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | public void setDummyAnimation() { |
Craig Mautner | 72669d1 | 2012-12-18 17:23:54 -0800 | [diff] [blame] | 170 | if (WindowManagerService.localLOGV) Slog.v(TAG, "Setting dummy animation in " + mAppToken |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 171 | + " hasContentToDisplay=" + mAppToken.hasContentToDisplay()); |
Craig Mautner | 1d961d4 | 2012-05-27 12:02:11 -0700 | [diff] [blame] | 172 | animation = sDummyAnimation; |
Craig Mautner | 94ef9df | 2012-05-02 17:08:39 -0700 | [diff] [blame] | 173 | hasTransformation = true; |
| 174 | transformation.clear(); |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 175 | transformation.setAlpha(mAppToken.hasContentToDisplay() ? 1 : 0); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Chong Zhang | 65d15d0 | 2016-03-14 13:59:32 -0700 | [diff] [blame] | 178 | void setNullAnimation() { |
| 179 | animation = null; |
| 180 | usingTransferredAnimation = false; |
| 181 | } |
| 182 | |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 183 | public void clearAnimation() { |
| 184 | if (animation != null) { |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 185 | animating = true; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 186 | } |
Winson Chung | ab79fce | 2014-11-04 16:15:22 -0800 | [diff] [blame] | 187 | clearThumbnail(); |
Chong Zhang | 65d15d0 | 2016-03-14 13:59:32 -0700 | [diff] [blame] | 188 | setNullAnimation(); |
Craig Mautner | 7636dfb | 2012-11-16 15:24:11 -0800 | [diff] [blame] | 189 | if (mAppToken.deferClearAllDrawn) { |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 190 | mAppToken.clearAllDrawn(); |
Craig Mautner | 7636dfb | 2012-11-16 15:24:11 -0800 | [diff] [blame] | 191 | } |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 192 | mStackClip = STACK_CLIP_BEFORE_ANIM; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 193 | mTransit = TRANSIT_UNSET; |
| 194 | mTransitFlags = 0; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Jorim Jaggi | 3787561 | 2015-02-19 21:05:31 +0100 | [diff] [blame] | 197 | public boolean isAnimating() { |
| 198 | return animation != null || mAppToken.inPendingTransaction; |
| 199 | } |
| 200 | |
Jorim Jaggi | c0c9324 | 2017-08-04 16:05:02 +0200 | [diff] [blame] | 201 | /** |
| 202 | * @return whether an animation is about to start, i.e. the animation is set already but we |
| 203 | * haven't processed the first frame yet. |
| 204 | */ |
| 205 | boolean isAnimationStarting() { |
| 206 | return animation != null && !animating; |
| 207 | } |
| 208 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 209 | public int getTransit() { |
| 210 | return mTransit; |
| 211 | } |
| 212 | |
| 213 | int getTransitFlags() { |
| 214 | return mTransitFlags; |
| 215 | } |
| 216 | |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 217 | public void clearThumbnail() { |
| 218 | if (thumbnail != null) { |
Jorim Jaggi | 3dac63a | 2016-03-01 12:37:07 +0100 | [diff] [blame] | 219 | thumbnail.hide(); |
| 220 | mService.mWindowPlacerLocked.destroyAfterTransaction(thumbnail); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 221 | thumbnail = null; |
| 222 | } |
Winson Chung | ab79fce | 2014-11-04 16:15:22 -0800 | [diff] [blame] | 223 | deferThumbnailDestruction = false; |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 226 | int getStackClip() { |
| 227 | return mStackClip; |
| 228 | } |
| 229 | |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 230 | void transferCurrentAnimation( |
| 231 | AppWindowAnimator toAppAnimator, WindowStateAnimator transferWinAnimator) { |
| 232 | |
| 233 | if (animation != null) { |
| 234 | toAppAnimator.animation = animation; |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 235 | toAppAnimator.animating = animating; |
| 236 | toAppAnimator.animLayerAdjustment = animLayerAdjustment; |
Chong Zhang | 65d15d0 | 2016-03-14 13:59:32 -0700 | [diff] [blame] | 237 | setNullAnimation(); |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 238 | animLayerAdjustment = 0; |
| 239 | toAppAnimator.updateLayers(); |
| 240 | updateLayers(); |
| 241 | toAppAnimator.usingTransferredAnimation = true; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 242 | toAppAnimator.mTransit = mTransit; |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 243 | } |
| 244 | if (transferWinAnimator != null) { |
| 245 | mAllAppWinAnimators.remove(transferWinAnimator); |
| 246 | toAppAnimator.mAllAppWinAnimators.add(transferWinAnimator); |
Chong Zhang | 8e06265 | 2016-04-29 15:58:45 -0700 | [diff] [blame] | 247 | toAppAnimator.hasTransformation = transferWinAnimator.mAppAnimator.hasTransformation; |
| 248 | if (toAppAnimator.hasTransformation) { |
| 249 | toAppAnimator.transformation.set(transferWinAnimator.mAppAnimator.transformation); |
| 250 | } else { |
| 251 | toAppAnimator.transformation.clear(); |
| 252 | } |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 253 | transferWinAnimator.mAppAnimator = toAppAnimator; |
| 254 | } |
| 255 | } |
| 256 | |
Robert Carr | dee1b3f | 2017-02-27 11:33:33 -0800 | [diff] [blame] | 257 | private void updateLayers() { |
| 258 | mAppToken.getDisplayContent().assignWindowLayers(false /* relayoutNeeded */); |
| 259 | thumbnailLayer = mAppToken.getHighestAnimLayer(); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | private void stepThumbnailAnimation(long currentTime) { |
| 263 | thumbnailTransformation.clear(); |
Filip Gruszczynski | 564a8f6 | 2015-11-20 11:25:23 -0800 | [diff] [blame] | 264 | final long animationFrameTime = getAnimationFrameTime(thumbnailAnimation, currentTime); |
| 265 | thumbnailAnimation.getTransformation(animationFrameTime, thumbnailTransformation); |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 266 | |
| 267 | ScreenRotationAnimation screenRotationAnimation = |
| 268 | mAnimator.getScreenRotationAnimationLocked(Display.DEFAULT_DISPLAY); |
| 269 | final boolean screenAnimation = screenRotationAnimation != null |
| 270 | && screenRotationAnimation.isAnimating(); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 271 | if (screenAnimation) { |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 272 | thumbnailTransformation.postCompose(screenRotationAnimation.getEnterTransformation()); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 273 | } |
| 274 | // cache often used attributes locally |
| 275 | final float tmpFloats[] = mService.mTmpFloats; |
| 276 | thumbnailTransformation.getMatrix().getValues(tmpFloats); |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 277 | if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(thumbnail, |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 278 | "thumbnail", "POS " + tmpFloats[Matrix.MTRANS_X] |
Filip Gruszczynski | 198dcbf | 2016-01-18 10:02:00 -0800 | [diff] [blame] | 279 | + ", " + tmpFloats[Matrix.MTRANS_Y]); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 280 | thumbnail.setPosition(tmpFloats[Matrix.MTRANS_X], tmpFloats[Matrix.MTRANS_Y]); |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 281 | if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(thumbnail, |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 282 | "thumbnail", "alpha=" + thumbnailTransformation.getAlpha() |
| 283 | + " layer=" + thumbnailLayer |
| 284 | + " matrix=[" + tmpFloats[Matrix.MSCALE_X] |
| 285 | + "," + tmpFloats[Matrix.MSKEW_Y] |
| 286 | + "][" + tmpFloats[Matrix.MSKEW_X] |
Filip Gruszczynski | 198dcbf | 2016-01-18 10:02:00 -0800 | [diff] [blame] | 287 | + "," + tmpFloats[Matrix.MSCALE_Y] + "]"); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 288 | thumbnail.setAlpha(thumbnailTransformation.getAlpha()); |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 289 | if (thumbnailForceAboveLayer > 0) { |
| 290 | thumbnail.setLayer(thumbnailForceAboveLayer + 1); |
| 291 | } else { |
| 292 | // The thumbnail is layered below the window immediately above this |
| 293 | // token's anim layer. |
| 294 | thumbnail.setLayer(thumbnailLayer + WindowManagerService.WINDOW_LAYER_MULTIPLIER |
| 295 | - WindowManagerService.LAYER_OFFSET_THUMBNAIL); |
| 296 | } |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 297 | thumbnail.setMatrix(tmpFloats[Matrix.MSCALE_X], tmpFloats[Matrix.MSKEW_Y], |
| 298 | tmpFloats[Matrix.MSKEW_X], tmpFloats[Matrix.MSCALE_Y]); |
Jorim Jaggi | de63d44 | 2016-03-14 14:56:56 +0100 | [diff] [blame] | 299 | thumbnail.setWindowCrop(thumbnailTransformation.getClipRect()); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Filip Gruszczynski | 564a8f6 | 2015-11-20 11:25:23 -0800 | [diff] [blame] | 302 | /** |
| 303 | * Sometimes we need to synchronize the first frame of animation with some external event, e.g. |
| 304 | * Recents hiding some of its content. To achieve this, we prolong the start of the animaiton |
| 305 | * and keep producing the first frame of the animation. |
| 306 | */ |
| 307 | private long getAnimationFrameTime(Animation animation, long currentTime) { |
| 308 | if (mProlongAnimation == PROLONG_ANIMATION_AT_START) { |
| 309 | animation.setStartTime(currentTime); |
| 310 | return currentTime + 1; |
| 311 | } |
| 312 | return currentTime; |
| 313 | } |
| 314 | |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 315 | private boolean stepAnimation(long currentTime) { |
| 316 | if (animation == null) { |
| 317 | return false; |
| 318 | } |
| 319 | transformation.clear(); |
Filip Gruszczynski | 564a8f6 | 2015-11-20 11:25:23 -0800 | [diff] [blame] | 320 | final long animationFrameTime = getAnimationFrameTime(animation, currentTime); |
| 321 | boolean hasMoreFrames = animation.getTransformation(animationFrameTime, transformation); |
Winson Chung | ab79fce | 2014-11-04 16:15:22 -0800 | [diff] [blame] | 322 | if (!hasMoreFrames) { |
| 323 | if (deferThumbnailDestruction && !deferFinalFrameCleanup) { |
| 324 | // We are deferring the thumbnail destruction, so extend the animation for one more |
| 325 | // (dummy) frame before we clean up |
| 326 | deferFinalFrameCleanup = true; |
| 327 | hasMoreFrames = true; |
| 328 | } else { |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 329 | if (false && DEBUG_ANIM) Slog.v(TAG, |
| 330 | "Stepped animation in " + mAppToken + ": more=" + hasMoreFrames + |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 331 | ", xform=" + transformation + ", mProlongAnimation=" + mProlongAnimation); |
Winson Chung | ab79fce | 2014-11-04 16:15:22 -0800 | [diff] [blame] | 332 | deferFinalFrameCleanup = false; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 333 | if (mProlongAnimation == PROLONG_ANIMATION_AT_END) { |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 334 | hasMoreFrames = true; |
| 335 | } else { |
Chong Zhang | 65d15d0 | 2016-03-14 13:59:32 -0700 | [diff] [blame] | 336 | setNullAnimation(); |
Filip Gruszczynski | 564a8f6 | 2015-11-20 11:25:23 -0800 | [diff] [blame] | 337 | clearThumbnail(); |
| 338 | if (DEBUG_ANIM) Slog.v(TAG, "Finished animation in " + mAppToken + " @ " |
| 339 | + currentTime); |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 340 | } |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 341 | } |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 342 | } |
Winson Chung | ab79fce | 2014-11-04 16:15:22 -0800 | [diff] [blame] | 343 | hasTransformation = hasMoreFrames; |
| 344 | return hasMoreFrames; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Jorim Jaggi | c554b77 | 2015-06-04 16:07:57 -0700 | [diff] [blame] | 347 | private long getStartTimeCorrection() { |
| 348 | if (mSkipFirstFrame) { |
| 349 | |
| 350 | // If the transition is an animation in which the first frame doesn't change the screen |
| 351 | // contents at all, we can just skip it and start at the second frame. So we shift the |
| 352 | // start time of the animation forward by minus the frame duration. |
| 353 | return -Choreographer.getInstance().getFrameIntervalNanos() / TimeUtils.NANOS_PER_MS; |
| 354 | } else { |
| 355 | return 0; |
| 356 | } |
| 357 | } |
| 358 | |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 359 | // This must be called while inside a transaction. |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 360 | boolean stepAnimationLocked(long currentTime) { |
Adrian Roos | e94c15c | 2017-05-09 13:17:54 -0700 | [diff] [blame] | 361 | if (mService.okToAnimate()) { |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 362 | // We will run animations as long as the display isn't frozen. |
| 363 | |
Craig Mautner | fbf378c | 2012-04-23 17:24:21 -0700 | [diff] [blame] | 364 | if (animation == sDummyAnimation) { |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 365 | // This guy is going to animate, but not yet. For now count |
| 366 | // it as not animating for purposes of scheduling transactions; |
| 367 | // when it is really time to animate, this will be set to |
| 368 | // a real animation and the next call will execute normally. |
| 369 | return false; |
| 370 | } |
| 371 | |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 372 | if ((mAppToken.allDrawn || animating || mAppToken.startingDisplayed) |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 373 | && animation != null) { |
| 374 | if (!animating) { |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 375 | if (DEBUG_ANIM) Slog.v(TAG, |
| 376 | "Starting animation in " + mAppToken + |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 377 | " @ " + currentTime + " scale=" |
| 378 | + mService.getTransitionAnimationScaleLocked() |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 379 | + " allDrawn=" + mAppToken.allDrawn + " animating=" + animating); |
Jorim Jaggi | c554b77 | 2015-06-04 16:07:57 -0700 | [diff] [blame] | 380 | long correction = getStartTimeCorrection(); |
| 381 | animation.setStartTime(currentTime + correction); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 382 | animating = true; |
| 383 | if (thumbnail != null) { |
| 384 | thumbnail.show(); |
Jorim Jaggi | c554b77 | 2015-06-04 16:07:57 -0700 | [diff] [blame] | 385 | thumbnailAnimation.setStartTime(currentTime + correction); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 386 | } |
Jorim Jaggi | c554b77 | 2015-06-04 16:07:57 -0700 | [diff] [blame] | 387 | mSkipFirstFrame = false; |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 388 | } |
| 389 | if (stepAnimation(currentTime)) { |
| 390 | // animation isn't over, step any thumbnail and that's |
| 391 | // it for now. |
| 392 | if (thumbnail != null) { |
| 393 | stepThumbnailAnimation(currentTime); |
| 394 | } |
| 395 | return true; |
| 396 | } |
| 397 | } |
| 398 | } else if (animation != null) { |
| 399 | // If the display is frozen, and there is a pending animation, |
| 400 | // clear it and make sure we run the cleanup code. |
| 401 | animating = true; |
| 402 | animation = null; |
| 403 | } |
| 404 | |
| 405 | hasTransformation = false; |
| 406 | |
Craig Mautner | 3de422f | 2012-04-06 18:04:13 -0700 | [diff] [blame] | 407 | if (!animating && animation == null) { |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 408 | return false; |
| 409 | } |
| 410 | |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 411 | mAppToken.setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "AppWindowToken"); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 412 | |
| 413 | clearAnimation(); |
| 414 | animating = false; |
| 415 | if (animLayerAdjustment != 0) { |
| 416 | animLayerAdjustment = 0; |
| 417 | updateLayers(); |
| 418 | } |
| 419 | if (mService.mInputMethodTarget != null |
| 420 | && mService.mInputMethodTarget.mAppToken == mAppToken) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 421 | mAppToken.getDisplayContent().computeImeTarget(true /* updateImeTarget */); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Wale Ogunwale | 15ead90 | 2016-09-02 14:30:11 -0700 | [diff] [blame] | 424 | if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + mAppToken |
Jorim Jaggi | dc9385a | 2017-05-13 02:00:31 +0200 | [diff] [blame] | 425 | + ": reportedVisible=" + mAppToken.reportedVisible |
| 426 | + " okToDisplay=" + mService.okToDisplay() |
Adrian Roos | e94c15c | 2017-05-09 13:17:54 -0700 | [diff] [blame] | 427 | + " okToAnimate=" + mService.okToAnimate() |
Jorim Jaggi | dc9385a | 2017-05-13 02:00:31 +0200 | [diff] [blame] | 428 | + " startingDisplayed=" + mAppToken.startingDisplayed); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 429 | |
| 430 | transformation.clear(); |
| 431 | |
Wale Ogunwale | ec533f6 | 2014-12-05 09:03:48 -0800 | [diff] [blame] | 432 | final int numAllAppWinAnimators = mAllAppWinAnimators.size(); |
| 433 | for (int i = 0; i < numAllAppWinAnimators; i++) { |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 434 | mAllAppWinAnimators.get(i).mWin.onExitAnimationDone(); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 435 | } |
Wale Ogunwale | a48eadb | 2015-05-14 17:43:12 -0700 | [diff] [blame] | 436 | mService.mAppTransition.notifyAppTransitionFinishedLocked(mAppToken.token); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 437 | return false; |
| 438 | } |
| 439 | |
Filip Gruszczynski | 974eb3d | 2015-10-23 17:33:11 -0700 | [diff] [blame] | 440 | // This must be called while inside a transaction. |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 441 | boolean showAllWindowsLocked() { |
| 442 | boolean isAnimating = false; |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 443 | final int NW = mAllAppWinAnimators.size(); |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 444 | for (int i=0; i<NW; i++) { |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 445 | WindowStateAnimator winAnimator = mAllAppWinAnimators.get(i); |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 446 | if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + winAnimator); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 447 | winAnimator.mWin.performShowLocked(); |
Jorim Jaggi | 5c80c41 | 2016-04-19 20:03:47 -0700 | [diff] [blame] | 448 | isAnimating |= winAnimator.isAnimationSet(); |
Craig Mautner | bec53f7 | 2012-04-05 11:49:05 -0700 | [diff] [blame] | 449 | } |
| 450 | return isAnimating; |
| 451 | } |
| 452 | |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 453 | void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
| 454 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 455 | pw.print(prefix); pw.print("mAnimator="); pw.println(mAnimator); |
| 456 | pw.print(prefix); pw.print("freezingScreen="); pw.print(freezingScreen); |
| 457 | pw.print(" allDrawn="); pw.print(allDrawn); |
| 458 | pw.print(" animLayerAdjustment="); pw.println(animLayerAdjustment); |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 459 | if (lastFreezeDuration != 0) { |
| 460 | pw.print(prefix); pw.print("lastFreezeDuration="); |
| 461 | TimeUtils.formatDuration(lastFreezeDuration, pw); pw.println(); |
| 462 | } |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 463 | if (animating || animation != null) { |
Craig Mautner | 9339c40 | 2012-11-30 11:23:56 -0800 | [diff] [blame] | 464 | pw.print(prefix); pw.print("animating="); pw.println(animating); |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 465 | pw.print(prefix); pw.print("animation="); pw.println(animation); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 466 | pw.print(prefix); pw.print("mTransit="); pw.println(mTransit); |
| 467 | pw.print(prefix); pw.print("mTransitFlags="); pw.println(mTransitFlags); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 468 | } |
| 469 | if (hasTransformation) { |
| 470 | pw.print(prefix); pw.print("XForm: "); |
| 471 | transformation.printShortString(pw); |
| 472 | pw.println(); |
| 473 | } |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 474 | if (thumbnail != null) { |
| 475 | pw.print(prefix); pw.print("thumbnail="); pw.print(thumbnail); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 476 | pw.print(" layer="); pw.println(thumbnailLayer); |
| 477 | pw.print(prefix); pw.print("thumbnailAnimation="); pw.println(thumbnailAnimation); |
| 478 | pw.print(prefix); pw.print("thumbnailTransformation="); |
| 479 | pw.println(thumbnailTransformation.toShortString()); |
| 480 | } |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 481 | for (int i=0; i<mAllAppWinAnimators.size(); i++) { |
| 482 | WindowStateAnimator wanim = mAllAppWinAnimators.get(i); |
| 483 | pw.print(prefix); pw.print("App Win Anim #"); pw.print(i); |
| 484 | pw.print(": "); pw.println(wanim); |
| 485 | } |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 486 | } |
Craig Mautner | fbf378c | 2012-04-23 17:24:21 -0700 | [diff] [blame] | 487 | |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 488 | void startProlongAnimation(int prolongType) { |
| 489 | mProlongAnimation = prolongType; |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 490 | mClearProlongedAnimation = false; |
| 491 | } |
| 492 | |
| 493 | void endProlongedAnimation() { |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 494 | mProlongAnimation = PROLONG_ANIMATION_DISABLED; |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 495 | } |
| 496 | |
Craig Mautner | fbf378c | 2012-04-23 17:24:21 -0700 | [diff] [blame] | 497 | // This is an animation that does nothing: it just immediately finishes |
| 498 | // itself every time it is called. It is used as a stub animation in cases |
| 499 | // where we want to synchronize multiple things that may be animating. |
| 500 | static final class DummyAnimation extends Animation { |
| 501 | @Override |
| 502 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 503 | return false; |
| 504 | } |
| 505 | } |
| 506 | |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 507 | } |