blob: 70bf15ceb4c384b1a36a6b93624b492df5318c54 [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
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080019import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
20import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
21import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
22import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
23import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang97782b42015-10-07 16:01:23 -070024import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
Chong Zhang97782b42015-10-07 16:01:23 -070025import static com.android.server.wm.WindowStateAnimator.WINDOW_FREEZE_LAYER;
Steven Timotiusf2d68892017-08-28 17:00:01 -070026import static com.android.server.wm.proto.ScreenRotationAnimationProto.ANIMATION_RUNNING;
27import static com.android.server.wm.proto.ScreenRotationAnimationProto.STARTED;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080028
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080029import android.content.Context;
Dianne Hackborna1111872010-11-23 20:55:11 -080030import android.graphics.Matrix;
Dianne Hackborna1111872010-11-23 20:55:11 -080031import android.graphics.PixelFormat;
32import android.graphics.Rect;
Dianne Hackborna1111872010-11-23 20:55:11 -080033import android.util.Slog;
Steven Timotiusf2d68892017-08-28 17:00:01 -070034import android.util.proto.ProtoOutputStream;
Craig Mautner6881a102012-07-27 13:04:51 -070035import android.view.Display;
Craig Mautner46ac6fa2013-08-01 10:06:34 -070036import android.view.DisplayInfo;
Dianne Hackborna1111872010-11-23 20:55:11 -080037import android.view.Surface;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080038import android.view.Surface.OutOfResourcesException;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080039import android.view.SurfaceControl;
Dianne Hackborna1111872010-11-23 20:55:11 -080040import android.view.SurfaceSession;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080041import android.view.animation.Animation;
42import android.view.animation.AnimationUtils;
43import android.view.animation.Transformation;
Dianne Hackborna1111872010-11-23 20:55:11 -080044
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080045import java.io.PrintWriter;
46
Craig Mautnere32c3072012-03-12 15:25:35 -070047class ScreenRotationAnimation {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080048 static final String TAG = TAG_WITH_CLASS_NAME ? "ScreenRotationAnimation" : TAG_WM;
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080049 static final boolean DEBUG_STATE = false;
50 static final boolean DEBUG_TRANSFORMS = false;
Dianne Hackborn187ae2102012-04-11 18:12:06 -070051 static final boolean TWO_PHASE_ANIMATION = false;
Dianne Hackbornd6b32b62012-03-16 11:54:51 -070052 static final boolean USE_CUSTOM_BLACK_FRAME = false;
Dianne Hackborna1111872010-11-23 20:55:11 -080053
Chong Zhang97782b42015-10-07 16:01:23 -070054 /*
55 * Layers for screen rotation animation. We put these layers above
56 * WINDOW_FREEZE_LAYER so that screen freeze will cover all windows.
57 */
58 static final int SCREEN_FREEZE_LAYER_BASE = WINDOW_FREEZE_LAYER + TYPE_LAYER_MULTIPLIER;
59 static final int SCREEN_FREEZE_LAYER_ENTER = SCREEN_FREEZE_LAYER_BASE;
60 static final int SCREEN_FREEZE_LAYER_SCREENSHOT = SCREEN_FREEZE_LAYER_BASE + 1;
61 static final int SCREEN_FREEZE_LAYER_EXIT = SCREEN_FREEZE_LAYER_BASE + 2;
62 static final int SCREEN_FREEZE_LAYER_CUSTOM = SCREEN_FREEZE_LAYER_BASE + 3;
Dianne Hackborn50660e22011-02-02 17:12:25 -080063
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080064 final Context mContext;
Craig Mautner46ac6fa2013-08-01 10:06:34 -070065 final DisplayContent mDisplayContent;
Mathias Agopian29479eb2013-02-14 14:36:04 -080066 SurfaceControl mSurfaceControl;
Dianne Hackbornd6b32b62012-03-16 11:54:51 -070067 BlackFrame mCustomBlackFrame;
68 BlackFrame mExitingBlackFrame;
69 BlackFrame mEnteringBlackFrame;
Dianne Hackborna1111872010-11-23 20:55:11 -080070 int mWidth, mHeight;
71
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080072 int mOriginalRotation;
73 int mOriginalWidth, mOriginalHeight;
Dianne Hackborna1111872010-11-23 20:55:11 -080074 int mCurRotation;
Craig Mautner46ac6fa2013-08-01 10:06:34 -070075 Rect mOriginalDisplayRect = new Rect();
76 Rect mCurrentDisplayRect = new Rect();
Dianne Hackborna1111872010-11-23 20:55:11 -080077
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080078 // For all animations, "exit" is for the UI elements that are going
79 // away (that is the snapshot of the old screen), and "enter" is for
80 // the new UI elements that are appearing (that is the active windows
81 // in their final orientation).
82
83 // The starting animation for the exiting and entering elements. This
84 // animation applies a transformation while the rotation is in progress.
85 // It is started immediately, before the new entering UI is ready.
86 Animation mStartExitAnimation;
87 final Transformation mStartExitTransformation = new Transformation();
88 Animation mStartEnterAnimation;
89 final Transformation mStartEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -080090 Animation mStartFrameAnimation;
91 final Transformation mStartFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080092
93 // The finishing animation for the exiting and entering elements. This
94 // animation needs to undo the transformation of the starting animation.
95 // It starts running once the new rotation UI elements are ready to be
96 // displayed.
97 Animation mFinishExitAnimation;
98 final Transformation mFinishExitTransformation = new Transformation();
99 Animation mFinishEnterAnimation;
100 final Transformation mFinishEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800101 Animation mFinishFrameAnimation;
102 final Transformation mFinishFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800103
104 // The current active animation to move from the old to the new rotated
105 // state. Which animation is run here will depend on the old and new
106 // rotations.
107 Animation mRotateExitAnimation;
108 final Transformation mRotateExitTransformation = new Transformation();
109 Animation mRotateEnterAnimation;
110 final Transformation mRotateEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800111 Animation mRotateFrameAnimation;
112 final Transformation mRotateFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800113
114 // A previously running rotate animation. This will be used if we need
115 // to switch to a new rotation before finishing the previous one.
116 Animation mLastRotateExitAnimation;
117 final Transformation mLastRotateExitTransformation = new Transformation();
118 Animation mLastRotateEnterAnimation;
119 final Transformation mLastRotateEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800120 Animation mLastRotateFrameAnimation;
121 final Transformation mLastRotateFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800122
123 // Complete transformations being applied.
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800124 final Transformation mExitTransformation = new Transformation();
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800125 final Transformation mEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800126 final Transformation mFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800127
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800128 boolean mStarted;
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800129 boolean mAnimRunning;
130 boolean mFinishAnimReady;
131 long mFinishAnimStartTime;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700132 boolean mForceDefaultOrientation;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800133
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800134 final Matrix mFrameInitialMatrix = new Matrix();
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800135 final Matrix mSnapshotInitialMatrix = new Matrix();
136 final Matrix mSnapshotFinalMatrix = new Matrix();
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700137 final Matrix mExitFrameFinalMatrix = new Matrix();
Dianne Hackborn50660e22011-02-02 17:12:25 -0800138 final Matrix mTmpMatrix = new Matrix();
Dianne Hackborna1111872010-11-23 20:55:11 -0800139 final float[] mTmpFloats = new float[9];
Craig Mautnerdbb79912012-03-01 18:59:14 -0800140 private boolean mMoreRotateEnter;
141 private boolean mMoreRotateExit;
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800142 private boolean mMoreRotateFrame;
Craig Mautnerdbb79912012-03-01 18:59:14 -0800143 private boolean mMoreFinishEnter;
144 private boolean mMoreFinishExit;
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800145 private boolean mMoreFinishFrame;
Craig Mautnerdbb79912012-03-01 18:59:14 -0800146 private boolean mMoreStartEnter;
147 private boolean mMoreStartExit;
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800148 private boolean mMoreStartFrame;
Craig Mautner3255a282012-04-16 15:42:47 -0700149 long mHalfwayPoint;
Dianne Hackborna1111872010-11-23 20:55:11 -0800150
Robert Carr68e5c9e2016-09-14 10:50:09 -0700151 private final WindowManagerService mService;
152
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800153 public void printTo(String prefix, PrintWriter pw) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800154 pw.print(prefix); pw.print("mSurface="); pw.print(mSurfaceControl);
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800155 pw.print(" mWidth="); pw.print(mWidth);
156 pw.print(" mHeight="); pw.println(mHeight);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700157 if (USE_CUSTOM_BLACK_FRAME) {
158 pw.print(prefix); pw.print("mCustomBlackFrame="); pw.println(mCustomBlackFrame);
159 if (mCustomBlackFrame != null) {
160 mCustomBlackFrame.printTo(prefix + " ", pw);
161 }
162 }
163 pw.print(prefix); pw.print("mExitingBlackFrame="); pw.println(mExitingBlackFrame);
164 if (mExitingBlackFrame != null) {
165 mExitingBlackFrame.printTo(prefix + " ", pw);
166 }
167 pw.print(prefix); pw.print("mEnteringBlackFrame="); pw.println(mEnteringBlackFrame);
168 if (mEnteringBlackFrame != null) {
169 mEnteringBlackFrame.printTo(prefix + " ", pw);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800170 }
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700171 pw.print(prefix); pw.print("mCurRotation="); pw.print(mCurRotation);
172 pw.print(" mOriginalRotation="); pw.println(mOriginalRotation);
173 pw.print(prefix); pw.print("mOriginalWidth="); pw.print(mOriginalWidth);
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800174 pw.print(" mOriginalHeight="); pw.println(mOriginalHeight);
175 pw.print(prefix); pw.print("mStarted="); pw.print(mStarted);
176 pw.print(" mAnimRunning="); pw.print(mAnimRunning);
177 pw.print(" mFinishAnimReady="); pw.print(mFinishAnimReady);
178 pw.print(" mFinishAnimStartTime="); pw.println(mFinishAnimStartTime);
179 pw.print(prefix); pw.print("mStartExitAnimation="); pw.print(mStartExitAnimation);
180 pw.print(" "); mStartExitTransformation.printShortString(pw); pw.println();
181 pw.print(prefix); pw.print("mStartEnterAnimation="); pw.print(mStartEnterAnimation);
182 pw.print(" "); mStartEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800183 pw.print(prefix); pw.print("mStartFrameAnimation="); pw.print(mStartFrameAnimation);
184 pw.print(" "); mStartFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800185 pw.print(prefix); pw.print("mFinishExitAnimation="); pw.print(mFinishExitAnimation);
186 pw.print(" "); mFinishExitTransformation.printShortString(pw); pw.println();
187 pw.print(prefix); pw.print("mFinishEnterAnimation="); pw.print(mFinishEnterAnimation);
188 pw.print(" "); mFinishEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800189 pw.print(prefix); pw.print("mFinishFrameAnimation="); pw.print(mFinishFrameAnimation);
190 pw.print(" "); mFinishFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800191 pw.print(prefix); pw.print("mRotateExitAnimation="); pw.print(mRotateExitAnimation);
192 pw.print(" "); mRotateExitTransformation.printShortString(pw); pw.println();
193 pw.print(prefix); pw.print("mRotateEnterAnimation="); pw.print(mRotateEnterAnimation);
194 pw.print(" "); mRotateEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800195 pw.print(prefix); pw.print("mRotateFrameAnimation="); pw.print(mRotateFrameAnimation);
196 pw.print(" "); mRotateFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800197 pw.print(prefix); pw.print("mExitTransformation=");
198 mExitTransformation.printShortString(pw); pw.println();
199 pw.print(prefix); pw.print("mEnterTransformation=");
200 mEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800201 pw.print(prefix); pw.print("mFrameTransformation=");
Steven Timotius8304ef42017-08-28 16:59:14 -0700202 mFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800203 pw.print(prefix); pw.print("mFrameInitialMatrix=");
204 mFrameInitialMatrix.printShortString(pw);
205 pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800206 pw.print(prefix); pw.print("mSnapshotInitialMatrix=");
207 mSnapshotInitialMatrix.printShortString(pw);
208 pw.print(" mSnapshotFinalMatrix="); mSnapshotFinalMatrix.printShortString(pw);
209 pw.println();
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700210 pw.print(prefix); pw.print("mExitFrameFinalMatrix=");
211 mExitFrameFinalMatrix.printShortString(pw);
212 pw.println();
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700213 pw.print(prefix); pw.print("mForceDefaultOrientation="); pw.print(mForceDefaultOrientation);
214 if (mForceDefaultOrientation) {
215 pw.print(" mOriginalDisplayRect="); pw.print(mOriginalDisplayRect.toShortString());
216 pw.print(" mCurrentDisplayRect="); pw.println(mCurrentDisplayRect.toShortString());
217 }
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800218 }
219
Steven Timotiusf2d68892017-08-28 17:00:01 -0700220 public void writeToProto(ProtoOutputStream proto, long fieldId) {
221 final long token = proto.start(fieldId);
222 proto.write(STARTED, mStarted);
223 proto.write(ANIMATION_RUNNING, mAnimRunning);
224 proto.end(token);
225 }
226
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700227 public ScreenRotationAnimation(Context context, DisplayContent displayContent,
Robert Carrb1579c82017-09-05 14:54:47 -0700228 boolean inTransaction, boolean forceDefaultOrientation,
Robert Carr68e5c9e2016-09-14 10:50:09 -0700229 boolean isSecure, WindowManagerService service) {
230 mService = service;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800231 mContext = context;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700232 mDisplayContent = displayContent;
233 displayContent.getLogicalDisplayRect(mOriginalDisplayRect);
Dianne Hackborna1111872010-11-23 20:55:11 -0800234
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800235 // Screenshot does NOT include rotation!
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700236 final Display display = displayContent.getDisplay();
237 int originalRotation = display.getRotation();
238 final int originalWidth;
239 final int originalHeight;
240 DisplayInfo displayInfo = displayContent.getDisplayInfo();
241 if (forceDefaultOrientation) {
242 // Emulated orientation.
243 mForceDefaultOrientation = true;
244 originalWidth = displayContent.mBaseDisplayWidth;
245 originalHeight = displayContent.mBaseDisplayHeight;
246 } else {
247 // Normal situation
248 originalWidth = displayInfo.logicalWidth;
249 originalHeight = displayInfo.logicalHeight;
250 }
Mathias Agopian0ab84ef2011-10-13 16:02:48 -0700251 if (originalRotation == Surface.ROTATION_90
252 || originalRotation == Surface.ROTATION_270) {
253 mWidth = originalHeight;
254 mHeight = originalWidth;
255 } else {
256 mWidth = originalWidth;
257 mHeight = originalHeight;
258 }
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800259
Jeff Brownbc68a592011-07-25 12:58:12 -0700260 mOriginalRotation = originalRotation;
261 mOriginalWidth = originalWidth;
262 mOriginalHeight = originalHeight;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800263
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800264 if (!inTransaction) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800265 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG_WM,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800266 ">>> OPEN TRANSACTION ScreenRotationAnimation");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700267 mService.openSurfaceTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800268 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700269
Dianne Hackborna1111872010-11-23 20:55:11 -0800270 try {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800271 try {
Robert Carrb1579c82017-09-05 14:54:47 -0700272 mSurfaceControl = displayContent.makeOverlay()
Robert Carre625fcf2017-09-01 12:36:28 -0700273 .setName("ScreenshotSurface")
274 .setSize(mWidth, mHeight)
275 .setSecure(isSecure)
276 .build();
Robert Carre13b58e2017-08-31 14:50:44 -0700277
Mathias Agopian11e7d882013-03-05 14:14:55 -0800278 // capture a screenshot into the surface we just created
279 Surface sur = new Surface();
280 sur.copyFrom(mSurfaceControl);
David Stevens848cf822017-08-01 17:54:23 -0700281 // TODO(multidisplay): we should use the proper display
Mathias Agopian11e7d882013-03-05 14:14:55 -0800282 SurfaceControl.screenshot(SurfaceControl.getBuiltInDisplay(
283 SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN), sur);
Chong Zhang97782b42015-10-07 16:01:23 -0700284 mSurfaceControl.setLayer(SCREEN_FREEZE_LAYER_SCREENSHOT);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800285 mSurfaceControl.setAlpha(0);
286 mSurfaceControl.show();
Craig Mautnere50d7fc2013-03-18 10:06:21 -0700287 sur.destroy();
Igor Murashkina86ab6402013-08-30 12:58:36 -0700288 } catch (OutOfResourcesException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800289 Slog.w(TAG, "Unable to allocate freeze surface", e);
Dianne Hackborn352cc982011-01-04 11:34:18 -0800290 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800291
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800292 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG_WM,
293 " FREEZE " + mSurfaceControl + ": CREATE");
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700294
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700295 setRotationInTransaction(originalRotation);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800296 } finally {
297 if (!inTransaction) {
Adrian Roos111aff92017-09-27 18:11:46 +0200298 mService.closeSurfaceTransaction("ScreenRotationAnimation");
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800299 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG_WM,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800300 "<<< CLOSE TRANSACTION ScreenRotationAnimation");
Dianne Hackborn352cc982011-01-04 11:34:18 -0800301 }
Dianne Hackborn0f761d62010-11-30 22:06:10 -0800302 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800303 }
304
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800305 boolean hasScreenshot() {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800306 return mSurfaceControl != null;
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800307 }
308
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700309 private void setSnapshotTransformInTransaction(Matrix matrix, float alpha) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800310 if (mSurfaceControl != null) {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800311 matrix.getValues(mTmpFloats);
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700312 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 Agopian29479eb2013-02-14 14:36:04 -0800320 mSurfaceControl.setMatrix(
Dianne Hackborn352cc982011-01-04 11:34:18 -0800321 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
322 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800323 mSurfaceControl.setAlpha(alpha);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800324 if (DEBUG_TRANSFORMS) {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800325 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 Hackborna1111872010-11-23 20:55:11 -0800333 }
334 }
335
Dianne Hackborn0aae2d42010-12-07 23:51:29 -0800336 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 Hackbornf9d0be92010-11-24 12:35:25 -0800357 // Must be called while in a transaction.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700358 private void setRotationInTransaction(int rotation) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800359 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 Ogunwale4a02d812015-02-12 23:01:38 -0800364 int delta = DisplayContent.deltaRotation(rotation, Surface.ROTATION_0);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -0800365 createRotationMatrix(delta, mWidth, mHeight, mSnapshotInitialMatrix);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800366
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800367 if (DEBUG_STATE) Slog.v(TAG, "**** ROTATION: " + delta);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700368 setSnapshotTransformInTransaction(mSnapshotInitialMatrix, 1.0f);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800369 }
370
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800371 // Must be called while in a transaction.
Robert Carrb1579c82017-09-05 14:54:47 -0700372 public boolean setRotationInTransaction(int rotation,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800373 long maxAnimationDuration, float animationScale, int finalWidth, int finalHeight) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700374 setRotationInTransaction(rotation);
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700375 if (TWO_PHASE_ANIMATION) {
Robert Carrb1579c82017-09-05 14:54:47 -0700376 return startAnimation(maxAnimationDuration, animationScale,
Craig Mautner3c174372013-02-21 17:54:37 -0800377 finalWidth, finalHeight, false, 0, 0);
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700378 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700379
380 // Don't start animation yet.
381 return false;
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800382 }
383
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800384 /**
385 * Returns true if animating.
386 */
Robert Carrb1579c82017-09-05 14:54:47 -0700387 private boolean startAnimation(long maxAnimationDuration,
Craig Mautner3c174372013-02-21 17:54:37 -0800388 float animationScale, int finalWidth, int finalHeight, boolean dismissing,
389 int exitAnim, int enterAnim) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800390 if (mSurfaceControl == null) {
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800391 // Can't do animation.
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800392 return false;
393 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800394 if (mStarted) {
395 return true;
396 }
397
398 mStarted = true;
399
400 boolean firstStart = false;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800401
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800402 // Figure out how the screen has moved from the original rotation.
Wale Ogunwale4a02d812015-02-12 23:01:38 -0800403 int delta = DisplayContent.deltaRotation(mCurRotation, mOriginalRotation);
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800404
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700405 if (TWO_PHASE_ANIMATION && mFinishExitAnimation == null
406 && (!dismissing || delta != Surface.ROTATION_0)) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800407 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 Hackbornd6b32b62012-03-16 11:54:51 -0700413 if (USE_CUSTOM_BLACK_FRAME) {
414 mStartFrameAnimation = AnimationUtils.loadAnimation(mContext,
415 com.android.internal.R.anim.screen_rotate_start_frame);
416 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800417 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 Hackbornd6b32b62012-03-16 11:54:51 -0700421 if (USE_CUSTOM_BLACK_FRAME) {
422 mFinishFrameAnimation = AnimationUtils.loadAnimation(mContext,
423 com.android.internal.R.anim.screen_rotate_finish_frame);
424 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800425 }
426
427 if (DEBUG_STATE) Slog.v(TAG, "Rotation delta: " + delta + " finalWidth="
428 + finalWidth + " finalHeight=" + finalHeight
429 + " origWidth=" + mOriginalWidth + " origHeight=" + mOriginalHeight);
430
Dianne Hackborn9d9ece32012-09-10 15:33:52 -0700431 final boolean customAnim;
Craig Mautner3c174372013-02-21 17:54:37 -0800432 if (exitAnim != 0 && enterAnim != 0) {
Dianne Hackborn9d9ece32012-09-10 15:33:52 -0700433 customAnim = true;
Craig Mautner3c174372013-02-21 17:54:37 -0800434 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext, exitAnim);
435 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext, enterAnim);
Dianne Hackborn9d9ece32012-09-10 15:33:52 -0700436 } 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 Hackbornf9d0be92010-11-24 12:35:25 -0800480 }
481
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800482 // 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 Hackborn187ae2102012-04-11 18:12:06 -0700486 if (TWO_PHASE_ANIMATION && firstStart) {
Dianne Hackborn9d9ece32012-09-10 15:33:52 -0700487 // 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 Hackbornfd1c5ed2012-01-13 13:09:16 -0800493 if (DEBUG_STATE) Slog.v(TAG, "Initializing start and finish animations");
494 mStartEnterAnimation.initialize(finalWidth, finalHeight,
Dianne Hackborn191874e32012-03-09 11:03:36 -0800495 halfWidth, halfHeight);
496 mStartExitAnimation.initialize(halfWidth, halfHeight,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800497 mOriginalWidth, mOriginalHeight);
498 mFinishEnterAnimation.initialize(finalWidth, finalHeight,
Dianne Hackborn191874e32012-03-09 11:03:36 -0800499 halfWidth, halfHeight);
500 mFinishExitAnimation.initialize(halfWidth, halfHeight,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800501 mOriginalWidth, mOriginalHeight);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700502 if (USE_CUSTOM_BLACK_FRAME) {
503 mStartFrameAnimation.initialize(finalWidth, finalHeight,
504 mOriginalWidth, mOriginalHeight);
505 mFinishFrameAnimation.initialize(finalWidth, finalHeight,
506 mOriginalWidth, mOriginalHeight);
507 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800508 }
509 mRotateEnterAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
510 mRotateExitAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700511 if (USE_CUSTOM_BLACK_FRAME) {
512 mRotateFrameAnimation.initialize(finalWidth, finalHeight, mOriginalWidth,
513 mOriginalHeight);
514 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800515 mAnimRunning = false;
516 mFinishAnimReady = false;
517 mFinishAnimStartTime = -1;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800518
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700519 if (TWO_PHASE_ANIMATION && firstStart) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800520 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 Hackbornd6b32b62012-03-16 11:54:51 -0700528 if (USE_CUSTOM_BLACK_FRAME) {
529 mStartFrameAnimation.restrictDuration(maxAnimationDuration);
530 mStartFrameAnimation.scaleCurrentDuration(animationScale);
531 mFinishFrameAnimation.restrictDuration(maxAnimationDuration);
532 mFinishFrameAnimation.scaleCurrentDuration(animationScale);
533 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800534 }
535 mRotateExitAnimation.restrictDuration(maxAnimationDuration);
536 mRotateExitAnimation.scaleCurrentDuration(animationScale);
537 mRotateEnterAnimation.restrictDuration(maxAnimationDuration);
538 mRotateEnterAnimation.scaleCurrentDuration(animationScale);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700539 if (USE_CUSTOM_BLACK_FRAME) {
540 mRotateFrameAnimation.restrictDuration(maxAnimationDuration);
541 mRotateFrameAnimation.scaleCurrentDuration(animationScale);
542 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800543
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700544 final int layerStack = mDisplayContent.getDisplay().getLayerStack();
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700545 if (USE_CUSTOM_BLACK_FRAME && mCustomBlackFrame == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800546 if (SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
547 TAG_WM,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800548 ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700549 mService.openSurfaceTransaction();
Dianne Hackborn50660e22011-02-02 17:12:25 -0800550
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800551 // 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 Hackbornfd1c5ed2012-01-13 13:09:16 -0800559 try {
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800560 Rect outer = new Rect(-mOriginalWidth*1, -mOriginalHeight*1,
561 mOriginalWidth*2, mOriginalHeight*2);
562 Rect inner = new Rect(0, 0, mOriginalWidth, mOriginalHeight);
Robert Carrb1579c82017-09-05 14:54:47 -0700563 mCustomBlackFrame = new BlackFrame(outer, inner,
564 SCREEN_FREEZE_LAYER_CUSTOM, mDisplayContent, false);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700565 mCustomBlackFrame.setMatrix(mFrameInitialMatrix);
Igor Murashkina86ab6402013-08-30 12:58:36 -0700566 } catch (OutOfResourcesException e) {
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700567 Slog.w(TAG, "Unable to allocate black surface", e);
568 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200569 mService.closeSurfaceTransaction("ScreenRotationAnimation.startAnimation");
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800570 if (SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
571 TAG_WM,
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700572 "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
573 }
574 }
575
Dianne Hackborn9d9ece32012-09-10 15:33:52 -0700576 if (!customAnim && mExitingBlackFrame == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800577 if (SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
578 TAG_WM,
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700579 ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700580 mService.openSurfaceTransaction();
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700581 try {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700582 // 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 Mautner46ac6fa2013-08-01 10:06:34 -0700590 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 }
Robert Carrb1579c82017-09-05 14:54:47 -0700603 mExitingBlackFrame = new BlackFrame(outer, inner,
604 SCREEN_FREEZE_LAYER_EXIT, mDisplayContent, mForceDefaultOrientation);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700605 mExitingBlackFrame.setMatrix(mFrameInitialMatrix);
Igor Murashkina86ab6402013-08-30 12:58:36 -0700606 } catch (OutOfResourcesException e) {
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700607 Slog.w(TAG, "Unable to allocate black surface", e);
608 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200609 mService.closeSurfaceTransaction("ScreenRotationAnimation.startAnimation");
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800610 if (SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
611 TAG_WM,
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700612 "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
613 }
614 }
615
Dianne Hackborn9d9ece32012-09-10 15:33:52 -0700616 if (customAnim && mEnteringBlackFrame == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800617 if (SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
618 TAG_WM,
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700619 ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700620 mService.openSurfaceTransaction();
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700621
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);
Robert Carrb1579c82017-09-05 14:54:47 -0700626 mEnteringBlackFrame = new BlackFrame(outer, inner,
627 SCREEN_FREEZE_LAYER_ENTER, mDisplayContent, false);
Igor Murashkina86ab6402013-08-30 12:58:36 -0700628 } catch (OutOfResourcesException e) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800629 Slog.w(TAG, "Unable to allocate black surface", e);
630 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200631 mService.closeSurfaceTransaction("ScreenRotationAnimation.startAnimation");
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800632 if (SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
633 TAG_WM,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800634 "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
635 }
Dianne Hackborn50660e22011-02-02 17:12:25 -0800636 }
637
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800638 return true;
639 }
640
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800641 /**
642 * Returns true if animating.
643 */
Robert Carrb1579c82017-09-05 14:54:47 -0700644 public boolean dismiss(long maxAnimationDuration,
Craig Mautner3c174372013-02-21 17:54:37 -0800645 float animationScale, int finalWidth, int finalHeight, int exitAnim, int enterAnim) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800646 if (DEBUG_STATE) Slog.v(TAG, "Dismiss!");
Mathias Agopian29479eb2013-02-14 14:36:04 -0800647 if (mSurfaceControl == null) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800648 // Can't do animation.
649 return false;
650 }
651 if (!mStarted) {
Robert Carrb1579c82017-09-05 14:54:47 -0700652 startAnimation(maxAnimationDuration, animationScale, finalWidth, finalHeight,
Craig Mautner3c174372013-02-21 17:54:37 -0800653 true, exitAnim, enterAnim);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800654 }
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 Hackbornf9d0be92010-11-24 12:35:25 -0800663 public void kill() {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800664 if (DEBUG_STATE) Slog.v(TAG, "Kill!");
Mathias Agopian29479eb2013-02-14 14:36:04 -0800665 if (mSurfaceControl != null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800666 if (SHOW_TRANSACTIONS ||
667 SHOW_SURFACE_ALLOC) Slog.i(TAG_WM,
Mathias Agopian29479eb2013-02-14 14:36:04 -0800668 " FREEZE " + mSurfaceControl + ": DESTROY");
669 mSurfaceControl.destroy();
670 mSurfaceControl = null;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800671 }
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700672 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 Hackborn352cc982011-01-04 11:34:18 -0800683 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700684 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 Hackbornf9d0be92010-11-24 12:35:25 -0800701 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700702 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 Hackbornfd1c5ed2012-01-13 13:09:16 -0800715 }
716 if (mRotateExitAnimation != null) {
717 mRotateExitAnimation.cancel();
718 mRotateExitAnimation = null;
719 }
720 if (mRotateEnterAnimation != null) {
721 mRotateEnterAnimation.cancel();
722 mRotateEnterAnimation = null;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800723 }
724 }
725
726 public boolean isAnimating() {
Craig Mautner7d8df392012-04-06 15:26:23 -0700727 return hasAnimations() || (TWO_PHASE_ANIMATION && mFinishAnimReady);
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700728 }
729
Dianne Hackborn4b169692012-11-29 17:51:24 -0800730 public boolean isRotating() {
731 return mCurRotation != mOriginalRotation;
732 }
733
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700734 private boolean hasAnimations() {
Craig Mautner7d8df392012-04-06 15:26:23 -0700735 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 Hackbornf9d0be92010-11-24 12:35:25 -0800742 }
743
Craig Mautnere32c3072012-03-12 15:25:35 -0700744 private boolean stepAnimation(long now) {
Craig Mautner3255a282012-04-16 15:42:47 -0700745 if (now > mHalfwayPoint) {
746 mHalfwayPoint = Long.MAX_VALUE;
747 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800748 if (mFinishAnimReady && mFinishAnimStartTime < 0) {
749 if (DEBUG_STATE) Slog.v(TAG, "Step: finish anim now ready");
750 mFinishAnimStartTime = now;
751 }
752
Craig Mautner7d8df392012-04-06 15:26:23 -0700753 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 Mautnerdbb79912012-03-01 18:59:14 -0800759
Craig Mautner7d8df392012-04-06 15:26:23 -0700760 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 Mautnerdbb79912012-03-01 18:59:14 -0800765 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700766 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 Hackborn9fd74802012-03-01 19:26:31 -0800772 }
773
Craig Mautnerdbb79912012-03-01 18:59:14 -0800774 long finishNow = mFinishAnimReady ? (now - mFinishAnimStartTime) : 0;
775 if (DEBUG_STATE) Slog.v(TAG, "Step: finishNow=" + finishNow);
776
Craig Mautner7d8df392012-04-06 15:26:23 -0700777 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 Mautnerdbb79912012-03-01 18:59:14 -0800783
Craig Mautner7d8df392012-04-06 15:26:23 -0700784 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 Mautnerdbb79912012-03-01 18:59:14 -0800789 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700790 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 Hackborn9fd74802012-03-01 19:26:31 -0800796 }
797
Craig Mautnerdbb79912012-03-01 18:59:14 -0800798 mMoreRotateExit = false;
799 if (mRotateExitAnimation != null) {
800 mMoreRotateExit = mRotateExitAnimation.getTransformation(now, mRotateExitTransformation);
801 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate exit: " + mRotateExitTransformation);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700802 }
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 Mautner7d8df392012-04-06 15:26:23 -0700810 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 Hackbornd6b32b62012-03-16 11:54:51 -0700816 }
817
Craig Mautner7d8df392012-04-06 15:26:23 -0700818 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 Hackbornd6b32b62012-03-16 11:54:51 -0700832 }
833 if (mRotateExitAnimation != null) {
834 if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, clearing rotate exit anim!");
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800835 mRotateExitAnimation.cancel();
836 mRotateExitAnimation = null;
837 mRotateExitTransformation.clear();
838 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800839 }
840
Craig Mautner7d8df392012-04-06 15:26:23 -0700841 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 Hackbornd6b32b62012-03-16 11:54:51 -0700855 }
856 if (mRotateEnterAnimation != null) {
857 if (DEBUG_STATE) Slog.v(TAG, "Enter animations done, clearing rotate enter anim!");
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800858 mRotateEnterAnimation.cancel();
859 mRotateEnterAnimation = null;
860 mRotateEnterTransformation.clear();
861 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800862 }
863
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700864 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 Hackborn9fd74802012-03-01 19:26:31 -0800879 mRotateFrameAnimation.cancel();
880 mRotateFrameAnimation = null;
881 mRotateFrameTransformation.clear();
882 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800883 }
884
885 mExitTransformation.set(mRotateExitTransformation);
Craig Mautnerdbb79912012-03-01 18:59:14 -0800886 mEnterTransformation.set(mRotateEnterTransformation);
Craig Mautner7d8df392012-04-06 15:26:23 -0700887 if (TWO_PHASE_ANIMATION) {
888 mExitTransformation.compose(mStartExitTransformation);
889 mExitTransformation.compose(mFinishExitTransformation);
890
891 mEnterTransformation.compose(mStartEnterTransformation);
892 mEnterTransformation.compose(mFinishEnterTransformation);
893 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800894
895 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final exit: " + mExitTransformation);
896 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final enter: " + mEnterTransformation);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700897
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 Mautnerdbb79912012-03-01 18:59:14 -0800908
Craig Mautner7d8df392012-04-06 15:26:23 -0700909 final boolean more = (TWO_PHASE_ANIMATION
910 && (mMoreStartEnter || mMoreStartExit || mMoreFinishEnter || mMoreFinishExit))
911 || (USE_CUSTOM_BLACK_FRAME
912 && (mMoreStartFrame || mMoreRotateFrame || mMoreFinishFrame))
Igor Murashkina86ab6402013-08-30 12:58:36 -0700913 || mMoreRotateEnter || mMoreRotateExit
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800914 || !mFinishAnimReady;
Craig Mautnerdbb79912012-03-01 18:59:14 -0800915
916 mSnapshotFinalMatrix.setConcat(mExitTransformation.getMatrix(), mSnapshotInitialMatrix);
917
918 if (DEBUG_STATE) Slog.v(TAG, "Step: more=" + more);
919
920 return more;
921 }
922
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700923 void updateSurfacesInTransaction() {
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700924 if (!mStarted) {
925 return;
926 }
927
Mathias Agopian29479eb2013-02-14 14:36:04 -0800928 if (mSurfaceControl != null) {
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700929 if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
Craig Mautnerdbb79912012-03-01 18:59:14 -0800930 if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, hiding screenshot surface");
Mathias Agopian29479eb2013-02-14 14:36:04 -0800931 mSurfaceControl.hide();
Craig Mautnerdbb79912012-03-01 18:59:14 -0800932 }
933 }
934
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700935 if (mCustomBlackFrame != null) {
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700936 if (!mMoreStartFrame && !mMoreFinishFrame && !mMoreRotateFrame) {
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800937 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding black frame");
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700938 mCustomBlackFrame.hide();
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700939 } else {
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700940 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 Mautner46ac6fa2013-08-01 10:06:34 -0700951 if (mForceDefaultOrientation) {
952 mExitingBlackFrame.setAlpha(mExitTransformation.getAlpha());
953 }
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700954 }
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 Mautnerdbb79912012-03-01 18:59:14 -0800963 }
964 }
965
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700966 setSnapshotTransformInTransaction(mSnapshotFinalMatrix, mExitTransformation.getAlpha());
Craig Mautnerdbb79912012-03-01 18:59:14 -0800967 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700968
Craig Mautnere32c3072012-03-12 15:25:35 -0700969 public boolean stepAnimationLocked(long now) {
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700970 if (!hasAnimations()) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800971 if (DEBUG_STATE) Slog.v(TAG, "Step: no animations running");
Craig Mautnera731cd32012-03-02 15:23:55 -0800972 mFinishAnimReady = false;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800973 return false;
974 }
975
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800976 if (!mAnimRunning) {
977 if (DEBUG_STATE) Slog.v(TAG, "Step: starting start, finish, rotate");
Craig Mautner7d8df392012-04-06 15:26:23 -0700978 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 Hackborn89620282011-09-11 12:47:45 -0700991 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700992 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 Hackborn9fd74802012-03-01 19:26:31 -08001002 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -08001003 if (mRotateEnterAnimation != null) {
1004 mRotateEnterAnimation.setStartTime(now);
1005 }
1006 if (mRotateExitAnimation != null) {
1007 mRotateExitAnimation.setStartTime(now);
1008 }
1009 mAnimRunning = true;
Craig Mautner3255a282012-04-16 15:42:47 -07001010 mHalfwayPoint = now + mRotateEnterAnimation.getDuration() / 2;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08001011 }
Craig Mautnere32c3072012-03-12 15:25:35 -07001012
1013 return stepAnimation(now);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08001014 }
1015
1016 public Transformation getEnterTransformation() {
1017 return mEnterTransformation;
Dianne Hackborna1111872010-11-23 20:55:11 -08001018 }
1019}