blob: 5a39de5c3242687371aca356b43958e596e54aa8 [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.Rect;
Dianne Hackborna1111872010-11-23 20:55:11 -080032import android.util.Slog;
Steven Timotiusf2d68892017-08-28 17:00:01 -070033import android.util.proto.ProtoOutputStream;
Craig Mautner6881a102012-07-27 13:04:51 -070034import android.view.Display;
Craig Mautner46ac6fa2013-08-01 10:06:34 -070035import android.view.DisplayInfo;
Dianne Hackborna1111872010-11-23 20:55:11 -080036import android.view.Surface;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080037import android.view.Surface.OutOfResourcesException;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080038import android.view.SurfaceControl;
Dianne Hackborna1111872010-11-23 20:55:11 -080039import android.view.SurfaceSession;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080040import android.view.animation.Animation;
41import android.view.animation.AnimationUtils;
42import android.view.animation.Transformation;
Dianne Hackborna1111872010-11-23 20:55:11 -080043
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080044import java.io.PrintWriter;
45
Craig Mautnere32c3072012-03-12 15:25:35 -070046class ScreenRotationAnimation {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080047 static final String TAG = TAG_WITH_CLASS_NAME ? "ScreenRotationAnimation" : TAG_WM;
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080048 static final boolean DEBUG_STATE = false;
49 static final boolean DEBUG_TRANSFORMS = false;
Dianne Hackborn187ae2102012-04-11 18:12:06 -070050 static final boolean TWO_PHASE_ANIMATION = false;
Dianne Hackbornd6b32b62012-03-16 11:54:51 -070051 static final boolean USE_CUSTOM_BLACK_FRAME = false;
Dianne Hackborna1111872010-11-23 20:55:11 -080052
Chong Zhang97782b42015-10-07 16:01:23 -070053 /*
54 * Layers for screen rotation animation. We put these layers above
55 * WINDOW_FREEZE_LAYER so that screen freeze will cover all windows.
56 */
57 static final int SCREEN_FREEZE_LAYER_BASE = WINDOW_FREEZE_LAYER + TYPE_LAYER_MULTIPLIER;
58 static final int SCREEN_FREEZE_LAYER_ENTER = SCREEN_FREEZE_LAYER_BASE;
59 static final int SCREEN_FREEZE_LAYER_SCREENSHOT = SCREEN_FREEZE_LAYER_BASE + 1;
60 static final int SCREEN_FREEZE_LAYER_EXIT = SCREEN_FREEZE_LAYER_BASE + 2;
61 static final int SCREEN_FREEZE_LAYER_CUSTOM = SCREEN_FREEZE_LAYER_BASE + 3;
Dianne Hackborn50660e22011-02-02 17:12:25 -080062
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080063 final Context mContext;
Craig Mautner46ac6fa2013-08-01 10:06:34 -070064 final DisplayContent mDisplayContent;
Mathias Agopian29479eb2013-02-14 14:36:04 -080065 SurfaceControl mSurfaceControl;
Dianne Hackbornd6b32b62012-03-16 11:54:51 -070066 BlackFrame mCustomBlackFrame;
67 BlackFrame mExitingBlackFrame;
68 BlackFrame mEnteringBlackFrame;
Dianne Hackborna1111872010-11-23 20:55:11 -080069 int mWidth, mHeight;
70
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080071 int mOriginalRotation;
72 int mOriginalWidth, mOriginalHeight;
Dianne Hackborna1111872010-11-23 20:55:11 -080073 int mCurRotation;
Craig Mautner46ac6fa2013-08-01 10:06:34 -070074 Rect mOriginalDisplayRect = new Rect();
75 Rect mCurrentDisplayRect = new Rect();
Dianne Hackborna1111872010-11-23 20:55:11 -080076
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080077 // For all animations, "exit" is for the UI elements that are going
78 // away (that is the snapshot of the old screen), and "enter" is for
79 // the new UI elements that are appearing (that is the active windows
80 // in their final orientation).
81
82 // The starting animation for the exiting and entering elements. This
83 // animation applies a transformation while the rotation is in progress.
84 // It is started immediately, before the new entering UI is ready.
85 Animation mStartExitAnimation;
86 final Transformation mStartExitTransformation = new Transformation();
87 Animation mStartEnterAnimation;
88 final Transformation mStartEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -080089 Animation mStartFrameAnimation;
90 final Transformation mStartFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080091
92 // The finishing animation for the exiting and entering elements. This
93 // animation needs to undo the transformation of the starting animation.
94 // It starts running once the new rotation UI elements are ready to be
95 // displayed.
96 Animation mFinishExitAnimation;
97 final Transformation mFinishExitTransformation = new Transformation();
98 Animation mFinishEnterAnimation;
99 final Transformation mFinishEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800100 Animation mFinishFrameAnimation;
101 final Transformation mFinishFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800102
103 // The current active animation to move from the old to the new rotated
104 // state. Which animation is run here will depend on the old and new
105 // rotations.
106 Animation mRotateExitAnimation;
107 final Transformation mRotateExitTransformation = new Transformation();
108 Animation mRotateEnterAnimation;
109 final Transformation mRotateEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800110 Animation mRotateFrameAnimation;
111 final Transformation mRotateFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800112
113 // A previously running rotate animation. This will be used if we need
114 // to switch to a new rotation before finishing the previous one.
115 Animation mLastRotateExitAnimation;
116 final Transformation mLastRotateExitTransformation = new Transformation();
117 Animation mLastRotateEnterAnimation;
118 final Transformation mLastRotateEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800119 Animation mLastRotateFrameAnimation;
120 final Transformation mLastRotateFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800121
122 // Complete transformations being applied.
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800123 final Transformation mExitTransformation = new Transformation();
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800124 final Transformation mEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800125 final Transformation mFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800126
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800127 boolean mStarted;
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800128 boolean mAnimRunning;
129 boolean mFinishAnimReady;
130 long mFinishAnimStartTime;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700131 boolean mForceDefaultOrientation;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800132
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800133 final Matrix mFrameInitialMatrix = new Matrix();
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800134 final Matrix mSnapshotInitialMatrix = new Matrix();
135 final Matrix mSnapshotFinalMatrix = new Matrix();
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700136 final Matrix mExitFrameFinalMatrix = new Matrix();
Dianne Hackborn50660e22011-02-02 17:12:25 -0800137 final Matrix mTmpMatrix = new Matrix();
Dianne Hackborna1111872010-11-23 20:55:11 -0800138 final float[] mTmpFloats = new float[9];
Craig Mautnerdbb79912012-03-01 18:59:14 -0800139 private boolean mMoreRotateEnter;
140 private boolean mMoreRotateExit;
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800141 private boolean mMoreRotateFrame;
Craig Mautnerdbb79912012-03-01 18:59:14 -0800142 private boolean mMoreFinishEnter;
143 private boolean mMoreFinishExit;
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800144 private boolean mMoreFinishFrame;
Craig Mautnerdbb79912012-03-01 18:59:14 -0800145 private boolean mMoreStartEnter;
146 private boolean mMoreStartExit;
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800147 private boolean mMoreStartFrame;
Craig Mautner3255a282012-04-16 15:42:47 -0700148 long mHalfwayPoint;
Dianne Hackborna1111872010-11-23 20:55:11 -0800149
Robert Carr68e5c9e2016-09-14 10:50:09 -0700150 private final WindowManagerService mService;
151
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800152 public void printTo(String prefix, PrintWriter pw) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800153 pw.print(prefix); pw.print("mSurface="); pw.print(mSurfaceControl);
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800154 pw.print(" mWidth="); pw.print(mWidth);
155 pw.print(" mHeight="); pw.println(mHeight);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700156 if (USE_CUSTOM_BLACK_FRAME) {
157 pw.print(prefix); pw.print("mCustomBlackFrame="); pw.println(mCustomBlackFrame);
158 if (mCustomBlackFrame != null) {
159 mCustomBlackFrame.printTo(prefix + " ", pw);
160 }
161 }
162 pw.print(prefix); pw.print("mExitingBlackFrame="); pw.println(mExitingBlackFrame);
163 if (mExitingBlackFrame != null) {
164 mExitingBlackFrame.printTo(prefix + " ", pw);
165 }
166 pw.print(prefix); pw.print("mEnteringBlackFrame="); pw.println(mEnteringBlackFrame);
167 if (mEnteringBlackFrame != null) {
168 mEnteringBlackFrame.printTo(prefix + " ", pw);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800169 }
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700170 pw.print(prefix); pw.print("mCurRotation="); pw.print(mCurRotation);
171 pw.print(" mOriginalRotation="); pw.println(mOriginalRotation);
172 pw.print(prefix); pw.print("mOriginalWidth="); pw.print(mOriginalWidth);
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800173 pw.print(" mOriginalHeight="); pw.println(mOriginalHeight);
174 pw.print(prefix); pw.print("mStarted="); pw.print(mStarted);
175 pw.print(" mAnimRunning="); pw.print(mAnimRunning);
176 pw.print(" mFinishAnimReady="); pw.print(mFinishAnimReady);
177 pw.print(" mFinishAnimStartTime="); pw.println(mFinishAnimStartTime);
178 pw.print(prefix); pw.print("mStartExitAnimation="); pw.print(mStartExitAnimation);
179 pw.print(" "); mStartExitTransformation.printShortString(pw); pw.println();
180 pw.print(prefix); pw.print("mStartEnterAnimation="); pw.print(mStartEnterAnimation);
181 pw.print(" "); mStartEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800182 pw.print(prefix); pw.print("mStartFrameAnimation="); pw.print(mStartFrameAnimation);
183 pw.print(" "); mStartFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800184 pw.print(prefix); pw.print("mFinishExitAnimation="); pw.print(mFinishExitAnimation);
185 pw.print(" "); mFinishExitTransformation.printShortString(pw); pw.println();
186 pw.print(prefix); pw.print("mFinishEnterAnimation="); pw.print(mFinishEnterAnimation);
187 pw.print(" "); mFinishEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800188 pw.print(prefix); pw.print("mFinishFrameAnimation="); pw.print(mFinishFrameAnimation);
189 pw.print(" "); mFinishFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800190 pw.print(prefix); pw.print("mRotateExitAnimation="); pw.print(mRotateExitAnimation);
191 pw.print(" "); mRotateExitTransformation.printShortString(pw); pw.println();
192 pw.print(prefix); pw.print("mRotateEnterAnimation="); pw.print(mRotateEnterAnimation);
193 pw.print(" "); mRotateEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800194 pw.print(prefix); pw.print("mRotateFrameAnimation="); pw.print(mRotateFrameAnimation);
195 pw.print(" "); mRotateFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800196 pw.print(prefix); pw.print("mExitTransformation=");
197 mExitTransformation.printShortString(pw); pw.println();
198 pw.print(prefix); pw.print("mEnterTransformation=");
199 mEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800200 pw.print(prefix); pw.print("mFrameTransformation=");
Steven Timotius8304ef42017-08-28 16:59:14 -0700201 mFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800202 pw.print(prefix); pw.print("mFrameInitialMatrix=");
203 mFrameInitialMatrix.printShortString(pw);
204 pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800205 pw.print(prefix); pw.print("mSnapshotInitialMatrix=");
206 mSnapshotInitialMatrix.printShortString(pw);
207 pw.print(" mSnapshotFinalMatrix="); mSnapshotFinalMatrix.printShortString(pw);
208 pw.println();
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700209 pw.print(prefix); pw.print("mExitFrameFinalMatrix=");
210 mExitFrameFinalMatrix.printShortString(pw);
211 pw.println();
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700212 pw.print(prefix); pw.print("mForceDefaultOrientation="); pw.print(mForceDefaultOrientation);
213 if (mForceDefaultOrientation) {
214 pw.print(" mOriginalDisplayRect="); pw.print(mOriginalDisplayRect.toShortString());
215 pw.print(" mCurrentDisplayRect="); pw.println(mCurrentDisplayRect.toShortString());
216 }
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800217 }
218
Steven Timotiusf2d68892017-08-28 17:00:01 -0700219 public void writeToProto(ProtoOutputStream proto, long fieldId) {
220 final long token = proto.start(fieldId);
221 proto.write(STARTED, mStarted);
222 proto.write(ANIMATION_RUNNING, mAnimRunning);
223 proto.end(token);
224 }
225
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700226 public ScreenRotationAnimation(Context context, DisplayContent displayContent,
Robert Carrb1579c82017-09-05 14:54:47 -0700227 boolean inTransaction, boolean forceDefaultOrientation,
Robert Carr68e5c9e2016-09-14 10:50:09 -0700228 boolean isSecure, WindowManagerService service) {
229 mService = service;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800230 mContext = context;
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700231 mDisplayContent = displayContent;
Bryce Leef3c6a472017-11-14 14:53:06 -0800232 displayContent.getBounds(mOriginalDisplayRect);
Dianne Hackborna1111872010-11-23 20:55:11 -0800233
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800234 // Screenshot does NOT include rotation!
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700235 final Display display = displayContent.getDisplay();
236 int originalRotation = display.getRotation();
237 final int originalWidth;
238 final int originalHeight;
239 DisplayInfo displayInfo = displayContent.getDisplayInfo();
240 if (forceDefaultOrientation) {
241 // Emulated orientation.
242 mForceDefaultOrientation = true;
243 originalWidth = displayContent.mBaseDisplayWidth;
244 originalHeight = displayContent.mBaseDisplayHeight;
245 } else {
246 // Normal situation
247 originalWidth = displayInfo.logicalWidth;
248 originalHeight = displayInfo.logicalHeight;
249 }
Mathias Agopian0ab84ef2011-10-13 16:02:48 -0700250 if (originalRotation == Surface.ROTATION_90
251 || originalRotation == Surface.ROTATION_270) {
252 mWidth = originalHeight;
253 mHeight = originalWidth;
254 } else {
255 mWidth = originalWidth;
256 mHeight = originalHeight;
257 }
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800258
Jeff Brownbc68a592011-07-25 12:58:12 -0700259 mOriginalRotation = originalRotation;
260 mOriginalWidth = originalWidth;
261 mOriginalHeight = originalHeight;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800262
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800263 if (!inTransaction) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800264 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG_WM,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800265 ">>> OPEN TRANSACTION ScreenRotationAnimation");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700266 mService.openSurfaceTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800267 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700268
Dianne Hackborna1111872010-11-23 20:55:11 -0800269 try {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800270 try {
Robert Carrb1579c82017-09-05 14:54:47 -0700271 mSurfaceControl = displayContent.makeOverlay()
Robert Carre625fcf2017-09-01 12:36:28 -0700272 .setName("ScreenshotSurface")
273 .setSize(mWidth, mHeight)
274 .setSecure(isSecure)
275 .build();
Robert Carre13b58e2017-08-31 14:50:44 -0700276
Mathias Agopian11e7d882013-03-05 14:14:55 -0800277 // capture a screenshot into the surface we just created
278 Surface sur = new Surface();
279 sur.copyFrom(mSurfaceControl);
David Stevens848cf822017-08-01 17:54:23 -0700280 // TODO(multidisplay): we should use the proper display
Mathias Agopian11e7d882013-03-05 14:14:55 -0800281 SurfaceControl.screenshot(SurfaceControl.getBuiltInDisplay(
282 SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN), sur);
Chong Zhang97782b42015-10-07 16:01:23 -0700283 mSurfaceControl.setLayer(SCREEN_FREEZE_LAYER_SCREENSHOT);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800284 mSurfaceControl.setAlpha(0);
285 mSurfaceControl.show();
Craig Mautnere50d7fc2013-03-18 10:06:21 -0700286 sur.destroy();
Igor Murashkina86ab6402013-08-30 12:58:36 -0700287 } catch (OutOfResourcesException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800288 Slog.w(TAG, "Unable to allocate freeze surface", e);
Dianne Hackborn352cc982011-01-04 11:34:18 -0800289 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800290
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800291 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG_WM,
292 " FREEZE " + mSurfaceControl + ": CREATE");
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700293
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700294 setRotationInTransaction(originalRotation);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800295 } finally {
296 if (!inTransaction) {
Adrian Roos111aff92017-09-27 18:11:46 +0200297 mService.closeSurfaceTransaction("ScreenRotationAnimation");
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800298 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG_WM,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800299 "<<< CLOSE TRANSACTION ScreenRotationAnimation");
Dianne Hackborn352cc982011-01-04 11:34:18 -0800300 }
Dianne Hackborn0f761d62010-11-30 22:06:10 -0800301 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800302 }
303
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800304 boolean hasScreenshot() {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800305 return mSurfaceControl != null;
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800306 }
307
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700308 private void setSnapshotTransformInTransaction(Matrix matrix, float alpha) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800309 if (mSurfaceControl != null) {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800310 matrix.getValues(mTmpFloats);
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700311 float x = mTmpFloats[Matrix.MTRANS_X];
312 float y = mTmpFloats[Matrix.MTRANS_Y];
313 if (mForceDefaultOrientation) {
Bryce Leef3c6a472017-11-14 14:53:06 -0800314 mDisplayContent.getBounds(mCurrentDisplayRect);
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700315 x -= mCurrentDisplayRect.left;
316 y -= mCurrentDisplayRect.top;
317 }
318 mSurfaceControl.setPosition(x, y);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800319 mSurfaceControl.setMatrix(
Dianne Hackborn352cc982011-01-04 11:34:18 -0800320 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
321 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800322 mSurfaceControl.setAlpha(alpha);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800323 if (DEBUG_TRANSFORMS) {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800324 float[] srcPnts = new float[] { 0, 0, mWidth, mHeight };
325 float[] dstPnts = new float[4];
326 matrix.mapPoints(dstPnts, srcPnts);
327 Slog.i(TAG, "Original : (" + srcPnts[0] + "," + srcPnts[1]
328 + ")-(" + srcPnts[2] + "," + srcPnts[3] + ")");
329 Slog.i(TAG, "Transformed: (" + dstPnts[0] + "," + dstPnts[1]
330 + ")-(" + dstPnts[2] + "," + dstPnts[3] + ")");
331 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800332 }
333 }
334
Dianne Hackborn0aae2d42010-12-07 23:51:29 -0800335 public static void createRotationMatrix(int rotation, int width, int height,
336 Matrix outMatrix) {
337 switch (rotation) {
338 case Surface.ROTATION_0:
339 outMatrix.reset();
340 break;
341 case Surface.ROTATION_90:
342 outMatrix.setRotate(90, 0, 0);
343 outMatrix.postTranslate(height, 0);
344 break;
345 case Surface.ROTATION_180:
346 outMatrix.setRotate(180, 0, 0);
347 outMatrix.postTranslate(width, height);
348 break;
349 case Surface.ROTATION_270:
350 outMatrix.setRotate(270, 0, 0);
351 outMatrix.postTranslate(0, width);
352 break;
353 }
354 }
355
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800356 // Must be called while in a transaction.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700357 private void setRotationInTransaction(int rotation) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800358 mCurRotation = rotation;
359
360 // Compute the transformation matrix that must be applied
361 // to the snapshot to make it stay in the same original position
362 // with the current screen rotation.
Wale Ogunwale4a02d812015-02-12 23:01:38 -0800363 int delta = DisplayContent.deltaRotation(rotation, Surface.ROTATION_0);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -0800364 createRotationMatrix(delta, mWidth, mHeight, mSnapshotInitialMatrix);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800365
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800366 if (DEBUG_STATE) Slog.v(TAG, "**** ROTATION: " + delta);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700367 setSnapshotTransformInTransaction(mSnapshotInitialMatrix, 1.0f);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800368 }
369
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800370 // Must be called while in a transaction.
Robert Carrb1579c82017-09-05 14:54:47 -0700371 public boolean setRotationInTransaction(int rotation,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800372 long maxAnimationDuration, float animationScale, int finalWidth, int finalHeight) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700373 setRotationInTransaction(rotation);
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700374 if (TWO_PHASE_ANIMATION) {
Robert Carrb1579c82017-09-05 14:54:47 -0700375 return startAnimation(maxAnimationDuration, animationScale,
Craig Mautner3c174372013-02-21 17:54:37 -0800376 finalWidth, finalHeight, false, 0, 0);
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700377 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700378
379 // Don't start animation yet.
380 return false;
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800381 }
382
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800383 /**
384 * Returns true if animating.
385 */
Robert Carrb1579c82017-09-05 14:54:47 -0700386 private boolean startAnimation(long maxAnimationDuration,
Craig Mautner3c174372013-02-21 17:54:37 -0800387 float animationScale, int finalWidth, int finalHeight, boolean dismissing,
388 int exitAnim, int enterAnim) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800389 if (mSurfaceControl == null) {
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800390 // Can't do animation.
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800391 return false;
392 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800393 if (mStarted) {
394 return true;
395 }
396
397 mStarted = true;
398
399 boolean firstStart = false;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800400
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800401 // Figure out how the screen has moved from the original rotation.
Wale Ogunwale4a02d812015-02-12 23:01:38 -0800402 int delta = DisplayContent.deltaRotation(mCurRotation, mOriginalRotation);
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800403
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700404 if (TWO_PHASE_ANIMATION && mFinishExitAnimation == null
405 && (!dismissing || delta != Surface.ROTATION_0)) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800406 if (DEBUG_STATE) Slog.v(TAG, "Creating start and finish animations");
407 firstStart = true;
408 mStartExitAnimation = AnimationUtils.loadAnimation(mContext,
409 com.android.internal.R.anim.screen_rotate_start_exit);
410 mStartEnterAnimation = AnimationUtils.loadAnimation(mContext,
411 com.android.internal.R.anim.screen_rotate_start_enter);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700412 if (USE_CUSTOM_BLACK_FRAME) {
413 mStartFrameAnimation = AnimationUtils.loadAnimation(mContext,
414 com.android.internal.R.anim.screen_rotate_start_frame);
415 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800416 mFinishExitAnimation = AnimationUtils.loadAnimation(mContext,
417 com.android.internal.R.anim.screen_rotate_finish_exit);
418 mFinishEnterAnimation = AnimationUtils.loadAnimation(mContext,
419 com.android.internal.R.anim.screen_rotate_finish_enter);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700420 if (USE_CUSTOM_BLACK_FRAME) {
421 mFinishFrameAnimation = AnimationUtils.loadAnimation(mContext,
422 com.android.internal.R.anim.screen_rotate_finish_frame);
423 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800424 }
425
426 if (DEBUG_STATE) Slog.v(TAG, "Rotation delta: " + delta + " finalWidth="
427 + finalWidth + " finalHeight=" + finalHeight
428 + " origWidth=" + mOriginalWidth + " origHeight=" + mOriginalHeight);
429
Dianne Hackborn9d9ece32012-09-10 15:33:52 -0700430 final boolean customAnim;
Craig Mautner3c174372013-02-21 17:54:37 -0800431 if (exitAnim != 0 && enterAnim != 0) {
Dianne Hackborn9d9ece32012-09-10 15:33:52 -0700432 customAnim = true;
Craig Mautner3c174372013-02-21 17:54:37 -0800433 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext, exitAnim);
434 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext, enterAnim);
Dianne Hackborn9d9ece32012-09-10 15:33:52 -0700435 } else {
436 customAnim = false;
437 switch (delta) {
438 case Surface.ROTATION_0:
439 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
440 com.android.internal.R.anim.screen_rotate_0_exit);
441 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
442 com.android.internal.R.anim.screen_rotate_0_enter);
443 if (USE_CUSTOM_BLACK_FRAME) {
444 mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
445 com.android.internal.R.anim.screen_rotate_0_frame);
446 }
447 break;
448 case Surface.ROTATION_90:
449 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
450 com.android.internal.R.anim.screen_rotate_plus_90_exit);
451 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
452 com.android.internal.R.anim.screen_rotate_plus_90_enter);
453 if (USE_CUSTOM_BLACK_FRAME) {
454 mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
455 com.android.internal.R.anim.screen_rotate_plus_90_frame);
456 }
457 break;
458 case Surface.ROTATION_180:
459 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
460 com.android.internal.R.anim.screen_rotate_180_exit);
461 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
462 com.android.internal.R.anim.screen_rotate_180_enter);
463 if (USE_CUSTOM_BLACK_FRAME) {
464 mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
465 com.android.internal.R.anim.screen_rotate_180_frame);
466 }
467 break;
468 case Surface.ROTATION_270:
469 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
470 com.android.internal.R.anim.screen_rotate_minus_90_exit);
471 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
472 com.android.internal.R.anim.screen_rotate_minus_90_enter);
473 if (USE_CUSTOM_BLACK_FRAME) {
474 mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
475 com.android.internal.R.anim.screen_rotate_minus_90_frame);
476 }
477 break;
478 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800479 }
480
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800481 // Initialize the animations. This is a hack, redefining what "parent"
482 // means to allow supplying the last and next size. In this definition
483 // "%p" is the original (let's call it "previous") size, and "%" is the
484 // screen's current/new size.
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700485 if (TWO_PHASE_ANIMATION && firstStart) {
Dianne Hackborn9d9ece32012-09-10 15:33:52 -0700486 // Compute partial steps between original and final sizes. These
487 // are used for the dimensions of the exiting and entering elements,
488 // so they are never stretched too significantly.
489 final int halfWidth = (finalWidth + mOriginalWidth) / 2;
490 final int halfHeight = (finalHeight + mOriginalHeight) / 2;
491
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800492 if (DEBUG_STATE) Slog.v(TAG, "Initializing start and finish animations");
493 mStartEnterAnimation.initialize(finalWidth, finalHeight,
Dianne Hackborn191874e32012-03-09 11:03:36 -0800494 halfWidth, halfHeight);
495 mStartExitAnimation.initialize(halfWidth, halfHeight,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800496 mOriginalWidth, mOriginalHeight);
497 mFinishEnterAnimation.initialize(finalWidth, finalHeight,
Dianne Hackborn191874e32012-03-09 11:03:36 -0800498 halfWidth, halfHeight);
499 mFinishExitAnimation.initialize(halfWidth, halfHeight,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800500 mOriginalWidth, mOriginalHeight);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700501 if (USE_CUSTOM_BLACK_FRAME) {
502 mStartFrameAnimation.initialize(finalWidth, finalHeight,
503 mOriginalWidth, mOriginalHeight);
504 mFinishFrameAnimation.initialize(finalWidth, finalHeight,
505 mOriginalWidth, mOriginalHeight);
506 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800507 }
508 mRotateEnterAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
509 mRotateExitAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700510 if (USE_CUSTOM_BLACK_FRAME) {
511 mRotateFrameAnimation.initialize(finalWidth, finalHeight, mOriginalWidth,
512 mOriginalHeight);
513 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800514 mAnimRunning = false;
515 mFinishAnimReady = false;
516 mFinishAnimStartTime = -1;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800517
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700518 if (TWO_PHASE_ANIMATION && firstStart) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800519 mStartExitAnimation.restrictDuration(maxAnimationDuration);
520 mStartExitAnimation.scaleCurrentDuration(animationScale);
521 mStartEnterAnimation.restrictDuration(maxAnimationDuration);
522 mStartEnterAnimation.scaleCurrentDuration(animationScale);
523 mFinishExitAnimation.restrictDuration(maxAnimationDuration);
524 mFinishExitAnimation.scaleCurrentDuration(animationScale);
525 mFinishEnterAnimation.restrictDuration(maxAnimationDuration);
526 mFinishEnterAnimation.scaleCurrentDuration(animationScale);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700527 if (USE_CUSTOM_BLACK_FRAME) {
528 mStartFrameAnimation.restrictDuration(maxAnimationDuration);
529 mStartFrameAnimation.scaleCurrentDuration(animationScale);
530 mFinishFrameAnimation.restrictDuration(maxAnimationDuration);
531 mFinishFrameAnimation.scaleCurrentDuration(animationScale);
532 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800533 }
534 mRotateExitAnimation.restrictDuration(maxAnimationDuration);
535 mRotateExitAnimation.scaleCurrentDuration(animationScale);
536 mRotateEnterAnimation.restrictDuration(maxAnimationDuration);
537 mRotateEnterAnimation.scaleCurrentDuration(animationScale);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700538 if (USE_CUSTOM_BLACK_FRAME) {
539 mRotateFrameAnimation.restrictDuration(maxAnimationDuration);
540 mRotateFrameAnimation.scaleCurrentDuration(animationScale);
541 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800542
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700543 final int layerStack = mDisplayContent.getDisplay().getLayerStack();
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700544 if (USE_CUSTOM_BLACK_FRAME && mCustomBlackFrame == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800545 if (SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
546 TAG_WM,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800547 ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700548 mService.openSurfaceTransaction();
Dianne Hackborn50660e22011-02-02 17:12:25 -0800549
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800550 // Compute the transformation matrix that must be applied
551 // the the black frame to make it stay in the initial position
552 // before the new screen rotation. This is different than the
553 // snapshot transformation because the snapshot is always based
554 // of the native orientation of the screen, not the orientation
555 // we were last in.
556 createRotationMatrix(delta, mOriginalWidth, mOriginalHeight, mFrameInitialMatrix);
557
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800558 try {
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800559 Rect outer = new Rect(-mOriginalWidth*1, -mOriginalHeight*1,
560 mOriginalWidth*2, mOriginalHeight*2);
561 Rect inner = new Rect(0, 0, mOriginalWidth, mOriginalHeight);
Robert Carrb1579c82017-09-05 14:54:47 -0700562 mCustomBlackFrame = new BlackFrame(outer, inner,
563 SCREEN_FREEZE_LAYER_CUSTOM, mDisplayContent, false);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700564 mCustomBlackFrame.setMatrix(mFrameInitialMatrix);
Igor Murashkina86ab6402013-08-30 12:58:36 -0700565 } catch (OutOfResourcesException e) {
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700566 Slog.w(TAG, "Unable to allocate black surface", e);
567 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200568 mService.closeSurfaceTransaction("ScreenRotationAnimation.startAnimation");
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800569 if (SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
570 TAG_WM,
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700571 "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
572 }
573 }
574
Dianne Hackborn9d9ece32012-09-10 15:33:52 -0700575 if (!customAnim && mExitingBlackFrame == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800576 if (SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
577 TAG_WM,
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700578 ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700579 mService.openSurfaceTransaction();
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700580 try {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700581 // Compute the transformation matrix that must be applied
582 // the the black frame to make it stay in the initial position
583 // before the new screen rotation. This is different than the
584 // snapshot transformation because the snapshot is always based
585 // of the native orientation of the screen, not the orientation
586 // we were last in.
587 createRotationMatrix(delta, mOriginalWidth, mOriginalHeight, mFrameInitialMatrix);
588
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700589 final Rect outer;
590 final Rect inner;
591 if (mForceDefaultOrientation) {
592 // Going from a smaller Display to a larger Display, add curtains to sides
593 // or top and bottom. Going from a larger to smaller display will result in
594 // no BlackSurfaces being constructed.
595 outer = mCurrentDisplayRect;
596 inner = mOriginalDisplayRect;
597 } else {
598 outer = new Rect(-mOriginalWidth*1, -mOriginalHeight*1,
599 mOriginalWidth*2, mOriginalHeight*2);
600 inner = new Rect(0, 0, mOriginalWidth, mOriginalHeight);
601 }
Robert Carrb1579c82017-09-05 14:54:47 -0700602 mExitingBlackFrame = new BlackFrame(outer, inner,
603 SCREEN_FREEZE_LAYER_EXIT, mDisplayContent, mForceDefaultOrientation);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700604 mExitingBlackFrame.setMatrix(mFrameInitialMatrix);
Igor Murashkina86ab6402013-08-30 12:58:36 -0700605 } catch (OutOfResourcesException e) {
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700606 Slog.w(TAG, "Unable to allocate black surface", e);
607 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200608 mService.closeSurfaceTransaction("ScreenRotationAnimation.startAnimation");
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800609 if (SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
610 TAG_WM,
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700611 "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
612 }
613 }
614
Dianne Hackborn9d9ece32012-09-10 15:33:52 -0700615 if (customAnim && mEnteringBlackFrame == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800616 if (SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
617 TAG_WM,
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700618 ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700619 mService.openSurfaceTransaction();
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700620
621 try {
622 Rect outer = new Rect(-finalWidth*1, -finalHeight*1,
623 finalWidth*2, finalHeight*2);
624 Rect inner = new Rect(0, 0, finalWidth, finalHeight);
Robert Carrb1579c82017-09-05 14:54:47 -0700625 mEnteringBlackFrame = new BlackFrame(outer, inner,
626 SCREEN_FREEZE_LAYER_ENTER, mDisplayContent, false);
Igor Murashkina86ab6402013-08-30 12:58:36 -0700627 } catch (OutOfResourcesException e) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800628 Slog.w(TAG, "Unable to allocate black surface", e);
629 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200630 mService.closeSurfaceTransaction("ScreenRotationAnimation.startAnimation");
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800631 if (SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
632 TAG_WM,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800633 "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
634 }
Dianne Hackborn50660e22011-02-02 17:12:25 -0800635 }
636
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800637 return true;
638 }
639
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800640 /**
641 * Returns true if animating.
642 */
Robert Carrb1579c82017-09-05 14:54:47 -0700643 public boolean dismiss(long maxAnimationDuration,
Craig Mautner3c174372013-02-21 17:54:37 -0800644 float animationScale, int finalWidth, int finalHeight, int exitAnim, int enterAnim) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800645 if (DEBUG_STATE) Slog.v(TAG, "Dismiss!");
Mathias Agopian29479eb2013-02-14 14:36:04 -0800646 if (mSurfaceControl == null) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800647 // Can't do animation.
648 return false;
649 }
650 if (!mStarted) {
Robert Carrb1579c82017-09-05 14:54:47 -0700651 startAnimation(maxAnimationDuration, animationScale, finalWidth, finalHeight,
Craig Mautner3c174372013-02-21 17:54:37 -0800652 true, exitAnim, enterAnim);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800653 }
654 if (!mStarted) {
655 return false;
656 }
657 if (DEBUG_STATE) Slog.v(TAG, "Setting mFinishAnimReady = true");
658 mFinishAnimReady = true;
659 return true;
660 }
661
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800662 public void kill() {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800663 if (DEBUG_STATE) Slog.v(TAG, "Kill!");
Mathias Agopian29479eb2013-02-14 14:36:04 -0800664 if (mSurfaceControl != null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800665 if (SHOW_TRANSACTIONS ||
666 SHOW_SURFACE_ALLOC) Slog.i(TAG_WM,
Mathias Agopian29479eb2013-02-14 14:36:04 -0800667 " FREEZE " + mSurfaceControl + ": DESTROY");
668 mSurfaceControl.destroy();
669 mSurfaceControl = null;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800670 }
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700671 if (mCustomBlackFrame != null) {
672 mCustomBlackFrame.kill();
673 mCustomBlackFrame = null;
674 }
675 if (mExitingBlackFrame != null) {
676 mExitingBlackFrame.kill();
677 mExitingBlackFrame = null;
678 }
679 if (mEnteringBlackFrame != null) {
680 mEnteringBlackFrame.kill();
681 mEnteringBlackFrame = null;
Dianne Hackborn352cc982011-01-04 11:34:18 -0800682 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700683 if (TWO_PHASE_ANIMATION) {
684 if (mStartExitAnimation != null) {
685 mStartExitAnimation.cancel();
686 mStartExitAnimation = null;
687 }
688 if (mStartEnterAnimation != null) {
689 mStartEnterAnimation.cancel();
690 mStartEnterAnimation = null;
691 }
692 if (mFinishExitAnimation != null) {
693 mFinishExitAnimation.cancel();
694 mFinishExitAnimation = null;
695 }
696 if (mFinishEnterAnimation != null) {
697 mFinishEnterAnimation.cancel();
698 mFinishEnterAnimation = null;
699 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800700 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700701 if (USE_CUSTOM_BLACK_FRAME) {
702 if (mStartFrameAnimation != null) {
703 mStartFrameAnimation.cancel();
704 mStartFrameAnimation = null;
705 }
706 if (mRotateFrameAnimation != null) {
707 mRotateFrameAnimation.cancel();
708 mRotateFrameAnimation = null;
709 }
710 if (mFinishFrameAnimation != null) {
711 mFinishFrameAnimation.cancel();
712 mFinishFrameAnimation = null;
713 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800714 }
715 if (mRotateExitAnimation != null) {
716 mRotateExitAnimation.cancel();
717 mRotateExitAnimation = null;
718 }
719 if (mRotateEnterAnimation != null) {
720 mRotateEnterAnimation.cancel();
721 mRotateEnterAnimation = null;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800722 }
723 }
724
725 public boolean isAnimating() {
Craig Mautner7d8df392012-04-06 15:26:23 -0700726 return hasAnimations() || (TWO_PHASE_ANIMATION && mFinishAnimReady);
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700727 }
728
Dianne Hackborn4b169692012-11-29 17:51:24 -0800729 public boolean isRotating() {
730 return mCurRotation != mOriginalRotation;
731 }
732
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700733 private boolean hasAnimations() {
Craig Mautner7d8df392012-04-06 15:26:23 -0700734 return (TWO_PHASE_ANIMATION &&
735 (mStartEnterAnimation != null || mStartExitAnimation != null
736 || mFinishEnterAnimation != null || mFinishExitAnimation != null))
737 || (USE_CUSTOM_BLACK_FRAME &&
738 (mStartFrameAnimation != null || mRotateFrameAnimation != null
739 || mFinishFrameAnimation != null))
740 || mRotateEnterAnimation != null || mRotateExitAnimation != null;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800741 }
742
Craig Mautnere32c3072012-03-12 15:25:35 -0700743 private boolean stepAnimation(long now) {
Craig Mautner3255a282012-04-16 15:42:47 -0700744 if (now > mHalfwayPoint) {
745 mHalfwayPoint = Long.MAX_VALUE;
746 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800747 if (mFinishAnimReady && mFinishAnimStartTime < 0) {
748 if (DEBUG_STATE) Slog.v(TAG, "Step: finish anim now ready");
749 mFinishAnimStartTime = now;
750 }
751
Craig Mautner7d8df392012-04-06 15:26:23 -0700752 if (TWO_PHASE_ANIMATION) {
753 mMoreStartExit = false;
754 if (mStartExitAnimation != null) {
755 mMoreStartExit = mStartExitAnimation.getTransformation(now, mStartExitTransformation);
756 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start exit: " + mStartExitTransformation);
757 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800758
Craig Mautner7d8df392012-04-06 15:26:23 -0700759 mMoreStartEnter = false;
760 if (mStartEnterAnimation != null) {
761 mMoreStartEnter = mStartEnterAnimation.getTransformation(now, mStartEnterTransformation);
762 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start enter: " + mStartEnterTransformation);
763 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800764 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700765 if (USE_CUSTOM_BLACK_FRAME) {
766 mMoreStartFrame = false;
767 if (mStartFrameAnimation != null) {
768 mMoreStartFrame = mStartFrameAnimation.getTransformation(now, mStartFrameTransformation);
769 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start frame: " + mStartFrameTransformation);
770 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800771 }
772
Craig Mautnerdbb79912012-03-01 18:59:14 -0800773 long finishNow = mFinishAnimReady ? (now - mFinishAnimStartTime) : 0;
774 if (DEBUG_STATE) Slog.v(TAG, "Step: finishNow=" + finishNow);
775
Craig Mautner7d8df392012-04-06 15:26:23 -0700776 if (TWO_PHASE_ANIMATION) {
777 mMoreFinishExit = false;
778 if (mFinishExitAnimation != null) {
779 mMoreFinishExit = mFinishExitAnimation.getTransformation(finishNow, mFinishExitTransformation);
780 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish exit: " + mFinishExitTransformation);
781 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800782
Craig Mautner7d8df392012-04-06 15:26:23 -0700783 mMoreFinishEnter = false;
784 if (mFinishEnterAnimation != null) {
785 mMoreFinishEnter = mFinishEnterAnimation.getTransformation(finishNow, mFinishEnterTransformation);
786 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish enter: " + mFinishEnterTransformation);
787 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800788 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700789 if (USE_CUSTOM_BLACK_FRAME) {
790 mMoreFinishFrame = false;
791 if (mFinishFrameAnimation != null) {
792 mMoreFinishFrame = mFinishFrameAnimation.getTransformation(finishNow, mFinishFrameTransformation);
793 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish frame: " + mFinishFrameTransformation);
794 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800795 }
796
Craig Mautnerdbb79912012-03-01 18:59:14 -0800797 mMoreRotateExit = false;
798 if (mRotateExitAnimation != null) {
799 mMoreRotateExit = mRotateExitAnimation.getTransformation(now, mRotateExitTransformation);
800 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate exit: " + mRotateExitTransformation);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700801 }
802
803 mMoreRotateEnter = false;
804 if (mRotateEnterAnimation != null) {
805 mMoreRotateEnter = mRotateEnterAnimation.getTransformation(now, mRotateEnterTransformation);
806 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate enter: " + mRotateEnterTransformation);
807 }
808
Craig Mautner7d8df392012-04-06 15:26:23 -0700809 if (USE_CUSTOM_BLACK_FRAME) {
810 mMoreRotateFrame = false;
811 if (mRotateFrameAnimation != null) {
812 mMoreRotateFrame = mRotateFrameAnimation.getTransformation(now, mRotateFrameTransformation);
813 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate frame: " + mRotateFrameTransformation);
814 }
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700815 }
816
Craig Mautner7d8df392012-04-06 15:26:23 -0700817 if (!mMoreRotateExit && (!TWO_PHASE_ANIMATION || (!mMoreStartExit && !mMoreFinishExit))) {
818 if (TWO_PHASE_ANIMATION) {
819 if (mStartExitAnimation != null) {
820 if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, clearing start exit anim!");
821 mStartExitAnimation.cancel();
822 mStartExitAnimation = null;
823 mStartExitTransformation.clear();
824 }
825 if (mFinishExitAnimation != null) {
826 if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, clearing finish exit anim!");
827 mFinishExitAnimation.cancel();
828 mFinishExitAnimation = null;
829 mFinishExitTransformation.clear();
830 }
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700831 }
832 if (mRotateExitAnimation != null) {
833 if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, clearing rotate exit anim!");
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800834 mRotateExitAnimation.cancel();
835 mRotateExitAnimation = null;
836 mRotateExitTransformation.clear();
837 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800838 }
839
Craig Mautner7d8df392012-04-06 15:26:23 -0700840 if (!mMoreRotateEnter && (!TWO_PHASE_ANIMATION || (!mMoreStartEnter && !mMoreFinishEnter))) {
841 if (TWO_PHASE_ANIMATION) {
842 if (mStartEnterAnimation != null) {
843 if (DEBUG_STATE) Slog.v(TAG, "Enter animations done, clearing start enter anim!");
844 mStartEnterAnimation.cancel();
845 mStartEnterAnimation = null;
846 mStartEnterTransformation.clear();
847 }
848 if (mFinishEnterAnimation != null) {
849 if (DEBUG_STATE) Slog.v(TAG, "Enter animations done, clearing finish enter anim!");
850 mFinishEnterAnimation.cancel();
851 mFinishEnterAnimation = null;
852 mFinishEnterTransformation.clear();
853 }
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700854 }
855 if (mRotateEnterAnimation != null) {
856 if (DEBUG_STATE) Slog.v(TAG, "Enter animations done, clearing rotate enter anim!");
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800857 mRotateEnterAnimation.cancel();
858 mRotateEnterAnimation = null;
859 mRotateEnterTransformation.clear();
860 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800861 }
862
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700863 if (USE_CUSTOM_BLACK_FRAME && !mMoreStartFrame && !mMoreRotateFrame && !mMoreFinishFrame) {
864 if (mStartFrameAnimation != null) {
865 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, clearing start frame anim!");
866 mStartFrameAnimation.cancel();
867 mStartFrameAnimation = null;
868 mStartFrameTransformation.clear();
869 }
870 if (mFinishFrameAnimation != null) {
871 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, clearing finish frame anim!");
872 mFinishFrameAnimation.cancel();
873 mFinishFrameAnimation = null;
874 mFinishFrameTransformation.clear();
875 }
876 if (mRotateFrameAnimation != null) {
877 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, clearing rotate frame anim!");
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800878 mRotateFrameAnimation.cancel();
879 mRotateFrameAnimation = null;
880 mRotateFrameTransformation.clear();
881 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800882 }
883
884 mExitTransformation.set(mRotateExitTransformation);
Craig Mautnerdbb79912012-03-01 18:59:14 -0800885 mEnterTransformation.set(mRotateEnterTransformation);
Craig Mautner7d8df392012-04-06 15:26:23 -0700886 if (TWO_PHASE_ANIMATION) {
887 mExitTransformation.compose(mStartExitTransformation);
888 mExitTransformation.compose(mFinishExitTransformation);
889
890 mEnterTransformation.compose(mStartEnterTransformation);
891 mEnterTransformation.compose(mFinishEnterTransformation);
892 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800893
894 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final exit: " + mExitTransformation);
895 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final enter: " + mEnterTransformation);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700896
897 if (USE_CUSTOM_BLACK_FRAME) {
898 //mFrameTransformation.set(mRotateExitTransformation);
899 //mFrameTransformation.compose(mStartExitTransformation);
900 //mFrameTransformation.compose(mFinishExitTransformation);
901 mFrameTransformation.set(mRotateFrameTransformation);
902 mFrameTransformation.compose(mStartFrameTransformation);
903 mFrameTransformation.compose(mFinishFrameTransformation);
904 mFrameTransformation.getMatrix().preConcat(mFrameInitialMatrix);
905 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final frame: " + mFrameTransformation);
906 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800907
Craig Mautner7d8df392012-04-06 15:26:23 -0700908 final boolean more = (TWO_PHASE_ANIMATION
909 && (mMoreStartEnter || mMoreStartExit || mMoreFinishEnter || mMoreFinishExit))
910 || (USE_CUSTOM_BLACK_FRAME
911 && (mMoreStartFrame || mMoreRotateFrame || mMoreFinishFrame))
Igor Murashkina86ab6402013-08-30 12:58:36 -0700912 || mMoreRotateEnter || mMoreRotateExit
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800913 || !mFinishAnimReady;
Craig Mautnerdbb79912012-03-01 18:59:14 -0800914
915 mSnapshotFinalMatrix.setConcat(mExitTransformation.getMatrix(), mSnapshotInitialMatrix);
916
917 if (DEBUG_STATE) Slog.v(TAG, "Step: more=" + more);
918
919 return more;
920 }
921
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700922 void updateSurfacesInTransaction() {
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700923 if (!mStarted) {
924 return;
925 }
926
Mathias Agopian29479eb2013-02-14 14:36:04 -0800927 if (mSurfaceControl != null) {
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700928 if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
Craig Mautnerdbb79912012-03-01 18:59:14 -0800929 if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, hiding screenshot surface");
Mathias Agopian29479eb2013-02-14 14:36:04 -0800930 mSurfaceControl.hide();
Craig Mautnerdbb79912012-03-01 18:59:14 -0800931 }
932 }
933
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700934 if (mCustomBlackFrame != null) {
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700935 if (!mMoreStartFrame && !mMoreFinishFrame && !mMoreRotateFrame) {
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800936 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding black frame");
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700937 mCustomBlackFrame.hide();
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700938 } else {
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700939 mCustomBlackFrame.setMatrix(mFrameTransformation.getMatrix());
940 }
941 }
942
943 if (mExitingBlackFrame != null) {
944 if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
945 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding exiting frame");
946 mExitingBlackFrame.hide();
947 } else {
948 mExitFrameFinalMatrix.setConcat(mExitTransformation.getMatrix(), mFrameInitialMatrix);
949 mExitingBlackFrame.setMatrix(mExitFrameFinalMatrix);
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700950 if (mForceDefaultOrientation) {
951 mExitingBlackFrame.setAlpha(mExitTransformation.getAlpha());
952 }
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700953 }
954 }
955
956 if (mEnteringBlackFrame != null) {
957 if (!mMoreStartEnter && !mMoreFinishEnter && !mMoreRotateEnter) {
958 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding entering frame");
959 mEnteringBlackFrame.hide();
960 } else {
961 mEnteringBlackFrame.setMatrix(mEnterTransformation.getMatrix());
Craig Mautnerdbb79912012-03-01 18:59:14 -0800962 }
963 }
964
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700965 setSnapshotTransformInTransaction(mSnapshotFinalMatrix, mExitTransformation.getAlpha());
Craig Mautnerdbb79912012-03-01 18:59:14 -0800966 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700967
Craig Mautnere32c3072012-03-12 15:25:35 -0700968 public boolean stepAnimationLocked(long now) {
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700969 if (!hasAnimations()) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800970 if (DEBUG_STATE) Slog.v(TAG, "Step: no animations running");
Craig Mautnera731cd32012-03-02 15:23:55 -0800971 mFinishAnimReady = false;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800972 return false;
973 }
974
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800975 if (!mAnimRunning) {
976 if (DEBUG_STATE) Slog.v(TAG, "Step: starting start, finish, rotate");
Craig Mautner7d8df392012-04-06 15:26:23 -0700977 if (TWO_PHASE_ANIMATION) {
978 if (mStartEnterAnimation != null) {
979 mStartEnterAnimation.setStartTime(now);
980 }
981 if (mStartExitAnimation != null) {
982 mStartExitAnimation.setStartTime(now);
983 }
984 if (mFinishEnterAnimation != null) {
985 mFinishEnterAnimation.setStartTime(0);
986 }
987 if (mFinishExitAnimation != null) {
988 mFinishExitAnimation.setStartTime(0);
989 }
Dianne Hackborn89620282011-09-11 12:47:45 -0700990 }
Craig Mautner7d8df392012-04-06 15:26:23 -0700991 if (USE_CUSTOM_BLACK_FRAME) {
992 if (mStartFrameAnimation != null) {
993 mStartFrameAnimation.setStartTime(now);
994 }
995 if (mFinishFrameAnimation != null) {
996 mFinishFrameAnimation.setStartTime(0);
997 }
998 if (mRotateFrameAnimation != null) {
999 mRotateFrameAnimation.setStartTime(now);
1000 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -08001001 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -08001002 if (mRotateEnterAnimation != null) {
1003 mRotateEnterAnimation.setStartTime(now);
1004 }
1005 if (mRotateExitAnimation != null) {
1006 mRotateExitAnimation.setStartTime(now);
1007 }
1008 mAnimRunning = true;
Craig Mautner3255a282012-04-16 15:42:47 -07001009 mHalfwayPoint = now + mRotateEnterAnimation.getDuration() / 2;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08001010 }
Craig Mautnere32c3072012-03-12 15:25:35 -07001011
1012 return stepAnimation(now);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08001013 }
1014
1015 public Transformation getEnterTransformation() {
1016 return mEnterTransformation;
Dianne Hackborna1111872010-11-23 20:55:11 -08001017 }
1018}