Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d09cc4ba authored by Craig Mautner's avatar Craig Mautner
Browse files

Move more items between layout and animate sides.

- Isolate DimAnimator animation from the layout side.
- Isolate mWallpaperForceHidingChanged and mOrientationChangeComplete
  from the animation side.
- Eliminate a redundant setting of mOrientationChangeComplete to true.
  It was already true at that point.
- Synchronize changes to mWindows and mAppTokens on mAnimator. This is
  a nop until we go to multiple threads.
- Synchronize AppWindowToken.freezingScreen on mAnimator.
- Modification to repeat layout debugging including temporary enabling
  of spew on layout repeats.

Change-Id: Ic8d82b1c197144aaf6957caa5f71e175288220f2
parent 4a727e34
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -48,6 +48,8 @@ class AppWindowToken extends WindowToken {
    // application token.  Note this list is NOT sorted!
    final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();

    final WindowAnimator mAnimator;

    int groupId = -1;
    boolean appFullscreen;
    int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
@@ -88,6 +90,7 @@ class AppWindowToken extends WindowToken {
    boolean removed;

    // Have we been asked to have this token keep the screen frozen?
    // Protect with mAnimator.
    boolean freezingScreen;

    boolean animating;
@@ -126,6 +129,7 @@ class AppWindowToken extends WindowToken {
        appWindowToken = this;
        appToken = _token;
        mInputApplicationHandle = new InputApplicationHandle(this);
        mAnimator = service.mAnimator;
    }

    public void setAnimation(Animation anim, boolean initialized) {
@@ -235,11 +239,11 @@ class AppWindowToken extends WindowToken {
        thumbnailTransformation.clear();
        thumbnailAnimation.getTransformation(currentTime, thumbnailTransformation);
        thumbnailTransformation.getMatrix().preTranslate(thumbnailX, thumbnailY);
        final boolean screenAnimation = service.mAnimator.mScreenRotationAnimation != null
                && service.mAnimator.mScreenRotationAnimation.isAnimating();
        final boolean screenAnimation = mAnimator.mScreenRotationAnimation != null
                && mAnimator.mScreenRotationAnimation.isAnimating();
        if (screenAnimation) {
            thumbnailTransformation.postCompose(
                    service.mAnimator.mScreenRotationAnimation.getEnterTransformation());
                    mAnimator.mScreenRotationAnimation.getEnterTransformation());
        }
        // cache often used attributes locally
        final float tmpFloats[] = service.mTmpFloats;
@@ -336,9 +340,9 @@ class AppWindowToken extends WindowToken {
            return false;
        }

        service.mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
        mAnimator.mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
        if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
            service.debugLayoutRepeats("AppWindowToken");
            service.debugLayoutRepeats("AppWindowToken", mAnimator.mPendingLayoutChanges);
        }

        clearAnimation();
+23 −12
Original line number Diff line number Diff line
@@ -57,12 +57,17 @@ class DimAnimator {
    }

    /**
     * Show the dim surface.
     * Set's the dim surface's layer and update dim parameters that will be used in
     * {@link #updateSurface} after all windows are examined.
     */
    void show(int dw, int dh) {
    void updateParameters(final Resources res, final Parameters params, final long currentTime) {
        final int dw = params.mDimWidth;
        final int dh = params.mDimHeight;
        final WindowStateAnimator winAnimator = params.mDimWinAnimator;
        final float target = params.mDimTarget;
        if (!mDimShown) {
            if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, "  DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
                    dw + "x" + dh + ")");
            if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
                "  DIM " + mDimSurface + ": SHOW pos=(0,0) (" + dw + "x" + dh + ")");
            mDimShown = true;
            try {
                mLastDimWidth = dw;
@@ -78,17 +83,9 @@ class DimAnimator {
            mLastDimHeight = dh;
            mDimSurface.setSize(dw, dh);
        }
    }

    /**
     * Set's the dim surface's layer and update dim parameters that will be used in
     * {@link #updateSurface} after all windows are examined.
     */
    void updateParameters(Resources res, WindowState w, long currentTime) {
        final WindowStateAnimator winAnimator = w.mWinAnimator;
        mDimSurface.setLayer(winAnimator.mAnimLayer - WindowManagerService.LAYER_OFFSET_DIM);

        final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
        if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, "  DIM "
                + mDimSurface + ": layer=" + (winAnimator.mAnimLayer-1) + " target=" + target);
        if (mDimTargetAlpha != target) {
@@ -189,4 +186,18 @@ class DimAnimator {
        pw.print(" delta="); pw.print(mDimDeltaPerMs);
        pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
    }

    static class Parameters {
        final WindowStateAnimator mDimWinAnimator;
        final int mDimWidth;
        final int mDimHeight;
        final float mDimTarget;
        Parameters(final WindowStateAnimator dimWinAnimator, final int dimWidth,
                final int dimHeight, final float dimTarget) {
            mDimWinAnimator = dimWinAnimator;
            mDimWidth = dimWidth;
            mDimHeight = dimHeight;
            mDimTarget = dimTarget;
        }
    }
}
 No newline at end of file
+59 −23
Original line number Diff line number Diff line
@@ -6,6 +6,9 @@ import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;

import static com.android.server.wm.WindowManagerService.LayoutFields.SET_UPDATE_ROTATION;
import static com.android.server.wm.WindowManagerService.LayoutFields.SET_WALLPAPER_MAY_CHANGE;
import static com.android.server.wm.WindowManagerService.LayoutFields.SET_FORCE_HIDING_CHANGED;

import static com.android.server.wm.WindowManagerService.H.SET_DIM_PARAMETERS;

import android.content.Context;
import android.os.SystemClock;
@@ -67,6 +70,9 @@ public class WindowAnimator {

    int mBulkUpdateParams = 0;

    DimAnimator mDimAnimator = null;
    DimAnimator.Parameters mDimParams = null;

    WindowAnimator(final WindowManagerService service, final Context context,
            final WindowManagerPolicy policy) {
        mService = service;
@@ -91,7 +97,8 @@ public class WindowAnimator {
            if (mService.mWallpaperTarget == target
                    || mService.mLowerWallpaperTarget == target
                    || mService.mUpperWallpaperTarget == target) {
                for (int i=0; i<mService.mWindows.size(); i++) {
                final int N = mService.mWindows.size();
                for (int i = 0; i < N; i++) {
                    WindowState w = mService.mWindows.get(i);
                    if (w.mIsWallpaper) {
                        target = w;
@@ -125,7 +132,8 @@ public class WindowAnimator {
                // stopped animating, do one more pass through the layout
                mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
                if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
                    mService.debugLayoutRepeats("appToken " + appToken + " done");
                    mService.debugLayoutRepeats("appToken " + appToken + " done",
                        mPendingLayoutChanges);
                }
            }
        }
@@ -141,7 +149,8 @@ public class WindowAnimator {
                // stopped animating, do one more pass through the layout
                mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
                if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
                    mService.debugLayoutRepeats("exiting appToken " + appToken + " done");
                    mService.debugLayoutRepeats("exiting appToken " + appToken + " done",
                        mPendingLayoutChanges);
                }
            }
        }
@@ -185,13 +194,13 @@ public class WindowAnimator {
                                && winAnimator.mAnimation.getDetachWallpaper()) {
                            mDetachedWallpaper = w;
                        }
                        if (winAnimator.mAnimation.getBackgroundColor() != 0) {
                        final int backgroundColor = winAnimator.mAnimation.getBackgroundColor();
                        if (backgroundColor != 0) {
                            if (mWindowAnimationBackground == null
                                    || (winAnimator.mAnimLayer <
                                            mWindowAnimationBackground.mWinAnimator.mAnimLayer)) {
                                mWindowAnimationBackground = w;
                                mWindowAnimationBackgroundColor =
                                        winAnimator.mAnimation.getBackgroundColor();
                                mWindowAnimationBackgroundColor = backgroundColor;
                            }
                        }
                    }
@@ -207,13 +216,13 @@ public class WindowAnimator {
                            && w.mAppToken.animation.getDetachWallpaper()) {
                        mDetachedWallpaper = w;
                    }
                    if (w.mAppToken.animation.getBackgroundColor() != 0) {
                    final int backgroundColor = w.mAppToken.animation.getBackgroundColor();
                    if (backgroundColor != 0) {
                        if (mWindowAnimationBackground == null
                                || (winAnimator.mAnimLayer <
                                        mWindowAnimationBackground.mWinAnimator.mAnimLayer)) {
                            mWindowAnimationBackground = w;
                            mWindowAnimationBackgroundColor =
                                    w.mAppToken.animation.getBackgroundColor();
                            mWindowAnimationBackgroundColor = backgroundColor;
                        }
                    }
                }
@@ -222,7 +231,8 @@ public class WindowAnimator {
                    mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
                    mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
                    if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
                        mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 2");
                        mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 2",
                            mPendingLayoutChanges);
                    }
                }

@@ -231,17 +241,18 @@ public class WindowAnimator {
                        if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG,
                                "Animation started that could impact force hide: "
                                + w);
                        mService.mInnerFields.mWallpaperForceHidingChanged = true;
                        mBulkUpdateParams |= SET_FORCE_HIDING_CHANGED;
                        mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
                        if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
                            mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 3");
                            mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 3",
                                mPendingLayoutChanges);
                        }
                        mService.mFocusMayChange = true;
                    } else if (w.isReadyForDisplay() && winAnimator.mAnimation == null) {
                        mForceHiding = true;
                    }
                } else if (mPolicy.canBeForceHidden(w, attrs)) {
                    boolean changed;
                    final boolean changed;
                    if (mForceHiding) {
                        changed = w.hideLw(false, false);
                        if (WindowManagerService.DEBUG_VISIBILITY && changed) Slog.v(TAG,
@@ -251,7 +262,7 @@ public class WindowAnimator {
                        if (WindowManagerService.DEBUG_VISIBILITY && changed) Slog.v(TAG,
                                "Now policy shown: " + w);
                        if (changed) {
                            if (mService.mInnerFields.mWallpaperForceHidingChanged
                            if ((mBulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0
                                    && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
                                // Assume we will need to animate.  If
                                // we don't (because the wallpaper will
@@ -275,7 +286,8 @@ public class WindowAnimator {
                        mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
                        mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
                        if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
                            mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 4");
                            mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 4",
                                mPendingLayoutChanges);
                        }
                    }
                }
@@ -326,7 +338,8 @@ public class WindowAnimator {
                if (winAnimator.performShowLocked()) {
                    mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
                    if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
                        mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 5");
                        mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 5",
                            mPendingLayoutChanges);
                    }
                }
            }
@@ -361,7 +374,6 @@ public class WindowAnimator {
                            "Setting mOrientationChangeComplete=true because wtoken "
                            + wtoken + " numInteresting=" + numInteresting
                            + " numDrawn=" + wtoken.numDrawnWindows);
                    mService.mInnerFields.mOrientationChangeComplete = true;
                }
            } else if (!wtoken.allDrawn) {
                int numInteresting = wtoken.numInterestingWindows;
@@ -373,7 +385,8 @@ public class WindowAnimator {
                    wtoken.allDrawn = true;
                    mPendingLayoutChanges |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
                    if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
                        mService.debugLayoutRepeats("testTokenMayBeDrawnLocked");
                        mService.debugLayoutRepeats("testTokenMayBeDrawnLocked",
                            mPendingLayoutChanges);
                    }

                    // We can now show all of the drawn windows!
@@ -419,14 +432,13 @@ public class WindowAnimator {
                mScreenRotationAnimation.updateSurfaces();
            }

            final int N = mService.mWindows.size();
            for (int i=N-1; i>=0; i--) {
            for (int i = mService.mWindows.size() - 1; i >= 0; i--) {
                WindowState w = mService.mWindows.get(i);
                w.mWinAnimator.prepareSurfaceLocked(true);
            }

            if (mService.mDimAnimator != null && mService.mDimAnimator.mDimShown) {
                mAnimating |= mService.mDimAnimator.updateSurface(mService.mInnerFields.mDimming,
            if (mDimAnimator != null && mDimAnimator.mDimShown) {
                mAnimating |= mDimAnimator.updateSurface(mService.mInnerFields.mDimming,
                            mCurrentTime, !mService.okToDisplay());
            }

@@ -438,6 +450,10 @@ public class WindowAnimator {
                    mService.mBlackFrame.clearMatrix();
                }
            }

            if (mDimParams != null) {
                mDimAnimator.updateParameters(mContext.getResources(), mDimParams, mCurrentTime);
            }
        } catch (RuntimeException e) {
            Log.wtf(TAG, "Unhandled exception in Window Manager", e);
        } finally {
@@ -450,7 +466,7 @@ public class WindowAnimator {
    }

    WindowState mCurrentFocus;
    void setCurrentFocus(WindowState currentFocus) {
    void setCurrentFocus(final WindowState currentFocus) {
        mCurrentFocus = currentFocus;
    }

@@ -462,6 +478,20 @@ public class WindowAnimator {
        mInnerDh = appHeight;
    }

    void startDimming(final WindowStateAnimator winAnimator, final float target,
                      final int width, final int height) {
        if (mDimAnimator == null) {
            mDimAnimator = new DimAnimator(mService.mFxSession);
        }
        mService.mH.sendMessage(mService.mH.obtainMessage(SET_DIM_PARAMETERS,
                new DimAnimator.Parameters(winAnimator, width, height, target)));
    }

    // TODO(cmautner): Move into Handler
    void stopDimming() {
        mService.mH.sendMessage(mService.mH.obtainMessage(SET_DIM_PARAMETERS, null));
    }

    public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
        if (mWindowDetachedWallpaper != null) {
            pw.print("  mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
@@ -470,5 +500,11 @@ public class WindowAnimator {
            pw.println("  mWindowAnimationBackgroundSurface:");
            mWindowAnimationBackgroundSurface.printTo("    ", pw);
        }
        if (mDimAnimator != null) {
            pw.println("  mDimAnimator:");
            mDimAnimator.printTo("    ", pw);
        } else {
            pw.println( "  no DimAnimator ");
        }
    }
}
+127 −54

File changed.

Preview size limit exceeded, changes collapsed.

+3 −0
Original line number Diff line number Diff line
@@ -65,6 +65,9 @@ final class WindowState implements WindowManagerPolicy.WindowState {
    WindowToken mRootToken;
    AppWindowToken mAppToken;
    AppWindowToken mTargetAppToken;

    // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
    // modified they will need to be locked.
    final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
    final DeathRecipient mDeathRecipient;
    final WindowState mAttachedWindow;
Loading