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