Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | */ |
| 16 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 17 | package com.android.server.wm; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 18 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 19 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS; |
| 20 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC; |
| 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; |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 24 | import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER; |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 25 | import static com.android.server.wm.WindowStateAnimator.WINDOW_FREEZE_LAYER; |
Steven Timotius | f2d6889 | 2017-08-28 17:00:01 -0700 | [diff] [blame] | 26 | import static com.android.server.wm.proto.ScreenRotationAnimationProto.ANIMATION_RUNNING; |
| 27 | import static com.android.server.wm.proto.ScreenRotationAnimationProto.STARTED; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 28 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 29 | import android.content.Context; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 30 | import android.graphics.Matrix; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 31 | import android.graphics.Rect; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 32 | import android.util.Slog; |
Steven Timotius | f2d6889 | 2017-08-28 17:00:01 -0700 | [diff] [blame] | 33 | import android.util.proto.ProtoOutputStream; |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 34 | import android.view.Display; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 35 | import android.view.DisplayInfo; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 36 | import android.view.Surface; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 37 | import android.view.Surface.OutOfResourcesException; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 38 | import android.view.SurfaceControl; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 39 | import android.view.SurfaceSession; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 40 | import android.view.animation.Animation; |
| 41 | import android.view.animation.AnimationUtils; |
| 42 | import android.view.animation.Transformation; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 43 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 44 | import java.io.PrintWriter; |
| 45 | |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 46 | class ScreenRotationAnimation { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 47 | static final String TAG = TAG_WITH_CLASS_NAME ? "ScreenRotationAnimation" : TAG_WM; |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 48 | static final boolean DEBUG_STATE = false; |
| 49 | static final boolean DEBUG_TRANSFORMS = false; |
Dianne Hackborn | 187ae210 | 2012-04-11 18:12:06 -0700 | [diff] [blame] | 50 | static final boolean TWO_PHASE_ANIMATION = false; |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 51 | static final boolean USE_CUSTOM_BLACK_FRAME = false; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 52 | |
Chong Zhang | 97782b4 | 2015-10-07 16:01:23 -0700 | [diff] [blame] | 53 | /* |
| 54 | * Layers for screen rotation animation. We put these layers above |
| 55 | * WINDOW_FREEZE_LAYER so that screen freeze will cover all windows. |
| 56 | */ |
| 57 | static final int SCREEN_FREEZE_LAYER_BASE = WINDOW_FREEZE_LAYER + TYPE_LAYER_MULTIPLIER; |
| 58 | static final int SCREEN_FREEZE_LAYER_ENTER = SCREEN_FREEZE_LAYER_BASE; |
| 59 | static final int SCREEN_FREEZE_LAYER_SCREENSHOT = SCREEN_FREEZE_LAYER_BASE + 1; |
| 60 | static final int SCREEN_FREEZE_LAYER_EXIT = SCREEN_FREEZE_LAYER_BASE + 2; |
| 61 | static final int SCREEN_FREEZE_LAYER_CUSTOM = SCREEN_FREEZE_LAYER_BASE + 3; |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 62 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 63 | final Context mContext; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 64 | final DisplayContent mDisplayContent; |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 65 | SurfaceControl mSurfaceControl; |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 66 | BlackFrame mCustomBlackFrame; |
| 67 | BlackFrame mExitingBlackFrame; |
| 68 | BlackFrame mEnteringBlackFrame; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 69 | int mWidth, mHeight; |
| 70 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 71 | int mOriginalRotation; |
| 72 | int mOriginalWidth, mOriginalHeight; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 73 | int mCurRotation; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 74 | Rect mOriginalDisplayRect = new Rect(); |
| 75 | Rect mCurrentDisplayRect = new Rect(); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 76 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 77 | // For all animations, "exit" is for the UI elements that are going |
| 78 | // away (that is the snapshot of the old screen), and "enter" is for |
| 79 | // the new UI elements that are appearing (that is the active windows |
| 80 | // in their final orientation). |
| 81 | |
| 82 | // The starting animation for the exiting and entering elements. This |
| 83 | // animation applies a transformation while the rotation is in progress. |
| 84 | // It is started immediately, before the new entering UI is ready. |
| 85 | Animation mStartExitAnimation; |
| 86 | final Transformation mStartExitTransformation = new Transformation(); |
| 87 | Animation mStartEnterAnimation; |
| 88 | final Transformation mStartEnterTransformation = new Transformation(); |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 89 | Animation mStartFrameAnimation; |
| 90 | final Transformation mStartFrameTransformation = new Transformation(); |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 91 | |
| 92 | // The finishing animation for the exiting and entering elements. This |
| 93 | // animation needs to undo the transformation of the starting animation. |
| 94 | // It starts running once the new rotation UI elements are ready to be |
| 95 | // displayed. |
| 96 | Animation mFinishExitAnimation; |
| 97 | final Transformation mFinishExitTransformation = new Transformation(); |
| 98 | Animation mFinishEnterAnimation; |
| 99 | final Transformation mFinishEnterTransformation = new Transformation(); |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 100 | Animation mFinishFrameAnimation; |
| 101 | final Transformation mFinishFrameTransformation = new Transformation(); |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 102 | |
| 103 | // The current active animation to move from the old to the new rotated |
| 104 | // state. Which animation is run here will depend on the old and new |
| 105 | // rotations. |
| 106 | Animation mRotateExitAnimation; |
| 107 | final Transformation mRotateExitTransformation = new Transformation(); |
| 108 | Animation mRotateEnterAnimation; |
| 109 | final Transformation mRotateEnterTransformation = new Transformation(); |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 110 | Animation mRotateFrameAnimation; |
| 111 | final Transformation mRotateFrameTransformation = new Transformation(); |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 112 | |
| 113 | // A previously running rotate animation. This will be used if we need |
| 114 | // to switch to a new rotation before finishing the previous one. |
| 115 | Animation mLastRotateExitAnimation; |
| 116 | final Transformation mLastRotateExitTransformation = new Transformation(); |
| 117 | Animation mLastRotateEnterAnimation; |
| 118 | final Transformation mLastRotateEnterTransformation = new Transformation(); |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 119 | Animation mLastRotateFrameAnimation; |
| 120 | final Transformation mLastRotateFrameTransformation = new Transformation(); |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 121 | |
| 122 | // Complete transformations being applied. |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 123 | final Transformation mExitTransformation = new Transformation(); |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 124 | final Transformation mEnterTransformation = new Transformation(); |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 125 | final Transformation mFrameTransformation = new Transformation(); |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 126 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 127 | boolean mStarted; |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 128 | boolean mAnimRunning; |
| 129 | boolean mFinishAnimReady; |
| 130 | long mFinishAnimStartTime; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 131 | boolean mForceDefaultOrientation; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 132 | |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 133 | final Matrix mFrameInitialMatrix = new Matrix(); |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 134 | final Matrix mSnapshotInitialMatrix = new Matrix(); |
| 135 | final Matrix mSnapshotFinalMatrix = new Matrix(); |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 136 | final Matrix mExitFrameFinalMatrix = new Matrix(); |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 137 | final Matrix mTmpMatrix = new Matrix(); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 138 | final float[] mTmpFloats = new float[9]; |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 139 | private boolean mMoreRotateEnter; |
| 140 | private boolean mMoreRotateExit; |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 141 | private boolean mMoreRotateFrame; |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 142 | private boolean mMoreFinishEnter; |
| 143 | private boolean mMoreFinishExit; |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 144 | private boolean mMoreFinishFrame; |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 145 | private boolean mMoreStartEnter; |
| 146 | private boolean mMoreStartExit; |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 147 | private boolean mMoreStartFrame; |
Craig Mautner | 3255a28 | 2012-04-16 15:42:47 -0700 | [diff] [blame] | 148 | long mHalfwayPoint; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 149 | |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 150 | private final WindowManagerService mService; |
| 151 | |
Dianne Hackborn | 4dcece8 | 2012-02-10 14:50:32 -0800 | [diff] [blame] | 152 | public void printTo(String prefix, PrintWriter pw) { |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 153 | pw.print(prefix); pw.print("mSurface="); pw.print(mSurfaceControl); |
Dianne Hackborn | 4dcece8 | 2012-02-10 14:50:32 -0800 | [diff] [blame] | 154 | pw.print(" mWidth="); pw.print(mWidth); |
| 155 | pw.print(" mHeight="); pw.println(mHeight); |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 156 | if (USE_CUSTOM_BLACK_FRAME) { |
| 157 | pw.print(prefix); pw.print("mCustomBlackFrame="); pw.println(mCustomBlackFrame); |
| 158 | if (mCustomBlackFrame != null) { |
| 159 | mCustomBlackFrame.printTo(prefix + " ", pw); |
| 160 | } |
| 161 | } |
| 162 | pw.print(prefix); pw.print("mExitingBlackFrame="); pw.println(mExitingBlackFrame); |
| 163 | if (mExitingBlackFrame != null) { |
| 164 | mExitingBlackFrame.printTo(prefix + " ", pw); |
| 165 | } |
| 166 | pw.print(prefix); pw.print("mEnteringBlackFrame="); pw.println(mEnteringBlackFrame); |
| 167 | if (mEnteringBlackFrame != null) { |
| 168 | mEnteringBlackFrame.printTo(prefix + " ", pw); |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 169 | } |
Dianne Hackborn | 187ae210 | 2012-04-11 18:12:06 -0700 | [diff] [blame] | 170 | pw.print(prefix); pw.print("mCurRotation="); pw.print(mCurRotation); |
| 171 | pw.print(" mOriginalRotation="); pw.println(mOriginalRotation); |
| 172 | pw.print(prefix); pw.print("mOriginalWidth="); pw.print(mOriginalWidth); |
Dianne Hackborn | 4dcece8 | 2012-02-10 14:50:32 -0800 | [diff] [blame] | 173 | pw.print(" mOriginalHeight="); pw.println(mOriginalHeight); |
| 174 | pw.print(prefix); pw.print("mStarted="); pw.print(mStarted); |
| 175 | pw.print(" mAnimRunning="); pw.print(mAnimRunning); |
| 176 | pw.print(" mFinishAnimReady="); pw.print(mFinishAnimReady); |
| 177 | pw.print(" mFinishAnimStartTime="); pw.println(mFinishAnimStartTime); |
| 178 | pw.print(prefix); pw.print("mStartExitAnimation="); pw.print(mStartExitAnimation); |
| 179 | pw.print(" "); mStartExitTransformation.printShortString(pw); pw.println(); |
| 180 | pw.print(prefix); pw.print("mStartEnterAnimation="); pw.print(mStartEnterAnimation); |
| 181 | pw.print(" "); mStartEnterTransformation.printShortString(pw); pw.println(); |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 182 | pw.print(prefix); pw.print("mStartFrameAnimation="); pw.print(mStartFrameAnimation); |
| 183 | pw.print(" "); mStartFrameTransformation.printShortString(pw); pw.println(); |
Dianne Hackborn | 4dcece8 | 2012-02-10 14:50:32 -0800 | [diff] [blame] | 184 | pw.print(prefix); pw.print("mFinishExitAnimation="); pw.print(mFinishExitAnimation); |
| 185 | pw.print(" "); mFinishExitTransformation.printShortString(pw); pw.println(); |
| 186 | pw.print(prefix); pw.print("mFinishEnterAnimation="); pw.print(mFinishEnterAnimation); |
| 187 | pw.print(" "); mFinishEnterTransformation.printShortString(pw); pw.println(); |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 188 | pw.print(prefix); pw.print("mFinishFrameAnimation="); pw.print(mFinishFrameAnimation); |
| 189 | pw.print(" "); mFinishFrameTransformation.printShortString(pw); pw.println(); |
Dianne Hackborn | 4dcece8 | 2012-02-10 14:50:32 -0800 | [diff] [blame] | 190 | pw.print(prefix); pw.print("mRotateExitAnimation="); pw.print(mRotateExitAnimation); |
| 191 | pw.print(" "); mRotateExitTransformation.printShortString(pw); pw.println(); |
| 192 | pw.print(prefix); pw.print("mRotateEnterAnimation="); pw.print(mRotateEnterAnimation); |
| 193 | pw.print(" "); mRotateEnterTransformation.printShortString(pw); pw.println(); |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 194 | pw.print(prefix); pw.print("mRotateFrameAnimation="); pw.print(mRotateFrameAnimation); |
| 195 | pw.print(" "); mRotateFrameTransformation.printShortString(pw); pw.println(); |
Dianne Hackborn | 4dcece8 | 2012-02-10 14:50:32 -0800 | [diff] [blame] | 196 | pw.print(prefix); pw.print("mExitTransformation="); |
| 197 | mExitTransformation.printShortString(pw); pw.println(); |
| 198 | pw.print(prefix); pw.print("mEnterTransformation="); |
| 199 | mEnterTransformation.printShortString(pw); pw.println(); |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 200 | pw.print(prefix); pw.print("mFrameTransformation="); |
Steven Timotius | 8304ef4 | 2017-08-28 16:59:14 -0700 | [diff] [blame] | 201 | mFrameTransformation.printShortString(pw); pw.println(); |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 202 | pw.print(prefix); pw.print("mFrameInitialMatrix="); |
| 203 | mFrameInitialMatrix.printShortString(pw); |
| 204 | pw.println(); |
Dianne Hackborn | 4dcece8 | 2012-02-10 14:50:32 -0800 | [diff] [blame] | 205 | pw.print(prefix); pw.print("mSnapshotInitialMatrix="); |
| 206 | mSnapshotInitialMatrix.printShortString(pw); |
| 207 | pw.print(" mSnapshotFinalMatrix="); mSnapshotFinalMatrix.printShortString(pw); |
| 208 | pw.println(); |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 209 | pw.print(prefix); pw.print("mExitFrameFinalMatrix="); |
| 210 | mExitFrameFinalMatrix.printShortString(pw); |
| 211 | pw.println(); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 212 | pw.print(prefix); pw.print("mForceDefaultOrientation="); pw.print(mForceDefaultOrientation); |
| 213 | if (mForceDefaultOrientation) { |
| 214 | pw.print(" mOriginalDisplayRect="); pw.print(mOriginalDisplayRect.toShortString()); |
| 215 | pw.print(" mCurrentDisplayRect="); pw.println(mCurrentDisplayRect.toShortString()); |
| 216 | } |
Dianne Hackborn | 4dcece8 | 2012-02-10 14:50:32 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Steven Timotius | f2d6889 | 2017-08-28 17:00:01 -0700 | [diff] [blame] | 219 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 220 | final long token = proto.start(fieldId); |
| 221 | proto.write(STARTED, mStarted); |
| 222 | proto.write(ANIMATION_RUNNING, mAnimRunning); |
| 223 | proto.end(token); |
| 224 | } |
| 225 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 226 | public ScreenRotationAnimation(Context context, DisplayContent displayContent, |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 227 | boolean forceDefaultOrientation, boolean isSecure, WindowManagerService service) { |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 228 | mService = service; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 229 | mContext = context; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 230 | mDisplayContent = displayContent; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 231 | displayContent.getBounds(mOriginalDisplayRect); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 232 | |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 233 | // Screenshot does NOT include rotation! |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 234 | final Display display = displayContent.getDisplay(); |
| 235 | int originalRotation = display.getRotation(); |
| 236 | final int originalWidth; |
| 237 | final int originalHeight; |
| 238 | DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 239 | if (forceDefaultOrientation) { |
| 240 | // Emulated orientation. |
| 241 | mForceDefaultOrientation = true; |
| 242 | originalWidth = displayContent.mBaseDisplayWidth; |
| 243 | originalHeight = displayContent.mBaseDisplayHeight; |
| 244 | } else { |
| 245 | // Normal situation |
| 246 | originalWidth = displayInfo.logicalWidth; |
| 247 | originalHeight = displayInfo.logicalHeight; |
| 248 | } |
Mathias Agopian | 0ab84ef | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 249 | if (originalRotation == Surface.ROTATION_90 |
| 250 | || originalRotation == Surface.ROTATION_270) { |
| 251 | mWidth = originalHeight; |
| 252 | mHeight = originalWidth; |
| 253 | } else { |
| 254 | mWidth = originalWidth; |
| 255 | mHeight = originalHeight; |
| 256 | } |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 257 | |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 258 | mOriginalRotation = originalRotation; |
| 259 | mOriginalWidth = originalWidth; |
| 260 | mOriginalHeight = originalHeight; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 261 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 262 | final SurfaceControl.Transaction t = new SurfaceControl.Transaction(); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 263 | try { |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 264 | mSurfaceControl = displayContent.makeOverlay() |
| 265 | .setName("ScreenshotSurface") |
| 266 | .setSize(mWidth, mHeight) |
| 267 | .setSecure(isSecure) |
| 268 | .build(); |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 269 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 270 | // capture a screenshot into the surface we just created |
| 271 | Surface sur = new Surface(); |
| 272 | sur.copyFrom(mSurfaceControl); |
| 273 | // TODO(multidisplay): we should use the proper display |
| 274 | SurfaceControl.screenshot(SurfaceControl.getBuiltInDisplay( |
| 275 | SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN), sur); |
| 276 | t.setLayer(mSurfaceControl, SCREEN_FREEZE_LAYER_SCREENSHOT); |
| 277 | t.setAlpha(mSurfaceControl, 0); |
| 278 | t.show(mSurfaceControl); |
| 279 | sur.destroy(); |
| 280 | } catch (OutOfResourcesException e) { |
| 281 | Slog.w(TAG, "Unable to allocate freeze surface", e); |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 282 | } |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 283 | |
| 284 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG_WM, |
| 285 | " FREEZE " + mSurfaceControl + ": CREATE"); |
| 286 | setRotation(t, originalRotation); |
| 287 | t.apply(); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 288 | } |
| 289 | |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 290 | boolean hasScreenshot() { |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 291 | return mSurfaceControl != null; |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 292 | } |
| 293 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 294 | private void setSnapshotTransform(SurfaceControl.Transaction t, Matrix matrix, float alpha) { |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 295 | if (mSurfaceControl != null) { |
Dianne Hackborn | 352cc98 | 2011-01-04 11:34:18 -0800 | [diff] [blame] | 296 | matrix.getValues(mTmpFloats); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 297 | float x = mTmpFloats[Matrix.MTRANS_X]; |
| 298 | float y = mTmpFloats[Matrix.MTRANS_Y]; |
| 299 | if (mForceDefaultOrientation) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 300 | mDisplayContent.getBounds(mCurrentDisplayRect); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 301 | x -= mCurrentDisplayRect.left; |
| 302 | y -= mCurrentDisplayRect.top; |
| 303 | } |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 304 | t.setPosition(mSurfaceControl, x, y); |
| 305 | t.setMatrix(mSurfaceControl, |
Dianne Hackborn | 352cc98 | 2011-01-04 11:34:18 -0800 | [diff] [blame] | 306 | mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y], |
| 307 | mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 308 | t.setAlpha(mSurfaceControl, alpha); |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 309 | if (DEBUG_TRANSFORMS) { |
Dianne Hackborn | 352cc98 | 2011-01-04 11:34:18 -0800 | [diff] [blame] | 310 | float[] srcPnts = new float[] { 0, 0, mWidth, mHeight }; |
| 311 | float[] dstPnts = new float[4]; |
| 312 | matrix.mapPoints(dstPnts, srcPnts); |
| 313 | Slog.i(TAG, "Original : (" + srcPnts[0] + "," + srcPnts[1] |
| 314 | + ")-(" + srcPnts[2] + "," + srcPnts[3] + ")"); |
| 315 | Slog.i(TAG, "Transformed: (" + dstPnts[0] + "," + dstPnts[1] |
| 316 | + ")-(" + dstPnts[2] + "," + dstPnts[3] + ")"); |
| 317 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 321 | public static void createRotationMatrix(int rotation, int width, int height, |
| 322 | Matrix outMatrix) { |
| 323 | switch (rotation) { |
| 324 | case Surface.ROTATION_0: |
| 325 | outMatrix.reset(); |
| 326 | break; |
| 327 | case Surface.ROTATION_90: |
| 328 | outMatrix.setRotate(90, 0, 0); |
| 329 | outMatrix.postTranslate(height, 0); |
| 330 | break; |
| 331 | case Surface.ROTATION_180: |
| 332 | outMatrix.setRotate(180, 0, 0); |
| 333 | outMatrix.postTranslate(width, height); |
| 334 | break; |
| 335 | case Surface.ROTATION_270: |
| 336 | outMatrix.setRotate(270, 0, 0); |
| 337 | outMatrix.postTranslate(0, width); |
| 338 | break; |
| 339 | } |
| 340 | } |
| 341 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 342 | private void setRotation(SurfaceControl.Transaction t, int rotation) { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 343 | mCurRotation = rotation; |
| 344 | |
| 345 | // Compute the transformation matrix that must be applied |
| 346 | // to the snapshot to make it stay in the same original position |
| 347 | // with the current screen rotation. |
Wale Ogunwale | 4a02d81 | 2015-02-12 23:01:38 -0800 | [diff] [blame] | 348 | int delta = DisplayContent.deltaRotation(rotation, Surface.ROTATION_0); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 349 | createRotationMatrix(delta, mWidth, mHeight, mSnapshotInitialMatrix); |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 350 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 351 | if (DEBUG_STATE) Slog.v(TAG, "**** ROTATION: " + delta); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 352 | setSnapshotTransform(t, mSnapshotInitialMatrix, 1.0f); |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 353 | } |
| 354 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 355 | public boolean setRotation(SurfaceControl.Transaction t, int rotation, |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 356 | long maxAnimationDuration, float animationScale, int finalWidth, int finalHeight) { |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 357 | setRotation(t, rotation); |
Dianne Hackborn | 187ae210 | 2012-04-11 18:12:06 -0700 | [diff] [blame] | 358 | if (TWO_PHASE_ANIMATION) { |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 359 | return startAnimation(t, maxAnimationDuration, animationScale, |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 360 | finalWidth, finalHeight, false, 0, 0); |
Dianne Hackborn | 187ae210 | 2012-04-11 18:12:06 -0700 | [diff] [blame] | 361 | } |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 362 | |
| 363 | // Don't start animation yet. |
| 364 | return false; |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 365 | } |
| 366 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 367 | /** |
| 368 | * Returns true if animating. |
| 369 | */ |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 370 | private boolean startAnimation(SurfaceControl.Transaction t, long maxAnimationDuration, |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 371 | float animationScale, int finalWidth, int finalHeight, boolean dismissing, |
| 372 | int exitAnim, int enterAnim) { |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 373 | if (mSurfaceControl == null) { |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 374 | // Can't do animation. |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 375 | return false; |
| 376 | } |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 377 | if (mStarted) { |
| 378 | return true; |
| 379 | } |
| 380 | |
| 381 | mStarted = true; |
| 382 | |
| 383 | boolean firstStart = false; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 384 | |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 385 | // Figure out how the screen has moved from the original rotation. |
Wale Ogunwale | 4a02d81 | 2015-02-12 23:01:38 -0800 | [diff] [blame] | 386 | int delta = DisplayContent.deltaRotation(mCurRotation, mOriginalRotation); |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 387 | |
Dianne Hackborn | 187ae210 | 2012-04-11 18:12:06 -0700 | [diff] [blame] | 388 | if (TWO_PHASE_ANIMATION && mFinishExitAnimation == null |
| 389 | && (!dismissing || delta != Surface.ROTATION_0)) { |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 390 | if (DEBUG_STATE) Slog.v(TAG, "Creating start and finish animations"); |
| 391 | firstStart = true; |
| 392 | mStartExitAnimation = AnimationUtils.loadAnimation(mContext, |
| 393 | com.android.internal.R.anim.screen_rotate_start_exit); |
| 394 | mStartEnterAnimation = AnimationUtils.loadAnimation(mContext, |
| 395 | com.android.internal.R.anim.screen_rotate_start_enter); |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 396 | if (USE_CUSTOM_BLACK_FRAME) { |
| 397 | mStartFrameAnimation = AnimationUtils.loadAnimation(mContext, |
| 398 | com.android.internal.R.anim.screen_rotate_start_frame); |
| 399 | } |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 400 | mFinishExitAnimation = AnimationUtils.loadAnimation(mContext, |
| 401 | com.android.internal.R.anim.screen_rotate_finish_exit); |
| 402 | mFinishEnterAnimation = AnimationUtils.loadAnimation(mContext, |
| 403 | com.android.internal.R.anim.screen_rotate_finish_enter); |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 404 | if (USE_CUSTOM_BLACK_FRAME) { |
| 405 | mFinishFrameAnimation = AnimationUtils.loadAnimation(mContext, |
| 406 | com.android.internal.R.anim.screen_rotate_finish_frame); |
| 407 | } |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | if (DEBUG_STATE) Slog.v(TAG, "Rotation delta: " + delta + " finalWidth=" |
| 411 | + finalWidth + " finalHeight=" + finalHeight |
| 412 | + " origWidth=" + mOriginalWidth + " origHeight=" + mOriginalHeight); |
| 413 | |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 414 | final boolean customAnim; |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 415 | if (exitAnim != 0 && enterAnim != 0) { |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 416 | customAnim = true; |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 417 | mRotateExitAnimation = AnimationUtils.loadAnimation(mContext, exitAnim); |
| 418 | mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext, enterAnim); |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 419 | } else { |
| 420 | customAnim = false; |
| 421 | switch (delta) { |
| 422 | case Surface.ROTATION_0: |
| 423 | mRotateExitAnimation = AnimationUtils.loadAnimation(mContext, |
| 424 | com.android.internal.R.anim.screen_rotate_0_exit); |
| 425 | mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext, |
| 426 | com.android.internal.R.anim.screen_rotate_0_enter); |
| 427 | if (USE_CUSTOM_BLACK_FRAME) { |
| 428 | mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext, |
| 429 | com.android.internal.R.anim.screen_rotate_0_frame); |
| 430 | } |
| 431 | break; |
| 432 | case Surface.ROTATION_90: |
| 433 | mRotateExitAnimation = AnimationUtils.loadAnimation(mContext, |
| 434 | com.android.internal.R.anim.screen_rotate_plus_90_exit); |
| 435 | mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext, |
| 436 | com.android.internal.R.anim.screen_rotate_plus_90_enter); |
| 437 | if (USE_CUSTOM_BLACK_FRAME) { |
| 438 | mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext, |
| 439 | com.android.internal.R.anim.screen_rotate_plus_90_frame); |
| 440 | } |
| 441 | break; |
| 442 | case Surface.ROTATION_180: |
| 443 | mRotateExitAnimation = AnimationUtils.loadAnimation(mContext, |
| 444 | com.android.internal.R.anim.screen_rotate_180_exit); |
| 445 | mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext, |
| 446 | com.android.internal.R.anim.screen_rotate_180_enter); |
| 447 | if (USE_CUSTOM_BLACK_FRAME) { |
| 448 | mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext, |
| 449 | com.android.internal.R.anim.screen_rotate_180_frame); |
| 450 | } |
| 451 | break; |
| 452 | case Surface.ROTATION_270: |
| 453 | mRotateExitAnimation = AnimationUtils.loadAnimation(mContext, |
| 454 | com.android.internal.R.anim.screen_rotate_minus_90_exit); |
| 455 | mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext, |
| 456 | com.android.internal.R.anim.screen_rotate_minus_90_enter); |
| 457 | if (USE_CUSTOM_BLACK_FRAME) { |
| 458 | mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext, |
| 459 | com.android.internal.R.anim.screen_rotate_minus_90_frame); |
| 460 | } |
| 461 | break; |
| 462 | } |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 463 | } |
| 464 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 465 | // Initialize the animations. This is a hack, redefining what "parent" |
| 466 | // means to allow supplying the last and next size. In this definition |
| 467 | // "%p" is the original (let's call it "previous") size, and "%" is the |
| 468 | // screen's current/new size. |
Dianne Hackborn | 187ae210 | 2012-04-11 18:12:06 -0700 | [diff] [blame] | 469 | if (TWO_PHASE_ANIMATION && firstStart) { |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 470 | // Compute partial steps between original and final sizes. These |
| 471 | // are used for the dimensions of the exiting and entering elements, |
| 472 | // so they are never stretched too significantly. |
| 473 | final int halfWidth = (finalWidth + mOriginalWidth) / 2; |
| 474 | final int halfHeight = (finalHeight + mOriginalHeight) / 2; |
| 475 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 476 | if (DEBUG_STATE) Slog.v(TAG, "Initializing start and finish animations"); |
| 477 | mStartEnterAnimation.initialize(finalWidth, finalHeight, |
Dianne Hackborn | 191874e3 | 2012-03-09 11:03:36 -0800 | [diff] [blame] | 478 | halfWidth, halfHeight); |
| 479 | mStartExitAnimation.initialize(halfWidth, halfHeight, |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 480 | mOriginalWidth, mOriginalHeight); |
| 481 | mFinishEnterAnimation.initialize(finalWidth, finalHeight, |
Dianne Hackborn | 191874e3 | 2012-03-09 11:03:36 -0800 | [diff] [blame] | 482 | halfWidth, halfHeight); |
| 483 | mFinishExitAnimation.initialize(halfWidth, halfHeight, |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 484 | mOriginalWidth, mOriginalHeight); |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 485 | if (USE_CUSTOM_BLACK_FRAME) { |
| 486 | mStartFrameAnimation.initialize(finalWidth, finalHeight, |
| 487 | mOriginalWidth, mOriginalHeight); |
| 488 | mFinishFrameAnimation.initialize(finalWidth, finalHeight, |
| 489 | mOriginalWidth, mOriginalHeight); |
| 490 | } |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 491 | } |
| 492 | mRotateEnterAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight); |
| 493 | mRotateExitAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight); |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 494 | if (USE_CUSTOM_BLACK_FRAME) { |
| 495 | mRotateFrameAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, |
| 496 | mOriginalHeight); |
| 497 | } |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 498 | mAnimRunning = false; |
| 499 | mFinishAnimReady = false; |
| 500 | mFinishAnimStartTime = -1; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 501 | |
Dianne Hackborn | 187ae210 | 2012-04-11 18:12:06 -0700 | [diff] [blame] | 502 | if (TWO_PHASE_ANIMATION && firstStart) { |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 503 | mStartExitAnimation.restrictDuration(maxAnimationDuration); |
| 504 | mStartExitAnimation.scaleCurrentDuration(animationScale); |
| 505 | mStartEnterAnimation.restrictDuration(maxAnimationDuration); |
| 506 | mStartEnterAnimation.scaleCurrentDuration(animationScale); |
| 507 | mFinishExitAnimation.restrictDuration(maxAnimationDuration); |
| 508 | mFinishExitAnimation.scaleCurrentDuration(animationScale); |
| 509 | mFinishEnterAnimation.restrictDuration(maxAnimationDuration); |
| 510 | mFinishEnterAnimation.scaleCurrentDuration(animationScale); |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 511 | if (USE_CUSTOM_BLACK_FRAME) { |
| 512 | mStartFrameAnimation.restrictDuration(maxAnimationDuration); |
| 513 | mStartFrameAnimation.scaleCurrentDuration(animationScale); |
| 514 | mFinishFrameAnimation.restrictDuration(maxAnimationDuration); |
| 515 | mFinishFrameAnimation.scaleCurrentDuration(animationScale); |
| 516 | } |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 517 | } |
| 518 | mRotateExitAnimation.restrictDuration(maxAnimationDuration); |
| 519 | mRotateExitAnimation.scaleCurrentDuration(animationScale); |
| 520 | mRotateEnterAnimation.restrictDuration(maxAnimationDuration); |
| 521 | mRotateEnterAnimation.scaleCurrentDuration(animationScale); |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 522 | if (USE_CUSTOM_BLACK_FRAME) { |
| 523 | mRotateFrameAnimation.restrictDuration(maxAnimationDuration); |
| 524 | mRotateFrameAnimation.scaleCurrentDuration(animationScale); |
| 525 | } |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 526 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 527 | final int layerStack = mDisplayContent.getDisplay().getLayerStack(); |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 528 | if (USE_CUSTOM_BLACK_FRAME && mCustomBlackFrame == null) { |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 529 | // Compute the transformation matrix that must be applied |
| 530 | // the the black frame to make it stay in the initial position |
| 531 | // before the new screen rotation. This is different than the |
| 532 | // snapshot transformation because the snapshot is always based |
| 533 | // of the native orientation of the screen, not the orientation |
| 534 | // we were last in. |
| 535 | createRotationMatrix(delta, mOriginalWidth, mOriginalHeight, mFrameInitialMatrix); |
| 536 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 537 | try { |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 538 | Rect outer = new Rect(-mOriginalWidth*1, -mOriginalHeight*1, |
| 539 | mOriginalWidth*2, mOriginalHeight*2); |
| 540 | Rect inner = new Rect(0, 0, mOriginalWidth, mOriginalHeight); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 541 | mCustomBlackFrame = new BlackFrame(t, outer, inner, |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 542 | SCREEN_FREEZE_LAYER_CUSTOM, mDisplayContent, false); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 543 | mCustomBlackFrame.setMatrix(t, mFrameInitialMatrix); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 544 | } catch (OutOfResourcesException e) { |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 545 | Slog.w(TAG, "Unable to allocate black surface", e); |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 546 | } |
| 547 | } |
| 548 | |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 549 | if (!customAnim && mExitingBlackFrame == null) { |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 550 | try { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 551 | // Compute the transformation matrix that must be applied |
| 552 | // the the black frame to make it stay in the initial position |
| 553 | // before the new screen rotation. This is different than the |
| 554 | // snapshot transformation because the snapshot is always based |
| 555 | // of the native orientation of the screen, not the orientation |
| 556 | // we were last in. |
| 557 | createRotationMatrix(delta, mOriginalWidth, mOriginalHeight, mFrameInitialMatrix); |
| 558 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 559 | final Rect outer; |
| 560 | final Rect inner; |
| 561 | if (mForceDefaultOrientation) { |
| 562 | // Going from a smaller Display to a larger Display, add curtains to sides |
| 563 | // or top and bottom. Going from a larger to smaller display will result in |
| 564 | // no BlackSurfaces being constructed. |
| 565 | outer = mCurrentDisplayRect; |
| 566 | inner = mOriginalDisplayRect; |
| 567 | } else { |
| 568 | outer = new Rect(-mOriginalWidth*1, -mOriginalHeight*1, |
| 569 | mOriginalWidth*2, mOriginalHeight*2); |
| 570 | inner = new Rect(0, 0, mOriginalWidth, mOriginalHeight); |
| 571 | } |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 572 | mExitingBlackFrame = new BlackFrame(t, outer, inner, |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 573 | SCREEN_FREEZE_LAYER_EXIT, mDisplayContent, mForceDefaultOrientation); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 574 | mExitingBlackFrame.setMatrix(t, mFrameInitialMatrix); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 575 | } catch (OutOfResourcesException e) { |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 576 | Slog.w(TAG, "Unable to allocate black surface", e); |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | |
Dianne Hackborn | 9d9ece3 | 2012-09-10 15:33:52 -0700 | [diff] [blame] | 580 | if (customAnim && mEnteringBlackFrame == null) { |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 581 | try { |
| 582 | Rect outer = new Rect(-finalWidth*1, -finalHeight*1, |
| 583 | finalWidth*2, finalHeight*2); |
| 584 | Rect inner = new Rect(0, 0, finalWidth, finalHeight); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 585 | mEnteringBlackFrame = new BlackFrame(t, outer, inner, |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 586 | SCREEN_FREEZE_LAYER_ENTER, mDisplayContent, false); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 587 | } catch (OutOfResourcesException e) { |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 588 | Slog.w(TAG, "Unable to allocate black surface", e); |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 589 | } |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 590 | } |
| 591 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 592 | return true; |
| 593 | } |
| 594 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 595 | /** |
| 596 | * Returns true if animating. |
| 597 | */ |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 598 | public boolean dismiss(SurfaceControl.Transaction t, long maxAnimationDuration, |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 599 | float animationScale, int finalWidth, int finalHeight, int exitAnim, int enterAnim) { |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 600 | if (DEBUG_STATE) Slog.v(TAG, "Dismiss!"); |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 601 | if (mSurfaceControl == null) { |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 602 | // Can't do animation. |
| 603 | return false; |
| 604 | } |
| 605 | if (!mStarted) { |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 606 | startAnimation(t, maxAnimationDuration, animationScale, finalWidth, finalHeight, |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 607 | true, exitAnim, enterAnim); |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 608 | } |
| 609 | if (!mStarted) { |
| 610 | return false; |
| 611 | } |
| 612 | if (DEBUG_STATE) Slog.v(TAG, "Setting mFinishAnimReady = true"); |
| 613 | mFinishAnimReady = true; |
| 614 | return true; |
| 615 | } |
| 616 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 617 | public void kill() { |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 618 | if (DEBUG_STATE) Slog.v(TAG, "Kill!"); |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 619 | if (mSurfaceControl != null) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 620 | if (SHOW_TRANSACTIONS || |
| 621 | SHOW_SURFACE_ALLOC) Slog.i(TAG_WM, |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 622 | " FREEZE " + mSurfaceControl + ": DESTROY"); |
| 623 | mSurfaceControl.destroy(); |
| 624 | mSurfaceControl = null; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 625 | } |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 626 | if (mCustomBlackFrame != null) { |
| 627 | mCustomBlackFrame.kill(); |
| 628 | mCustomBlackFrame = null; |
| 629 | } |
| 630 | if (mExitingBlackFrame != null) { |
| 631 | mExitingBlackFrame.kill(); |
| 632 | mExitingBlackFrame = null; |
| 633 | } |
| 634 | if (mEnteringBlackFrame != null) { |
| 635 | mEnteringBlackFrame.kill(); |
| 636 | mEnteringBlackFrame = null; |
Dianne Hackborn | 352cc98 | 2011-01-04 11:34:18 -0800 | [diff] [blame] | 637 | } |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 638 | if (TWO_PHASE_ANIMATION) { |
| 639 | if (mStartExitAnimation != null) { |
| 640 | mStartExitAnimation.cancel(); |
| 641 | mStartExitAnimation = null; |
| 642 | } |
| 643 | if (mStartEnterAnimation != null) { |
| 644 | mStartEnterAnimation.cancel(); |
| 645 | mStartEnterAnimation = null; |
| 646 | } |
| 647 | if (mFinishExitAnimation != null) { |
| 648 | mFinishExitAnimation.cancel(); |
| 649 | mFinishExitAnimation = null; |
| 650 | } |
| 651 | if (mFinishEnterAnimation != null) { |
| 652 | mFinishEnterAnimation.cancel(); |
| 653 | mFinishEnterAnimation = null; |
| 654 | } |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 655 | } |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 656 | if (USE_CUSTOM_BLACK_FRAME) { |
| 657 | if (mStartFrameAnimation != null) { |
| 658 | mStartFrameAnimation.cancel(); |
| 659 | mStartFrameAnimation = null; |
| 660 | } |
| 661 | if (mRotateFrameAnimation != null) { |
| 662 | mRotateFrameAnimation.cancel(); |
| 663 | mRotateFrameAnimation = null; |
| 664 | } |
| 665 | if (mFinishFrameAnimation != null) { |
| 666 | mFinishFrameAnimation.cancel(); |
| 667 | mFinishFrameAnimation = null; |
| 668 | } |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 669 | } |
| 670 | if (mRotateExitAnimation != null) { |
| 671 | mRotateExitAnimation.cancel(); |
| 672 | mRotateExitAnimation = null; |
| 673 | } |
| 674 | if (mRotateEnterAnimation != null) { |
| 675 | mRotateEnterAnimation.cancel(); |
| 676 | mRotateEnterAnimation = null; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | |
| 680 | public boolean isAnimating() { |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 681 | return hasAnimations() || (TWO_PHASE_ANIMATION && mFinishAnimReady); |
Dianne Hackborn | 187ae210 | 2012-04-11 18:12:06 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Dianne Hackborn | 4b16969 | 2012-11-29 17:51:24 -0800 | [diff] [blame] | 684 | public boolean isRotating() { |
| 685 | return mCurRotation != mOriginalRotation; |
| 686 | } |
| 687 | |
Dianne Hackborn | 187ae210 | 2012-04-11 18:12:06 -0700 | [diff] [blame] | 688 | private boolean hasAnimations() { |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 689 | return (TWO_PHASE_ANIMATION && |
| 690 | (mStartEnterAnimation != null || mStartExitAnimation != null |
| 691 | || mFinishEnterAnimation != null || mFinishExitAnimation != null)) |
| 692 | || (USE_CUSTOM_BLACK_FRAME && |
| 693 | (mStartFrameAnimation != null || mRotateFrameAnimation != null |
| 694 | || mFinishFrameAnimation != null)) |
| 695 | || mRotateEnterAnimation != null || mRotateExitAnimation != null; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 696 | } |
| 697 | |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 698 | private boolean stepAnimation(long now) { |
Craig Mautner | 3255a28 | 2012-04-16 15:42:47 -0700 | [diff] [blame] | 699 | if (now > mHalfwayPoint) { |
| 700 | mHalfwayPoint = Long.MAX_VALUE; |
| 701 | } |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 702 | if (mFinishAnimReady && mFinishAnimStartTime < 0) { |
| 703 | if (DEBUG_STATE) Slog.v(TAG, "Step: finish anim now ready"); |
| 704 | mFinishAnimStartTime = now; |
| 705 | } |
| 706 | |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 707 | if (TWO_PHASE_ANIMATION) { |
| 708 | mMoreStartExit = false; |
| 709 | if (mStartExitAnimation != null) { |
| 710 | mMoreStartExit = mStartExitAnimation.getTransformation(now, mStartExitTransformation); |
| 711 | if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start exit: " + mStartExitTransformation); |
| 712 | } |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 713 | |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 714 | mMoreStartEnter = false; |
| 715 | if (mStartEnterAnimation != null) { |
| 716 | mMoreStartEnter = mStartEnterAnimation.getTransformation(now, mStartEnterTransformation); |
| 717 | if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start enter: " + mStartEnterTransformation); |
| 718 | } |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 719 | } |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 720 | if (USE_CUSTOM_BLACK_FRAME) { |
| 721 | mMoreStartFrame = false; |
| 722 | if (mStartFrameAnimation != null) { |
| 723 | mMoreStartFrame = mStartFrameAnimation.getTransformation(now, mStartFrameTransformation); |
| 724 | if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start frame: " + mStartFrameTransformation); |
| 725 | } |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 726 | } |
| 727 | |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 728 | long finishNow = mFinishAnimReady ? (now - mFinishAnimStartTime) : 0; |
| 729 | if (DEBUG_STATE) Slog.v(TAG, "Step: finishNow=" + finishNow); |
| 730 | |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 731 | if (TWO_PHASE_ANIMATION) { |
| 732 | mMoreFinishExit = false; |
| 733 | if (mFinishExitAnimation != null) { |
| 734 | mMoreFinishExit = mFinishExitAnimation.getTransformation(finishNow, mFinishExitTransformation); |
| 735 | if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish exit: " + mFinishExitTransformation); |
| 736 | } |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 737 | |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 738 | mMoreFinishEnter = false; |
| 739 | if (mFinishEnterAnimation != null) { |
| 740 | mMoreFinishEnter = mFinishEnterAnimation.getTransformation(finishNow, mFinishEnterTransformation); |
| 741 | if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish enter: " + mFinishEnterTransformation); |
| 742 | } |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 743 | } |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 744 | if (USE_CUSTOM_BLACK_FRAME) { |
| 745 | mMoreFinishFrame = false; |
| 746 | if (mFinishFrameAnimation != null) { |
| 747 | mMoreFinishFrame = mFinishFrameAnimation.getTransformation(finishNow, mFinishFrameTransformation); |
| 748 | if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish frame: " + mFinishFrameTransformation); |
| 749 | } |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 750 | } |
| 751 | |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 752 | mMoreRotateExit = false; |
| 753 | if (mRotateExitAnimation != null) { |
| 754 | mMoreRotateExit = mRotateExitAnimation.getTransformation(now, mRotateExitTransformation); |
| 755 | if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate exit: " + mRotateExitTransformation); |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | mMoreRotateEnter = false; |
| 759 | if (mRotateEnterAnimation != null) { |
| 760 | mMoreRotateEnter = mRotateEnterAnimation.getTransformation(now, mRotateEnterTransformation); |
| 761 | if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate enter: " + mRotateEnterTransformation); |
| 762 | } |
| 763 | |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 764 | if (USE_CUSTOM_BLACK_FRAME) { |
| 765 | mMoreRotateFrame = false; |
| 766 | if (mRotateFrameAnimation != null) { |
| 767 | mMoreRotateFrame = mRotateFrameAnimation.getTransformation(now, mRotateFrameTransformation); |
| 768 | if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate frame: " + mRotateFrameTransformation); |
| 769 | } |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 770 | } |
| 771 | |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 772 | if (!mMoreRotateExit && (!TWO_PHASE_ANIMATION || (!mMoreStartExit && !mMoreFinishExit))) { |
| 773 | if (TWO_PHASE_ANIMATION) { |
| 774 | if (mStartExitAnimation != null) { |
| 775 | if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, clearing start exit anim!"); |
| 776 | mStartExitAnimation.cancel(); |
| 777 | mStartExitAnimation = null; |
| 778 | mStartExitTransformation.clear(); |
| 779 | } |
| 780 | if (mFinishExitAnimation != null) { |
| 781 | if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, clearing finish exit anim!"); |
| 782 | mFinishExitAnimation.cancel(); |
| 783 | mFinishExitAnimation = null; |
| 784 | mFinishExitTransformation.clear(); |
| 785 | } |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 786 | } |
| 787 | if (mRotateExitAnimation != null) { |
| 788 | if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, clearing rotate exit anim!"); |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 789 | mRotateExitAnimation.cancel(); |
| 790 | mRotateExitAnimation = null; |
| 791 | mRotateExitTransformation.clear(); |
| 792 | } |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 793 | } |
| 794 | |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 795 | if (!mMoreRotateEnter && (!TWO_PHASE_ANIMATION || (!mMoreStartEnter && !mMoreFinishEnter))) { |
| 796 | if (TWO_PHASE_ANIMATION) { |
| 797 | if (mStartEnterAnimation != null) { |
| 798 | if (DEBUG_STATE) Slog.v(TAG, "Enter animations done, clearing start enter anim!"); |
| 799 | mStartEnterAnimation.cancel(); |
| 800 | mStartEnterAnimation = null; |
| 801 | mStartEnterTransformation.clear(); |
| 802 | } |
| 803 | if (mFinishEnterAnimation != null) { |
| 804 | if (DEBUG_STATE) Slog.v(TAG, "Enter animations done, clearing finish enter anim!"); |
| 805 | mFinishEnterAnimation.cancel(); |
| 806 | mFinishEnterAnimation = null; |
| 807 | mFinishEnterTransformation.clear(); |
| 808 | } |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 809 | } |
| 810 | if (mRotateEnterAnimation != null) { |
| 811 | if (DEBUG_STATE) Slog.v(TAG, "Enter animations done, clearing rotate enter anim!"); |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 812 | mRotateEnterAnimation.cancel(); |
| 813 | mRotateEnterAnimation = null; |
| 814 | mRotateEnterTransformation.clear(); |
| 815 | } |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 816 | } |
| 817 | |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 818 | if (USE_CUSTOM_BLACK_FRAME && !mMoreStartFrame && !mMoreRotateFrame && !mMoreFinishFrame) { |
| 819 | if (mStartFrameAnimation != null) { |
| 820 | if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, clearing start frame anim!"); |
| 821 | mStartFrameAnimation.cancel(); |
| 822 | mStartFrameAnimation = null; |
| 823 | mStartFrameTransformation.clear(); |
| 824 | } |
| 825 | if (mFinishFrameAnimation != null) { |
| 826 | if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, clearing finish frame anim!"); |
| 827 | mFinishFrameAnimation.cancel(); |
| 828 | mFinishFrameAnimation = null; |
| 829 | mFinishFrameTransformation.clear(); |
| 830 | } |
| 831 | if (mRotateFrameAnimation != null) { |
| 832 | if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, clearing rotate frame anim!"); |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 833 | mRotateFrameAnimation.cancel(); |
| 834 | mRotateFrameAnimation = null; |
| 835 | mRotateFrameTransformation.clear(); |
| 836 | } |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | mExitTransformation.set(mRotateExitTransformation); |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 840 | mEnterTransformation.set(mRotateEnterTransformation); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 841 | if (TWO_PHASE_ANIMATION) { |
| 842 | mExitTransformation.compose(mStartExitTransformation); |
| 843 | mExitTransformation.compose(mFinishExitTransformation); |
| 844 | |
| 845 | mEnterTransformation.compose(mStartEnterTransformation); |
| 846 | mEnterTransformation.compose(mFinishEnterTransformation); |
| 847 | } |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 848 | |
| 849 | if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final exit: " + mExitTransformation); |
| 850 | if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final enter: " + mEnterTransformation); |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 851 | |
| 852 | if (USE_CUSTOM_BLACK_FRAME) { |
| 853 | //mFrameTransformation.set(mRotateExitTransformation); |
| 854 | //mFrameTransformation.compose(mStartExitTransformation); |
| 855 | //mFrameTransformation.compose(mFinishExitTransformation); |
| 856 | mFrameTransformation.set(mRotateFrameTransformation); |
| 857 | mFrameTransformation.compose(mStartFrameTransformation); |
| 858 | mFrameTransformation.compose(mFinishFrameTransformation); |
| 859 | mFrameTransformation.getMatrix().preConcat(mFrameInitialMatrix); |
| 860 | if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final frame: " + mFrameTransformation); |
| 861 | } |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 862 | |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 863 | final boolean more = (TWO_PHASE_ANIMATION |
| 864 | && (mMoreStartEnter || mMoreStartExit || mMoreFinishEnter || mMoreFinishExit)) |
| 865 | || (USE_CUSTOM_BLACK_FRAME |
| 866 | && (mMoreStartFrame || mMoreRotateFrame || mMoreFinishFrame)) |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 867 | || mMoreRotateEnter || mMoreRotateExit |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 868 | || !mFinishAnimReady; |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 869 | |
| 870 | mSnapshotFinalMatrix.setConcat(mExitTransformation.getMatrix(), mSnapshotInitialMatrix); |
| 871 | |
| 872 | if (DEBUG_STATE) Slog.v(TAG, "Step: more=" + more); |
| 873 | |
| 874 | return more; |
| 875 | } |
| 876 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 877 | void updateSurfaces(SurfaceControl.Transaction t) { |
Dianne Hackborn | 187ae210 | 2012-04-11 18:12:06 -0700 | [diff] [blame] | 878 | if (!mStarted) { |
| 879 | return; |
| 880 | } |
| 881 | |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 882 | if (mSurfaceControl != null) { |
Craig Mautner | bf90eaa | 2012-03-15 11:28:53 -0700 | [diff] [blame] | 883 | if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) { |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 884 | if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, hiding screenshot surface"); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 885 | t.hide(mSurfaceControl); |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 886 | } |
| 887 | } |
| 888 | |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 889 | if (mCustomBlackFrame != null) { |
Craig Mautner | bf90eaa | 2012-03-15 11:28:53 -0700 | [diff] [blame] | 890 | if (!mMoreStartFrame && !mMoreFinishFrame && !mMoreRotateFrame) { |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 891 | if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding black frame"); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 892 | mCustomBlackFrame.hide(t); |
Craig Mautner | bf90eaa | 2012-03-15 11:28:53 -0700 | [diff] [blame] | 893 | } else { |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 894 | mCustomBlackFrame.setMatrix(t, mFrameTransformation.getMatrix()); |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 895 | } |
| 896 | } |
| 897 | |
| 898 | if (mExitingBlackFrame != null) { |
| 899 | if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) { |
| 900 | if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding exiting frame"); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 901 | mExitingBlackFrame.hide(t); |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 902 | } else { |
| 903 | mExitFrameFinalMatrix.setConcat(mExitTransformation.getMatrix(), mFrameInitialMatrix); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 904 | mExitingBlackFrame.setMatrix(t, mExitFrameFinalMatrix); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 905 | if (mForceDefaultOrientation) { |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 906 | mExitingBlackFrame.setAlpha(t, mExitTransformation.getAlpha()); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 907 | } |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 908 | } |
| 909 | } |
| 910 | |
| 911 | if (mEnteringBlackFrame != null) { |
| 912 | if (!mMoreStartEnter && !mMoreFinishEnter && !mMoreRotateEnter) { |
| 913 | if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding entering frame"); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 914 | mEnteringBlackFrame.hide(t); |
Dianne Hackborn | d6b32b6 | 2012-03-16 11:54:51 -0700 | [diff] [blame] | 915 | } else { |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 916 | mEnteringBlackFrame.setMatrix(t, mEnterTransformation.getMatrix()); |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 917 | } |
| 918 | } |
| 919 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame^] | 920 | setSnapshotTransform(t, mSnapshotFinalMatrix, mExitTransformation.getAlpha()); |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 921 | } |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 922 | |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 923 | public boolean stepAnimationLocked(long now) { |
Dianne Hackborn | 187ae210 | 2012-04-11 18:12:06 -0700 | [diff] [blame] | 924 | if (!hasAnimations()) { |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 925 | if (DEBUG_STATE) Slog.v(TAG, "Step: no animations running"); |
Craig Mautner | a731cd3 | 2012-03-02 15:23:55 -0800 | [diff] [blame] | 926 | mFinishAnimReady = false; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 927 | return false; |
| 928 | } |
| 929 | |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 930 | if (!mAnimRunning) { |
| 931 | if (DEBUG_STATE) Slog.v(TAG, "Step: starting start, finish, rotate"); |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 932 | if (TWO_PHASE_ANIMATION) { |
| 933 | if (mStartEnterAnimation != null) { |
| 934 | mStartEnterAnimation.setStartTime(now); |
| 935 | } |
| 936 | if (mStartExitAnimation != null) { |
| 937 | mStartExitAnimation.setStartTime(now); |
| 938 | } |
| 939 | if (mFinishEnterAnimation != null) { |
| 940 | mFinishEnterAnimation.setStartTime(0); |
| 941 | } |
| 942 | if (mFinishExitAnimation != null) { |
| 943 | mFinishExitAnimation.setStartTime(0); |
| 944 | } |
Dianne Hackborn | 8962028 | 2011-09-11 12:47:45 -0700 | [diff] [blame] | 945 | } |
Craig Mautner | 7d8df39 | 2012-04-06 15:26:23 -0700 | [diff] [blame] | 946 | if (USE_CUSTOM_BLACK_FRAME) { |
| 947 | if (mStartFrameAnimation != null) { |
| 948 | mStartFrameAnimation.setStartTime(now); |
| 949 | } |
| 950 | if (mFinishFrameAnimation != null) { |
| 951 | mFinishFrameAnimation.setStartTime(0); |
| 952 | } |
| 953 | if (mRotateFrameAnimation != null) { |
| 954 | mRotateFrameAnimation.setStartTime(now); |
| 955 | } |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 956 | } |
Dianne Hackborn | fd1c5ed | 2012-01-13 13:09:16 -0800 | [diff] [blame] | 957 | if (mRotateEnterAnimation != null) { |
| 958 | mRotateEnterAnimation.setStartTime(now); |
| 959 | } |
| 960 | if (mRotateExitAnimation != null) { |
| 961 | mRotateExitAnimation.setStartTime(now); |
| 962 | } |
| 963 | mAnimRunning = true; |
Craig Mautner | 3255a28 | 2012-04-16 15:42:47 -0700 | [diff] [blame] | 964 | mHalfwayPoint = now + mRotateEnterAnimation.getDuration() / 2; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 965 | } |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 966 | |
| 967 | return stepAnimation(now); |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | public Transformation getEnterTransformation() { |
| 971 | return mEnterTransformation; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 972 | } |
| 973 | } |