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