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