blob: aa8e781b1c075af25ea12f07a0a0a376c59738d9 [file] [log] [blame]
Craig Mautnerc2c0a612014-02-20 20:25:41 -08001/*
2 * Copyright (C) 2014 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 */
Craig Mautnera2c77052012-03-26 12:14:43 -070016
17package com.android.server.wm;
18
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -070019import static android.app.ActivityManager.StackId;
Robert Carr1b5ea722016-04-20 13:23:28 -070020import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -080021import static android.view.Display.DEFAULT_DISPLAY;
Wale Ogunwalee7bf46b2015-09-30 09:19:28 -070022import static android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -080023import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070024import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Jorim Jaggieb88d832016-04-13 20:17:43 -070025import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
Jorim Jaggiff71d202016-04-14 13:12:36 -070026import static com.android.server.wm.AppWindowAnimator.sDummyAnimation;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +010027import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
Wale Ogunwale2728bf42016-03-03 11:03:26 -080028import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080029import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
30import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
31import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
32import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
33import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
34import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE;
35import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
36import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -080037import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_CROP;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080038import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
39import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
40import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
41import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
42import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang97782b42015-10-07 16:01:23 -070043import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -080044import static com.android.server.wm.WindowManagerService.localLOGV;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080045import static com.android.server.wm.WindowManagerService.logWithStack;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070046import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
47import static com.android.server.wm.WindowSurfacePlacer.SET_TURN_ON_SCREEN;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070048
Craig Mautnerc2f9be02012-03-27 17:32:29 -070049import android.content.Context;
50import android.graphics.Matrix;
51import android.graphics.PixelFormat;
Craig Mautner7358fbf2012-04-12 21:06:33 -070052import android.graphics.Point;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070053import android.graphics.Rect;
Robert Carr6da3cc02016-06-16 15:17:07 -070054import android.graphics.RectF;
Craig Mautner48ba1e72012-04-02 13:18:16 -070055import android.graphics.Region;
Craig Mautnera51a9562012-04-17 17:05:26 -070056import android.os.Debug;
Craig Mautner9c795042014-10-28 19:59:59 -070057import android.os.RemoteException;
Chong Zhang8784be62016-06-28 15:25:07 -070058import android.os.Trace;
Craig Mautnera2c77052012-03-26 12:14:43 -070059import android.util.Slog;
Craig Mautner59c00972012-07-30 12:10:24 -070060import android.view.DisplayInfo;
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -070061import android.view.MagnificationSpec;
Robert Carr6da3cc02016-06-16 15:17:07 -070062import android.view.Surface;
Igor Murashkina86ab6402013-08-30 12:58:36 -070063import android.view.Surface.OutOfResourcesException;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080064import android.view.SurfaceControl;
Craig Mautnera2c77052012-03-26 12:14:43 -070065import android.view.WindowManager;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070066import android.view.WindowManager.LayoutParams;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -080067import android.view.WindowManagerPolicy;
Craig Mautnera2c77052012-03-26 12:14:43 -070068import android.view.animation.Animation;
Jorim Jaggif8d77da2014-11-11 16:59:12 +010069import android.view.animation.AnimationSet;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070070import android.view.animation.AnimationUtils;
Craig Mautnera2c77052012-03-26 12:14:43 -070071import android.view.animation.Transformation;
72
73import com.android.server.wm.WindowManagerService.H;
74
75import java.io.PrintWriter;
76
77/**
Craig Mautnerc2f9be02012-03-27 17:32:29 -070078 * Keep track of animations and surface operations for a single WindowState.
79 **/
Craig Mautnera2c77052012-03-26 12:14:43 -070080class WindowStateAnimator {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080081 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowStateAnimator" : TAG_WM;
Chong Zhang97782b42015-10-07 16:01:23 -070082 static final int WINDOW_FREEZE_LAYER = TYPE_LAYER_MULTIPLIER * 200;
Craig Mautnera2c77052012-03-26 12:14:43 -070083
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010084 /**
85 * Mode how the window gets clipped by the stack bounds during an animation: The clipping should
86 * be applied after applying the animation transformation, i.e. the stack bounds don't move
87 * during the animation.
88 */
89 static final int STACK_CLIP_AFTER_ANIM = 0;
90
91 /**
92 * Mode how the window gets clipped by the stack bounds: The clipping should be applied before
93 * applying the animation transformation, i.e. the stack bounds move with the window.
94 */
95 static final int STACK_CLIP_BEFORE_ANIM = 1;
96
97 /**
98 * Mode how window gets clipped by the stack bounds during an animation: Don't clip the window
99 * by the stack bounds.
100 */
101 static final int STACK_CLIP_NONE = 2;
102
Craig Mautner918b53b2012-07-09 14:15:54 -0700103 // Unchanging local convenience fields.
Craig Mautnera2c77052012-03-26 12:14:43 -0700104 final WindowManagerService mService;
105 final WindowState mWin;
Craig Mautner322e4032012-07-13 13:35:20 -0700106 final WindowStateAnimator mAttachedWinAnimator;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700107 final WindowAnimator mAnimator;
Craig Mautner8863cca2012-09-18 15:04:34 -0700108 AppWindowAnimator mAppAnimator;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700109 final Session mSession;
110 final WindowManagerPolicy mPolicy;
111 final Context mContext;
Craig Mautner918b53b2012-07-09 14:15:54 -0700112 final boolean mIsWallpaper;
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700113 final WallpaperController mWallpaperControllerLocked;
Craig Mautnera2c77052012-03-26 12:14:43 -0700114
115 // Currently running animation.
116 boolean mAnimating;
117 boolean mLocalAnimating;
118 Animation mAnimation;
119 boolean mAnimationIsEntrance;
120 boolean mHasTransformation;
121 boolean mHasLocalTransformation;
122 final Transformation mTransformation = new Transformation();
123 boolean mWasAnimating; // Were we animating going into the most recent animation step?
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700124 int mAnimLayer;
125 int mLastLayer;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100126 long mAnimationStartTime;
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100127 long mLastAnimationTime;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100128 int mStackClip = STACK_CLIP_BEFORE_ANIM;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700129
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700130 /**
131 * Set when we have changed the size of the surface, to know that
132 * we must tell them application to resize (and thus redraw itself).
133 */
134 boolean mSurfaceResized;
Chong Zhang5b2f1992015-11-13 15:40:36 -0800135 /**
136 * Whether we should inform the client on next relayoutWindow that
137 * the surface has been resized since last time.
138 */
139 boolean mReportSurfaceResized;
Robert Carre6a83512015-11-03 16:09:21 -0800140 WindowSurfaceController mSurfaceController;
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800141 private WindowSurfaceController mPendingDestroySurface;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700142
143 /**
144 * Set if the client has asked that the destroy of its surface be delayed
145 * until it explicitly says it is okay.
146 */
147 boolean mSurfaceDestroyDeferred;
148
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800149 private boolean mDestroyPreservedSurfaceUponRedraw;
Craig Mautner7d8df392012-04-06 15:26:23 -0700150 float mShownAlpha = 0;
151 float mAlpha = 0;
152 float mLastAlpha = 0;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700153
Winson Chung399f6202014-03-19 10:47:20 -0700154 boolean mHasClipRect;
155 Rect mClipRect = new Rect();
156 Rect mTmpClipRect = new Rect();
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100157 Rect mTmpFinalClipRect = new Rect();
Winson Chung399f6202014-03-19 10:47:20 -0700158 Rect mLastClipRect = new Rect();
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100159 Rect mLastFinalClipRect = new Rect();
Filip Gruszczynski4b8eea72015-09-14 18:16:19 -0700160 Rect mTmpStackBounds = new Rect();
Winson Chung399f6202014-03-19 10:47:20 -0700161
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -0800162 /**
163 * This is rectangle of the window's surface that is not covered by
164 * system decorations.
165 */
166 private final Rect mSystemDecorRect = new Rect();
167 private final Rect mLastSystemDecorRect = new Rect();
168
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800169 // Used to save animation distances between the time they are calculated and when they are used.
170 private int mAnimDx;
171 private int mAnimDy;
Jorim Jaggic5af4f82015-07-01 17:16:27 -0700172
173 /** Is the next animation to be started a window move animation? */
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800174 private boolean mAnimateMove = false;
Jorim Jaggic5af4f82015-07-01 17:16:27 -0700175
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700176 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
177 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
178
179 boolean mHaveMatrix;
180
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700181 // Set to true if, when the window gets displayed, it should perform
182 // an enter animation.
183 boolean mEnterAnimationPending;
Craig Mautnera2c77052012-03-26 12:14:43 -0700184
Craig Mautner9c795042014-10-28 19:59:59 -0700185 /** Used to indicate that this window is undergoing an enter animation. Used for system
186 * windows to make the callback to View.dispatchOnWindowShownCallback(). Set when the
187 * window is first added or shown, cleared when the callback has been made. */
188 boolean mEnteringAnimation;
189
Jorim Jaggiff71d202016-04-14 13:12:36 -0700190 private boolean mAnimationStartDelayed;
191
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100192 boolean mKeyguardGoingAwayAnimation;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800193 boolean mKeyguardGoingAwayWithWallpaper;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200194
John Reck80181b92015-05-19 11:09:32 -0700195 /** The pixel format of the underlying SurfaceControl */
196 int mSurfaceFormat;
197
Craig Mautner749a7bb2012-04-02 13:49:53 -0700198 /** This is set when there is no Surface */
199 static final int NO_SURFACE = 0;
200 /** This is set after the Surface has been created but before the window has been drawn. During
201 * this time the surface is hidden. */
202 static final int DRAW_PENDING = 1;
203 /** This is set after the window has finished drawing for the first time but before its surface
204 * is shown. The surface will be displayed when the next layout is run. */
205 static final int COMMIT_DRAW_PENDING = 2;
206 /** This is set during the time after the window's drawing has been committed, and before its
207 * surface is actually shown. It is used to delay showing the surface until all windows in a
208 * token are ready to be shown. */
209 static final int READY_TO_SHOW = 3;
210 /** Set when the window has been shown in the screen the first time. */
211 static final int HAS_DRAWN = 4;
Adrian Roos3eeb4e62014-05-19 12:43:26 +0200212
Craig Mautner276a6eb2014-11-04 15:32:57 -0800213 String drawStateToString() {
214 switch (mDrawState) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700215 case NO_SURFACE: return "NO_SURFACE";
216 case DRAW_PENDING: return "DRAW_PENDING";
217 case COMMIT_DRAW_PENDING: return "COMMIT_DRAW_PENDING";
218 case READY_TO_SHOW: return "READY_TO_SHOW";
219 case HAS_DRAWN: return "HAS_DRAWN";
Craig Mautner276a6eb2014-11-04 15:32:57 -0800220 default: return Integer.toString(mDrawState);
Craig Mautner6fbda632012-07-03 09:26:39 -0700221 }
222 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700223 int mDrawState;
Craig Mautnera608b882012-03-30 13:03:49 -0700224
Craig Mautner749a7bb2012-04-02 13:49:53 -0700225 /** Was this window last hidden? */
226 boolean mLastHidden;
Craig Mautnera608b882012-03-30 13:03:49 -0700227
Craig Mautnerbec53f72012-04-05 11:49:05 -0700228 int mAttrType;
229
Robert Carr679c8072016-04-07 15:51:48 -0700230 static final long PENDING_TRANSACTION_FINISH_WAIT_TIME = 100;
Robert Carr679c8072016-04-07 15:51:48 -0700231
Robert Carrc7294602016-05-13 11:32:05 -0700232 boolean mForceScaleUntilResize;
233
Robert Carr04092112016-06-02 12:56:12 -0700234 // WindowState.mHScale and WindowState.mVScale contain the
235 // scale according to client specified layout parameters (e.g.
236 // one layout size, with another surface size, creates such scaling).
237 // Here we track an additional scaling factor used to follow stack
238 // scaling (as in the case of the Pinned stack animation).
239 float mExtraHScale = (float) 1.0;
240 float mExtraVScale = (float) 1.0;
241
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800242 private final Rect mTmpSize = new Rect();
243
Craig Mautnerc431e892015-02-11 13:14:26 -0800244 WindowStateAnimator(final WindowState win) {
Craig Mautner918b53b2012-07-09 14:15:54 -0700245 final WindowManagerService service = win.mService;
246
Craig Mautnera2c77052012-03-26 12:14:43 -0700247 mService = service;
Craig Mautner918b53b2012-07-09 14:15:54 -0700248 mAnimator = service.mAnimator;
249 mPolicy = service.mPolicy;
250 mContext = service.mContext;
Craig Mautnerd3849f52014-03-27 13:19:29 -0700251 final DisplayContent displayContent = win.getDisplayContent();
252 if (displayContent != null) {
253 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800254 mAnimDx = displayInfo.appWidth;
255 mAnimDy = displayInfo.appHeight;
Craig Mautnerd3849f52014-03-27 13:19:29 -0700256 } else {
257 Slog.w(TAG, "WindowStateAnimator ctor: Display has been removed");
258 // This is checked on return and dealt with.
259 }
Craig Mautner918b53b2012-07-09 14:15:54 -0700260
261 mWin = win;
Craig Mautner322e4032012-07-13 13:35:20 -0700262 mAttachedWinAnimator = win.mAttachedWindow == null
263 ? null : win.mAttachedWindow.mWinAnimator;
264 mAppAnimator = win.mAppToken == null ? null : win.mAppToken.mAppAnimator;
Craig Mautner918b53b2012-07-09 14:15:54 -0700265 mSession = win.mSession;
Craig Mautner918b53b2012-07-09 14:15:54 -0700266 mAttrType = win.mAttrs.type;
267 mIsWallpaper = win.mIsWallpaper;
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700268 mWallpaperControllerLocked = mService.mWallpaperControllerLocked;
Craig Mautnera2c77052012-03-26 12:14:43 -0700269 }
270
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100271 public void setAnimation(Animation anim, long startTime, int stackClip) {
Craig Mautnerbec53f72012-04-05 11:49:05 -0700272 if (localLOGV) Slog.v(TAG, "Setting animation in " + this + ": " + anim);
Craig Mautnera2c77052012-03-26 12:14:43 -0700273 mAnimating = false;
274 mLocalAnimating = false;
275 mAnimation = anim;
276 mAnimation.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION);
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700277 mAnimation.scaleCurrentDuration(mService.getWindowAnimationScaleLocked());
Craig Mautnera2c77052012-03-26 12:14:43 -0700278 // Start out animation gone if window is gone, or visible if window is visible.
279 mTransformation.clear();
Craig Mautner749a7bb2012-04-02 13:49:53 -0700280 mTransformation.setAlpha(mLastHidden ? 0 : 1);
Craig Mautnera2c77052012-03-26 12:14:43 -0700281 mHasLocalTransformation = true;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100282 mAnimationStartTime = startTime;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100283 mStackClip = stackClip;
284 }
285
286 public void setAnimation(Animation anim, int stackClip) {
287 setAnimation(anim, -1, stackClip);
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100288 }
289
290 public void setAnimation(Animation anim) {
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100291 setAnimation(anim, -1, STACK_CLIP_AFTER_ANIM);
Craig Mautnera2c77052012-03-26 12:14:43 -0700292 }
293
294 public void clearAnimation() {
295 if (mAnimation != null) {
296 mAnimating = true;
297 mLocalAnimating = false;
298 mAnimation.cancel();
299 mAnimation = null;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100300 mKeyguardGoingAwayAnimation = false;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800301 mKeyguardGoingAwayWithWallpaper = false;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100302 mStackClip = STACK_CLIP_BEFORE_ANIM;
Craig Mautnera2c77052012-03-26 12:14:43 -0700303 }
304 }
305
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700306 /**
307 * Is the window or its container currently set to animate or currently animating?
308 */
309 boolean isAnimationSet() {
Craig Mautnera2c77052012-03-26 12:14:43 -0700310 return mAnimation != null
Craig Mautner322e4032012-07-13 13:35:20 -0700311 || (mAttachedWinAnimator != null && mAttachedWinAnimator.mAnimation != null)
Jorim Jaggi37875612015-02-19 21:05:31 +0100312 || (mAppAnimator != null && mAppAnimator.isAnimating());
Craig Mautnera2c77052012-03-26 12:14:43 -0700313 }
314
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700315 /**
316 * @return whether an animation is about to start, i.e. the animation is set already but we
317 * haven't processed the first frame yet.
318 */
319 boolean isAnimationStarting() {
320 return isAnimationSet() && !mAnimating;
321 }
322
Craig Mautner0afddcb2012-05-08 15:38:00 -0700323 /** Is the window animating the DummyAnimation? */
324 boolean isDummyAnimation() {
Craig Mautner322e4032012-07-13 13:35:20 -0700325 return mAppAnimator != null
Jorim Jaggiff71d202016-04-14 13:12:36 -0700326 && mAppAnimator.animation == sDummyAnimation;
Craig Mautner0afddcb2012-05-08 15:38:00 -0700327 }
328
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700329 /**
330 * Is this window currently set to animate or currently animating?
331 */
332 boolean isWindowAnimationSet() {
Craig Mautnera2c77052012-03-26 12:14:43 -0700333 return mAnimation != null;
334 }
335
Chong Zhange22006d2016-05-09 10:59:59 -0700336 /**
337 * Is this window currently waiting to run an opening animation?
338 */
339 boolean isWaitingForOpening() {
340 return mService.mAppTransition.isTransitionSet() && isDummyAnimation()
341 && mService.mOpeningApps.contains(mWin.mAppToken);
342 }
343
Craig Mautnera2c77052012-03-26 12:14:43 -0700344 void cancelExitAnimationForNextAnimationLocked() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800345 if (DEBUG_ANIM) Slog.d(TAG,
346 "cancelExitAnimationForNextAnimationLocked: " + mWin);
347
Craig Mautnera2c77052012-03-26 12:14:43 -0700348 if (mAnimation != null) {
349 mAnimation.cancel();
350 mAnimation = null;
Craig Mautner4d7349b2012-04-20 14:52:47 -0700351 mLocalAnimating = false;
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800352 mWin.destroyOrSaveSurface();
Craig Mautnera2c77052012-03-26 12:14:43 -0700353 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700354 }
355
356 private boolean stepAnimation(long currentTime) {
357 if ((mAnimation == null) || !mLocalAnimating) {
358 return false;
359 }
Jorim Jaggiff71d202016-04-14 13:12:36 -0700360 currentTime = getAnimationFrameTime(mAnimation, currentTime);
Craig Mautnera2c77052012-03-26 12:14:43 -0700361 mTransformation.clear();
362 final boolean more = mAnimation.getTransformation(currentTime, mTransformation);
Jorim Jaggiff71d202016-04-14 13:12:36 -0700363 if (mAnimationStartDelayed && mAnimationIsEntrance) {
364 mTransformation.setAlpha(0f);
365 }
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700366 if (false && DEBUG_ANIM) Slog.v(TAG, "Stepped animation in " + this + ": more=" + more
367 + ", xform=" + mTransformation);
Craig Mautnera2c77052012-03-26 12:14:43 -0700368 return more;
369 }
370
371 // This must be called while inside a transaction. Returns true if
372 // there is more animation to run.
373 boolean stepAnimationLocked(long currentTime) {
Chet Haase9c450412015-10-01 13:25:58 -0700374 // Save the animation state as it was before this step so WindowManagerService can tell if
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700375 // we just started or just stopped animating by comparing mWasAnimating with isAnimationSet().
Chet Haase9c450412015-10-01 13:25:58 -0700376 mWasAnimating = mAnimating;
Craig Mautnerdf88d732014-01-27 09:21:32 -0800377 final DisplayContent displayContent = mWin.getDisplayContent();
378 if (displayContent != null && mService.okToDisplay()) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700379 // We will run animations as long as the display isn't frozen.
380
381 if (mWin.isDrawnLw() && mAnimation != null) {
382 mHasTransformation = true;
383 mHasLocalTransformation = true;
384 if (!mLocalAnimating) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700385 if (DEBUG_ANIM) Slog.v(
386 TAG, "Starting animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700387 " @ " + currentTime + ": ww=" + mWin.mFrame.width() +
388 " wh=" + mWin.mFrame.height() +
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800389 " dx=" + mAnimDx + " dy=" + mAnimDy +
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700390 " scale=" + mService.getWindowAnimationScaleLocked());
Craig Mautnerdf88d732014-01-27 09:21:32 -0800391 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
tiger_huangb7f3f922015-04-27 20:36:46 +0800392 if (mAnimateMove) {
393 mAnimateMove = false;
394 mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(),
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800395 mAnimDx, mAnimDy);
tiger_huangb7f3f922015-04-27 20:36:46 +0800396 } else {
397 mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(),
398 displayInfo.appWidth, displayInfo.appHeight);
399 }
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800400 mAnimDx = displayInfo.appWidth;
401 mAnimDy = displayInfo.appHeight;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100402 mAnimation.setStartTime(mAnimationStartTime != -1
403 ? mAnimationStartTime
404 : currentTime);
Craig Mautnera2c77052012-03-26 12:14:43 -0700405 mLocalAnimating = true;
406 mAnimating = true;
407 }
408 if ((mAnimation != null) && mLocalAnimating) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100409 mLastAnimationTime = currentTime;
Craig Mautnera2c77052012-03-26 12:14:43 -0700410 if (stepAnimation(currentTime)) {
411 return true;
412 }
413 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700414 if (DEBUG_ANIM) Slog.v(
415 TAG, "Finished animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700416 " @ " + currentTime);
417 //WindowManagerService.this.dump();
418 }
419 mHasLocalTransformation = false;
Craig Mautner322e4032012-07-13 13:35:20 -0700420 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppAnimator != null
421 && mAppAnimator.animation != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700422 // When our app token is animating, we kind-of pretend like
423 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
424 // part of this check means that we will only do this if
425 // our window is not currently exiting, or it is not
426 // locally animating itself. The idea being that one that
427 // is exiting and doing a local animation should be removed
428 // once that animation is done.
429 mAnimating = true;
430 mHasTransformation = true;
431 mTransformation.clear();
432 return false;
433 } else if (mHasTransformation) {
434 // Little trick to get through the path below to act like
435 // we have finished an animation.
436 mAnimating = true;
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700437 } else if (isAnimationSet()) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700438 mAnimating = true;
439 }
440 } else if (mAnimation != null) {
441 // If the display is frozen, and there is a pending animation,
442 // clear it and make sure we run the cleanup code.
443 mAnimating = true;
Craig Mautnera2c77052012-03-26 12:14:43 -0700444 }
445
446 if (!mAnimating && !mLocalAnimating) {
447 return false;
448 }
449
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700450 // Done animating, clean up.
451 if (DEBUG_ANIM) Slog.v(
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800452 TAG, "Animation done in " + this + ": exiting=" + mWin.mAnimatingExit
Craig Mautnera2c77052012-03-26 12:14:43 -0700453 + ", reportedVisible="
454 + (mWin.mAppToken != null ? mWin.mAppToken.reportedVisible : false));
455
456 mAnimating = false;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100457 mKeyguardGoingAwayAnimation = false;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800458 mKeyguardGoingAwayWithWallpaper = false;
Craig Mautnera2c77052012-03-26 12:14:43 -0700459 mLocalAnimating = false;
460 if (mAnimation != null) {
461 mAnimation.cancel();
462 mAnimation = null;
463 }
Craig Mautnere7ae2502012-03-26 17:11:19 -0700464 if (mAnimator.mWindowDetachedWallpaper == mWin) {
465 mAnimator.mWindowDetachedWallpaper = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700466 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -0800467 mAnimLayer = mWin.mLayer
468 + mService.mLayersController.getSpecialWindowAnimLayerAdjustment(mWin);
Filip Gruszczynski14b4e572015-11-03 15:53:55 -0800469 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this + " anim layer: " + mAnimLayer);
Craig Mautnera2c77052012-03-26 12:14:43 -0700470 mHasTransformation = false;
471 mHasLocalTransformation = false;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100472 mStackClip = STACK_CLIP_BEFORE_ANIM;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -0800473 mWin.checkPolicyVisibilityChange();
Craig Mautnera2c77052012-03-26 12:14:43 -0700474 mTransformation.clear();
Craig Mautner749a7bb2012-04-02 13:49:53 -0700475 if (mDrawState == HAS_DRAWN
Craig Mautnera2c77052012-03-26 12:14:43 -0700476 && mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
477 && mWin.mAppToken != null
478 && mWin.mAppToken.firstWindowDrawn
479 && mWin.mAppToken.startingData != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700480 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
Craig Mautnera2c77052012-03-26 12:14:43 -0700481 + mWin.mToken + ": first real window done animating");
482 mService.mFinishedStarting.add(mWin.mAppToken);
483 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
Craig Mautner81defc72013-10-29 11:10:42 -0700484 } else if (mAttrType == LayoutParams.TYPE_STATUS_BAR && mWin.mPolicyVisibility) {
485 // Upon completion of a not-visible to visible status bar animation a relayout is
486 // required.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800487 if (displayContent != null) {
488 displayContent.layoutNeeded = true;
489 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700490 }
491
492 finishExit();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800493 final int displayId = mWin.getDisplayId();
Craig Mautner76a71652012-09-03 23:23:58 -0700494 mAnimator.setPendingLayoutChanges(displayId, WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800495 if (DEBUG_LAYOUT_REPEATS)
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700496 mService.mWindowPlacerLocked.debugLayoutRepeats(
497 "WindowStateAnimator", mAnimator.getPendingLayoutChanges(displayId));
Craig Mautnera2c77052012-03-26 12:14:43 -0700498
499 if (mWin.mAppToken != null) {
500 mWin.mAppToken.updateReportedVisibilityLocked();
501 }
502
503 return false;
504 }
505
506 void finishExit() {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800507 if (DEBUG_ANIM) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700508 TAG, "finishExit in " + this
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800509 + ": exiting=" + mWin.mAnimatingExit
Craig Mautnera2c77052012-03-26 12:14:43 -0700510 + " remove=" + mWin.mRemoveOnExit
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700511 + " windowAnimating=" + isWindowAnimationSet());
Craig Mautnera2c77052012-03-26 12:14:43 -0700512
Wale Ogunwale33fde7d2016-03-05 22:38:51 -0800513 if (!mWin.mChildWindows.isEmpty()) {
514 // Copying to a different list as multiple children can be removed.
515 final WindowList childWindows = new WindowList(mWin.mChildWindows);
516 for (int i = childWindows.size() - 1; i >= 0; i--) {
517 childWindows.get(i).mWinAnimator.finishExit();
518 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700519 }
520
Filip Gruszczynski57f76f12015-11-04 16:10:54 -0800521 if (mEnteringAnimation) {
522 mEnteringAnimation = false;
523 mService.requestTraversal();
524 // System windows don't have an activity and an app token as a result, but need a way
525 // to be informed about their entrance animation end.
526 if (mWin.mAppToken == null) {
527 try {
528 mWin.mClient.dispatchWindowShown();
529 } catch (RemoteException e) {
530 }
Craig Mautner9c795042014-10-28 19:59:59 -0700531 }
532 }
533
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700534 if (!isWindowAnimationSet()) {
Svetoslav75b55d02014-12-03 16:26:35 -0800535 //TODO (multidisplay): Accessibility is supported only for the default display.
536 if (mService.mAccessibilityController != null
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800537 && mWin.getDisplayId() == DEFAULT_DISPLAY) {
Svetoslav75b55d02014-12-03 16:26:35 -0800538 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
539 }
540 }
541
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800542 if (!mWin.mAnimatingExit) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700543 return;
544 }
545
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700546 if (isWindowAnimationSet()) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700547 return;
548 }
549
Wale Ogunwale2728bf42016-03-03 11:03:26 -0800550 if (WindowManagerService.localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
551 "Exit animation finished in " + this + ": remove=" + mWin.mRemoveOnExit);
Robert Carre12aece2016-02-02 22:43:27 -0800552
553
554 mWin.mDestroying = true;
555
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800556 final boolean hasSurface = hasSurface();
557 if (hasSurface) {
558 hide("finishExit");
559 }
560
Robert Carre12aece2016-02-02 22:43:27 -0800561 // If we have an app token, we ask it to destroy the surface for us,
562 // so that it can take care to ensure the activity has actually stopped
563 // and the surface is not still in use. Otherwise we add the service to
564 // mDestroySurface and allow it to be processed in our next transaction.
565 if (mWin.mAppToken != null) {
Robert Carre12aece2016-02-02 22:43:27 -0800566 mWin.mAppToken.destroySurfaces();
567 } else {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800568 if (hasSurface) {
Robert Carre12aece2016-02-02 22:43:27 -0800569 mService.mDestroySurface.add(mWin);
Robert Carre12aece2016-02-02 22:43:27 -0800570 }
Robert Carre12aece2016-02-02 22:43:27 -0800571 if (mWin.mRemoveOnExit) {
572 mService.mPendingRemove.add(mWin);
573 mWin.mRemoveOnExit = false;
574 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700575 }
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800576 mWin.mAnimatingExit = false;
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700577 mWallpaperControllerLocked.hideWallpapers(mWin);
Craig Mautner0afddcb2012-05-08 15:38:00 -0700578 }
579
Filip Gruszczynski63a35e22015-11-05 15:38:59 -0800580 void hide(String reason) {
Craig Mautner0afddcb2012-05-08 15:38:00 -0700581 if (!mLastHidden) {
582 //dump();
583 mLastHidden = true;
Wale Ogunwalef9e09782015-11-09 12:42:37 -0800584 if (mSurfaceController != null) {
585 mSurfaceController.hideInTransaction(reason);
586 }
Craig Mautner0afddcb2012-05-08 15:38:00 -0700587 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700588 }
589
Craig Mautnera608b882012-03-30 13:03:49 -0700590 boolean finishDrawingLocked() {
Craig Mautner42d04db2014-11-06 12:13:23 -0800591 final boolean startingWindow =
592 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
593 if (DEBUG_STARTING_WINDOW && startingWindow) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700594 Slog.v(TAG, "Finishing drawing window " + mWin + ": mDrawState="
Craig Mautner276a6eb2014-11-04 15:32:57 -0800595 + drawStateToString());
Craig Mautner6fbda632012-07-03 09:26:39 -0700596 }
Robert Carr1ca6a332016-04-11 18:00:43 -0700597
Chong Zhangcbbcc0f2016-05-17 20:46:58 -0700598 boolean layoutNeeded = mWin.clearAnimatingWithSavedSurface();
Chong Zhang92147042016-05-09 12:47:11 -0700599
Craig Mautner749a7bb2012-04-02 13:49:53 -0700600 if (mDrawState == DRAW_PENDING) {
Craig Mautneref25d7a2012-05-15 23:01:47 -0700601 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
Chong Zhang5b2f1992015-11-13 15:40:36 -0800602 Slog.v(TAG, "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING " + mWin + " in "
Robert Carre6a83512015-11-03 16:09:21 -0800603 + mSurfaceController);
Craig Mautner42d04db2014-11-06 12:13:23 -0800604 if (DEBUG_STARTING_WINDOW && startingWindow) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700605 Slog.v(TAG, "Draw state now committed in " + mWin);
606 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700607 mDrawState = COMMIT_DRAW_PENDING;
Chong Zhangcbbcc0f2016-05-17 20:46:58 -0700608 layoutNeeded = true;
Craig Mautnera608b882012-03-30 13:03:49 -0700609 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700610
Chong Zhangcbbcc0f2016-05-17 20:46:58 -0700611 return layoutNeeded;
Craig Mautnera608b882012-03-30 13:03:49 -0700612 }
613
614 // This must be called while inside a transaction.
Craig Mautnerc431e892015-02-11 13:14:26 -0800615 boolean commitFinishDrawingLocked() {
Craig Mautner6fbda632012-07-03 09:26:39 -0700616 if (DEBUG_STARTING_WINDOW &&
617 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
618 Slog.i(TAG, "commitFinishDrawingLocked: " + mWin + " cur mDrawState="
Craig Mautner276a6eb2014-11-04 15:32:57 -0800619 + drawStateToString());
Craig Mautner6fbda632012-07-03 09:26:39 -0700620 }
Craig Mautner276a6eb2014-11-04 15:32:57 -0800621 if (mDrawState != COMMIT_DRAW_PENDING && mDrawState != READY_TO_SHOW) {
Craig Mautnera608b882012-03-30 13:03:49 -0700622 return false;
623 }
Craig Mautner6fbda632012-07-03 09:26:39 -0700624 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) {
Robert Carre6a83512015-11-03 16:09:21 -0800625 Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurfaceController);
Craig Mautner6fbda632012-07-03 09:26:39 -0700626 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700627 mDrawState = READY_TO_SHOW;
Chong Zhang0275e392015-09-17 10:41:44 -0700628 boolean result = false;
Craig Mautnera608b882012-03-30 13:03:49 -0700629 final AppWindowToken atoken = mWin.mAppToken;
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800630 if (atoken == null || atoken.allDrawn || mWin.mAttrs.type == TYPE_APPLICATION_STARTING) {
Chong Zhang0275e392015-09-17 10:41:44 -0700631 result = performShowLocked();
632 }
Chong Zhang97782b42015-10-07 16:01:23 -0700633 return result;
Craig Mautnera608b882012-03-30 13:03:49 -0700634 }
635
Chong Zhang97782b42015-10-07 16:01:23 -0700636 void preserveSurfaceLocked() {
637 if (mDestroyPreservedSurfaceUponRedraw) {
Chong Zhangb9b0fec2016-02-11 18:51:51 -0800638 // This could happen when switching the surface mode very fast. For example,
639 // we preserved a surface when dragResizing changed to true. Then before the
640 // preserved surface is removed, dragResizing changed to false again.
641 // In this case, we need to leave the preserved surface alone, and destroy
642 // the actual surface, so that the createSurface call could create a surface
643 // of the proper size. The preserved surface will still be removed when client
644 // finishes drawing to the new surface.
645 mSurfaceDestroyDeferred = false;
646 destroySurfaceLocked();
647 mSurfaceDestroyDeferred = true;
Chong Zhang97782b42015-10-07 16:01:23 -0700648 return;
649 }
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -0800650 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, "SET FREEZE LAYER", false);
Wale Ogunwalef9e09782015-11-09 12:42:37 -0800651 if (mSurfaceController != null) {
652 mSurfaceController.setLayer(mAnimLayer + 1);
653 }
Chong Zhang97782b42015-10-07 16:01:23 -0700654 mDestroyPreservedSurfaceUponRedraw = true;
655 mSurfaceDestroyDeferred = true;
656 destroySurfaceLocked();
657 }
658
659 void destroyPreservedSurfaceLocked() {
660 if (!mDestroyPreservedSurfaceUponRedraw) {
661 return;
662 }
663 destroyDeferredSurfaceLocked();
664 mDestroyPreservedSurfaceUponRedraw = false;
665 }
666
Chong Zhangeb665572016-05-09 18:28:27 -0700667 void markPreservedSurfaceForDestroy() {
668 if (mDestroyPreservedSurfaceUponRedraw
669 && !mService.mDestroyPreservedSurface.contains(mWin)) {
670 mService.mDestroyPreservedSurface.add(mWin);
671 }
672 }
673
Robert Carre6a83512015-11-03 16:09:21 -0800674 WindowSurfaceController createSurfaceLocked() {
Alan Viveretteccb11e12014-07-08 16:04:02 -0700675 final WindowState w = mWin;
Chong Zhanga8975bd2016-01-28 17:13:47 -0800676 if (w.hasSavedSurface()) {
Chong Zhang0464a932016-02-03 11:47:16 -0800677 if (DEBUG_ANIM) Slog.i(TAG,
678 "createSurface: " + this + ": called when we had a saved surface");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800679 w.restoreSavedSurface();
680 return mSurfaceController;
Chong Zhanga8975bd2016-01-28 17:13:47 -0800681 }
682
Wale Ogunwale722ff892016-02-18 13:37:55 -0800683 if (mSurfaceController != null) {
684 return mSurfaceController;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700685 }
Wale Ogunwale722ff892016-02-18 13:37:55 -0800686
687 w.setHasSurface(false);
688
689 if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG,
690 "createSurface " + this + ": mDrawState=DRAW_PENDING");
691
692 mDrawState = DRAW_PENDING;
693 if (w.mAppToken != null) {
694 if (w.mAppToken.mAppAnimator.animation == null) {
Chong Zhang92147042016-05-09 12:47:11 -0700695 w.mAppToken.clearAllDrawn();
Wale Ogunwale722ff892016-02-18 13:37:55 -0800696 } else {
697 // Currently animating, persist current state of allDrawn until animation
698 // is complete.
699 w.mAppToken.deferClearAllDrawn = true;
700 }
701 }
702
703 mService.makeWindowFreezingScreenIfNeededLocked(w);
704
705 int flags = SurfaceControl.HIDDEN;
706 final WindowManager.LayoutParams attrs = w.mAttrs;
707
708 if (mService.isSecureLocked(w)) {
709 flags |= SurfaceControl.SECURE;
710 }
711
712 mTmpSize.set(w.mFrame.left + w.mXOffset, w.mFrame.top + w.mYOffset, 0, 0);
713 calculateSurfaceBounds(w, attrs);
714 final int width = mTmpSize.width();
715 final int height = mTmpSize.height();
716
717 if (DEBUG_VISIBILITY) {
718 Slog.v(TAG, "Creating surface in session "
719 + mSession.mSurfaceSession + " window " + this
720 + " w=" + width + " h=" + height
721 + " x=" + mTmpSize.left + " y=" + mTmpSize.top
722 + " format=" + attrs.format + " flags=" + flags);
723 }
724
725 // We may abort, so initialize to defaults.
726 mLastSystemDecorRect.set(0, 0, 0, 0);
727 mHasClipRect = false;
728 mClipRect.set(0, 0, 0, 0);
729 mLastClipRect.set(0, 0, 0, 0);
730
731 // Set up surface control with initial size.
732 try {
733
734 final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0;
735 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
736 if (!PixelFormat.formatHasAlpha(attrs.format)
737 // Don't make surface with surfaceInsets opaque as they display a
738 // translucent shadow.
739 && attrs.surfaceInsets.left == 0
740 && attrs.surfaceInsets.top == 0
741 && attrs.surfaceInsets.right == 0
742 && attrs.surfaceInsets.bottom == 0
743 // Don't make surface opaque when resizing to reduce the amount of
744 // artifacts shown in areas the app isn't drawing content to.
745 && !w.isDragResizing()) {
746 flags |= SurfaceControl.OPAQUE;
747 }
748
749 mSurfaceController = new WindowSurfaceController(mSession.mSurfaceSession,
750 attrs.getTitle().toString(),
751 width, height, format, flags, this);
752
753 w.setHasSurface(true);
754
755 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
756 Slog.i(TAG, " CREATE SURFACE "
757 + mSurfaceController + " IN SESSION "
758 + mSession.mSurfaceSession
759 + ": pid=" + mSession.mPid + " format="
760 + attrs.format + " flags=0x"
761 + Integer.toHexString(flags)
762 + " / " + this);
763 }
764 } catch (OutOfResourcesException e) {
765 Slog.w(TAG, "OutOfResourcesException creating surface");
766 mService.reclaimSomeSurfaceMemoryLocked(this, "create", true);
767 mDrawState = NO_SURFACE;
768 return null;
769 } catch (Exception e) {
770 Slog.e(TAG, "Exception creating surface", e);
771 mDrawState = NO_SURFACE;
772 return null;
773 }
774
775 if (WindowManagerService.localLOGV) Slog.v(TAG, "Got surface: " + mSurfaceController
776 + ", set left=" + w.mFrame.left + " top=" + w.mFrame.top
777 + ", animLayer=" + mAnimLayer);
778
779 if (SHOW_LIGHT_TRANSACTIONS) {
780 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
781 WindowManagerService.logSurface(w, "CREATE pos=("
782 + w.mFrame.left + "," + w.mFrame.top + ") ("
783 + width + "x" + height + "), layer=" + mAnimLayer + " HIDE", false);
784 }
785
786 // Start a new transaction and apply position & offset.
787 final int layerStack = w.getDisplayContent().getDisplay().getLayerStack();
Wale Ogunwale722ff892016-02-18 13:37:55 -0800788 mSurfaceController.setPositionAndLayer(mTmpSize.left, mTmpSize.top, layerStack, mAnimLayer);
789 mLastHidden = true;
790
791 if (WindowManagerService.localLOGV) Slog.v(TAG, "Created surface " + this);
Robert Carre6a83512015-11-03 16:09:21 -0800792 return mSurfaceController;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700793 }
794
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800795 private void calculateSurfaceBounds(WindowState w, LayoutParams attrs) {
796 if ((attrs.flags & FLAG_SCALED) != 0) {
797 // For a scaled surface, we always want the requested size.
798 mTmpSize.right = mTmpSize.left + w.mRequestedWidth;
799 mTmpSize.bottom = mTmpSize.top + w.mRequestedHeight;
800 } else {
801 // When we're doing a drag-resizing, request a surface that's fullscreen size,
802 // so that we don't need to reallocate during the process. This also prevents
803 // buffer drops due to size mismatch.
804 if (w.isDragResizing()) {
805 if (w.getResizeMode() == DRAG_RESIZE_MODE_FREEFORM) {
806 mTmpSize.left = 0;
807 mTmpSize.top = 0;
808 }
809 final DisplayInfo displayInfo = w.getDisplayInfo();
810 mTmpSize.right = mTmpSize.left + displayInfo.logicalWidth;
811 mTmpSize.bottom = mTmpSize.top + displayInfo.logicalHeight;
812 } else {
813 mTmpSize.right = mTmpSize.left + w.mCompatFrame.width();
814 mTmpSize.bottom = mTmpSize.top + w.mCompatFrame.height();
815 }
816 }
817
818 // Something is wrong and SurfaceFlinger will not like this, try to revert to sane values.
Filip Gruszczynskie6ed1952015-12-21 09:34:16 -0800819 // This doesn't necessarily mean that there is an error in the system. The sizes might be
820 // incorrect, because it is before the first layout or draw.
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800821 if (mTmpSize.width() < 1) {
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800822 mTmpSize.right = mTmpSize.left + 1;
823 }
824 if (mTmpSize.height() < 1) {
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800825 mTmpSize.bottom = mTmpSize.top + 1;
826 }
827
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800828 // Adjust for surface insets.
Phil Weavera4b32b92016-06-02 13:55:39 -0700829 mTmpSize.left -= attrs.surfaceInsets.left;
830 mTmpSize.top -= attrs.surfaceInsets.top;
831 mTmpSize.right += attrs.surfaceInsets.right;
832 mTmpSize.bottom += attrs.surfaceInsets.bottom;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800833 }
834
Chong Zhangeb22e8e2016-01-20 19:52:22 -0800835 boolean hasSurface() {
Chong Zhang92147042016-05-09 12:47:11 -0700836 return !mWin.hasSavedSurface()
Chong Zhangeb22e8e2016-01-20 19:52:22 -0800837 && mSurfaceController != null && mSurfaceController.hasSurface();
838 }
839
Craig Mautner96868332012-12-04 14:29:11 -0800840 void destroySurfaceLocked() {
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700841 final AppWindowToken wtoken = mWin.mAppToken;
842 if (wtoken != null) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700843 if (mWin == wtoken.startingWindow) {
844 wtoken.startingDisplayed = false;
845 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700846 }
847
Chong Zhang92147042016-05-09 12:47:11 -0700848 mWin.clearHasSavedSurface();
Robert Carr13f7be9e2015-12-02 18:39:45 -0800849
Wale Ogunwale722ff892016-02-18 13:37:55 -0800850 if (mSurfaceController == null) {
851 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700852 }
Wale Ogunwale722ff892016-02-18 13:37:55 -0800853
854 int i = mWin.mChildWindows.size();
855 // When destroying a surface we want to make sure child windows are hidden. If we are
856 // preserving the surface until redraw though we intend to swap it out with another surface
857 // for resizing. In this case the window always remains visible to the user and the child
858 // windows should likewise remain visible.
859 while (!mDestroyPreservedSurfaceUponRedraw && i > 0) {
860 i--;
861 WindowState c = mWin.mChildWindows.get(i);
862 c.mAttachedHidden = true;
863 }
864
865 try {
866 if (DEBUG_VISIBILITY) logWithStack(TAG, "Window " + this + " destroying surface "
867 + mSurfaceController + ", session " + mSession);
868 if (mSurfaceDestroyDeferred) {
869 if (mSurfaceController != null && mPendingDestroySurface != mSurfaceController) {
870 if (mPendingDestroySurface != null) {
871 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
872 WindowManagerService.logSurface(mWin, "DESTROY PENDING", true);
873 }
874 mPendingDestroySurface.destroyInTransaction();
875 }
876 mPendingDestroySurface = mSurfaceController;
877 }
878 } else {
879 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
880 WindowManagerService.logSurface(mWin, "DESTROY", true);
881 }
882 destroySurface();
883 }
884 // Don't hide wallpaper if we're deferring the surface destroy
885 // because of a surface change.
886 if (!mDestroyPreservedSurfaceUponRedraw) {
887 mWallpaperControllerLocked.hideWallpapers(mWin);
888 }
889 } catch (RuntimeException e) {
890 Slog.w(TAG, "Exception thrown when destroying Window " + this
891 + " surface " + mSurfaceController + " session " + mSession + ": " + e.toString());
892 }
893
894 // Whether the surface was preserved (and copied to mPendingDestroySurface) or not, it
895 // needs to be cleared to match the WindowState.mHasSurface state. It is also necessary
896 // so it can be recreated successfully in mPendingDestroySurface case.
897 mWin.setHasSurface(false);
898 if (mSurfaceController != null) {
899 mSurfaceController.setShown(false);
900 }
901 mSurfaceController = null;
902 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700903 }
904
Craig Mautner96868332012-12-04 14:29:11 -0800905 void destroyDeferredSurfaceLocked() {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700906 try {
907 if (mPendingDestroySurface != null) {
908 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -0800909 WindowManagerService.logSurface(mWin, "DESTROY PENDING", true);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700910 }
Robert Carre6a83512015-11-03 16:09:21 -0800911 mPendingDestroySurface.destroyInTransaction();
Chong Zhang6e21cf42015-11-09 14:41:42 -0800912 // Don't hide wallpaper if we're destroying a deferred surface
913 // after a surface mode change.
914 if (!mDestroyPreservedSurfaceUponRedraw) {
915 mWallpaperControllerLocked.hideWallpapers(mWin);
916 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700917 }
918 } catch (RuntimeException e) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700919 Slog.w(TAG, "Exception thrown when destroying Window "
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700920 + this + " surface " + mPendingDestroySurface
921 + " session " + mSession + ": " + e.toString());
922 }
923 mSurfaceDestroyDeferred = false;
924 mPendingDestroySurface = null;
925 }
926
Robert Carr298f9272016-08-09 13:08:01 -0700927 void applyMagnificationSpec(MagnificationSpec spec, Matrix transform) {
928 final int surfaceInsetLeft = mWin.mAttrs.surfaceInsets.left;
929 final int surfaceInsetTop = mWin.mAttrs.surfaceInsets.top;
930
931 if (spec != null && !spec.isNop()) {
932 float scale = spec.scale;
933 transform.postScale(scale, scale);
934 transform.postTranslate(spec.offsetX, spec.offsetY);
935
936 // As we are scaling the whole surface, to keep the content
937 // in the same position we will also have to scale the surfaceInsets.
938 transform.postTranslate(-(surfaceInsetLeft*scale - surfaceInsetLeft),
939 -(surfaceInsetTop*scale - surfaceInsetTop));
940 }
941 }
942
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700943 void computeShownFrameLocked() {
944 final boolean selfTransformation = mHasLocalTransformation;
945 Transformation attachedTransformation =
Craig Mautner322e4032012-07-13 13:35:20 -0700946 (mAttachedWinAnimator != null && mAttachedWinAnimator.mHasLocalTransformation)
947 ? mAttachedWinAnimator.mTransformation : null;
948 Transformation appTransformation = (mAppAnimator != null && mAppAnimator.hasTransformation)
949 ? mAppAnimator.transformation : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700950
951 // Wallpapers are animated based on the "real" window they
952 // are currently targeting.
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700953 final WindowState wallpaperTarget = mWallpaperControllerLocked.getWallpaperTarget();
Craig Mautner798adef2013-10-22 14:29:01 -0700954 if (mIsWallpaper && wallpaperTarget != null && mService.mAnimateWallpaperWithTarget) {
955 final WindowStateAnimator wallpaperAnimator = wallpaperTarget.mWinAnimator;
Craig Mautner918b53b2012-07-09 14:15:54 -0700956 if (wallpaperAnimator.mHasLocalTransformation &&
957 wallpaperAnimator.mAnimation != null &&
958 !wallpaperAnimator.mAnimation.getDetachWallpaper()) {
959 attachedTransformation = wallpaperAnimator.mTransformation;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800960 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700961 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
962 }
963 }
Craig Mautner798adef2013-10-22 14:29:01 -0700964 final AppWindowAnimator wpAppAnimator = wallpaperTarget.mAppToken == null ?
965 null : wallpaperTarget.mAppToken.mAppAnimator;
966 if (wpAppAnimator != null && wpAppAnimator.hasTransformation
Craig Mautner918b53b2012-07-09 14:15:54 -0700967 && wpAppAnimator.animation != null
968 && !wpAppAnimator.animation.getDetachWallpaper()) {
Craig Mautner59431632012-04-04 11:56:44 -0700969 appTransformation = wpAppAnimator.transformation;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800970 if (DEBUG_WALLPAPER && appTransformation != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700971 Slog.v(TAG, "WP target app xform: " + appTransformation);
972 }
973 }
974 }
975
Craig Mautnera91f9e22012-09-14 16:22:08 -0700976 final int displayId = mWin.getDisplayId();
977 final ScreenRotationAnimation screenRotationAnimation =
978 mAnimator.getScreenRotationAnimationLocked(displayId);
979 final boolean screenAnimation =
980 screenRotationAnimation != null && screenRotationAnimation.isAnimating();
Robert Carr2f0fe622015-09-25 14:56:38 -0700981
982 mHasClipRect = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700983 if (selfTransformation || attachedTransformation != null
984 || appTransformation != null || screenAnimation) {
985 // cache often used attributes locally
986 final Rect frame = mWin.mFrame;
987 final float tmpFloats[] = mService.mTmpFloats;
988 final Matrix tmpMatrix = mWin.mTmpMatrix;
989
990 // Compute the desired transformation.
Dianne Hackborn4b169692012-11-29 17:51:24 -0800991 if (screenAnimation && screenRotationAnimation.isRotating()) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700992 // If we are doing a screen animation, the global rotation
993 // applied to windows can result in windows that are carefully
994 // aligned with each other to slightly separate, allowing you
995 // to see what is behind them. An unsightly mess. This...
996 // thing... magically makes it call good: scale each window
997 // slightly (two pixels larger in each dimension, from the
998 // window's center).
999 final float w = frame.width();
1000 final float h = frame.height();
1001 if (w>=1 && h>=1) {
1002 tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2);
1003 } else {
1004 tmpMatrix.reset();
1005 }
1006 } else {
1007 tmpMatrix.reset();
1008 }
1009 tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale);
1010 if (selfTransformation) {
1011 tmpMatrix.postConcat(mTransformation.getMatrix());
1012 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001013 if (attachedTransformation != null) {
1014 tmpMatrix.postConcat(attachedTransformation.getMatrix());
1015 }
1016 if (appTransformation != null) {
1017 tmpMatrix.postConcat(appTransformation.getMatrix());
1018 }
Jorim Jaggie1d43612016-04-01 18:20:33 -07001019
1020 // The translation that applies the position of the window needs to be applied at the
1021 // end in case that other translations include scaling. Otherwise the scaling will
1022 // affect this translation. But it needs to be set before the screen rotation animation
1023 // so the pivot point is at the center of the screen for all windows.
1024 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001025 if (screenAnimation) {
Craig Mautnera91f9e22012-09-14 16:22:08 -07001026 tmpMatrix.postConcat(screenRotationAnimation.getEnterTransformation().getMatrix());
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001027 }
Winson Chung399f6202014-03-19 10:47:20 -07001028
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001029 //TODO (multidisplay): Magnification is supported only for the default display.
Filip Gruszczynski69cbc352015-11-11 13:46:04 -08001030 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
Svetoslav8e3feb12014-02-24 13:46:47 -08001031 MagnificationSpec spec = mService.mAccessibilityController
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001032 .getMagnificationSpecForWindowLocked(mWin);
Robert Carr298f9272016-08-09 13:08:01 -07001033 applyMagnificationSpec(spec, tmpMatrix);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001034 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001035
1036 // "convert" it into SurfaceFlinger's format
1037 // (a 2x2 matrix + an offset)
1038 // Here we must not transform the position of the surface
1039 // since it is already included in the transformation.
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001040 //Slog.i(TAG_WM, "Transform: " + matrix);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001041
1042 mHaveMatrix = true;
1043 tmpMatrix.getValues(tmpFloats);
1044 mDsDx = tmpFloats[Matrix.MSCALE_X];
1045 mDtDx = tmpFloats[Matrix.MSKEW_Y];
1046 mDsDy = tmpFloats[Matrix.MSKEW_X];
1047 mDtDy = tmpFloats[Matrix.MSCALE_Y];
1048 float x = tmpFloats[Matrix.MTRANS_X];
1049 float y = tmpFloats[Matrix.MTRANS_Y];
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001050 mWin.mShownPosition.set((int) x, (int) y);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001051
1052 // Now set the alpha... but because our current hardware
1053 // can't do alpha transformation on a non-opaque surface,
1054 // turn it off if we are running an animation that is also
1055 // transforming since it is more important to have that
1056 // animation be smooth.
1057 mShownAlpha = mAlpha;
1058 if (!mService.mLimitedAlphaCompositing
1059 || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format)
1060 || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
1061 && x == frame.left && y == frame.top))) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001062 //Slog.i(TAG_WM, "Applying alpha transform");
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001063 if (selfTransformation) {
1064 mShownAlpha *= mTransformation.getAlpha();
1065 }
1066 if (attachedTransformation != null) {
1067 mShownAlpha *= attachedTransformation.getAlpha();
1068 }
1069 if (appTransformation != null) {
1070 mShownAlpha *= appTransformation.getAlpha();
Winson Chung399f6202014-03-19 10:47:20 -07001071 if (appTransformation.hasClipRect()) {
1072 mClipRect.set(appTransformation.getClipRect());
1073 mHasClipRect = true;
Robert Carrf3b72c72016-03-21 18:16:39 -07001074 // The app transformation clip will be in the coordinate space of the main
1075 // activity window, which the animation correctly assumes will be placed at
1076 // (0,0)+(insets) relative to the containing frame. This isn't necessarily
1077 // true for child windows though which can have an arbitrary frame position
1078 // relative to their containing frame. We need to offset the difference
1079 // between the containing frame as used to calculate the crop and our
1080 // bounds to compensate for this.
Wale Ogunwale246c2092016-04-07 14:12:44 -07001081 if (mWin.layoutInParentFrame()) {
Robert Carrf3b72c72016-03-21 18:16:39 -07001082 mClipRect.offset( (mWin.mContainingFrame.left - mWin.mFrame.left),
1083 mWin.mContainingFrame.top - mWin.mFrame.top );
1084 }
Winson Chung399f6202014-03-19 10:47:20 -07001085 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001086 }
1087 if (screenAnimation) {
Craig Mautnera91f9e22012-09-14 16:22:08 -07001088 mShownAlpha *= screenRotationAnimation.getEnterTransformation().getAlpha();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001089 }
1090 } else {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001091 //Slog.i(TAG_WM, "Not applying alpha transform");
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001092 }
1093
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001094 if ((DEBUG_SURFACE_TRACE || WindowManagerService.localLOGV)
Craig Mautnera91f9e22012-09-14 16:22:08 -07001095 && (mShownAlpha == 1.0 || mShownAlpha == 0.0)) Slog.v(
1096 TAG, "computeShownFrameLocked: Animating " + this + " mAlpha=" + mAlpha
1097 + " self=" + (selfTransformation ? mTransformation.getAlpha() : "null")
1098 + " attached=" + (attachedTransformation == null ?
1099 "null" : attachedTransformation.getAlpha())
1100 + " app=" + (appTransformation == null ? "null" : appTransformation.getAlpha())
1101 + " screen=" + (screenAnimation ?
1102 screenRotationAnimation.getEnterTransformation().getAlpha() : "null"));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001103 return;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001104 } else if (mIsWallpaper && mService.mWindowPlacerLocked.mWallpaperActionPending) {
Craig Mautner4d7349b2012-04-20 14:52:47 -07001105 return;
Chong Zhang3005e752015-09-18 18:46:28 -07001106 } else if (mWin.isDragResizeChanged()) {
1107 // This window is awaiting a relayout because user just started (or ended)
1108 // drag-resizing. The shown frame (which affects surface size and pos)
1109 // should not be updated until we get next finished draw with the new surface.
1110 // Otherwise one or two frames rendered with old settings would be displayed
1111 // with new geometry.
1112 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001113 }
1114
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001115 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautner4d7349b2012-04-20 14:52:47 -07001116 TAG, "computeShownFrameLocked: " + this +
1117 " not attached, mAlpha=" + mAlpha);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001118
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001119 MagnificationSpec spec = null;
1120 //TODO (multidisplay): Magnification is supported only for the default display.
Filip Gruszczynski69cbc352015-11-11 13:46:04 -08001121 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
Svetoslav8e3feb12014-02-24 13:46:47 -08001122 spec = mService.mAccessibilityController.getMagnificationSpecForWindowLocked(mWin);
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001123 }
Craig Mautner165be0c2015-01-27 15:16:58 -08001124 if (spec != null) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001125 final Rect frame = mWin.mFrame;
1126 final float tmpFloats[] = mService.mTmpFloats;
1127 final Matrix tmpMatrix = mWin.mTmpMatrix;
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001128
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001129 tmpMatrix.setScale(mWin.mGlobalScale, mWin.mGlobalScale);
1130 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001131
Robert Carr298f9272016-08-09 13:08:01 -07001132 applyMagnificationSpec(spec, tmpMatrix);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001133
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001134 tmpMatrix.getValues(tmpFloats);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001135
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001136 mHaveMatrix = true;
1137 mDsDx = tmpFloats[Matrix.MSCALE_X];
1138 mDtDx = tmpFloats[Matrix.MSKEW_Y];
1139 mDsDy = tmpFloats[Matrix.MSKEW_X];
1140 mDtDy = tmpFloats[Matrix.MSCALE_Y];
1141 float x = tmpFloats[Matrix.MTRANS_X];
1142 float y = tmpFloats[Matrix.MTRANS_Y];
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001143 mWin.mShownPosition.set((int) x, (int) y);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001144
1145 mShownAlpha = mAlpha;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001146 } else {
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001147 mWin.mShownPosition.set(mWin.mFrame.left, mWin.mFrame.top);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001148 if (mWin.mXOffset != 0 || mWin.mYOffset != 0) {
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001149 mWin.mShownPosition.offset(mWin.mXOffset, mWin.mYOffset);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001150 }
1151 mShownAlpha = mAlpha;
1152 mHaveMatrix = false;
1153 mDsDx = mWin.mGlobalScale;
1154 mDtDx = 0;
1155 mDsDy = 0;
1156 mDtDy = mWin.mGlobalScale;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001157 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001158 }
1159
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001160 private void calculateSystemDecorRect() {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001161 final WindowState w = mWin;
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001162 final Rect decorRect = w.mDecorFrame;
Alan Viverette49a22e82014-07-12 20:01:27 -07001163 final int width = w.mFrame.width();
1164 final int height = w.mFrame.height();
Alan Viveretteccb11e12014-07-08 16:04:02 -07001165
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001166 // Compute the offset of the window in relation to the decor rect.
Alan Viverette49a22e82014-07-12 20:01:27 -07001167 final int left = w.mXOffset + w.mFrame.left;
1168 final int top = w.mYOffset + w.mFrame.top;
Alan Viveretteccb11e12014-07-08 16:04:02 -07001169
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001170 // Initialize the decor rect to the entire frame.
Robert Carr2487ce72016-04-07 15:18:45 -07001171 if (w.isDockedResizing() ||
1172 (w.isChildWindow() && w.mAttachedWindow.isDockedResizing())) {
Jorim Jaggidc249c42015-12-15 14:57:31 -08001173
1174 // If we are resizing with the divider, the task bounds might be smaller than the
1175 // stack bounds. The system decor is used to clip to the task bounds, which we don't
1176 // want in this case in order to avoid holes.
Robert Carr2487ce72016-04-07 15:18:45 -07001177 //
1178 // We take care to not shrink the width, for surfaces which are larger than
1179 // the display region. Of course this area will not eventually be visible
1180 // but if we truncate the width now, we will calculate incorrectly
1181 // when adjusting to the stack bounds.
Jorim Jaggidc249c42015-12-15 14:57:31 -08001182 final DisplayInfo displayInfo = w.getDisplayContent().getDisplayInfo();
Robert Carr2487ce72016-04-07 15:18:45 -07001183 mSystemDecorRect.set(0, 0,
1184 Math.max(width, displayInfo.logicalWidth),
1185 Math.max(height, displayInfo.logicalHeight));
Jorim Jaggidc249c42015-12-15 14:57:31 -08001186 } else {
1187 mSystemDecorRect.set(0, 0, width, height);
1188 }
Alan Viveretteccb11e12014-07-08 16:04:02 -07001189
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001190 // If a freeform window is animating from a position where it would be cutoff, it would be
1191 // cutoff during the animation. We don't want that, so for the duration of the animation
1192 // we ignore the decor cropping and depend on layering to position windows correctly.
1193 final boolean cropToDecor = !(w.inFreeformWorkspace() && w.isAnimatingLw());
1194 if (cropToDecor) {
1195 // Intersect with the decor rect, offsetted by window position.
1196 mSystemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
1197 decorRect.right - left, decorRect.bottom - top);
1198 }
Alan Viveretteccb11e12014-07-08 16:04:02 -07001199
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001200 // If size compatibility is being applied to the window, the
1201 // surface is scaled relative to the screen. Also apply this
1202 // scaling to the crop rect. We aren't using the standard rect
1203 // scale function because we want to round things to make the crop
1204 // always round to a larger rect to ensure we don't crop too
1205 // much and hide part of the window that should be seen.
1206 if (w.mEnforceSizeCompat && w.mInvGlobalScale != 1.0f) {
1207 final float scale = w.mInvGlobalScale;
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001208 mSystemDecorRect.left = (int) (mSystemDecorRect.left * scale - 0.5f);
1209 mSystemDecorRect.top = (int) (mSystemDecorRect.top * scale - 0.5f);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001210 mSystemDecorRect.right = (int) ((mSystemDecorRect.right + 1) * scale - 0.5f);
1211 mSystemDecorRect.bottom = (int) ((mSystemDecorRect.bottom + 1) * scale - 0.5f);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001212 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001213 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001214
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001215 void calculateSurfaceWindowCrop(Rect clipRect, Rect finalClipRect) {
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001216 final WindowState w = mWin;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001217 final DisplayContent displayContent = w.getDisplayContent();
1218 if (displayContent == null) {
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001219 clipRect.setEmpty();
1220 finalClipRect.setEmpty();
1221 return;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001222 }
Wale Ogunwaleb3eba812015-07-30 20:20:16 -07001223 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001224 if (DEBUG_WINDOW_CROP) Slog.d(TAG,
1225 "Updating crop win=" + w + " mLastCrop=" + mLastClipRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001226
1227 // Need to recompute a new system decor rect each time.
Robert Carr58f29132015-10-29 14:19:05 -07001228 if (!w.isDefaultDisplay()) {
Jeff Brown28e0b092012-09-25 11:31:28 -07001229 // On a different display there is no system decor. Crop the window
1230 // by the screen boundaries.
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001231 mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height());
1232 mSystemDecorRect.intersect(-w.mCompatFrame.left, -w.mCompatFrame.top,
Jeff Brown28e0b092012-09-25 11:31:28 -07001233 displayInfo.logicalWidth - w.mCompatFrame.left,
1234 displayInfo.logicalHeight - w.mCompatFrame.top);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001235 } else if (w.mLayer >= mService.mSystemDecorLayer) {
1236 // Above the decor layer is easy, just use the entire window.
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001237 mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height());
Craig Mautner165be0c2015-01-27 15:16:58 -08001238 } else if (w.mDecorFrame.isEmpty()) {
1239 // Windows without policy decor aren't cropped.
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001240 mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height());
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001241 } else if (w.mAttrs.type == LayoutParams.TYPE_WALLPAPER && mAnimator.isAnimating()) {
Adrian Roosd47ad032014-08-15 23:17:05 +02001242 // If we're animating, the wallpaper crop should only be updated at the end of the
1243 // animation.
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001244 mTmpClipRect.set(mSystemDecorRect);
1245 calculateSystemDecorRect();
1246 mSystemDecorRect.union(mTmpClipRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001247 } else {
John Spurlock46646232013-09-30 22:32:42 -04001248 // Crop to the system decor specified by policy.
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001249 calculateSystemDecorRect();
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001250 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "Applying decor to crop win=" + w + " mDecorFrame="
1251 + w.mDecorFrame + " mSystemDecorRect=" + mSystemDecorRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001252 }
1253
Chong Zhang0abb20f2015-11-19 14:17:31 -08001254 final boolean fullscreen = w.isFrameFullscreen(displayInfo);
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001255 final boolean isFreeformResizing =
Jorim Jaggidcf467c2015-11-05 13:59:32 +01001256 w.isDragResizing() && w.getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
Robert Carr51a1b872015-12-08 14:03:13 -08001257
1258 // We use the clip rect as provided by the tranformation for non-fullscreen windows to
1259 // avoid premature clipping with the system decor rect.
1260 clipRect.set((mHasClipRect && !fullscreen) ? mClipRect : mSystemDecorRect);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001261 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "win=" + w + " Initial clip rect: " + clipRect
1262 + " mHasClipRect=" + mHasClipRect + " fullscreen=" + fullscreen);
Robert Carr51a1b872015-12-08 14:03:13 -08001263
1264 if (isFreeformResizing && !w.isChildWindow()) {
1265 // For freeform resizing non child windows, we are using the big surface positioned
1266 // at 0,0. Thus we must express the crop in that coordinate space.
1267 clipRect.offset(w.mShownPosition.x, w.mShownPosition.y);
Chong Zhang09b21ef2015-09-14 10:20:21 -07001268 }
Robert Carr51a1b872015-12-08 14:03:13 -08001269
Alan Viverette49a22e82014-07-12 20:01:27 -07001270 // Expand the clip rect for surface insets.
1271 final WindowManager.LayoutParams attrs = w.mAttrs;
1272 clipRect.left -= attrs.surfaceInsets.left;
1273 clipRect.top -= attrs.surfaceInsets.top;
1274 clipRect.right += attrs.surfaceInsets.right;
1275 clipRect.bottom += attrs.surfaceInsets.bottom;
1276
Wale Ogunwaleb3eba812015-07-30 20:20:16 -07001277 if (mHasClipRect && fullscreen) {
1278 // We intersect the clip rect specified by the transformation with the expanded system
1279 // decor rect to prevent artifacts from drawing during animation if the transformation
1280 // clip rect extends outside the system decor rect.
1281 clipRect.intersect(mClipRect);
1282 }
Alan Viverette49a22e82014-07-12 20:01:27 -07001283 // The clip rect was generated assuming (0,0) as the window origin,
1284 // so we need to translate to match the actual surface coordinates.
1285 clipRect.offset(attrs.surfaceInsets.left, attrs.surfaceInsets.top);
Robert Carr58f29132015-10-29 14:19:05 -07001286
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001287 finalClipRect.setEmpty();
1288 adjustCropToStackBounds(w, clipRect, finalClipRect, isFreeformResizing);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001289 if (DEBUG_WINDOW_CROP) Slog.d(TAG,
1290 "win=" + w + " Clip rect after stack adjustment=" + clipRect);
Robert Carr58f29132015-10-29 14:19:05 -07001291
Chia-I Wue6bcaf12016-05-27 10:58:48 +08001292 w.transformClipRectFromScreenToSurfaceSpace(clipRect);
Robert Carr58f29132015-10-29 14:19:05 -07001293
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08001294 // See {@link WindowState#notifyMovedInStack} for why this is necessary.
1295 if (w.hasJustMovedInStack() && mLastClipRect.isEmpty() && !clipRect.isEmpty()) {
1296 clipRect.setEmpty();
1297 }
Robert Carr0d00c2e2016-02-29 17:45:02 -08001298 }
1299
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001300 void updateSurfaceWindowCrop(Rect clipRect, Rect finalClipRect, boolean recoveringMemory) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001301 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "updateSurfaceWindowCrop: win=" + mWin
1302 + " clipRect=" + clipRect + " finalClipRect=" + finalClipRect);
Robert Carr4320d332016-06-10 15:13:32 -07001303 if (clipRect != null) {
1304 if (!clipRect.equals(mLastClipRect)) {
1305 mLastClipRect.set(clipRect);
1306 mSurfaceController.setCropInTransaction(clipRect, recoveringMemory);
1307 }
1308 } else {
1309 mSurfaceController.clearCropInTransaction(recoveringMemory);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001310 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001311 if (!finalClipRect.equals(mLastFinalClipRect)) {
1312 mLastFinalClipRect.set(finalClipRect);
1313 mSurfaceController.setFinalCropInTransaction(finalClipRect);
Chong Zhangcc3eccf2016-05-16 18:25:45 -07001314 if (mDestroyPreservedSurfaceUponRedraw && mPendingDestroySurface != null) {
1315 mPendingDestroySurface.setFinalCropInTransaction(finalClipRect);
1316 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001317 }
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001318 }
1319
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001320 private int resolveStackClip() {
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001321 // App animation overrides window animation stack clip mode.
1322 if (mAppAnimator != null && mAppAnimator.animation != null) {
1323 return mAppAnimator.getStackClip();
1324 } else {
1325 return mStackClip;
1326 }
1327 }
1328 private void adjustCropToStackBounds(WindowState w, Rect clipRect, Rect finalClipRect,
1329 boolean isFreeformResizing) {
Wale Ogunwale4c5aa5172016-04-19 11:29:05 -07001330
1331 final DisplayContent displayContent = w.getDisplayContent();
1332 if (displayContent != null && !displayContent.isDefaultDisplay) {
1333 // There are some windows that live on other displays while their app and main window
1334 // live on the default display (e.g. casting...). We don't want to crop this windows
1335 // to the stack bounds which is only currently supported on the default display.
1336 // TODO(multi-display): Need to support cropping to stack bounds on other displays
1337 // when we have stacks on other displays.
1338 return;
1339 }
1340
Chong Zhang112eb8c2015-11-02 11:17:00 -08001341 final Task task = w.getTask();
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001342 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001343 return;
Filip Gruszczynski4b8eea72015-09-14 18:16:19 -07001344 }
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001345
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001346 final int stackClip = resolveStackClip();
1347
1348 // It's animating and we don't want to clip it to stack bounds during animation - abort.
Jorim Jaggi5c80c412016-04-19 20:03:47 -07001349 if (isAnimationSet() && stackClip == STACK_CLIP_NONE) {
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001350 return;
1351 }
1352
Chong Zhangbcb8d822016-02-26 16:21:02 -08001353 final WindowState winShowWhenLocked = (WindowState) mPolicy.getWinShowWhenLockedLw();
Jorim Jaggid7f6e7c2016-04-11 19:04:24 -07001354 if (w == winShowWhenLocked && mPolicy.isKeyguardShowingOrOccluded()) {
Chong Zhangbcb8d822016-02-26 16:21:02 -08001355 return;
1356 }
1357
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001358 final TaskStack stack = task.mStack;
1359 stack.getDimBounds(mTmpStackBounds);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001360 final Rect surfaceInsets = w.getAttrs().surfaceInsets;
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001361 // When we resize we use the big surface approach, which means we can't trust the
1362 // window frame bounds anymore. Instead, the window will be placed at 0, 0, but to avoid
1363 // hardcoding it, we use surface coordinates.
1364 final int frameX = isFreeformResizing ? (int) mSurfaceController.getX() :
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001365 w.mFrame.left + mWin.mXOffset - surfaceInsets.left;
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001366 final int frameY = isFreeformResizing ? (int) mSurfaceController.getY() :
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001367 w.mFrame.top + mWin.mYOffset - surfaceInsets.top;
Robert Carr0d00c2e2016-02-29 17:45:02 -08001368
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001369 // If we are animating, we either apply the clip before applying all the animation
1370 // transformation or after all the transformation.
Chong Zhangcc3eccf2016-05-16 18:25:45 -07001371 final boolean useFinalClipRect = isAnimationSet() && stackClip == STACK_CLIP_AFTER_ANIM
1372 || mDestroyPreservedSurfaceUponRedraw;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001373
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001374 // We need to do some acrobatics with surface position, because their clip region is
1375 // relative to the inside of the surface, but the stack bounds aren't.
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001376 if (useFinalClipRect) {
1377 finalClipRect.set(mTmpStackBounds);
1378 } else {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001379 if (StackId.hasWindowShadow(stack.mStackId)
1380 && !StackId.isTaskResizeAllowed(stack.mStackId)) {
1381 // The windows in this stack display drop shadows and the fill the entire stack
1382 // area. Adjust the stack bounds we will use to cropping take into account the
1383 // offsets we use to display the drop shadow so it doesn't get cropped.
1384 mTmpStackBounds.inset(-surfaceInsets.left, -surfaceInsets.top,
1385 -surfaceInsets.right, -surfaceInsets.bottom);
1386 }
1387
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001388 clipRect.left = Math.max(0,
1389 Math.max(mTmpStackBounds.left, frameX + clipRect.left) - frameX);
1390 clipRect.top = Math.max(0,
1391 Math.max(mTmpStackBounds.top, frameY + clipRect.top) - frameY);
1392 clipRect.right = Math.max(0,
1393 Math.min(mTmpStackBounds.right, frameX + clipRect.right) - frameX);
1394 clipRect.bottom = Math.max(0,
1395 Math.min(mTmpStackBounds.bottom, frameY + clipRect.bottom) - frameY);
1396 }
Filip Gruszczynski4b8eea72015-09-14 18:16:19 -07001397 }
1398
Wale Ogunwale4c8b7952015-04-07 10:49:40 -07001399 void setSurfaceBoundariesLocked(final boolean recoveringMemory) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001400 final WindowState w = mWin;
Robert Carr0d00c2e2016-02-29 17:45:02 -08001401 final Task task = w.getTask();
Alan Viveretteccb11e12014-07-08 16:04:02 -07001402
Jorim Jaggif3df0aa2016-04-06 15:56:33 -07001403 // We got resized, so block all updates until we got the new surface.
Andrii Kulianeb1d3222016-05-16 15:17:55 -07001404 if (w.isResizedWhileNotDragResizing() && !w.isGoneForLayoutLw()) {
Jorim Jaggif3df0aa2016-04-06 15:56:33 -07001405 return;
1406 }
1407
Filip Gruszczynski69cbc352015-11-11 13:46:04 -08001408 mTmpSize.set(w.mShownPosition.x, w.mShownPosition.y, 0, 0);
1409 calculateSurfaceBounds(w, w.getAttrs());
Chong Zhang0275e392015-09-17 10:41:44 -07001410
Robert Carr04092112016-06-02 12:56:12 -07001411 mExtraHScale = (float) 1.0;
1412 mExtraVScale = (float) 1.0;
Robert Carre1034cc32016-02-01 13:08:15 -08001413
Robert Carr6da3cc02016-06-16 15:17:07 -07001414 boolean wasForceScaled = mForceScaleUntilResize;
1415 boolean wasSeamlesslyRotated = w.mSeamlesslyRotated;
1416
Robert Carrfed10072016-05-26 11:48:49 -07001417 // Once relayout has been called at least once, we need to make sure
1418 // we only resize the client surface during calls to relayout. For
1419 // clients which use indeterminate measure specs (MATCH_PARENT),
1420 // we may try and change their window size without a call to relayout.
1421 // However, this would be unsafe, as the client may be in the middle
1422 // of producing a frame at the old size, having just completed layout
1423 // to find the surface size changed underneath it.
Robert Carr3ccc5272016-06-20 22:06:32 -07001424 if (!w.mRelayoutCalled || w.mInRelayout) {
Robert Carrfed10072016-05-26 11:48:49 -07001425 mSurfaceResized = mSurfaceController.setSizeInTransaction(
1426 mTmpSize.width(), mTmpSize.height(), recoveringMemory);
1427 } else {
1428 mSurfaceResized = false;
1429 }
Robert Carrc7294602016-05-13 11:32:05 -07001430 mForceScaleUntilResize = mForceScaleUntilResize && !mSurfaceResized;
Robert Carr6da3cc02016-06-16 15:17:07 -07001431 // If we are undergoing seamless rotation, the surface has already
1432 // been set up to persist at it's old location. We need to freeze
1433 // updates until a resize occurs.
Robert Carrb14d4abc2016-10-03 18:13:33 -07001434 mService.markForSeamlessRotation(w, w.mSeamlesslyRotated && !mSurfaceResized);
Robert Carrc7294602016-05-13 11:32:05 -07001435
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001436 calculateSurfaceWindowCrop(mTmpClipRect, mTmpFinalClipRect);
Robert Carra9408d42016-06-03 13:28:48 -07001437
1438 float surfaceWidth = mSurfaceController.getWidth();
1439 float surfaceHeight = mSurfaceController.getHeight();
1440
Robert Carrc7294602016-05-13 11:32:05 -07001441 if ((task != null && task.mStack.getForceScaleToCrop()) || mForceScaleUntilResize) {
Robert Carrbc133762016-05-12 14:04:38 -07001442 int hInsets = w.getAttrs().surfaceInsets.left + w.getAttrs().surfaceInsets.right;
1443 int vInsets = w.getAttrs().surfaceInsets.top + w.getAttrs().surfaceInsets.bottom;
Robert Carra9408d42016-06-03 13:28:48 -07001444 if (!mForceScaleUntilResize) {
1445 mSurfaceController.forceScaleableInTransaction(true);
1446 }
Robert Carrbc133762016-05-12 14:04:38 -07001447 // We want to calculate the scaling based on the content area, not based on
1448 // the entire surface, so that we scale in sync with windows that don't have insets.
Robert Carr04092112016-06-02 12:56:12 -07001449 mExtraHScale = (mTmpClipRect.width() - hInsets) / (float)(surfaceWidth - hInsets);
1450 mExtraVScale = (mTmpClipRect.height() - vInsets) / (float)(surfaceHeight - vInsets);
Robert Carr0d00c2e2016-02-29 17:45:02 -08001451
1452 // In the case of ForceScaleToCrop we scale entire tasks together,
1453 // and so we need to scale our offsets relative to the task bounds
1454 // or parent and child windows would fall out of alignment.
Robert Carr04092112016-06-02 12:56:12 -07001455 int posX = (int) (mTmpSize.left - w.mAttrs.x * (1 - mExtraHScale));
1456 int posY = (int) (mTmpSize.top - w.mAttrs.y * (1 - mExtraVScale));
Robert Carrbc133762016-05-12 14:04:38 -07001457 // Imagine we are scaling down. As we scale the buffer down, we decrease the
1458 // distance between the surface top left, and the start of the surface contents
1459 // (previously it was surfaceInsets.left pixels in screen space but now it
Robert Carr04092112016-06-02 12:56:12 -07001460 // will be surfaceInsets.left*mExtraHScale). This means in order to keep the
Robert Carrbc133762016-05-12 14:04:38 -07001461 // non inset content at the same position, we have to shift the whole window
1462 // forward. Likewise for scaling up, we've increased this distance, and we need
1463 // to shift by a negative number to compensate.
Robert Carr04092112016-06-02 12:56:12 -07001464 posX += w.getAttrs().surfaceInsets.left * (1 - mExtraHScale);
1465 posY += w.getAttrs().surfaceInsets.top * (1 - mExtraVScale);
Robert Carrbc133762016-05-12 14:04:38 -07001466
Robert Carra9408d42016-06-03 13:28:48 -07001467 mSurfaceController.setPositionInTransaction((float)Math.floor(posX),
1468 (float)Math.floor(posY), recoveringMemory);
Robert Carr0d00c2e2016-02-29 17:45:02 -08001469
1470 // Since we are scaled to fit in our previously desired crop, we can now
1471 // expose the whole window in buffer space, and not risk extending
1472 // past where the system would have cropped us
Robert Carrfed10072016-05-26 11:48:49 -07001473 mTmpClipRect.set(0, 0, (int)surfaceWidth, (int)surfaceHeight);
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001474 mTmpFinalClipRect.setEmpty();
Robert Carrc7294602016-05-13 11:32:05 -07001475
1476 // Various surfaces in the scaled stack may resize at different times.
1477 // We need to ensure for each surface, that we disable transformation matrix
1478 // scaling in the same transaction which we resize the surface in.
1479 // As we are in SCALING_MODE_SCALE_TO_WINDOW, SurfaceFlinger will
Robert Carra9408d42016-06-03 13:28:48 -07001480 // then take over the scaling until the new buffer arrives, and things
Robert Carrc7294602016-05-13 11:32:05 -07001481 // will be seamless.
1482 mForceScaleUntilResize = true;
Robert Carr0d00c2e2016-02-29 17:45:02 -08001483 } else {
Robert Carr6da3cc02016-06-16 15:17:07 -07001484 if (!w.mSeamlesslyRotated) {
1485 mSurfaceController.setPositionInTransaction(mTmpSize.left, mTmpSize.top,
1486 recoveringMemory);
1487 }
Robert Carr0d00c2e2016-02-29 17:45:02 -08001488 }
1489
Robert Carra9408d42016-06-03 13:28:48 -07001490 // If we are ending the scaling mode. We switch to SCALING_MODE_FREEZE
Robert Carr6da3cc02016-06-16 15:17:07 -07001491 // to prevent further updates until buffer latch.
1492 // When ending both force scaling, and seamless rotation, we need to freeze
1493 // the Surface geometry until a buffer comes in at the new size (normally position and crop
1494 // are unfrozen). setGeometryAppliesWithResizeInTransaction accomplishes this for us.
1495 if ((wasForceScaled && !mForceScaleUntilResize) ||
1496 (wasSeamlesslyRotated && !w.mSeamlesslyRotated)) {
1497 mSurfaceController.setGeometryAppliesWithResizeInTransaction(true);
Robert Carra9408d42016-06-03 13:28:48 -07001498 mSurfaceController.forceScaleableInTransaction(false);
1499 }
Robert Carr4320d332016-06-10 15:13:32 -07001500
1501 Rect clipRect = mTmpClipRect;
Robert Carra9408d42016-06-03 13:28:48 -07001502 if (w.inPinnedWorkspace()) {
Robert Carr4320d332016-06-10 15:13:32 -07001503 clipRect = null;
Robert Carra9408d42016-06-03 13:28:48 -07001504 task.mStack.getDimBounds(mTmpFinalClipRect);
1505 mTmpFinalClipRect.inset(-w.mAttrs.surfaceInsets.left, -w.mAttrs.surfaceInsets.top,
1506 -w.mAttrs.surfaceInsets.right, -w.mAttrs.surfaceInsets.bottom);
1507 }
1508
Robert Carr6da3cc02016-06-16 15:17:07 -07001509 if (!w.mSeamlesslyRotated) {
1510 updateSurfaceWindowCrop(clipRect, mTmpFinalClipRect, recoveringMemory);
1511 mSurfaceController.setMatrixInTransaction(mDsDx * w.mHScale * mExtraHScale,
1512 mDtDx * w.mVScale * mExtraVScale,
1513 mDsDy * w.mHScale * mExtraHScale,
1514 mDtDy * w.mVScale * mExtraVScale, recoveringMemory);
1515 }
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001516
Robert Carre6a83512015-11-03 16:09:21 -08001517 if (mSurfaceResized) {
Chong Zhang5b2f1992015-11-13 15:40:36 -08001518 mReportSurfaceResized = true;
Robert Carre6a83512015-11-03 16:09:21 -08001519 mAnimator.setPendingLayoutChanges(w.getDisplayId(),
1520 WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
1521 w.applyDimLayerIfNeeded();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001522 }
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001523
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001524 }
1525
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001526 void prepareSurfaceLocked(final boolean recoveringMemory) {
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001527 final WindowState w = mWin;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001528 if (!hasSurface()) {
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001529 if (w.mOrientationChanging) {
1530 if (DEBUG_ORIENTATION) {
1531 Slog.v(TAG, "Orientation change skips hidden " + w);
1532 }
1533 w.mOrientationChanging = false;
1534 }
1535 return;
1536 }
1537
Chong Zhang70211742016-04-28 18:27:53 -07001538 // Do not change surface properties of opening apps if we are waiting for the
1539 // transition to be ready. transitionGoodToGo could be not ready even after all
1540 // opening apps are drawn. It's only waiting on isFetchingAppTransitionsSpecs()
1541 // to get the animation spec. (For example, go into Recents and immediately open
1542 // the same app again before the app's surface is destroyed or saved, the surface
1543 // is always ready in the whole process.) If we go ahead here, the opening app
1544 // will be shown with the full size before the correct animation spec arrives.
Chong Zhange22006d2016-05-09 10:59:59 -07001545 if (isWaitingForOpening()) {
Chong Zhang70211742016-04-28 18:27:53 -07001546 return;
1547 }
1548
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001549 boolean displayed = false;
1550
1551 computeShownFrameLocked();
1552
Craig Mautnera91f9e22012-09-14 16:22:08 -07001553 setSurfaceBoundariesLocked(recoveringMemory);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001554
Craig Mautner918b53b2012-07-09 14:15:54 -07001555 if (mIsWallpaper && !mWin.mWallpaperVisible) {
Craig Mautner0fa77c12012-06-11 15:57:19 -07001556 // Wallpaper is no longer visible and there is no wp target => hide it.
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001557 hide("prepareSurfaceLocked");
Craig Mautner72669d12012-12-18 17:23:54 -08001558 } else if (w.mAttachedHidden || !w.isOnScreen()) {
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001559 hide("prepareSurfaceLocked");
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001560 mWallpaperControllerLocked.hideWallpapers(w);
Craig Mautnerb9836b92012-06-11 11:40:09 -07001561
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001562 // If we are waiting for this window to handle an
1563 // orientation change, well, it is hidden, so
1564 // doesn't really matter. Note that this does
1565 // introduce a potential glitch if the window
1566 // becomes unhidden before it has drawn for the
1567 // new orientation.
1568 if (w.mOrientationChanging) {
1569 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001570 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001571 "Orientation change skips hidden " + w);
1572 }
1573 } else if (mLastLayer != mAnimLayer
1574 || mLastAlpha != mShownAlpha
1575 || mLastDsDx != mDsDx
1576 || mLastDtDx != mDtDx
1577 || mLastDsDy != mDsDy
1578 || mLastDtDy != mDtDy
1579 || w.mLastHScale != w.mHScale
1580 || w.mLastVScale != w.mVScale
Craig Mautner749a7bb2012-04-02 13:49:53 -07001581 || mLastHidden) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001582 displayed = true;
1583 mLastAlpha = mShownAlpha;
1584 mLastLayer = mAnimLayer;
1585 mLastDsDx = mDsDx;
1586 mLastDtDx = mDtDx;
1587 mLastDsDy = mDsDy;
1588 mLastDtDy = mDtDy;
1589 w.mLastHScale = w.mHScale;
1590 w.mLastVScale = w.mVScale;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001591 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
Robert Carre6a83512015-11-03 16:09:21 -08001592 "controller=" + mSurfaceController +
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001593 "alpha=" + mShownAlpha + " layer=" + mAnimLayer
Craig Mautner78505d82014-09-02 14:36:31 -07001594 + " matrix=[" + mDsDx + "*" + w.mHScale
1595 + "," + mDtDx + "*" + w.mVScale
1596 + "][" + mDsDy + "*" + w.mHScale
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -08001597 + "," + mDtDy + "*" + w.mVScale + "]", false);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001598
Robert Carre6a83512015-11-03 16:09:21 -08001599 boolean prepared =
1600 mSurfaceController.prepareToShowInTransaction(mShownAlpha, mAnimLayer,
Robert Carr04092112016-06-02 12:56:12 -07001601 mDsDx * w.mHScale * mExtraHScale,
1602 mDtDx * w.mVScale * mExtraVScale,
1603 mDsDy * w.mHScale * mExtraHScale,
1604 mDtDy * w.mVScale * mExtraVScale,
Robert Carre6a83512015-11-03 16:09:21 -08001605 recoveringMemory);
1606
1607 if (prepared && mLastHidden && mDrawState == HAS_DRAWN) {
1608 if (showSurfaceRobustlyLocked()) {
Chong Zhangeb665572016-05-09 18:28:27 -07001609 markPreservedSurfaceForDestroy();
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -08001610 mAnimator.requestRemovalOfReplacedWindows(w);
Robert Carre6a83512015-11-03 16:09:21 -08001611 mLastHidden = false;
1612 if (mIsWallpaper) {
1613 mWallpaperControllerLocked.dispatchWallpaperVisibility(w, true);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001614 }
Robert Carre6a83512015-11-03 16:09:21 -08001615 // This draw means the difference between unique content and mirroring.
1616 // Run another pass through performLayout to set mHasContent in the
1617 // LogicalDisplay.
1618 mAnimator.setPendingLayoutChanges(w.getDisplayId(),
1619 WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
1620 } else {
1621 w.mOrientationChanging = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001622 }
1623 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001624 if (hasSurface()) {
Robert Carre6a83512015-11-03 16:09:21 -08001625 w.mToken.hasVisible = true;
1626 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001627 } else {
Jorim Jaggi5c80c412016-04-19 20:03:47 -07001628 if (DEBUG_ANIM && isAnimationSet()) {
Chong Zhange05db742016-02-16 16:58:37 -08001629 Slog.v(TAG, "prepareSurface: No changes in animation for " + this);
Craig Mautner83339b42012-05-01 22:13:23 -07001630 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001631 displayed = true;
1632 }
1633
1634 if (displayed) {
1635 if (w.mOrientationChanging) {
1636 if (!w.isDrawnLw()) {
Craig Mautner2639da52012-07-09 09:39:06 -07001637 mAnimator.mBulkUpdateParams &= ~SET_ORIENTATION_CHANGE_COMPLETE;
Dianne Hackborna57c6952013-03-29 14:46:40 -07001638 mAnimator.mLastWindowFreezeSource = w;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001639 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001640 "Orientation continue waiting for draw in " + w);
1641 } else {
1642 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001643 if (DEBUG_ORIENTATION) Slog.v(TAG, "Orientation change complete in " + w);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001644 }
1645 }
1646 w.mToken.hasVisible = true;
1647 }
1648 }
1649
Craig Mautneref655012013-01-03 11:20:24 -08001650 void setTransparentRegionHintLocked(final Region region) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001651 if (mSurfaceController == null) {
1652 Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true");
1653 return;
1654 }
Robert Carre6a83512015-11-03 16:09:21 -08001655 mSurfaceController.setTransparentRegionHint(region);
Craig Mautner48ba1e72012-04-02 13:18:16 -07001656 }
1657
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001658 void setWallpaperOffset(Point shownPosition) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07001659 final LayoutParams attrs = mWin.getAttrs();
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001660 final int left = shownPosition.x - attrs.surfaceInsets.left;
1661 final int top = shownPosition.y - attrs.surfaceInsets.top;
Robert Carre6a83512015-11-03 16:09:21 -08001662
1663 try {
Craig Mautner71dd1b62014-02-18 15:48:52 -08001664 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setWallpaperOffset");
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001665 SurfaceControl.openTransaction();
Robert Carre6a83512015-11-03 16:09:21 -08001666 mSurfaceController.setPositionInTransaction(mWin.mFrame.left + left,
1667 mWin.mFrame.top + top, false);
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001668 calculateSurfaceWindowCrop(mTmpClipRect, mTmpFinalClipRect);
1669 updateSurfaceWindowCrop(mTmpClipRect, mTmpFinalClipRect, false);
Robert Carre6a83512015-11-03 16:09:21 -08001670 } catch (RuntimeException e) {
1671 Slog.w(TAG, "Error positioning surface of " + mWin
1672 + " pos=(" + left + "," + top + ")", e);
1673 } finally {
1674 SurfaceControl.closeTransaction();
1675 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1676 "<<< CLOSE TRANSACTION setWallpaperOffset");
Craig Mautner48ba1e72012-04-02 13:18:16 -07001677 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001678 }
1679
John Reck80181b92015-05-19 11:09:32 -07001680 /**
1681 * Try to change the pixel format without recreating the surface. This
1682 * will be common in the case of changing from PixelFormat.OPAQUE to
1683 * PixelFormat.TRANSLUCENT in the hardware-accelerated case as both
1684 * requested formats resolve to the same underlying SurfaceControl format
1685 * @return True if format was succesfully changed, false otherwise
1686 */
1687 boolean tryChangeFormatInPlaceLocked() {
Robert Carre6a83512015-11-03 16:09:21 -08001688 if (mSurfaceController == null) {
John Reck80181b92015-05-19 11:09:32 -07001689 return false;
1690 }
1691 final LayoutParams attrs = mWin.getAttrs();
Wale Ogunwalee7bf46b2015-09-30 09:19:28 -07001692 final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0;
John Reck80181b92015-05-19 11:09:32 -07001693 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
1694 if (format == mSurfaceFormat) {
1695 setOpaqueLocked(!PixelFormat.formatHasAlpha(attrs.format));
1696 return true;
1697 }
1698 return false;
1699 }
1700
Craig Mautner6f612042014-09-07 13:13:23 -07001701 void setOpaqueLocked(boolean isOpaque) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001702 if (mSurfaceController == null) {
1703 return;
1704 }
Robert Carre6a83512015-11-03 16:09:21 -08001705 mSurfaceController.setOpaque(isOpaque);
Craig Mautner71dd1b62014-02-18 15:48:52 -08001706 }
1707
Wale Ogunwalef5ad42f2015-06-12 13:59:03 -07001708 void setSecureLocked(boolean isSecure) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001709 if (mSurfaceController == null) {
1710 return;
1711 }
Robert Carre6a83512015-11-03 16:09:21 -08001712 mSurfaceController.setSecure(isSecure);
Wale Ogunwalef5ad42f2015-06-12 13:59:03 -07001713 }
1714
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001715 // This must be called while inside a transaction.
1716 boolean performShowLocked() {
Craig Mautner5962b122012-10-05 14:45:52 -07001717 if (mWin.isHiddenFromUserLocked()) {
Wale Ogunwale4eef94f2015-07-17 22:29:54 -07001718 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + mWin + ", belonging to " + mWin.mOwnerUid);
1719 mWin.hideLw(false);
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001720 return false;
1721 }
Craig Mautner6fbda632012-07-03 09:26:39 -07001722 if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
1723 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001724 Slog.v(TAG, "performShow on " + this
Craig Mautnerc431e892015-02-11 13:14:26 -08001725 + ": mDrawState=" + drawStateToString() + " readyForDisplay="
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001726 + mWin.isReadyForDisplayIgnoringKeyguard()
Craig Mautner6fbda632012-07-03 09:26:39 -07001727 + " starting=" + (mWin.mAttrs.type == TYPE_APPLICATION_STARTING)
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001728 + " during animation: policyVis=" + mWin.mPolicyVisibility
1729 + " attHidden=" + mWin.mAttachedHidden
1730 + " tok.hiddenRequested="
1731 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
1732 + " tok.hidden="
1733 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
1734 + " animating=" + mAnimating
1735 + " tok animating="
Craig Mautnerc431e892015-02-11 13:14:26 -08001736 + (mAppAnimator != null ? mAppAnimator.animating : false) + " Callers="
1737 + Debug.getCallers(3));
Craig Mautner6fbda632012-07-03 09:26:39 -07001738 }
1739 if (mDrawState == READY_TO_SHOW && mWin.isReadyForDisplayIgnoringKeyguard()) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001740 if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
1741 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
1742 Slog.v(TAG, "Showing " + this
1743 + " during animation: policyVis=" + mWin.mPolicyVisibility
1744 + " attHidden=" + mWin.mAttachedHidden
1745 + " tok.hiddenRequested="
1746 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
1747 + " tok.hidden="
1748 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
1749 + " animating=" + mAnimating
1750 + " tok animating="
Craig Mautner322e4032012-07-13 13:35:20 -07001751 + (mAppAnimator != null ? mAppAnimator.animating : false));
Craig Mautner6fbda632012-07-03 09:26:39 -07001752 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001753
1754 mService.enableScreenIfNeededLocked();
1755
1756 applyEnterAnimationLocked();
1757
Craig Mautnerde6198e2012-04-19 09:59:31 -07001758 // Force the show in the next prepareSurfaceLocked() call.
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001759 mLastAlpha = -1;
Craig Mautneref25d7a2012-05-15 23:01:47 -07001760 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM)
Chong Zhang5b2f1992015-11-13 15:40:36 -08001761 Slog.v(TAG, "performShowLocked: mDrawState=HAS_DRAWN in " + mWin);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001762 mDrawState = HAS_DRAWN;
Craig Mautner96868332012-12-04 14:29:11 -08001763 mService.scheduleAnimationLocked();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001764
1765 int i = mWin.mChildWindows.size();
1766 while (i > 0) {
1767 i--;
1768 WindowState c = mWin.mChildWindows.get(i);
1769 if (c.mAttachedHidden) {
1770 c.mAttachedHidden = false;
Robert Carre6a83512015-11-03 16:09:21 -08001771 if (c.mWinAnimator.mSurfaceController != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001772 c.mWinAnimator.performShowLocked();
Filip Gruszczynski921171a2015-09-30 22:02:57 +00001773 // It hadn't been shown, which means layout not
1774 // performed on it, so now we want to make sure to
1775 // do a layout. If called from within the transaction
1776 // loop, this will cause it to restart with a new
1777 // layout.
1778 final DisplayContent displayContent = c.getDisplayContent();
1779 if (displayContent != null) {
1780 displayContent.layoutNeeded = true;
1781 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001782 }
1783 }
1784 }
1785
Filip Gruszczynskib6e66622015-10-25 16:05:27 -07001786 if (mWin.mAttrs.type != TYPE_APPLICATION_STARTING && mWin.mAppToken != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001787 mWin.mAppToken.onFirstWindowDrawn(mWin, this);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001788 }
Chong Zhangc806d902015-11-30 09:44:27 -08001789
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -07001790 if (mWin.mAttrs.type == TYPE_INPUT_METHOD) {
1791 mWin.mDisplayContent.mDividerControllerLocked.resetImeHideRequested();
1792 }
1793
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001794 return true;
1795 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001796 return false;
1797 }
1798
1799 /**
1800 * Have the surface flinger show a surface, robustly dealing with
1801 * error conditions. In particular, if there is not enough memory
1802 * to show the surface, then we will try to get rid of other surfaces
1803 * in order to succeed.
1804 *
1805 * @return Returns true if the surface was successfully shown.
1806 */
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001807 private boolean showSurfaceRobustlyLocked() {
Robert Carr1b5ea722016-04-20 13:23:28 -07001808 final Task task = mWin.getTask();
1809 if (task != null && StackId.windowsAreScaleable(task.mStack.mStackId)) {
1810 mSurfaceController.forceScaleableInTransaction(true);
1811 }
1812
Robert Carre6a83512015-11-03 16:09:21 -08001813 boolean shown = mSurfaceController.showRobustlyInTransaction();
1814 if (!shown)
1815 return false;
1816
1817 if (mWin.mTurnOnScreen) {
1818 if (DEBUG_VISIBILITY) Slog.v(TAG, "Show surface turning screen on: " + mWin);
1819 mWin.mTurnOnScreen = false;
1820 mAnimator.mBulkUpdateParams |= SET_TURN_ON_SCREEN;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001821 }
Robert Carre6a83512015-11-03 16:09:21 -08001822 return true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001823 }
1824
1825 void applyEnterAnimationLocked() {
Robert Carrb439a632016-04-07 22:52:10 -07001826 // If we are the new part of a window replacement transition and we have requested
1827 // not to animate, we instead want to make it seamless, so we don't want to apply
1828 // an enter transition.
1829 if (mWin.mSkipEnterAnimationForSeamlessReplacement) {
1830 return;
1831 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001832 final int transit;
1833 if (mEnterAnimationPending) {
1834 mEnterAnimationPending = false;
1835 transit = WindowManagerPolicy.TRANSIT_ENTER;
1836 } else {
1837 transit = WindowManagerPolicy.TRANSIT_SHOW;
1838 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001839 applyAnimationLocked(transit, true);
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001840 //TODO (multidisplay): Magnification is supported only for the default display.
Svetoslav8e3feb12014-02-24 13:46:47 -08001841 if (mService.mAccessibilityController != null
Filip Gruszczynski69cbc352015-11-11 13:46:04 -08001842 && mWin.getDisplayId() == DEFAULT_DISPLAY) {
Svetoslav8e3feb12014-02-24 13:46:47 -08001843 mService.mAccessibilityController.onWindowTransitionLocked(mWin, transit);
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -07001844 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001845 }
1846
1847 /**
1848 * Choose the correct animation and set it to the passed WindowState.
Craig Mautner4b71aa12012-12-27 17:20:01 -08001849 * @param transit If AppTransition.TRANSIT_PREVIEW_DONE and the app window has been drawn
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001850 * then the animation will be app_starting_exit. Any other value loads the animation from
1851 * the switch statement below.
1852 * @param isEntrance The animation type the last time this was called. Used to keep from
1853 * loading the same animation twice.
1854 * @return true if an animation has been loaded.
1855 */
1856 boolean applyAnimationLocked(int transit, boolean isEntrance) {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001857 if ((mLocalAnimating && mAnimationIsEntrance == isEntrance)
1858 || mKeyguardGoingAwayAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001859 // If we are trying to apply an animation, but already running
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001860 // an animation of the same type, then just leave that one alone.
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001861
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001862 // If we are in a keyguard exit animation, and the window should animate away, modify
1863 // keyguard exit animation such that it also fades out.
1864 if (mAnimation != null && mKeyguardGoingAwayAnimation
1865 && transit == WindowManagerPolicy.TRANSIT_PREVIEW_DONE) {
1866 applyFadeoutDuringKeyguardExitAnimation();
1867 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001868 return true;
1869 }
1870
1871 // Only apply an animation if the display isn't frozen. If it is
1872 // frozen, there is no reason to animate and it can cause strange
1873 // artifacts when we unfreeze the display if some different animation
1874 // is running.
Chong Zhang8784be62016-06-28 15:25:07 -07001875 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "WSA#applyAnimationLocked");
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001876 if (mService.okToDisplay()) {
1877 int anim = mPolicy.selectAnimationLw(mWin, transit);
1878 int attr = -1;
1879 Animation a = null;
1880 if (anim != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001881 a = anim != -1 ? AnimationUtils.loadAnimation(mContext, anim) : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001882 } else {
1883 switch (transit) {
1884 case WindowManagerPolicy.TRANSIT_ENTER:
1885 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
1886 break;
1887 case WindowManagerPolicy.TRANSIT_EXIT:
1888 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
1889 break;
1890 case WindowManagerPolicy.TRANSIT_SHOW:
1891 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
1892 break;
1893 case WindowManagerPolicy.TRANSIT_HIDE:
1894 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
1895 break;
1896 }
1897 if (attr >= 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001898 a = mService.mAppTransition.loadAnimationAttr(mWin.mAttrs, attr);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001899 }
1900 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001901 if (DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001902 "applyAnimation: win=" + this
1903 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
Craig Mautner4d7349b2012-04-20 14:52:47 -07001904 + " a=" + a
Craig Mautner8863cca2012-09-18 15:04:34 -07001905 + " transit=" + transit
Craig Mautner83339b42012-05-01 22:13:23 -07001906 + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001907 if (a != null) {
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -08001908 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001909 setAnimation(a);
1910 mAnimationIsEntrance = isEntrance;
1911 }
1912 } else {
1913 clearAnimation();
1914 }
Chong Zhang8784be62016-06-28 15:25:07 -07001915 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
1916
Jorim Jaggieb88d832016-04-13 20:17:43 -07001917 if (mWin.mAttrs.type == TYPE_INPUT_METHOD) {
1918 mService.adjustForImeIfNeeded(mWin.mDisplayContent);
Jorim Jaggi7a4fd5e2016-04-14 19:55:35 -07001919 if (isEntrance) {
1920 mWin.setDisplayLayoutNeeded();
1921 mService.mWindowPlacerLocked.requestTraversal();
1922 }
Jorim Jaggieb88d832016-04-13 20:17:43 -07001923 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001924 return mAnimation != null;
1925 }
1926
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001927 private void applyFadeoutDuringKeyguardExitAnimation() {
1928 long startTime = mAnimation.getStartTime();
1929 long duration = mAnimation.getDuration();
1930 long elapsed = mLastAnimationTime - startTime;
1931 long fadeDuration = duration - elapsed;
1932 if (fadeDuration <= 0) {
1933 // Never mind, this would be no visible animation, so abort the animation change.
1934 return;
1935 }
1936 AnimationSet newAnimation = new AnimationSet(false /* shareInterpolator */);
1937 newAnimation.setDuration(duration);
1938 newAnimation.setStartTime(startTime);
1939 newAnimation.addAnimation(mAnimation);
1940 Animation fadeOut = AnimationUtils.loadAnimation(
1941 mContext, com.android.internal.R.anim.app_starting_exit);
1942 fadeOut.setDuration(fadeDuration);
1943 fadeOut.setStartOffset(elapsed);
1944 newAnimation.addAnimation(fadeOut);
Filip Gruszczynskif52dd202015-11-15 20:36:38 -08001945 newAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(), mAnimDx, mAnimDy);
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001946 mAnimation = newAnimation;
1947 }
1948
Craig Mautnera2c77052012-03-26 12:14:43 -07001949 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1950 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
1951 || mAnimation != null) {
1952 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
1953 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
1954 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001955 pw.print(" mAnimation="); pw.print(mAnimation);
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001956 pw.print(" mStackClip="); pw.println(mStackClip);
Craig Mautnera2c77052012-03-26 12:14:43 -07001957 }
1958 if (mHasTransformation || mHasLocalTransformation) {
1959 pw.print(prefix); pw.print("XForm: has=");
1960 pw.print(mHasTransformation);
1961 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
1962 pw.print(" "); mTransformation.printShortString(pw);
1963 pw.println();
1964 }
Robert Carre6a83512015-11-03 16:09:21 -08001965 if (mSurfaceController != null) {
1966 mSurfaceController.dump(pw, prefix, dumpAll);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001967 }
Robert Carre6a83512015-11-03 16:09:21 -08001968 if (dumpAll) {
1969 pw.print(prefix); pw.print("mDrawState="); pw.print(drawStateToString());
1970 pw.print(prefix); pw.print(" mLastHidden="); pw.println(mLastHidden);
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001971 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
1972 pw.print(" last="); mLastSystemDecorRect.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001973 pw.print(" mHasClipRect="); pw.print(mHasClipRect);
1974 pw.print(" mLastClipRect="); mLastClipRect.printShortString(pw);
1975
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001976 if (!mLastFinalClipRect.isEmpty()) {
1977 pw.print(" mLastFinalClipRect="); mLastFinalClipRect.printShortString(pw);
1978 }
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001979 pw.println();
Robert Carre6a83512015-11-03 16:09:21 -08001980 }
1981
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001982 if (mPendingDestroySurface != null) {
1983 pw.print(prefix); pw.print("mPendingDestroySurface=");
1984 pw.println(mPendingDestroySurface);
1985 }
1986 if (mSurfaceResized || mSurfaceDestroyDeferred) {
1987 pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized);
1988 pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred);
1989 }
1990 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
1991 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
1992 pw.print(" mAlpha="); pw.print(mAlpha);
1993 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
1994 }
1995 if (mHaveMatrix || mWin.mGlobalScale != 1) {
1996 pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale);
1997 pw.print(" mDsDx="); pw.print(mDsDx);
1998 pw.print(" mDtDx="); pw.print(mDtDx);
1999 pw.print(" mDsDy="); pw.print(mDsDy);
2000 pw.print(" mDtDy="); pw.println(mDtDy);
2001 }
Jorim Jaggiff71d202016-04-14 13:12:36 -07002002 if (mAnimationStartDelayed) {
2003 pw.print(prefix); pw.print("mAnimationStartDelayed="); pw.print(mAnimationStartDelayed);
2004 }
Craig Mautnera2c77052012-03-26 12:14:43 -07002005 }
2006
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07002007 @Override
2008 public String toString() {
Dianne Hackborn529e7442012-11-01 14:22:28 -07002009 StringBuffer sb = new StringBuffer("WindowStateAnimator{");
2010 sb.append(Integer.toHexString(System.identityHashCode(this)));
2011 sb.append(' ');
2012 sb.append(mWin.mAttrs.getTitle());
2013 sb.append('}');
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07002014 return sb.toString();
2015 }
Robert Carre6a83512015-11-03 16:09:21 -08002016
2017 void reclaimSomeSurfaceMemory(String operation, boolean secure) {
2018 mService.reclaimSomeSurfaceMemoryLocked(this, operation, secure);
2019 }
2020
2021 boolean getShown() {
2022 if (mSurfaceController != null) {
2023 return mSurfaceController.getShown();
2024 }
2025 return false;
2026 }
2027
2028 void destroySurface() {
Wale Ogunwale722ff892016-02-18 13:37:55 -08002029 try {
2030 if (mSurfaceController != null) {
2031 mSurfaceController.destroyInTransaction();
2032 }
2033 } catch (RuntimeException e) {
2034 Slog.w(TAG, "Exception thrown when destroying surface " + this
2035 + " surface " + mSurfaceController + " session " + mSession + ": " + e);
2036 } finally {
2037 mWin.setHasSurface(false);
2038 mSurfaceController = null;
2039 mDrawState = NO_SURFACE;
2040 }
Robert Carre6a83512015-11-03 16:09:21 -08002041 }
Filip Gruszczynskif52dd202015-11-15 20:36:38 -08002042
2043 void setMoveAnimation(int left, int top) {
2044 final Animation a = AnimationUtils.loadAnimation(mContext,
2045 com.android.internal.R.anim.window_move_from_decor);
2046 setAnimation(a);
2047 mAnimDx = mWin.mLastFrame.left - left;
2048 mAnimDy = mWin.mLastFrame.top - top;
2049 mAnimateMove = true;
2050 }
Robert Carr679c8072016-04-07 15:51:48 -07002051
2052 void deferTransactionUntilParentFrame(long frameNumber) {
2053 if (!mWin.isChildWindow()) {
2054 return;
2055 }
Robert Carr679c8072016-04-07 15:51:48 -07002056 mSurfaceController.deferTransactionUntil(
2057 mWin.mAttachedWindow.mWinAnimator.mSurfaceController.getHandle(),
2058 frameNumber);
2059 }
2060
Jorim Jaggiff71d202016-04-14 13:12:36 -07002061 /**
2062 * Sometimes we need to synchronize the first frame of animation with some external event.
2063 * To achieve this, we prolong the start of the animation and keep producing the first frame of
2064 * the animation.
2065 */
2066 private long getAnimationFrameTime(Animation animation, long currentTime) {
2067 if (mAnimationStartDelayed) {
2068 animation.setStartTime(currentTime);
2069 return currentTime + 1;
2070 }
2071 return currentTime;
2072 }
2073
2074 void startDelayingAnimationStart() {
2075 mAnimationStartDelayed = true;
2076 }
2077
2078 void endDelayingAnimationStart() {
2079 mAnimationStartDelayed = false;
2080 }
Robert Carr6da3cc02016-06-16 15:17:07 -07002081
2082 void seamlesslyRotateWindow(int oldRotation, int newRotation) {
2083 final WindowState w = mWin;
2084 if (!w.isVisibleNow() || w.mIsWallpaper) {
2085 return;
2086 }
2087
2088 final Rect cropRect = mService.mTmpRect;
2089 final Rect displayRect = mService.mTmpRect2;
2090 final RectF frameRect = mService.mTmpRectF;
2091 final Matrix transform = mService.mTmpTransform;
2092
2093 final float x = w.mFrame.left;
2094 final float y = w.mFrame.top;
2095 final float width = w.mFrame.width();
2096 final float height = w.mFrame.height();
2097
2098 mService.getDefaultDisplayContentLocked().getLogicalDisplayRect(displayRect);
2099 final float displayWidth = displayRect.width();
2100 final float displayHeight = displayRect.height();
2101
2102 // Compute a transform matrix to undo the coordinate space transformation,
2103 // and present the window at the same physical position it previously occupied.
2104 final int deltaRotation = DisplayContent.deltaRotation(newRotation, oldRotation);
Andrii Kulian781240d2016-10-05 01:11:52 -07002105 DisplayContent.createRotationMatrix(deltaRotation, x, y, displayWidth, displayHeight,
2106 transform);
Robert Carr6da3cc02016-06-16 15:17:07 -07002107
2108 // We have two cases:
2109 // 1. Windows with NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY:
2110 // These windows never change buffer size when rotating. Rather the window manager
2111 // just updates the scaling factors to fit in the new coordinate system,
2112 // and SurfaceFlinger takes care of updating the buffer contents. So in this case
2113 // we just need we just need to update the scaling factors and things are seamless
2114 // already.
2115 // 2. Other windows:
2116 // In this case, we need to apply a rotation matrix to the window. For example
2117 // if we have a portrait window and rotate to landscape, the window is still portrait
2118 // and now extends off the bottom of the screen (and only halfway across). Essentially we
2119 // apply a transform to display the current buffer at it's old position
2120 // (in the new coordinate space). We then freeze layer updates until the resize
2121 // occurs, at which point we undo, them.
2122 if (w.isChildWindow() && mSurfaceController.getTransformToDisplayInverse()) {
2123 frameRect.set(x, y, x+width, y+height);
2124 transform.mapRect(frameRect);
2125
2126 w.mAttrs.x = (int) frameRect.left - w.mAttachedWindow.mFrame.left;
2127 w.mAttrs.y = (int) frameRect.top - w.mAttachedWindow.mFrame.top;
2128 w.mAttrs.width = (int) Math.ceil(frameRect.width());
2129 w.mAttrs.height = (int) Math.ceil(frameRect.height());
2130
2131 w.setWindowScale(w.mRequestedWidth, w.mRequestedHeight);
2132
2133 w.applyGravityAndUpdateFrame(w.mContainingFrame, w.mDisplayFrame);
2134 computeShownFrameLocked();
2135 setSurfaceBoundariesLocked(false);
2136
2137 // The stack bounds will not yet be rotated at this point so setSurfaceBoundaries locked
2138 // will crop us incorrectly. Overwrite the crop, exposing the full surface. By the next
2139 // transaction this will be corrected.
2140 cropRect.set(0, 0, w.mRequestedWidth, w.mRequestedWidth + w.mRequestedHeight);
2141 mSurfaceController.setCropInTransaction(cropRect, false);
2142 } else {
Robert Carrb14d4abc2016-10-03 18:13:33 -07002143 mService.markForSeamlessRotation(w, true);
Robert Carr6da3cc02016-06-16 15:17:07 -07002144 transform.getValues(mService.mTmpFloats);
2145
2146 float DsDx = mService.mTmpFloats[Matrix.MSCALE_X];
2147 float DtDx = mService.mTmpFloats[Matrix.MSKEW_Y];
2148 float DsDy = mService.mTmpFloats[Matrix.MSKEW_X];
2149 float DtDy = mService.mTmpFloats[Matrix.MSCALE_Y];
2150 float nx = mService.mTmpFloats[Matrix.MTRANS_X];
2151 float ny = mService.mTmpFloats[Matrix.MTRANS_Y];
2152 mSurfaceController.setPositionInTransaction(nx, ny, false);
2153 mSurfaceController.setMatrixInTransaction(DsDx * w.mHScale,
2154 DtDx * w.mVScale,
2155 DsDy * w.mHScale,
2156 DtDy * w.mVScale, false);
2157 }
2158 }
Craig Mautnera2c77052012-03-26 12:14:43 -07002159}