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