blob: 6b3c36865ae8badfd0f7ab0148dbb1004f9a21b9 [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
Craig Mautnerc2f9be02012-03-27 17:32:29 -070019import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Craig Mautnerb3b36ba2013-05-20 13:21:10 -070020import static com.android.server.wm.WindowManagerService.DEBUG_ANIM;
21import static com.android.server.wm.WindowManagerService.DEBUG_LAYERS;
22import static com.android.server.wm.WindowManagerService.DEBUG_ORIENTATION;
23import static com.android.server.wm.WindowManagerService.DEBUG_STARTING_WINDOW;
24import static com.android.server.wm.WindowManagerService.DEBUG_SURFACE_TRACE;
25import static com.android.server.wm.WindowManagerService.SHOW_TRANSACTIONS;
26import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
27import static com.android.server.wm.WindowManagerService.SHOW_LIGHT_TRANSACTIONS;
28import static com.android.server.wm.WindowManagerService.SHOW_SURFACE_ALLOC;
29import static com.android.server.wm.WindowManagerService.localLOGV;
Craig Mautner2639da52012-07-09 09:39:06 -070030import static com.android.server.wm.WindowManagerService.LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE;
Craig Mautner7d8df392012-04-06 15:26:23 -070031import static com.android.server.wm.WindowManagerService.LayoutFields.SET_TURN_ON_SCREEN;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070032
Craig Mautnerc2f9be02012-03-27 17:32:29 -070033import android.content.Context;
34import android.graphics.Matrix;
35import android.graphics.PixelFormat;
Craig Mautner7358fbf2012-04-12 21:06:33 -070036import android.graphics.Point;
37import android.graphics.PointF;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070038import android.graphics.Rect;
Craig Mautner58106812012-12-28 12:27:40 -080039import android.graphics.RectF;
Craig Mautner48ba1e72012-04-02 13:18:16 -070040import android.graphics.Region;
Craig Mautnera51a9562012-04-17 17:05:26 -070041import android.os.Debug;
Craig Mautnera2c77052012-03-26 12:14:43 -070042import android.util.Slog;
Svetoslav Ganov545252f2012-12-10 18:29:24 -080043import android.view.Display;
Craig Mautner59c00972012-07-30 12:10:24 -070044import android.view.DisplayInfo;
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -070045import android.view.MagnificationSpec;
Igor Murashkina86ab6402013-08-30 12:58:36 -070046import android.view.Surface.OutOfResourcesException;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080047import android.view.SurfaceControl;
Craig Mautner7358fbf2012-04-12 21:06:33 -070048import android.view.SurfaceSession;
Craig Mautnera2c77052012-03-26 12:14:43 -070049import android.view.WindowManager;
50import android.view.WindowManagerPolicy;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070051import android.view.WindowManager.LayoutParams;
Craig Mautnera2c77052012-03-26 12:14:43 -070052import android.view.animation.Animation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070053import android.view.animation.AnimationUtils;
Craig Mautnera2c77052012-03-26 12:14:43 -070054import android.view.animation.Transformation;
55
56import com.android.server.wm.WindowManagerService.H;
57
58import java.io.PrintWriter;
Craig Mautner7358fbf2012-04-12 21:06:33 -070059import java.util.ArrayList;
Craig Mautnera2c77052012-03-26 12:14:43 -070060
Craig Mautner59c00972012-07-30 12:10:24 -070061class WinAnimatorList extends ArrayList<WindowStateAnimator> {
62}
63
Craig Mautnera2c77052012-03-26 12:14:43 -070064/**
Craig Mautnerc2f9be02012-03-27 17:32:29 -070065 * Keep track of animations and surface operations for a single WindowState.
66 **/
Craig Mautnera2c77052012-03-26 12:14:43 -070067class WindowStateAnimator {
Craig Mautnerc2f9be02012-03-27 17:32:29 -070068 static final String TAG = "WindowStateAnimator";
Craig Mautnera2c77052012-03-26 12:14:43 -070069
Craig Mautner918b53b2012-07-09 14:15:54 -070070 // Unchanging local convenience fields.
Craig Mautnera2c77052012-03-26 12:14:43 -070071 final WindowManagerService mService;
72 final WindowState mWin;
Craig Mautner322e4032012-07-13 13:35:20 -070073 final WindowStateAnimator mAttachedWinAnimator;
Craig Mautnere7ae2502012-03-26 17:11:19 -070074 final WindowAnimator mAnimator;
Craig Mautner8863cca2012-09-18 15:04:34 -070075 AppWindowAnimator mAppAnimator;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070076 final Session mSession;
77 final WindowManagerPolicy mPolicy;
78 final Context mContext;
Craig Mautner918b53b2012-07-09 14:15:54 -070079 final boolean mIsWallpaper;
Craig Mautnera2c77052012-03-26 12:14:43 -070080
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -070081 // If this is a universe background window, this is the transformation
82 // it is applying to the rest of the universe.
83 final Transformation mUniverseTransform = new Transformation();
84
Craig Mautnera2c77052012-03-26 12:14:43 -070085 // Currently running animation.
86 boolean mAnimating;
87 boolean mLocalAnimating;
88 Animation mAnimation;
89 boolean mAnimationIsEntrance;
90 boolean mHasTransformation;
91 boolean mHasLocalTransformation;
92 final Transformation mTransformation = new Transformation();
93 boolean mWasAnimating; // Were we animating going into the most recent animation step?
Craig Mautnerc2f9be02012-03-27 17:32:29 -070094 int mAnimLayer;
95 int mLastLayer;
96
Mathias Agopian29479eb2013-02-14 14:36:04 -080097 SurfaceControl mSurfaceControl;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080098 SurfaceControl mPendingDestroySurface;
Craig Mautnerc2f9be02012-03-27 17:32:29 -070099
100 /**
101 * Set when we have changed the size of the surface, to know that
102 * we must tell them application to resize (and thus redraw itself).
103 */
104 boolean mSurfaceResized;
105
106 /**
107 * Set if the client has asked that the destroy of its surface be delayed
108 * until it explicitly says it is okay.
109 */
110 boolean mSurfaceDestroyDeferred;
111
Craig Mautner7d8df392012-04-06 15:26:23 -0700112 float mShownAlpha = 0;
113 float mAlpha = 0;
114 float mLastAlpha = 0;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700115
Winson Chung399f6202014-03-19 10:47:20 -0700116 boolean mHasClipRect;
117 Rect mClipRect = new Rect();
118 Rect mTmpClipRect = new Rect();
119 Rect mLastClipRect = new Rect();
120
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700121 // Used to save animation distances between the time they are calculated and when they are
122 // used.
123 int mAnimDw;
124 int mAnimDh;
125 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
126 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
127
128 boolean mHaveMatrix;
129
130 // For debugging, this is the last information given to the surface flinger.
131 boolean mSurfaceShown;
132 float mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
133 int mSurfaceLayer;
134 float mSurfaceAlpha;
135
136 // Set to true if, when the window gets displayed, it should perform
137 // an enter animation.
138 boolean mEnterAnimationPending;
Craig Mautnera2c77052012-03-26 12:14:43 -0700139
Craig Mautner749a7bb2012-04-02 13:49:53 -0700140 /** This is set when there is no Surface */
141 static final int NO_SURFACE = 0;
142 /** This is set after the Surface has been created but before the window has been drawn. During
143 * this time the surface is hidden. */
144 static final int DRAW_PENDING = 1;
145 /** This is set after the window has finished drawing for the first time but before its surface
146 * is shown. The surface will be displayed when the next layout is run. */
147 static final int COMMIT_DRAW_PENDING = 2;
148 /** This is set during the time after the window's drawing has been committed, and before its
149 * surface is actually shown. It is used to delay showing the surface until all windows in a
150 * token are ready to be shown. */
151 static final int READY_TO_SHOW = 3;
152 /** Set when the window has been shown in the screen the first time. */
153 static final int HAS_DRAWN = 4;
Craig Mautner6fbda632012-07-03 09:26:39 -0700154 static String drawStateToString(int state) {
155 switch (state) {
156 case NO_SURFACE: return "NO_SURFACE";
157 case DRAW_PENDING: return "DRAW_PENDING";
158 case COMMIT_DRAW_PENDING: return "COMMIT_DRAW_PENDING";
159 case READY_TO_SHOW: return "READY_TO_SHOW";
160 case HAS_DRAWN: return "HAS_DRAWN";
161 default: return Integer.toString(state);
162 }
163 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700164 int mDrawState;
Craig Mautnera608b882012-03-30 13:03:49 -0700165
Craig Mautner749a7bb2012-04-02 13:49:53 -0700166 /** Was this window last hidden? */
167 boolean mLastHidden;
Craig Mautnera608b882012-03-30 13:03:49 -0700168
Craig Mautnerbec53f72012-04-05 11:49:05 -0700169 int mAttrFlags;
170 int mAttrType;
171
Craig Mautner918b53b2012-07-09 14:15:54 -0700172 public WindowStateAnimator(final WindowState win) {
173 final WindowManagerService service = win.mService;
174
Craig Mautnera2c77052012-03-26 12:14:43 -0700175 mService = service;
Craig Mautner918b53b2012-07-09 14:15:54 -0700176 mAnimator = service.mAnimator;
177 mPolicy = service.mPolicy;
178 mContext = service.mContext;
Craig Mautnerdf88d732014-01-27 09:21:32 -0800179 final DisplayInfo displayInfo = win.getDisplayContent().getDisplayInfo();
Craig Mautner59c00972012-07-30 12:10:24 -0700180 mAnimDw = displayInfo.appWidth;
181 mAnimDh = displayInfo.appHeight;
Craig Mautner918b53b2012-07-09 14:15:54 -0700182
183 mWin = win;
Craig Mautner322e4032012-07-13 13:35:20 -0700184 mAttachedWinAnimator = win.mAttachedWindow == null
185 ? null : win.mAttachedWindow.mWinAnimator;
186 mAppAnimator = win.mAppToken == null ? null : win.mAppToken.mAppAnimator;
Craig Mautner918b53b2012-07-09 14:15:54 -0700187 mSession = win.mSession;
188 mAttrFlags = win.mAttrs.flags;
189 mAttrType = win.mAttrs.type;
190 mIsWallpaper = win.mIsWallpaper;
Craig Mautnera2c77052012-03-26 12:14:43 -0700191 }
192
193 public void setAnimation(Animation anim) {
Craig Mautnerbec53f72012-04-05 11:49:05 -0700194 if (localLOGV) Slog.v(TAG, "Setting animation in " + this + ": " + anim);
Craig Mautnera2c77052012-03-26 12:14:43 -0700195 mAnimating = false;
196 mLocalAnimating = false;
197 mAnimation = anim;
198 mAnimation.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION);
199 mAnimation.scaleCurrentDuration(mService.mWindowAnimationScale);
200 // Start out animation gone if window is gone, or visible if window is visible.
201 mTransformation.clear();
Craig Mautner749a7bb2012-04-02 13:49:53 -0700202 mTransformation.setAlpha(mLastHidden ? 0 : 1);
Craig Mautnera2c77052012-03-26 12:14:43 -0700203 mHasLocalTransformation = true;
204 }
205
206 public void clearAnimation() {
207 if (mAnimation != null) {
208 mAnimating = true;
209 mLocalAnimating = false;
210 mAnimation.cancel();
211 mAnimation = null;
212 }
213 }
214
215 /** Is the window or its container currently animating? */
216 boolean isAnimating() {
Craig Mautnera2c77052012-03-26 12:14:43 -0700217 return mAnimation != null
Craig Mautner322e4032012-07-13 13:35:20 -0700218 || (mAttachedWinAnimator != null && mAttachedWinAnimator.mAnimation != null)
219 || (mAppAnimator != null &&
220 (mAppAnimator.animation != null
221 || mAppAnimator.mAppToken.inPendingTransaction));
Craig Mautnera2c77052012-03-26 12:14:43 -0700222 }
223
Craig Mautner0afddcb2012-05-08 15:38:00 -0700224 /** Is the window animating the DummyAnimation? */
225 boolean isDummyAnimation() {
Craig Mautner322e4032012-07-13 13:35:20 -0700226 return mAppAnimator != null
227 && mAppAnimator.animation == AppWindowAnimator.sDummyAnimation;
Craig Mautner0afddcb2012-05-08 15:38:00 -0700228 }
229
Craig Mautnera2c77052012-03-26 12:14:43 -0700230 /** Is this window currently animating? */
231 boolean isWindowAnimating() {
232 return mAnimation != null;
233 }
234
Craig Mautnera2c77052012-03-26 12:14:43 -0700235 void cancelExitAnimationForNextAnimationLocked() {
Craig Mautnera2c77052012-03-26 12:14:43 -0700236 if (mAnimation != null) {
237 mAnimation.cancel();
238 mAnimation = null;
Craig Mautner4d7349b2012-04-20 14:52:47 -0700239 mLocalAnimating = false;
Craig Mautner96868332012-12-04 14:29:11 -0800240 destroySurfaceLocked();
Craig Mautnera2c77052012-03-26 12:14:43 -0700241 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700242 }
243
244 private boolean stepAnimation(long currentTime) {
245 if ((mAnimation == null) || !mLocalAnimating) {
246 return false;
247 }
248 mTransformation.clear();
249 final boolean more = mAnimation.getTransformation(currentTime, mTransformation);
Craig Mautner9e809442012-06-22 17:13:04 -0700250 if (false && DEBUG_ANIM) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700251 TAG, "Stepped animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700252 ": more=" + more + ", xform=" + mTransformation);
253 return more;
254 }
255
256 // This must be called while inside a transaction. Returns true if
257 // there is more animation to run.
258 boolean stepAnimationLocked(long currentTime) {
259 // Save the animation state as it was before this step so WindowManagerService can tell if
260 // we just started or just stopped animating by comparing mWasAnimating with isAnimating().
261 mWasAnimating = mAnimating;
Craig Mautnerdf88d732014-01-27 09:21:32 -0800262 final DisplayContent displayContent = mWin.getDisplayContent();
263 if (displayContent != null && mService.okToDisplay()) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700264 // We will run animations as long as the display isn't frozen.
265
266 if (mWin.isDrawnLw() && mAnimation != null) {
267 mHasTransformation = true;
268 mHasLocalTransformation = true;
269 if (!mLocalAnimating) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700270 if (DEBUG_ANIM) Slog.v(
271 TAG, "Starting animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700272 " @ " + currentTime + ": ww=" + mWin.mFrame.width() +
273 " wh=" + mWin.mFrame.height() +
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700274 " dw=" + mAnimDw + " dh=" + mAnimDh +
Craig Mautnera2c77052012-03-26 12:14:43 -0700275 " scale=" + mService.mWindowAnimationScale);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700276 mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(),
277 mAnimDw, mAnimDh);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800278 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Craig Mautner59c00972012-07-30 12:10:24 -0700279 mAnimDw = displayInfo.appWidth;
280 mAnimDh = displayInfo.appHeight;
Craig Mautnera2c77052012-03-26 12:14:43 -0700281 mAnimation.setStartTime(currentTime);
282 mLocalAnimating = true;
283 mAnimating = true;
284 }
285 if ((mAnimation != null) && mLocalAnimating) {
286 if (stepAnimation(currentTime)) {
287 return true;
288 }
289 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700290 if (DEBUG_ANIM) Slog.v(
291 TAG, "Finished animation in " + this +
Craig Mautnera2c77052012-03-26 12:14:43 -0700292 " @ " + currentTime);
293 //WindowManagerService.this.dump();
294 }
295 mHasLocalTransformation = false;
Craig Mautner322e4032012-07-13 13:35:20 -0700296 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppAnimator != null
297 && mAppAnimator.animation != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700298 // When our app token is animating, we kind-of pretend like
299 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
300 // part of this check means that we will only do this if
301 // our window is not currently exiting, or it is not
302 // locally animating itself. The idea being that one that
303 // is exiting and doing a local animation should be removed
304 // once that animation is done.
305 mAnimating = true;
306 mHasTransformation = true;
307 mTransformation.clear();
308 return false;
309 } else if (mHasTransformation) {
310 // Little trick to get through the path below to act like
311 // we have finished an animation.
312 mAnimating = true;
313 } else if (isAnimating()) {
314 mAnimating = true;
315 }
316 } else if (mAnimation != null) {
317 // If the display is frozen, and there is a pending animation,
318 // clear it and make sure we run the cleanup code.
319 mAnimating = true;
Craig Mautnera2c77052012-03-26 12:14:43 -0700320 }
321
322 if (!mAnimating && !mLocalAnimating) {
323 return false;
324 }
325
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700326 // Done animating, clean up.
327 if (DEBUG_ANIM) Slog.v(
328 TAG, "Animation done in " + this + ": exiting=" + mWin.mExiting
Craig Mautnera2c77052012-03-26 12:14:43 -0700329 + ", reportedVisible="
330 + (mWin.mAppToken != null ? mWin.mAppToken.reportedVisible : false));
331
332 mAnimating = false;
333 mLocalAnimating = false;
334 if (mAnimation != null) {
335 mAnimation.cancel();
336 mAnimation = null;
337 }
Craig Mautnere7ae2502012-03-26 17:11:19 -0700338 if (mAnimator.mWindowDetachedWallpaper == mWin) {
339 mAnimator.mWindowDetachedWallpaper = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700340 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700341 mAnimLayer = mWin.mLayer;
Craig Mautnera2c77052012-03-26 12:14:43 -0700342 if (mWin.mIsImWindow) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700343 mAnimLayer += mService.mInputMethodAnimLayerAdjustment;
Craig Mautner918b53b2012-07-09 14:15:54 -0700344 } else if (mIsWallpaper) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700345 mAnimLayer += mService.mWallpaperAnimLayerAdjustment;
Craig Mautnera2c77052012-03-26 12:14:43 -0700346 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700347 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
348 + " anim layer: " + mAnimLayer);
Craig Mautnera2c77052012-03-26 12:14:43 -0700349 mHasTransformation = false;
350 mHasLocalTransformation = false;
351 if (mWin.mPolicyVisibility != mWin.mPolicyVisibilityAfterAnim) {
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700352 if (DEBUG_VISIBILITY) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700353 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
Craig Mautnera2c77052012-03-26 12:14:43 -0700354 + mWin.mPolicyVisibilityAfterAnim);
355 }
356 mWin.mPolicyVisibility = mWin.mPolicyVisibilityAfterAnim;
Craig Mautnerdf88d732014-01-27 09:21:32 -0800357 if (displayContent != null) {
358 displayContent.layoutNeeded = true;
359 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700360 if (!mWin.mPolicyVisibility) {
361 if (mService.mCurrentFocus == mWin) {
Craig Mautner58458122013-09-14 14:59:50 -0700362 if (WindowManagerService.DEBUG_FOCUS_LIGHT) Slog.i(TAG,
363 "setAnimationLocked: setting mFocusMayChange true");
Craig Mautnera2c77052012-03-26 12:14:43 -0700364 mService.mFocusMayChange = true;
365 }
366 // Window is no longer visible -- make sure if we were waiting
367 // for it to be displayed before enabling the display, that
368 // we allow the display to be enabled now.
369 mService.enableScreenIfNeededLocked();
370 }
371 }
372 mTransformation.clear();
Craig Mautner749a7bb2012-04-02 13:49:53 -0700373 if (mDrawState == HAS_DRAWN
Craig Mautnera2c77052012-03-26 12:14:43 -0700374 && mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
375 && mWin.mAppToken != null
376 && mWin.mAppToken.firstWindowDrawn
377 && mWin.mAppToken.startingData != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700378 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
Craig Mautnera2c77052012-03-26 12:14:43 -0700379 + mWin.mToken + ": first real window done animating");
380 mService.mFinishedStarting.add(mWin.mAppToken);
381 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
Craig Mautner81defc72013-10-29 11:10:42 -0700382 } else if (mAttrType == LayoutParams.TYPE_STATUS_BAR && mWin.mPolicyVisibility) {
383 // Upon completion of a not-visible to visible status bar animation a relayout is
384 // required.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800385 if (displayContent != null) {
386 displayContent.layoutNeeded = true;
387 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700388 }
389
390 finishExit();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800391 final int displayId = mWin.getDisplayId();
Craig Mautner76a71652012-09-03 23:23:58 -0700392 mAnimator.setPendingLayoutChanges(displayId, WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700393 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) mService.debugLayoutRepeats(
Craig Mautner66f78d72012-12-04 16:46:50 -0800394 "WindowStateAnimator", mAnimator.getPendingLayoutChanges(displayId));
Craig Mautnera2c77052012-03-26 12:14:43 -0700395
396 if (mWin.mAppToken != null) {
397 mWin.mAppToken.updateReportedVisibilityLocked();
398 }
399
400 return false;
401 }
402
403 void finishExit() {
404 if (WindowManagerService.DEBUG_ANIM) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700405 TAG, "finishExit in " + this
Craig Mautnera2c77052012-03-26 12:14:43 -0700406 + ": exiting=" + mWin.mExiting
407 + " remove=" + mWin.mRemoveOnExit
408 + " windowAnimating=" + isWindowAnimating());
409
410 final int N = mWin.mChildWindows.size();
411 for (int i=0; i<N; i++) {
412 mWin.mChildWindows.get(i).mWinAnimator.finishExit();
413 }
414
415 if (!mWin.mExiting) {
416 return;
417 }
418
419 if (isWindowAnimating()) {
420 return;
421 }
422
423 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700424 TAG, "Exit animation finished in " + this
Craig Mautnera2c77052012-03-26 12:14:43 -0700425 + ": remove=" + mWin.mRemoveOnExit);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800426 if (mSurfaceControl != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700427 mService.mDestroySurface.add(mWin);
428 mWin.mDestroying = true;
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700429 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(
Craig Mautnera2c77052012-03-26 12:14:43 -0700430 mWin, "HIDE (finishExit)", null);
Craig Mautner0afddcb2012-05-08 15:38:00 -0700431 hide();
Craig Mautnera2c77052012-03-26 12:14:43 -0700432 }
433 mWin.mExiting = false;
434 if (mWin.mRemoveOnExit) {
435 mService.mPendingRemove.add(mWin);
436 mWin.mRemoveOnExit = false;
437 }
Craig Mautner96868332012-12-04 14:29:11 -0800438 mAnimator.hideWallpapersLocked(mWin);
Craig Mautner0afddcb2012-05-08 15:38:00 -0700439 }
440
441 void hide() {
442 if (!mLastHidden) {
443 //dump();
444 mLastHidden = true;
445 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
446 "HIDE (performLayout)", null);
Mathias Agopian29479eb2013-02-14 14:36:04 -0800447 if (mSurfaceControl != null) {
Craig Mautner0afddcb2012-05-08 15:38:00 -0700448 mSurfaceShown = false;
449 try {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800450 mSurfaceControl.hide();
Craig Mautner0afddcb2012-05-08 15:38:00 -0700451 } catch (RuntimeException e) {
452 Slog.w(TAG, "Exception hiding surface in " + mWin);
453 }
454 }
455 }
Craig Mautnera2c77052012-03-26 12:14:43 -0700456 }
457
Craig Mautnera608b882012-03-30 13:03:49 -0700458 boolean finishDrawingLocked() {
Craig Mautner6fbda632012-07-03 09:26:39 -0700459 if (DEBUG_STARTING_WINDOW &&
460 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
461 Slog.v(TAG, "Finishing drawing window " + mWin + ": mDrawState="
462 + drawStateToString(mDrawState));
463 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700464 if (mDrawState == DRAW_PENDING) {
Craig Mautneref25d7a2012-05-15 23:01:47 -0700465 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
466 Slog.v(TAG, "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING " + this + " in "
Mathias Agopian29479eb2013-02-14 14:36:04 -0800467 + mSurfaceControl);
Craig Mautner6fbda632012-07-03 09:26:39 -0700468 if (DEBUG_STARTING_WINDOW &&
469 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
470 Slog.v(TAG, "Draw state now committed in " + mWin);
471 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700472 mDrawState = COMMIT_DRAW_PENDING;
Craig Mautnera608b882012-03-30 13:03:49 -0700473 return true;
474 }
475 return false;
476 }
477
478 // This must be called while inside a transaction.
479 boolean commitFinishDrawingLocked(long currentTime) {
Craig Mautner6fbda632012-07-03 09:26:39 -0700480 if (DEBUG_STARTING_WINDOW &&
481 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
482 Slog.i(TAG, "commitFinishDrawingLocked: " + mWin + " cur mDrawState="
483 + drawStateToString(mDrawState));
484 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700485 if (mDrawState != COMMIT_DRAW_PENDING) {
Craig Mautnera608b882012-03-30 13:03:49 -0700486 return false;
487 }
Craig Mautner6fbda632012-07-03 09:26:39 -0700488 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800489 Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurfaceControl);
Craig Mautner6fbda632012-07-03 09:26:39 -0700490 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700491 mDrawState = READY_TO_SHOW;
Craig Mautnera608b882012-03-30 13:03:49 -0700492 final boolean starting = mWin.mAttrs.type == TYPE_APPLICATION_STARTING;
493 final AppWindowToken atoken = mWin.mAppToken;
494 if (atoken == null || atoken.allDrawn || starting) {
495 performShowLocked();
496 }
497 return true;
498 }
499
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800500 static class SurfaceTrace extends SurfaceControl {
Craig Mautner7d8df392012-04-06 15:26:23 -0700501 private final static String SURFACE_TAG = "SurfaceTrace";
502 final static ArrayList<SurfaceTrace> sSurfaces = new ArrayList<SurfaceTrace>();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700503
Craig Mautner7d8df392012-04-06 15:26:23 -0700504 private float mSurfaceTraceAlpha = 0;
Craig Mautner7358fbf2012-04-12 21:06:33 -0700505 private int mLayer;
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700506 private final PointF mPosition = new PointF();
507 private final Point mSize = new Point();
508 private final Rect mWindowCrop = new Rect();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700509 private boolean mShown = false;
Jeff Brown98365d72012-08-19 20:30:52 -0700510 private int mLayerStack;
Craig Mautner71dd1b62014-02-18 15:48:52 -0800511 private boolean mIsOpaque;
Igor Murashkina86ab6402013-08-30 12:58:36 -0700512 private final String mName;
Craig Mautner7358fbf2012-04-12 21:06:33 -0700513
Craig Mautner7d8df392012-04-06 15:26:23 -0700514 public SurfaceTrace(SurfaceSession s,
Jeff Brown64a55af2012-08-26 02:47:39 -0700515 String name, int w, int h, int format, int flags)
Craig Mautner7358fbf2012-04-12 21:06:33 -0700516 throws OutOfResourcesException {
Jeff Brown64a55af2012-08-26 02:47:39 -0700517 super(s, name, w, h, format, flags);
Jeff Brown98365d72012-08-19 20:30:52 -0700518 mName = name != null ? name : "Not named";
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700519 mSize.set(w, h);
Craig Mautner7d8df392012-04-06 15:26:23 -0700520 Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700521 + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700522 }
523
524 @Override
525 public void setAlpha(float alpha) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700526 if (mSurfaceTraceAlpha != alpha) {
527 Slog.v(SURFACE_TAG, "setAlpha(" + alpha + "): OLD:" + this + ". Called by "
Dianne Hackborn98129732012-11-01 16:28:16 -0700528 + Debug.getCallers(3));
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700529 mSurfaceTraceAlpha = alpha;
Dianne Hackborn98129732012-11-01 16:28:16 -0700530 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700531 super.setAlpha(alpha);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700532 }
533
534 @Override
535 public void setLayer(int zorder) {
Dianne Hackborn98129732012-11-01 16:28:16 -0700536 if (zorder != mLayer) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700537 Slog.v(SURFACE_TAG, "setLayer(" + zorder + "): OLD:" + this + ". Called by "
Dianne Hackborn98129732012-11-01 16:28:16 -0700538 + Debug.getCallers(3));
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700539 mLayer = zorder;
Dianne Hackborn98129732012-11-01 16:28:16 -0700540 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700541 super.setLayer(zorder);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700542
543 sSurfaces.remove(this);
544 int i;
545 for (i = sSurfaces.size() - 1; i >= 0; i--) {
Craig Mautner7d8df392012-04-06 15:26:23 -0700546 SurfaceTrace s = sSurfaces.get(i);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700547 if (s.mLayer < zorder) {
548 break;
549 }
550 }
551 sSurfaces.add(i + 1, this);
552 }
553
554 @Override
555 public void setPosition(float x, float y) {
Dianne Hackborn98129732012-11-01 16:28:16 -0700556 if (x != mPosition.x || y != mPosition.y) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700557 Slog.v(SURFACE_TAG, "setPosition(" + x + "," + y + "): OLD:" + this
558 + ". Called by " + Debug.getCallers(3));
Craig Mautner66d77302013-04-10 15:33:26 -0700559 mPosition.set(x, y);
Dianne Hackborn98129732012-11-01 16:28:16 -0700560 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700561 super.setPosition(x, y);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700562 }
563
564 @Override
565 public void setSize(int w, int h) {
Dianne Hackborn98129732012-11-01 16:28:16 -0700566 if (w != mSize.x || h != mSize.y) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700567 Slog.v(SURFACE_TAG, "setSize(" + w + "," + h + "): OLD:" + this + ". Called by "
Dianne Hackborn98129732012-11-01 16:28:16 -0700568 + Debug.getCallers(3));
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700569 mSize.set(w, h);
Dianne Hackborn98129732012-11-01 16:28:16 -0700570 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700571 super.setSize(w, h);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700572 }
573
574 @Override
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700575 public void setWindowCrop(Rect crop) {
Craig Mautneref25d7a2012-05-15 23:01:47 -0700576 if (crop != null) {
Dianne Hackborn98129732012-11-01 16:28:16 -0700577 if (!crop.equals(mWindowCrop)) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700578 Slog.v(SURFACE_TAG, "setWindowCrop(" + crop.toShortString() + "): OLD:" + this
579 + ". Called by " + Debug.getCallers(3));
Craig Mautner66d77302013-04-10 15:33:26 -0700580 mWindowCrop.set(crop);
Dianne Hackborn98129732012-11-01 16:28:16 -0700581 }
Craig Mautneref25d7a2012-05-15 23:01:47 -0700582 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700583 super.setWindowCrop(crop);
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700584 }
585
586 @Override
Jeff Brown98365d72012-08-19 20:30:52 -0700587 public void setLayerStack(int layerStack) {
Dianne Hackborn98129732012-11-01 16:28:16 -0700588 if (layerStack != mLayerStack) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700589 Slog.v(SURFACE_TAG, "setLayerStack(" + layerStack + "): OLD:" + this
590 + ". Called by " + Debug.getCallers(3));
Craig Mautner66d77302013-04-10 15:33:26 -0700591 mLayerStack = layerStack;
Dianne Hackborn98129732012-11-01 16:28:16 -0700592 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700593 super.setLayerStack(layerStack);
Craig Mautner9de49362012-08-02 14:30:30 -0700594 }
595
596 @Override
Craig Mautner71dd1b62014-02-18 15:48:52 -0800597 public void setOpaque(boolean isOpaque) {
598 if (isOpaque != mIsOpaque) {
599 Slog.v(SURFACE_TAG, "setOpaque(" + isOpaque + "): OLD:" + this
600 + ". Called by " + Debug.getCallers(3));
601 mIsOpaque = isOpaque;
602 }
603 super.setOpaque(isOpaque);
604 }
605
606 @Override
Craig Mautner7358fbf2012-04-12 21:06:33 -0700607 public void hide() {
Dianne Hackborn98129732012-11-01 16:28:16 -0700608 if (mShown) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700609 Slog.v(SURFACE_TAG, "hide: OLD:" + this + ". Called by " + Debug.getCallers(3));
Craig Mautner66d77302013-04-10 15:33:26 -0700610 mShown = false;
Dianne Hackborn98129732012-11-01 16:28:16 -0700611 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700612 super.hide();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700613 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700614
Craig Mautner7358fbf2012-04-12 21:06:33 -0700615 @Override
616 public void show() {
Dianne Hackborn98129732012-11-01 16:28:16 -0700617 if (!mShown) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700618 Slog.v(SURFACE_TAG, "show: OLD:" + this + ". Called by " + Debug.getCallers(3));
Craig Mautner66d77302013-04-10 15:33:26 -0700619 mShown = true;
Dianne Hackborn98129732012-11-01 16:28:16 -0700620 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700621 super.show();
Craig Mautner7358fbf2012-04-12 21:06:33 -0700622 }
623
624 @Override
625 public void destroy() {
626 super.destroy();
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700627 Slog.v(SURFACE_TAG, "destroy: " + this + ". Called by " + Debug.getCallers(3));
Craig Mautner7358fbf2012-04-12 21:06:33 -0700628 sSurfaces.remove(this);
629 }
630
Craig Mautneracaf9cc2012-04-17 11:45:25 -0700631 @Override
632 public void release() {
633 super.release();
634 Slog.v(SURFACE_TAG, "release: " + this + ". Called by "
Craig Mautnera51a9562012-04-17 17:05:26 -0700635 + Debug.getCallers(3));
Craig Mautneracaf9cc2012-04-17 11:45:25 -0700636 sSurfaces.remove(this);
637 }
638
Craig Mautner7358fbf2012-04-12 21:06:33 -0700639 static void dumpAllSurfaces() {
640 final int N = sSurfaces.size();
641 for (int i = 0; i < N; i++) {
642 Slog.i(TAG, "SurfaceDump: " + sSurfaces.get(i));
643 }
644 }
645
646 @Override
647 public String toString() {
Craig Mautnerfbf378c2012-04-23 17:24:21 -0700648 return "Surface " + Integer.toHexString(System.identityHashCode(this)) + " "
Jeff Brown98365d72012-08-19 20:30:52 -0700649 + mName + " (" + mLayerStack + "): shown=" + mShown + " layer=" + mLayer
Craig Mautner7d8df392012-04-06 15:26:23 -0700650 + " alpha=" + mSurfaceTraceAlpha + " " + mPosition.x + "," + mPosition.y
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700651 + " " + mSize.x + "x" + mSize.y
Craig Mautner71dd1b62014-02-18 15:48:52 -0800652 + " crop=" + mWindowCrop.toShortString()
653 + " opaque=" + mIsOpaque;
Craig Mautner7358fbf2012-04-12 21:06:33 -0700654 }
655 }
656
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800657 SurfaceControl createSurfaceLocked() {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800658 if (mSurfaceControl == null) {
Craig Mautner83339b42012-05-01 22:13:23 -0700659 if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG,
660 "createSurface " + this + ": mDrawState=DRAW_PENDING");
Craig Mautner749a7bb2012-04-02 13:49:53 -0700661 mDrawState = DRAW_PENDING;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700662 if (mWin.mAppToken != null) {
Craig Mautner7636dfb2012-11-16 15:24:11 -0800663 if (mWin.mAppToken.mAppAnimator.animation == null) {
664 mWin.mAppToken.allDrawn = false;
665 mWin.mAppToken.deferClearAllDrawn = false;
666 } else {
667 // Currently animating, persist current state of allDrawn until animation
668 // is complete.
669 mWin.mAppToken.deferClearAllDrawn = true;
670 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700671 }
672
673 mService.makeWindowFreezingScreenIfNeededLocked(mWin);
674
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800675 int flags = SurfaceControl.HIDDEN;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700676 final WindowManager.LayoutParams attrs = mWin.mAttrs;
677
678 if ((attrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800679 flags |= SurfaceControl.SECURE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700680 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700681 if (DEBUG_VISIBILITY) Slog.v(
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700682 TAG, "Creating surface in session "
683 + mSession.mSurfaceSession + " window " + this
684 + " w=" + mWin.mCompatFrame.width()
685 + " h=" + mWin.mCompatFrame.height() + " format="
686 + attrs.format + " flags=" + flags);
687
688 int w = mWin.mCompatFrame.width();
689 int h = mWin.mCompatFrame.height();
690 if ((attrs.flags & LayoutParams.FLAG_SCALED) != 0) {
691 // for a scaled surface, we always want the requested
692 // size.
693 w = mWin.mRequestedWidth;
694 h = mWin.mRequestedHeight;
695 }
696
697 // Something is wrong and SurfaceFlinger will not like this,
698 // try to revert to sane values
699 if (w <= 0) w = 1;
700 if (h <= 0) h = 1;
701
702 mSurfaceShown = false;
703 mSurfaceLayer = 0;
Craig Mautner7d8df392012-04-06 15:26:23 -0700704 mSurfaceAlpha = 0;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700705 mSurfaceX = 0;
706 mSurfaceY = 0;
707 mSurfaceW = w;
708 mSurfaceH = h;
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700709 mWin.mLastSystemDecorRect.set(0, 0, 0, 0);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700710 try {
711 final boolean isHwAccelerated = (attrs.flags &
712 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
713 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
714 if (!PixelFormat.formatHasAlpha(attrs.format)) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800715 flags |= SurfaceControl.OPAQUE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700716 }
Craig Mautner7358fbf2012-04-12 21:06:33 -0700717 if (DEBUG_SURFACE_TRACE) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800718 mSurfaceControl = new SurfaceTrace(
Jeff Brown64a55af2012-08-26 02:47:39 -0700719 mSession.mSurfaceSession,
Craig Mautner7358fbf2012-04-12 21:06:33 -0700720 attrs.getTitle().toString(),
Jeff Brown64a55af2012-08-26 02:47:39 -0700721 w, h, format, flags);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700722 } else {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800723 mSurfaceControl = new SurfaceControl(
Jeff Brown64a55af2012-08-26 02:47:39 -0700724 mSession.mSurfaceSession,
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700725 attrs.getTitle().toString(),
Jeff Brown64a55af2012-08-26 02:47:39 -0700726 w, h, format, flags);
Craig Mautner7358fbf2012-04-12 21:06:33 -0700727 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700728 mWin.mHasSurface = true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700729 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG,
730 " CREATE SURFACE "
Mathias Agopian29479eb2013-02-14 14:36:04 -0800731 + mSurfaceControl + " IN SESSION "
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700732 + mSession.mSurfaceSession
733 + ": pid=" + mSession.mPid + " format="
734 + attrs.format + " flags=0x"
735 + Integer.toHexString(flags)
736 + " / " + this);
Igor Murashkina86ab6402013-08-30 12:58:36 -0700737 } catch (OutOfResourcesException e) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700738 mWin.mHasSurface = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700739 Slog.w(TAG, "OutOfResourcesException creating surface");
740 mService.reclaimSomeSurfaceMemoryLocked(this, "create", true);
Craig Mautner749a7bb2012-04-02 13:49:53 -0700741 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700742 return null;
743 } catch (Exception e) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700744 mWin.mHasSurface = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700745 Slog.e(TAG, "Exception creating surface", e);
Craig Mautner749a7bb2012-04-02 13:49:53 -0700746 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700747 return null;
748 }
749
750 if (WindowManagerService.localLOGV) Slog.v(
Mathias Agopian29479eb2013-02-14 14:36:04 -0800751 TAG, "Got surface: " + mSurfaceControl
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700752 + ", set left=" + mWin.mFrame.left + " top=" + mWin.mFrame.top
753 + ", animLayer=" + mAnimLayer);
754 if (SHOW_LIGHT_TRANSACTIONS) {
755 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
756 WindowManagerService.logSurface(mWin, "CREATE pos=("
757 + mWin.mFrame.left + "," + mWin.mFrame.top + ") ("
758 + mWin.mCompatFrame.width() + "x" + mWin.mCompatFrame.height()
759 + "), layer=" + mAnimLayer + " HIDE", null);
760 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800761 SurfaceControl.openTransaction();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700762 try {
763 try {
764 mSurfaceX = mWin.mFrame.left + mWin.mXOffset;
765 mSurfaceY = mWin.mFrame.top + mWin.mYOffset;
Mathias Agopian29479eb2013-02-14 14:36:04 -0800766 mSurfaceControl.setPosition(mSurfaceX, mSurfaceY);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700767 mSurfaceLayer = mAnimLayer;
Craig Mautnerdf88d732014-01-27 09:21:32 -0800768 final DisplayContent displayContent = mWin.getDisplayContent();
769 if (displayContent != null) {
770 mSurfaceControl.setLayerStack(displayContent.getDisplay().getLayerStack());
771 }
Mathias Agopian29479eb2013-02-14 14:36:04 -0800772 mSurfaceControl.setLayer(mAnimLayer);
773 mSurfaceControl.setAlpha(0);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700774 mSurfaceShown = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700775 } catch (RuntimeException e) {
776 Slog.w(TAG, "Error creating surface in " + w, e);
777 mService.reclaimSomeSurfaceMemoryLocked(this, "create-init", true);
778 }
Craig Mautner749a7bb2012-04-02 13:49:53 -0700779 mLastHidden = true;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700780 } finally {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800781 SurfaceControl.closeTransaction();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700782 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
783 "<<< CLOSE TRANSACTION createSurfaceLocked");
784 }
785 if (WindowManagerService.localLOGV) Slog.v(
786 TAG, "Created surface " + this);
787 }
Mathias Agopian29479eb2013-02-14 14:36:04 -0800788 return mSurfaceControl;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700789 }
790
Craig Mautner96868332012-12-04 14:29:11 -0800791 void destroySurfaceLocked() {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700792 if (mWin.mAppToken != null && mWin == mWin.mAppToken.startingWindow) {
793 mWin.mAppToken.startingDisplayed = false;
794 }
795
Mathias Agopian29479eb2013-02-14 14:36:04 -0800796 if (mSurfaceControl != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700797
798 int i = mWin.mChildWindows.size();
799 while (i > 0) {
800 i--;
801 WindowState c = mWin.mChildWindows.get(i);
802 c.mAttachedHidden = true;
803 }
804
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700805 try {
806 if (DEBUG_VISIBILITY) {
807 RuntimeException e = null;
808 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
809 e = new RuntimeException();
810 e.fillInStackTrace();
811 }
812 Slog.w(TAG, "Window " + this + " destroying surface "
Mathias Agopian29479eb2013-02-14 14:36:04 -0800813 + mSurfaceControl + ", session " + mSession, e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700814 }
815 if (mSurfaceDestroyDeferred) {
Mathias Agopian29479eb2013-02-14 14:36:04 -0800816 if (mSurfaceControl != null && mPendingDestroySurface != mSurfaceControl) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700817 if (mPendingDestroySurface != null) {
818 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
819 RuntimeException e = null;
820 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
821 e = new RuntimeException();
822 e.fillInStackTrace();
823 }
824 WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
825 }
826 mPendingDestroySurface.destroy();
827 }
Mathias Agopian29479eb2013-02-14 14:36:04 -0800828 mPendingDestroySurface = mSurfaceControl;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700829 }
830 } else {
831 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
832 RuntimeException e = null;
833 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
834 e = new RuntimeException();
835 e.fillInStackTrace();
836 }
837 WindowManagerService.logSurface(mWin, "DESTROY", e);
838 }
Mathias Agopian29479eb2013-02-14 14:36:04 -0800839 mSurfaceControl.destroy();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700840 }
Craig Mautner96868332012-12-04 14:29:11 -0800841 mAnimator.hideWallpapersLocked(mWin);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700842 } catch (RuntimeException e) {
843 Slog.w(TAG, "Exception thrown when destroying Window " + this
Mathias Agopian29479eb2013-02-14 14:36:04 -0800844 + " surface " + mSurfaceControl + " session " + mSession
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700845 + ": " + e.toString());
846 }
847
848 mSurfaceShown = false;
Mathias Agopian29479eb2013-02-14 14:36:04 -0800849 mSurfaceControl = null;
Craig Mautnere8552142012-11-07 13:55:47 -0800850 mWin.mHasSurface = false;
Craig Mautnerbf08af32012-05-16 19:43:42 -0700851 mDrawState = NO_SURFACE;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700852 }
853 }
854
Craig Mautner96868332012-12-04 14:29:11 -0800855 void destroyDeferredSurfaceLocked() {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700856 try {
857 if (mPendingDestroySurface != null) {
858 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
859 RuntimeException e = null;
860 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
861 e = new RuntimeException();
862 e.fillInStackTrace();
863 }
864 WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
865 }
866 mPendingDestroySurface.destroy();
Craig Mautner96868332012-12-04 14:29:11 -0800867 mAnimator.hideWallpapersLocked(mWin);
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700868 }
869 } catch (RuntimeException e) {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700870 Slog.w(TAG, "Exception thrown when destroying Window "
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700871 + this + " surface " + mPendingDestroySurface
872 + " session " + mSession + ": " + e.toString());
873 }
874 mSurfaceDestroyDeferred = false;
875 mPendingDestroySurface = null;
876 }
877
878 void computeShownFrameLocked() {
879 final boolean selfTransformation = mHasLocalTransformation;
880 Transformation attachedTransformation =
Craig Mautner322e4032012-07-13 13:35:20 -0700881 (mAttachedWinAnimator != null && mAttachedWinAnimator.mHasLocalTransformation)
882 ? mAttachedWinAnimator.mTransformation : null;
883 Transformation appTransformation = (mAppAnimator != null && mAppAnimator.hasTransformation)
884 ? mAppAnimator.transformation : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700885
886 // Wallpapers are animated based on the "real" window they
887 // are currently targeting.
Craig Mautner798adef2013-10-22 14:29:01 -0700888 final WindowState wallpaperTarget = mService.mWallpaperTarget;
889 if (mIsWallpaper && wallpaperTarget != null && mService.mAnimateWallpaperWithTarget) {
890 final WindowStateAnimator wallpaperAnimator = wallpaperTarget.mWinAnimator;
Craig Mautner918b53b2012-07-09 14:15:54 -0700891 if (wallpaperAnimator.mHasLocalTransformation &&
892 wallpaperAnimator.mAnimation != null &&
893 !wallpaperAnimator.mAnimation.getDetachWallpaper()) {
894 attachedTransformation = wallpaperAnimator.mTransformation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700895 if (WindowManagerService.DEBUG_WALLPAPER && attachedTransformation != null) {
896 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
897 }
898 }
Craig Mautner798adef2013-10-22 14:29:01 -0700899 final AppWindowAnimator wpAppAnimator = wallpaperTarget.mAppToken == null ?
900 null : wallpaperTarget.mAppToken.mAppAnimator;
901 if (wpAppAnimator != null && wpAppAnimator.hasTransformation
Craig Mautner918b53b2012-07-09 14:15:54 -0700902 && wpAppAnimator.animation != null
903 && !wpAppAnimator.animation.getDetachWallpaper()) {
Craig Mautner59431632012-04-04 11:56:44 -0700904 appTransformation = wpAppAnimator.transformation;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700905 if (WindowManagerService.DEBUG_WALLPAPER && appTransformation != null) {
906 Slog.v(TAG, "WP target app xform: " + appTransformation);
907 }
908 }
909 }
910
Craig Mautnera91f9e22012-09-14 16:22:08 -0700911 final int displayId = mWin.getDisplayId();
912 final ScreenRotationAnimation screenRotationAnimation =
913 mAnimator.getScreenRotationAnimationLocked(displayId);
914 final boolean screenAnimation =
915 screenRotationAnimation != null && screenRotationAnimation.isAnimating();
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700916 if (selfTransformation || attachedTransformation != null
917 || appTransformation != null || screenAnimation) {
918 // cache often used attributes locally
919 final Rect frame = mWin.mFrame;
920 final float tmpFloats[] = mService.mTmpFloats;
921 final Matrix tmpMatrix = mWin.mTmpMatrix;
922
923 // Compute the desired transformation.
Dianne Hackborn4b169692012-11-29 17:51:24 -0800924 if (screenAnimation && screenRotationAnimation.isRotating()) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700925 // If we are doing a screen animation, the global rotation
926 // applied to windows can result in windows that are carefully
927 // aligned with each other to slightly separate, allowing you
928 // to see what is behind them. An unsightly mess. This...
929 // thing... magically makes it call good: scale each window
930 // slightly (two pixels larger in each dimension, from the
931 // window's center).
932 final float w = frame.width();
933 final float h = frame.height();
934 if (w>=1 && h>=1) {
935 tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2);
936 } else {
937 tmpMatrix.reset();
938 }
939 } else {
940 tmpMatrix.reset();
941 }
942 tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale);
943 if (selfTransformation) {
944 tmpMatrix.postConcat(mTransformation.getMatrix());
945 }
946 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
947 if (attachedTransformation != null) {
948 tmpMatrix.postConcat(attachedTransformation.getMatrix());
949 }
950 if (appTransformation != null) {
951 tmpMatrix.postConcat(appTransformation.getMatrix());
952 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700953 if (mAnimator.mUniverseBackground != null) {
954 tmpMatrix.postConcat(mAnimator.mUniverseBackground.mUniverseTransform.getMatrix());
955 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700956 if (screenAnimation) {
Craig Mautnera91f9e22012-09-14 16:22:08 -0700957 tmpMatrix.postConcat(screenRotationAnimation.getEnterTransformation().getMatrix());
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700958 }
Winson Chung399f6202014-03-19 10:47:20 -0700959
Svetoslav Ganov545252f2012-12-10 18:29:24 -0800960 //TODO (multidisplay): Magnification is supported only for the default display.
Svetoslav8e3feb12014-02-24 13:46:47 -0800961 if (mService.mAccessibilityController != null && displayId == Display.DEFAULT_DISPLAY) {
962 MagnificationSpec spec = mService.mAccessibilityController
Svetoslav Ganov545252f2012-12-10 18:29:24 -0800963 .getMagnificationSpecForWindowLocked(mWin);
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -0700964 if (spec != null && !spec.isNop()) {
965 tmpMatrix.postScale(spec.scale, spec.scale);
966 tmpMatrix.postTranslate(spec.offsetX, spec.offsetY);
967 }
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700968 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700969
970 // "convert" it into SurfaceFlinger's format
971 // (a 2x2 matrix + an offset)
972 // Here we must not transform the position of the surface
973 // since it is already included in the transformation.
974 //Slog.i(TAG, "Transform: " + matrix);
975
976 mHaveMatrix = true;
977 tmpMatrix.getValues(tmpFloats);
978 mDsDx = tmpFloats[Matrix.MSCALE_X];
979 mDtDx = tmpFloats[Matrix.MSKEW_Y];
980 mDsDy = tmpFloats[Matrix.MSKEW_X];
981 mDtDy = tmpFloats[Matrix.MSCALE_Y];
982 float x = tmpFloats[Matrix.MTRANS_X];
983 float y = tmpFloats[Matrix.MTRANS_Y];
984 int w = frame.width();
985 int h = frame.height();
986 mWin.mShownFrame.set(x, y, x+w, y+h);
987
988 // Now set the alpha... but because our current hardware
989 // can't do alpha transformation on a non-opaque surface,
990 // turn it off if we are running an animation that is also
991 // transforming since it is more important to have that
992 // animation be smooth.
993 mShownAlpha = mAlpha;
Winson Chung399f6202014-03-19 10:47:20 -0700994 mHasClipRect = false;
Craig Mautnerc2f9be02012-03-27 17:32:29 -0700995 if (!mService.mLimitedAlphaCompositing
996 || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format)
997 || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
998 && x == frame.left && y == frame.top))) {
999 //Slog.i(TAG, "Applying alpha transform");
1000 if (selfTransformation) {
1001 mShownAlpha *= mTransformation.getAlpha();
1002 }
1003 if (attachedTransformation != null) {
1004 mShownAlpha *= attachedTransformation.getAlpha();
1005 }
1006 if (appTransformation != null) {
1007 mShownAlpha *= appTransformation.getAlpha();
Winson Chung399f6202014-03-19 10:47:20 -07001008 if (appTransformation.hasClipRect()) {
1009 mClipRect.set(appTransformation.getClipRect());
1010 mHasClipRect = true;
1011 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001012 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001013 if (mAnimator.mUniverseBackground != null) {
1014 mShownAlpha *= mAnimator.mUniverseBackground.mUniverseTransform.getAlpha();
1015 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001016 if (screenAnimation) {
Craig Mautnera91f9e22012-09-14 16:22:08 -07001017 mShownAlpha *= screenRotationAnimation.getEnterTransformation().getAlpha();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001018 }
1019 } else {
1020 //Slog.i(TAG, "Not applying alpha transform");
1021 }
1022
Craig Mautnera91f9e22012-09-14 16:22:08 -07001023 if ((DEBUG_SURFACE_TRACE || WindowManagerService.localLOGV)
1024 && (mShownAlpha == 1.0 || mShownAlpha == 0.0)) Slog.v(
1025 TAG, "computeShownFrameLocked: Animating " + this + " mAlpha=" + mAlpha
1026 + " self=" + (selfTransformation ? mTransformation.getAlpha() : "null")
1027 + " attached=" + (attachedTransformation == null ?
1028 "null" : attachedTransformation.getAlpha())
1029 + " app=" + (appTransformation == null ? "null" : appTransformation.getAlpha())
1030 + " screen=" + (screenAnimation ?
1031 screenRotationAnimation.getEnterTransformation().getAlpha() : "null"));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001032 return;
Craig Mautner96868332012-12-04 14:29:11 -08001033 } else if (mIsWallpaper && mService.mInnerFields.mWallpaperActionPending) {
Craig Mautner4d7349b2012-04-20 14:52:47 -07001034 return;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001035 }
1036
1037 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautner4d7349b2012-04-20 14:52:47 -07001038 TAG, "computeShownFrameLocked: " + this +
1039 " not attached, mAlpha=" + mAlpha);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001040
1041 final boolean applyUniverseTransformation = (mAnimator.mUniverseBackground != null
1042 && mWin.mAttrs.type != WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND
1043 && mWin.mBaseLayer < mAnimator.mAboveUniverseLayer);
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001044 MagnificationSpec spec = null;
1045 //TODO (multidisplay): Magnification is supported only for the default display.
Svetoslav8e3feb12014-02-24 13:46:47 -08001046 if (mService.mAccessibilityController != null && displayId == Display.DEFAULT_DISPLAY) {
1047 spec = mService.mAccessibilityController.getMagnificationSpecForWindowLocked(mWin);
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001048 }
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001049 if (applyUniverseTransformation || spec != null) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001050 final Rect frame = mWin.mFrame;
1051 final float tmpFloats[] = mService.mTmpFloats;
1052 final Matrix tmpMatrix = mWin.mTmpMatrix;
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001053
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001054 tmpMatrix.setScale(mWin.mGlobalScale, mWin.mGlobalScale);
1055 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001056
1057 if (applyUniverseTransformation) {
1058 tmpMatrix.postConcat(mAnimator.mUniverseBackground.mUniverseTransform.getMatrix());
1059 }
1060
1061 if (spec != null && !spec.isNop()) {
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -07001062 tmpMatrix.postScale(spec.scale, spec.scale);
1063 tmpMatrix.postTranslate(spec.offsetX, spec.offsetY);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001064 }
1065
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001066 tmpMatrix.getValues(tmpFloats);
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001067
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001068 mHaveMatrix = true;
1069 mDsDx = tmpFloats[Matrix.MSCALE_X];
1070 mDtDx = tmpFloats[Matrix.MSKEW_Y];
1071 mDsDy = tmpFloats[Matrix.MSKEW_X];
1072 mDtDy = tmpFloats[Matrix.MSCALE_Y];
1073 float x = tmpFloats[Matrix.MTRANS_X];
1074 float y = tmpFloats[Matrix.MTRANS_Y];
1075 int w = frame.width();
1076 int h = frame.height();
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07001077 mWin.mShownFrame.set(x, y, x + w, y + h);
1078
1079 mShownAlpha = mAlpha;
1080 if (applyUniverseTransformation) {
1081 mShownAlpha *= mAnimator.mUniverseBackground.mUniverseTransform.getAlpha();
1082 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001083 } else {
1084 mWin.mShownFrame.set(mWin.mFrame);
1085 if (mWin.mXOffset != 0 || mWin.mYOffset != 0) {
1086 mWin.mShownFrame.offset(mWin.mXOffset, mWin.mYOffset);
1087 }
1088 mShownAlpha = mAlpha;
1089 mHaveMatrix = false;
1090 mDsDx = mWin.mGlobalScale;
1091 mDtDx = 0;
1092 mDsDy = 0;
1093 mDtDy = mWin.mGlobalScale;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001094 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001095 }
1096
1097 void applyDecorRect(final Rect decorRect) {
1098 final WindowState w = mWin;
1099 // Compute the offset of the window in relation to the decor rect.
1100 final int offX = w.mXOffset + w.mFrame.left;
1101 final int offY = w.mYOffset + w.mFrame.top;
1102 // Initialize the decor rect to the entire frame.
1103 w.mSystemDecorRect.set(0, 0, w.mFrame.width(), w.mFrame.height());
1104 // Intersect with the decor rect, offsetted by window position.
1105 w.mSystemDecorRect.intersect(decorRect.left-offX, decorRect.top-offY,
1106 decorRect.right-offX, decorRect.bottom-offY);
1107 // If size compatibility is being applied to the window, the
1108 // surface is scaled relative to the screen. Also apply this
1109 // scaling to the crop rect. We aren't using the standard rect
1110 // scale function because we want to round things to make the crop
1111 // always round to a larger rect to ensure we don't crop too
1112 // much and hide part of the window that should be seen.
1113 if (w.mEnforceSizeCompat && w.mInvGlobalScale != 1.0f) {
1114 final float scale = w.mInvGlobalScale;
1115 w.mSystemDecorRect.left = (int) (w.mSystemDecorRect.left * scale - 0.5f);
1116 w.mSystemDecorRect.top = (int) (w.mSystemDecorRect.top * scale - 0.5f);
1117 w.mSystemDecorRect.right = (int) ((w.mSystemDecorRect.right+1) * scale - 0.5f);
1118 w.mSystemDecorRect.bottom = (int) ((w.mSystemDecorRect.bottom+1) * scale - 0.5f);
1119 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001120 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001121
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001122 void updateSurfaceWindowCrop(final boolean recoveringMemory) {
1123 final WindowState w = mWin;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001124 final DisplayContent displayContent = w.getDisplayContent();
1125 if (displayContent == null) {
1126 return;
1127 }
1128 DisplayInfo displayInfo = displayContent.getDisplayInfo();
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001129
1130 // Need to recompute a new system decor rect each time.
1131 if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
1132 // Currently can't do this cropping for scaled windows. We'll
1133 // just keep the crop rect the same as the source surface.
1134 w.mSystemDecorRect.set(0, 0, w.mRequestedWidth, w.mRequestedHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07001135 } else if (!w.isDefaultDisplay()) {
Jeff Brown28e0b092012-09-25 11:31:28 -07001136 // On a different display there is no system decor. Crop the window
1137 // by the screen boundaries.
Jeff Brown36714102012-09-24 17:36:06 -07001138 w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height());
Jeff Brown28e0b092012-09-25 11:31:28 -07001139 w.mSystemDecorRect.intersect(-w.mCompatFrame.left, -w.mCompatFrame.top,
1140 displayInfo.logicalWidth - w.mCompatFrame.left,
1141 displayInfo.logicalHeight - w.mCompatFrame.top);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001142 } else if (w.mLayer >= mService.mSystemDecorLayer) {
1143 // Above the decor layer is easy, just use the entire window.
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001144 // Unless we have a universe background... in which case all the
1145 // windows need to be cropped by the screen, so they don't cover
1146 // the universe background.
1147 if (mAnimator.mUniverseBackground == null) {
1148 w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(),
1149 w.mCompatFrame.height());
1150 } else {
1151 applyDecorRect(mService.mScreenRect);
1152 }
John Spurlock46646232013-09-30 22:32:42 -04001153 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND
1154 || w.mDecorFrame.isEmpty()) {
1155 // The universe background isn't cropped, nor windows without policy decor.
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001156 w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(),
1157 w.mCompatFrame.height());
1158 } else {
John Spurlock46646232013-09-30 22:32:42 -04001159 // Crop to the system decor specified by policy.
1160 applyDecorRect(w.mDecorFrame);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001161 }
1162
Winson Chung399f6202014-03-19 10:47:20 -07001163 // By default, the clip rect is the system decor rect
1164 Rect clipRect = w.mSystemDecorRect;
1165 if (mHasClipRect) {
1166
1167 // If we have an animated clip rect, intersect it with the system decor rect
Winson Chung96d970c2014-03-20 18:04:46 -07001168 // NOTE: We are adding a temporary workaround due to the status bar not always reporting
1169 // the correct system decor rect. In such cases, we take into account the specified
1170 // content insets as well.
1171 int offsetTop = Math.max(w.mSystemDecorRect.top, w.mContentInsets.top);
Winson Chung399f6202014-03-19 10:47:20 -07001172 mTmpClipRect.set(w.mSystemDecorRect);
1173 mTmpClipRect.offset(0, -offsetTop);
1174 mTmpClipRect.intersect(mClipRect);
1175 mTmpClipRect.offset(0, offsetTop);
1176 clipRect = mTmpClipRect;
1177
1178 }
1179
1180 if (!clipRect.equals(mLastClipRect)) {
1181 mLastClipRect.set(clipRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001182 try {
1183 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
Winson Chung399f6202014-03-19 10:47:20 -07001184 "CROP " + clipRect.toShortString(), null);
1185 mSurfaceControl.setWindowCrop(clipRect);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001186 } catch (RuntimeException e) {
1187 Slog.w(TAG, "Error setting crop surface of " + w
Winson Chung399f6202014-03-19 10:47:20 -07001188 + " crop=" + clipRect.toShortString(), e);
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001189 if (!recoveringMemory) {
1190 mService.reclaimSomeSurfaceMemoryLocked(this, "crop", true);
1191 }
1192 }
1193 }
1194 }
1195
Craig Mautnera91f9e22012-09-14 16:22:08 -07001196 void setSurfaceBoundariesLocked(final boolean recoveringMemory) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001197 final WindowState w = mWin;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001198 int width, height;
1199 if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
1200 // for a scaled surface, we just want to use
1201 // the requested size.
1202 width = w.mRequestedWidth;
1203 height = w.mRequestedHeight;
1204 } else {
1205 width = w.mCompatFrame.width();
1206 height = w.mCompatFrame.height();
1207 }
1208
1209 if (width < 1) {
1210 width = 1;
1211 }
1212 if (height < 1) {
1213 height = 1;
1214 }
1215 final boolean surfaceResized = mSurfaceW != width || mSurfaceH != height;
1216 if (surfaceResized) {
1217 mSurfaceW = width;
1218 mSurfaceH = height;
1219 }
1220
Craig Mautner4d7349b2012-04-20 14:52:47 -07001221 final float left = w.mShownFrame.left;
1222 final float top = w.mShownFrame.top;
1223 if (mSurfaceX != left || mSurfaceY != top) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001224 try {
1225 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
Craig Mautner4d7349b2012-04-20 14:52:47 -07001226 "POS " + left + ", " + top, null);
1227 mSurfaceX = left;
1228 mSurfaceY = top;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001229 mSurfaceControl.setPosition(left, top);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001230 } catch (RuntimeException e) {
1231 Slog.w(TAG, "Error positioning surface of " + w
Craig Mautner4d7349b2012-04-20 14:52:47 -07001232 + " pos=(" + left
1233 + "," + top + ")", e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001234 if (!recoveringMemory) {
1235 mService.reclaimSomeSurfaceMemoryLocked(this, "position", true);
1236 }
1237 }
1238 }
1239
1240 if (surfaceResized) {
1241 try {
1242 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1243 "SIZE " + width + "x" + height, null);
1244 mSurfaceResized = true;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001245 mSurfaceControl.setSize(width, height);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001246 mAnimator.setPendingLayoutChanges(w.getDisplayId(),
Craig Mautner76a71652012-09-03 23:23:58 -07001247 WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
Craig Mautner3a67f352012-05-07 11:21:33 -07001248 if ((w.mAttrs.flags & LayoutParams.FLAG_DIM_BEHIND) != 0) {
Craig Mautner05d29032013-05-03 13:40:13 -07001249 w.getStack().startDimmingIfNeeded(this);
Craig Mautner3a67f352012-05-07 11:21:33 -07001250 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001251 } catch (RuntimeException e) {
1252 // If something goes wrong with the surface (such
1253 // as running out of memory), don't take down the
1254 // entire system.
1255 Slog.e(TAG, "Error resizing surface of " + w
1256 + " size=(" + width + "x" + height + ")", e);
1257 if (!recoveringMemory) {
1258 mService.reclaimSomeSurfaceMemoryLocked(this, "size", true);
1259 }
1260 }
1261 }
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07001262
Dianne Hackborn3e52fc22012-05-15 17:58:02 -07001263 updateSurfaceWindowCrop(recoveringMemory);
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001264 }
1265
1266 public void prepareSurfaceLocked(final boolean recoveringMemory) {
1267 final WindowState w = mWin;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001268 if (mSurfaceControl == null) {
Craig Mautneracaf9cc2012-04-17 11:45:25 -07001269 if (w.mOrientationChanging) {
1270 if (DEBUG_ORIENTATION) {
1271 Slog.v(TAG, "Orientation change skips hidden " + w);
1272 }
1273 w.mOrientationChanging = false;
1274 }
1275 return;
1276 }
1277
1278 boolean displayed = false;
1279
1280 computeShownFrameLocked();
1281
Craig Mautnera91f9e22012-09-14 16:22:08 -07001282 setSurfaceBoundariesLocked(recoveringMemory);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001283
Craig Mautner918b53b2012-07-09 14:15:54 -07001284 if (mIsWallpaper && !mWin.mWallpaperVisible) {
Craig Mautner0fa77c12012-06-11 15:57:19 -07001285 // Wallpaper is no longer visible and there is no wp target => hide it.
1286 hide();
Craig Mautner72669d12012-12-18 17:23:54 -08001287 } else if (w.mAttachedHidden || !w.isOnScreen()) {
Craig Mautner0afddcb2012-05-08 15:38:00 -07001288 hide();
Craig Mautner96868332012-12-04 14:29:11 -08001289 mAnimator.hideWallpapersLocked(w);
Craig Mautnerb9836b92012-06-11 11:40:09 -07001290
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001291 // If we are waiting for this window to handle an
1292 // orientation change, well, it is hidden, so
1293 // doesn't really matter. Note that this does
1294 // introduce a potential glitch if the window
1295 // becomes unhidden before it has drawn for the
1296 // new orientation.
1297 if (w.mOrientationChanging) {
1298 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001299 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001300 "Orientation change skips hidden " + w);
1301 }
1302 } else if (mLastLayer != mAnimLayer
1303 || mLastAlpha != mShownAlpha
1304 || mLastDsDx != mDsDx
1305 || mLastDtDx != mDtDx
1306 || mLastDsDy != mDsDy
1307 || mLastDtDy != mDtDy
1308 || w.mLastHScale != w.mHScale
1309 || w.mLastVScale != w.mVScale
Craig Mautner749a7bb2012-04-02 13:49:53 -07001310 || mLastHidden) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001311 displayed = true;
1312 mLastAlpha = mShownAlpha;
1313 mLastLayer = mAnimLayer;
1314 mLastDsDx = mDsDx;
1315 mLastDtDx = mDtDx;
1316 mLastDsDy = mDsDy;
1317 mLastDtDy = mDtDy;
1318 w.mLastHScale = w.mHScale;
1319 w.mLastVScale = w.mVScale;
1320 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1321 "alpha=" + mShownAlpha + " layer=" + mAnimLayer
1322 + " matrix=[" + (mDsDx*w.mHScale)
1323 + "," + (mDtDx*w.mVScale)
1324 + "][" + (mDsDy*w.mHScale)
1325 + "," + (mDtDy*w.mVScale) + "]", null);
Mathias Agopian29479eb2013-02-14 14:36:04 -08001326 if (mSurfaceControl != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001327 try {
1328 mSurfaceAlpha = mShownAlpha;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001329 mSurfaceControl.setAlpha(mShownAlpha);
Craig Mautnerad5725d2012-06-05 10:20:56 -07001330 mSurfaceLayer = mAnimLayer;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001331 mSurfaceControl.setLayer(mAnimLayer);
1332 mSurfaceControl.setMatrix(
Winson Chung399f6202014-03-19 10:47:20 -07001333 mDsDx * w.mHScale, mDtDx * w.mVScale,
1334 mDsDy * w.mHScale, mDtDy * w.mVScale);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001335
1336 if (mLastHidden && mDrawState == HAS_DRAWN) {
1337 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
1338 "SHOW (performLayout)", null);
1339 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
1340 + " during relayout");
1341 if (showSurfaceRobustlyLocked()) {
1342 mLastHidden = false;
Craig Mautner918b53b2012-07-09 14:15:54 -07001343 if (mIsWallpaper) {
Craig Mautner507a2ee2012-06-13 08:39:38 -07001344 mService.dispatchWallpaperVisibility(w, true);
1345 }
Craig Mautner8efb0a42013-08-08 14:59:00 -07001346 // This draw means the difference between unique content and mirroring.
1347 // Run another pass through performLayout to set mHasContent in the
1348 // LogicalDisplay.
1349 mAnimator.setPendingLayoutChanges(w.getDisplayId(),
1350 WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001351 } else {
1352 w.mOrientationChanging = false;
1353 }
1354 }
Mathias Agopian29479eb2013-02-14 14:36:04 -08001355 if (mSurfaceControl != null) {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001356 w.mToken.hasVisible = true;
1357 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001358 } catch (RuntimeException e) {
1359 Slog.w(TAG, "Error updating surface in " + w, e);
1360 if (!recoveringMemory) {
1361 mService.reclaimSomeSurfaceMemoryLocked(this, "update", true);
1362 }
1363 }
1364 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001365 } else {
Craig Mautner9e809442012-06-22 17:13:04 -07001366 if (DEBUG_ANIM && isAnimating()) {
1367 Slog.v(TAG, "prepareSurface: No changes in animation for " + this);
Craig Mautner83339b42012-05-01 22:13:23 -07001368 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001369 displayed = true;
1370 }
1371
1372 if (displayed) {
1373 if (w.mOrientationChanging) {
1374 if (!w.isDrawnLw()) {
Craig Mautner2639da52012-07-09 09:39:06 -07001375 mAnimator.mBulkUpdateParams &= ~SET_ORIENTATION_CHANGE_COMPLETE;
Dianne Hackborna57c6952013-03-29 14:46:40 -07001376 mAnimator.mLastWindowFreezeSource = w;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001377 if (DEBUG_ORIENTATION) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001378 "Orientation continue waiting for draw in " + w);
1379 } else {
1380 w.mOrientationChanging = false;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001381 if (DEBUG_ORIENTATION) Slog.v(TAG, "Orientation change complete in " + w);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001382 }
1383 }
1384 w.mToken.hasVisible = true;
1385 }
1386 }
1387
Craig Mautneref655012013-01-03 11:20:24 -08001388 void setTransparentRegionHintLocked(final Region region) {
Mathias Agopian29479eb2013-02-14 14:36:04 -08001389 if (mSurfaceControl == null) {
Craig Mautner1f4e0cc2012-04-10 14:24:38 -07001390 Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true");
1391 return;
1392 }
Craig Mautner71dd1b62014-02-18 15:48:52 -08001393 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setTransparentRegion");
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001394 SurfaceControl.openTransaction();
Craig Mautner48ba1e72012-04-02 13:18:16 -07001395 try {
1396 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
1397 "transparentRegionHint=" + region, null);
Mathias Agopian29479eb2013-02-14 14:36:04 -08001398 mSurfaceControl.setTransparentRegionHint(region);
Craig Mautner48ba1e72012-04-02 13:18:16 -07001399 } finally {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001400 SurfaceControl.closeTransaction();
Craig Mautner48ba1e72012-04-02 13:18:16 -07001401 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1402 "<<< CLOSE TRANSACTION setTransparentRegion");
1403 }
1404 }
1405
Craig Mautner58106812012-12-28 12:27:40 -08001406 void setWallpaperOffset(RectF shownFrame) {
1407 final int left = (int) shownFrame.left;
1408 final int top = (int) shownFrame.top;
1409 if (mSurfaceX != left || mSurfaceY != top) {
1410 mSurfaceX = left;
1411 mSurfaceY = top;
1412 if (mAnimating) {
1413 // If this window (or its app token) is animating, then the position
1414 // of the surface will be re-computed on the next animation frame.
1415 // We can't poke it directly here because it depends on whatever
1416 // transformation is being applied by the animation.
1417 return;
1418 }
Craig Mautner71dd1b62014-02-18 15:48:52 -08001419 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setWallpaperOffset");
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001420 SurfaceControl.openTransaction();
Craig Mautner58106812012-12-28 12:27:40 -08001421 try {
1422 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
1423 "POS " + left + ", " + top, null);
Mathias Agopian29479eb2013-02-14 14:36:04 -08001424 mSurfaceControl.setPosition(mWin.mFrame.left + left, mWin.mFrame.top + top);
Craig Mautner58106812012-12-28 12:27:40 -08001425 updateSurfaceWindowCrop(false);
1426 } catch (RuntimeException e) {
1427 Slog.w(TAG, "Error positioning surface of " + mWin
1428 + " pos=(" + left + "," + top + ")", e);
1429 } finally {
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001430 SurfaceControl.closeTransaction();
Craig Mautner58106812012-12-28 12:27:40 -08001431 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
1432 "<<< CLOSE TRANSACTION setWallpaperOffset");
1433 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001434 }
Craig Mautner48ba1e72012-04-02 13:18:16 -07001435 }
1436
Craig Mautner71dd1b62014-02-18 15:48:52 -08001437 void setOpaque(boolean isOpaque) {
1438 if (mSurfaceControl == null) {
1439 return;
1440 }
1441 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setOpaque");
1442 SurfaceControl.openTransaction();
1443 try {
1444 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, "isOpaque=" + isOpaque,
1445 null);
1446 mSurfaceControl.setOpaque(isOpaque);
1447 } finally {
1448 SurfaceControl.closeTransaction();
1449 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION setOpaque");
1450 }
1451 }
1452
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001453 // This must be called while inside a transaction.
1454 boolean performShowLocked() {
Craig Mautner5962b122012-10-05 14:45:52 -07001455 if (mWin.isHiddenFromUserLocked()) {
Craig Mautner88400d32012-09-30 12:35:45 -07001456 Slog.w(TAG, "current user violation " + mService.mCurrentUserId + " trying to display "
Craig Mautnera2d7b112012-08-21 15:12:20 -07001457 + this + ", type " + mWin.mAttrs.type + ", belonging to " + mWin.mOwnerUid);
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001458 return false;
1459 }
Craig Mautner6fbda632012-07-03 09:26:39 -07001460 if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
1461 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001462 RuntimeException e = null;
1463 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
1464 e = new RuntimeException();
1465 e.fillInStackTrace();
1466 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001467 Slog.v(TAG, "performShow on " + this
Craig Mautner749a7bb2012-04-02 13:49:53 -07001468 + ": mDrawState=" + mDrawState + " readyForDisplay="
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001469 + mWin.isReadyForDisplayIgnoringKeyguard()
Craig Mautner6fbda632012-07-03 09:26:39 -07001470 + " starting=" + (mWin.mAttrs.type == TYPE_APPLICATION_STARTING)
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001471 + " during animation: policyVis=" + mWin.mPolicyVisibility
1472 + " attHidden=" + mWin.mAttachedHidden
1473 + " tok.hiddenRequested="
1474 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
1475 + " tok.hidden="
1476 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
1477 + " animating=" + mAnimating
1478 + " tok animating="
Craig Mautner322e4032012-07-13 13:35:20 -07001479 + (mAppAnimator != null ? mAppAnimator.animating : false), e);
Craig Mautner6fbda632012-07-03 09:26:39 -07001480 }
1481 if (mDrawState == READY_TO_SHOW && mWin.isReadyForDisplayIgnoringKeyguard()) {
1482 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
1483 WindowManagerService.logSurface(mWin, "SHOW (performShowLocked)", null);
1484 if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
1485 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
1486 Slog.v(TAG, "Showing " + this
1487 + " during animation: policyVis=" + mWin.mPolicyVisibility
1488 + " attHidden=" + mWin.mAttachedHidden
1489 + " tok.hiddenRequested="
1490 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
1491 + " tok.hidden="
1492 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
1493 + " animating=" + mAnimating
1494 + " tok animating="
Craig Mautner322e4032012-07-13 13:35:20 -07001495 + (mAppAnimator != null ? mAppAnimator.animating : false));
Craig Mautner6fbda632012-07-03 09:26:39 -07001496 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001497
1498 mService.enableScreenIfNeededLocked();
1499
1500 applyEnterAnimationLocked();
1501
Craig Mautnerde6198e2012-04-19 09:59:31 -07001502 // Force the show in the next prepareSurfaceLocked() call.
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001503 mLastAlpha = -1;
Craig Mautneref25d7a2012-05-15 23:01:47 -07001504 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM)
1505 Slog.v(TAG, "performShowLocked: mDrawState=HAS_DRAWN in " + this);
Craig Mautner749a7bb2012-04-02 13:49:53 -07001506 mDrawState = HAS_DRAWN;
Craig Mautner96868332012-12-04 14:29:11 -08001507 mService.scheduleAnimationLocked();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001508
1509 int i = mWin.mChildWindows.size();
1510 while (i > 0) {
1511 i--;
1512 WindowState c = mWin.mChildWindows.get(i);
1513 if (c.mAttachedHidden) {
1514 c.mAttachedHidden = false;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001515 if (c.mWinAnimator.mSurfaceControl != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001516 c.mWinAnimator.performShowLocked();
1517 // It hadn't been shown, which means layout not
1518 // performed on it, so now we want to make sure to
1519 // do a layout. If called from within the transaction
1520 // loop, this will cause it to restart with a new
1521 // layout.
Craig Mautnerdf88d732014-01-27 09:21:32 -08001522 final DisplayContent displayContent = c.getDisplayContent();
1523 if (displayContent != null) {
1524 displayContent.layoutNeeded = true;
1525 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001526 }
1527 }
1528 }
1529
1530 if (mWin.mAttrs.type != TYPE_APPLICATION_STARTING
1531 && mWin.mAppToken != null) {
1532 mWin.mAppToken.firstWindowDrawn = true;
1533
1534 if (mWin.mAppToken.startingData != null) {
1535 if (WindowManagerService.DEBUG_STARTING_WINDOW ||
Craig Mautnerd87946b2012-03-29 18:00:19 -07001536 WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001537 "Finish starting " + mWin.mToken
1538 + ": first real window is shown, no animation");
1539 // If this initial window is animating, stop it -- we
1540 // will do an animation to reveal it from behind the
1541 // starting window, so there is no need for it to also
1542 // be doing its own stuff.
Craig Mautner4d7349b2012-04-20 14:52:47 -07001543 clearAnimation();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001544 mService.mFinishedStarting.add(mWin.mAppToken);
1545 mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
1546 }
1547 mWin.mAppToken.updateReportedVisibilityLocked();
1548 }
1549
1550 return true;
1551 }
1552
1553 return false;
1554 }
1555
1556 /**
1557 * Have the surface flinger show a surface, robustly dealing with
1558 * error conditions. In particular, if there is not enough memory
1559 * to show the surface, then we will try to get rid of other surfaces
1560 * in order to succeed.
1561 *
1562 * @return Returns true if the surface was successfully shown.
1563 */
1564 boolean showSurfaceRobustlyLocked() {
1565 try {
Mathias Agopian29479eb2013-02-14 14:36:04 -08001566 if (mSurfaceControl != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001567 mSurfaceShown = true;
Mathias Agopian29479eb2013-02-14 14:36:04 -08001568 mSurfaceControl.show();
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001569 if (mWin.mTurnOnScreen) {
1570 if (DEBUG_VISIBILITY) Slog.v(TAG,
1571 "Show surface turning screen on: " + mWin);
1572 mWin.mTurnOnScreen = false;
Craig Mautner7d8df392012-04-06 15:26:23 -07001573 mAnimator.mBulkUpdateParams |= SET_TURN_ON_SCREEN;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001574 }
1575 }
1576 return true;
1577 } catch (RuntimeException e) {
Mathias Agopian29479eb2013-02-14 14:36:04 -08001578 Slog.w(TAG, "Failure showing surface " + mSurfaceControl + " in " + mWin, e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001579 }
1580
1581 mService.reclaimSomeSurfaceMemoryLocked(this, "show", true);
1582
1583 return false;
1584 }
1585
1586 void applyEnterAnimationLocked() {
1587 final int transit;
1588 if (mEnterAnimationPending) {
1589 mEnterAnimationPending = false;
1590 transit = WindowManagerPolicy.TRANSIT_ENTER;
1591 } else {
1592 transit = WindowManagerPolicy.TRANSIT_SHOW;
1593 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001594 applyAnimationLocked(transit, true);
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001595 //TODO (multidisplay): Magnification is supported only for the default display.
Svetoslav8e3feb12014-02-24 13:46:47 -08001596 if (mService.mAccessibilityController != null
Svetoslav Ganov545252f2012-12-10 18:29:24 -08001597 && mWin.getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslav8e3feb12014-02-24 13:46:47 -08001598 mService.mAccessibilityController.onWindowTransitionLocked(mWin, transit);
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -07001599 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001600 }
1601
1602 /**
1603 * Choose the correct animation and set it to the passed WindowState.
Craig Mautner4b71aa12012-12-27 17:20:01 -08001604 * @param transit If AppTransition.TRANSIT_PREVIEW_DONE and the app window has been drawn
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001605 * then the animation will be app_starting_exit. Any other value loads the animation from
1606 * the switch statement below.
1607 * @param isEntrance The animation type the last time this was called. Used to keep from
1608 * loading the same animation twice.
1609 * @return true if an animation has been loaded.
1610 */
1611 boolean applyAnimationLocked(int transit, boolean isEntrance) {
1612 if (mLocalAnimating && mAnimationIsEntrance == isEntrance) {
1613 // If we are trying to apply an animation, but already running
1614 // an animation of the same type, then just leave that one alone.
1615 return true;
1616 }
1617
1618 // Only apply an animation if the display isn't frozen. If it is
1619 // frozen, there is no reason to animate and it can cause strange
1620 // artifacts when we unfreeze the display if some different animation
1621 // is running.
1622 if (mService.okToDisplay()) {
1623 int anim = mPolicy.selectAnimationLw(mWin, transit);
1624 int attr = -1;
1625 Animation a = null;
1626 if (anim != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001627 a = anim != -1 ? AnimationUtils.loadAnimation(mContext, anim) : null;
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001628 } else {
1629 switch (transit) {
1630 case WindowManagerPolicy.TRANSIT_ENTER:
1631 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
1632 break;
1633 case WindowManagerPolicy.TRANSIT_EXIT:
1634 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
1635 break;
1636 case WindowManagerPolicy.TRANSIT_SHOW:
1637 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
1638 break;
1639 case WindowManagerPolicy.TRANSIT_HIDE:
1640 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
1641 break;
1642 }
1643 if (attr >= 0) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001644 a = mService.mAppTransition.loadAnimation(mWin.mAttrs, attr);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001645 }
1646 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001647 if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001648 "applyAnimation: win=" + this
1649 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
Craig Mautner4d7349b2012-04-20 14:52:47 -07001650 + " a=" + a
Craig Mautner8863cca2012-09-18 15:04:34 -07001651 + " transit=" + transit
Craig Mautner83339b42012-05-01 22:13:23 -07001652 + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001653 if (a != null) {
1654 if (WindowManagerService.DEBUG_ANIM) {
1655 RuntimeException e = null;
1656 if (!WindowManagerService.HIDE_STACK_CRAWLS) {
1657 e = new RuntimeException();
1658 e.fillInStackTrace();
1659 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001660 Slog.v(TAG, "Loaded animation " + a + " for " + this, e);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001661 }
1662 setAnimation(a);
1663 mAnimationIsEntrance = isEntrance;
1664 }
1665 } else {
1666 clearAnimation();
1667 }
1668
1669 return mAnimation != null;
1670 }
1671
Craig Mautnera2c77052012-03-26 12:14:43 -07001672 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1673 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
1674 || mAnimation != null) {
1675 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
1676 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
1677 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
1678 pw.print(" mAnimation="); pw.println(mAnimation);
1679 }
1680 if (mHasTransformation || mHasLocalTransformation) {
1681 pw.print(prefix); pw.print("XForm: has=");
1682 pw.print(mHasTransformation);
1683 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
1684 pw.print(" "); mTransformation.printShortString(pw);
1685 pw.println();
1686 }
Mathias Agopian29479eb2013-02-14 14:36:04 -08001687 if (mSurfaceControl != null) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001688 if (dumpAll) {
Mathias Agopian29479eb2013-02-14 14:36:04 -08001689 pw.print(prefix); pw.print("mSurface="); pw.println(mSurfaceControl);
Craig Mautner6fbda632012-07-03 09:26:39 -07001690 pw.print(prefix); pw.print("mDrawState=");
1691 pw.print(drawStateToString(mDrawState));
Craig Mautner749a7bb2012-04-02 13:49:53 -07001692 pw.print(" mLastHidden="); pw.println(mLastHidden);
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001693 }
1694 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
1695 pw.print(" layer="); pw.print(mSurfaceLayer);
1696 pw.print(" alpha="); pw.print(mSurfaceAlpha);
1697 pw.print(" rect=("); pw.print(mSurfaceX);
1698 pw.print(","); pw.print(mSurfaceY);
1699 pw.print(") "); pw.print(mSurfaceW);
1700 pw.print(" x "); pw.println(mSurfaceH);
1701 }
1702 if (mPendingDestroySurface != null) {
1703 pw.print(prefix); pw.print("mPendingDestroySurface=");
1704 pw.println(mPendingDestroySurface);
1705 }
1706 if (mSurfaceResized || mSurfaceDestroyDeferred) {
1707 pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized);
1708 pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred);
1709 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001710 if (mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND) {
1711 pw.print(prefix); pw.print("mUniverseTransform=");
1712 mUniverseTransform.printShortString(pw);
1713 pw.println();
1714 }
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001715 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
1716 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
1717 pw.print(" mAlpha="); pw.print(mAlpha);
1718 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
1719 }
1720 if (mHaveMatrix || mWin.mGlobalScale != 1) {
1721 pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale);
1722 pw.print(" mDsDx="); pw.print(mDsDx);
1723 pw.print(" mDtDx="); pw.print(mDtDx);
1724 pw.print(" mDsDy="); pw.print(mDsDy);
1725 pw.print(" mDtDy="); pw.println(mDtDy);
1726 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001727 }
1728
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001729 @Override
1730 public String toString() {
Dianne Hackborn529e7442012-11-01 14:22:28 -07001731 StringBuffer sb = new StringBuffer("WindowStateAnimator{");
1732 sb.append(Integer.toHexString(System.identityHashCode(this)));
1733 sb.append(' ');
1734 sb.append(mWin.mAttrs.getTitle());
1735 sb.append('}');
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001736 return sb.toString();
1737 }
Craig Mautnera2c77052012-03-26 12:14:43 -07001738}