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