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