blob: 2a525d4e2e63e83a569f9c26dd9ef6df9f8253fa [file] [log] [blame]
Craig Mautnerc2c0a612014-02-20 20:25:41 -08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Craig Mautnera2c77052012-03-26 12:14:43 -070016
17package com.android.server.wm;
18
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -070019import static android.app.ActivityManager.StackId;
Robert Carr1b5ea722016-04-20 13:23:28 -070020import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -080021import static android.view.Display.DEFAULT_DISPLAY;
Wale Ogunwalee7bf46b2015-09-30 09:19:28 -070022import static android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -080023import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070024import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Jorim Jaggieb88d832016-04-13 20:17:43 -070025import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
Jorim Jaggiff71d202016-04-14 13:12:36 -070026import static com.android.server.wm.AppWindowAnimator.sDummyAnimation;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +010027import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
Wale Ogunwale2728bf42016-03-03 11:03:26 -080028import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080029import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
30import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
31import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
32import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
33import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
34import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE;
35import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
36import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -080037import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_CROP;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080038import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
39import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
40import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
41import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
42import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang97782b42015-10-07 16:01:23 -070043import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -080044import static com.android.server.wm.WindowManagerService.localLOGV;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080045import static com.android.server.wm.WindowManagerService.logWithStack;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070046import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
47import static com.android.server.wm.WindowSurfacePlacer.SET_TURN_ON_SCREEN;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070048
Craig Mautnerc2f9be02012-03-27 17:32:29 -070049import android.content.Context;
50import android.graphics.Matrix;
51import android.graphics.PixelFormat;
Craig Mautner7358fbf2012-04-12 21:06:33 -070052import android.graphics.Point;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070053import android.graphics.Rect;
Robert Carr6da3cc02016-06-16 15:17:07 -070054import android.graphics.RectF;
Craig Mautner48ba1e72012-04-02 13:18:16 -070055import android.graphics.Region;
Craig Mautnera51a9562012-04-17 17:05:26 -070056import android.os.Debug;
Craig Mautner9c795042014-10-28 19:59:59 -070057import android.os.RemoteException;
Chong Zhang8784be62016-06-28 15:25:07 -070058import android.os.Trace;
Craig Mautnera2c77052012-03-26 12:14:43 -070059import android.util.Slog;
Craig Mautner59c00972012-07-30 12:10:24 -070060import android.view.DisplayInfo;
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -070061import android.view.MagnificationSpec;
Robert Carr6da3cc02016-06-16 15:17:07 -070062import android.view.Surface;
Igor Murashkina86ab6402013-08-30 12:58:36 -070063import android.view.Surface.OutOfResourcesException;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080064import android.view.SurfaceControl;
Craig Mautnera2c77052012-03-26 12:14:43 -070065import android.view.WindowManager;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070066import android.view.WindowManager.LayoutParams;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -080067import android.view.WindowManagerPolicy;
Craig Mautnera2c77052012-03-26 12:14:43 -070068import android.view.animation.Animation;
Jorim Jaggif8d77da2014-11-11 16:59:12 +010069import android.view.animation.AnimationSet;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070070import android.view.animation.AnimationUtils;
Craig Mautnera2c77052012-03-26 12:14:43 -070071import android.view.animation.Transformation;
72
73import com.android.server.wm.WindowManagerService.H;
74
75import java.io.PrintWriter;
76
77/**
Craig Mautnerc2f9be02012-03-27 17:32:29 -070078 * Keep track of animations and surface operations for a single WindowState.
79 **/
Craig Mautnera2c77052012-03-26 12:14:43 -070080class WindowStateAnimator {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080081 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowStateAnimator" : TAG_WM;
Chong Zhang97782b42015-10-07 16:01:23 -070082 static final int WINDOW_FREEZE_LAYER = TYPE_LAYER_MULTIPLIER * 200;
Craig Mautnera2c77052012-03-26 12:14:43 -070083
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010084 /**
85 * Mode how the window gets clipped by the stack bounds during an animation: The clipping should
86 * be applied after applying the animation transformation, i.e. the stack bounds don't move
87 * during the animation.
88 */
89 static final int STACK_CLIP_AFTER_ANIM = 0;
90
91 /**
92 * Mode how the window gets clipped by the stack bounds: The clipping should be applied before
93 * applying the animation transformation, i.e. the stack bounds move with the window.
94 */
95 static final int STACK_CLIP_BEFORE_ANIM = 1;
96
97 /**
98 * Mode how window gets clipped by the stack bounds during an animation: Don't clip the window
99 * by the stack bounds.
100 */
101 static final int STACK_CLIP_NONE = 2;
102
Craig Mautner918b53b2012-07-09 14:15:54 -0700103 // Unchanging local convenience fields.
Craig Mautnera2c77052012-03-26 12:14:43 -0700104 final WindowManagerService mService;
105 final WindowState mWin;
Craig Mautner322e4032012-07-13 13:35:20 -0700106 final WindowStateAnimator mAttachedWinAnimator;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700107 final WindowAnimator mAnimator;
Craig Mautner8863cca2012-09-18 15:04:34 -0700108 AppWindowAnimator mAppAnimator;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700109 final Session mSession;
110 final WindowManagerPolicy mPolicy;
111 final Context mContext;
Craig Mautner918b53b2012-07-09 14:15:54 -0700112 final boolean mIsWallpaper;
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700113 final WallpaperController mWallpaperControllerLocked;
Craig Mautnera2c77052012-03-26 12:14:43 -0700114
115 // Currently running animation.
116 boolean mAnimating;
117 boolean mLocalAnimating;
118 Animation mAnimation;
119 boolean mAnimationIsEntrance;
120 boolean mHasTransformation;
121 boolean mHasLocalTransformation;
122 final Transformation mTransformation = new Transformation();
123 boolean mWasAnimating; // Were we animating going into the most recent animation step?
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700124 int mAnimLayer;
125 int mLastLayer;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100126 long mAnimationStartTime;
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100127 long mLastAnimationTime;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100128 int mStackClip = STACK_CLIP_BEFORE_ANIM;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700129
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700130 /**
131 * Set when we have changed the size of the surface, to know that
132 * we must tell them application to resize (and thus redraw itself).
133 */
134 boolean mSurfaceResized;
Chong Zhang5b2f1992015-11-13 15:40:36 -0800135 /**
136 * Whether we should inform the client on next relayoutWindow that
137 * the surface has been resized since last time.
138 */
139 boolean mReportSurfaceResized;
Robert Carre6a83512015-11-03 16:09:21 -0800140 WindowSurfaceController mSurfaceController;
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800141 private WindowSurfaceController mPendingDestroySurface;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700142
143 /**
144 * Set if the client has asked that the destroy of its surface be delayed
145 * until it explicitly says it is okay.
146 */
147 boolean mSurfaceDestroyDeferred;
148
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800149 private boolean mDestroyPreservedSurfaceUponRedraw;
Craig Mautner7d8df392012-04-06 15:26:23 -0700150 float mShownAlpha = 0;
151 float mAlpha = 0;
152 float mLastAlpha = 0;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700153
Winson Chung399f6202014-03-19 10:47:20 -0700154 boolean mHasClipRect;
155 Rect mClipRect = new Rect();
156 Rect mTmpClipRect = new Rect();
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100157 Rect mTmpFinalClipRect = new Rect();
Winson Chung399f6202014-03-19 10:47:20 -0700158 Rect mLastClipRect = new Rect();
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100159 Rect mLastFinalClipRect = new Rect();
Filip Gruszczynski4b8eea72015-09-14 18:16:19 -0700160 Rect mTmpStackBounds = new Rect();
Winson Chung399f6202014-03-19 10:47:20 -0700161
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -0800162 /**
163 * This is rectangle of the window's surface that is not covered by
164 * system decorations.
165 */
166 private final Rect mSystemDecorRect = new Rect();
167 private final Rect mLastSystemDecorRect = new Rect();
168
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800169 // Used to save animation distances between the time they are calculated and when they are used.
170 private int mAnimDx;
171 private int mAnimDy;
Jorim Jaggic5af4f82015-07-01 17:16:27 -0700172
173 /** Is the next animation to be started a window move animation? */
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800174 private boolean mAnimateMove = false;
Jorim Jaggic5af4f82015-07-01 17:16:27 -0700175
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700176 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
177 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
178
179 boolean mHaveMatrix;
180
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700181 // Set to true if, when the window gets displayed, it should perform
182 // an enter animation.
183 boolean mEnterAnimationPending;
Craig Mautnera2c77052012-03-26 12:14:43 -0700184
Craig Mautner9c795042014-10-28 19:59:59 -0700185 /** Used to indicate that this window is undergoing an enter animation. Used for system
186 * windows to make the callback to View.dispatchOnWindowShownCallback(). Set when the
187 * window is first added or shown, cleared when the callback has been made. */
188 boolean mEnteringAnimation;
189
Jorim Jaggiff71d202016-04-14 13:12:36 -0700190 private boolean mAnimationStartDelayed;
191
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100192 boolean mKeyguardGoingAwayAnimation;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800193 boolean mKeyguardGoingAwayWithWallpaper;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200194
John Reck80181b92015-05-19 11:09:32 -0700195 /** The pixel format of the underlying SurfaceControl */
196 int mSurfaceFormat;
197
Craig Mautner749a7bb2012-04-02 13:49:53 -0700198 /** This is set when there is no Surface */
199 static final int NO_SURFACE = 0;
200 /** This is set after the Surface has been created but before the window has been drawn. During
201 * this time the surface is hidden. */
202 static final int DRAW_PENDING = 1;
203 /** This is set after the window has finished drawing for the first time but before its surface
204 * is shown. The surface will be displayed when the next layout is run. */
205 static final int COMMIT_DRAW_PENDING = 2;
206 /** This is set during the time after the window's drawing has been committed, and before its
207 * surface is actually shown. It is used to delay showing the surface until all windows in a
208 * token are ready to be shown. */
209 static final int READY_TO_SHOW = 3;
210 /** Set when the window has been shown in the screen the first time. */
211 static final int HAS_DRAWN = 4;
Adrian Roos3eeb4e62014-05-19 12:43:26 +0200212
Craig Mautner276a6eb2014-11-04 15:32:57 -0800213 String drawStateToString() {
214 switch (mDrawState) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700215 case NO_SURFACE: return "NO_SURFACE";
216 case DRAW_PENDING: return "DRAW_PENDING";
217 case COMMIT_DRAW_PENDING: return "COMMIT_DRAW_PENDING";
218 case READY_TO_SHOW: return "READY_TO_SHOW";
219 case HAS_DRAWN: return "HAS_DRAWN";
Craig Mautner276a6eb2014-11-04 15:32:57 -0800220 default: return Integer.toString(mDrawState);
Craig Mautner6fbda632012-07-03 09:26:39 -0700221 }
222 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700223 int mDrawState;
Craig Mautnera608b882012-03-30 13:03:49 -0700224
Craig Mautner749a7bb2012-04-02 13:49:53 -0700225 /** Was this window last hidden? */
226 boolean mLastHidden;
Craig Mautnera608b882012-03-30 13:03:49 -0700227
Craig Mautnerbec53f72012-04-05 11:49:05 -0700228 int mAttrType;
229
Robert Carr679c8072016-04-07 15:51:48 -0700230 static final long PENDING_TRANSACTION_FINISH_WAIT_TIME = 100;
Robert Carr679c8072016-04-07 15:51:48 -0700231
Robert Carrc7294602016-05-13 11:32:05 -0700232 boolean mForceScaleUntilResize;
233
Robert Carr04092112016-06-02 12:56:12 -0700234 // WindowState.mHScale and WindowState.mVScale contain the
235 // scale according to client specified layout parameters (e.g.
236 // one layout size, with another surface size, creates such scaling).
237 // Here we track an additional scaling factor used to follow stack
238 // scaling (as in the case of the Pinned stack animation).
239 float mExtraHScale = (float) 1.0;
240 float mExtraVScale = (float) 1.0;
241
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800242 private final Rect mTmpSize = new Rect();
243
Craig Mautnerc431e892015-02-11 13:14:26 -0800244 WindowStateAnimator(final WindowState win) {
Craig Mautner918b53b2012-07-09 14:15:54 -0700245 final WindowManagerService service = win.mService;
246
Craig Mautnera2c77052012-03-26 12:14:43 -0700247 mService = service;
Craig Mautner918b53b2012-07-09 14:15:54 -0700248 mAnimator = service.mAnimator;
249 mPolicy = service.mPolicy;
250 mContext = service.mContext;
Craig Mautnerd3849f52014-03-27 13:19:29 -0700251 final DisplayContent displayContent = win.getDisplayContent();
252 if (displayContent != null) {
253 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800254 mAnimDx = displayInfo.appWidth;
255 mAnimDy = displayInfo.appHeight;
Craig Mautnerd3849f52014-03-27 13:19:29 -0700256 } else {
257 Slog.w(TAG, "WindowStateAnimator ctor: Display has been removed");
258 // This is checked on return and dealt with.
259 }
Craig Mautner918b53b2012-07-09 14:15:54 -0700260
261 mWin = win;
Craig Mautner322e4032012-07-13 13:35:20 -0700262 mAttachedWinAnimator = win.mAttachedWindow == null
263 ? null : win.mAttachedWindow.mWinAnimator;
264 mAppAnimator = win.mAppToken == null ? null : win.mAppToken.mAppAnimator;
Craig Mautner918b53b2012-07-09 14:15:54 -0700265 mSession = win.mSession;
Craig Mautner918b53b2012-07-09 14:15:54 -0700266 mAttrType = win.mAttrs.type;
267 mIsWallpaper = win.mIsWallpaper;
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700268 mWallpaperControllerLocked = mService.mWallpaperControllerLocked;
Craig Mautnera2c77052012-03-26 12:14:43 -0700269 }
270
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100271 public void setAnimation(Animation anim, long startTime, int stackClip) {
Craig Mautnerbec53f72012-04-05 11:49:05 -0700272 if (localLOGV) Slog.v(TAG, "Setting animation in " + this + ": " + anim);
Craig Mautnera2c77052012-03-26 12:14:43 -0700273 mAnimating = false;
274 mLocalAnimating = false;
275 mAnimation = anim;
276 mAnimation.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION);
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700277 mAnimation.scaleCurrentDuration(mService.getWindowAnimationScaleLocked());
Craig Mautnera2c77052012-03-26 12:14:43 -0700278 // Start out animation gone if window is gone, or visible if window is visible.
279 mTransformation.clear();
Craig Mautner749a7bb2012-04-02 13:49:53 -0700280 mTransformation.setAlpha(mLastHidden ? 0 : 1);
Craig Mautnera2c77052012-03-26 12:14:43 -0700281 mHasLocalTransformation = true;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100282 mAnimationStartTime = startTime;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100283 mStackClip = stackClip;
284 }
285
286 public void setAnimation(Animation anim, int stackClip) {
287 setAnimation(anim, -1, stackClip);
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100288 }
289
290 public void setAnimation(Animation anim) {
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100291 setAnimation(anim, -1, STACK_CLIP_AFTER_ANIM);
Craig Mautnera2c77052012-03-26 12:14:43 -0700292 }
293
294 public void clearAnimation() {
295 if (mAnimation != null) {
296 mAnimating = true;
297 mLocalAnimating = false;
298 mAnimation.cancel();
299 mAnimation = null;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100300 mKeyguardGoingAwayAnimation = false;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800301 mKeyguardGoingAwayWithWallpaper = false;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100302 mStackClip = STACK_CLIP_BEFORE_ANIM;
Craig Mautnera2c77052012-03-26 12:14:43 -0700303 }
304 }
305
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700306 /**
307 * Is the window or its container currently set to animate or currently animating?
308 */
309 boolean isAnimationSet() {
Craig Mautnera2c77052012-03-26 12:14:43 -0700310 return mAnimation != null
Craig Mautner322e4032012-07-13 13:35:20 -0700311 || (mAttachedWinAnimator != null && mAttachedWinAnimator.mAnimation != null)
Jorim Jaggi37875612015-02-19 21:05:31 +0100312 || (mAppAnimator != null && mAppAnimator.isAnimating());
Craig Mautnera2c77052012-03-26 12:14:43 -0700313 }
314
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700315 /**
316 * @return whether an animation is about to start, i.e. the animation is set already but we
317 * haven't processed the first frame yet.
318 */
319 boolean isAnimationStarting() {
320 return isAnimationSet() && !mAnimating;
321 }
322
Craig Mautner0afddcb2012-05-08 15:38:00 -0700323 /** Is the window animating the DummyAnimation? */
324 boolean isDummyAnimation() {
Craig Mautner322e4032012-07-13 13:35:20 -0700325 return mAppAnimator != null
Jorim Jaggiff71d202016-04-14 13:12:36 -0700326 && mAppAnimator.animation == sDummyAnimation;
Craig Mautner0afddcb2012-05-08 15:38:00 -0700327 }
328
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700329 /**
330 * Is this window currently set to animate or currently animating?
331 */
332 boolean isWindowAnimationSet() {
Craig Mautnera2c77052012-03-26 12:14:43 -0700333 return mAnimation != null;
334 }
335
Chong Zhange22006d2016-05-09 10:59:59 -0700336 /**
337 * Is this window currently waiting to run an opening animation?
338 */
339 boolean isWaitingForOpening() {
340 return mService.mAppTransition.isTransitionSet() && isDummyAnimation()
341 && mService.mOpeningApps.contains(mWin.mAppToken);
342 }
343
Craig Mautnera2c77052012-03-26 12:14:43 -0700344 void cancelExitAnimationForNextAnimationLocked() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800345 if (DEBUG_ANIM) Slog.d(TAG,
346 "cancelExitAnimationForNextAnimationLocked: " + mWin);
347
Craig Mautnera2c77052012-03-26 12:14:43 -0700348 if (mAnimation != null) {
349 mAnimation.cancel();
350 mAnimation = null;
Craig Mautner4d7349b2012-04-20 14:52:47 -0700351 mLocalAnimating = false;
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800352 mWin.destroyOrSaveSurface();
Craig Mautnera2c77052012-03-26 12:14:43 -0700353 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700354 }
355
356 private boolean stepAnimation(long currentTime) {
357 if ((mAnimation == null) || !mLocalAnimating) {
358 return false;
359 }
Jorim Jaggiff71d202016-04-14 13:12:36 -0700360 currentTime = getAnimationFrameTime(mAnimation, currentTime);
Craig Mautnera2c77052012-03-26 12:14:43 -0700361 mTransformation.clear();
362 final boolean more = mAnimation.getTransformation(currentTime, mTransformation);
Jorim Jaggiff71d202016-04-14 13:12:36 -0700363 if (mAnimationStartDelayed && mAnimationIsEntrance) {
364 mTransformation.setAlpha(0f);
365 }
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700366 if (false && DEBUG_ANIM) Slog.v(TAG, "Stepped animation in " + this + ": more=" + more
367 + ", xform=" + mTransformation);
Craig Mautnera2c77052012-03-26 12:14:43 -0700368 return more;
369 }
370
371 // This must be called while inside a transaction. Returns true if
372 // there is more animation to run.
373 boolean stepAnimationLocked(long currentTime) {
Chet Haase9c450412015-10-01 13:25:58 -0700374 // Save the animation state as it was before this step so WindowManagerService can tell if
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700375 // we just started or just stopped animating by comparing mWasAnimating with isAnimationSet().
Chet Haase9c450412015-10-01 13:25:58 -0700376 mWasAnimating = mAnimating;
Craig Mautnerdf88d732014-01-27 09:21:32 -0800377 final DisplayContent displayContent = mWin.getDisplayContent();
378 if (displayContent != null && mService.okToDisplay()) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700379 // We will run animations as long as the display isn't frozen.
380
381 if (mWin.isDrawnLw() && mAnimation != null) {
382 mHasTransformation = true;
383 mHasLocalTransformation = true;
384 if (!mLocalAnimating) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700385 if (DEBUG_ANIM) Slog.v(
386 TAG, "Starting animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700387 " @ " + currentTime + ": ww=" + mWin.mFrame.width() +
388 " wh=" + mWin.mFrame.height() +
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800389 " dx=" + mAnimDx + " dy=" + mAnimDy +
Dianne Hackborneb94fa72014-06-03 17:48:12 -0700390 " scale=" + mService.getWindowAnimationScaleLocked());
Craig Mautnerdf88d732014-01-27 09:21:32 -0800391 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
tiger_huangb7f3f922015-04-27 20:36:46 +0800392 if (mAnimateMove) {
393 mAnimateMove = false;
394 mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(),
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800395 mAnimDx, mAnimDy);
tiger_huangb7f3f922015-04-27 20:36:46 +0800396 } else {
397 mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(),
398 displayInfo.appWidth, displayInfo.appHeight);
399 }
Filip Gruszczynskif52dd202015-11-15 20:36:38 -0800400 mAnimDx = displayInfo.appWidth;
401 mAnimDy = displayInfo.appHeight;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100402 mAnimation.setStartTime(mAnimationStartTime != -1
403 ? mAnimationStartTime
404 : currentTime);
Craig Mautnera2c77052012-03-26 12:14:43 -0700405 mLocalAnimating = true;
406 mAnimating = true;
407 }
408 if ((mAnimation != null) && mLocalAnimating) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100409 mLastAnimationTime = currentTime;
Craig Mautnera2c77052012-03-26 12:14:43 -0700410 if (stepAnimation(currentTime)) {
411 return true;
412 }
413 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700414 if (DEBUG_ANIM) Slog.v(
415 TAG, "Finished animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700416 " @ " + currentTime);
417 //WindowManagerService.this.dump();
418 }
419 mHasLocalTransformation = false;
Craig Mautner322e4032012-07-13 13:35:20 -0700420 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppAnimator != null
421 && mAppAnimator.animation != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700422 // When our app token is animating, we kind-of pretend like
423 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
424 // part of this check means that we will only do this if
425 // our window is not currently exiting, or it is not
426 // locally animating itself. The idea being that one that
427 // is exiting and doing a local animation should be removed
428 // once that animation is done.
429 mAnimating = true;
430 mHasTransformation = true;
431 mTransformation.clear();
432 return false;
433 } else if (mHasTransformation) {
434 // Little trick to get through the path below to act like
435 // we have finished an animation.
436 mAnimating = true;
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700437 } else if (isAnimationSet()) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700438 mAnimating = true;
439 }
440 } else if (mAnimation != null) {
441 // If the display is frozen, and there is a pending animation,
442 // clear it and make sure we run the cleanup code.
443 mAnimating = true;
Craig Mautnera2c77052012-03-26 12:14:43 -0700444 }
445
446 if (!mAnimating && !mLocalAnimating) {
447 return false;
448 }
449
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700450 // Done animating, clean up.
451 if (DEBUG_ANIM) Slog.v(
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800452 TAG, "Animation done in " + this + ": exiting=" + mWin.mAnimatingExit
Craig Mautnera2c77052012-03-26 12:14:43 -0700453 + ", reportedVisible="
454 + (mWin.mAppToken != null ? mWin.mAppToken.reportedVisible : false));
455
456 mAnimating = false;
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100457 mKeyguardGoingAwayAnimation = false;
Adrian Roosd5c2db62016-03-08 16:11:31 -0800458 mKeyguardGoingAwayWithWallpaper = false;
Craig Mautnera2c77052012-03-26 12:14:43 -0700459 mLocalAnimating = false;
460 if (mAnimation != null) {
461 mAnimation.cancel();
462 mAnimation = null;
463 }
Craig Mautnere7ae2502012-03-26 17:11:19 -0700464 if (mAnimator.mWindowDetachedWallpaper == mWin) {
465 mAnimator.mWindowDetachedWallpaper = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700466 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -0800467 mAnimLayer = mWin.mLayer
468 + mService.mLayersController.getSpecialWindowAnimLayerAdjustment(mWin);
Filip Gruszczynski14b4e572015-11-03 15:53:55 -0800469 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this + " anim layer: " + mAnimLayer);
Craig Mautnera2c77052012-03-26 12:14:43 -0700470 mHasTransformation = false;
471 mHasLocalTransformation = false;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100472 mStackClip = STACK_CLIP_BEFORE_ANIM;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -0800473 mWin.checkPolicyVisibilityChange();
Craig Mautnera2c77052012-03-26 12:14:43 -0700474 mTransformation.clear();
Craig Mautner749a7bb2012-04-02 13:49:53 -0700475 if (mDrawState == HAS_DRAWN
Craig Mautnera2c77052012-03-26 12:14:43 -0700476 && mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
477 && mWin.mAppToken != null
478 && mWin.mAppToken.firstWindowDrawn
479 && mWin.mAppToken.startingData != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700480 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
Craig Mautnera2c77052012-03-26 12:14:43 -0700481 + mWin.mToken + ": first real window done animating");
482 mService.mFinishedStarting.add(mWin.mAppToken);
483 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
Craig Mautner81defc72013-10-29 11:10:42 -0700484 } else if (mAttrType == LayoutParams.TYPE_STATUS_BAR && mWin.mPolicyVisibility) {
485 // Upon completion of a not-visible to visible status bar animation a relayout is
486 // required.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800487 if (displayContent != null) {
488 displayContent.layoutNeeded = true;
489 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700490 }
491
492 finishExit();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800493 final int displayId = mWin.getDisplayId();
Craig Mautner76a71652012-09-03 23:23:58 -0700494 mAnimator.setPendingLayoutChanges(displayId, WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800495 if (DEBUG_LAYOUT_REPEATS)
Filip Gruszczynski4501d232015-09-02 13:00:02 -0700496 mService.mWindowPlacerLocked.debugLayoutRepeats(
497 "WindowStateAnimator", mAnimator.getPendingLayoutChanges(displayId));
Craig Mautnera2c77052012-03-26 12:14:43 -0700498
499 if (mWin.mAppToken != null) {
500 mWin.mAppToken.updateReportedVisibilityLocked();
501 }
502
503 return false;
504 }
505
506 void finishExit() {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800507 if (DEBUG_ANIM) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700508 TAG, "finishExit in " + this
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800509 + ": exiting=" + mWin.mAnimatingExit
Craig Mautnera2c77052012-03-26 12:14:43 -0700510 + " remove=" + mWin.mRemoveOnExit
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700511 + " windowAnimating=" + isWindowAnimationSet());
Craig Mautnera2c77052012-03-26 12:14:43 -0700512
Wale Ogunwale33fde7d2016-03-05 22:38:51 -0800513 if (!mWin.mChildWindows.isEmpty()) {
514 // Copying to a different list as multiple children can be removed.
515 final WindowList childWindows = new WindowList(mWin.mChildWindows);
516 for (int i = childWindows.size() - 1; i >= 0; i--) {
517 childWindows.get(i).mWinAnimator.finishExit();
518 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700519 }
520
Filip Gruszczynski57f76f12015-11-04 16:10:54 -0800521 if (mEnteringAnimation) {
522 mEnteringAnimation = false;
523 mService.requestTraversal();
524 // System windows don't have an activity and an app token as a result, but need a way
525 // to be informed about their entrance animation end.
526 if (mWin.mAppToken == null) {
527 try {
528 mWin.mClient.dispatchWindowShown();
529 } catch (RemoteException e) {
530 }
Craig Mautner9c795042014-10-28 19:59:59 -0700531 }
532 }
533
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700534 if (!isWindowAnimationSet()) {
Svetoslav75b55d02014-12-03 16:26:35 -0800535 //TODO (multidisplay): Accessibility is supported only for the default display.
536 if (mService.mAccessibilityController != null
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800537 && mWin.getDisplayId() == DEFAULT_DISPLAY) {
Svetoslav75b55d02014-12-03 16:26:35 -0800538 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
539 }
540 }
541
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800542 if (!mWin.mAnimatingExit) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700543 return;
544 }
545
Jorim Jaggi5c80c412016-04-19 20:03:47 -0700546 if (isWindowAnimationSet()) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700547 return;
548 }
549
Wale Ogunwale2728bf42016-03-03 11:03:26 -0800550 if (WindowManagerService.localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
551 "Exit animation finished in " + this + ": remove=" + mWin.mRemoveOnExit);
Robert Carre12aece2016-02-02 22:43:27 -0800552
553
554 mWin.mDestroying = true;
555
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800556 final boolean hasSurface = hasSurface();
557 if (hasSurface) {
558 hide("finishExit");
559 }
560
Robert Carre12aece2016-02-02 22:43:27 -0800561 // If we have an app token, we ask it to destroy the surface for us,
562 // so that it can take care to ensure the activity has actually stopped
563 // and the surface is not still in use. Otherwise we add the service to
564 // mDestroySurface and allow it to be processed in our next transaction.
565 if (mWin.mAppToken != null) {
Robert Carre12aece2016-02-02 22:43:27 -0800566 mWin.mAppToken.destroySurfaces();
567 } else {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800568 if (hasSurface) {
Robert Carre12aece2016-02-02 22:43:27 -0800569 mService.mDestroySurface.add(mWin);
Robert Carre12aece2016-02-02 22:43:27 -0800570 }
Robert Carre12aece2016-02-02 22:43:27 -0800571 if (mWin.mRemoveOnExit) {
572 mService.mPendingRemove.add(mWin);
573 mWin.mRemoveOnExit = false;
574 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700575 }
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800576 mWin.mAnimatingExit = false;
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700577 mWallpaperControllerLocked.hideWallpapers(mWin);
Craig Mautner0afddcb2012-05-08 15:38:00 -0700578 }
579
Filip Gruszczynski63a35e22015-11-05 15:38:59 -0800580 void hide(String reason) {
Craig Mautner0afddcb2012-05-08 15:38:00 -0700581 if (!mLastHidden) {
582 //dump();
583 mLastHidden = true;
Wale Ogunwalef9e09782015-11-09 12:42:37 -0800584 if (mSurfaceController != null) {
585 mSurfaceController.hideInTransaction(reason);
586 }
Craig Mautner0afddcb2012-05-08 15:38:00 -0700587 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700588 }
589
Craig Mautnera608b882012-03-30 13:03:49 -0700590 boolean finishDrawingLocked() {
Craig Mautner42d04db2014-11-06 12:13:23 -0800591 final boolean startingWindow =
592 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
593 if (DEBUG_STARTING_WINDOW && startingWindow) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700594 Slog.v(TAG, "Finishing drawing window " + mWin + ": mDrawState="
Craig Mautner276a6eb2014-11-04 15:32:57 -0800595 + drawStateToString());
Craig Mautner6fbda632012-07-03 09:26:39 -0700596 }
Robert Carr1ca6a332016-04-11 18:00:43 -0700597
Chong Zhangcbbcc0f2016-05-17 20:46:58 -0700598 boolean layoutNeeded = mWin.clearAnimatingWithSavedSurface();
Chong Zhang92147042016-05-09 12:47:11 -0700599
Craig Mautner749a7bb2012-04-02 13:49:53 -0700600 if (mDrawState == DRAW_PENDING) {
Craig Mautneref25d7a2012-05-15 23:01:47 -0700601 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
Chong Zhang5b2f1992015-11-13 15:40:36 -0800602 Slog.v(TAG, "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING " + mWin + " in "
Robert Carre6a83512015-11-03 16:09:21 -0800603 + mSurfaceController);
Craig Mautner42d04db2014-11-06 12:13:23 -0800604 if (DEBUG_STARTING_WINDOW && startingWindow) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700605 Slog.v(TAG, "Draw state now committed in " + mWin);
606 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700607 mDrawState = COMMIT_DRAW_PENDING;
Chong Zhangcbbcc0f2016-05-17 20:46:58 -0700608 layoutNeeded = true;
Craig Mautnera608b882012-03-30 13:03:49 -0700609 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700610
Chong Zhangcbbcc0f2016-05-17 20:46:58 -0700611 return layoutNeeded;
Craig Mautnera608b882012-03-30 13:03:49 -0700612 }
613
614 // This must be called while inside a transaction.
Craig Mautnerc431e892015-02-11 13:14:26 -0800615 boolean commitFinishDrawingLocked() {
Craig Mautner6fbda632012-07-03 09:26:39 -0700616 if (DEBUG_STARTING_WINDOW &&
617 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
618 Slog.i(TAG, "commitFinishDrawingLocked: " + mWin + " cur mDrawState="
Craig Mautner276a6eb2014-11-04 15:32:57 -0800619 + drawStateToString());
Craig Mautner6fbda632012-07-03 09:26:39 -0700620 }
Craig Mautner276a6eb2014-11-04 15:32:57 -0800621 if (mDrawState != COMMIT_DRAW_PENDING && mDrawState != READY_TO_SHOW) {
Craig Mautnera608b882012-03-30 13:03:49 -0700622 return false;
623 }
Craig Mautner6fbda632012-07-03 09:26:39 -0700624 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) {
Robert Carre6a83512015-11-03 16:09:21 -0800625 Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurfaceController);
Craig Mautner6fbda632012-07-03 09:26:39 -0700626 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700627 mDrawState = READY_TO_SHOW;
Chong Zhang0275e392015-09-17 10:41:44 -0700628 boolean result = false;
Craig Mautnera608b882012-03-30 13:03:49 -0700629 final AppWindowToken atoken = mWin.mAppToken;
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800630 if (atoken == null || atoken.allDrawn || mWin.mAttrs.type == TYPE_APPLICATION_STARTING) {
Chong Zhang0275e392015-09-17 10:41:44 -0700631 result = performShowLocked();
632 }
Chong Zhang97782b42015-10-07 16:01:23 -0700633 return result;
Craig Mautnera608b882012-03-30 13:03:49 -0700634 }
635
Chong Zhang97782b42015-10-07 16:01:23 -0700636 void preserveSurfaceLocked() {
637 if (mDestroyPreservedSurfaceUponRedraw) {
Chong Zhangb9b0fec2016-02-11 18:51:51 -0800638 // This could happen when switching the surface mode very fast. For example,
639 // we preserved a surface when dragResizing changed to true. Then before the
640 // preserved surface is removed, dragResizing changed to false again.
641 // In this case, we need to leave the preserved surface alone, and destroy
642 // the actual surface, so that the createSurface call could create a surface
643 // of the proper size. The preserved surface will still be removed when client
644 // finishes drawing to the new surface.
645 mSurfaceDestroyDeferred = false;
646 destroySurfaceLocked();
647 mSurfaceDestroyDeferred = true;
Chong Zhang97782b42015-10-07 16:01:23 -0700648 return;
649 }
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -0800650 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, "SET FREEZE LAYER", false);
Wale Ogunwalef9e09782015-11-09 12:42:37 -0800651 if (mSurfaceController != null) {
652 mSurfaceController.setLayer(mAnimLayer + 1);
653 }
Chong Zhang97782b42015-10-07 16:01:23 -0700654 mDestroyPreservedSurfaceUponRedraw = true;
655 mSurfaceDestroyDeferred = true;
656 destroySurfaceLocked();
657 }
658
659 void destroyPreservedSurfaceLocked() {
660 if (!mDestroyPreservedSurfaceUponRedraw) {
661 return;
662 }
663 destroyDeferredSurfaceLocked();
664 mDestroyPreservedSurfaceUponRedraw = false;
665 }
666
Chong Zhangeb665572016-05-09 18:28:27 -0700667 void markPreservedSurfaceForDestroy() {
668 if (mDestroyPreservedSurfaceUponRedraw
669 && !mService.mDestroyPreservedSurface.contains(mWin)) {
670 mService.mDestroyPreservedSurface.add(mWin);
671 }
672 }
673
Robert Carre6a83512015-11-03 16:09:21 -0800674 WindowSurfaceController createSurfaceLocked() {
Alan Viveretteccb11e12014-07-08 16:04:02 -0700675 final WindowState w = mWin;
Chong Zhanga8975bd2016-01-28 17:13:47 -0800676 if (w.hasSavedSurface()) {
Chong Zhang0464a932016-02-03 11:47:16 -0800677 if (DEBUG_ANIM) Slog.i(TAG,
678 "createSurface: " + this + ": called when we had a saved surface");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800679 w.restoreSavedSurface();
680 return mSurfaceController;
Chong Zhanga8975bd2016-01-28 17:13:47 -0800681 }
682
Wale Ogunwale722ff892016-02-18 13:37:55 -0800683 if (mSurfaceController != null) {
684 return mSurfaceController;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700685 }
Wale Ogunwale722ff892016-02-18 13:37:55 -0800686
687 w.setHasSurface(false);
688
689 if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG,
690 "createSurface " + this + ": mDrawState=DRAW_PENDING");
691
692 mDrawState = DRAW_PENDING;
693 if (w.mAppToken != null) {
694 if (w.mAppToken.mAppAnimator.animation == null) {
Chong Zhang92147042016-05-09 12:47:11 -0700695 w.mAppToken.clearAllDrawn();
Wale Ogunwale722ff892016-02-18 13:37:55 -0800696 } else {
697 // Currently animating, persist current state of allDrawn until animation
698 // is complete.
699 w.mAppToken.deferClearAllDrawn = true;
700 }
701 }
702
703 mService.makeWindowFreezingScreenIfNeededLocked(w);
704
705 int flags = SurfaceControl.HIDDEN;
706 final WindowManager.LayoutParams attrs = w.mAttrs;
707
708 if (mService.isSecureLocked(w)) {
709 flags |= SurfaceControl.SECURE;
710 }
711
712 mTmpSize.set(w.mFrame.left + w.mXOffset, w.mFrame.top + w.mYOffset, 0, 0);
713 calculateSurfaceBounds(w, attrs);
714 final int width = mTmpSize.width();
715 final int height = mTmpSize.height();
716
717 if (DEBUG_VISIBILITY) {
718 Slog.v(TAG, "Creating surface in session "
719 + mSession.mSurfaceSession + " window " + this
720 + " w=" + width + " h=" + height
721 + " x=" + mTmpSize.left + " y=" + mTmpSize.top
722 + " format=" + attrs.format + " flags=" + flags);
723 }
724
725 // We may abort, so initialize to defaults.
726 mLastSystemDecorRect.set(0, 0, 0, 0);
727 mHasClipRect = false;
728 mClipRect.set(0, 0, 0, 0);
729 mLastClipRect.set(0, 0, 0, 0);
730
731 // Set up surface control with initial size.
732 try {
733
734 final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0;
735 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
736 if (!PixelFormat.formatHasAlpha(attrs.format)
737 // Don't make surface with surfaceInsets opaque as they display a
738 // translucent shadow.
739 && attrs.surfaceInsets.left == 0
740 && attrs.surfaceInsets.top == 0
741 && attrs.surfaceInsets.right == 0
742 && attrs.surfaceInsets.bottom == 0
743 // Don't make surface opaque when resizing to reduce the amount of
744 // artifacts shown in areas the app isn't drawing content to.
745 && !w.isDragResizing()) {
746 flags |= SurfaceControl.OPAQUE;
747 }
748
749 mSurfaceController = new WindowSurfaceController(mSession.mSurfaceSession,
750 attrs.getTitle().toString(),
751 width, height, format, flags, this);
752
753 w.setHasSurface(true);
754
755 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
756 Slog.i(TAG, " CREATE SURFACE "
757 + mSurfaceController + " IN SESSION "
758 + mSession.mSurfaceSession
759 + ": pid=" + mSession.mPid + " format="
760 + attrs.format + " flags=0x"
761 + Integer.toHexString(flags)
762 + " / " + this);
763 }
764 } catch (OutOfResourcesException e) {
765 Slog.w(TAG, "OutOfResourcesException creating surface");
766 mService.reclaimSomeSurfaceMemoryLocked(this, "create", true);
767 mDrawState = NO_SURFACE;
768 return null;
769 } catch (Exception e) {
770 Slog.e(TAG, "Exception creating surface", e);
771 mDrawState = NO_SURFACE;
772 return null;
773 }
774
775 if (WindowManagerService.localLOGV) Slog.v(TAG, "Got surface: " + mSurfaceController
776 + ", set left=" + w.mFrame.left + " top=" + w.mFrame.top
777 + ", animLayer=" + mAnimLayer);
778
779 if (SHOW_LIGHT_TRANSACTIONS) {
780 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
781 WindowManagerService.logSurface(w, "CREATE pos=("
782 + w.mFrame.left + "," + w.mFrame.top + ") ("
783 + width + "x" + height + "), layer=" + mAnimLayer + " HIDE", false);
784 }
785
786 // Start a new transaction and apply position & offset.
787 final int layerStack = w.getDisplayContent().getDisplay().getLayerStack();
Wale Ogunwale722ff892016-02-18 13:37:55 -0800788 mSurfaceController.setPositionAndLayer(mTmpSize.left, mTmpSize.top, layerStack, mAnimLayer);
789 mLastHidden = true;
790
791 if (WindowManagerService.localLOGV) Slog.v(TAG, "Created surface " + this);
Robert Carre6a83512015-11-03 16:09:21 -0800792 return mSurfaceController;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700793 }
794
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800795 private void calculateSurfaceBounds(WindowState w, LayoutParams attrs) {
796 if ((attrs.flags & FLAG_SCALED) != 0) {
797 // For a scaled surface, we always want the requested size.
798 mTmpSize.right = mTmpSize.left + w.mRequestedWidth;
799 mTmpSize.bottom = mTmpSize.top + w.mRequestedHeight;
800 } else {
801 // When we're doing a drag-resizing, request a surface that's fullscreen size,
802 // so that we don't need to reallocate during the process. This also prevents
803 // buffer drops due to size mismatch.
804 if (w.isDragResizing()) {
805 if (w.getResizeMode() == DRAG_RESIZE_MODE_FREEFORM) {
806 mTmpSize.left = 0;
807 mTmpSize.top = 0;
808 }
809 final DisplayInfo displayInfo = w.getDisplayInfo();
810 mTmpSize.right = mTmpSize.left + displayInfo.logicalWidth;
811 mTmpSize.bottom = mTmpSize.top + displayInfo.logicalHeight;
812 } else {
813 mTmpSize.right = mTmpSize.left + w.mCompatFrame.width();
814 mTmpSize.bottom = mTmpSize.top + w.mCompatFrame.height();
815 }
816 }
817
818 // Something is wrong and SurfaceFlinger will not like this, try to revert to sane values.
Filip Gruszczynskie6ed1952015-12-21 09:34:16 -0800819 // This doesn't necessarily mean that there is an error in the system. The sizes might be
820 // incorrect, because it is before the first layout or draw.
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800821 if (mTmpSize.width() < 1) {
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800822 mTmpSize.right = mTmpSize.left + 1;
823 }
824 if (mTmpSize.height() < 1) {
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800825 mTmpSize.bottom = mTmpSize.top + 1;
826 }
827
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800828 // Adjust for surface insets.
Phil Weavera4b32b92016-06-02 13:55:39 -0700829 mTmpSize.left -= attrs.surfaceInsets.left;
830 mTmpSize.top -= attrs.surfaceInsets.top;
831 mTmpSize.right += attrs.surfaceInsets.right;
832 mTmpSize.bottom += attrs.surfaceInsets.bottom;
Filip Gruszczynski69cbc352015-11-11 13:46:04 -0800833 }
834
Chong Zhangeb22e8e2016-01-20 19:52:22 -0800835 boolean hasSurface() {
Chong Zhang92147042016-05-09 12:47:11 -0700836 return !mWin.hasSavedSurface()
Chong Zhangeb22e8e2016-01-20 19:52:22 -0800837 && mSurfaceController != null && mSurfaceController.hasSurface();
838 }
839
Craig Mautner96868332012-12-04 14:29:11 -0800840 void destroySurfaceLocked() {
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700841 final AppWindowToken wtoken = mWin.mAppToken;
842 if (wtoken != null) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -0700843 if (mWin == wtoken.startingWindow) {
844 wtoken.startingDisplayed = false;
845 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700846 }
847
Chong Zhang92147042016-05-09 12:47:11 -0700848 mWin.clearHasSavedSurface();
Robert Carr13f7be9e2015-12-02 18:39:45 -0800849
Wale Ogunwale722ff892016-02-18 13:37:55 -0800850 if (mSurfaceController == null) {
851 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700852 }
Wale Ogunwale722ff892016-02-18 13:37:55 -0800853
854 int i = mWin.mChildWindows.size();
855 // When destroying a surface we want to make sure child windows are hidden. If we are
856 // preserving the surface until redraw though we intend to swap it out with another surface
857 // for resizing. In this case the window always remains visible to the user and the child
858 // windows should likewise remain visible.
859 while (!mDestroyPreservedSurfaceUponRedraw && i > 0) {
860 i--;
861 WindowState c = mWin.mChildWindows.get(i);
862 c.mAttachedHidden = true;
863 }
864
865 try {
866 if (DEBUG_VISIBILITY) logWithStack(TAG, "Window " + this + " destroying surface "
867 + mSurfaceController + ", session " + mSession);
868 if (mSurfaceDestroyDeferred) {
869 if (mSurfaceController != null && mPendingDestroySurface != mSurfaceController) {
870 if (mPendingDestroySurface != null) {
871 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
872 WindowManagerService.logSurface(mWin, "DESTROY PENDING", true);
873 }
874 mPendingDestroySurface.destroyInTransaction();
875 }
876 mPendingDestroySurface = mSurfaceController;
877 }
878 } else {
879 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
880 WindowManagerService.logSurface(mWin, "DESTROY", true);
881 }
882 destroySurface();
883 }
884 // Don't hide wallpaper if we're deferring the surface destroy
885 // because of a surface change.
886 if (!mDestroyPreservedSurfaceUponRedraw) {
887 mWallpaperControllerLocked.hideWallpapers(mWin);
888 }
889 } catch (RuntimeException e) {
890 Slog.w(TAG, "Exception thrown when destroying Window " + this
891 + " surface " + mSurfaceController + " session " + mSession + ": " + e.toString());
892 }
893
894 // Whether the surface was preserved (and copied to mPendingDestroySurface) or not, it
895 // needs to be cleared to match the WindowState.mHasSurface state. It is also necessary
896 // so it can be recreated successfully in mPendingDestroySurface case.
897 mWin.setHasSurface(false);
898 if (mSurfaceController != null) {
899 mSurfaceController.setShown(false);
900 }
901 mSurfaceController = null;
902 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700903 }
904
Craig Mautner96868332012-12-04 14:29:11 -0800905 void destroyDeferredSurfaceLocked() {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700906 try {
907 if (mPendingDestroySurface != null) {
908 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -0800909 WindowManagerService.logSurface(mWin, "DESTROY PENDING", true);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700910 }
Robert Carre6a83512015-11-03 16:09:21 -0800911 mPendingDestroySurface.destroyInTransaction();
Chong Zhang6e21cf42015-11-09 14:41:42 -0800912 // Don't hide wallpaper if we're destroying a deferred surface
913 // after a surface mode change.
914 if (!mDestroyPreservedSurfaceUponRedraw) {
915 mWallpaperControllerLocked.hideWallpapers(mWin);
916 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700917 }
918 } catch (RuntimeException e) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700919 Slog.w(TAG, "Exception thrown when destroying Window "
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700920 + this + " surface " + mPendingDestroySurface
921 + " session " + mSession + ": " + e.toString());
922 }
923 mSurfaceDestroyDeferred = false;
924 mPendingDestroySurface = null;
925 }
926
Robert Carr298f9272016-08-09 13:08:01 -0700927 void applyMagnificationSpec(MagnificationSpec spec, Matrix transform) {
928 final int surfaceInsetLeft = mWin.mAttrs.surfaceInsets.left;
929 final int surfaceInsetTop = mWin.mAttrs.surfaceInsets.top;
930
931 if (spec != null && !spec.isNop()) {
932 float scale = spec.scale;
933 transform.postScale(scale, scale);
934 transform.postTranslate(spec.offsetX, spec.offsetY);
935
936 // As we are scaling the whole surface, to keep the content
937 // in the same position we will also have to scale the surfaceInsets.
938 transform.postTranslate(-(surfaceInsetLeft*scale - surfaceInsetLeft),
939 -(surfaceInsetTop*scale - surfaceInsetTop));
940 }
941 }
942
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700943 void computeShownFrameLocked() {
944 final boolean selfTransformation = mHasLocalTransformation;
945 Transformation attachedTransformation =
Craig Mautner322e4032012-07-13 13:35:20 -0700946 (mAttachedWinAnimator != null && mAttachedWinAnimator.mHasLocalTransformation)
947 ? mAttachedWinAnimator.mTransformation : null;
948 Transformation appTransformation = (mAppAnimator != null && mAppAnimator.hasTransformation)
949 ? mAppAnimator.transformation : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700950
951 // Wallpapers are animated based on the "real" window they
952 // are currently targeting.
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700953 final WindowState wallpaperTarget = mWallpaperControllerLocked.getWallpaperTarget();
Craig Mautner798adef2013-10-22 14:29:01 -0700954 if (mIsWallpaper && wallpaperTarget != null && mService.mAnimateWallpaperWithTarget) {
955 final WindowStateAnimator wallpaperAnimator = wallpaperTarget.mWinAnimator;
Craig Mautner918b53b2012-07-09 14:15:54 -0700956 if (wallpaperAnimator.mHasLocalTransformation &&
957 wallpaperAnimator.mAnimation != null &&
958 !wallpaperAnimator.mAnimation.getDetachWallpaper()) {
959 attachedTransformation = wallpaperAnimator.mTransformation;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800960 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700961 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
962 }
963 }
Craig Mautner798adef2013-10-22 14:29:01 -0700964 final AppWindowAnimator wpAppAnimator = wallpaperTarget.mAppToken == null ?
965 null : wallpaperTarget.mAppToken.mAppAnimator;
966 if (wpAppAnimator != null && wpAppAnimator.hasTransformation
Craig Mautner918b53b2012-07-09 14:15:54 -0700967 && wpAppAnimator.animation != null
968 && !wpAppAnimator.animation.getDetachWallpaper()) {
Craig Mautner59431632012-04-04 11:56:44 -0700969 appTransformation = wpAppAnimator.transformation;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800970 if (DEBUG_WALLPAPER && appTransformation != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700971 Slog.v(TAG, "WP target app xform: " + appTransformation);
972 }
973 }
974 }
975
Craig Mautnera91f9e22012-09-14 16:22:08 -0700976 final int displayId = mWin.getDisplayId();
977 final ScreenRotationAnimation screenRotationAnimation =
978 mAnimator.getScreenRotationAnimationLocked(displayId);
979 final boolean screenAnimation =
980 screenRotationAnimation != null && screenRotationAnimation.isAnimating();
Robert Carr2f0fe622015-09-25 14:56:38 -0700981
982 mHasClipRect = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700983 if (selfTransformation || attachedTransformation != null
984 || appTransformation != null || screenAnimation) {
985 // cache often used attributes locally
986 final Rect frame = mWin.mFrame;
987 final float tmpFloats[] = mService.mTmpFloats;
988 final Matrix tmpMatrix = mWin.mTmpMatrix;
989
990 // Compute the desired transformation.
Dianne Hackborn4b169692012-11-29 17:51:24 -0800991 if (screenAnimation && screenRotationAnimation.isRotating()) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700992 // If we are doing a screen animation, the global rotation
993 // applied to windows can result in windows that are carefully
994 // aligned with each other to slightly separate, allowing you
995 // to see what is behind them. An unsightly mess. This...
996 // thing... magically makes it call good: scale each window
997 // slightly (two pixels larger in each dimension, from the
998 // window's center).
999 final float w = frame.width();
1000 final float h = frame.height();
1001 if (w>=1 && h>=1) {
1002 tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2);
1003 } else {
1004 tmpMatrix.reset();
1005 }
1006 } else {
1007 tmpMatrix.reset();
1008 }
1009 tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale);
1010 if (selfTransformation) {
1011 tmpMatrix.postConcat(mTransformation.getMatrix());
1012 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001013 if (attachedTransformation != null) {
1014 tmpMatrix.postConcat(attachedTransformation.getMatrix());
1015 }
Qiushi.Han867210c2016-10-14 11:11:14 +08001016 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001017 if (appTransformation != null) {
1018 tmpMatrix.postConcat(appTransformation.getMatrix());
1019 }
1020 if (screenAnimation) {
Craig Mautnera91f9e22012-09-14 16:22:08 -07001021 tmpMatrix.postConcat(screenRotationAnimation.getEnterTransformation().getMatrix());
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001022 }
Winson Chung399f6202014-03-19 10:47:20 -07001023
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001024 //TODO (multidisplay): Magnification is supported only for the default display.
Filip Gruszczynski69cbc352015-11-11 13:46:04 -08001025 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
Svetoslav8e3feb12014-02-24 13:46:47 -08001026 MagnificationSpec spec = mService.mAccessibilityController
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001027 .getMagnificationSpecForWindowLocked(mWin);
Robert Carr298f9272016-08-09 13:08:01 -07001028 applyMagnificationSpec(spec, tmpMatrix);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001029 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001030
1031 // "convert" it into SurfaceFlinger's format
1032 // (a 2x2 matrix + an offset)
1033 // Here we must not transform the position of the surface
1034 // since it is already included in the transformation.
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001035 //Slog.i(TAG_WM, "Transform: " + matrix);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001036
1037 mHaveMatrix = true;
1038 tmpMatrix.getValues(tmpFloats);
1039 mDsDx = tmpFloats[Matrix.MSCALE_X];
1040 mDtDx = tmpFloats[Matrix.MSKEW_Y];
1041 mDsDy = tmpFloats[Matrix.MSKEW_X];
1042 mDtDy = tmpFloats[Matrix.MSCALE_Y];
1043 float x = tmpFloats[Matrix.MTRANS_X];
1044 float y = tmpFloats[Matrix.MTRANS_Y];
Qiushi Han32fed962016-10-01 17:06:49 +08001045 mWin.mShownPosition.set(Math.round(x), Math.round(y));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001046
1047 // Now set the alpha... but because our current hardware
1048 // can't do alpha transformation on a non-opaque surface,
1049 // turn it off if we are running an animation that is also
1050 // transforming since it is more important to have that
1051 // animation be smooth.
1052 mShownAlpha = mAlpha;
1053 if (!mService.mLimitedAlphaCompositing
1054 || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format)
1055 || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
1056 && x == frame.left && y == frame.top))) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001057 //Slog.i(TAG_WM, "Applying alpha transform");
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001058 if (selfTransformation) {
1059 mShownAlpha *= mTransformation.getAlpha();
1060 }
1061 if (attachedTransformation != null) {
1062 mShownAlpha *= attachedTransformation.getAlpha();
1063 }
1064 if (appTransformation != null) {
1065 mShownAlpha *= appTransformation.getAlpha();
Winson Chung399f6202014-03-19 10:47:20 -07001066 if (appTransformation.hasClipRect()) {
1067 mClipRect.set(appTransformation.getClipRect());
1068 mHasClipRect = true;
Robert Carrf3b72c72016-03-21 18:16:39 -07001069 // The app transformation clip will be in the coordinate space of the main
1070 // activity window, which the animation correctly assumes will be placed at
1071 // (0,0)+(insets) relative to the containing frame. This isn't necessarily
1072 // true for child windows though which can have an arbitrary frame position
1073 // relative to their containing frame. We need to offset the difference
1074 // between the containing frame as used to calculate the crop and our
1075 // bounds to compensate for this.
Wale Ogunwale246c2092016-04-07 14:12:44 -07001076 if (mWin.layoutInParentFrame()) {
Robert Carrf3b72c72016-03-21 18:16:39 -07001077 mClipRect.offset( (mWin.mContainingFrame.left - mWin.mFrame.left),
1078 mWin.mContainingFrame.top - mWin.mFrame.top );
1079 }
Winson Chung399f6202014-03-19 10:47:20 -07001080 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001081 }
1082 if (screenAnimation) {
Craig Mautnera91f9e22012-09-14 16:22:08 -07001083 mShownAlpha *= screenRotationAnimation.getEnterTransformation().getAlpha();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001084 }
1085 } else {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001086 //Slog.i(TAG_WM, "Not applying alpha transform");
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001087 }
1088
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001089 if ((DEBUG_SURFACE_TRACE || WindowManagerService.localLOGV)
Craig Mautnera91f9e22012-09-14 16:22:08 -07001090 && (mShownAlpha == 1.0 || mShownAlpha == 0.0)) Slog.v(
1091 TAG, "computeShownFrameLocked: Animating " + this + " mAlpha=" + mAlpha
1092 + " self=" + (selfTransformation ? mTransformation.getAlpha() : "null")
1093 + " attached=" + (attachedTransformation == null ?
1094 "null" : attachedTransformation.getAlpha())
1095 + " app=" + (appTransformation == null ? "null" : appTransformation.getAlpha())
1096 + " screen=" + (screenAnimation ?
1097 screenRotationAnimation.getEnterTransformation().getAlpha() : "null"));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001098 return;
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001099 } else if (mIsWallpaper && mService.mWindowPlacerLocked.mWallpaperActionPending) {
Craig Mautner4d7349b2012-04-20 14:52:47 -07001100 return;
Chong Zhang3005e752015-09-18 18:46:28 -07001101 } else if (mWin.isDragResizeChanged()) {
1102 // This window is awaiting a relayout because user just started (or ended)
1103 // drag-resizing. The shown frame (which affects surface size and pos)
1104 // should not be updated until we get next finished draw with the new surface.
1105 // Otherwise one or two frames rendered with old settings would be displayed
1106 // with new geometry.
1107 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001108 }
1109
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001110 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautner4d7349b2012-04-20 14:52:47 -07001111 TAG, "computeShownFrameLocked: " + this +
1112 " not attached, mAlpha=" + mAlpha);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001113
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001114 MagnificationSpec spec = null;
1115 //TODO (multidisplay): Magnification is supported only for the default display.
Filip Gruszczynski69cbc352015-11-11 13:46:04 -08001116 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
Svetoslav8e3feb12014-02-24 13:46:47 -08001117 spec = mService.mAccessibilityController.getMagnificationSpecForWindowLocked(mWin);
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001118 }
Craig Mautner165be0c2015-01-27 15:16:58 -08001119 if (spec != null) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001120 final Rect frame = mWin.mFrame;
1121 final float tmpFloats[] = mService.mTmpFloats;
1122 final Matrix tmpMatrix = mWin.mTmpMatrix;
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001123
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001124 tmpMatrix.setScale(mWin.mGlobalScale, mWin.mGlobalScale);
1125 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001126
Robert Carr298f9272016-08-09 13:08:01 -07001127 applyMagnificationSpec(spec, tmpMatrix);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001128
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001129 tmpMatrix.getValues(tmpFloats);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001130
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001131 mHaveMatrix = true;
1132 mDsDx = tmpFloats[Matrix.MSCALE_X];
1133 mDtDx = tmpFloats[Matrix.MSKEW_Y];
1134 mDsDy = tmpFloats[Matrix.MSKEW_X];
1135 mDtDy = tmpFloats[Matrix.MSCALE_Y];
1136 float x = tmpFloats[Matrix.MTRANS_X];
1137 float y = tmpFloats[Matrix.MTRANS_Y];
Qiushi Han32fed962016-10-01 17:06:49 +08001138 mWin.mShownPosition.set(Math.round(x), Math.round(y));
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001139
1140 mShownAlpha = mAlpha;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001141 } else {
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001142 mWin.mShownPosition.set(mWin.mFrame.left, mWin.mFrame.top);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001143 if (mWin.mXOffset != 0 || mWin.mYOffset != 0) {
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001144 mWin.mShownPosition.offset(mWin.mXOffset, mWin.mYOffset);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001145 }
1146 mShownAlpha = mAlpha;
1147 mHaveMatrix = false;
1148 mDsDx = mWin.mGlobalScale;
1149 mDtDx = 0;
1150 mDsDy = 0;
1151 mDtDy = mWin.mGlobalScale;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001152 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001153 }
1154
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001155 private void calculateSystemDecorRect() {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001156 final WindowState w = mWin;
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001157 final Rect decorRect = w.mDecorFrame;
Alan Viverette49a22e82014-07-12 20:01:27 -07001158 final int width = w.mFrame.width();
1159 final int height = w.mFrame.height();
Alan Viveretteccb11e12014-07-08 16:04:02 -07001160
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001161 // Compute the offset of the window in relation to the decor rect.
Alan Viverette49a22e82014-07-12 20:01:27 -07001162 final int left = w.mXOffset + w.mFrame.left;
1163 final int top = w.mYOffset + w.mFrame.top;
Alan Viveretteccb11e12014-07-08 16:04:02 -07001164
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001165 // Initialize the decor rect to the entire frame.
Robert Carr2487ce72016-04-07 15:18:45 -07001166 if (w.isDockedResizing() ||
1167 (w.isChildWindow() && w.mAttachedWindow.isDockedResizing())) {
Jorim Jaggidc249c42015-12-15 14:57:31 -08001168
1169 // If we are resizing with the divider, the task bounds might be smaller than the
1170 // stack bounds. The system decor is used to clip to the task bounds, which we don't
1171 // want in this case in order to avoid holes.
Robert Carr2487ce72016-04-07 15:18:45 -07001172 //
1173 // We take care to not shrink the width, for surfaces which are larger than
1174 // the display region. Of course this area will not eventually be visible
1175 // but if we truncate the width now, we will calculate incorrectly
1176 // when adjusting to the stack bounds.
Jorim Jaggidc249c42015-12-15 14:57:31 -08001177 final DisplayInfo displayInfo = w.getDisplayContent().getDisplayInfo();
Robert Carr2487ce72016-04-07 15:18:45 -07001178 mSystemDecorRect.set(0, 0,
1179 Math.max(width, displayInfo.logicalWidth),
1180 Math.max(height, displayInfo.logicalHeight));
Jorim Jaggidc249c42015-12-15 14:57:31 -08001181 } else {
1182 mSystemDecorRect.set(0, 0, width, height);
1183 }
Alan Viveretteccb11e12014-07-08 16:04:02 -07001184
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001185 // If a freeform window is animating from a position where it would be cutoff, it would be
1186 // cutoff during the animation. We don't want that, so for the duration of the animation
1187 // we ignore the decor cropping and depend on layering to position windows correctly.
1188 final boolean cropToDecor = !(w.inFreeformWorkspace() && w.isAnimatingLw());
1189 if (cropToDecor) {
1190 // Intersect with the decor rect, offsetted by window position.
1191 mSystemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
1192 decorRect.right - left, decorRect.bottom - top);
1193 }
Alan Viveretteccb11e12014-07-08 16:04:02 -07001194
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001195 // If size compatibility is being applied to the window, the
1196 // surface is scaled relative to the screen. Also apply this
1197 // scaling to the crop rect. We aren't using the standard rect
1198 // scale function because we want to round things to make the crop
1199 // always round to a larger rect to ensure we don't crop too
1200 // much and hide part of the window that should be seen.
1201 if (w.mEnforceSizeCompat && w.mInvGlobalScale != 1.0f) {
1202 final float scale = w.mInvGlobalScale;
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001203 mSystemDecorRect.left = (int) (mSystemDecorRect.left * scale - 0.5f);
1204 mSystemDecorRect.top = (int) (mSystemDecorRect.top * scale - 0.5f);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001205 mSystemDecorRect.right = (int) ((mSystemDecorRect.right + 1) * scale - 0.5f);
1206 mSystemDecorRect.bottom = (int) ((mSystemDecorRect.bottom + 1) * scale - 0.5f);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001207 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001208 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001209
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001210 void calculateSurfaceWindowCrop(Rect clipRect, Rect finalClipRect) {
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001211 final WindowState w = mWin;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001212 final DisplayContent displayContent = w.getDisplayContent();
1213 if (displayContent == null) {
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001214 clipRect.setEmpty();
1215 finalClipRect.setEmpty();
1216 return;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001217 }
Wale Ogunwaleb3eba812015-07-30 20:20:16 -07001218 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001219 if (DEBUG_WINDOW_CROP) Slog.d(TAG,
1220 "Updating crop win=" + w + " mLastCrop=" + mLastClipRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001221
1222 // Need to recompute a new system decor rect each time.
Robert Carr58f29132015-10-29 14:19:05 -07001223 if (!w.isDefaultDisplay()) {
Jeff Brown28e0b092012-09-25 11:31:28 -07001224 // On a different display there is no system decor. Crop the window
1225 // by the screen boundaries.
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001226 mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height());
1227 mSystemDecorRect.intersect(-w.mCompatFrame.left, -w.mCompatFrame.top,
Jeff Brown28e0b092012-09-25 11:31:28 -07001228 displayInfo.logicalWidth - w.mCompatFrame.left,
1229 displayInfo.logicalHeight - w.mCompatFrame.top);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001230 } else if (w.mLayer >= mService.mSystemDecorLayer) {
1231 // Above the decor layer is easy, just use the entire window.
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001232 mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height());
Craig Mautner165be0c2015-01-27 15:16:58 -08001233 } else if (w.mDecorFrame.isEmpty()) {
1234 // Windows without policy decor aren't cropped.
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001235 mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height());
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001236 } else if (w.mAttrs.type == LayoutParams.TYPE_WALLPAPER && mAnimator.isAnimating()) {
Adrian Roosd47ad032014-08-15 23:17:05 +02001237 // If we're animating, the wallpaper crop should only be updated at the end of the
1238 // animation.
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001239 mTmpClipRect.set(mSystemDecorRect);
1240 calculateSystemDecorRect();
1241 mSystemDecorRect.union(mTmpClipRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001242 } else {
John Spurlock46646232013-09-30 22:32:42 -04001243 // Crop to the system decor specified by policy.
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001244 calculateSystemDecorRect();
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001245 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "Applying decor to crop win=" + w + " mDecorFrame="
1246 + w.mDecorFrame + " mSystemDecorRect=" + mSystemDecorRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001247 }
1248
Chong Zhang0abb20f2015-11-19 14:17:31 -08001249 final boolean fullscreen = w.isFrameFullscreen(displayInfo);
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001250 final boolean isFreeformResizing =
Jorim Jaggidcf467c2015-11-05 13:59:32 +01001251 w.isDragResizing() && w.getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
Robert Carr51a1b872015-12-08 14:03:13 -08001252
1253 // We use the clip rect as provided by the tranformation for non-fullscreen windows to
1254 // avoid premature clipping with the system decor rect.
1255 clipRect.set((mHasClipRect && !fullscreen) ? mClipRect : mSystemDecorRect);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001256 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "win=" + w + " Initial clip rect: " + clipRect
1257 + " mHasClipRect=" + mHasClipRect + " fullscreen=" + fullscreen);
Robert Carr51a1b872015-12-08 14:03:13 -08001258
1259 if (isFreeformResizing && !w.isChildWindow()) {
1260 // For freeform resizing non child windows, we are using the big surface positioned
1261 // at 0,0. Thus we must express the crop in that coordinate space.
1262 clipRect.offset(w.mShownPosition.x, w.mShownPosition.y);
Chong Zhang09b21ef2015-09-14 10:20:21 -07001263 }
Robert Carr51a1b872015-12-08 14:03:13 -08001264
Alan Viverette49a22e82014-07-12 20:01:27 -07001265 // Expand the clip rect for surface insets.
1266 final WindowManager.LayoutParams attrs = w.mAttrs;
1267 clipRect.left -= attrs.surfaceInsets.left;
1268 clipRect.top -= attrs.surfaceInsets.top;
1269 clipRect.right += attrs.surfaceInsets.right;
1270 clipRect.bottom += attrs.surfaceInsets.bottom;
1271
Wale Ogunwaleb3eba812015-07-30 20:20:16 -07001272 if (mHasClipRect && fullscreen) {
1273 // We intersect the clip rect specified by the transformation with the expanded system
1274 // decor rect to prevent artifacts from drawing during animation if the transformation
1275 // clip rect extends outside the system decor rect.
1276 clipRect.intersect(mClipRect);
1277 }
Alan Viverette49a22e82014-07-12 20:01:27 -07001278 // The clip rect was generated assuming (0,0) as the window origin,
1279 // so we need to translate to match the actual surface coordinates.
1280 clipRect.offset(attrs.surfaceInsets.left, attrs.surfaceInsets.top);
Robert Carr58f29132015-10-29 14:19:05 -07001281
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001282 finalClipRect.setEmpty();
1283 adjustCropToStackBounds(w, clipRect, finalClipRect, isFreeformResizing);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001284 if (DEBUG_WINDOW_CROP) Slog.d(TAG,
1285 "win=" + w + " Clip rect after stack adjustment=" + clipRect);
Robert Carr58f29132015-10-29 14:19:05 -07001286
Chia-I Wue6bcaf12016-05-27 10:58:48 +08001287 w.transformClipRectFromScreenToSurfaceSpace(clipRect);
Robert Carr58f29132015-10-29 14:19:05 -07001288
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08001289 // See {@link WindowState#notifyMovedInStack} for why this is necessary.
1290 if (w.hasJustMovedInStack() && mLastClipRect.isEmpty() && !clipRect.isEmpty()) {
1291 clipRect.setEmpty();
1292 }
Robert Carr0d00c2e2016-02-29 17:45:02 -08001293 }
1294
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001295 void updateSurfaceWindowCrop(Rect clipRect, Rect finalClipRect, boolean recoveringMemory) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001296 if (DEBUG_WINDOW_CROP) Slog.d(TAG, "updateSurfaceWindowCrop: win=" + mWin
1297 + " clipRect=" + clipRect + " finalClipRect=" + finalClipRect);
Robert Carr4320d332016-06-10 15:13:32 -07001298 if (clipRect != null) {
1299 if (!clipRect.equals(mLastClipRect)) {
1300 mLastClipRect.set(clipRect);
1301 mSurfaceController.setCropInTransaction(clipRect, recoveringMemory);
1302 }
1303 } else {
1304 mSurfaceController.clearCropInTransaction(recoveringMemory);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001305 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001306 if (!finalClipRect.equals(mLastFinalClipRect)) {
1307 mLastFinalClipRect.set(finalClipRect);
1308 mSurfaceController.setFinalCropInTransaction(finalClipRect);
Chong Zhangcc3eccf2016-05-16 18:25:45 -07001309 if (mDestroyPreservedSurfaceUponRedraw && mPendingDestroySurface != null) {
1310 mPendingDestroySurface.setFinalCropInTransaction(finalClipRect);
1311 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001312 }
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001313 }
1314
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001315 private int resolveStackClip() {
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001316 // App animation overrides window animation stack clip mode.
1317 if (mAppAnimator != null && mAppAnimator.animation != null) {
1318 return mAppAnimator.getStackClip();
1319 } else {
1320 return mStackClip;
1321 }
1322 }
1323 private void adjustCropToStackBounds(WindowState w, Rect clipRect, Rect finalClipRect,
1324 boolean isFreeformResizing) {
Wale Ogunwale4c5aa5172016-04-19 11:29:05 -07001325
1326 final DisplayContent displayContent = w.getDisplayContent();
1327 if (displayContent != null && !displayContent.isDefaultDisplay) {
1328 // There are some windows that live on other displays while their app and main window
1329 // live on the default display (e.g. casting...). We don't want to crop this windows
1330 // to the stack bounds which is only currently supported on the default display.
1331 // TODO(multi-display): Need to support cropping to stack bounds on other displays
1332 // when we have stacks on other displays.
1333 return;
1334 }
1335
Chong Zhang112eb8c2015-11-02 11:17:00 -08001336 final Task task = w.getTask();
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001337 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001338 return;
Filip Gruszczynski4b8eea72015-09-14 18:16:19 -07001339 }
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001340
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001341 final int stackClip = resolveStackClip();
1342
1343 // It's animating and we don't want to clip it to stack bounds during animation - abort.
Jorim Jaggi5c80c412016-04-19 20:03:47 -07001344 if (isAnimationSet() && stackClip == STACK_CLIP_NONE) {
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001345 return;
1346 }
1347
Chong Zhangbcb8d822016-02-26 16:21:02 -08001348 final WindowState winShowWhenLocked = (WindowState) mPolicy.getWinShowWhenLockedLw();
Jorim Jaggid7f6e7c2016-04-11 19:04:24 -07001349 if (w == winShowWhenLocked && mPolicy.isKeyguardShowingOrOccluded()) {
Chong Zhangbcb8d822016-02-26 16:21:02 -08001350 return;
1351 }
1352
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001353 final TaskStack stack = task.mStack;
1354 stack.getDimBounds(mTmpStackBounds);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001355 final Rect surfaceInsets = w.getAttrs().surfaceInsets;
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001356 // When we resize we use the big surface approach, which means we can't trust the
1357 // window frame bounds anymore. Instead, the window will be placed at 0, 0, but to avoid
1358 // hardcoding it, we use surface coordinates.
1359 final int frameX = isFreeformResizing ? (int) mSurfaceController.getX() :
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001360 w.mFrame.left + mWin.mXOffset - surfaceInsets.left;
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001361 final int frameY = isFreeformResizing ? (int) mSurfaceController.getY() :
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001362 w.mFrame.top + mWin.mYOffset - surfaceInsets.top;
Robert Carr0d00c2e2016-02-29 17:45:02 -08001363
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001364 // If we are animating, we either apply the clip before applying all the animation
1365 // transformation or after all the transformation.
Chong Zhangcc3eccf2016-05-16 18:25:45 -07001366 final boolean useFinalClipRect = isAnimationSet() && stackClip == STACK_CLIP_AFTER_ANIM
1367 || mDestroyPreservedSurfaceUponRedraw;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001368
Wale Ogunwale69cf50f2015-11-13 11:08:36 -08001369 // We need to do some acrobatics with surface position, because their clip region is
1370 // relative to the inside of the surface, but the stack bounds aren't.
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001371 if (useFinalClipRect) {
1372 finalClipRect.set(mTmpStackBounds);
1373 } else {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001374 if (StackId.hasWindowShadow(stack.mStackId)
1375 && !StackId.isTaskResizeAllowed(stack.mStackId)) {
1376 // The windows in this stack display drop shadows and the fill the entire stack
1377 // area. Adjust the stack bounds we will use to cropping take into account the
1378 // offsets we use to display the drop shadow so it doesn't get cropped.
1379 mTmpStackBounds.inset(-surfaceInsets.left, -surfaceInsets.top,
1380 -surfaceInsets.right, -surfaceInsets.bottom);
1381 }
1382
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001383 clipRect.left = Math.max(0,
1384 Math.max(mTmpStackBounds.left, frameX + clipRect.left) - frameX);
1385 clipRect.top = Math.max(0,
1386 Math.max(mTmpStackBounds.top, frameY + clipRect.top) - frameY);
1387 clipRect.right = Math.max(0,
1388 Math.min(mTmpStackBounds.right, frameX + clipRect.right) - frameX);
1389 clipRect.bottom = Math.max(0,
1390 Math.min(mTmpStackBounds.bottom, frameY + clipRect.bottom) - frameY);
1391 }
Filip Gruszczynski4b8eea72015-09-14 18:16:19 -07001392 }
1393
Wale Ogunwale4c8b7952015-04-07 10:49:40 -07001394 void setSurfaceBoundariesLocked(final boolean recoveringMemory) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001395 final WindowState w = mWin;
Robert Carr0d00c2e2016-02-29 17:45:02 -08001396 final Task task = w.getTask();
Alan Viveretteccb11e12014-07-08 16:04:02 -07001397
Jorim Jaggif3df0aa2016-04-06 15:56:33 -07001398 // We got resized, so block all updates until we got the new surface.
Andrii Kulianeb1d3222016-05-16 15:17:55 -07001399 if (w.isResizedWhileNotDragResizing() && !w.isGoneForLayoutLw()) {
Jorim Jaggif3df0aa2016-04-06 15:56:33 -07001400 return;
1401 }
1402
Filip Gruszczynski69cbc352015-11-11 13:46:04 -08001403 mTmpSize.set(w.mShownPosition.x, w.mShownPosition.y, 0, 0);
1404 calculateSurfaceBounds(w, w.getAttrs());
Chong Zhang0275e392015-09-17 10:41:44 -07001405
Robert Carr04092112016-06-02 12:56:12 -07001406 mExtraHScale = (float) 1.0;
1407 mExtraVScale = (float) 1.0;
Robert Carre1034cc32016-02-01 13:08:15 -08001408
Robert Carr6da3cc02016-06-16 15:17:07 -07001409 boolean wasForceScaled = mForceScaleUntilResize;
1410 boolean wasSeamlesslyRotated = w.mSeamlesslyRotated;
1411
Robert Carrfed10072016-05-26 11:48:49 -07001412 // Once relayout has been called at least once, we need to make sure
1413 // we only resize the client surface during calls to relayout. For
1414 // clients which use indeterminate measure specs (MATCH_PARENT),
1415 // we may try and change their window size without a call to relayout.
1416 // However, this would be unsafe, as the client may be in the middle
1417 // of producing a frame at the old size, having just completed layout
1418 // to find the surface size changed underneath it.
Robert Carr3ccc5272016-06-20 22:06:32 -07001419 if (!w.mRelayoutCalled || w.mInRelayout) {
Robert Carrfed10072016-05-26 11:48:49 -07001420 mSurfaceResized = mSurfaceController.setSizeInTransaction(
1421 mTmpSize.width(), mTmpSize.height(), recoveringMemory);
1422 } else {
1423 mSurfaceResized = false;
1424 }
Robert Carrc7294602016-05-13 11:32:05 -07001425 mForceScaleUntilResize = mForceScaleUntilResize && !mSurfaceResized;
Robert Carr6da3cc02016-06-16 15:17:07 -07001426 // If we are undergoing seamless rotation, the surface has already
1427 // been set up to persist at it's old location. We need to freeze
1428 // updates until a resize occurs.
Robert Carrb14d4abc2016-10-03 18:13:33 -07001429 mService.markForSeamlessRotation(w, w.mSeamlesslyRotated && !mSurfaceResized);
Robert Carrc7294602016-05-13 11:32:05 -07001430
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001431 calculateSurfaceWindowCrop(mTmpClipRect, mTmpFinalClipRect);
Robert Carra9408d42016-06-03 13:28:48 -07001432
1433 float surfaceWidth = mSurfaceController.getWidth();
1434 float surfaceHeight = mSurfaceController.getHeight();
1435
Robert Carrc7294602016-05-13 11:32:05 -07001436 if ((task != null && task.mStack.getForceScaleToCrop()) || mForceScaleUntilResize) {
Robert Carrbc133762016-05-12 14:04:38 -07001437 int hInsets = w.getAttrs().surfaceInsets.left + w.getAttrs().surfaceInsets.right;
1438 int vInsets = w.getAttrs().surfaceInsets.top + w.getAttrs().surfaceInsets.bottom;
Robert Carra9408d42016-06-03 13:28:48 -07001439 if (!mForceScaleUntilResize) {
1440 mSurfaceController.forceScaleableInTransaction(true);
1441 }
Robert Carrbc133762016-05-12 14:04:38 -07001442 // We want to calculate the scaling based on the content area, not based on
1443 // the entire surface, so that we scale in sync with windows that don't have insets.
Robert Carr04092112016-06-02 12:56:12 -07001444 mExtraHScale = (mTmpClipRect.width() - hInsets) / (float)(surfaceWidth - hInsets);
1445 mExtraVScale = (mTmpClipRect.height() - vInsets) / (float)(surfaceHeight - vInsets);
Robert Carr0d00c2e2016-02-29 17:45:02 -08001446
1447 // In the case of ForceScaleToCrop we scale entire tasks together,
1448 // and so we need to scale our offsets relative to the task bounds
1449 // or parent and child windows would fall out of alignment.
Robert Carr04092112016-06-02 12:56:12 -07001450 int posX = (int) (mTmpSize.left - w.mAttrs.x * (1 - mExtraHScale));
1451 int posY = (int) (mTmpSize.top - w.mAttrs.y * (1 - mExtraVScale));
Robert Carrbc133762016-05-12 14:04:38 -07001452 // Imagine we are scaling down. As we scale the buffer down, we decrease the
1453 // distance between the surface top left, and the start of the surface contents
1454 // (previously it was surfaceInsets.left pixels in screen space but now it
Robert Carr04092112016-06-02 12:56:12 -07001455 // will be surfaceInsets.left*mExtraHScale). This means in order to keep the
Robert Carrbc133762016-05-12 14:04:38 -07001456 // non inset content at the same position, we have to shift the whole window
1457 // forward. Likewise for scaling up, we've increased this distance, and we need
1458 // to shift by a negative number to compensate.
Robert Carr04092112016-06-02 12:56:12 -07001459 posX += w.getAttrs().surfaceInsets.left * (1 - mExtraHScale);
1460 posY += w.getAttrs().surfaceInsets.top * (1 - mExtraVScale);
Robert Carrbc133762016-05-12 14:04:38 -07001461
Robert Carra9408d42016-06-03 13:28:48 -07001462 mSurfaceController.setPositionInTransaction((float)Math.floor(posX),
1463 (float)Math.floor(posY), recoveringMemory);
Robert Carr0d00c2e2016-02-29 17:45:02 -08001464
1465 // Since we are scaled to fit in our previously desired crop, we can now
1466 // expose the whole window in buffer space, and not risk extending
1467 // past where the system would have cropped us
Robert Carrfed10072016-05-26 11:48:49 -07001468 mTmpClipRect.set(0, 0, (int)surfaceWidth, (int)surfaceHeight);
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001469 mTmpFinalClipRect.setEmpty();
Robert Carrc7294602016-05-13 11:32:05 -07001470
1471 // Various surfaces in the scaled stack may resize at different times.
1472 // We need to ensure for each surface, that we disable transformation matrix
1473 // scaling in the same transaction which we resize the surface in.
1474 // As we are in SCALING_MODE_SCALE_TO_WINDOW, SurfaceFlinger will
Robert Carra9408d42016-06-03 13:28:48 -07001475 // then take over the scaling until the new buffer arrives, and things
Robert Carrc7294602016-05-13 11:32:05 -07001476 // will be seamless.
1477 mForceScaleUntilResize = true;
Robert Carr0d00c2e2016-02-29 17:45:02 -08001478 } else {
Robert Carr6da3cc02016-06-16 15:17:07 -07001479 if (!w.mSeamlesslyRotated) {
1480 mSurfaceController.setPositionInTransaction(mTmpSize.left, mTmpSize.top,
1481 recoveringMemory);
1482 }
Robert Carr0d00c2e2016-02-29 17:45:02 -08001483 }
1484
Robert Carra9408d42016-06-03 13:28:48 -07001485 // If we are ending the scaling mode. We switch to SCALING_MODE_FREEZE
Robert Carr6da3cc02016-06-16 15:17:07 -07001486 // to prevent further updates until buffer latch.
1487 // When ending both force scaling, and seamless rotation, we need to freeze
1488 // the Surface geometry until a buffer comes in at the new size (normally position and crop
1489 // are unfrozen). setGeometryAppliesWithResizeInTransaction accomplishes this for us.
1490 if ((wasForceScaled && !mForceScaleUntilResize) ||
1491 (wasSeamlesslyRotated && !w.mSeamlesslyRotated)) {
1492 mSurfaceController.setGeometryAppliesWithResizeInTransaction(true);
Robert Carra9408d42016-06-03 13:28:48 -07001493 mSurfaceController.forceScaleableInTransaction(false);
1494 }
Robert Carr4320d332016-06-10 15:13:32 -07001495
1496 Rect clipRect = mTmpClipRect;
Robert Carra9408d42016-06-03 13:28:48 -07001497 if (w.inPinnedWorkspace()) {
Robert Carr4320d332016-06-10 15:13:32 -07001498 clipRect = null;
Robert Carra9408d42016-06-03 13:28:48 -07001499 task.mStack.getDimBounds(mTmpFinalClipRect);
1500 mTmpFinalClipRect.inset(-w.mAttrs.surfaceInsets.left, -w.mAttrs.surfaceInsets.top,
1501 -w.mAttrs.surfaceInsets.right, -w.mAttrs.surfaceInsets.bottom);
1502 }
1503
Robert Carr6da3cc02016-06-16 15:17:07 -07001504 if (!w.mSeamlesslyRotated) {
1505 updateSurfaceWindowCrop(clipRect, mTmpFinalClipRect, recoveringMemory);
1506 mSurfaceController.setMatrixInTransaction(mDsDx * w.mHScale * mExtraHScale,
1507 mDtDx * w.mVScale * mExtraVScale,
1508 mDsDy * w.mHScale * mExtraHScale,
1509 mDtDy * w.mVScale * mExtraVScale, recoveringMemory);
1510 }
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001511
Robert Carre6a83512015-11-03 16:09:21 -08001512 if (mSurfaceResized) {
Chong Zhang5b2f1992015-11-13 15:40:36 -08001513 mReportSurfaceResized = true;
Robert Carre6a83512015-11-03 16:09:21 -08001514 mAnimator.setPendingLayoutChanges(w.getDisplayId(),
1515 WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
1516 w.applyDimLayerIfNeeded();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001517 }
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001518
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001519 }
1520
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001521 void prepareSurfaceLocked(final boolean recoveringMemory) {
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001522 final WindowState w = mWin;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001523 if (!hasSurface()) {
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001524 if (w.mOrientationChanging) {
1525 if (DEBUG_ORIENTATION) {
1526 Slog.v(TAG, "Orientation change skips hidden " + w);
1527 }
1528 w.mOrientationChanging = false;
1529 }
1530 return;
1531 }
1532
Chong Zhang70211742016-04-28 18:27:53 -07001533 // Do not change surface properties of opening apps if we are waiting for the
1534 // transition to be ready. transitionGoodToGo could be not ready even after all
1535 // opening apps are drawn. It's only waiting on isFetchingAppTransitionsSpecs()
1536 // to get the animation spec. (For example, go into Recents and immediately open
1537 // the same app again before the app's surface is destroyed or saved, the surface
1538 // is always ready in the whole process.) If we go ahead here, the opening app
1539 // will be shown with the full size before the correct animation spec arrives.
Chong Zhange22006d2016-05-09 10:59:59 -07001540 if (isWaitingForOpening()) {
Chong Zhang70211742016-04-28 18:27:53 -07001541 return;
1542 }
1543
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001544 boolean displayed = false;
1545
1546 computeShownFrameLocked();
1547
Craig Mautnera91f9e22012-09-14 16:22:08 -07001548 setSurfaceBoundariesLocked(recoveringMemory);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001549
Craig Mautner918b53b2012-07-09 14:15:54 -07001550 if (mIsWallpaper && !mWin.mWallpaperVisible) {
Craig Mautner0fa77c12012-06-11 15:57:19 -07001551 // Wallpaper is no longer visible and there is no wp target => hide it.
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001552 hide("prepareSurfaceLocked");
Craig Mautner72669d12012-12-18 17:23:54 -08001553 } else if (w.mAttachedHidden || !w.isOnScreen()) {
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001554 hide("prepareSurfaceLocked");
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001555 mWallpaperControllerLocked.hideWallpapers(w);
Craig Mautnerb9836b92012-06-11 11:40:09 -07001556
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001557 // If we are waiting for this window to handle an
1558 // orientation change, well, it is hidden, so
1559 // doesn't really matter. Note that this does
1560 // introduce a potential glitch if the window
1561 // becomes unhidden before it has drawn for the
1562 // new orientation.
1563 if (w.mOrientationChanging) {
1564 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001565 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001566 "Orientation change skips hidden " + w);
1567 }
1568 } else if (mLastLayer != mAnimLayer
1569 || mLastAlpha != mShownAlpha
1570 || mLastDsDx != mDsDx
1571 || mLastDtDx != mDtDx
1572 || mLastDsDy != mDsDy
1573 || mLastDtDy != mDtDy
1574 || w.mLastHScale != w.mHScale
1575 || w.mLastVScale != w.mVScale
Craig Mautner749a7bb2012-04-02 13:49:53 -07001576 || mLastHidden) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001577 displayed = true;
1578 mLastAlpha = mShownAlpha;
1579 mLastLayer = mAnimLayer;
1580 mLastDsDx = mDsDx;
1581 mLastDtDx = mDtDx;
1582 mLastDsDy = mDsDy;
1583 mLastDtDy = mDtDy;
1584 w.mLastHScale = w.mHScale;
1585 w.mLastVScale = w.mVScale;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001586 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
Robert Carre6a83512015-11-03 16:09:21 -08001587 "controller=" + mSurfaceController +
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001588 "alpha=" + mShownAlpha + " layer=" + mAnimLayer
Craig Mautner78505d82014-09-02 14:36:31 -07001589 + " matrix=[" + mDsDx + "*" + w.mHScale
1590 + "," + mDtDx + "*" + w.mVScale
1591 + "][" + mDsDy + "*" + w.mHScale
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -08001592 + "," + mDtDy + "*" + w.mVScale + "]", false);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001593
Robert Carre6a83512015-11-03 16:09:21 -08001594 boolean prepared =
1595 mSurfaceController.prepareToShowInTransaction(mShownAlpha, mAnimLayer,
Robert Carr04092112016-06-02 12:56:12 -07001596 mDsDx * w.mHScale * mExtraHScale,
1597 mDtDx * w.mVScale * mExtraVScale,
1598 mDsDy * w.mHScale * mExtraHScale,
1599 mDtDy * w.mVScale * mExtraVScale,
Robert Carre6a83512015-11-03 16:09:21 -08001600 recoveringMemory);
1601
1602 if (prepared && mLastHidden && mDrawState == HAS_DRAWN) {
1603 if (showSurfaceRobustlyLocked()) {
Chong Zhangeb665572016-05-09 18:28:27 -07001604 markPreservedSurfaceForDestroy();
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -08001605 mAnimator.requestRemovalOfReplacedWindows(w);
Robert Carre6a83512015-11-03 16:09:21 -08001606 mLastHidden = false;
1607 if (mIsWallpaper) {
1608 mWallpaperControllerLocked.dispatchWallpaperVisibility(w, true);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001609 }
Robert Carre6a83512015-11-03 16:09:21 -08001610 // This draw means the difference between unique content and mirroring.
1611 // Run another pass through performLayout to set mHasContent in the
1612 // LogicalDisplay.
1613 mAnimator.setPendingLayoutChanges(w.getDisplayId(),
1614 WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
1615 } else {
1616 w.mOrientationChanging = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001617 }
1618 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001619 if (hasSurface()) {
Robert Carre6a83512015-11-03 16:09:21 -08001620 w.mToken.hasVisible = true;
1621 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001622 } else {
Jorim Jaggi5c80c412016-04-19 20:03:47 -07001623 if (DEBUG_ANIM && isAnimationSet()) {
Chong Zhange05db742016-02-16 16:58:37 -08001624 Slog.v(TAG, "prepareSurface: No changes in animation for " + this);
Craig Mautner83339b42012-05-01 22:13:23 -07001625 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001626 displayed = true;
1627 }
1628
1629 if (displayed) {
1630 if (w.mOrientationChanging) {
1631 if (!w.isDrawnLw()) {
Craig Mautner2639da52012-07-09 09:39:06 -07001632 mAnimator.mBulkUpdateParams &= ~SET_ORIENTATION_CHANGE_COMPLETE;
Dianne Hackborna57c6952013-03-29 14:46:40 -07001633 mAnimator.mLastWindowFreezeSource = w;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001634 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001635 "Orientation continue waiting for draw in " + w);
1636 } else {
1637 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001638 if (DEBUG_ORIENTATION) Slog.v(TAG, "Orientation change complete in " + w);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001639 }
1640 }
1641 w.mToken.hasVisible = true;
1642 }
1643 }
1644
Craig Mautneref655012013-01-03 11:20:24 -08001645 void setTransparentRegionHintLocked(final Region region) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001646 if (mSurfaceController == null) {
1647 Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true");
1648 return;
1649 }
Robert Carre6a83512015-11-03 16:09:21 -08001650 mSurfaceController.setTransparentRegionHint(region);
Craig Mautner48ba1e72012-04-02 13:18:16 -07001651 }
1652
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001653 void setWallpaperOffset(Point shownPosition) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07001654 final LayoutParams attrs = mWin.getAttrs();
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001655 final int left = shownPosition.x - attrs.surfaceInsets.left;
1656 final int top = shownPosition.y - attrs.surfaceInsets.top;
Robert Carre6a83512015-11-03 16:09:21 -08001657
1658 try {
Craig Mautner71dd1b62014-02-18 15:48:52 -08001659 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setWallpaperOffset");
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001660 SurfaceControl.openTransaction();
Robert Carre6a83512015-11-03 16:09:21 -08001661 mSurfaceController.setPositionInTransaction(mWin.mFrame.left + left,
1662 mWin.mFrame.top + top, false);
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001663 calculateSurfaceWindowCrop(mTmpClipRect, mTmpFinalClipRect);
1664 updateSurfaceWindowCrop(mTmpClipRect, mTmpFinalClipRect, false);
Robert Carre6a83512015-11-03 16:09:21 -08001665 } catch (RuntimeException e) {
1666 Slog.w(TAG, "Error positioning surface of " + mWin
1667 + " pos=(" + left + "," + top + ")", e);
1668 } finally {
1669 SurfaceControl.closeTransaction();
1670 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1671 "<<< CLOSE TRANSACTION setWallpaperOffset");
Craig Mautner48ba1e72012-04-02 13:18:16 -07001672 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001673 }
1674
John Reck80181b92015-05-19 11:09:32 -07001675 /**
1676 * Try to change the pixel format without recreating the surface. This
1677 * will be common in the case of changing from PixelFormat.OPAQUE to
1678 * PixelFormat.TRANSLUCENT in the hardware-accelerated case as both
1679 * requested formats resolve to the same underlying SurfaceControl format
1680 * @return True if format was succesfully changed, false otherwise
1681 */
1682 boolean tryChangeFormatInPlaceLocked() {
Robert Carre6a83512015-11-03 16:09:21 -08001683 if (mSurfaceController == null) {
John Reck80181b92015-05-19 11:09:32 -07001684 return false;
1685 }
1686 final LayoutParams attrs = mWin.getAttrs();
Wale Ogunwalee7bf46b2015-09-30 09:19:28 -07001687 final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0;
John Reck80181b92015-05-19 11:09:32 -07001688 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
1689 if (format == mSurfaceFormat) {
1690 setOpaqueLocked(!PixelFormat.formatHasAlpha(attrs.format));
1691 return true;
1692 }
1693 return false;
1694 }
1695
Craig Mautner6f612042014-09-07 13:13:23 -07001696 void setOpaqueLocked(boolean isOpaque) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001697 if (mSurfaceController == null) {
1698 return;
1699 }
Robert Carre6a83512015-11-03 16:09:21 -08001700 mSurfaceController.setOpaque(isOpaque);
Craig Mautner71dd1b62014-02-18 15:48:52 -08001701 }
1702
Wale Ogunwalef5ad42f2015-06-12 13:59:03 -07001703 void setSecureLocked(boolean isSecure) {
Wale Ogunwalef9e09782015-11-09 12:42:37 -08001704 if (mSurfaceController == null) {
1705 return;
1706 }
Robert Carre6a83512015-11-03 16:09:21 -08001707 mSurfaceController.setSecure(isSecure);
Wale Ogunwalef5ad42f2015-06-12 13:59:03 -07001708 }
1709
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001710 // This must be called while inside a transaction.
1711 boolean performShowLocked() {
Craig Mautner5962b122012-10-05 14:45:52 -07001712 if (mWin.isHiddenFromUserLocked()) {
Wale Ogunwale4eef94f2015-07-17 22:29:54 -07001713 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + mWin + ", belonging to " + mWin.mOwnerUid);
1714 mWin.hideLw(false);
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001715 return false;
1716 }
Craig Mautner6fbda632012-07-03 09:26:39 -07001717 if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
1718 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001719 Slog.v(TAG, "performShow on " + this
Craig Mautnerc431e892015-02-11 13:14:26 -08001720 + ": mDrawState=" + drawStateToString() + " readyForDisplay="
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001721 + mWin.isReadyForDisplayIgnoringKeyguard()
Craig Mautner6fbda632012-07-03 09:26:39 -07001722 + " starting=" + (mWin.mAttrs.type == TYPE_APPLICATION_STARTING)
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001723 + " during animation: policyVis=" + mWin.mPolicyVisibility
1724 + " attHidden=" + mWin.mAttachedHidden
1725 + " tok.hiddenRequested="
1726 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
1727 + " tok.hidden="
1728 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
1729 + " animating=" + mAnimating
1730 + " tok animating="
Craig Mautnerc431e892015-02-11 13:14:26 -08001731 + (mAppAnimator != null ? mAppAnimator.animating : false) + " Callers="
1732 + Debug.getCallers(3));
Craig Mautner6fbda632012-07-03 09:26:39 -07001733 }
1734 if (mDrawState == READY_TO_SHOW && mWin.isReadyForDisplayIgnoringKeyguard()) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001735 if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
1736 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
1737 Slog.v(TAG, "Showing " + this
1738 + " during animation: policyVis=" + mWin.mPolicyVisibility
1739 + " attHidden=" + mWin.mAttachedHidden
1740 + " tok.hiddenRequested="
1741 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
1742 + " tok.hidden="
1743 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
1744 + " animating=" + mAnimating
1745 + " tok animating="
Craig Mautner322e4032012-07-13 13:35:20 -07001746 + (mAppAnimator != null ? mAppAnimator.animating : false));
Craig Mautner6fbda632012-07-03 09:26:39 -07001747 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001748
1749 mService.enableScreenIfNeededLocked();
1750
1751 applyEnterAnimationLocked();
1752
Craig Mautnerde6198e2012-04-19 09:59:31 -07001753 // Force the show in the next prepareSurfaceLocked() call.
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001754 mLastAlpha = -1;
Craig Mautneref25d7a2012-05-15 23:01:47 -07001755 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM)
Chong Zhang5b2f1992015-11-13 15:40:36 -08001756 Slog.v(TAG, "performShowLocked: mDrawState=HAS_DRAWN in " + mWin);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001757 mDrawState = HAS_DRAWN;
Craig Mautner96868332012-12-04 14:29:11 -08001758 mService.scheduleAnimationLocked();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001759
1760 int i = mWin.mChildWindows.size();
1761 while (i > 0) {
1762 i--;
1763 WindowState c = mWin.mChildWindows.get(i);
1764 if (c.mAttachedHidden) {
1765 c.mAttachedHidden = false;
Robert Carre6a83512015-11-03 16:09:21 -08001766 if (c.mWinAnimator.mSurfaceController != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001767 c.mWinAnimator.performShowLocked();
Filip Gruszczynski921171a2015-09-30 22:02:57 +00001768 // It hadn't been shown, which means layout not
1769 // performed on it, so now we want to make sure to
1770 // do a layout. If called from within the transaction
1771 // loop, this will cause it to restart with a new
1772 // layout.
1773 final DisplayContent displayContent = c.getDisplayContent();
1774 if (displayContent != null) {
1775 displayContent.layoutNeeded = true;
1776 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001777 }
1778 }
1779 }
1780
Filip Gruszczynskib6e66622015-10-25 16:05:27 -07001781 if (mWin.mAttrs.type != TYPE_APPLICATION_STARTING && mWin.mAppToken != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001782 mWin.mAppToken.onFirstWindowDrawn(mWin, this);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001783 }
Chong Zhangc806d902015-11-30 09:44:27 -08001784
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -07001785 if (mWin.mAttrs.type == TYPE_INPUT_METHOD) {
1786 mWin.mDisplayContent.mDividerControllerLocked.resetImeHideRequested();
1787 }
1788
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001789 return true;
1790 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001791 return false;
1792 }
1793
1794 /**
1795 * Have the surface flinger show a surface, robustly dealing with
1796 * error conditions. In particular, if there is not enough memory
1797 * to show the surface, then we will try to get rid of other surfaces
1798 * in order to succeed.
1799 *
1800 * @return Returns true if the surface was successfully shown.
1801 */
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001802 private boolean showSurfaceRobustlyLocked() {
Robert Carr1b5ea722016-04-20 13:23:28 -07001803 final Task task = mWin.getTask();
1804 if (task != null && StackId.windowsAreScaleable(task.mStack.mStackId)) {
1805 mSurfaceController.forceScaleableInTransaction(true);
1806 }
1807
Robert Carre6a83512015-11-03 16:09:21 -08001808 boolean shown = mSurfaceController.showRobustlyInTransaction();
1809 if (!shown)
1810 return false;
1811
1812 if (mWin.mTurnOnScreen) {
1813 if (DEBUG_VISIBILITY) Slog.v(TAG, "Show surface turning screen on: " + mWin);
1814 mWin.mTurnOnScreen = false;
1815 mAnimator.mBulkUpdateParams |= SET_TURN_ON_SCREEN;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001816 }
Robert Carre6a83512015-11-03 16:09:21 -08001817 return true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001818 }
1819
1820 void applyEnterAnimationLocked() {
Robert Carrb439a632016-04-07 22:52:10 -07001821 // If we are the new part of a window replacement transition and we have requested
1822 // not to animate, we instead want to make it seamless, so we don't want to apply
1823 // an enter transition.
1824 if (mWin.mSkipEnterAnimationForSeamlessReplacement) {
1825 return;
1826 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001827 final int transit;
1828 if (mEnterAnimationPending) {
1829 mEnterAnimationPending = false;
1830 transit = WindowManagerPolicy.TRANSIT_ENTER;
1831 } else {
1832 transit = WindowManagerPolicy.TRANSIT_SHOW;
1833 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001834 applyAnimationLocked(transit, true);
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001835 //TODO (multidisplay): Magnification is supported only for the default display.
Svetoslav8e3feb12014-02-24 13:46:47 -08001836 if (mService.mAccessibilityController != null
Filip Gruszczynski69cbc352015-11-11 13:46:04 -08001837 && mWin.getDisplayId() == DEFAULT_DISPLAY) {
Svetoslav8e3feb12014-02-24 13:46:47 -08001838 mService.mAccessibilityController.onWindowTransitionLocked(mWin, transit);
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -07001839 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001840 }
1841
1842 /**
1843 * Choose the correct animation and set it to the passed WindowState.
Craig Mautner4b71aa12012-12-27 17:20:01 -08001844 * @param transit If AppTransition.TRANSIT_PREVIEW_DONE and the app window has been drawn
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001845 * then the animation will be app_starting_exit. Any other value loads the animation from
1846 * the switch statement below.
1847 * @param isEntrance The animation type the last time this was called. Used to keep from
1848 * loading the same animation twice.
1849 * @return true if an animation has been loaded.
1850 */
1851 boolean applyAnimationLocked(int transit, boolean isEntrance) {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001852 if ((mLocalAnimating && mAnimationIsEntrance == isEntrance)
1853 || mKeyguardGoingAwayAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001854 // If we are trying to apply an animation, but already running
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001855 // an animation of the same type, then just leave that one alone.
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001856
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001857 // If we are in a keyguard exit animation, and the window should animate away, modify
1858 // keyguard exit animation such that it also fades out.
1859 if (mAnimation != null && mKeyguardGoingAwayAnimation
1860 && transit == WindowManagerPolicy.TRANSIT_PREVIEW_DONE) {
1861 applyFadeoutDuringKeyguardExitAnimation();
1862 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001863 return true;
1864 }
1865
1866 // Only apply an animation if the display isn't frozen. If it is
1867 // frozen, there is no reason to animate and it can cause strange
1868 // artifacts when we unfreeze the display if some different animation
1869 // is running.
Chong Zhang8784be62016-06-28 15:25:07 -07001870 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "WSA#applyAnimationLocked");
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001871 if (mService.okToDisplay()) {
1872 int anim = mPolicy.selectAnimationLw(mWin, transit);
1873 int attr = -1;
1874 Animation a = null;
1875 if (anim != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001876 a = anim != -1 ? AnimationUtils.loadAnimation(mContext, anim) : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001877 } else {
1878 switch (transit) {
1879 case WindowManagerPolicy.TRANSIT_ENTER:
1880 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
1881 break;
1882 case WindowManagerPolicy.TRANSIT_EXIT:
1883 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
1884 break;
1885 case WindowManagerPolicy.TRANSIT_SHOW:
1886 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
1887 break;
1888 case WindowManagerPolicy.TRANSIT_HIDE:
1889 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
1890 break;
1891 }
1892 if (attr >= 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001893 a = mService.mAppTransition.loadAnimationAttr(mWin.mAttrs, attr);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001894 }
1895 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001896 if (DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001897 "applyAnimation: win=" + this
1898 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
Craig Mautner4d7349b2012-04-20 14:52:47 -07001899 + " a=" + a
Craig Mautner8863cca2012-09-18 15:04:34 -07001900 + " transit=" + transit
Craig Mautner83339b42012-05-01 22:13:23 -07001901 + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001902 if (a != null) {
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -08001903 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001904 setAnimation(a);
1905 mAnimationIsEntrance = isEntrance;
1906 }
1907 } else {
1908 clearAnimation();
1909 }
Chong Zhang8784be62016-06-28 15:25:07 -07001910 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
1911
Jorim Jaggieb88d832016-04-13 20:17:43 -07001912 if (mWin.mAttrs.type == TYPE_INPUT_METHOD) {
1913 mService.adjustForImeIfNeeded(mWin.mDisplayContent);
Jorim Jaggi7a4fd5e2016-04-14 19:55:35 -07001914 if (isEntrance) {
1915 mWin.setDisplayLayoutNeeded();
1916 mService.mWindowPlacerLocked.requestTraversal();
1917 }
Jorim Jaggieb88d832016-04-13 20:17:43 -07001918 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001919 return mAnimation != null;
1920 }
1921
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001922 private void applyFadeoutDuringKeyguardExitAnimation() {
1923 long startTime = mAnimation.getStartTime();
1924 long duration = mAnimation.getDuration();
1925 long elapsed = mLastAnimationTime - startTime;
1926 long fadeDuration = duration - elapsed;
1927 if (fadeDuration <= 0) {
1928 // Never mind, this would be no visible animation, so abort the animation change.
1929 return;
1930 }
1931 AnimationSet newAnimation = new AnimationSet(false /* shareInterpolator */);
1932 newAnimation.setDuration(duration);
1933 newAnimation.setStartTime(startTime);
1934 newAnimation.addAnimation(mAnimation);
1935 Animation fadeOut = AnimationUtils.loadAnimation(
1936 mContext, com.android.internal.R.anim.app_starting_exit);
1937 fadeOut.setDuration(fadeDuration);
1938 fadeOut.setStartOffset(elapsed);
1939 newAnimation.addAnimation(fadeOut);
Filip Gruszczynskif52dd202015-11-15 20:36:38 -08001940 newAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(), mAnimDx, mAnimDy);
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001941 mAnimation = newAnimation;
1942 }
1943
Craig Mautnera2c77052012-03-26 12:14:43 -07001944 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1945 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
1946 || mAnimation != null) {
1947 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
1948 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
1949 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001950 pw.print(" mAnimation="); pw.print(mAnimation);
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001951 pw.print(" mStackClip="); pw.println(mStackClip);
Craig Mautnera2c77052012-03-26 12:14:43 -07001952 }
1953 if (mHasTransformation || mHasLocalTransformation) {
1954 pw.print(prefix); pw.print("XForm: has=");
1955 pw.print(mHasTransformation);
1956 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
1957 pw.print(" "); mTransformation.printShortString(pw);
1958 pw.println();
1959 }
Robert Carre6a83512015-11-03 16:09:21 -08001960 if (mSurfaceController != null) {
1961 mSurfaceController.dump(pw, prefix, dumpAll);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001962 }
Robert Carre6a83512015-11-03 16:09:21 -08001963 if (dumpAll) {
1964 pw.print(prefix); pw.print("mDrawState="); pw.print(drawStateToString());
1965 pw.print(prefix); pw.print(" mLastHidden="); pw.println(mLastHidden);
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001966 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
1967 pw.print(" last="); mLastSystemDecorRect.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07001968 pw.print(" mHasClipRect="); pw.print(mHasClipRect);
1969 pw.print(" mLastClipRect="); mLastClipRect.printShortString(pw);
1970
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001971 if (!mLastFinalClipRect.isEmpty()) {
1972 pw.print(" mLastFinalClipRect="); mLastFinalClipRect.printShortString(pw);
1973 }
Filip Gruszczynskif34a04c2015-12-07 15:05:49 -08001974 pw.println();
Robert Carre6a83512015-11-03 16:09:21 -08001975 }
1976
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001977 if (mPendingDestroySurface != null) {
1978 pw.print(prefix); pw.print("mPendingDestroySurface=");
1979 pw.println(mPendingDestroySurface);
1980 }
1981 if (mSurfaceResized || mSurfaceDestroyDeferred) {
1982 pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized);
1983 pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred);
1984 }
1985 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
1986 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
1987 pw.print(" mAlpha="); pw.print(mAlpha);
1988 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
1989 }
1990 if (mHaveMatrix || mWin.mGlobalScale != 1) {
1991 pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale);
1992 pw.print(" mDsDx="); pw.print(mDsDx);
1993 pw.print(" mDtDx="); pw.print(mDtDx);
1994 pw.print(" mDsDy="); pw.print(mDsDy);
1995 pw.print(" mDtDy="); pw.println(mDtDy);
1996 }
Jorim Jaggiff71d202016-04-14 13:12:36 -07001997 if (mAnimationStartDelayed) {
1998 pw.print(prefix); pw.print("mAnimationStartDelayed="); pw.print(mAnimationStartDelayed);
1999 }
Craig Mautnera2c77052012-03-26 12:14:43 -07002000 }
2001
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07002002 @Override
2003 public String toString() {
Dianne Hackborn529e7442012-11-01 14:22:28 -07002004 StringBuffer sb = new StringBuffer("WindowStateAnimator{");
2005 sb.append(Integer.toHexString(System.identityHashCode(this)));
2006 sb.append(' ');
2007 sb.append(mWin.mAttrs.getTitle());
2008 sb.append('}');
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07002009 return sb.toString();
2010 }
Robert Carre6a83512015-11-03 16:09:21 -08002011
2012 void reclaimSomeSurfaceMemory(String operation, boolean secure) {
2013 mService.reclaimSomeSurfaceMemoryLocked(this, operation, secure);
2014 }
2015
2016 boolean getShown() {
2017 if (mSurfaceController != null) {
2018 return mSurfaceController.getShown();
2019 }
2020 return false;
2021 }
2022
2023 void destroySurface() {
Wale Ogunwale722ff892016-02-18 13:37:55 -08002024 try {
2025 if (mSurfaceController != null) {
2026 mSurfaceController.destroyInTransaction();
2027 }
2028 } catch (RuntimeException e) {
2029 Slog.w(TAG, "Exception thrown when destroying surface " + this
2030 + " surface " + mSurfaceController + " session " + mSession + ": " + e);
2031 } finally {
2032 mWin.setHasSurface(false);
2033 mSurfaceController = null;
2034 mDrawState = NO_SURFACE;
2035 }
Robert Carre6a83512015-11-03 16:09:21 -08002036 }
Filip Gruszczynskif52dd202015-11-15 20:36:38 -08002037
2038 void setMoveAnimation(int left, int top) {
2039 final Animation a = AnimationUtils.loadAnimation(mContext,
2040 com.android.internal.R.anim.window_move_from_decor);
2041 setAnimation(a);
2042 mAnimDx = mWin.mLastFrame.left - left;
2043 mAnimDy = mWin.mLastFrame.top - top;
2044 mAnimateMove = true;
2045 }
Robert Carr679c8072016-04-07 15:51:48 -07002046
2047 void deferTransactionUntilParentFrame(long frameNumber) {
2048 if (!mWin.isChildWindow()) {
2049 return;
2050 }
Robert Carr679c8072016-04-07 15:51:48 -07002051 mSurfaceController.deferTransactionUntil(
2052 mWin.mAttachedWindow.mWinAnimator.mSurfaceController.getHandle(),
2053 frameNumber);
2054 }
2055
Jorim Jaggiff71d202016-04-14 13:12:36 -07002056 /**
2057 * Sometimes we need to synchronize the first frame of animation with some external event.
2058 * To achieve this, we prolong the start of the animation and keep producing the first frame of
2059 * the animation.
2060 */
2061 private long getAnimationFrameTime(Animation animation, long currentTime) {
2062 if (mAnimationStartDelayed) {
2063 animation.setStartTime(currentTime);
2064 return currentTime + 1;
2065 }
2066 return currentTime;
2067 }
2068
2069 void startDelayingAnimationStart() {
2070 mAnimationStartDelayed = true;
2071 }
2072
2073 void endDelayingAnimationStart() {
2074 mAnimationStartDelayed = false;
2075 }
Robert Carr6da3cc02016-06-16 15:17:07 -07002076
2077 void seamlesslyRotateWindow(int oldRotation, int newRotation) {
2078 final WindowState w = mWin;
2079 if (!w.isVisibleNow() || w.mIsWallpaper) {
2080 return;
2081 }
2082
2083 final Rect cropRect = mService.mTmpRect;
2084 final Rect displayRect = mService.mTmpRect2;
2085 final RectF frameRect = mService.mTmpRectF;
2086 final Matrix transform = mService.mTmpTransform;
2087
2088 final float x = w.mFrame.left;
2089 final float y = w.mFrame.top;
2090 final float width = w.mFrame.width();
2091 final float height = w.mFrame.height();
2092
2093 mService.getDefaultDisplayContentLocked().getLogicalDisplayRect(displayRect);
2094 final float displayWidth = displayRect.width();
2095 final float displayHeight = displayRect.height();
2096
2097 // Compute a transform matrix to undo the coordinate space transformation,
2098 // and present the window at the same physical position it previously occupied.
2099 final int deltaRotation = DisplayContent.deltaRotation(newRotation, oldRotation);
Andrii Kulian781240d2016-10-05 01:11:52 -07002100 DisplayContent.createRotationMatrix(deltaRotation, x, y, displayWidth, displayHeight,
2101 transform);
Robert Carr6da3cc02016-06-16 15:17:07 -07002102
2103 // We have two cases:
2104 // 1. Windows with NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY:
2105 // These windows never change buffer size when rotating. Rather the window manager
2106 // just updates the scaling factors to fit in the new coordinate system,
2107 // and SurfaceFlinger takes care of updating the buffer contents. So in this case
2108 // we just need we just need to update the scaling factors and things are seamless
2109 // already.
2110 // 2. Other windows:
2111 // In this case, we need to apply a rotation matrix to the window. For example
2112 // if we have a portrait window and rotate to landscape, the window is still portrait
2113 // and now extends off the bottom of the screen (and only halfway across). Essentially we
2114 // apply a transform to display the current buffer at it's old position
2115 // (in the new coordinate space). We then freeze layer updates until the resize
2116 // occurs, at which point we undo, them.
2117 if (w.isChildWindow() && mSurfaceController.getTransformToDisplayInverse()) {
2118 frameRect.set(x, y, x+width, y+height);
2119 transform.mapRect(frameRect);
2120
2121 w.mAttrs.x = (int) frameRect.left - w.mAttachedWindow.mFrame.left;
2122 w.mAttrs.y = (int) frameRect.top - w.mAttachedWindow.mFrame.top;
2123 w.mAttrs.width = (int) Math.ceil(frameRect.width());
2124 w.mAttrs.height = (int) Math.ceil(frameRect.height());
2125
2126 w.setWindowScale(w.mRequestedWidth, w.mRequestedHeight);
2127
2128 w.applyGravityAndUpdateFrame(w.mContainingFrame, w.mDisplayFrame);
2129 computeShownFrameLocked();
2130 setSurfaceBoundariesLocked(false);
2131
2132 // The stack bounds will not yet be rotated at this point so setSurfaceBoundaries locked
2133 // will crop us incorrectly. Overwrite the crop, exposing the full surface. By the next
2134 // transaction this will be corrected.
2135 cropRect.set(0, 0, w.mRequestedWidth, w.mRequestedWidth + w.mRequestedHeight);
2136 mSurfaceController.setCropInTransaction(cropRect, false);
2137 } else {
Robert Carrb14d4abc2016-10-03 18:13:33 -07002138 mService.markForSeamlessRotation(w, true);
Robert Carr6da3cc02016-06-16 15:17:07 -07002139 transform.getValues(mService.mTmpFloats);
2140
2141 float DsDx = mService.mTmpFloats[Matrix.MSCALE_X];
2142 float DtDx = mService.mTmpFloats[Matrix.MSKEW_Y];
2143 float DsDy = mService.mTmpFloats[Matrix.MSKEW_X];
2144 float DtDy = mService.mTmpFloats[Matrix.MSCALE_Y];
2145 float nx = mService.mTmpFloats[Matrix.MTRANS_X];
2146 float ny = mService.mTmpFloats[Matrix.MTRANS_Y];
2147 mSurfaceController.setPositionInTransaction(nx, ny, false);
2148 mSurfaceController.setMatrixInTransaction(DsDx * w.mHScale,
2149 DtDx * w.mVScale,
2150 DsDy * w.mHScale,
2151 DtDy * w.mVScale, false);
2152 }
2153 }
Craig Mautnera2c77052012-03-26 12:14:43 -07002154}