blob: 283d49815049e0a53ce4cd5c3be43b6c90106edb [file] [log] [blame]
Dianne Hackborna1111872010-11-23 20:55:11 -08001/*
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 Hackborn6e1eb762011-02-17 16:07:28 -080017package com.android.server.wm;
Dianne Hackborna1111872010-11-23 20:55:11 -080018
Dianne Hackborn4dcece82012-02-10 14:50:32 -080019import java.io.PrintWriter;
20
Chong Zhang97782b42015-10-07 16:01:23 -070021import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
Craig Mautner7d8df392012-04-06 15:26:23 -070022import static com.android.server.wm.WindowStateAnimator.SurfaceTrace;
Chong Zhang97782b42015-10-07 16:01:23 -070023import static com.android.server.wm.WindowStateAnimator.WINDOW_FREEZE_LAYER;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080024import android.content.Context;
Dianne Hackborna1111872010-11-23 20:55:11 -080025import android.graphics.Matrix;
Dianne Hackborna1111872010-11-23 20:55:11 -080026import android.graphics.PixelFormat;
27import android.graphics.Rect;
Dianne Hackborna1111872010-11-23 20:55:11 -080028import android.util.Slog;
Craig Mautner6881a102012-07-27 13:04:51 -070029import android.view.Display;
Craig Mautner46ac6fa2013-08-01 10:06:34 -070030import android.view.DisplayInfo;
Igor Murashkina86ab6402013-08-30 12:58:36 -070031import android.view.Surface.OutOfResourcesException;
Dianne Hackborna1111872010-11-23 20:55:11 -080032import android.view.Surface;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080033import android.view.SurfaceControl;
Dianne Hackborna1111872010-11-23 20:55:11 -080034import android.view.SurfaceSession;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080035import android.view.animation.Animation;
36import android.view.animation.AnimationUtils;
37import android.view.animation.Transformation;
Dianne Hackborna1111872010-11-23 20:55:11 -080038
Craig Mautnere32c3072012-03-12 15:25:35 -070039class ScreenRotationAnimation {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080040 static final String TAG = "ScreenRotationAnimation";
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080041 static final boolean DEBUG_STATE = false;
42 static final boolean DEBUG_TRANSFORMS = false;
Dianne Hackborn187ae2102012-04-11 18:12:06 -070043 static final boolean TWO_PHASE_ANIMATION = false;
Dianne Hackbornd6b32b62012-03-16 11:54:51 -070044 static final boolean USE_CUSTOM_BLACK_FRAME = false;
Dianne Hackborna1111872010-11-23 20:55:11 -080045
Chong Zhang97782b42015-10-07 16:01:23 -070046 /*
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 Hackborn50660e22011-02-02 17:12:25 -080055
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080056 final Context mContext;
Craig Mautner46ac6fa2013-08-01 10:06:34 -070057 final DisplayContent mDisplayContent;
Mathias Agopian29479eb2013-02-14 14:36:04 -080058 SurfaceControl mSurfaceControl;
Dianne Hackbornd6b32b62012-03-16 11:54:51 -070059 BlackFrame mCustomBlackFrame;
60 BlackFrame mExitingBlackFrame;
61 BlackFrame mEnteringBlackFrame;
Dianne Hackborna1111872010-11-23 20:55:11 -080062 int mWidth, mHeight;
63
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080064 int mOriginalRotation;
65 int mOriginalWidth, mOriginalHeight;
Dianne Hackborna1111872010-11-23 20:55:11 -080066 int mCurRotation;
Craig Mautner46ac6fa2013-08-01 10:06:34 -070067 Rect mOriginalDisplayRect = new Rect();
68 Rect mCurrentDisplayRect = new Rect();
Dianne Hackborna1111872010-11-23 20:55:11 -080069
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080070 // 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 Hackborn9fd74802012-03-01 19:26:31 -080082 Animation mStartFrameAnimation;
83 final Transformation mStartFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080084
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 Hackborn9fd74802012-03-01 19:26:31 -080093 Animation mFinishFrameAnimation;
94 final Transformation mFinishFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080095
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 Hackborn9fd74802012-03-01 19:26:31 -0800103 Animation mRotateFrameAnimation;
104 final Transformation mRotateFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800105
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 Hackborn9fd74802012-03-01 19:26:31 -0800112 Animation mLastRotateFrameAnimation;
113 final Transformation mLastRotateFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800114
115 // Complete transformations being applied.
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800116 final Transformation mExitTransformation = new Transformation();
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800117 final Transformation mEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800118 final Transformation mFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800119
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800120 boolean mStarted;
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800121 boolean mAnimRunning;
122 boolean mFinishAnimReady;
123 long mFinishAnimStartTime;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700124 boolean mForceDefaultOrientation;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800125
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800126 final Matrix mFrameInitialMatrix = new Matrix();
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800127 final Matrix mSnapshotInitialMatrix = new Matrix();
128 final Matrix mSnapshotFinalMatrix = new Matrix();
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700129 final Matrix mExitFrameFinalMatrix = new Matrix();
Dianne Hackborn50660e22011-02-02 17:12:25 -0800130 final Matrix mTmpMatrix = new Matrix();
Dianne Hackborna1111872010-11-23 20:55:11 -0800131 final float[] mTmpFloats = new float[9];
Craig Mautnerdbb79912012-03-01 18:59:14 -0800132 private boolean mMoreRotateEnter;
133 private boolean mMoreRotateExit;
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800134 private boolean mMoreRotateFrame;
Craig Mautnerdbb79912012-03-01 18:59:14 -0800135 private boolean mMoreFinishEnter;
136 private boolean mMoreFinishExit;
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800137 private boolean mMoreFinishFrame;
Craig Mautnerdbb79912012-03-01 18:59:14 -0800138 private boolean mMoreStartEnter;
139 private boolean mMoreStartExit;
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800140 private boolean mMoreStartFrame;
Craig Mautner3255a282012-04-16 15:42:47 -0700141 long mHalfwayPoint;
Dianne Hackborna1111872010-11-23 20:55:11 -0800142
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800143 public void printTo(String prefix, PrintWriter pw) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800144 pw.print(prefix); pw.print("mSurface="); pw.print(mSurfaceControl);
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800145 pw.print(" mWidth="); pw.print(mWidth);
146 pw.print(" mHeight="); pw.println(mHeight);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700147 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 Hackborn9fd74802012-03-01 19:26:31 -0800160 }
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700161 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 Hackborn4dcece82012-02-10 14:50:32 -0800164 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 Hackborn9fd74802012-03-01 19:26:31 -0800173 pw.print(prefix); pw.print("mStartFrameAnimation="); pw.print(mStartFrameAnimation);
174 pw.print(" "); mStartFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800175 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 Hackborn9fd74802012-03-01 19:26:31 -0800179 pw.print(prefix); pw.print("mFinishFrameAnimation="); pw.print(mFinishFrameAnimation);
180 pw.print(" "); mFinishFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800181 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 Hackborn9fd74802012-03-01 19:26:31 -0800185 pw.print(prefix); pw.print("mRotateFrameAnimation="); pw.print(mRotateFrameAnimation);
186 pw.print(" "); mRotateFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800187 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 Hackborn9fd74802012-03-01 19:26:31 -0800191 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 Hackborn4dcece82012-02-10 14:50:32 -0800196 pw.print(prefix); pw.print("mSnapshotInitialMatrix=");
197 mSnapshotInitialMatrix.printShortString(pw);
198 pw.print(" mSnapshotFinalMatrix="); mSnapshotFinalMatrix.printShortString(pw);
199 pw.println();
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700200 pw.print(prefix); pw.print("mExitFrameFinalMatrix=");
201 mExitFrameFinalMatrix.printShortString(pw);
202 pw.println();
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700203 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 Hackborn4dcece82012-02-10 14:50:32 -0800208 }
209
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700210 public ScreenRotationAnimation(Context context, DisplayContent displayContent,
Minoru Aoi2b74a242014-03-13 12:00:34 +0900211 SurfaceSession session, boolean inTransaction, boolean forceDefaultOrientation,
212 boolean isSecure) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800213 mContext = context;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700214 mDisplayContent = displayContent;
215 displayContent.getLogicalDisplayRect(mOriginalDisplayRect);
Dianne Hackborna1111872010-11-23 20:55:11 -0800216
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800217 // Screenshot does NOT include rotation!
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700218 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 Agopian0ab84ef2011-10-13 16:02:48 -0700233 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 Hackbornde75cb42011-03-02 17:11:21 -0800241
Jeff Brownbc68a592011-07-25 12:58:12 -0700242 mOriginalRotation = originalRotation;
243 mOriginalWidth = originalWidth;
244 mOriginalHeight = originalHeight;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800245
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800246 if (!inTransaction) {
Dianne Hackborn36991742011-10-11 21:35:26 -0700247 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800248 ">>> OPEN TRANSACTION ScreenRotationAnimation");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800249 SurfaceControl.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800250 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700251
Dianne Hackborna1111872010-11-23 20:55:11 -0800252 try {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800253 try {
Minoru Aoi2b74a242014-03-13 12:00:34 +0900254 int flags = SurfaceControl.HIDDEN;
255 if (isSecure) {
256 flags |= SurfaceControl.SECURE;
257 }
258
Craig Mautner7d8df392012-04-06 15:26:23 -0700259 if (WindowManagerService.DEBUG_SURFACE_TRACE) {
Mathias Agopian11e7d882013-03-05 14:14:55 -0800260 mSurfaceControl = new SurfaceTrace(session, "ScreenshotSurface",
Jeff Brown64a55af2012-08-26 02:47:39 -0700261 mWidth, mHeight,
Minoru Aoi2b74a242014-03-13 12:00:34 +0900262 PixelFormat.OPAQUE, flags);
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700263 Slog.w(TAG, "ScreenRotationAnimation ctor: displayOffset="
264 + mOriginalDisplayRect.toShortString());
Craig Mautner7d8df392012-04-06 15:26:23 -0700265 } else {
Mathias Agopian11e7d882013-03-05 14:14:55 -0800266 mSurfaceControl = new SurfaceControl(session, "ScreenshotSurface",
Jeff Brown64a55af2012-08-26 02:47:39 -0700267 mWidth, mHeight,
Minoru Aoi2b74a242014-03-13 12:00:34 +0900268 PixelFormat.OPAQUE, flags);
Mathias Agopian0ab84ef2011-10-13 16:02:48 -0700269 }
Mathias Agopian11e7d882013-03-05 14:14:55 -0800270 // 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 Mautner46ac6fa2013-08-01 10:06:34 -0700276 mSurfaceControl.setLayerStack(display.getLayerStack());
Chong Zhang97782b42015-10-07 16:01:23 -0700277 mSurfaceControl.setLayer(SCREEN_FREEZE_LAYER_SCREENSHOT);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800278 mSurfaceControl.setAlpha(0);
279 mSurfaceControl.show();
Craig Mautnere50d7fc2013-03-18 10:06:21 -0700280 sur.destroy();
Igor Murashkina86ab6402013-08-30 12:58:36 -0700281 } catch (OutOfResourcesException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800282 Slog.w(TAG, "Unable to allocate freeze surface", e);
Dianne Hackborn352cc982011-01-04 11:34:18 -0800283 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800284
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700285 if (WindowManagerService.SHOW_TRANSACTIONS ||
286 WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
Mathias Agopian29479eb2013-02-14 14:36:04 -0800287 " FREEZE " + mSurfaceControl + ": CREATE");
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700288
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700289 setRotationInTransaction(originalRotation);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800290 } finally {
291 if (!inTransaction) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800292 SurfaceControl.closeTransaction();
Dianne Hackborn36991742011-10-11 21:35:26 -0700293 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800294 "<<< CLOSE TRANSACTION ScreenRotationAnimation");
Dianne Hackborn352cc982011-01-04 11:34:18 -0800295 }
Dianne Hackborn0f761d62010-11-30 22:06:10 -0800296 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800297 }
298
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800299 boolean hasScreenshot() {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800300 return mSurfaceControl != null;
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800301 }
302
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700303 private void setSnapshotTransformInTransaction(Matrix matrix, float alpha) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800304 if (mSurfaceControl != null) {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800305 matrix.getValues(mTmpFloats);
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700306 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 Agopian29479eb2013-02-14 14:36:04 -0800314 mSurfaceControl.setMatrix(
Dianne Hackborn352cc982011-01-04 11:34:18 -0800315 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
316 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800317 mSurfaceControl.setAlpha(alpha);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800318 if (DEBUG_TRANSFORMS) {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800319 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 Hackborna1111872010-11-23 20:55:11 -0800327 }
328 }
329
Dianne Hackborn0aae2d42010-12-07 23:51:29 -0800330 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 Hackbornf9d0be92010-11-24 12:35:25 -0800351 // Must be called while in a transaction.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700352 private void setRotationInTransaction(int rotation) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800353 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 Ogunwale4a02d812015-02-12 23:01:38 -0800358 int delta = DisplayContent.deltaRotation(rotation, Surface.ROTATION_0);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -0800359 createRotationMatrix(delta, mWidth, mHeight, mSnapshotInitialMatrix);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800360
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800361 if (DEBUG_STATE) Slog.v(TAG, "**** ROTATION: " + delta);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700362 setSnapshotTransformInTransaction(mSnapshotInitialMatrix, 1.0f);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800363 }
364
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800365 // Must be called while in a transaction.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700366 public boolean setRotationInTransaction(int rotation, SurfaceSession session,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800367 long maxAnimationDuration, float animationScale, int finalWidth, int finalHeight) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700368 setRotationInTransaction(rotation);
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700369 if (TWO_PHASE_ANIMATION) {
370 return startAnimation(session, maxAnimationDuration, animationScale,
Craig Mautner3c174372013-02-21 17:54:37 -0800371 finalWidth, finalHeight, false, 0, 0);
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700372 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700373
374 // Don't start animation yet.
375 return false;
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800376 }
377
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800378 /**
379 * Returns true if animating.
380 */
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800381 private boolean startAnimation(SurfaceSession session, long maxAnimationDuration,
Craig Mautner3c174372013-02-21 17:54:37 -0800382 float animationScale, int finalWidth, int finalHeight, boolean dismissing,
383 int exitAnim, int enterAnim) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800384 if (mSurfaceControl == null) {
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800385 // Can't do animation.
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800386 return false;
387 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800388 if (mStarted) {
389 return true;
390 }
391
392 mStarted = true;
393
394 boolean firstStart = false;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800395
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800396 // Figure out how the screen has moved from the original rotation.
Wale Ogunwale4a02d812015-02-12 23:01:38 -0800397 int delta = DisplayContent.deltaRotation(mCurRotation, mOriginalRotation);
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800398
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700399 if (TWO_PHASE_ANIMATION && mFinishExitAnimation == null
400 && (!dismissing || delta != Surface.ROTATION_0)) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800401 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 Hackbornd6b32b62012-03-16 11:54:51 -0700407 if (USE_CUSTOM_BLACK_FRAME) {
408 mStartFrameAnimation = AnimationUtils.loadAnimation(mContext,
409 com.android.internal.R.anim.screen_rotate_start_frame);
410 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800411 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 Hackbornd6b32b62012-03-16 11:54:51 -0700415 if (USE_CUSTOM_BLACK_FRAME) {
416 mFinishFrameAnimation = AnimationUtils.loadAnimation(mContext,
417 com.android.internal.R.anim.screen_rotate_finish_frame);
418 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800419 }
420
421 if (DEBUG_STATE) Slog.v(TAG, "Rotation delta: " + delta + " finalWidth="
422 + finalWidth + " finalHeight=" + finalHeight
423 + " origWidth=" + mOriginalWidth + " origHeight=" + mOriginalHeight);
424
Dianne Hackborn9d9ece32012-09-10 15:33:52 -0700425 final boolean customAnim;
Craig Mautner3c174372013-02-21 17:54:37 -0800426 if (exitAnim != 0 && enterAnim != 0) {
Dianne Hackborn9d9ece32012-09-10 15:33:52 -0700427 customAnim = true;
Craig Mautner3c174372013-02-21 17:54:37 -0800428 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext, exitAnim);
429 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext, enterAnim);
Dianne Hackborn9d9ece32012-09-10 15:33:52 -0700430 } 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 Hackbornf9d0be92010-11-24 12:35:25 -0800474 }
475
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800476 // 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 Hackborn187ae2102012-04-11 18:12:06 -0700480 if (TWO_PHASE_ANIMATION && firstStart) {
Dianne Hackborn9d9ece32012-09-10 15:33:52 -0700481 // 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 Hackbornfd1c5ed2012-01-13 13:09:16 -0800487 if (DEBUG_STATE) Slog.v(TAG, "Initializing start and finish animations");
488 mStartEnterAnimation.initialize(finalWidth, finalHeight,
Dianne Hackborn191874e32012-03-09 11:03:36 -0800489 halfWidth, halfHeight);
490 mStartExitAnimation.initialize(halfWidth, halfHeight,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800491 mOriginalWidth, mOriginalHeight);
492 mFinishEnterAnimation.initialize(finalWidth, finalHeight,
Dianne Hackborn191874e32012-03-09 11:03:36 -0800493 halfWidth, halfHeight);
494 mFinishExitAnimation.initialize(halfWidth, halfHeight,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800495 mOriginalWidth, mOriginalHeight);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700496 if (USE_CUSTOM_BLACK_FRAME) {
497 mStartFrameAnimation.initialize(finalWidth, finalHeight,
498 mOriginalWidth, mOriginalHeight);
499 mFinishFrameAnimation.initialize(finalWidth, finalHeight,
500 mOriginalWidth, mOriginalHeight);
501 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800502 }
503 mRotateEnterAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
504 mRotateExitAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700505 if (USE_CUSTOM_BLACK_FRAME) {
506 mRotateFrameAnimation.initialize(finalWidth, finalHeight, mOriginalWidth,
507 mOriginalHeight);
508 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800509 mAnimRunning = false;
510 mFinishAnimReady = false;
511 mFinishAnimStartTime = -1;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800512
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700513 if (TWO_PHASE_ANIMATION && firstStart) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800514 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 Hackbornd6b32b62012-03-16 11:54:51 -0700522 if (USE_CUSTOM_BLACK_FRAME) {
523 mStartFrameAnimation.restrictDuration(maxAnimationDuration);
524 mStartFrameAnimation.scaleCurrentDuration(animationScale);
525 mFinishFrameAnimation.restrictDuration(maxAnimationDuration);
526 mFinishFrameAnimation.scaleCurrentDuration(animationScale);
527 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800528 }
529 mRotateExitAnimation.restrictDuration(maxAnimationDuration);
530 mRotateExitAnimation.scaleCurrentDuration(animationScale);
531 mRotateEnterAnimation.restrictDuration(maxAnimationDuration);
532 mRotateEnterAnimation.scaleCurrentDuration(animationScale);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700533 if (USE_CUSTOM_BLACK_FRAME) {
534 mRotateFrameAnimation.restrictDuration(maxAnimationDuration);
535 mRotateFrameAnimation.scaleCurrentDuration(animationScale);
536 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800537
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700538 final int layerStack = mDisplayContent.getDisplay().getLayerStack();
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700539 if (USE_CUSTOM_BLACK_FRAME && mCustomBlackFrame == null) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800540 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
541 WindowManagerService.TAG,
542 ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800543 SurfaceControl.openTransaction();
Dianne Hackborn50660e22011-02-02 17:12:25 -0800544
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800545 // 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 Hackbornfd1c5ed2012-01-13 13:09:16 -0800553 try {
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800554 Rect outer = new Rect(-mOriginalWidth*1, -mOriginalHeight*1,
555 mOriginalWidth*2, mOriginalHeight*2);
556 Rect inner = new Rect(0, 0, mOriginalWidth, mOriginalHeight);
Chong Zhang97782b42015-10-07 16:01:23 -0700557 mCustomBlackFrame = new BlackFrame(session, outer, inner,
558 SCREEN_FREEZE_LAYER_CUSTOM, layerStack, false);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700559 mCustomBlackFrame.setMatrix(mFrameInitialMatrix);
Igor Murashkina86ab6402013-08-30 12:58:36 -0700560 } catch (OutOfResourcesException e) {
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700561 Slog.w(TAG, "Unable to allocate black surface", e);
562 } finally {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800563 SurfaceControl.closeTransaction();
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700564 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
565 WindowManagerService.TAG,
566 "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
567 }
568 }
569
Dianne Hackborn9d9ece32012-09-10 15:33:52 -0700570 if (!customAnim && mExitingBlackFrame == null) {
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700571 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
572 WindowManagerService.TAG,
573 ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800574 SurfaceControl.openTransaction();
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700575 try {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700576 // 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 Mautner46ac6fa2013-08-01 10:06:34 -0700584 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 Zhang97782b42015-10-07 16:01:23 -0700597 mExitingBlackFrame = new BlackFrame(session, outer, inner,
598 SCREEN_FREEZE_LAYER_EXIT, layerStack, mForceDefaultOrientation);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700599 mExitingBlackFrame.setMatrix(mFrameInitialMatrix);
Igor Murashkina86ab6402013-08-30 12:58:36 -0700600 } catch (OutOfResourcesException e) {
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700601 Slog.w(TAG, "Unable to allocate black surface", e);
602 } finally {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800603 SurfaceControl.closeTransaction();
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700604 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
605 WindowManagerService.TAG,
606 "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
607 }
608 }
609
Dianne Hackborn9d9ece32012-09-10 15:33:52 -0700610 if (customAnim && mEnteringBlackFrame == null) {
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700611 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
612 WindowManagerService.TAG,
613 ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800614 SurfaceControl.openTransaction();
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700615
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 Zhang97782b42015-10-07 16:01:23 -0700620 mEnteringBlackFrame = new BlackFrame(session, outer, inner,
621 SCREEN_FREEZE_LAYER_ENTER, layerStack, false);
Igor Murashkina86ab6402013-08-30 12:58:36 -0700622 } catch (OutOfResourcesException e) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800623 Slog.w(TAG, "Unable to allocate black surface", e);
624 } finally {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800625 SurfaceControl.closeTransaction();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800626 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
627 WindowManagerService.TAG,
628 "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
629 }
Dianne Hackborn50660e22011-02-02 17:12:25 -0800630 }
631
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800632 return true;
633 }
634
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800635 /**
636 * Returns true if animating.
637 */
638 public boolean dismiss(SurfaceSession session, long maxAnimationDuration,
Craig Mautner3c174372013-02-21 17:54:37 -0800639 float animationScale, int finalWidth, int finalHeight, int exitAnim, int enterAnim) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800640 if (DEBUG_STATE) Slog.v(TAG, "Dismiss!");
Mathias Agopian29479eb2013-02-14 14:36:04 -0800641 if (mSurfaceControl == null) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800642 // Can't do animation.
643 return false;
644 }
645 if (!mStarted) {
646 startAnimation(session, maxAnimationDuration, animationScale, finalWidth, finalHeight,
Craig Mautner3c174372013-02-21 17:54:37 -0800647 true, exitAnim, enterAnim);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800648 }
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 Hackbornf9d0be92010-11-24 12:35:25 -0800657 public void kill() {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800658 if (DEBUG_STATE) Slog.v(TAG, "Kill!");
Mathias Agopian29479eb2013-02-14 14:36:04 -0800659 if (mSurfaceControl != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700660 if (WindowManagerService.SHOW_TRANSACTIONS ||
661 WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
Mathias Agopian29479eb2013-02-14 14:36:04 -0800662 " FREEZE " + mSurfaceControl + ": DESTROY");
663 mSurfaceControl.destroy();
664 mSurfaceControl = null;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800665 }
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700666 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 Hackborn352cc982011-01-04 11:34:18 -0800677 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700678 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 Hackbornf9d0be92010-11-24 12:35:25 -0800695 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700696 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 Hackbornfd1c5ed2012-01-13 13:09:16 -0800709 }
710 if (mRotateExitAnimation != null) {
711 mRotateExitAnimation.cancel();
712 mRotateExitAnimation = null;
713 }
714 if (mRotateEnterAnimation != null) {
715 mRotateEnterAnimation.cancel();
716 mRotateEnterAnimation = null;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800717 }
718 }
719
720 public boolean isAnimating() {
Craig Mautner7d8df392012-04-06 15:26:23 -0700721 return hasAnimations() || (TWO_PHASE_ANIMATION && mFinishAnimReady);
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700722 }
723
Dianne Hackborn4b169692012-11-29 17:51:24 -0800724 public boolean isRotating() {
725 return mCurRotation != mOriginalRotation;
726 }
727
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700728 private boolean hasAnimations() {
Craig Mautner7d8df392012-04-06 15:26:23 -0700729 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 Hackbornf9d0be92010-11-24 12:35:25 -0800736 }
737
Craig Mautnere32c3072012-03-12 15:25:35 -0700738 private boolean stepAnimation(long now) {
Craig Mautner3255a282012-04-16 15:42:47 -0700739 if (now > mHalfwayPoint) {
740 mHalfwayPoint = Long.MAX_VALUE;
741 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800742 if (mFinishAnimReady && mFinishAnimStartTime < 0) {
743 if (DEBUG_STATE) Slog.v(TAG, "Step: finish anim now ready");
744 mFinishAnimStartTime = now;
745 }
746
Craig Mautner7d8df392012-04-06 15:26:23 -0700747 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 Mautnerdbb79912012-03-01 18:59:14 -0800753
Craig Mautner7d8df392012-04-06 15:26:23 -0700754 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 Mautnerdbb79912012-03-01 18:59:14 -0800759 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700760 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 Hackborn9fd74802012-03-01 19:26:31 -0800766 }
767
Craig Mautnerdbb79912012-03-01 18:59:14 -0800768 long finishNow = mFinishAnimReady ? (now - mFinishAnimStartTime) : 0;
769 if (DEBUG_STATE) Slog.v(TAG, "Step: finishNow=" + finishNow);
770
Craig Mautner7d8df392012-04-06 15:26:23 -0700771 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 Mautnerdbb79912012-03-01 18:59:14 -0800777
Craig Mautner7d8df392012-04-06 15:26:23 -0700778 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 Mautnerdbb79912012-03-01 18:59:14 -0800783 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700784 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 Hackborn9fd74802012-03-01 19:26:31 -0800790 }
791
Craig Mautnerdbb79912012-03-01 18:59:14 -0800792 mMoreRotateExit = false;
793 if (mRotateExitAnimation != null) {
794 mMoreRotateExit = mRotateExitAnimation.getTransformation(now, mRotateExitTransformation);
795 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate exit: " + mRotateExitTransformation);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700796 }
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 Mautner7d8df392012-04-06 15:26:23 -0700804 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 Hackbornd6b32b62012-03-16 11:54:51 -0700810 }
811
Craig Mautner7d8df392012-04-06 15:26:23 -0700812 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 Hackbornd6b32b62012-03-16 11:54:51 -0700826 }
827 if (mRotateExitAnimation != null) {
828 if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, clearing rotate exit anim!");
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800829 mRotateExitAnimation.cancel();
830 mRotateExitAnimation = null;
831 mRotateExitTransformation.clear();
832 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800833 }
834
Craig Mautner7d8df392012-04-06 15:26:23 -0700835 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 Hackbornd6b32b62012-03-16 11:54:51 -0700849 }
850 if (mRotateEnterAnimation != null) {
851 if (DEBUG_STATE) Slog.v(TAG, "Enter animations done, clearing rotate enter anim!");
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800852 mRotateEnterAnimation.cancel();
853 mRotateEnterAnimation = null;
854 mRotateEnterTransformation.clear();
855 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800856 }
857
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700858 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 Hackborn9fd74802012-03-01 19:26:31 -0800873 mRotateFrameAnimation.cancel();
874 mRotateFrameAnimation = null;
875 mRotateFrameTransformation.clear();
876 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800877 }
878
879 mExitTransformation.set(mRotateExitTransformation);
Craig Mautnerdbb79912012-03-01 18:59:14 -0800880 mEnterTransformation.set(mRotateEnterTransformation);
Craig Mautner7d8df392012-04-06 15:26:23 -0700881 if (TWO_PHASE_ANIMATION) {
882 mExitTransformation.compose(mStartExitTransformation);
883 mExitTransformation.compose(mFinishExitTransformation);
884
885 mEnterTransformation.compose(mStartEnterTransformation);
886 mEnterTransformation.compose(mFinishEnterTransformation);
887 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800888
889 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final exit: " + mExitTransformation);
890 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final enter: " + mEnterTransformation);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700891
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 Mautnerdbb79912012-03-01 18:59:14 -0800902
Craig Mautner7d8df392012-04-06 15:26:23 -0700903 final boolean more = (TWO_PHASE_ANIMATION
904 && (mMoreStartEnter || mMoreStartExit || mMoreFinishEnter || mMoreFinishExit))
905 || (USE_CUSTOM_BLACK_FRAME
906 && (mMoreStartFrame || mMoreRotateFrame || mMoreFinishFrame))
Igor Murashkina86ab6402013-08-30 12:58:36 -0700907 || mMoreRotateEnter || mMoreRotateExit
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800908 || !mFinishAnimReady;
Craig Mautnerdbb79912012-03-01 18:59:14 -0800909
910 mSnapshotFinalMatrix.setConcat(mExitTransformation.getMatrix(), mSnapshotInitialMatrix);
911
912 if (DEBUG_STATE) Slog.v(TAG, "Step: more=" + more);
913
914 return more;
915 }
916
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700917 void updateSurfacesInTransaction() {
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700918 if (!mStarted) {
919 return;
920 }
921
Mathias Agopian29479eb2013-02-14 14:36:04 -0800922 if (mSurfaceControl != null) {
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700923 if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
Craig Mautnerdbb79912012-03-01 18:59:14 -0800924 if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, hiding screenshot surface");
Mathias Agopian29479eb2013-02-14 14:36:04 -0800925 mSurfaceControl.hide();
Craig Mautnerdbb79912012-03-01 18:59:14 -0800926 }
927 }
928
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700929 if (mCustomBlackFrame != null) {
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700930 if (!mMoreStartFrame && !mMoreFinishFrame && !mMoreRotateFrame) {
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800931 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding black frame");
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700932 mCustomBlackFrame.hide();
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700933 } else {
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700934 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 Mautner46ac6fa2013-08-01 10:06:34 -0700945 if (mForceDefaultOrientation) {
946 mExitingBlackFrame.setAlpha(mExitTransformation.getAlpha());
947 }
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700948 }
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 Mautnerdbb79912012-03-01 18:59:14 -0800957 }
958 }
959
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700960 setSnapshotTransformInTransaction(mSnapshotFinalMatrix, mExitTransformation.getAlpha());
Craig Mautnerdbb79912012-03-01 18:59:14 -0800961 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700962
Craig Mautnere32c3072012-03-12 15:25:35 -0700963 public boolean stepAnimationLocked(long now) {
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700964 if (!hasAnimations()) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800965 if (DEBUG_STATE) Slog.v(TAG, "Step: no animations running");
Craig Mautnera731cd32012-03-02 15:23:55 -0800966 mFinishAnimReady = false;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800967 return false;
968 }
969
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800970 if (!mAnimRunning) {
971 if (DEBUG_STATE) Slog.v(TAG, "Step: starting start, finish, rotate");
Craig Mautner7d8df392012-04-06 15:26:23 -0700972 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 Hackborn89620282011-09-11 12:47:45 -0700985 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700986 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 Hackborn9fd74802012-03-01 19:26:31 -0800996 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800997 if (mRotateEnterAnimation != null) {
998 mRotateEnterAnimation.setStartTime(now);
999 }
1000 if (mRotateExitAnimation != null) {
1001 mRotateExitAnimation.setStartTime(now);
1002 }
1003 mAnimRunning = true;
Craig Mautner3255a282012-04-16 15:42:47 -07001004 mHalfwayPoint = now + mRotateEnterAnimation.getDuration() / 2;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08001005 }
Craig Mautnere32c3072012-03-12 15:25:35 -07001006
1007 return stepAnimation(now);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08001008 }
1009
1010 public Transformation getEnterTransformation() {
1011 return mEnterTransformation;
Dianne Hackborna1111872010-11-23 20:55:11 -08001012 }
1013}