WindowStateAnimator.java revision 4a0ffb004a62595b6aac598445908013ab9d9915
1/* 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 */ 16 17package com.android.server.wm; 18 19import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; 20import 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; 30import static com.android.server.wm.WindowManagerService.LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE; 31import static com.android.server.wm.WindowManagerService.LayoutFields.SET_TURN_ON_SCREEN; 32 33import android.content.Context; 34import android.graphics.Matrix; 35import android.graphics.PixelFormat; 36import android.graphics.Point; 37import android.graphics.PointF; 38import android.graphics.Rect; 39import android.graphics.RectF; 40import android.graphics.Region; 41import android.os.Debug; 42import android.util.Slog; 43import android.view.Display; 44import android.view.DisplayInfo; 45import android.view.MagnificationSpec; 46import android.view.Surface.OutOfResourcesException; 47import android.view.SurfaceControl; 48import android.view.SurfaceSession; 49import android.view.View; 50import android.view.WindowManager; 51import android.view.WindowManagerPolicy; 52import android.view.WindowManager.LayoutParams; 53import android.view.animation.Animation; 54import android.view.animation.AnimationUtils; 55import android.view.animation.Transformation; 56 57import com.android.server.wm.WindowManagerService.H; 58 59import java.io.PrintWriter; 60import java.util.ArrayList; 61 62class WinAnimatorList extends ArrayList<WindowStateAnimator> { 63} 64 65/** 66 * Keep track of animations and surface operations for a single WindowState. 67 **/ 68class WindowStateAnimator { 69 static final String TAG = "WindowStateAnimator"; 70 71 // Unchanging local convenience fields. 72 final WindowManagerService mService; 73 final WindowState mWin; 74 final WindowStateAnimator mAttachedWinAnimator; 75 final WindowAnimator mAnimator; 76 AppWindowAnimator mAppAnimator; 77 final Session mSession; 78 final WindowManagerPolicy mPolicy; 79 final Context mContext; 80 final boolean mIsWallpaper; 81 82 // If this is a universe background window, this is the transformation 83 // it is applying to the rest of the universe. 84 final Transformation mUniverseTransform = new Transformation(); 85 86 // Currently running animation. 87 boolean mAnimating; 88 boolean mLocalAnimating; 89 Animation mAnimation; 90 boolean mAnimationIsEntrance; 91 boolean mHasTransformation; 92 boolean mHasLocalTransformation; 93 final Transformation mTransformation = new Transformation(); 94 boolean mWasAnimating; // Were we animating going into the most recent animation step? 95 int mAnimLayer; 96 int mLastLayer; 97 98 SurfaceControl mSurfaceControl; 99 SurfaceControl mPendingDestroySurface; 100 101 /** 102 * Set when we have changed the size of the surface, to know that 103 * we must tell them application to resize (and thus redraw itself). 104 */ 105 boolean mSurfaceResized; 106 107 /** 108 * Set if the client has asked that the destroy of its surface be delayed 109 * until it explicitly says it is okay. 110 */ 111 boolean mSurfaceDestroyDeferred; 112 113 float mShownAlpha = 0; 114 float mAlpha = 0; 115 float mLastAlpha = 0; 116 117 boolean mHasClipRect; 118 Rect mClipRect = new Rect(); 119 Rect mTmpClipRect = new Rect(); 120 Rect mLastClipRect = new Rect(); 121 122 // Used to save animation distances between the time they are calculated and when they are 123 // used. 124 int mAnimDw; 125 int mAnimDh; 126 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; 127 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; 128 129 boolean mHaveMatrix; 130 131 // For debugging, this is the last information given to the surface flinger. 132 boolean mSurfaceShown; 133 float mSurfaceX, mSurfaceY; 134 float mSurfaceW, mSurfaceH; 135 int mSurfaceLayer; 136 float mSurfaceAlpha; 137 138 // Set to true if, when the window gets displayed, it should perform 139 // an enter animation. 140 boolean mEnterAnimationPending; 141 142 /** This is set when there is no Surface */ 143 static final int NO_SURFACE = 0; 144 /** This is set after the Surface has been created but before the window has been drawn. During 145 * this time the surface is hidden. */ 146 static final int DRAW_PENDING = 1; 147 /** This is set after the window has finished drawing for the first time but before its surface 148 * is shown. The surface will be displayed when the next layout is run. */ 149 static final int COMMIT_DRAW_PENDING = 2; 150 /** This is set during the time after the window's drawing has been committed, and before its 151 * surface is actually shown. It is used to delay showing the surface until all windows in a 152 * token are ready to be shown. */ 153 static final int READY_TO_SHOW = 3; 154 /** Set when the window has been shown in the screen the first time. */ 155 static final int HAS_DRAWN = 4; 156 157 private static final int SYSTEM_UI_FLAGS_LAYOUT_STABLE_FULLSCREEN = 158 View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; 159 160 static String drawStateToString(int state) { 161 switch (state) { 162 case NO_SURFACE: return "NO_SURFACE"; 163 case DRAW_PENDING: return "DRAW_PENDING"; 164 case COMMIT_DRAW_PENDING: return "COMMIT_DRAW_PENDING"; 165 case READY_TO_SHOW: return "READY_TO_SHOW"; 166 case HAS_DRAWN: return "HAS_DRAWN"; 167 default: return Integer.toString(state); 168 } 169 } 170 int mDrawState; 171 172 /** Was this window last hidden? */ 173 boolean mLastHidden; 174 175 int mAttrType; 176 177 public WindowStateAnimator(final WindowState win) { 178 final WindowManagerService service = win.mService; 179 180 mService = service; 181 mAnimator = service.mAnimator; 182 mPolicy = service.mPolicy; 183 mContext = service.mContext; 184 final DisplayContent displayContent = win.getDisplayContent(); 185 if (displayContent != null) { 186 final DisplayInfo displayInfo = displayContent.getDisplayInfo(); 187 mAnimDw = displayInfo.appWidth; 188 mAnimDh = displayInfo.appHeight; 189 } else { 190 Slog.w(TAG, "WindowStateAnimator ctor: Display has been removed"); 191 // This is checked on return and dealt with. 192 } 193 194 mWin = win; 195 mAttachedWinAnimator = win.mAttachedWindow == null 196 ? null : win.mAttachedWindow.mWinAnimator; 197 mAppAnimator = win.mAppToken == null ? null : win.mAppToken.mAppAnimator; 198 mSession = win.mSession; 199 mAttrType = win.mAttrs.type; 200 mIsWallpaper = win.mIsWallpaper; 201 } 202 203 public void setAnimation(Animation anim) { 204 if (localLOGV) Slog.v(TAG, "Setting animation in " + this + ": " + anim); 205 mAnimating = false; 206 mLocalAnimating = false; 207 mAnimation = anim; 208 mAnimation.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION); 209 mAnimation.scaleCurrentDuration(mService.getWindowAnimationScaleLocked()); 210 // Start out animation gone if window is gone, or visible if window is visible. 211 mTransformation.clear(); 212 mTransformation.setAlpha(mLastHidden ? 0 : 1); 213 mHasLocalTransformation = true; 214 } 215 216 public void clearAnimation() { 217 if (mAnimation != null) { 218 mAnimating = true; 219 mLocalAnimating = false; 220 mAnimation.cancel(); 221 mAnimation = null; 222 } 223 } 224 225 /** Is the window or its container currently animating? */ 226 boolean isAnimating() { 227 return mAnimation != null 228 || (mAttachedWinAnimator != null && mAttachedWinAnimator.mAnimation != null) 229 || (mAppAnimator != null && 230 (mAppAnimator.animation != null 231 || mAppAnimator.mAppToken.inPendingTransaction)); 232 } 233 234 /** Is the window animating the DummyAnimation? */ 235 boolean isDummyAnimation() { 236 return mAppAnimator != null 237 && mAppAnimator.animation == AppWindowAnimator.sDummyAnimation; 238 } 239 240 /** Is this window currently animating? */ 241 boolean isWindowAnimating() { 242 return mAnimation != null; 243 } 244 245 void cancelExitAnimationForNextAnimationLocked() { 246 if (mAnimation != null) { 247 mAnimation.cancel(); 248 mAnimation = null; 249 mLocalAnimating = false; 250 destroySurfaceLocked(); 251 } 252 } 253 254 private boolean stepAnimation(long currentTime) { 255 if ((mAnimation == null) || !mLocalAnimating) { 256 return false; 257 } 258 mTransformation.clear(); 259 final boolean more = mAnimation.getTransformation(currentTime, mTransformation); 260 if (false && DEBUG_ANIM) Slog.v( 261 TAG, "Stepped animation in " + this + 262 ": more=" + more + ", xform=" + mTransformation); 263 return more; 264 } 265 266 // This must be called while inside a transaction. Returns true if 267 // there is more animation to run. 268 boolean stepAnimationLocked(long currentTime) { 269 // Save the animation state as it was before this step so WindowManagerService can tell if 270 // we just started or just stopped animating by comparing mWasAnimating with isAnimating(). 271 mWasAnimating = mAnimating; 272 final DisplayContent displayContent = mWin.getDisplayContent(); 273 if (displayContent != null && mService.okToDisplay()) { 274 // We will run animations as long as the display isn't frozen. 275 276 if (mWin.isDrawnLw() && mAnimation != null) { 277 mHasTransformation = true; 278 mHasLocalTransformation = true; 279 if (!mLocalAnimating) { 280 if (DEBUG_ANIM) Slog.v( 281 TAG, "Starting animation in " + this + 282 " @ " + currentTime + ": ww=" + mWin.mFrame.width() + 283 " wh=" + mWin.mFrame.height() + 284 " dw=" + mAnimDw + " dh=" + mAnimDh + 285 " scale=" + mService.getWindowAnimationScaleLocked()); 286 mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(), 287 mAnimDw, mAnimDh); 288 final DisplayInfo displayInfo = displayContent.getDisplayInfo(); 289 mAnimDw = displayInfo.appWidth; 290 mAnimDh = displayInfo.appHeight; 291 mAnimation.setStartTime(currentTime); 292 mLocalAnimating = true; 293 mAnimating = true; 294 } 295 if ((mAnimation != null) && mLocalAnimating) { 296 if (stepAnimation(currentTime)) { 297 return true; 298 } 299 } 300 if (DEBUG_ANIM) Slog.v( 301 TAG, "Finished animation in " + this + 302 " @ " + currentTime); 303 //WindowManagerService.this.dump(); 304 } 305 mHasLocalTransformation = false; 306 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppAnimator != null 307 && mAppAnimator.animation != null) { 308 // When our app token is animating, we kind-of pretend like 309 // we are as well. Note the mLocalAnimating mAnimationIsEntrance 310 // part of this check means that we will only do this if 311 // our window is not currently exiting, or it is not 312 // locally animating itself. The idea being that one that 313 // is exiting and doing a local animation should be removed 314 // once that animation is done. 315 mAnimating = true; 316 mHasTransformation = true; 317 mTransformation.clear(); 318 return false; 319 } else if (mHasTransformation) { 320 // Little trick to get through the path below to act like 321 // we have finished an animation. 322 mAnimating = true; 323 } else if (isAnimating()) { 324 mAnimating = true; 325 } 326 } else if (mAnimation != null) { 327 // If the display is frozen, and there is a pending animation, 328 // clear it and make sure we run the cleanup code. 329 mAnimating = true; 330 } 331 332 if (!mAnimating && !mLocalAnimating) { 333 return false; 334 } 335 336 // Done animating, clean up. 337 if (DEBUG_ANIM) Slog.v( 338 TAG, "Animation done in " + this + ": exiting=" + mWin.mExiting 339 + ", reportedVisible=" 340 + (mWin.mAppToken != null ? mWin.mAppToken.reportedVisible : false)); 341 342 mAnimating = false; 343 mLocalAnimating = false; 344 if (mAnimation != null) { 345 mAnimation.cancel(); 346 mAnimation = null; 347 } 348 if (mAnimator.mWindowDetachedWallpaper == mWin) { 349 mAnimator.mWindowDetachedWallpaper = null; 350 } 351 mAnimLayer = mWin.mLayer; 352 if (mWin.mIsImWindow) { 353 mAnimLayer += mService.mInputMethodAnimLayerAdjustment; 354 } else if (mIsWallpaper) { 355 mAnimLayer += mService.mWallpaperAnimLayerAdjustment; 356 } 357 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this 358 + " anim layer: " + mAnimLayer); 359 mHasTransformation = false; 360 mHasLocalTransformation = false; 361 if (mWin.mPolicyVisibility != mWin.mPolicyVisibilityAfterAnim) { 362 if (DEBUG_VISIBILITY) { 363 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " 364 + mWin.mPolicyVisibilityAfterAnim); 365 } 366 mWin.mPolicyVisibility = mWin.mPolicyVisibilityAfterAnim; 367 if (displayContent != null) { 368 displayContent.layoutNeeded = true; 369 } 370 if (!mWin.mPolicyVisibility) { 371 if (mService.mCurrentFocus == mWin) { 372 if (WindowManagerService.DEBUG_FOCUS_LIGHT) Slog.i(TAG, 373 "setAnimationLocked: setting mFocusMayChange true"); 374 mService.mFocusMayChange = true; 375 } 376 // Window is no longer visible -- make sure if we were waiting 377 // for it to be displayed before enabling the display, that 378 // we allow the display to be enabled now. 379 mService.enableScreenIfNeededLocked(); 380 } 381 } 382 mTransformation.clear(); 383 if (mDrawState == HAS_DRAWN 384 && mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING 385 && mWin.mAppToken != null 386 && mWin.mAppToken.firstWindowDrawn 387 && mWin.mAppToken.startingData != null) { 388 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " 389 + mWin.mToken + ": first real window done animating"); 390 mService.mFinishedStarting.add(mWin.mAppToken); 391 mService.mH.sendEmptyMessage(H.FINISHED_STARTING); 392 } else if (mAttrType == LayoutParams.TYPE_STATUS_BAR && mWin.mPolicyVisibility) { 393 // Upon completion of a not-visible to visible status bar animation a relayout is 394 // required. 395 if (displayContent != null) { 396 displayContent.layoutNeeded = true; 397 } 398 } 399 400 finishExit(); 401 final int displayId = mWin.getDisplayId(); 402 mAnimator.setPendingLayoutChanges(displayId, WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM); 403 if (WindowManagerService.DEBUG_LAYOUT_REPEATS) mService.debugLayoutRepeats( 404 "WindowStateAnimator", mAnimator.getPendingLayoutChanges(displayId)); 405 406 if (mWin.mAppToken != null) { 407 mWin.mAppToken.updateReportedVisibilityLocked(); 408 } 409 410 return false; 411 } 412 413 void finishExit() { 414 if (WindowManagerService.DEBUG_ANIM) Slog.v( 415 TAG, "finishExit in " + this 416 + ": exiting=" + mWin.mExiting 417 + " remove=" + mWin.mRemoveOnExit 418 + " windowAnimating=" + isWindowAnimating()); 419 420 final int N = mWin.mChildWindows.size(); 421 for (int i=0; i<N; i++) { 422 mWin.mChildWindows.get(i).mWinAnimator.finishExit(); 423 } 424 425 if (!mWin.mExiting) { 426 return; 427 } 428 429 if (isWindowAnimating()) { 430 return; 431 } 432 433 if (WindowManagerService.localLOGV) Slog.v( 434 TAG, "Exit animation finished in " + this 435 + ": remove=" + mWin.mRemoveOnExit); 436 if (mSurfaceControl != null) { 437 mService.mDestroySurface.add(mWin); 438 mWin.mDestroying = true; 439 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface( 440 mWin, "HIDE (finishExit)", null); 441 hide(); 442 } 443 mWin.mExiting = false; 444 if (mWin.mRemoveOnExit) { 445 mService.mPendingRemove.add(mWin); 446 mWin.mRemoveOnExit = false; 447 } 448 mAnimator.hideWallpapersLocked(mWin); 449 } 450 451 void hide() { 452 if (!mLastHidden) { 453 //dump(); 454 mLastHidden = true; 455 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, 456 "HIDE (performLayout)", null); 457 if (mSurfaceControl != null) { 458 mSurfaceShown = false; 459 try { 460 mSurfaceControl.hide(); 461 } catch (RuntimeException e) { 462 Slog.w(TAG, "Exception hiding surface in " + mWin); 463 } 464 } 465 } 466 } 467 468 boolean finishDrawingLocked() { 469 if (DEBUG_STARTING_WINDOW && 470 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { 471 Slog.v(TAG, "Finishing drawing window " + mWin + ": mDrawState=" 472 + drawStateToString(mDrawState)); 473 } 474 if (mDrawState == DRAW_PENDING) { 475 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || SHOW_TRANSACTIONS || DEBUG_ORIENTATION) 476 Slog.v(TAG, "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING " + this + " in " 477 + mSurfaceControl); 478 if (DEBUG_STARTING_WINDOW && 479 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { 480 Slog.v(TAG, "Draw state now committed in " + mWin); 481 } 482 mDrawState = COMMIT_DRAW_PENDING; 483 return true; 484 } 485 return false; 486 } 487 488 // This must be called while inside a transaction. 489 boolean commitFinishDrawingLocked(long currentTime) { 490 if (DEBUG_STARTING_WINDOW && 491 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { 492 Slog.i(TAG, "commitFinishDrawingLocked: " + mWin + " cur mDrawState=" 493 + drawStateToString(mDrawState)); 494 } 495 if (mDrawState != COMMIT_DRAW_PENDING) { 496 return false; 497 } 498 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) { 499 Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurfaceControl); 500 } 501 mDrawState = READY_TO_SHOW; 502 final boolean starting = mWin.mAttrs.type == TYPE_APPLICATION_STARTING; 503 final AppWindowToken atoken = mWin.mAppToken; 504 if (atoken == null || atoken.allDrawn || starting) { 505 performShowLocked(); 506 } 507 return true; 508 } 509 510 static class SurfaceTrace extends SurfaceControl { 511 private final static String SURFACE_TAG = "SurfaceTrace"; 512 final static ArrayList<SurfaceTrace> sSurfaces = new ArrayList<SurfaceTrace>(); 513 514 private float mSurfaceTraceAlpha = 0; 515 private int mLayer; 516 private final PointF mPosition = new PointF(); 517 private final Point mSize = new Point(); 518 private final Rect mWindowCrop = new Rect(); 519 private boolean mShown = false; 520 private int mLayerStack; 521 private boolean mIsOpaque; 522 private final String mName; 523 524 public SurfaceTrace(SurfaceSession s, 525 String name, int w, int h, int format, int flags) 526 throws OutOfResourcesException { 527 super(s, name, w, h, format, flags); 528 mName = name != null ? name : "Not named"; 529 mSize.set(w, h); 530 Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by " 531 + Debug.getCallers(3)); 532 } 533 534 @Override 535 public void setAlpha(float alpha) { 536 if (mSurfaceTraceAlpha != alpha) { 537 Slog.v(SURFACE_TAG, "setAlpha(" + alpha + "): OLD:" + this + ". Called by " 538 + Debug.getCallers(3)); 539 mSurfaceTraceAlpha = alpha; 540 } 541 super.setAlpha(alpha); 542 } 543 544 @Override 545 public void setLayer(int zorder) { 546 if (zorder != mLayer) { 547 Slog.v(SURFACE_TAG, "setLayer(" + zorder + "): OLD:" + this + ". Called by " 548 + Debug.getCallers(3)); 549 mLayer = zorder; 550 } 551 super.setLayer(zorder); 552 553 sSurfaces.remove(this); 554 int i; 555 for (i = sSurfaces.size() - 1; i >= 0; i--) { 556 SurfaceTrace s = sSurfaces.get(i); 557 if (s.mLayer < zorder) { 558 break; 559 } 560 } 561 sSurfaces.add(i + 1, this); 562 } 563 564 @Override 565 public void setPosition(float x, float y) { 566 if (x != mPosition.x || y != mPosition.y) { 567 Slog.v(SURFACE_TAG, "setPosition(" + x + "," + y + "): OLD:" + this 568 + ". Called by " + Debug.getCallers(3)); 569 mPosition.set(x, y); 570 } 571 super.setPosition(x, y); 572 } 573 574 @Override 575 public void setSize(int w, int h) { 576 if (w != mSize.x || h != mSize.y) { 577 Slog.v(SURFACE_TAG, "setSize(" + w + "," + h + "): OLD:" + this + ". Called by " 578 + Debug.getCallers(3)); 579 mSize.set(w, h); 580 } 581 super.setSize(w, h); 582 } 583 584 @Override 585 public void setWindowCrop(Rect crop) { 586 if (crop != null) { 587 if (!crop.equals(mWindowCrop)) { 588 Slog.v(SURFACE_TAG, "setWindowCrop(" + crop.toShortString() + "): OLD:" + this 589 + ". Called by " + Debug.getCallers(3)); 590 mWindowCrop.set(crop); 591 } 592 } 593 super.setWindowCrop(crop); 594 } 595 596 @Override 597 public void setLayerStack(int layerStack) { 598 if (layerStack != mLayerStack) { 599 Slog.v(SURFACE_TAG, "setLayerStack(" + layerStack + "): OLD:" + this 600 + ". Called by " + Debug.getCallers(3)); 601 mLayerStack = layerStack; 602 } 603 super.setLayerStack(layerStack); 604 } 605 606 @Override 607 public void setOpaque(boolean isOpaque) { 608 if (isOpaque != mIsOpaque) { 609 Slog.v(SURFACE_TAG, "setOpaque(" + isOpaque + "): OLD:" + this 610 + ". Called by " + Debug.getCallers(3)); 611 mIsOpaque = isOpaque; 612 } 613 super.setOpaque(isOpaque); 614 } 615 616 @Override 617 public void hide() { 618 if (mShown) { 619 Slog.v(SURFACE_TAG, "hide: OLD:" + this + ". Called by " + Debug.getCallers(3)); 620 mShown = false; 621 } 622 super.hide(); 623 } 624 625 @Override 626 public void show() { 627 if (!mShown) { 628 Slog.v(SURFACE_TAG, "show: OLD:" + this + ". Called by " + Debug.getCallers(3)); 629 mShown = true; 630 } 631 super.show(); 632 } 633 634 @Override 635 public void destroy() { 636 super.destroy(); 637 Slog.v(SURFACE_TAG, "destroy: " + this + ". Called by " + Debug.getCallers(3)); 638 sSurfaces.remove(this); 639 } 640 641 @Override 642 public void release() { 643 super.release(); 644 Slog.v(SURFACE_TAG, "release: " + this + ". Called by " 645 + Debug.getCallers(3)); 646 sSurfaces.remove(this); 647 } 648 649 static void dumpAllSurfaces() { 650 final int N = sSurfaces.size(); 651 for (int i = 0; i < N; i++) { 652 Slog.i(TAG, "SurfaceDump: " + sSurfaces.get(i)); 653 } 654 } 655 656 @Override 657 public String toString() { 658 return "Surface " + Integer.toHexString(System.identityHashCode(this)) + " " 659 + mName + " (" + mLayerStack + "): shown=" + mShown + " layer=" + mLayer 660 + " alpha=" + mSurfaceTraceAlpha + " " + mPosition.x + "," + mPosition.y 661 + " " + mSize.x + "x" + mSize.y 662 + " crop=" + mWindowCrop.toShortString() 663 + " opaque=" + mIsOpaque; 664 } 665 } 666 667 SurfaceControl createSurfaceLocked() { 668 final WindowState w = mWin; 669 if (mSurfaceControl == null) { 670 if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG, 671 "createSurface " + this + ": mDrawState=DRAW_PENDING"); 672 mDrawState = DRAW_PENDING; 673 if (w.mAppToken != null) { 674 if (w.mAppToken.mAppAnimator.animation == null) { 675 w.mAppToken.allDrawn = false; 676 w.mAppToken.deferClearAllDrawn = false; 677 } else { 678 // Currently animating, persist current state of allDrawn until animation 679 // is complete. 680 w.mAppToken.deferClearAllDrawn = true; 681 } 682 } 683 684 mService.makeWindowFreezingScreenIfNeededLocked(w); 685 686 int flags = SurfaceControl.HIDDEN; 687 final WindowManager.LayoutParams attrs = w.mAttrs; 688 689 if ((attrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { 690 flags |= SurfaceControl.SECURE; 691 } 692 693 int width; 694 int height; 695 if ((attrs.flags & LayoutParams.FLAG_SCALED) != 0) { 696 // for a scaled surface, we always want the requested 697 // size. 698 width = w.mRequestedWidth; 699 height = w.mRequestedHeight; 700 } else { 701 width = w.mCompatFrame.width(); 702 height = w.mCompatFrame.height(); 703 } 704 705 // Something is wrong and SurfaceFlinger will not like this, 706 // try to revert to sane values 707 if (width <= 0) { 708 width = 1; 709 } 710 if (height <= 0) { 711 height = 1; 712 } 713 714 float left = w.mFrame.left + w.mXOffset; 715 float top = w.mFrame.top + w.mYOffset; 716 717 // Adjust for surface insets. 718 width += attrs.surfaceInsets.left + attrs.surfaceInsets.right; 719 height += attrs.surfaceInsets.top + attrs.surfaceInsets.bottom; 720 left -= attrs.surfaceInsets.left; 721 top -= attrs.surfaceInsets.top; 722 723 if (DEBUG_VISIBILITY) { 724 Slog.v(TAG, "Creating surface in session " 725 + mSession.mSurfaceSession + " window " + this 726 + " w=" + width + " h=" + height 727 + " x=" + left + " y=" + top 728 + " format=" + attrs.format + " flags=" + flags); 729 } 730 731 // We may abort, so initialize to defaults. 732 mSurfaceShown = false; 733 mSurfaceLayer = 0; 734 mSurfaceAlpha = 0; 735 mSurfaceX = 0; 736 mSurfaceY = 0; 737 w.mLastSystemDecorRect.set(0, 0, 0, 0); 738 739 // Set up surface control with initial size. 740 try { 741 mSurfaceW = width; 742 mSurfaceH = height; 743 744 final boolean isHwAccelerated = (attrs.flags & 745 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0; 746 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format; 747 if (!PixelFormat.formatHasAlpha(attrs.format)) { 748 flags |= SurfaceControl.OPAQUE; 749 } 750 751 if (DEBUG_SURFACE_TRACE) { 752 mSurfaceControl = new SurfaceTrace( 753 mSession.mSurfaceSession, 754 attrs.getTitle().toString(), 755 width, height, format, flags); 756 } else { 757 mSurfaceControl = new SurfaceControl( 758 mSession.mSurfaceSession, 759 attrs.getTitle().toString(), 760 width, height, format, flags); 761 } 762 763 w.mHasSurface = true; 764 765 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) { 766 Slog.i(TAG, " CREATE SURFACE " 767 + mSurfaceControl + " IN SESSION " 768 + mSession.mSurfaceSession 769 + ": pid=" + mSession.mPid + " format=" 770 + attrs.format + " flags=0x" 771 + Integer.toHexString(flags) 772 + " / " + this); 773 } 774 } catch (OutOfResourcesException e) { 775 w.mHasSurface = false; 776 Slog.w(TAG, "OutOfResourcesException creating surface"); 777 mService.reclaimSomeSurfaceMemoryLocked(this, "create", true); 778 mDrawState = NO_SURFACE; 779 return null; 780 } catch (Exception e) { 781 w.mHasSurface = false; 782 Slog.e(TAG, "Exception creating surface", e); 783 mDrawState = NO_SURFACE; 784 return null; 785 } 786 787 if (WindowManagerService.localLOGV) { 788 Slog.v(TAG, "Got surface: " + mSurfaceControl 789 + ", set left=" + w.mFrame.left + " top=" + w.mFrame.top 790 + ", animLayer=" + mAnimLayer); 791 } 792 793 if (SHOW_LIGHT_TRANSACTIONS) { 794 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked"); 795 WindowManagerService.logSurface(w, "CREATE pos=(" 796 + w.mFrame.left + "," + w.mFrame.top + ") (" 797 + w.mCompatFrame.width() + "x" + w.mCompatFrame.height() 798 + "), layer=" + mAnimLayer + " HIDE", null); 799 } 800 801 // Start a new transaction and apply position & offset. 802 SurfaceControl.openTransaction(); 803 try { 804 mSurfaceX = left; 805 mSurfaceY = top; 806 807 try { 808 mSurfaceControl.setPosition(left, top); 809 mSurfaceLayer = mAnimLayer; 810 final DisplayContent displayContent = w.getDisplayContent(); 811 if (displayContent != null) { 812 mSurfaceControl.setLayerStack(displayContent.getDisplay().getLayerStack()); 813 } 814 mSurfaceControl.setLayer(mAnimLayer); 815 mSurfaceControl.setAlpha(0); 816 mSurfaceShown = false; 817 } catch (RuntimeException e) { 818 Slog.w(TAG, "Error creating surface in " + w, e); 819 mService.reclaimSomeSurfaceMemoryLocked(this, "create-init", true); 820 } 821 mLastHidden = true; 822 } finally { 823 SurfaceControl.closeTransaction(); 824 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, 825 "<<< CLOSE TRANSACTION createSurfaceLocked"); 826 } 827 if (WindowManagerService.localLOGV) Slog.v( 828 TAG, "Created surface " + this); 829 } 830 return mSurfaceControl; 831 } 832 833 void destroySurfaceLocked() { 834 if (mWin.mAppToken != null && mWin == mWin.mAppToken.startingWindow) { 835 mWin.mAppToken.startingDisplayed = false; 836 } 837 838 if (mSurfaceControl != null) { 839 840 int i = mWin.mChildWindows.size(); 841 while (i > 0) { 842 i--; 843 WindowState c = mWin.mChildWindows.get(i); 844 c.mAttachedHidden = true; 845 } 846 847 try { 848 if (DEBUG_VISIBILITY) { 849 RuntimeException e = null; 850 if (!WindowManagerService.HIDE_STACK_CRAWLS) { 851 e = new RuntimeException(); 852 e.fillInStackTrace(); 853 } 854 Slog.w(TAG, "Window " + this + " destroying surface " 855 + mSurfaceControl + ", session " + mSession, e); 856 } 857 if (mSurfaceDestroyDeferred) { 858 if (mSurfaceControl != null && mPendingDestroySurface != mSurfaceControl) { 859 if (mPendingDestroySurface != null) { 860 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) { 861 RuntimeException e = null; 862 if (!WindowManagerService.HIDE_STACK_CRAWLS) { 863 e = new RuntimeException(); 864 e.fillInStackTrace(); 865 } 866 WindowManagerService.logSurface(mWin, "DESTROY PENDING", e); 867 } 868 mPendingDestroySurface.destroy(); 869 } 870 mPendingDestroySurface = mSurfaceControl; 871 } 872 } else { 873 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) { 874 RuntimeException e = null; 875 if (!WindowManagerService.HIDE_STACK_CRAWLS) { 876 e = new RuntimeException(); 877 e.fillInStackTrace(); 878 } 879 WindowManagerService.logSurface(mWin, "DESTROY", e); 880 } 881 mSurfaceControl.destroy(); 882 } 883 mAnimator.hideWallpapersLocked(mWin); 884 } catch (RuntimeException e) { 885 Slog.w(TAG, "Exception thrown when destroying Window " + this 886 + " surface " + mSurfaceControl + " session " + mSession 887 + ": " + e.toString()); 888 } 889 890 mSurfaceShown = false; 891 mSurfaceControl = null; 892 mWin.mHasSurface = false; 893 mDrawState = NO_SURFACE; 894 } 895 } 896 897 void destroyDeferredSurfaceLocked() { 898 try { 899 if (mPendingDestroySurface != null) { 900 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) { 901 RuntimeException e = null; 902 if (!WindowManagerService.HIDE_STACK_CRAWLS) { 903 e = new RuntimeException(); 904 e.fillInStackTrace(); 905 } 906 WindowManagerService.logSurface(mWin, "DESTROY PENDING", e); 907 } 908 mPendingDestroySurface.destroy(); 909 mAnimator.hideWallpapersLocked(mWin); 910 } 911 } catch (RuntimeException e) { 912 Slog.w(TAG, "Exception thrown when destroying Window " 913 + this + " surface " + mPendingDestroySurface 914 + " session " + mSession + ": " + e.toString()); 915 } 916 mSurfaceDestroyDeferred = false; 917 mPendingDestroySurface = null; 918 } 919 920 void computeShownFrameLocked() { 921 final boolean selfTransformation = mHasLocalTransformation; 922 Transformation attachedTransformation = 923 (mAttachedWinAnimator != null && mAttachedWinAnimator.mHasLocalTransformation) 924 ? mAttachedWinAnimator.mTransformation : null; 925 Transformation appTransformation = (mAppAnimator != null && mAppAnimator.hasTransformation) 926 ? mAppAnimator.transformation : null; 927 928 // Wallpapers are animated based on the "real" window they 929 // are currently targeting. 930 final WindowState wallpaperTarget = mService.mWallpaperTarget; 931 if (mIsWallpaper && wallpaperTarget != null && mService.mAnimateWallpaperWithTarget) { 932 final WindowStateAnimator wallpaperAnimator = wallpaperTarget.mWinAnimator; 933 if (wallpaperAnimator.mHasLocalTransformation && 934 wallpaperAnimator.mAnimation != null && 935 !wallpaperAnimator.mAnimation.getDetachWallpaper()) { 936 attachedTransformation = wallpaperAnimator.mTransformation; 937 if (WindowManagerService.DEBUG_WALLPAPER && attachedTransformation != null) { 938 Slog.v(TAG, "WP target attached xform: " + attachedTransformation); 939 } 940 } 941 final AppWindowAnimator wpAppAnimator = wallpaperTarget.mAppToken == null ? 942 null : wallpaperTarget.mAppToken.mAppAnimator; 943 if (wpAppAnimator != null && wpAppAnimator.hasTransformation 944 && wpAppAnimator.animation != null 945 && !wpAppAnimator.animation.getDetachWallpaper()) { 946 appTransformation = wpAppAnimator.transformation; 947 if (WindowManagerService.DEBUG_WALLPAPER && appTransformation != null) { 948 Slog.v(TAG, "WP target app xform: " + appTransformation); 949 } 950 } 951 } 952 953 final int displayId = mWin.getDisplayId(); 954 final ScreenRotationAnimation screenRotationAnimation = 955 mAnimator.getScreenRotationAnimationLocked(displayId); 956 final boolean screenAnimation = 957 screenRotationAnimation != null && screenRotationAnimation.isAnimating(); 958 if (selfTransformation || attachedTransformation != null 959 || appTransformation != null || screenAnimation) { 960 // cache often used attributes locally 961 final Rect frame = mWin.mFrame; 962 final float tmpFloats[] = mService.mTmpFloats; 963 final Matrix tmpMatrix = mWin.mTmpMatrix; 964 965 // Compute the desired transformation. 966 if (screenAnimation && screenRotationAnimation.isRotating()) { 967 // If we are doing a screen animation, the global rotation 968 // applied to windows can result in windows that are carefully 969 // aligned with each other to slightly separate, allowing you 970 // to see what is behind them. An unsightly mess. This... 971 // thing... magically makes it call good: scale each window 972 // slightly (two pixels larger in each dimension, from the 973 // window's center). 974 final float w = frame.width(); 975 final float h = frame.height(); 976 if (w>=1 && h>=1) { 977 tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2); 978 } else { 979 tmpMatrix.reset(); 980 } 981 } else { 982 tmpMatrix.reset(); 983 } 984 tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale); 985 if (selfTransformation) { 986 tmpMatrix.postConcat(mTransformation.getMatrix()); 987 } 988 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset); 989 if (attachedTransformation != null) { 990 tmpMatrix.postConcat(attachedTransformation.getMatrix()); 991 } 992 if (appTransformation != null) { 993 tmpMatrix.postConcat(appTransformation.getMatrix()); 994 } 995 if (mAnimator.mUniverseBackground != null) { 996 tmpMatrix.postConcat(mAnimator.mUniverseBackground.mUniverseTransform.getMatrix()); 997 } 998 if (screenAnimation) { 999 tmpMatrix.postConcat(screenRotationAnimation.getEnterTransformation().getMatrix()); 1000 } 1001 1002 //TODO (multidisplay): Magnification is supported only for the default display. 1003 if (mService.mAccessibilityController != null && displayId == Display.DEFAULT_DISPLAY) { 1004 MagnificationSpec spec = mService.mAccessibilityController 1005 .getMagnificationSpecForWindowLocked(mWin); 1006 if (spec != null && !spec.isNop()) { 1007 tmpMatrix.postScale(spec.scale, spec.scale); 1008 tmpMatrix.postTranslate(spec.offsetX, spec.offsetY); 1009 } 1010 } 1011 1012 // "convert" it into SurfaceFlinger's format 1013 // (a 2x2 matrix + an offset) 1014 // Here we must not transform the position of the surface 1015 // since it is already included in the transformation. 1016 //Slog.i(TAG, "Transform: " + matrix); 1017 1018 mHaveMatrix = true; 1019 tmpMatrix.getValues(tmpFloats); 1020 mDsDx = tmpFloats[Matrix.MSCALE_X]; 1021 mDtDx = tmpFloats[Matrix.MSKEW_Y]; 1022 mDsDy = tmpFloats[Matrix.MSKEW_X]; 1023 mDtDy = tmpFloats[Matrix.MSCALE_Y]; 1024 float x = tmpFloats[Matrix.MTRANS_X]; 1025 float y = tmpFloats[Matrix.MTRANS_Y]; 1026 int w = frame.width(); 1027 int h = frame.height(); 1028 mWin.mShownFrame.set(x, y, x+w, y+h); 1029 1030 // Now set the alpha... but because our current hardware 1031 // can't do alpha transformation on a non-opaque surface, 1032 // turn it off if we are running an animation that is also 1033 // transforming since it is more important to have that 1034 // animation be smooth. 1035 mShownAlpha = mAlpha; 1036 mHasClipRect = false; 1037 if (!mService.mLimitedAlphaCompositing 1038 || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format) 1039 || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) 1040 && x == frame.left && y == frame.top))) { 1041 //Slog.i(TAG, "Applying alpha transform"); 1042 if (selfTransformation) { 1043 mShownAlpha *= mTransformation.getAlpha(); 1044 } 1045 if (attachedTransformation != null) { 1046 mShownAlpha *= attachedTransformation.getAlpha(); 1047 } 1048 if (appTransformation != null) { 1049 mShownAlpha *= appTransformation.getAlpha(); 1050 if (appTransformation.hasClipRect()) { 1051 mClipRect.set(appTransformation.getClipRect()); 1052 mHasClipRect = true; 1053 } 1054 } 1055 if (mAnimator.mUniverseBackground != null) { 1056 mShownAlpha *= mAnimator.mUniverseBackground.mUniverseTransform.getAlpha(); 1057 } 1058 if (screenAnimation) { 1059 mShownAlpha *= screenRotationAnimation.getEnterTransformation().getAlpha(); 1060 } 1061 } else { 1062 //Slog.i(TAG, "Not applying alpha transform"); 1063 } 1064 1065 if ((DEBUG_SURFACE_TRACE || WindowManagerService.localLOGV) 1066 && (mShownAlpha == 1.0 || mShownAlpha == 0.0)) Slog.v( 1067 TAG, "computeShownFrameLocked: Animating " + this + " mAlpha=" + mAlpha 1068 + " self=" + (selfTransformation ? mTransformation.getAlpha() : "null") 1069 + " attached=" + (attachedTransformation == null ? 1070 "null" : attachedTransformation.getAlpha()) 1071 + " app=" + (appTransformation == null ? "null" : appTransformation.getAlpha()) 1072 + " screen=" + (screenAnimation ? 1073 screenRotationAnimation.getEnterTransformation().getAlpha() : "null")); 1074 return; 1075 } else if (mIsWallpaper && mService.mInnerFields.mWallpaperActionPending) { 1076 return; 1077 } 1078 1079 if (WindowManagerService.localLOGV) Slog.v( 1080 TAG, "computeShownFrameLocked: " + this + 1081 " not attached, mAlpha=" + mAlpha); 1082 1083 final boolean applyUniverseTransformation = (mAnimator.mUniverseBackground != null 1084 && mWin.mAttrs.type != WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND 1085 && mWin.mBaseLayer < mAnimator.mAboveUniverseLayer); 1086 MagnificationSpec spec = null; 1087 //TODO (multidisplay): Magnification is supported only for the default display. 1088 if (mService.mAccessibilityController != null && displayId == Display.DEFAULT_DISPLAY) { 1089 spec = mService.mAccessibilityController.getMagnificationSpecForWindowLocked(mWin); 1090 } 1091 if (applyUniverseTransformation || spec != null) { 1092 final Rect frame = mWin.mFrame; 1093 final float tmpFloats[] = mService.mTmpFloats; 1094 final Matrix tmpMatrix = mWin.mTmpMatrix; 1095 1096 tmpMatrix.setScale(mWin.mGlobalScale, mWin.mGlobalScale); 1097 tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset); 1098 1099 if (applyUniverseTransformation) { 1100 tmpMatrix.postConcat(mAnimator.mUniverseBackground.mUniverseTransform.getMatrix()); 1101 } 1102 1103 if (spec != null && !spec.isNop()) { 1104 tmpMatrix.postScale(spec.scale, spec.scale); 1105 tmpMatrix.postTranslate(spec.offsetX, spec.offsetY); 1106 } 1107 1108 tmpMatrix.getValues(tmpFloats); 1109 1110 mHaveMatrix = true; 1111 mDsDx = tmpFloats[Matrix.MSCALE_X]; 1112 mDtDx = tmpFloats[Matrix.MSKEW_Y]; 1113 mDsDy = tmpFloats[Matrix.MSKEW_X]; 1114 mDtDy = tmpFloats[Matrix.MSCALE_Y]; 1115 float x = tmpFloats[Matrix.MTRANS_X]; 1116 float y = tmpFloats[Matrix.MTRANS_Y]; 1117 int w = frame.width(); 1118 int h = frame.height(); 1119 mWin.mShownFrame.set(x, y, x + w, y + h); 1120 1121 mShownAlpha = mAlpha; 1122 if (applyUniverseTransformation) { 1123 mShownAlpha *= mAnimator.mUniverseBackground.mUniverseTransform.getAlpha(); 1124 } 1125 } else { 1126 mWin.mShownFrame.set(mWin.mFrame); 1127 if (mWin.mXOffset != 0 || mWin.mYOffset != 0) { 1128 mWin.mShownFrame.offset(mWin.mXOffset, mWin.mYOffset); 1129 } 1130 mShownAlpha = mAlpha; 1131 mHaveMatrix = false; 1132 mDsDx = mWin.mGlobalScale; 1133 mDtDx = 0; 1134 mDsDy = 0; 1135 mDtDy = mWin.mGlobalScale; 1136 } 1137 } 1138 1139 void applyDecorRect(final Rect decorRect) { 1140 final WindowState w = mWin; 1141 final int width = w.mFrame.width(); 1142 final int height = w.mFrame.height(); 1143 1144 // Compute the offset of the window in relation to the decor rect. 1145 final int left = w.mXOffset + w.mFrame.left; 1146 final int top = w.mYOffset + w.mFrame.top; 1147 1148 // Initialize the decor rect to the entire frame. 1149 w.mSystemDecorRect.set(0, 0, width, height); 1150 1151 // Intersect with the decor rect, offsetted by window position. 1152 w.mSystemDecorRect.intersect(decorRect.left - left, decorRect.top - top, 1153 decorRect.right - left, decorRect.bottom - top); 1154 1155 // If size compatibility is being applied to the window, the 1156 // surface is scaled relative to the screen. Also apply this 1157 // scaling to the crop rect. We aren't using the standard rect 1158 // scale function because we want to round things to make the crop 1159 // always round to a larger rect to ensure we don't crop too 1160 // much and hide part of the window that should be seen. 1161 if (w.mEnforceSizeCompat && w.mInvGlobalScale != 1.0f) { 1162 final float scale = w.mInvGlobalScale; 1163 w.mSystemDecorRect.left = (int) (w.mSystemDecorRect.left * scale - 0.5f); 1164 w.mSystemDecorRect.top = (int) (w.mSystemDecorRect.top * scale - 0.5f); 1165 w.mSystemDecorRect.right = (int) ((w.mSystemDecorRect.right+1) * scale - 0.5f); 1166 w.mSystemDecorRect.bottom = (int) ((w.mSystemDecorRect.bottom+1) * scale - 0.5f); 1167 } 1168 } 1169 1170 void updateSurfaceWindowCrop(final boolean recoveringMemory) { 1171 final WindowState w = mWin; 1172 final DisplayContent displayContent = w.getDisplayContent(); 1173 if (displayContent == null) { 1174 return; 1175 } 1176 1177 // Need to recompute a new system decor rect each time. 1178 if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { 1179 // Currently can't do this cropping for scaled windows. We'll 1180 // just keep the crop rect the same as the source surface. 1181 w.mSystemDecorRect.set(0, 0, w.mRequestedWidth, w.mRequestedHeight); 1182 } else if (!w.isDefaultDisplay()) { 1183 // On a different display there is no system decor. Crop the window 1184 // by the screen boundaries. 1185 final DisplayInfo displayInfo = displayContent.getDisplayInfo(); 1186 w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height()); 1187 w.mSystemDecorRect.intersect(-w.mCompatFrame.left, -w.mCompatFrame.top, 1188 displayInfo.logicalWidth - w.mCompatFrame.left, 1189 displayInfo.logicalHeight - w.mCompatFrame.top); 1190 } else if (w.mLayer >= mService.mSystemDecorLayer) { 1191 // Above the decor layer is easy, just use the entire window. 1192 // Unless we have a universe background... in which case all the 1193 // windows need to be cropped by the screen, so they don't cover 1194 // the universe background. 1195 if (mAnimator.mUniverseBackground == null) { 1196 w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height()); 1197 } else { 1198 applyDecorRect(mService.mScreenRect); 1199 } 1200 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND 1201 || w.mDecorFrame.isEmpty()) { 1202 // The universe background isn't cropped, nor windows without policy decor. 1203 w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height()); 1204 } else { 1205 // Crop to the system decor specified by policy. 1206 applyDecorRect(w.mDecorFrame); 1207 } 1208 1209 // By default, the clip rect is the system decor. 1210 final Rect clipRect = mTmpClipRect; 1211 clipRect.set(w.mSystemDecorRect); 1212 1213 // Expand the clip rect for surface insets. 1214 final WindowManager.LayoutParams attrs = w.mAttrs; 1215 clipRect.left -= attrs.surfaceInsets.left; 1216 clipRect.top -= attrs.surfaceInsets.top; 1217 clipRect.right += attrs.surfaceInsets.right; 1218 clipRect.bottom += attrs.surfaceInsets.bottom; 1219 1220 // If we have an animated clip rect, intersect it with the clip rect. 1221 if (mHasClipRect) { 1222 // NOTE: We are adding a temporary workaround due to the status bar 1223 // not always reporting the correct system decor rect. In such 1224 // cases, we take into account the specified content insets as well. 1225 if ((w.mSystemUiVisibility & SYSTEM_UI_FLAGS_LAYOUT_STABLE_FULLSCREEN) 1226 == SYSTEM_UI_FLAGS_LAYOUT_STABLE_FULLSCREEN) { 1227 // Don't apply the workaround to apps explicitly requesting 1228 // fullscreen layout. 1229 clipRect.intersect(mClipRect); 1230 } else { 1231 final int offsetTop = Math.max(clipRect.top, w.mContentInsets.top); 1232 clipRect.offset(0, -offsetTop); 1233 clipRect.intersect(mClipRect); 1234 clipRect.offset(0, offsetTop); 1235 } 1236 } 1237 1238 // The clip rect was generated assuming (0,0) as the window origin, 1239 // so we need to translate to match the actual surface coordinates. 1240 clipRect.offset(attrs.surfaceInsets.left, attrs.surfaceInsets.top); 1241 1242 if (!clipRect.equals(mLastClipRect)) { 1243 mLastClipRect.set(clipRect); 1244 try { 1245 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w, 1246 "CROP " + clipRect.toShortString(), null); 1247 mSurfaceControl.setWindowCrop(clipRect); 1248 } catch (RuntimeException e) { 1249 Slog.w(TAG, "Error setting crop surface of " + w 1250 + " crop=" + clipRect.toShortString(), e); 1251 if (!recoveringMemory) { 1252 mService.reclaimSomeSurfaceMemoryLocked(this, "crop", true); 1253 } 1254 } 1255 } 1256 } 1257 1258 void setSurfaceBoundariesLocked(final boolean recoveringMemory) { 1259 final WindowState w = mWin; 1260 1261 int width; 1262 int height; 1263 if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { 1264 // for a scaled surface, we always want the requested 1265 // size. 1266 width = w.mRequestedWidth; 1267 height = w.mRequestedHeight; 1268 } else { 1269 width = w.mCompatFrame.width(); 1270 height = w.mCompatFrame.height(); 1271 } 1272 1273 // Something is wrong and SurfaceFlinger will not like this, 1274 // try to revert to sane values 1275 if (width < 1) { 1276 width = 1; 1277 } 1278 if (height < 1) { 1279 height = 1; 1280 } 1281 1282 float left = w.mShownFrame.left; 1283 float top = w.mShownFrame.top; 1284 1285 // Adjust for surface insets. 1286 final LayoutParams attrs = w.getAttrs(); 1287 width += attrs.surfaceInsets.left + attrs.surfaceInsets.right; 1288 height += attrs.surfaceInsets.top + attrs.surfaceInsets.bottom; 1289 left -= attrs.surfaceInsets.left; 1290 top -= attrs.surfaceInsets.top; 1291 1292 final boolean surfaceMoved = mSurfaceX != left || mSurfaceY != top; 1293 if (surfaceMoved) { 1294 mSurfaceX = left; 1295 mSurfaceY = top; 1296 1297 try { 1298 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w, 1299 "POS " + left + ", " + top, null); 1300 mSurfaceControl.setPosition(left, top); 1301 } catch (RuntimeException e) { 1302 Slog.w(TAG, "Error positioning surface of " + w 1303 + " pos=(" + left + "," + top + ")", e); 1304 if (!recoveringMemory) { 1305 mService.reclaimSomeSurfaceMemoryLocked(this, "position", true); 1306 } 1307 } 1308 } 1309 1310 final boolean surfaceResized = mSurfaceW != width || mSurfaceH != height; 1311 if (surfaceResized) { 1312 mSurfaceW = width; 1313 mSurfaceH = height; 1314 mSurfaceResized = true; 1315 1316 try { 1317 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w, 1318 "SIZE " + width + "x" + height, null); 1319 mSurfaceControl.setSize(width, height); 1320 mAnimator.setPendingLayoutChanges(w.getDisplayId(), 1321 WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER); 1322 if ((w.mAttrs.flags & LayoutParams.FLAG_DIM_BEHIND) != 0) { 1323 w.getStack().startDimmingIfNeeded(this); 1324 } 1325 } catch (RuntimeException e) { 1326 // If something goes wrong with the surface (such 1327 // as running out of memory), don't take down the 1328 // entire system. 1329 Slog.e(TAG, "Error resizing surface of " + w 1330 + " size=(" + width + "x" + height + ")", e); 1331 if (!recoveringMemory) { 1332 mService.reclaimSomeSurfaceMemoryLocked(this, "size", true); 1333 } 1334 } 1335 } 1336 1337 updateSurfaceWindowCrop(recoveringMemory); 1338 } 1339 1340 public void prepareSurfaceLocked(final boolean recoveringMemory) { 1341 final WindowState w = mWin; 1342 if (mSurfaceControl == null) { 1343 if (w.mOrientationChanging) { 1344 if (DEBUG_ORIENTATION) { 1345 Slog.v(TAG, "Orientation change skips hidden " + w); 1346 } 1347 w.mOrientationChanging = false; 1348 } 1349 return; 1350 } 1351 1352 boolean displayed = false; 1353 1354 computeShownFrameLocked(); 1355 1356 setSurfaceBoundariesLocked(recoveringMemory); 1357 1358 if (mIsWallpaper && !mWin.mWallpaperVisible) { 1359 // Wallpaper is no longer visible and there is no wp target => hide it. 1360 hide(); 1361 } else if (w.mAttachedHidden || !w.isOnScreen()) { 1362 hide(); 1363 mAnimator.hideWallpapersLocked(w); 1364 1365 // If we are waiting for this window to handle an 1366 // orientation change, well, it is hidden, so 1367 // doesn't really matter. Note that this does 1368 // introduce a potential glitch if the window 1369 // becomes unhidden before it has drawn for the 1370 // new orientation. 1371 if (w.mOrientationChanging) { 1372 w.mOrientationChanging = false; 1373 if (DEBUG_ORIENTATION) Slog.v(TAG, 1374 "Orientation change skips hidden " + w); 1375 } 1376 } else if (mLastLayer != mAnimLayer 1377 || mLastAlpha != mShownAlpha 1378 || mLastDsDx != mDsDx 1379 || mLastDtDx != mDtDx 1380 || mLastDsDy != mDsDy 1381 || mLastDtDy != mDtDy 1382 || w.mLastHScale != w.mHScale 1383 || w.mLastVScale != w.mVScale 1384 || mLastHidden) { 1385 displayed = true; 1386 mLastAlpha = mShownAlpha; 1387 mLastLayer = mAnimLayer; 1388 mLastDsDx = mDsDx; 1389 mLastDtDx = mDtDx; 1390 mLastDsDy = mDsDy; 1391 mLastDtDy = mDtDy; 1392 w.mLastHScale = w.mHScale; 1393 w.mLastVScale = w.mVScale; 1394 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w, 1395 "alpha=" + mShownAlpha + " layer=" + mAnimLayer 1396 + " matrix=[" + (mDsDx*w.mHScale) 1397 + "," + (mDtDx*w.mVScale) 1398 + "][" + (mDsDy*w.mHScale) 1399 + "," + (mDtDy*w.mVScale) + "]", null); 1400 if (mSurfaceControl != null) { 1401 try { 1402 mSurfaceAlpha = mShownAlpha; 1403 mSurfaceControl.setAlpha(mShownAlpha); 1404 mSurfaceLayer = mAnimLayer; 1405 mSurfaceControl.setLayer(mAnimLayer); 1406 mSurfaceControl.setMatrix( 1407 mDsDx * w.mHScale, mDtDx * w.mVScale, 1408 mDsDy * w.mHScale, mDtDy * w.mVScale); 1409 1410 if (mLastHidden && mDrawState == HAS_DRAWN) { 1411 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w, 1412 "SHOW (performLayout)", null); 1413 if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w 1414 + " during relayout"); 1415 if (showSurfaceRobustlyLocked()) { 1416 mLastHidden = false; 1417 if (mIsWallpaper) { 1418 mService.dispatchWallpaperVisibility(w, true); 1419 } 1420 // This draw means the difference between unique content and mirroring. 1421 // Run another pass through performLayout to set mHasContent in the 1422 // LogicalDisplay. 1423 mAnimator.setPendingLayoutChanges(w.getDisplayId(), 1424 WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM); 1425 } else { 1426 w.mOrientationChanging = false; 1427 } 1428 } 1429 if (mSurfaceControl != null) { 1430 w.mToken.hasVisible = true; 1431 } 1432 } catch (RuntimeException e) { 1433 Slog.w(TAG, "Error updating surface in " + w, e); 1434 if (!recoveringMemory) { 1435 mService.reclaimSomeSurfaceMemoryLocked(this, "update", true); 1436 } 1437 } 1438 } 1439 } else { 1440 if (DEBUG_ANIM && isAnimating()) { 1441 Slog.v(TAG, "prepareSurface: No changes in animation for " + this); 1442 } 1443 displayed = true; 1444 } 1445 1446 if (displayed) { 1447 if (w.mOrientationChanging) { 1448 if (!w.isDrawnLw()) { 1449 mAnimator.mBulkUpdateParams &= ~SET_ORIENTATION_CHANGE_COMPLETE; 1450 mAnimator.mLastWindowFreezeSource = w; 1451 if (DEBUG_ORIENTATION) Slog.v(TAG, 1452 "Orientation continue waiting for draw in " + w); 1453 } else { 1454 w.mOrientationChanging = false; 1455 if (DEBUG_ORIENTATION) Slog.v(TAG, "Orientation change complete in " + w); 1456 } 1457 } 1458 w.mToken.hasVisible = true; 1459 } 1460 } 1461 1462 void setTransparentRegionHintLocked(final Region region) { 1463 if (mSurfaceControl == null) { 1464 Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true"); 1465 return; 1466 } 1467 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setTransparentRegion"); 1468 SurfaceControl.openTransaction(); 1469 try { 1470 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, 1471 "transparentRegionHint=" + region, null); 1472 mSurfaceControl.setTransparentRegionHint(region); 1473 } finally { 1474 SurfaceControl.closeTransaction(); 1475 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, 1476 "<<< CLOSE TRANSACTION setTransparentRegion"); 1477 } 1478 } 1479 1480 void setWallpaperOffset(RectF shownFrame) { 1481 final int left = (int) shownFrame.left; 1482 final int top = (int) shownFrame.top; 1483 if (mSurfaceX != left || mSurfaceY != top) { 1484 mSurfaceX = left; 1485 mSurfaceY = top; 1486 if (mAnimating) { 1487 // If this window (or its app token) is animating, then the position 1488 // of the surface will be re-computed on the next animation frame. 1489 // We can't poke it directly here because it depends on whatever 1490 // transformation is being applied by the animation. 1491 return; 1492 } 1493 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setWallpaperOffset"); 1494 SurfaceControl.openTransaction(); 1495 try { 1496 if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, 1497 "POS " + left + ", " + top, null); 1498 mSurfaceControl.setPosition(mWin.mFrame.left + left, mWin.mFrame.top + top); 1499 updateSurfaceWindowCrop(false); 1500 } catch (RuntimeException e) { 1501 Slog.w(TAG, "Error positioning surface of " + mWin 1502 + " pos=(" + left + "," + top + ")", e); 1503 } finally { 1504 SurfaceControl.closeTransaction(); 1505 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, 1506 "<<< CLOSE TRANSACTION setWallpaperOffset"); 1507 } 1508 } 1509 } 1510 1511 void setOpaque(boolean isOpaque) { 1512 if (mSurfaceControl == null) { 1513 return; 1514 } 1515 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setOpaque"); 1516 SurfaceControl.openTransaction(); 1517 try { 1518 if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, "isOpaque=" + isOpaque, 1519 null); 1520 mSurfaceControl.setOpaque(isOpaque); 1521 } finally { 1522 SurfaceControl.closeTransaction(); 1523 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION setOpaque"); 1524 } 1525 } 1526 1527 // This must be called while inside a transaction. 1528 boolean performShowLocked() { 1529 if (mWin.isHiddenFromUserLocked()) { 1530 Slog.w(TAG, "current user violation " + mService.mCurrentUserId + " trying to display " 1531 + this + ", type " + mWin.mAttrs.type + ", belonging to " + mWin.mOwnerUid); 1532 return false; 1533 } 1534 if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW && 1535 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) { 1536 RuntimeException e = null; 1537 if (!WindowManagerService.HIDE_STACK_CRAWLS) { 1538 e = new RuntimeException(); 1539 e.fillInStackTrace(); 1540 } 1541 Slog.v(TAG, "performShow on " + this 1542 + ": mDrawState=" + mDrawState + " readyForDisplay=" 1543 + mWin.isReadyForDisplayIgnoringKeyguard() 1544 + " starting=" + (mWin.mAttrs.type == TYPE_APPLICATION_STARTING) 1545 + " during animation: policyVis=" + mWin.mPolicyVisibility 1546 + " attHidden=" + mWin.mAttachedHidden 1547 + " tok.hiddenRequested=" 1548 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false) 1549 + " tok.hidden=" 1550 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false) 1551 + " animating=" + mAnimating 1552 + " tok animating=" 1553 + (mAppAnimator != null ? mAppAnimator.animating : false), e); 1554 } 1555 if (mDrawState == READY_TO_SHOW && mWin.isReadyForDisplayIgnoringKeyguard()) { 1556 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) 1557 WindowManagerService.logSurface(mWin, "SHOW (performShowLocked)", null); 1558 if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW && 1559 mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) { 1560 Slog.v(TAG, "Showing " + this 1561 + " during animation: policyVis=" + mWin.mPolicyVisibility 1562 + " attHidden=" + mWin.mAttachedHidden 1563 + " tok.hiddenRequested=" 1564 + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false) 1565 + " tok.hidden=" 1566 + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false) 1567 + " animating=" + mAnimating 1568 + " tok animating=" 1569 + (mAppAnimator != null ? mAppAnimator.animating : false)); 1570 } 1571 1572 mService.enableScreenIfNeededLocked(); 1573 1574 applyEnterAnimationLocked(); 1575 1576 // Force the show in the next prepareSurfaceLocked() call. 1577 mLastAlpha = -1; 1578 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) 1579 Slog.v(TAG, "performShowLocked: mDrawState=HAS_DRAWN in " + this); 1580 mDrawState = HAS_DRAWN; 1581 mService.scheduleAnimationLocked(); 1582 1583 int i = mWin.mChildWindows.size(); 1584 while (i > 0) { 1585 i--; 1586 WindowState c = mWin.mChildWindows.get(i); 1587 if (c.mAttachedHidden) { 1588 c.mAttachedHidden = false; 1589 if (c.mWinAnimator.mSurfaceControl != null) { 1590 c.mWinAnimator.performShowLocked(); 1591 // It hadn't been shown, which means layout not 1592 // performed on it, so now we want to make sure to 1593 // do a layout. If called from within the transaction 1594 // loop, this will cause it to restart with a new 1595 // layout. 1596 final DisplayContent displayContent = c.getDisplayContent(); 1597 if (displayContent != null) { 1598 displayContent.layoutNeeded = true; 1599 } 1600 } 1601 } 1602 } 1603 1604 if (mWin.mAttrs.type != TYPE_APPLICATION_STARTING 1605 && mWin.mAppToken != null) { 1606 mWin.mAppToken.firstWindowDrawn = true; 1607 1608 if (mWin.mAppToken.startingData != null) { 1609 if (WindowManagerService.DEBUG_STARTING_WINDOW || 1610 WindowManagerService.DEBUG_ANIM) Slog.v(TAG, 1611 "Finish starting " + mWin.mToken 1612 + ": first real window is shown, no animation"); 1613 // If this initial window is animating, stop it -- we 1614 // will do an animation to reveal it from behind the 1615 // starting window, so there is no need for it to also 1616 // be doing its own stuff. 1617 clearAnimation(); 1618 mService.mFinishedStarting.add(mWin.mAppToken); 1619 mService.mH.sendEmptyMessage(H.FINISHED_STARTING); 1620 } 1621 mWin.mAppToken.updateReportedVisibilityLocked(); 1622 } 1623 1624 return true; 1625 } 1626 1627 return false; 1628 } 1629 1630 /** 1631 * Have the surface flinger show a surface, robustly dealing with 1632 * error conditions. In particular, if there is not enough memory 1633 * to show the surface, then we will try to get rid of other surfaces 1634 * in order to succeed. 1635 * 1636 * @return Returns true if the surface was successfully shown. 1637 */ 1638 boolean showSurfaceRobustlyLocked() { 1639 try { 1640 if (mSurfaceControl != null) { 1641 mSurfaceShown = true; 1642 mSurfaceControl.show(); 1643 if (mWin.mTurnOnScreen) { 1644 if (DEBUG_VISIBILITY) Slog.v(TAG, 1645 "Show surface turning screen on: " + mWin); 1646 mWin.mTurnOnScreen = false; 1647 mAnimator.mBulkUpdateParams |= SET_TURN_ON_SCREEN; 1648 } 1649 } 1650 return true; 1651 } catch (RuntimeException e) { 1652 Slog.w(TAG, "Failure showing surface " + mSurfaceControl + " in " + mWin, e); 1653 } 1654 1655 mService.reclaimSomeSurfaceMemoryLocked(this, "show", true); 1656 1657 return false; 1658 } 1659 1660 void applyEnterAnimationLocked() { 1661 final int transit; 1662 if (mEnterAnimationPending) { 1663 mEnterAnimationPending = false; 1664 transit = WindowManagerPolicy.TRANSIT_ENTER; 1665 } else { 1666 transit = WindowManagerPolicy.TRANSIT_SHOW; 1667 } 1668 applyAnimationLocked(transit, true); 1669 //TODO (multidisplay): Magnification is supported only for the default display. 1670 if (mService.mAccessibilityController != null 1671 && mWin.getDisplayId() == Display.DEFAULT_DISPLAY) { 1672 mService.mAccessibilityController.onWindowTransitionLocked(mWin, transit); 1673 } 1674 } 1675 1676 /** 1677 * Choose the correct animation and set it to the passed WindowState. 1678 * @param transit If AppTransition.TRANSIT_PREVIEW_DONE and the app window has been drawn 1679 * then the animation will be app_starting_exit. Any other value loads the animation from 1680 * the switch statement below. 1681 * @param isEntrance The animation type the last time this was called. Used to keep from 1682 * loading the same animation twice. 1683 * @return true if an animation has been loaded. 1684 */ 1685 boolean applyAnimationLocked(int transit, boolean isEntrance) { 1686 if (mLocalAnimating && mAnimationIsEntrance == isEntrance) { 1687 // If we are trying to apply an animation, but already running 1688 // an animation of the same type, then just leave that one alone. 1689 return true; 1690 } 1691 1692 // Only apply an animation if the display isn't frozen. If it is 1693 // frozen, there is no reason to animate and it can cause strange 1694 // artifacts when we unfreeze the display if some different animation 1695 // is running. 1696 if (mService.okToDisplay()) { 1697 int anim = mPolicy.selectAnimationLw(mWin, transit); 1698 int attr = -1; 1699 Animation a = null; 1700 if (anim != 0) { 1701 a = anim != -1 ? AnimationUtils.loadAnimation(mContext, anim) : null; 1702 } else { 1703 switch (transit) { 1704 case WindowManagerPolicy.TRANSIT_ENTER: 1705 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; 1706 break; 1707 case WindowManagerPolicy.TRANSIT_EXIT: 1708 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; 1709 break; 1710 case WindowManagerPolicy.TRANSIT_SHOW: 1711 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; 1712 break; 1713 case WindowManagerPolicy.TRANSIT_HIDE: 1714 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; 1715 break; 1716 } 1717 if (attr >= 0) { 1718 a = mService.mAppTransition.loadAnimationAttr(mWin.mAttrs, attr); 1719 } 1720 } 1721 if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG, 1722 "applyAnimation: win=" + this 1723 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) 1724 + " a=" + a 1725 + " transit=" + transit 1726 + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3)); 1727 if (a != null) { 1728 if (WindowManagerService.DEBUG_ANIM) { 1729 RuntimeException e = null; 1730 if (!WindowManagerService.HIDE_STACK_CRAWLS) { 1731 e = new RuntimeException(); 1732 e.fillInStackTrace(); 1733 } 1734 Slog.v(TAG, "Loaded animation " + a + " for " + this, e); 1735 } 1736 setAnimation(a); 1737 mAnimationIsEntrance = isEntrance; 1738 } 1739 } else { 1740 clearAnimation(); 1741 } 1742 1743 return mAnimation != null; 1744 } 1745 1746 public void dump(PrintWriter pw, String prefix, boolean dumpAll) { 1747 if (mAnimating || mLocalAnimating || mAnimationIsEntrance 1748 || mAnimation != null) { 1749 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); 1750 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); 1751 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); 1752 pw.print(" mAnimation="); pw.println(mAnimation); 1753 } 1754 if (mHasTransformation || mHasLocalTransformation) { 1755 pw.print(prefix); pw.print("XForm: has="); 1756 pw.print(mHasTransformation); 1757 pw.print(" hasLocal="); pw.print(mHasLocalTransformation); 1758 pw.print(" "); mTransformation.printShortString(pw); 1759 pw.println(); 1760 } 1761 if (mSurfaceControl != null) { 1762 if (dumpAll) { 1763 pw.print(prefix); pw.print("mSurface="); pw.println(mSurfaceControl); 1764 pw.print(prefix); pw.print("mDrawState="); 1765 pw.print(drawStateToString(mDrawState)); 1766 pw.print(" mLastHidden="); pw.println(mLastHidden); 1767 } 1768 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); 1769 pw.print(" layer="); pw.print(mSurfaceLayer); 1770 pw.print(" alpha="); pw.print(mSurfaceAlpha); 1771 pw.print(" rect=("); pw.print(mSurfaceX); 1772 pw.print(","); pw.print(mSurfaceY); 1773 pw.print(") "); pw.print(mSurfaceW); 1774 pw.print(" x "); pw.println(mSurfaceH); 1775 } 1776 if (mPendingDestroySurface != null) { 1777 pw.print(prefix); pw.print("mPendingDestroySurface="); 1778 pw.println(mPendingDestroySurface); 1779 } 1780 if (mSurfaceResized || mSurfaceDestroyDeferred) { 1781 pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized); 1782 pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred); 1783 } 1784 if (mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND) { 1785 pw.print(prefix); pw.print("mUniverseTransform="); 1786 mUniverseTransform.printShortString(pw); 1787 pw.println(); 1788 } 1789 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { 1790 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); 1791 pw.print(" mAlpha="); pw.print(mAlpha); 1792 pw.print(" mLastAlpha="); pw.println(mLastAlpha); 1793 } 1794 if (mHaveMatrix || mWin.mGlobalScale != 1) { 1795 pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale); 1796 pw.print(" mDsDx="); pw.print(mDsDx); 1797 pw.print(" mDtDx="); pw.print(mDtDx); 1798 pw.print(" mDsDy="); pw.print(mDsDy); 1799 pw.print(" mDtDy="); pw.println(mDtDy); 1800 } 1801 } 1802 1803 @Override 1804 public String toString() { 1805 StringBuffer sb = new StringBuffer("WindowStateAnimator{"); 1806 sb.append(Integer.toHexString(System.identityHashCode(this))); 1807 sb.append(' '); 1808 sb.append(mWin.mAttrs.getTitle()); 1809 sb.append('}'); 1810 return sb.toString(); 1811 } 1812} 1813