blob: 788f28dadfebf4cd18a6391ce991fa8040c8717a [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;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -080020import static android.view.Display.DEFAULT_DISPLAY;
Wale Ogunwalee7bf46b2015-09-30 09:19:28 -070021import static android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -080022import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070023import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Jorim Jaggieb88d832016-04-13 20:17:43 -070024import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
Jorim Jaggiff71d202016-04-14 13:12:36 -070025import static com.android.server.wm.AppWindowAnimator.sDummyAnimation;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +010026import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080027import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
28import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
29import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
30import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
31import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
32import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE;
33import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
34import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -080035import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_CROP;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080036import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
37import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
38import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
39import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
40import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang97782b42015-10-07 16:01:23 -070041import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -080042import static com.android.server.wm.WindowManagerService.localLOGV;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080043import static com.android.server.wm.WindowManagerService.logWithStack;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070044import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
45import static com.android.server.wm.WindowSurfacePlacer.SET_TURN_ON_SCREEN;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070046
Craig Mautnerc2f9be02012-03-27 17:32:29 -070047import android.content.Context;
48import android.graphics.Matrix;
49import android.graphics.PixelFormat;
Craig Mautner7358fbf2012-04-12 21:06:33 -070050import android.graphics.Point;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070051import android.graphics.Rect;
Robert Carr6da3cc02016-06-16 15:17:07 -070052import android.graphics.RectF;
Craig Mautner48ba1e72012-04-02 13:18:16 -070053import android.graphics.Region;
Craig Mautnera51a9562012-04-17 17:05:26 -070054import android.os.Debug;
Chong Zhang8784be62016-06-28 15:25:07 -070055import android.os.Trace;
Craig Mautnera2c77052012-03-26 12:14:43 -070056import android.util.Slog;
Craig Mautner59c00972012-07-30 12:10:24 -070057import android.view.DisplayInfo;
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -070058import android.view.MagnificationSpec;
Robert Carr6da3cc02016-06-16 15:17:07 -070059import android.view.Surface;
Igor Murashkina86ab6402013-08-30 12:58:36 -070060import android.view.Surface.OutOfResourcesException;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080061import android.view.SurfaceControl;
Craig Mautnera2c77052012-03-26 12:14:43 -070062import android.view.WindowManager;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070063import android.view.WindowManager.LayoutParams;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -080064import android.view.WindowManagerPolicy;
Craig Mautnera2c77052012-03-26 12:14:43 -070065import android.view.animation.Animation;
Jorim Jaggif8d77da2014-11-11 16:59:12 +010066import android.view.animation.AnimationSet;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070067import android.view.animation.AnimationUtils;
Craig Mautnera2c77052012-03-26 12:14:43 -070068import android.view.animation.Transformation;
69
70import com.android.server.wm.WindowManagerService.H;
71
72import java.io.PrintWriter;
73
74/**
Craig Mautnerc2f9be02012-03-27 17:32:29 -070075 * Keep track of animations and surface operations for a single WindowState.
76 **/
Craig Mautnera2c77052012-03-26 12:14:43 -070077class WindowStateAnimator {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080078 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowStateAnimator" : TAG_WM;
Chong Zhang97782b42015-10-07 16:01:23 -070079 static final int WINDOW_FREEZE_LAYER = TYPE_LAYER_MULTIPLIER * 200;
Craig Mautnera2c77052012-03-26 12:14:43 -070080
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010081 /**
82 * Mode how the window gets clipped by the stack bounds during an animation: The clipping should
83 * be applied after applying the animation transformation, i.e. the stack bounds don't move
84 * during the animation.
85 */
86 static final int STACK_CLIP_AFTER_ANIM = 0;
87
88 /**
89 * Mode how the window gets clipped by the stack bounds: The clipping should be applied before
90 * applying the animation transformation, i.e. the stack bounds move with the window.
91 */
92 static final int STACK_CLIP_BEFORE_ANIM = 1;
93
94 /**
95 * Mode how window gets clipped by the stack bounds during an animation: Don't clip the window
96 * by the stack bounds.
97 */
98 static final int STACK_CLIP_NONE = 2;
99
Craig Mautner918b53b2012-07-09 14:15:54 -0700100 // Unchanging local convenience fields.
Craig Mautnera2c77052012-03-26 12:14:43 -0700101 final WindowManagerService mService;
102 final WindowState mWin;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700103 private final WindowStateAnimator mParentWinAnimator;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700104 final WindowAnimator mAnimator;
Craig Mautner8863cca2012-09-18 15:04:34 -0700105 AppWindowAnimator mAppAnimator;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700106 final Session mSession;
107 final WindowManagerPolicy mPolicy;
108 final Context mContext;
Craig Mautner918b53b2012-07-09 14:15:54 -0700109 final boolean mIsWallpaper;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -0700110 private final WallpaperController mWallpaperControllerLocked;
Craig Mautnera2c77052012-03-26 12:14:43 -0700111
112 // Currently running animation.
113 boolean mAnimating;
114 boolean mLocalAnimating;
115 Animation mAnimation;
116 boolean mAnimationIsEntrance;
117 boolean mHasTransformation;
118 boolean mHasLocalTransformation;
119 final Transformation mTransformation = new Transformation();
120 boolean mWasAnimating; // Were we animating going into the most recent animation step?
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700121 int mAnimLayer;
122 int mLastLayer;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100123 long mAnimationStartTime;
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100124 long mLastAnimationTime;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100125 int mStackClip = STACK_CLIP_BEFORE_ANIM;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700126
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700127 /**
128 * Set when we have changed the size of the surface, to know that
129 * we must tell them application to resize (and thus redraw itself).
130 */
131 boolean mSurfaceResized;
Chong Zhang5b2f1992015-11-13 15:40:36 -0800132 /**
133 * Whether we should inform the client on next relayoutWindow that
134 * the surface has been resized since last time.
135 */
136 boolean mReportSurfaceResized;
Robert Carre6a83512015-11-03 16:09:21 -0800137 WindowSurfaceController mSurfaceController;
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800138 private WindowSurfaceController mPendingDestroySurface;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700139
140 /**
141 * Set if the client has asked that the destroy of its surface be delayed
142 * until it explicitly says it is okay.
143 */
144 boolean mSurfaceDestroyDeferred;
145
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800146 private boolean mDestroyPreservedSurfaceUponRedraw;
Craig Mautner7d8df392012-04-06 15:26:23 -0700147 float mShownAlpha = 0;
148 float mAlpha = 0;
149 float mLastAlpha = 0;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700150
Winson Chung399f6202014-03-19 10:47:20 -0700151 boolean mHasClipRect;
152 Rect mClipRect = new Rect();
153 Rect mTmpClipRect = new Rect();
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100154 Rect mTmpFinalClipRect = new Rect();
Winson Chung399f6202014-03-19 10:47:20 -0700155 Rect mLastClipRect = new Rect();
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100156 Rect mLastFinalClipRect = new Rect();
Filip Gruszczynski4b8eea72015-09-14 18:16:19 -0700157 Rect mTmpStackBounds = new Rect();
Winson Chung399f6202014-03-19 10:47:20 -0700158
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -0800159 /**
160 * This is rectangle of the window's surface that is not covered by
161 * system decorations.
162 */
163 private final Rect mSystemDecorRect = new Rect();
164 private final Rect mLastSystemDecorRect = new Rect();
165
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800166 // Used to save animation distances between the time they are calculated and when they are used.
167 private int mAnimDx;
168 private int mAnimDy;
Jorim Jaggic5af4f82015-07-01 17:16:27 -0700169
170 /** Is the next animation to be started a window move animation? */
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800171 private boolean mAnimateMove = false;
Jorim Jaggic5af4f82015-07-01 17:16:27 -0700172
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700173 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
174 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
175
176 boolean mHaveMatrix;
177
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700178 // Set to true if, when the window gets displayed, it should perform
179 // an enter animation.
180 boolean mEnterAnimationPending;
Craig Mautnera2c77052012-03-26 12:14:43 -0700181
Craig Mautner9c795042014-10-28 19:59:59 -0700182 /** Used to indicate that this window is undergoing an enter animation. Used for system
183 * windows to make the callback to View.dispatchOnWindowShownCallback(). Set when the
184 * window is first added or shown, cleared when the callback has been made. */
185 boolean mEnteringAnimation;
186
Jorim Jaggiff71d202016-04-14 13:12:36 -0700187 private boolean mAnimationStartDelayed;
188
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100189 boolean mKeyguardGoingAwayAnimation;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800190 boolean mKeyguardGoingAwayWithWallpaper;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200191
John Reck80181b92015-05-19 11:09:32 -0700192 /** The pixel format of the underlying SurfaceControl */
193 int mSurfaceFormat;
194
Craig Mautner749a7bb2012-04-02 13:49:53 -0700195 /** This is set when there is no Surface */
196 static final int NO_SURFACE = 0;
197 /** This is set after the Surface has been created but before the window has been drawn. During
198 * this time the surface is hidden. */
199 static final int DRAW_PENDING = 1;
200 /** This is set after the window has finished drawing for the first time but before its surface
201 * is shown. The surface will be displayed when the next layout is run. */
202 static final int COMMIT_DRAW_PENDING = 2;
203 /** This is set during the time after the window's drawing has been committed, and before its
204 * surface is actually shown. It is used to delay showing the surface until all windows in a
205 * token are ready to be shown. */
206 static final int READY_TO_SHOW = 3;
207 /** Set when the window has been shown in the screen the first time. */
208 static final int HAS_DRAWN = 4;
Adrian Roos3eeb4e62014-05-19 12:43:26 +0200209
Craig Mautner276a6eb2014-11-04 15:32:57 -0800210 String drawStateToString() {
211 switch (mDrawState) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700212 case NO_SURFACE: return "NO_SURFACE";
213 case DRAW_PENDING: return "DRAW_PENDING";
214 case COMMIT_DRAW_PENDING: return "COMMIT_DRAW_PENDING";
215 case READY_TO_SHOW: return "READY_TO_SHOW";
216 case HAS_DRAWN: return "HAS_DRAWN";
Craig Mautner276a6eb2014-11-04 15:32:57 -0800217 default: return Integer.toString(mDrawState);
Craig Mautner6fbda632012-07-03 09:26:39 -0700218 }
219 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700220 int mDrawState;
Craig Mautnera608b882012-03-30 13:03:49 -0700221
Craig Mautner749a7bb2012-04-02 13:49:53 -0700222 /** Was this window last hidden? */
223 boolean mLastHidden;
Craig Mautnera608b882012-03-30 13:03:49 -0700224
Craig Mautnerbec53f72012-04-05 11:49:05 -0700225 int mAttrType;
226
Robert Carr679c8072016-04-07 15:51:48 -0700227 static final long PENDING_TRANSACTION_FINISH_WAIT_TIME = 100;
Robert Carr679c8072016-04-07 15:51:48 -0700228
Robert Carrc7294602016-05-13 11:32:05 -0700229 boolean mForceScaleUntilResize;
230
Robert Carr04092112016-06-02 12:56:12 -0700231 // WindowState.mHScale and WindowState.mVScale contain the
232 // scale according to client specified layout parameters (e.g.
233 // one layout size, with another surface size, creates such scaling).
234 // Here we track an additional scaling factor used to follow stack
235 // scaling (as in the case of the Pinned stack animation).
236 float mExtraHScale = (float) 1.0;
237 float mExtraVScale = (float) 1.0;
238
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800239 private final Rect mTmpSize = new Rect();
240
Craig Mautnerc431e892015-02-11 13:14:26 -0800241 WindowStateAnimator(final WindowState win) {
Craig Mautner918b53b2012-07-09 14:15:54 -0700242 final WindowManagerService service = win.mService;
243
Craig Mautnera2c77052012-03-26 12:14:43 -0700244 mService = service;
Craig Mautner918b53b2012-07-09 14:15:54 -0700245 mAnimator = service.mAnimator;
246 mPolicy = service.mPolicy;
247 mContext = service.mContext;
Craig Mautnerd3849f52014-03-27 13:19:29 -0700248 final DisplayContent displayContent = win.getDisplayContent();
249 if (displayContent != null) {
250 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800251 mAnimDx = displayInfo.appWidth;
252 mAnimDy = displayInfo.appHeight;
Craig Mautnerd3849f52014-03-27 13:19:29 -0700253 } else {
254 Slog.w(TAG, "WindowStateAnimator ctor: Display has been removed");
255 // This is checked on return and dealt with.
256 }
Craig Mautner918b53b2012-07-09 14:15:54 -0700257
258 mWin = win;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -0700259 mParentWinAnimator = !win.isChildWindow() ? null : win.getParentWindow().mWinAnimator;
Craig Mautner322e4032012-07-13 13:35:20 -0700260 mAppAnimator = win.mAppToken == null ? null : win.mAppToken.mAppAnimator;
Craig Mautner918b53b2012-07-09 14:15:54 -0700261 mSession = win.mSession;
Craig Mautner918b53b2012-07-09 14:15:54 -0700262 mAttrType = win.mAttrs.type;
263 mIsWallpaper = win.mIsWallpaper;
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700264 mWallpaperControllerLocked = mService.mWallpaperControllerLocked;
Craig Mautnera2c77052012-03-26 12:14:43 -0700265 }
266
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100267 public void setAnimation(Animation anim, long startTime, int stackClip) {
Craig Mautnerbec53f72012-04-05 11:49:05 -0700268 if (localLOGV) Slog.v(TAG, "Setting animation in " + this + ": " + anim);
Craig Mautnera2c77052012-03-26 12:14:43 -0700269 mAnimating = false;
270 mLocalAnimating = false;
271 mAnimation = anim;
272 mAnimation.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION);
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700273 mAnimation.scaleCurrentDuration(mService.getWindowAnimationScaleLocked());
Craig Mautnera2c77052012-03-26 12:14:43 -0700274 // Start out animation gone if window is gone, or visible if window is visible.
275 mTransformation.clear();
Craig Mautner749a7bb2012-04-02 13:49:53 -0700276 mTransformation.setAlpha(mLastHidden ? 0 : 1);
Craig Mautnera2c77052012-03-26 12:14:43 -0700277 mHasLocalTransformation = true;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100278 mAnimationStartTime = startTime;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100279 mStackClip = stackClip;
280 }
281
282 public void setAnimation(Animation anim, int stackClip) {
283 setAnimation(anim, -1, stackClip);
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100284 }
285
286 public void setAnimation(Animation anim) {
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100287 setAnimation(anim, -1, STACK_CLIP_AFTER_ANIM);
Craig Mautnera2c77052012-03-26 12:14:43 -0700288 }
289
290 public void clearAnimation() {
291 if (mAnimation != null) {
292 mAnimating = true;
293 mLocalAnimating = false;
294 mAnimation.cancel();
295 mAnimation = null;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100296 mKeyguardGoingAwayAnimation = false;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800297 mKeyguardGoingAwayWithWallpaper = false;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100298 mStackClip = STACK_CLIP_BEFORE_ANIM;
Craig Mautnera2c77052012-03-26 12:14:43 -0700299 }
300 }
301
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700302 /**
303 * Is the window or its container currently set to animate or currently animating?
304 */
305 boolean isAnimationSet() {
Craig Mautnera2c77052012-03-26 12:14:43 -0700306 return mAnimation != null
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700307 || (mParentWinAnimator != null && mParentWinAnimator.mAnimation != null)
Jorim Jaggi37875612015-02-19 21:05:31 +0100308 || (mAppAnimator != null && mAppAnimator.isAnimating());
Craig Mautnera2c77052012-03-26 12:14:43 -0700309 }
310
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700311 /**
312 * @return whether an animation is about to start, i.e. the animation is set already but we
313 * haven't processed the first frame yet.
314 */
315 boolean isAnimationStarting() {
316 return isAnimationSet() && !mAnimating;
317 }
318
Craig Mautner0afddcb2012-05-08 15:38:00 -0700319 /** Is the window animating the DummyAnimation? */
320 boolean isDummyAnimation() {
Craig Mautner322e4032012-07-13 13:35:20 -0700321 return mAppAnimator != null
Jorim Jaggiff71d202016-04-14 13:12:36 -0700322 && mAppAnimator.animation == sDummyAnimation;
Craig Mautner0afddcb2012-05-08 15:38:00 -0700323 }
324
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700325 /**
326 * Is this window currently set to animate or currently animating?
327 */
328 boolean isWindowAnimationSet() {
Craig Mautnera2c77052012-03-26 12:14:43 -0700329 return mAnimation != null;
330 }
331
Chong Zhange22006d2016-05-09 10:59:59 -0700332 /**
333 * Is this window currently waiting to run an opening animation?
334 */
335 boolean isWaitingForOpening() {
336 return mService.mAppTransition.isTransitionSet() && isDummyAnimation()
337 && mService.mOpeningApps.contains(mWin.mAppToken);
338 }
339
Craig Mautnera2c77052012-03-26 12:14:43 -0700340 void cancelExitAnimationForNextAnimationLocked() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800341 if (DEBUG_ANIM) Slog.d(TAG,
342 "cancelExitAnimationForNextAnimationLocked: " + mWin);
343
Craig Mautnera2c77052012-03-26 12:14:43 -0700344 if (mAnimation != null) {
345 mAnimation.cancel();
346 mAnimation = null;
Craig Mautner4d7349b2012-04-20 14:52:47 -0700347 mLocalAnimating = false;
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800348 mWin.destroyOrSaveSurface();
Craig Mautnera2c77052012-03-26 12:14:43 -0700349 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700350 }
351
352 private boolean stepAnimation(long currentTime) {
353 if ((mAnimation == null) || !mLocalAnimating) {
354 return false;
355 }
Jorim Jaggiff71d202016-04-14 13:12:36 -0700356 currentTime = getAnimationFrameTime(mAnimation, currentTime);
Craig Mautnera2c77052012-03-26 12:14:43 -0700357 mTransformation.clear();
358 final boolean more = mAnimation.getTransformation(currentTime, mTransformation);
Jorim Jaggiff71d202016-04-14 13:12:36 -0700359 if (mAnimationStartDelayed && mAnimationIsEntrance) {
360 mTransformation.setAlpha(0f);
361 }
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700362 if (false && DEBUG_ANIM) Slog.v(TAG, "Stepped animation in " + this + ": more=" + more
363 + ", xform=" + mTransformation);
Craig Mautnera2c77052012-03-26 12:14:43 -0700364 return more;
365 }
366
367 // This must be called while inside a transaction. Returns true if
368 // there is more animation to run.
369 boolean stepAnimationLocked(long currentTime) {
Chet Haase9c450412015-10-01 13:25:58 -0700370 // Save the animation state as it was before this step so WindowManagerService can tell if
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700371 // we just started or just stopped animating by comparing mWasAnimating with isAnimationSet().
Chet Haase9c450412015-10-01 13:25:58 -0700372 mWasAnimating = mAnimating;
Craig Mautnerdf88d732014-01-27 09:21:32 -0800373 final DisplayContent displayContent = mWin.getDisplayContent();
374 if (displayContent != null && mService.okToDisplay()) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700375 // We will run animations as long as the display isn't frozen.
376
377 if (mWin.isDrawnLw() && mAnimation != null) {
378 mHasTransformation = true;
379 mHasLocalTransformation = true;
380 if (!mLocalAnimating) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700381 if (DEBUG_ANIM) Slog.v(
382 TAG, "Starting animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700383 " @ " + currentTime + ": ww=" + mWin.mFrame.width() +
384 " wh=" + mWin.mFrame.height() +
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800385 " dx=" + mAnimDx + " dy=" + mAnimDy +
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700386 " scale=" + mService.getWindowAnimationScaleLocked());
Craig Mautnerdf88d732014-01-27 09:21:32 -0800387 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
tiger_huangb7f3f922015-04-27 20:36:46 +0800388 if (mAnimateMove) {
389 mAnimateMove = false;
390 mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(),
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800391 mAnimDx, mAnimDy);
tiger_huangb7f3f922015-04-27 20:36:46 +0800392 } else {
393 mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(),
394 displayInfo.appWidth, displayInfo.appHeight);
395 }
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800396 mAnimDx = displayInfo.appWidth;
397 mAnimDy = displayInfo.appHeight;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100398 mAnimation.setStartTime(mAnimationStartTime != -1
399 ? mAnimationStartTime
400 : currentTime);
Craig Mautnera2c77052012-03-26 12:14:43 -0700401 mLocalAnimating = true;
402 mAnimating = true;
403 }
404 if ((mAnimation != null) && mLocalAnimating) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100405 mLastAnimationTime = currentTime;
Craig Mautnera2c77052012-03-26 12:14:43 -0700406 if (stepAnimation(currentTime)) {
407 return true;
408 }
409 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700410 if (DEBUG_ANIM) Slog.v(
411 TAG, "Finished animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700412 " @ " + currentTime);
413 //WindowManagerService.this.dump();
414 }
415 mHasLocalTransformation = false;
Craig Mautner322e4032012-07-13 13:35:20 -0700416 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppAnimator != null
417 && mAppAnimator.animation != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700418 // When our app token is animating, we kind-of pretend like
419 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
420 // part of this check means that we will only do this if
421 // our window is not currently exiting, or it is not
422 // locally animating itself. The idea being that one that
423 // is exiting and doing a local animation should be removed
424 // once that animation is done.
425 mAnimating = true;
426 mHasTransformation = true;
427 mTransformation.clear();
428 return false;
429 } else if (mHasTransformation) {
430 // Little trick to get through the path below to act like
431 // we have finished an animation.
432 mAnimating = true;
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700433 } else if (isAnimationSet()) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700434 mAnimating = true;
435 }
436 } else if (mAnimation != null) {
437 // If the display is frozen, and there is a pending animation,
438 // clear it and make sure we run the cleanup code.
439 mAnimating = true;
Craig Mautnera2c77052012-03-26 12:14:43 -0700440 }
441
442 if (!mAnimating && !mLocalAnimating) {
443 return false;
444 }
445
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700446 // Done animating, clean up.
447 if (DEBUG_ANIM) Slog.v(
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800448 TAG, "Animation done in " + this + ": exiting=" + mWin.mAnimatingExit
Craig Mautnera2c77052012-03-26 12:14:43 -0700449 + ", reportedVisible="
450 + (mWin.mAppToken != null ? mWin.mAppToken.reportedVisible : false));
451
452 mAnimating = false;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100453 mKeyguardGoingAwayAnimation = false;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800454 mKeyguardGoingAwayWithWallpaper = false;
Craig Mautnera2c77052012-03-26 12:14:43 -0700455 mLocalAnimating = false;
456 if (mAnimation != null) {
457 mAnimation.cancel();
458 mAnimation = null;
459 }
Craig Mautnere7ae2502012-03-26 17:11:19 -0700460 if (mAnimator.mWindowDetachedWallpaper == mWin) {
461 mAnimator.mWindowDetachedWallpaper = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700462 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -0800463 mAnimLayer = mWin.mLayer
464 + mService.mLayersController.getSpecialWindowAnimLayerAdjustment(mWin);
Filip Gruszczynski14b4e572015-11-03 15:53:55 -0800465 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this + " anim layer: " + mAnimLayer);
Craig Mautnera2c77052012-03-26 12:14:43 -0700466 mHasTransformation = false;
467 mHasLocalTransformation = false;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100468 mStackClip = STACK_CLIP_BEFORE_ANIM;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -0800469 mWin.checkPolicyVisibilityChange();
Craig Mautnera2c77052012-03-26 12:14:43 -0700470 mTransformation.clear();
Craig Mautner749a7bb2012-04-02 13:49:53 -0700471 if (mDrawState == HAS_DRAWN
Craig Mautnera2c77052012-03-26 12:14:43 -0700472 && mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
473 && mWin.mAppToken != null
474 && mWin.mAppToken.firstWindowDrawn
475 && mWin.mAppToken.startingData != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700476 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
Craig Mautnera2c77052012-03-26 12:14:43 -0700477 + mWin.mToken + ": first real window done animating");
478 mService.mFinishedStarting.add(mWin.mAppToken);
479 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
Craig Mautner81defc72013-10-29 11:10:42 -0700480 } else if (mAttrType == LayoutParams.TYPE_STATUS_BAR && mWin.mPolicyVisibility) {
481 // Upon completion of a not-visible to visible status bar animation a relayout is
482 // required.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800483 if (displayContent != null) {
484 displayContent.layoutNeeded = true;
485 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700486 }
487
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700488 mWin.onExitAnimationDone();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800489 final int displayId = mWin.getDisplayId();
Craig Mautner76a71652012-09-03 23:23:58 -0700490 mAnimator.setPendingLayoutChanges(displayId, WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800491 if (DEBUG_LAYOUT_REPEATS)
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700492 mService.mWindowPlacerLocked.debugLayoutRepeats(
493 "WindowStateAnimator", mAnimator.getPendingLayoutChanges(displayId));
Craig Mautnera2c77052012-03-26 12:14:43 -0700494
495 if (mWin.mAppToken != null) {
496 mWin.mAppToken.updateReportedVisibilityLocked();
497 }
498
499 return false;
500 }
501
Filip Gruszczynski63a35e22015-11-05 15:38:59 -0800502 void hide(String reason) {
Craig Mautner0afddcb2012-05-08 15:38:00 -0700503 if (!mLastHidden) {
504 //dump();
505 mLastHidden = true;
Wale Ogunwalef9e09782015-11-09 12:42:37 -0800506 if (mSurfaceController != null) {
507 mSurfaceController.hideInTransaction(reason);
508 }
Craig Mautner0afddcb2012-05-08 15:38:00 -0700509 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700510 }
511
Craig Mautnera608b882012-03-30 13:03:49 -0700512 boolean finishDrawingLocked() {
Craig Mautner42d04db2014-11-06 12:13:23 -0800513 final boolean startingWindow =
514 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
515 if (DEBUG_STARTING_WINDOW && startingWindow) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700516 Slog.v(TAG, "Finishing drawing window " + mWin + ": mDrawState="
Craig Mautner276a6eb2014-11-04 15:32:57 -0800517 + drawStateToString());
Craig Mautner6fbda632012-07-03 09:26:39 -0700518 }
Robert Carr1ca6a332016-04-11 18:00:43 -0700519
Chong Zhangcbbcc0f2016-05-17 20:46:58 -0700520 boolean layoutNeeded = mWin.clearAnimatingWithSavedSurface();
Chong Zhang92147042016-05-09 12:47:11 -0700521
Craig Mautner749a7bb2012-04-02 13:49:53 -0700522 if (mDrawState == DRAW_PENDING) {
Craig Mautneref25d7a2012-05-15 23:01:47 -0700523 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
Chong Zhang5b2f1992015-11-13 15:40:36 -0800524 Slog.v(TAG, "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING " + mWin + " in "
Robert Carre6a83512015-11-03 16:09:21 -0800525 + mSurfaceController);
Craig Mautner42d04db2014-11-06 12:13:23 -0800526 if (DEBUG_STARTING_WINDOW && startingWindow) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700527 Slog.v(TAG, "Draw state now committed in " + mWin);
528 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700529 mDrawState = COMMIT_DRAW_PENDING;
Chong Zhangcbbcc0f2016-05-17 20:46:58 -0700530 layoutNeeded = true;
Craig Mautnera608b882012-03-30 13:03:49 -0700531 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700532
Chong Zhangcbbcc0f2016-05-17 20:46:58 -0700533 return layoutNeeded;
Craig Mautnera608b882012-03-30 13:03:49 -0700534 }
535
536 // This must be called while inside a transaction.
Craig Mautnerc431e892015-02-11 13:14:26 -0800537 boolean commitFinishDrawingLocked() {
Craig Mautner6fbda632012-07-03 09:26:39 -0700538 if (DEBUG_STARTING_WINDOW &&
539 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
540 Slog.i(TAG, "commitFinishDrawingLocked: " + mWin + " cur mDrawState="
Craig Mautner276a6eb2014-11-04 15:32:57 -0800541 + drawStateToString());
Craig Mautner6fbda632012-07-03 09:26:39 -0700542 }
Craig Mautner276a6eb2014-11-04 15:32:57 -0800543 if (mDrawState != COMMIT_DRAW_PENDING && mDrawState != READY_TO_SHOW) {
Craig Mautnera608b882012-03-30 13:03:49 -0700544 return false;
545 }
Craig Mautner6fbda632012-07-03 09:26:39 -0700546 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) {
Robert Carre6a83512015-11-03 16:09:21 -0800547 Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurfaceController);
Craig Mautner6fbda632012-07-03 09:26:39 -0700548 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700549 mDrawState = READY_TO_SHOW;
Chong Zhang0275e392015-09-17 10:41:44 -0700550 boolean result = false;
Craig Mautnera608b882012-03-30 13:03:49 -0700551 final AppWindowToken atoken = mWin.mAppToken;
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800552 if (atoken == null || atoken.allDrawn || mWin.mAttrs.type == TYPE_APPLICATION_STARTING) {
Wale Ogunwale9d147902016-07-16 11:58:55 -0700553 result = mWin.performShowLocked();
Chong Zhang0275e392015-09-17 10:41:44 -0700554 }
Chong Zhang97782b42015-10-07 16:01:23 -0700555 return result;
Craig Mautnera608b882012-03-30 13:03:49 -0700556 }
557
Chong Zhang97782b42015-10-07 16:01:23 -0700558 void preserveSurfaceLocked() {
559 if (mDestroyPreservedSurfaceUponRedraw) {
Chong Zhangb9b0fec2016-02-11 18:51:51 -0800560 // This could happen when switching the surface mode very fast. For example,
561 // we preserved a surface when dragResizing changed to true. Then before the
562 // preserved surface is removed, dragResizing changed to false again.
563 // In this case, we need to leave the preserved surface alone, and destroy
564 // the actual surface, so that the createSurface call could create a surface
565 // of the proper size. The preserved surface will still be removed when client
566 // finishes drawing to the new surface.
567 mSurfaceDestroyDeferred = false;
568 destroySurfaceLocked();
569 mSurfaceDestroyDeferred = true;
Chong Zhang97782b42015-10-07 16:01:23 -0700570 return;
571 }
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -0800572 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, "SET FREEZE LAYER", false);
Wale Ogunwalef9e09782015-11-09 12:42:37 -0800573 if (mSurfaceController != null) {
574 mSurfaceController.setLayer(mAnimLayer + 1);
575 }
Chong Zhang97782b42015-10-07 16:01:23 -0700576 mDestroyPreservedSurfaceUponRedraw = true;
577 mSurfaceDestroyDeferred = true;
578 destroySurfaceLocked();
579 }
580
581 void destroyPreservedSurfaceLocked() {
582 if (!mDestroyPreservedSurfaceUponRedraw) {
583 return;
584 }
585 destroyDeferredSurfaceLocked();
586 mDestroyPreservedSurfaceUponRedraw = false;
587 }
588
Chong Zhangeb665572016-05-09 18:28:27 -0700589 void markPreservedSurfaceForDestroy() {
590 if (mDestroyPreservedSurfaceUponRedraw
591 && !mService.mDestroyPreservedSurface.contains(mWin)) {
592 mService.mDestroyPreservedSurface.add(mWin);
593 }
594 }
595
Robert Carre6a83512015-11-03 16:09:21 -0800596 WindowSurfaceController createSurfaceLocked() {
Alan Viveretteccb11e12014-07-08 16:04:02 -0700597 final WindowState w = mWin;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700598 if (w.restoreSavedSurface()) {
Chong Zhang0464a932016-02-03 11:47:16 -0800599 if (DEBUG_ANIM) Slog.i(TAG,
600 "createSurface: " + this + ": called when we had a saved surface");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800601 return mSurfaceController;
Chong Zhanga8975bd2016-01-28 17:13:47 -0800602 }
603
Wale Ogunwale722ff892016-02-18 13:37:55 -0800604 if (mSurfaceController != null) {
605 return mSurfaceController;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700606 }
Wale Ogunwale722ff892016-02-18 13:37:55 -0800607
608 w.setHasSurface(false);
609
610 if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG,
611 "createSurface " + this + ": mDrawState=DRAW_PENDING");
612
613 mDrawState = DRAW_PENDING;
614 if (w.mAppToken != null) {
615 if (w.mAppToken.mAppAnimator.animation == null) {
Chong Zhang92147042016-05-09 12:47:11 -0700616 w.mAppToken.clearAllDrawn();
Wale Ogunwale722ff892016-02-18 13:37:55 -0800617 } else {
618 // Currently animating, persist current state of allDrawn until animation
619 // is complete.
620 w.mAppToken.deferClearAllDrawn = true;
621 }
622 }
623
624 mService.makeWindowFreezingScreenIfNeededLocked(w);
625
626 int flags = SurfaceControl.HIDDEN;
627 final WindowManager.LayoutParams attrs = w.mAttrs;
628
629 if (mService.isSecureLocked(w)) {
630 flags |= SurfaceControl.SECURE;
631 }
632
633 mTmpSize.set(w.mFrame.left + w.mXOffset, w.mFrame.top + w.mYOffset, 0, 0);
634 calculateSurfaceBounds(w, attrs);
635 final int width = mTmpSize.width();
636 final int height = mTmpSize.height();
637
638 if (DEBUG_VISIBILITY) {
639 Slog.v(TAG, "Creating surface in session "
640 + mSession.mSurfaceSession + " window " + this
641 + " w=" + width + " h=" + height
642 + " x=" + mTmpSize.left + " y=" + mTmpSize.top
643 + " format=" + attrs.format + " flags=" + flags);
644 }
645
646 // We may abort, so initialize to defaults.
647 mLastSystemDecorRect.set(0, 0, 0, 0);
648 mHasClipRect = false;
649 mClipRect.set(0, 0, 0, 0);
650 mLastClipRect.set(0, 0, 0, 0);
651
652 // Set up surface control with initial size.
653 try {
654
655 final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0;
656 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
657 if (!PixelFormat.formatHasAlpha(attrs.format)
658 // Don't make surface with surfaceInsets opaque as they display a
659 // translucent shadow.
660 && attrs.surfaceInsets.left == 0
661 && attrs.surfaceInsets.top == 0
662 && attrs.surfaceInsets.right == 0
663 && attrs.surfaceInsets.bottom == 0
664 // Don't make surface opaque when resizing to reduce the amount of
665 // artifacts shown in areas the app isn't drawing content to.
666 && !w.isDragResizing()) {
667 flags |= SurfaceControl.OPAQUE;
668 }
669
670 mSurfaceController = new WindowSurfaceController(mSession.mSurfaceSession,
671 attrs.getTitle().toString(),
672 width, height, format, flags, this);
673
674 w.setHasSurface(true);
675
676 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
677 Slog.i(TAG, " CREATE SURFACE "
678 + mSurfaceController + " IN SESSION "
679 + mSession.mSurfaceSession
680 + ": pid=" + mSession.mPid + " format="
681 + attrs.format + " flags=0x"
682 + Integer.toHexString(flags)
683 + " / " + this);
684 }
685 } catch (OutOfResourcesException e) {
686 Slog.w(TAG, "OutOfResourcesException creating surface");
687 mService.reclaimSomeSurfaceMemoryLocked(this, "create", true);
688 mDrawState = NO_SURFACE;
689 return null;
690 } catch (Exception e) {
691 Slog.e(TAG, "Exception creating surface", e);
692 mDrawState = NO_SURFACE;
693 return null;
694 }
695
696 if (WindowManagerService.localLOGV) Slog.v(TAG, "Got surface: " + mSurfaceController
697 + ", set left=" + w.mFrame.left + " top=" + w.mFrame.top
698 + ", animLayer=" + mAnimLayer);
699
700 if (SHOW_LIGHT_TRANSACTIONS) {
701 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
702 WindowManagerService.logSurface(w, "CREATE pos=("
703 + w.mFrame.left + "," + w.mFrame.top + ") ("
704 + width + "x" + height + "), layer=" + mAnimLayer + " HIDE", false);
705 }
706
707 // Start a new transaction and apply position & offset.
708 final int layerStack = w.getDisplayContent().getDisplay().getLayerStack();
Wale Ogunwale722ff892016-02-18 13:37:55 -0800709 mSurfaceController.setPositionAndLayer(mTmpSize.left, mTmpSize.top, layerStack, mAnimLayer);
710 mLastHidden = true;
711
712 if (WindowManagerService.localLOGV) Slog.v(TAG, "Created surface " + this);
Robert Carre6a83512015-11-03 16:09:21 -0800713 return mSurfaceController;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700714 }
715
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800716 private void calculateSurfaceBounds(WindowState w, LayoutParams attrs) {
717 if ((attrs.flags & FLAG_SCALED) != 0) {
718 // For a scaled surface, we always want the requested size.
719 mTmpSize.right = mTmpSize.left + w.mRequestedWidth;
720 mTmpSize.bottom = mTmpSize.top + w.mRequestedHeight;
721 } else {
722 // When we're doing a drag-resizing, request a surface that's fullscreen size,
723 // so that we don't need to reallocate during the process. This also prevents
724 // buffer drops due to size mismatch.
725 if (w.isDragResizing()) {
726 if (w.getResizeMode() == DRAG_RESIZE_MODE_FREEFORM) {
727 mTmpSize.left = 0;
728 mTmpSize.top = 0;
729 }
730 final DisplayInfo displayInfo = w.getDisplayInfo();
731 mTmpSize.right = mTmpSize.left + displayInfo.logicalWidth;
732 mTmpSize.bottom = mTmpSize.top + displayInfo.logicalHeight;
733 } else {
734 mTmpSize.right = mTmpSize.left + w.mCompatFrame.width();
735 mTmpSize.bottom = mTmpSize.top + w.mCompatFrame.height();
736 }
737 }
738
739 // Something is wrong and SurfaceFlinger will not like this, try to revert to sane values.
Filip Gruszczynskie6ed1952015-12-21 09:34:16 -0800740 // This doesn't necessarily mean that there is an error in the system. The sizes might be
741 // incorrect, because it is before the first layout or draw.
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800742 if (mTmpSize.width() < 1) {
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800743 mTmpSize.right = mTmpSize.left + 1;
744 }
745 if (mTmpSize.height() < 1) {
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800746 mTmpSize.bottom = mTmpSize.top + 1;
747 }
748
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800749 // Adjust for surface insets.
Phil Weavera4b32b92016-06-02 13:55:39 -0700750 mTmpSize.left -= attrs.surfaceInsets.left;
751 mTmpSize.top -= attrs.surfaceInsets.top;
752 mTmpSize.right += attrs.surfaceInsets.right;
753 mTmpSize.bottom += attrs.surfaceInsets.bottom;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800754 }
755
Chong Zhangeb22e8e2016-01-20 19:52:22 -0800756 boolean hasSurface() {
Chong Zhang92147042016-05-09 12:47:11 -0700757 return !mWin.hasSavedSurface()
Chong Zhangeb22e8e2016-01-20 19:52:22 -0800758 && mSurfaceController != null && mSurfaceController.hasSurface();
759 }
760
Craig Mautner96868332012-12-04 14:29:11 -0800761 void destroySurfaceLocked() {
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700762 final AppWindowToken wtoken = mWin.mAppToken;
763 if (wtoken != null) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700764 if (mWin == wtoken.startingWindow) {
765 wtoken.startingDisplayed = false;
766 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700767 }
768
Chong Zhang92147042016-05-09 12:47:11 -0700769 mWin.clearHasSavedSurface();
Robert Carr13f7be9e2015-12-02 18:39:45 -0800770
Wale Ogunwale722ff892016-02-18 13:37:55 -0800771 if (mSurfaceController == null) {
772 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700773 }
Wale Ogunwale722ff892016-02-18 13:37:55 -0800774
Wale Ogunwale722ff892016-02-18 13:37:55 -0800775 // When destroying a surface we want to make sure child windows are hidden. If we are
776 // preserving the surface until redraw though we intend to swap it out with another surface
777 // for resizing. In this case the window always remains visible to the user and the child
778 // windows should likewise remain visible.
Wale Ogunwale9d147902016-07-16 11:58:55 -0700779 if (!mDestroyPreservedSurfaceUponRedraw) {
780 mWin.mHidden = true;
Wale Ogunwale722ff892016-02-18 13:37:55 -0800781 }
782
783 try {
784 if (DEBUG_VISIBILITY) logWithStack(TAG, "Window " + this + " destroying surface "
785 + mSurfaceController + ", session " + mSession);
786 if (mSurfaceDestroyDeferred) {
787 if (mSurfaceController != null && mPendingDestroySurface != mSurfaceController) {
788 if (mPendingDestroySurface != null) {
789 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
790 WindowManagerService.logSurface(mWin, "DESTROY PENDING", true);
791 }
792 mPendingDestroySurface.destroyInTransaction();
793 }
794 mPendingDestroySurface = mSurfaceController;
795 }
796 } else {
797 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
798 WindowManagerService.logSurface(mWin, "DESTROY", true);
799 }
800 destroySurface();
801 }
802 // Don't hide wallpaper if we're deferring the surface destroy
803 // because of a surface change.
804 if (!mDestroyPreservedSurfaceUponRedraw) {
805 mWallpaperControllerLocked.hideWallpapers(mWin);
806 }
807 } catch (RuntimeException e) {
808 Slog.w(TAG, "Exception thrown when destroying Window " + this
809 + " surface " + mSurfaceController + " session " + mSession + ": " + e.toString());
810 }
811
812 // Whether the surface was preserved (and copied to mPendingDestroySurface) or not, it
813 // needs to be cleared to match the WindowState.mHasSurface state. It is also necessary
814 // so it can be recreated successfully in mPendingDestroySurface case.
815 mWin.setHasSurface(false);
816 if (mSurfaceController != null) {
817 mSurfaceController.setShown(false);
818 }
819 mSurfaceController = null;
820 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700821 }
822
Craig Mautner96868332012-12-04 14:29:11 -0800823 void destroyDeferredSurfaceLocked() {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700824 try {
825 if (mPendingDestroySurface != null) {
826 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -0800827 WindowManagerService.logSurface(mWin, "DESTROY PENDING", true);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700828 }
Robert Carre6a83512015-11-03 16:09:21 -0800829 mPendingDestroySurface.destroyInTransaction();
Chong Zhang6e21cf42015-11-09 14:41:42 -0800830 // Don't hide wallpaper if we're destroying a deferred surface
831 // after a surface mode change.
832 if (!mDestroyPreservedSurfaceUponRedraw) {
833 mWallpaperControllerLocked.hideWallpapers(mWin);
834 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700835 }
836 } catch (RuntimeException e) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700837 Slog.w(TAG, "Exception thrown when destroying Window "
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700838 + this + " surface " + mPendingDestroySurface
839 + " session " + mSession + ": " + e.toString());
840 }
841 mSurfaceDestroyDeferred = false;
842 mPendingDestroySurface = null;
843 }
844
Robert Carr298f9272016-08-09 13:08:01 -0700845 void applyMagnificationSpec(MagnificationSpec spec, Matrix transform) {
846 final int surfaceInsetLeft = mWin.mAttrs.surfaceInsets.left;
847 final int surfaceInsetTop = mWin.mAttrs.surfaceInsets.top;
848
849 if (spec != null && !spec.isNop()) {
850 float scale = spec.scale;
851 transform.postScale(scale, scale);
852 transform.postTranslate(spec.offsetX, spec.offsetY);
853
854 // As we are scaling the whole surface, to keep the content
855 // in the same position we will also have to scale the surfaceInsets.
856 transform.postTranslate(-(surfaceInsetLeft*scale - surfaceInsetLeft),
857 -(surfaceInsetTop*scale - surfaceInsetTop));
858 }
859 }
860
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700861 void computeShownFrameLocked() {
862 final boolean selfTransformation = mHasLocalTransformation;
863 Transformation attachedTransformation =
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700864 (mParentWinAnimator != null && mParentWinAnimator.mHasLocalTransformation)
865 ? mParentWinAnimator.mTransformation : null;
Craig Mautner322e4032012-07-13 13:35:20 -0700866 Transformation appTransformation = (mAppAnimator != null && mAppAnimator.hasTransformation)
867 ? mAppAnimator.transformation : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700868
869 // Wallpapers are animated based on the "real" window they
870 // are currently targeting.
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700871 final WindowState wallpaperTarget = mWallpaperControllerLocked.getWallpaperTarget();
Craig Mautner798adef2013-10-22 14:29:01 -0700872 if (mIsWallpaper && wallpaperTarget != null && mService.mAnimateWallpaperWithTarget) {
873 final WindowStateAnimator wallpaperAnimator = wallpaperTarget.mWinAnimator;
Craig Mautner918b53b2012-07-09 14:15:54 -0700874 if (wallpaperAnimator.mHasLocalTransformation &&
875 wallpaperAnimator.mAnimation != null &&
876 !wallpaperAnimator.mAnimation.getDetachWallpaper()) {
877 attachedTransformation = wallpaperAnimator.mTransformation;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800878 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700879 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
880 }
881 }
Craig Mautner798adef2013-10-22 14:29:01 -0700882 final AppWindowAnimator wpAppAnimator = wallpaperTarget.mAppToken == null ?
883 null : wallpaperTarget.mAppToken.mAppAnimator;
884 if (wpAppAnimator != null && wpAppAnimator.hasTransformation
Craig Mautner918b53b2012-07-09 14:15:54 -0700885 && wpAppAnimator.animation != null
886 && !wpAppAnimator.animation.getDetachWallpaper()) {
Craig Mautner59431632012-04-04 11:56:44 -0700887 appTransformation = wpAppAnimator.transformation;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800888 if (DEBUG_WALLPAPER && appTransformation != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700889 Slog.v(TAG, "WP target app xform: " + appTransformation);
890 }
891 }
892 }
893
Craig Mautnera91f9e22012-09-14 16:22:08 -0700894 final int displayId = mWin.getDisplayId();
895 final ScreenRotationAnimation screenRotationAnimation =
896 mAnimator.getScreenRotationAnimationLocked(displayId);
897 final boolean screenAnimation =
898 screenRotationAnimation != null && screenRotationAnimation.isAnimating();
Robert Carr2f0fe622015-09-25 14:56:38 -0700899
900 mHasClipRect = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700901 if (selfTransformation || attachedTransformation != null
902 || appTransformation != null || screenAnimation) {
903 // cache often used attributes locally
904 final Rect frame = mWin.mFrame;
905 final float tmpFloats[] = mService.mTmpFloats;
906 final Matrix tmpMatrix = mWin.mTmpMatrix;
907
908 // Compute the desired transformation.
Dianne Hackborn4b169692012-11-29 17:51:24 -0800909 if (screenAnimation && screenRotationAnimation.isRotating()) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700910 // If we are doing a screen animation, the global rotation
911 // applied to windows can result in windows that are carefully
912 // aligned with each other to slightly separate, allowing you
913 // to see what is behind them. An unsightly mess. This...
914 // thing... magically makes it call good: scale each window
915 // slightly (two pixels larger in each dimension, from the
916 // window's center).
917 final float w = frame.width();
918 final float h = frame.height();
919 if (w>=1 && h>=1) {
920 tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2);
921 } else {
922 tmpMatrix.reset();
923 }
924 } else {
925 tmpMatrix.reset();
926 }
927 tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale);
928 if (selfTransformation) {
929 tmpMatrix.postConcat(mTransformation.getMatrix());
930 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700931 if (attachedTransformation != null) {
932 tmpMatrix.postConcat(attachedTransformation.getMatrix());
933 }
934 if (appTransformation != null) {
935 tmpMatrix.postConcat(appTransformation.getMatrix());
936 }
Jorim Jaggie1d43612016-04-01 18:20:33 -0700937
938 // The translation that applies the position of the window needs to be applied at the
939 // end in case that other translations include scaling. Otherwise the scaling will
940 // affect this translation. But it needs to be set before the screen rotation animation
941 // so the pivot point is at the center of the screen for all windows.
942 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700943 if (screenAnimation) {
Craig Mautnera91f9e22012-09-14 16:22:08 -0700944 tmpMatrix.postConcat(screenRotationAnimation.getEnterTransformation().getMatrix());
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700945 }
Winson Chung399f6202014-03-19 10:47:20 -0700946
Svetoslav Ganov545252f2012-12-10 18:29:24 -0800947 //TODO (multidisplay): Magnification is supported only for the default display.
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800948 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
Svetoslav8e3feb12014-02-24 13:46:47 -0800949 MagnificationSpec spec = mService.mAccessibilityController
Svetoslav Ganov545252f2012-12-10 18:29:24 -0800950 .getMagnificationSpecForWindowLocked(mWin);
Robert Carr298f9272016-08-09 13:08:01 -0700951 applyMagnificationSpec(spec, tmpMatrix);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700952 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700953
954 // "convert" it into SurfaceFlinger's format
955 // (a 2x2 matrix + an offset)
956 // Here we must not transform the position of the surface
957 // since it is already included in the transformation.
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800958 //Slog.i(TAG_WM, "Transform: " + matrix);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700959
960 mHaveMatrix = true;
961 tmpMatrix.getValues(tmpFloats);
962 mDsDx = tmpFloats[Matrix.MSCALE_X];
963 mDtDx = tmpFloats[Matrix.MSKEW_Y];
964 mDsDy = tmpFloats[Matrix.MSKEW_X];
965 mDtDy = tmpFloats[Matrix.MSCALE_Y];
966 float x = tmpFloats[Matrix.MTRANS_X];
967 float y = tmpFloats[Matrix.MTRANS_Y];
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700968 mWin.mShownPosition.set((int) x, (int) y);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700969
970 // Now set the alpha... but because our current hardware
971 // can't do alpha transformation on a non-opaque surface,
972 // turn it off if we are running an animation that is also
973 // transforming since it is more important to have that
974 // animation be smooth.
975 mShownAlpha = mAlpha;
976 if (!mService.mLimitedAlphaCompositing
977 || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format)
978 || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
979 && x == frame.left && y == frame.top))) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800980 //Slog.i(TAG_WM, "Applying alpha transform");
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700981 if (selfTransformation) {
982 mShownAlpha *= mTransformation.getAlpha();
983 }
984 if (attachedTransformation != null) {
985 mShownAlpha *= attachedTransformation.getAlpha();
986 }
987 if (appTransformation != null) {
988 mShownAlpha *= appTransformation.getAlpha();
Winson Chung399f6202014-03-19 10:47:20 -0700989 if (appTransformation.hasClipRect()) {
990 mClipRect.set(appTransformation.getClipRect());
991 mHasClipRect = true;
Robert Carrf3b72c72016-03-21 18:16:39 -0700992 // The app transformation clip will be in the coordinate space of the main
993 // activity window, which the animation correctly assumes will be placed at
994 // (0,0)+(insets) relative to the containing frame. This isn't necessarily
995 // true for child windows though which can have an arbitrary frame position
996 // relative to their containing frame. We need to offset the difference
997 // between the containing frame as used to calculate the crop and our
998 // bounds to compensate for this.
Wale Ogunwale246c2092016-04-07 14:12:44 -0700999 if (mWin.layoutInParentFrame()) {
Robert Carrf3b72c72016-03-21 18:16:39 -07001000 mClipRect.offset( (mWin.mContainingFrame.left - mWin.mFrame.left),
1001 mWin.mContainingFrame.top - mWin.mFrame.top );
1002 }
Winson Chung399f6202014-03-19 10:47:20 -07001003 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001004 }
1005 if (screenAnimation) {
Craig Mautnera91f9e22012-09-14 16:22:08 -07001006 mShownAlpha *= screenRotationAnimation.getEnterTransformation().getAlpha();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001007 }
1008 } else {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001009 //Slog.i(TAG_WM, "Not applying alpha transform");
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001010 }
1011
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001012 if ((DEBUG_SURFACE_TRACE || WindowManagerService.localLOGV)
Craig Mautnera91f9e22012-09-14 16:22:08 -07001013 && (mShownAlpha == 1.0 || mShownAlpha == 0.0)) Slog.v(
1014 TAG, "computeShownFrameLocked: Animating " + this + " mAlpha=" + mAlpha
1015 + " self=" + (selfTransformation ? mTransformation.getAlpha() : "null")
1016 + " attached=" + (attachedTransformation == null ?
1017 "null" : attachedTransformation.getAlpha())
1018 + " app=" + (appTransformation == null ? "null" : appTransformation.getAlpha())
1019 + " screen=" + (screenAnimation ?
1020 screenRotationAnimation.getEnterTransformation().getAlpha() : "null"));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001021 return;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001022 } else if (mIsWallpaper && mService.mWindowPlacerLocked.mWallpaperActionPending) {
Craig Mautner4d7349b2012-04-20 14:52:47 -07001023 return;
Chong Zhang3005e752015-09-18 18:46:28 -07001024 } else if (mWin.isDragResizeChanged()) {
1025 // This window is awaiting a relayout because user just started (or ended)
1026 // drag-resizing. The shown frame (which affects surface size and pos)
1027 // should not be updated until we get next finished draw with the new surface.
1028 // Otherwise one or two frames rendered with old settings would be displayed
1029 // with new geometry.
1030 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001031 }
1032
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001033 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautner4d7349b2012-04-20 14:52:47 -07001034 TAG, "computeShownFrameLocked: " + this +
1035 " not attached, mAlpha=" + mAlpha);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001036
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001037 MagnificationSpec spec = null;
1038 //TODO (multidisplay): Magnification is supported only for the default display.
Filip Gruszczynski69cbc352015-11-11 13:46:04 -08001039 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
Svetoslav8e3feb12014-02-24 13:46:47 -08001040 spec = mService.mAccessibilityController.getMagnificationSpecForWindowLocked(mWin);
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001041 }
Craig Mautner165be0c2015-01-27 15:16:58 -08001042 if (spec != null) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001043 final Rect frame = mWin.mFrame;
1044 final float tmpFloats[] = mService.mTmpFloats;
1045 final Matrix tmpMatrix = mWin.mTmpMatrix;
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001046
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001047 tmpMatrix.setScale(mWin.mGlobalScale, mWin.mGlobalScale);
1048 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001049
Robert Carr298f9272016-08-09 13:08:01 -07001050 applyMagnificationSpec(spec, tmpMatrix);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001051
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001052 tmpMatrix.getValues(tmpFloats);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001053
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001054 mHaveMatrix = true;
1055 mDsDx = tmpFloats[Matrix.MSCALE_X];
1056 mDtDx = tmpFloats[Matrix.MSKEW_Y];
1057 mDsDy = tmpFloats[Matrix.MSKEW_X];
1058 mDtDy = tmpFloats[Matrix.MSCALE_Y];
1059 float x = tmpFloats[Matrix.MTRANS_X];
1060 float y = tmpFloats[Matrix.MTRANS_Y];
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001061 mWin.mShownPosition.set((int) x, (int) y);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001062
1063 mShownAlpha = mAlpha;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001064 } else {
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001065 mWin.mShownPosition.set(mWin.mFrame.left, mWin.mFrame.top);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001066 if (mWin.mXOffset != 0 || mWin.mYOffset != 0) {
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001067 mWin.mShownPosition.offset(mWin.mXOffset, mWin.mYOffset);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001068 }
1069 mShownAlpha = mAlpha;
1070 mHaveMatrix = false;
1071 mDsDx = mWin.mGlobalScale;
1072 mDtDx = 0;
1073 mDsDy = 0;
1074 mDtDy = mWin.mGlobalScale;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001075 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001076 }
1077
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001078 private void calculateSystemDecorRect() {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001079 final WindowState w = mWin;
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001080 final Rect decorRect = w.mDecorFrame;
Alan Viverette49a22e82014-07-12 20:01:27 -07001081 final int width = w.mFrame.width();
1082 final int height = w.mFrame.height();
Alan Viveretteccb11e12014-07-08 16:04:02 -07001083
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001084 // Compute the offset of the window in relation to the decor rect.
Alan Viverette49a22e82014-07-12 20:01:27 -07001085 final int left = w.mXOffset + w.mFrame.left;
1086 final int top = w.mYOffset + w.mFrame.top;
Alan Viveretteccb11e12014-07-08 16:04:02 -07001087
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001088 // Initialize the decor rect to the entire frame.
Robert Carr2487ce72016-04-07 15:18:45 -07001089 if (w.isDockedResizing() ||
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001090 (w.isChildWindow() && w.getParentWindow().isDockedResizing())) {
Jorim Jaggidc249c42015-12-15 14:57:31 -08001091
1092 // If we are resizing with the divider, the task bounds might be smaller than the
1093 // stack bounds. The system decor is used to clip to the task bounds, which we don't
1094 // want in this case in order to avoid holes.
Robert Carr2487ce72016-04-07 15:18:45 -07001095 //
1096 // We take care to not shrink the width, for surfaces which are larger than
1097 // the display region. Of course this area will not eventually be visible
1098 // but if we truncate the width now, we will calculate incorrectly
1099 // when adjusting to the stack bounds.
Jorim Jaggidc249c42015-12-15 14:57:31 -08001100 final DisplayInfo displayInfo = w.getDisplayContent().getDisplayInfo();
Robert Carr2487ce72016-04-07 15:18:45 -07001101 mSystemDecorRect.set(0, 0,
1102 Math.max(width, displayInfo.logicalWidth),
1103 Math.max(height, displayInfo.logicalHeight));
Jorim Jaggidc249c42015-12-15 14:57:31 -08001104 } else {
1105 mSystemDecorRect.set(0, 0, width, height);
1106 }
Alan Viveretteccb11e12014-07-08 16:04:02 -07001107
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001108 // If a freeform window is animating from a position where it would be cutoff, it would be
1109 // cutoff during the animation. We don't want that, so for the duration of the animation
1110 // we ignore the decor cropping and depend on layering to position windows correctly.
1111 final boolean cropToDecor = !(w.inFreeformWorkspace() && w.isAnimatingLw());
1112 if (cropToDecor) {
1113 // Intersect with the decor rect, offsetted by window position.
1114 mSystemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
1115 decorRect.right - left, decorRect.bottom - top);
1116 }
Alan Viveretteccb11e12014-07-08 16:04:02 -07001117
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001118 // If size compatibility is being applied to the window, the
1119 // surface is scaled relative to the screen. Also apply this
1120 // scaling to the crop rect. We aren't using the standard rect
1121 // scale function because we want to round things to make the crop
1122 // always round to a larger rect to ensure we don't crop too
1123 // much and hide part of the window that should be seen.
1124 if (w.mEnforceSizeCompat && w.mInvGlobalScale != 1.0f) {
1125 final float scale = w.mInvGlobalScale;
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001126 mSystemDecorRect.left = (int) (mSystemDecorRect.left * scale - 0.5f);
1127 mSystemDecorRect.top = (int) (mSystemDecorRect.top * scale - 0.5f);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001128 mSystemDecorRect.right = (int) ((mSystemDecorRect.right + 1) * scale - 0.5f);
1129 mSystemDecorRect.bottom = (int) ((mSystemDecorRect.bottom + 1) * scale - 0.5f);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001130 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001131 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001132
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001133 void calculateSurfaceWindowCrop(Rect clipRect, Rect finalClipRect) {
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001134 final WindowState w = mWin;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001135 final DisplayContent displayContent = w.getDisplayContent();
1136 if (displayContent == null) {
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001137 clipRect.setEmpty();
1138 finalClipRect.setEmpty();
1139 return;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001140 }
Wale Ogunwaleb3eba812015-07-30 20:20:16 -07001141 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001142 if (DEBUG_WINDOW_CROP) Slog.d(TAG,
1143 "Updating crop win=" + w + " mLastCrop=" + mLastClipRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001144
1145 // Need to recompute a new system decor rect each time.
Robert Carr58f29132015-10-29 14:19:05 -07001146 if (!w.isDefaultDisplay()) {
Jeff Brown28e0b092012-09-25 11:31:28 -07001147 // On a different display there is no system decor. Crop the window
1148 // by the screen boundaries.
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001149 mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height());
1150 mSystemDecorRect.intersect(-w.mCompatFrame.left, -w.mCompatFrame.top,
Jeff Brown28e0b092012-09-25 11:31:28 -07001151 displayInfo.logicalWidth - w.mCompatFrame.left,
1152 displayInfo.logicalHeight - w.mCompatFrame.top);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001153 } else if (w.mLayer >= mService.mSystemDecorLayer) {
1154 // Above the decor layer is easy, just use the entire window.
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001155 mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height());
Craig Mautner165be0c2015-01-27 15:16:58 -08001156 } else if (w.mDecorFrame.isEmpty()) {
1157 // Windows without policy decor aren't cropped.
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001158 mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height());
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001159 } else if (w.mAttrs.type == LayoutParams.TYPE_WALLPAPER && mAnimator.isAnimating()) {
Adrian Roosd47ad032014-08-15 23:17:05 +02001160 // If we're animating, the wallpaper crop should only be updated at the end of the
1161 // animation.
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001162 mTmpClipRect.set(mSystemDecorRect);
1163 calculateSystemDecorRect();
1164 mSystemDecorRect.union(mTmpClipRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001165 } else {
John Spurlock46646232013-09-30 22:32:42 -04001166 // Crop to the system decor specified by policy.
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001167 calculateSystemDecorRect();
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001168 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "Applying decor to crop win=" + w + " mDecorFrame="
1169 + w.mDecorFrame + " mSystemDecorRect=" + mSystemDecorRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001170 }
1171
Chong Zhang0abb20f2015-11-19 14:17:31 -08001172 final boolean fullscreen = w.isFrameFullscreen(displayInfo);
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001173 final boolean isFreeformResizing =
Jorim Jaggidcf467c2015-11-05 13:59:32 +01001174 w.isDragResizing() && w.getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
Robert Carr51a1b872015-12-08 14:03:13 -08001175
1176 // We use the clip rect as provided by the tranformation for non-fullscreen windows to
1177 // avoid premature clipping with the system decor rect.
1178 clipRect.set((mHasClipRect && !fullscreen) ? mClipRect : mSystemDecorRect);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001179 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "win=" + w + " Initial clip rect: " + clipRect
1180 + " mHasClipRect=" + mHasClipRect + " fullscreen=" + fullscreen);
Robert Carr51a1b872015-12-08 14:03:13 -08001181
1182 if (isFreeformResizing && !w.isChildWindow()) {
1183 // For freeform resizing non child windows, we are using the big surface positioned
1184 // at 0,0. Thus we must express the crop in that coordinate space.
1185 clipRect.offset(w.mShownPosition.x, w.mShownPosition.y);
Chong Zhang09b21ef2015-09-14 10:20:21 -07001186 }
Robert Carr51a1b872015-12-08 14:03:13 -08001187
Alan Viverette49a22e82014-07-12 20:01:27 -07001188 // Expand the clip rect for surface insets.
1189 final WindowManager.LayoutParams attrs = w.mAttrs;
1190 clipRect.left -= attrs.surfaceInsets.left;
1191 clipRect.top -= attrs.surfaceInsets.top;
1192 clipRect.right += attrs.surfaceInsets.right;
1193 clipRect.bottom += attrs.surfaceInsets.bottom;
1194
Wale Ogunwaleb3eba812015-07-30 20:20:16 -07001195 if (mHasClipRect && fullscreen) {
1196 // We intersect the clip rect specified by the transformation with the expanded system
1197 // decor rect to prevent artifacts from drawing during animation if the transformation
1198 // clip rect extends outside the system decor rect.
1199 clipRect.intersect(mClipRect);
1200 }
Alan Viverette49a22e82014-07-12 20:01:27 -07001201 // The clip rect was generated assuming (0,0) as the window origin,
1202 // so we need to translate to match the actual surface coordinates.
1203 clipRect.offset(attrs.surfaceInsets.left, attrs.surfaceInsets.top);
Robert Carr58f29132015-10-29 14:19:05 -07001204
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001205 finalClipRect.setEmpty();
1206 adjustCropToStackBounds(w, clipRect, finalClipRect, isFreeformResizing);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001207 if (DEBUG_WINDOW_CROP) Slog.d(TAG,
1208 "win=" + w + " Clip rect after stack adjustment=" + clipRect);
Robert Carr58f29132015-10-29 14:19:05 -07001209
Chia-I Wue6bcaf12016-05-27 10:58:48 +08001210 w.transformClipRectFromScreenToSurfaceSpace(clipRect);
Robert Carr58f29132015-10-29 14:19:05 -07001211
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08001212 // See {@link WindowState#notifyMovedInStack} for why this is necessary.
1213 if (w.hasJustMovedInStack() && mLastClipRect.isEmpty() && !clipRect.isEmpty()) {
1214 clipRect.setEmpty();
1215 }
Robert Carr0d00c2e2016-02-29 17:45:02 -08001216 }
1217
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001218 void updateSurfaceWindowCrop(Rect clipRect, Rect finalClipRect, boolean recoveringMemory) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001219 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "updateSurfaceWindowCrop: win=" + mWin
1220 + " clipRect=" + clipRect + " finalClipRect=" + finalClipRect);
Robert Carr4320d332016-06-10 15:13:32 -07001221 if (clipRect != null) {
1222 if (!clipRect.equals(mLastClipRect)) {
1223 mLastClipRect.set(clipRect);
1224 mSurfaceController.setCropInTransaction(clipRect, recoveringMemory);
1225 }
1226 } else {
1227 mSurfaceController.clearCropInTransaction(recoveringMemory);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001228 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001229 if (!finalClipRect.equals(mLastFinalClipRect)) {
1230 mLastFinalClipRect.set(finalClipRect);
1231 mSurfaceController.setFinalCropInTransaction(finalClipRect);
Chong Zhangcc3eccf2016-05-16 18:25:45 -07001232 if (mDestroyPreservedSurfaceUponRedraw && mPendingDestroySurface != null) {
1233 mPendingDestroySurface.setFinalCropInTransaction(finalClipRect);
1234 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001235 }
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001236 }
1237
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001238 private int resolveStackClip() {
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001239 // App animation overrides window animation stack clip mode.
1240 if (mAppAnimator != null && mAppAnimator.animation != null) {
1241 return mAppAnimator.getStackClip();
1242 } else {
1243 return mStackClip;
1244 }
1245 }
1246 private void adjustCropToStackBounds(WindowState w, Rect clipRect, Rect finalClipRect,
1247 boolean isFreeformResizing) {
Wale Ogunwale4c5aa5172016-04-19 11:29:05 -07001248
1249 final DisplayContent displayContent = w.getDisplayContent();
1250 if (displayContent != null && !displayContent.isDefaultDisplay) {
1251 // There are some windows that live on other displays while their app and main window
1252 // live on the default display (e.g. casting...). We don't want to crop this windows
1253 // to the stack bounds which is only currently supported on the default display.
1254 // TODO(multi-display): Need to support cropping to stack bounds on other displays
1255 // when we have stacks on other displays.
1256 return;
1257 }
1258
Chong Zhang112eb8c2015-11-02 11:17:00 -08001259 final Task task = w.getTask();
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001260 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001261 return;
Filip Gruszczynski4b8eea72015-09-14 18:16:19 -07001262 }
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001263
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001264 final int stackClip = resolveStackClip();
1265
1266 // It's animating and we don't want to clip it to stack bounds during animation - abort.
Jorim Jaggi5c80c412016-04-19 20:03:47 -07001267 if (isAnimationSet() && stackClip == STACK_CLIP_NONE) {
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001268 return;
1269 }
1270
Chong Zhangbcb8d822016-02-26 16:21:02 -08001271 final WindowState winShowWhenLocked = (WindowState) mPolicy.getWinShowWhenLockedLw();
Jorim Jaggid7f6e7c2016-04-11 19:04:24 -07001272 if (w == winShowWhenLocked && mPolicy.isKeyguardShowingOrOccluded()) {
Chong Zhangbcb8d822016-02-26 16:21:02 -08001273 return;
1274 }
1275
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001276 final TaskStack stack = task.mStack;
1277 stack.getDimBounds(mTmpStackBounds);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001278 final Rect surfaceInsets = w.getAttrs().surfaceInsets;
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001279 // When we resize we use the big surface approach, which means we can't trust the
1280 // window frame bounds anymore. Instead, the window will be placed at 0, 0, but to avoid
1281 // hardcoding it, we use surface coordinates.
1282 final int frameX = isFreeformResizing ? (int) mSurfaceController.getX() :
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001283 w.mFrame.left + mWin.mXOffset - surfaceInsets.left;
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001284 final int frameY = isFreeformResizing ? (int) mSurfaceController.getY() :
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001285 w.mFrame.top + mWin.mYOffset - surfaceInsets.top;
Robert Carr0d00c2e2016-02-29 17:45:02 -08001286
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001287 // If we are animating, we either apply the clip before applying all the animation
1288 // transformation or after all the transformation.
Chong Zhangcc3eccf2016-05-16 18:25:45 -07001289 final boolean useFinalClipRect = isAnimationSet() && stackClip == STACK_CLIP_AFTER_ANIM
1290 || mDestroyPreservedSurfaceUponRedraw;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001291
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001292 // We need to do some acrobatics with surface position, because their clip region is
1293 // relative to the inside of the surface, but the stack bounds aren't.
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001294 if (useFinalClipRect) {
1295 finalClipRect.set(mTmpStackBounds);
1296 } else {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001297 if (StackId.hasWindowShadow(stack.mStackId)
1298 && !StackId.isTaskResizeAllowed(stack.mStackId)) {
1299 // The windows in this stack display drop shadows and the fill the entire stack
1300 // area. Adjust the stack bounds we will use to cropping take into account the
1301 // offsets we use to display the drop shadow so it doesn't get cropped.
1302 mTmpStackBounds.inset(-surfaceInsets.left, -surfaceInsets.top,
1303 -surfaceInsets.right, -surfaceInsets.bottom);
1304 }
1305
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001306 clipRect.left = Math.max(0,
1307 Math.max(mTmpStackBounds.left, frameX + clipRect.left) - frameX);
1308 clipRect.top = Math.max(0,
1309 Math.max(mTmpStackBounds.top, frameY + clipRect.top) - frameY);
1310 clipRect.right = Math.max(0,
1311 Math.min(mTmpStackBounds.right, frameX + clipRect.right) - frameX);
1312 clipRect.bottom = Math.max(0,
1313 Math.min(mTmpStackBounds.bottom, frameY + clipRect.bottom) - frameY);
1314 }
Filip Gruszczynski4b8eea72015-09-14 18:16:19 -07001315 }
1316
Wale Ogunwale4c8b7952015-04-07 10:49:40 -07001317 void setSurfaceBoundariesLocked(final boolean recoveringMemory) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001318 final WindowState w = mWin;
Robert Carr0d00c2e2016-02-29 17:45:02 -08001319 final Task task = w.getTask();
Alan Viveretteccb11e12014-07-08 16:04:02 -07001320
Jorim Jaggif3df0aa2016-04-06 15:56:33 -07001321 // We got resized, so block all updates until we got the new surface.
Andrii Kulianeb1d3222016-05-16 15:17:55 -07001322 if (w.isResizedWhileNotDragResizing() && !w.isGoneForLayoutLw()) {
Jorim Jaggif3df0aa2016-04-06 15:56:33 -07001323 return;
1324 }
1325
Filip Gruszczynski69cbc352015-11-11 13:46:04 -08001326 mTmpSize.set(w.mShownPosition.x, w.mShownPosition.y, 0, 0);
1327 calculateSurfaceBounds(w, w.getAttrs());
Chong Zhang0275e392015-09-17 10:41:44 -07001328
Robert Carr04092112016-06-02 12:56:12 -07001329 mExtraHScale = (float) 1.0;
1330 mExtraVScale = (float) 1.0;
Robert Carre1034cc32016-02-01 13:08:15 -08001331
Robert Carr6da3cc02016-06-16 15:17:07 -07001332 boolean wasForceScaled = mForceScaleUntilResize;
1333 boolean wasSeamlesslyRotated = w.mSeamlesslyRotated;
1334
Robert Carrfed10072016-05-26 11:48:49 -07001335 // Once relayout has been called at least once, we need to make sure
1336 // we only resize the client surface during calls to relayout. For
1337 // clients which use indeterminate measure specs (MATCH_PARENT),
1338 // we may try and change their window size without a call to relayout.
1339 // However, this would be unsafe, as the client may be in the middle
1340 // of producing a frame at the old size, having just completed layout
1341 // to find the surface size changed underneath it.
Robert Carr3ccc5272016-06-20 22:06:32 -07001342 if (!w.mRelayoutCalled || w.mInRelayout) {
Robert Carrfed10072016-05-26 11:48:49 -07001343 mSurfaceResized = mSurfaceController.setSizeInTransaction(
1344 mTmpSize.width(), mTmpSize.height(), recoveringMemory);
1345 } else {
1346 mSurfaceResized = false;
1347 }
Robert Carrc7294602016-05-13 11:32:05 -07001348 mForceScaleUntilResize = mForceScaleUntilResize && !mSurfaceResized;
Robert Carr6da3cc02016-06-16 15:17:07 -07001349 // If we are undergoing seamless rotation, the surface has already
1350 // been set up to persist at it's old location. We need to freeze
1351 // updates until a resize occurs.
1352 w.mSeamlesslyRotated = w.mSeamlesslyRotated && !mSurfaceResized;
Robert Carrc7294602016-05-13 11:32:05 -07001353
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001354 calculateSurfaceWindowCrop(mTmpClipRect, mTmpFinalClipRect);
Robert Carra9408d42016-06-03 13:28:48 -07001355
1356 float surfaceWidth = mSurfaceController.getWidth();
1357 float surfaceHeight = mSurfaceController.getHeight();
1358
Robert Carrc7294602016-05-13 11:32:05 -07001359 if ((task != null && task.mStack.getForceScaleToCrop()) || mForceScaleUntilResize) {
Robert Carrbc133762016-05-12 14:04:38 -07001360 int hInsets = w.getAttrs().surfaceInsets.left + w.getAttrs().surfaceInsets.right;
1361 int vInsets = w.getAttrs().surfaceInsets.top + w.getAttrs().surfaceInsets.bottom;
Robert Carra9408d42016-06-03 13:28:48 -07001362 if (!mForceScaleUntilResize) {
1363 mSurfaceController.forceScaleableInTransaction(true);
1364 }
Robert Carrbc133762016-05-12 14:04:38 -07001365 // We want to calculate the scaling based on the content area, not based on
1366 // the entire surface, so that we scale in sync with windows that don't have insets.
Robert Carr04092112016-06-02 12:56:12 -07001367 mExtraHScale = (mTmpClipRect.width() - hInsets) / (float)(surfaceWidth - hInsets);
1368 mExtraVScale = (mTmpClipRect.height() - vInsets) / (float)(surfaceHeight - vInsets);
Robert Carr0d00c2e2016-02-29 17:45:02 -08001369
1370 // In the case of ForceScaleToCrop we scale entire tasks together,
1371 // and so we need to scale our offsets relative to the task bounds
1372 // or parent and child windows would fall out of alignment.
Robert Carr04092112016-06-02 12:56:12 -07001373 int posX = (int) (mTmpSize.left - w.mAttrs.x * (1 - mExtraHScale));
1374 int posY = (int) (mTmpSize.top - w.mAttrs.y * (1 - mExtraVScale));
Robert Carrbc133762016-05-12 14:04:38 -07001375 // Imagine we are scaling down. As we scale the buffer down, we decrease the
1376 // distance between the surface top left, and the start of the surface contents
1377 // (previously it was surfaceInsets.left pixels in screen space but now it
Robert Carr04092112016-06-02 12:56:12 -07001378 // will be surfaceInsets.left*mExtraHScale). This means in order to keep the
Robert Carrbc133762016-05-12 14:04:38 -07001379 // non inset content at the same position, we have to shift the whole window
1380 // forward. Likewise for scaling up, we've increased this distance, and we need
1381 // to shift by a negative number to compensate.
Robert Carr04092112016-06-02 12:56:12 -07001382 posX += w.getAttrs().surfaceInsets.left * (1 - mExtraHScale);
1383 posY += w.getAttrs().surfaceInsets.top * (1 - mExtraVScale);
Robert Carrbc133762016-05-12 14:04:38 -07001384
Robert Carra9408d42016-06-03 13:28:48 -07001385 mSurfaceController.setPositionInTransaction((float)Math.floor(posX),
1386 (float)Math.floor(posY), recoveringMemory);
Robert Carr0d00c2e2016-02-29 17:45:02 -08001387
1388 // Since we are scaled to fit in our previously desired crop, we can now
1389 // expose the whole window in buffer space, and not risk extending
1390 // past where the system would have cropped us
Robert Carrfed10072016-05-26 11:48:49 -07001391 mTmpClipRect.set(0, 0, (int)surfaceWidth, (int)surfaceHeight);
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001392 mTmpFinalClipRect.setEmpty();
Robert Carrc7294602016-05-13 11:32:05 -07001393
1394 // Various surfaces in the scaled stack may resize at different times.
1395 // We need to ensure for each surface, that we disable transformation matrix
1396 // scaling in the same transaction which we resize the surface in.
1397 // As we are in SCALING_MODE_SCALE_TO_WINDOW, SurfaceFlinger will
Robert Carra9408d42016-06-03 13:28:48 -07001398 // then take over the scaling until the new buffer arrives, and things
Robert Carrc7294602016-05-13 11:32:05 -07001399 // will be seamless.
1400 mForceScaleUntilResize = true;
Robert Carr0d00c2e2016-02-29 17:45:02 -08001401 } else {
Robert Carr6da3cc02016-06-16 15:17:07 -07001402 if (!w.mSeamlesslyRotated) {
1403 mSurfaceController.setPositionInTransaction(mTmpSize.left, mTmpSize.top,
1404 recoveringMemory);
1405 }
Robert Carr0d00c2e2016-02-29 17:45:02 -08001406 }
1407
Robert Carra9408d42016-06-03 13:28:48 -07001408 // If we are ending the scaling mode. We switch to SCALING_MODE_FREEZE
Robert Carr6da3cc02016-06-16 15:17:07 -07001409 // to prevent further updates until buffer latch.
1410 // When ending both force scaling, and seamless rotation, we need to freeze
1411 // the Surface geometry until a buffer comes in at the new size (normally position and crop
1412 // are unfrozen). setGeometryAppliesWithResizeInTransaction accomplishes this for us.
1413 if ((wasForceScaled && !mForceScaleUntilResize) ||
1414 (wasSeamlesslyRotated && !w.mSeamlesslyRotated)) {
1415 mSurfaceController.setGeometryAppliesWithResizeInTransaction(true);
Robert Carra9408d42016-06-03 13:28:48 -07001416 mSurfaceController.forceScaleableInTransaction(false);
1417 }
Robert Carr4320d332016-06-10 15:13:32 -07001418
1419 Rect clipRect = mTmpClipRect;
Robert Carra9408d42016-06-03 13:28:48 -07001420 if (w.inPinnedWorkspace()) {
Robert Carr4320d332016-06-10 15:13:32 -07001421 clipRect = null;
Robert Carra9408d42016-06-03 13:28:48 -07001422 task.mStack.getDimBounds(mTmpFinalClipRect);
1423 mTmpFinalClipRect.inset(-w.mAttrs.surfaceInsets.left, -w.mAttrs.surfaceInsets.top,
1424 -w.mAttrs.surfaceInsets.right, -w.mAttrs.surfaceInsets.bottom);
1425 }
1426
Robert Carr6da3cc02016-06-16 15:17:07 -07001427 if (!w.mSeamlesslyRotated) {
1428 updateSurfaceWindowCrop(clipRect, mTmpFinalClipRect, recoveringMemory);
1429 mSurfaceController.setMatrixInTransaction(mDsDx * w.mHScale * mExtraHScale,
1430 mDtDx * w.mVScale * mExtraVScale,
1431 mDsDy * w.mHScale * mExtraHScale,
1432 mDtDy * w.mVScale * mExtraVScale, recoveringMemory);
1433 }
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001434
Robert Carre6a83512015-11-03 16:09:21 -08001435 if (mSurfaceResized) {
Chong Zhang5b2f1992015-11-13 15:40:36 -08001436 mReportSurfaceResized = true;
Robert Carre6a83512015-11-03 16:09:21 -08001437 mAnimator.setPendingLayoutChanges(w.getDisplayId(),
1438 WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
1439 w.applyDimLayerIfNeeded();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001440 }
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001441
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001442 }
1443
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001444 void prepareSurfaceLocked(final boolean recoveringMemory) {
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001445 final WindowState w = mWin;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001446 if (!hasSurface()) {
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001447 if (w.mOrientationChanging) {
1448 if (DEBUG_ORIENTATION) {
1449 Slog.v(TAG, "Orientation change skips hidden " + w);
1450 }
1451 w.mOrientationChanging = false;
1452 }
1453 return;
1454 }
1455
Chong Zhang70211742016-04-28 18:27:53 -07001456 // Do not change surface properties of opening apps if we are waiting for the
1457 // transition to be ready. transitionGoodToGo could be not ready even after all
1458 // opening apps are drawn. It's only waiting on isFetchingAppTransitionsSpecs()
1459 // to get the animation spec. (For example, go into Recents and immediately open
1460 // the same app again before the app's surface is destroyed or saved, the surface
1461 // is always ready in the whole process.) If we go ahead here, the opening app
1462 // will be shown with the full size before the correct animation spec arrives.
Chong Zhange22006d2016-05-09 10:59:59 -07001463 if (isWaitingForOpening()) {
Chong Zhang70211742016-04-28 18:27:53 -07001464 return;
1465 }
1466
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001467 boolean displayed = false;
1468
1469 computeShownFrameLocked();
1470
Craig Mautnera91f9e22012-09-14 16:22:08 -07001471 setSurfaceBoundariesLocked(recoveringMemory);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001472
Craig Mautner918b53b2012-07-09 14:15:54 -07001473 if (mIsWallpaper && !mWin.mWallpaperVisible) {
Craig Mautner0fa77c12012-06-11 15:57:19 -07001474 // Wallpaper is no longer visible and there is no wp target => hide it.
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001475 hide("prepareSurfaceLocked");
Wale Ogunwale9d147902016-07-16 11:58:55 -07001476 } else if (w.isParentWindowHidden() || !w.isOnScreen()) {
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001477 hide("prepareSurfaceLocked");
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001478 mWallpaperControllerLocked.hideWallpapers(w);
Craig Mautnerb9836b92012-06-11 11:40:09 -07001479
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001480 // If we are waiting for this window to handle an
1481 // orientation change, well, it is hidden, so
1482 // doesn't really matter. Note that this does
1483 // introduce a potential glitch if the window
1484 // becomes unhidden before it has drawn for the
1485 // new orientation.
1486 if (w.mOrientationChanging) {
1487 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001488 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001489 "Orientation change skips hidden " + w);
1490 }
1491 } else if (mLastLayer != mAnimLayer
1492 || mLastAlpha != mShownAlpha
1493 || mLastDsDx != mDsDx
1494 || mLastDtDx != mDtDx
1495 || mLastDsDy != mDsDy
1496 || mLastDtDy != mDtDy
1497 || w.mLastHScale != w.mHScale
1498 || w.mLastVScale != w.mVScale
Craig Mautner749a7bb2012-04-02 13:49:53 -07001499 || mLastHidden) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001500 displayed = true;
1501 mLastAlpha = mShownAlpha;
1502 mLastLayer = mAnimLayer;
1503 mLastDsDx = mDsDx;
1504 mLastDtDx = mDtDx;
1505 mLastDsDy = mDsDy;
1506 mLastDtDy = mDtDy;
1507 w.mLastHScale = w.mHScale;
1508 w.mLastVScale = w.mVScale;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001509 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
Robert Carre6a83512015-11-03 16:09:21 -08001510 "controller=" + mSurfaceController +
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001511 "alpha=" + mShownAlpha + " layer=" + mAnimLayer
Craig Mautner78505d82014-09-02 14:36:31 -07001512 + " matrix=[" + mDsDx + "*" + w.mHScale
1513 + "," + mDtDx + "*" + w.mVScale
1514 + "][" + mDsDy + "*" + w.mHScale
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -08001515 + "," + mDtDy + "*" + w.mVScale + "]", false);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001516
Robert Carre6a83512015-11-03 16:09:21 -08001517 boolean prepared =
1518 mSurfaceController.prepareToShowInTransaction(mShownAlpha, mAnimLayer,
Robert Carr04092112016-06-02 12:56:12 -07001519 mDsDx * w.mHScale * mExtraHScale,
1520 mDtDx * w.mVScale * mExtraVScale,
1521 mDsDy * w.mHScale * mExtraHScale,
1522 mDtDy * w.mVScale * mExtraVScale,
Robert Carre6a83512015-11-03 16:09:21 -08001523 recoveringMemory);
1524
1525 if (prepared && mLastHidden && mDrawState == HAS_DRAWN) {
1526 if (showSurfaceRobustlyLocked()) {
Chong Zhangeb665572016-05-09 18:28:27 -07001527 markPreservedSurfaceForDestroy();
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -08001528 mAnimator.requestRemovalOfReplacedWindows(w);
Robert Carre6a83512015-11-03 16:09:21 -08001529 mLastHidden = false;
1530 if (mIsWallpaper) {
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07001531 w.dispatchWallpaperVisibility(true);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001532 }
Robert Carre6a83512015-11-03 16:09:21 -08001533 // This draw means the difference between unique content and mirroring.
1534 // Run another pass through performLayout to set mHasContent in the
1535 // LogicalDisplay.
1536 mAnimator.setPendingLayoutChanges(w.getDisplayId(),
1537 WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
1538 } else {
1539 w.mOrientationChanging = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001540 }
1541 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001542 if (hasSurface()) {
Robert Carre6a83512015-11-03 16:09:21 -08001543 w.mToken.hasVisible = true;
1544 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001545 } else {
Jorim Jaggi5c80c412016-04-19 20:03:47 -07001546 if (DEBUG_ANIM && isAnimationSet()) {
Chong Zhange05db742016-02-16 16:58:37 -08001547 Slog.v(TAG, "prepareSurface: No changes in animation for " + this);
Craig Mautner83339b42012-05-01 22:13:23 -07001548 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001549 displayed = true;
1550 }
1551
1552 if (displayed) {
1553 if (w.mOrientationChanging) {
1554 if (!w.isDrawnLw()) {
Craig Mautner2639da52012-07-09 09:39:06 -07001555 mAnimator.mBulkUpdateParams &= ~SET_ORIENTATION_CHANGE_COMPLETE;
Dianne Hackborna57c6952013-03-29 14:46:40 -07001556 mAnimator.mLastWindowFreezeSource = w;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001557 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001558 "Orientation continue waiting for draw in " + w);
1559 } else {
1560 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001561 if (DEBUG_ORIENTATION) Slog.v(TAG, "Orientation change complete in " + w);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001562 }
1563 }
1564 w.mToken.hasVisible = true;
1565 }
1566 }
1567
Craig Mautneref655012013-01-03 11:20:24 -08001568 void setTransparentRegionHintLocked(final Region region) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001569 if (mSurfaceController == null) {
1570 Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true");
1571 return;
1572 }
Robert Carre6a83512015-11-03 16:09:21 -08001573 mSurfaceController.setTransparentRegionHint(region);
Craig Mautner48ba1e72012-04-02 13:18:16 -07001574 }
1575
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001576 void setWallpaperOffset(Point shownPosition) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07001577 final LayoutParams attrs = mWin.getAttrs();
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001578 final int left = shownPosition.x - attrs.surfaceInsets.left;
1579 final int top = shownPosition.y - attrs.surfaceInsets.top;
Robert Carre6a83512015-11-03 16:09:21 -08001580
1581 try {
Craig Mautner71dd1b62014-02-18 15:48:52 -08001582 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setWallpaperOffset");
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001583 SurfaceControl.openTransaction();
Robert Carre6a83512015-11-03 16:09:21 -08001584 mSurfaceController.setPositionInTransaction(mWin.mFrame.left + left,
1585 mWin.mFrame.top + top, false);
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001586 calculateSurfaceWindowCrop(mTmpClipRect, mTmpFinalClipRect);
1587 updateSurfaceWindowCrop(mTmpClipRect, mTmpFinalClipRect, false);
Robert Carre6a83512015-11-03 16:09:21 -08001588 } catch (RuntimeException e) {
1589 Slog.w(TAG, "Error positioning surface of " + mWin
1590 + " pos=(" + left + "," + top + ")", e);
1591 } finally {
1592 SurfaceControl.closeTransaction();
1593 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1594 "<<< CLOSE TRANSACTION setWallpaperOffset");
Craig Mautner48ba1e72012-04-02 13:18:16 -07001595 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001596 }
1597
John Reck80181b92015-05-19 11:09:32 -07001598 /**
1599 * Try to change the pixel format without recreating the surface. This
1600 * will be common in the case of changing from PixelFormat.OPAQUE to
1601 * PixelFormat.TRANSLUCENT in the hardware-accelerated case as both
1602 * requested formats resolve to the same underlying SurfaceControl format
1603 * @return True if format was succesfully changed, false otherwise
1604 */
1605 boolean tryChangeFormatInPlaceLocked() {
Robert Carre6a83512015-11-03 16:09:21 -08001606 if (mSurfaceController == null) {
John Reck80181b92015-05-19 11:09:32 -07001607 return false;
1608 }
1609 final LayoutParams attrs = mWin.getAttrs();
Wale Ogunwalee7bf46b2015-09-30 09:19:28 -07001610 final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0;
John Reck80181b92015-05-19 11:09:32 -07001611 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
1612 if (format == mSurfaceFormat) {
1613 setOpaqueLocked(!PixelFormat.formatHasAlpha(attrs.format));
1614 return true;
1615 }
1616 return false;
1617 }
1618
Craig Mautner6f612042014-09-07 13:13:23 -07001619 void setOpaqueLocked(boolean isOpaque) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001620 if (mSurfaceController == null) {
1621 return;
1622 }
Robert Carre6a83512015-11-03 16:09:21 -08001623 mSurfaceController.setOpaque(isOpaque);
Craig Mautner71dd1b62014-02-18 15:48:52 -08001624 }
1625
Wale Ogunwalef5ad42f2015-06-12 13:59:03 -07001626 void setSecureLocked(boolean isSecure) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001627 if (mSurfaceController == null) {
1628 return;
1629 }
Robert Carre6a83512015-11-03 16:09:21 -08001630 mSurfaceController.setSecure(isSecure);
Wale Ogunwalef5ad42f2015-06-12 13:59:03 -07001631 }
1632
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001633 /**
1634 * Have the surface flinger show a surface, robustly dealing with
1635 * error conditions. In particular, if there is not enough memory
1636 * to show the surface, then we will try to get rid of other surfaces
1637 * in order to succeed.
1638 *
1639 * @return Returns true if the surface was successfully shown.
1640 */
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001641 private boolean showSurfaceRobustlyLocked() {
Robert Carr1b5ea722016-04-20 13:23:28 -07001642 final Task task = mWin.getTask();
1643 if (task != null && StackId.windowsAreScaleable(task.mStack.mStackId)) {
1644 mSurfaceController.forceScaleableInTransaction(true);
1645 }
1646
Robert Carre6a83512015-11-03 16:09:21 -08001647 boolean shown = mSurfaceController.showRobustlyInTransaction();
1648 if (!shown)
1649 return false;
1650
1651 if (mWin.mTurnOnScreen) {
1652 if (DEBUG_VISIBILITY) Slog.v(TAG, "Show surface turning screen on: " + mWin);
1653 mWin.mTurnOnScreen = false;
1654 mAnimator.mBulkUpdateParams |= SET_TURN_ON_SCREEN;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001655 }
Robert Carre6a83512015-11-03 16:09:21 -08001656 return true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001657 }
1658
1659 void applyEnterAnimationLocked() {
Robert Carrb439a632016-04-07 22:52:10 -07001660 // If we are the new part of a window replacement transition and we have requested
1661 // not to animate, we instead want to make it seamless, so we don't want to apply
1662 // an enter transition.
1663 if (mWin.mSkipEnterAnimationForSeamlessReplacement) {
1664 return;
1665 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001666 final int transit;
1667 if (mEnterAnimationPending) {
1668 mEnterAnimationPending = false;
1669 transit = WindowManagerPolicy.TRANSIT_ENTER;
1670 } else {
1671 transit = WindowManagerPolicy.TRANSIT_SHOW;
1672 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001673 applyAnimationLocked(transit, true);
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001674 //TODO (multidisplay): Magnification is supported only for the default display.
Svetoslav8e3feb12014-02-24 13:46:47 -08001675 if (mService.mAccessibilityController != null
Filip Gruszczynski69cbc352015-11-11 13:46:04 -08001676 && mWin.getDisplayId() == DEFAULT_DISPLAY) {
Svetoslav8e3feb12014-02-24 13:46:47 -08001677 mService.mAccessibilityController.onWindowTransitionLocked(mWin, transit);
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -07001678 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001679 }
1680
1681 /**
1682 * Choose the correct animation and set it to the passed WindowState.
Craig Mautner4b71aa12012-12-27 17:20:01 -08001683 * @param transit If AppTransition.TRANSIT_PREVIEW_DONE and the app window has been drawn
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001684 * then the animation will be app_starting_exit. Any other value loads the animation from
1685 * the switch statement below.
1686 * @param isEntrance The animation type the last time this was called. Used to keep from
1687 * loading the same animation twice.
1688 * @return true if an animation has been loaded.
1689 */
1690 boolean applyAnimationLocked(int transit, boolean isEntrance) {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001691 if ((mLocalAnimating && mAnimationIsEntrance == isEntrance)
1692 || mKeyguardGoingAwayAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001693 // If we are trying to apply an animation, but already running
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001694 // an animation of the same type, then just leave that one alone.
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001695
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001696 // If we are in a keyguard exit animation, and the window should animate away, modify
1697 // keyguard exit animation such that it also fades out.
1698 if (mAnimation != null && mKeyguardGoingAwayAnimation
1699 && transit == WindowManagerPolicy.TRANSIT_PREVIEW_DONE) {
1700 applyFadeoutDuringKeyguardExitAnimation();
1701 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001702 return true;
1703 }
1704
1705 // Only apply an animation if the display isn't frozen. If it is
1706 // frozen, there is no reason to animate and it can cause strange
1707 // artifacts when we unfreeze the display if some different animation
1708 // is running.
Chong Zhang8784be62016-06-28 15:25:07 -07001709 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "WSA#applyAnimationLocked");
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001710 if (mService.okToDisplay()) {
1711 int anim = mPolicy.selectAnimationLw(mWin, transit);
1712 int attr = -1;
1713 Animation a = null;
1714 if (anim != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001715 a = anim != -1 ? AnimationUtils.loadAnimation(mContext, anim) : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001716 } else {
1717 switch (transit) {
1718 case WindowManagerPolicy.TRANSIT_ENTER:
1719 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
1720 break;
1721 case WindowManagerPolicy.TRANSIT_EXIT:
1722 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
1723 break;
1724 case WindowManagerPolicy.TRANSIT_SHOW:
1725 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
1726 break;
1727 case WindowManagerPolicy.TRANSIT_HIDE:
1728 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
1729 break;
1730 }
1731 if (attr >= 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001732 a = mService.mAppTransition.loadAnimationAttr(mWin.mAttrs, attr);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001733 }
1734 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001735 if (DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001736 "applyAnimation: win=" + this
1737 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
Craig Mautner4d7349b2012-04-20 14:52:47 -07001738 + " a=" + a
Craig Mautner8863cca2012-09-18 15:04:34 -07001739 + " transit=" + transit
Craig Mautner83339b42012-05-01 22:13:23 -07001740 + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001741 if (a != null) {
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -08001742 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001743 setAnimation(a);
1744 mAnimationIsEntrance = isEntrance;
1745 }
1746 } else {
1747 clearAnimation();
1748 }
Chong Zhang8784be62016-06-28 15:25:07 -07001749 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
1750
Jorim Jaggieb88d832016-04-13 20:17:43 -07001751 if (mWin.mAttrs.type == TYPE_INPUT_METHOD) {
1752 mService.adjustForImeIfNeeded(mWin.mDisplayContent);
Jorim Jaggi7a4fd5e2016-04-14 19:55:35 -07001753 if (isEntrance) {
1754 mWin.setDisplayLayoutNeeded();
1755 mService.mWindowPlacerLocked.requestTraversal();
1756 }
Jorim Jaggieb88d832016-04-13 20:17:43 -07001757 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001758 return mAnimation != null;
1759 }
1760
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001761 private void applyFadeoutDuringKeyguardExitAnimation() {
1762 long startTime = mAnimation.getStartTime();
1763 long duration = mAnimation.getDuration();
1764 long elapsed = mLastAnimationTime - startTime;
1765 long fadeDuration = duration - elapsed;
1766 if (fadeDuration <= 0) {
1767 // Never mind, this would be no visible animation, so abort the animation change.
1768 return;
1769 }
1770 AnimationSet newAnimation = new AnimationSet(false /* shareInterpolator */);
1771 newAnimation.setDuration(duration);
1772 newAnimation.setStartTime(startTime);
1773 newAnimation.addAnimation(mAnimation);
1774 Animation fadeOut = AnimationUtils.loadAnimation(
1775 mContext, com.android.internal.R.anim.app_starting_exit);
1776 fadeOut.setDuration(fadeDuration);
1777 fadeOut.setStartOffset(elapsed);
1778 newAnimation.addAnimation(fadeOut);
Filip Gruszczynskif52dd202015-11-15 20:36:38 -08001779 newAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(), mAnimDx, mAnimDy);
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001780 mAnimation = newAnimation;
1781 }
1782
Craig Mautnera2c77052012-03-26 12:14:43 -07001783 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1784 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
1785 || mAnimation != null) {
1786 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
1787 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
1788 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001789 pw.print(" mAnimation="); pw.print(mAnimation);
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001790 pw.print(" mStackClip="); pw.println(mStackClip);
Craig Mautnera2c77052012-03-26 12:14:43 -07001791 }
1792 if (mHasTransformation || mHasLocalTransformation) {
1793 pw.print(prefix); pw.print("XForm: has=");
1794 pw.print(mHasTransformation);
1795 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
1796 pw.print(" "); mTransformation.printShortString(pw);
1797 pw.println();
1798 }
Robert Carre6a83512015-11-03 16:09:21 -08001799 if (mSurfaceController != null) {
1800 mSurfaceController.dump(pw, prefix, dumpAll);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001801 }
Robert Carre6a83512015-11-03 16:09:21 -08001802 if (dumpAll) {
1803 pw.print(prefix); pw.print("mDrawState="); pw.print(drawStateToString());
1804 pw.print(prefix); pw.print(" mLastHidden="); pw.println(mLastHidden);
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001805 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
1806 pw.print(" last="); mLastSystemDecorRect.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001807 pw.print(" mHasClipRect="); pw.print(mHasClipRect);
1808 pw.print(" mLastClipRect="); mLastClipRect.printShortString(pw);
1809
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001810 if (!mLastFinalClipRect.isEmpty()) {
1811 pw.print(" mLastFinalClipRect="); mLastFinalClipRect.printShortString(pw);
1812 }
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001813 pw.println();
Robert Carre6a83512015-11-03 16:09:21 -08001814 }
1815
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001816 if (mPendingDestroySurface != null) {
1817 pw.print(prefix); pw.print("mPendingDestroySurface=");
1818 pw.println(mPendingDestroySurface);
1819 }
1820 if (mSurfaceResized || mSurfaceDestroyDeferred) {
1821 pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized);
1822 pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred);
1823 }
1824 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
1825 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
1826 pw.print(" mAlpha="); pw.print(mAlpha);
1827 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
1828 }
1829 if (mHaveMatrix || mWin.mGlobalScale != 1) {
1830 pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale);
1831 pw.print(" mDsDx="); pw.print(mDsDx);
1832 pw.print(" mDtDx="); pw.print(mDtDx);
1833 pw.print(" mDsDy="); pw.print(mDsDy);
1834 pw.print(" mDtDy="); pw.println(mDtDy);
1835 }
Jorim Jaggiff71d202016-04-14 13:12:36 -07001836 if (mAnimationStartDelayed) {
1837 pw.print(prefix); pw.print("mAnimationStartDelayed="); pw.print(mAnimationStartDelayed);
1838 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001839 }
1840
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001841 @Override
1842 public String toString() {
Dianne Hackborn529e7442012-11-01 14:22:28 -07001843 StringBuffer sb = new StringBuffer("WindowStateAnimator{");
1844 sb.append(Integer.toHexString(System.identityHashCode(this)));
1845 sb.append(' ');
1846 sb.append(mWin.mAttrs.getTitle());
1847 sb.append('}');
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001848 return sb.toString();
1849 }
Robert Carre6a83512015-11-03 16:09:21 -08001850
1851 void reclaimSomeSurfaceMemory(String operation, boolean secure) {
1852 mService.reclaimSomeSurfaceMemoryLocked(this, operation, secure);
1853 }
1854
1855 boolean getShown() {
1856 if (mSurfaceController != null) {
1857 return mSurfaceController.getShown();
1858 }
1859 return false;
1860 }
1861
1862 void destroySurface() {
Wale Ogunwale722ff892016-02-18 13:37:55 -08001863 try {
1864 if (mSurfaceController != null) {
1865 mSurfaceController.destroyInTransaction();
1866 }
1867 } catch (RuntimeException e) {
1868 Slog.w(TAG, "Exception thrown when destroying surface " + this
1869 + " surface " + mSurfaceController + " session " + mSession + ": " + e);
1870 } finally {
1871 mWin.setHasSurface(false);
1872 mSurfaceController = null;
1873 mDrawState = NO_SURFACE;
1874 }
Robert Carre6a83512015-11-03 16:09:21 -08001875 }
Filip Gruszczynskif52dd202015-11-15 20:36:38 -08001876
1877 void setMoveAnimation(int left, int top) {
1878 final Animation a = AnimationUtils.loadAnimation(mContext,
1879 com.android.internal.R.anim.window_move_from_decor);
1880 setAnimation(a);
1881 mAnimDx = mWin.mLastFrame.left - left;
1882 mAnimDy = mWin.mLastFrame.top - top;
1883 mAnimateMove = true;
1884 }
Robert Carr679c8072016-04-07 15:51:48 -07001885
1886 void deferTransactionUntilParentFrame(long frameNumber) {
1887 if (!mWin.isChildWindow()) {
1888 return;
1889 }
Robert Carr679c8072016-04-07 15:51:48 -07001890 mSurfaceController.deferTransactionUntil(
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001891 mWin.getParentWindow().mWinAnimator.mSurfaceController.getHandle(), frameNumber);
Robert Carr679c8072016-04-07 15:51:48 -07001892 }
1893
Jorim Jaggiff71d202016-04-14 13:12:36 -07001894 /**
1895 * Sometimes we need to synchronize the first frame of animation with some external event.
1896 * To achieve this, we prolong the start of the animation and keep producing the first frame of
1897 * the animation.
1898 */
1899 private long getAnimationFrameTime(Animation animation, long currentTime) {
1900 if (mAnimationStartDelayed) {
1901 animation.setStartTime(currentTime);
1902 return currentTime + 1;
1903 }
1904 return currentTime;
1905 }
1906
1907 void startDelayingAnimationStart() {
1908 mAnimationStartDelayed = true;
1909 }
1910
1911 void endDelayingAnimationStart() {
1912 mAnimationStartDelayed = false;
1913 }
Robert Carr6da3cc02016-06-16 15:17:07 -07001914
1915 void seamlesslyRotateWindow(int oldRotation, int newRotation) {
1916 final WindowState w = mWin;
1917 if (!w.isVisibleNow() || w.mIsWallpaper) {
1918 return;
1919 }
1920
1921 final Rect cropRect = mService.mTmpRect;
1922 final Rect displayRect = mService.mTmpRect2;
1923 final RectF frameRect = mService.mTmpRectF;
1924 final Matrix transform = mService.mTmpTransform;
1925
1926 final float x = w.mFrame.left;
1927 final float y = w.mFrame.top;
1928 final float width = w.mFrame.width();
1929 final float height = w.mFrame.height();
1930
1931 mService.getDefaultDisplayContentLocked().getLogicalDisplayRect(displayRect);
1932 final float displayWidth = displayRect.width();
1933 final float displayHeight = displayRect.height();
1934
1935 // Compute a transform matrix to undo the coordinate space transformation,
1936 // and present the window at the same physical position it previously occupied.
1937 final int deltaRotation = DisplayContent.deltaRotation(newRotation, oldRotation);
1938 switch (deltaRotation) {
1939 case Surface.ROTATION_0:
1940 transform.reset();
1941 break;
1942 case Surface.ROTATION_270:
1943 transform.setRotate(270, 0, 0);
1944 transform.postTranslate(0, displayHeight);
1945 transform.postTranslate(y, 0);
1946 break;
1947 case Surface.ROTATION_180:
1948 transform.reset();
1949 break;
1950 case Surface.ROTATION_90:
1951 transform.setRotate(90, 0, 0);
1952 transform.postTranslate(displayWidth, 0);
1953 transform.postTranslate(-y, x);
1954 break;
1955 }
1956
1957 // We have two cases:
1958 // 1. Windows with NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY:
1959 // These windows never change buffer size when rotating. Rather the window manager
1960 // just updates the scaling factors to fit in the new coordinate system,
1961 // and SurfaceFlinger takes care of updating the buffer contents. So in this case
1962 // we just need we just need to update the scaling factors and things are seamless
1963 // already.
1964 // 2. Other windows:
1965 // In this case, we need to apply a rotation matrix to the window. For example
1966 // if we have a portrait window and rotate to landscape, the window is still portrait
1967 // and now extends off the bottom of the screen (and only halfway across). Essentially we
1968 // apply a transform to display the current buffer at it's old position
1969 // (in the new coordinate space). We then freeze layer updates until the resize
1970 // occurs, at which point we undo, them.
1971 if (w.isChildWindow() && mSurfaceController.getTransformToDisplayInverse()) {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001972 frameRect.set(x, y, x + width, y + height);
Robert Carr6da3cc02016-06-16 15:17:07 -07001973 transform.mapRect(frameRect);
1974
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001975 final Rect parentWindowFrame = w.getParentWindow().mFrame;
1976 w.mAttrs.x = (int) frameRect.left - parentWindowFrame.left;
1977 w.mAttrs.y = (int) frameRect.top - parentWindowFrame.top;
Robert Carr6da3cc02016-06-16 15:17:07 -07001978 w.mAttrs.width = (int) Math.ceil(frameRect.width());
1979 w.mAttrs.height = (int) Math.ceil(frameRect.height());
1980
1981 w.setWindowScale(w.mRequestedWidth, w.mRequestedHeight);
1982
1983 w.applyGravityAndUpdateFrame(w.mContainingFrame, w.mDisplayFrame);
1984 computeShownFrameLocked();
1985 setSurfaceBoundariesLocked(false);
1986
1987 // The stack bounds will not yet be rotated at this point so setSurfaceBoundaries locked
1988 // will crop us incorrectly. Overwrite the crop, exposing the full surface. By the next
1989 // transaction this will be corrected.
1990 cropRect.set(0, 0, w.mRequestedWidth, w.mRequestedWidth + w.mRequestedHeight);
1991 mSurfaceController.setCropInTransaction(cropRect, false);
1992 } else {
1993 w.mSeamlesslyRotated = true;
1994 transform.getValues(mService.mTmpFloats);
1995
1996 float DsDx = mService.mTmpFloats[Matrix.MSCALE_X];
1997 float DtDx = mService.mTmpFloats[Matrix.MSKEW_Y];
1998 float DsDy = mService.mTmpFloats[Matrix.MSKEW_X];
1999 float DtDy = mService.mTmpFloats[Matrix.MSCALE_Y];
2000 float nx = mService.mTmpFloats[Matrix.MTRANS_X];
2001 float ny = mService.mTmpFloats[Matrix.MTRANS_Y];
2002 mSurfaceController.setPositionInTransaction(nx, ny, false);
2003 mSurfaceController.setMatrixInTransaction(DsDx * w.mHScale,
2004 DtDx * w.mVScale,
2005 DsDy * w.mHScale,
2006 DtDy * w.mVScale, false);
2007 }
2008 }
Craig Mautnera2c77052012-03-26 12:14:43 -07002009}