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