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