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

Commit 6d332c51 authored by Craig Mautner's avatar Craig Mautner Committed by Android (Google) Code Review
Browse files

Merge "Minor refactoring prior to major refactoring."

parents ad32461e 2fb98b14
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -222,7 +222,7 @@ class AppWindowToken extends WindowToken {

    // This must be called while inside a transaction.
    boolean stepAnimationLocked(long currentTime, int dw, int dh) {
        if (!service.mDisplayFrozen && service.mPolicy.isScreenOnFully()) {
        if (service.okToDisplay()) {
            // We will run animations as long as the display isn't frozen.

            if (animation == WindowManagerService.sDummyAnimation) {
+4 −2
Original line number Diff line number Diff line
@@ -32,12 +32,14 @@ public class BlackFrame {
    class BlackSurface {
        final int left;
        final int top;
        final int layer;
        final Surface surface;

        BlackSurface(SurfaceSession session, int layer, int l, int t, int r, int b)
                throws Surface.OutOfResourcesException {
            left = l;
            top = t;
            this.layer = layer;
            int w = r-l;
            int h = b-t;
            surface = new Surface(session, 0, "BlackSurface",
@@ -45,8 +47,6 @@ public class BlackFrame {
            if (WindowManagerService.SHOW_TRANSACTIONS ||
                    WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
                            "  BLACK " + surface + ": CREATE layer=" + layer);
            surface.setAlpha(1.0f);
            surface.setLayer(layer);
        }

        void setMatrix(Matrix matrix) {
@@ -58,6 +58,8 @@ public class BlackFrame {
            surface.setMatrix(
                    mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
                    mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
            surface.setAlpha(1.0f);
            surface.setLayer(layer);
            if (false) {
                Slog.i(WindowManagerService.TAG, "Black Surface @ (" + left + "," + top + "): ("
                        + mTmpFloats[Matrix.MTRANS_X] + ","
+7 −9
Original line number Diff line number Diff line
@@ -130,33 +130,31 @@ class DimAnimator {
            }
        }

        boolean animating = false;
        if (mLastDimAnimTime != 0) {
        boolean animating = mLastDimAnimTime != 0;
        if (animating) {
            mDimCurrentAlpha += mDimDeltaPerMs
                    * (currentTime-mLastDimAnimTime);
            boolean more = true;
            if (displayFrozen) {
                // If the display is frozen, there is no reason to animate.
                more = false;
                animating = false;
            } else if (mDimDeltaPerMs > 0) {
                if (mDimCurrentAlpha > mDimTargetAlpha) {
                    more = false;
                    animating = false;
                }
            } else if (mDimDeltaPerMs < 0) {
                if (mDimCurrentAlpha < mDimTargetAlpha) {
                    more = false;
                    animating = false;
                }
            } else {
                more = false;
                animating = false;
            }

            // Do we need to continue animating?
            if (more) {
            if (animating) {
                if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, "  DIM "
                        + mDimSurface + ": alpha=" + mDimCurrentAlpha);
                mLastDimAnimTime = currentTime;
                mDimSurface.setAlpha(mDimCurrentAlpha);
                animating = true;
            } else {
                mDimCurrentAlpha = mDimTargetAlpha;
                mLastDimAnimTime = 0;
+63 −139
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.server.wm;

import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
@@ -173,7 +172,6 @@ public class WindowManagerService extends IWindowManager.Stub
    static final boolean HIDE_STACK_CRAWLS = true;

    static final boolean PROFILE_ORIENTATION = false;
    static final boolean BLUR = true;
    static final boolean localLOGV = DEBUG;

    /** How much to multiply the policy's type layer, to reserve room
@@ -195,11 +193,6 @@ public class WindowManagerService extends IWindowManager.Stub
     */
    static final int LAYER_OFFSET_DIM = 1;

    /**
     * Blur surface layer is immediately below dim layer.
     */
    static final int LAYER_OFFSET_BLUR = 2;

    /**
     * Layer at which to put the rotation freeze snapshot.
     */
@@ -416,8 +409,6 @@ public class WindowManagerService extends IWindowManager.Stub

    SurfaceSession mFxSession;
    private DimAnimator mDimAnimator = null;
    Surface mBlurSurface;
    boolean mBlurShown;
    Watermark mWatermark;
    StrictModeFlash mStrictModeFlash;
    ScreenRotationAnimation mScreenRotationAnimation;
@@ -597,7 +588,6 @@ public class WindowManagerService extends IWindowManager.Stub
        private int mAdjResult = 0;
        private Session mHoldScreen = null;
        private boolean mObscured = false;
        private boolean mBlurring = false;
        private boolean mDimming = false;
        private boolean mSyswin = false;
        private float mScreenBrightness = -1;
@@ -735,6 +725,7 @@ public class WindowManagerService extends IWindowManager.Stub
            mAllowBootMessages = allowBootMsgs;
        }

        @Override
        public void run() {
            Looper.prepare();
            WindowManagerService s = new WindowManagerService(mContext, mPM,
@@ -774,6 +765,7 @@ public class WindowManagerService extends IWindowManager.Stub
            mPM = pm;
        }

        @Override
        public void run() {
            Looper.prepare();
            WindowManagerPolicyThread.set(this, Looper.myLooper());
@@ -2302,8 +2294,7 @@ public class WindowManagerService extends IWindowManager.Stub
        // to hold off on removing the window until the animation is done.
        // If the display is frozen, just remove immediately, since the
        // animation wouldn't be seen.
        if (win.mSurface != null && !mDisplayFrozen && mDisplayEnabled
                && mPolicy.isScreenOnFully()) {
        if (win.mSurface != null && okToDisplay()) {
            // If we are not currently running the exit animation, we
            // need to see about starting one.
            if (wasVisible=win.isWinVisibleLw()) {
@@ -2687,8 +2678,7 @@ public class WindowManagerService extends IWindowManager.Stub
                    win.mEnterAnimationPending = true;
                }
                if (displayed) {
                    if (win.isDrawnLw() && !mDisplayFrozen
                            && mDisplayEnabled && mPolicy.isScreenOnFully()) {
                    if (win.isDrawnLw() && okToDisplay()) {
                        applyEnterAnimationLocked(win);
                    }
                    if ((win.mAttrs.flags
@@ -3015,7 +3005,7 @@ public class WindowManagerService extends IWindowManager.Stub
        // frozen, there is no reason to animate and it can cause strange
        // artifacts when we unfreeze the display if some different animation
        // is running.
        if (!mDisplayFrozen && mDisplayEnabled && mPolicy.isScreenOnFully()) {
        if (okToDisplay()) {
            int anim = mPolicy.selectAnimationLw(win, transit);
            int attr = -1;
            Animation a = null;
@@ -3101,7 +3091,7 @@ public class WindowManagerService extends IWindowManager.Stub
        // frozen, there is no reason to animate and it can cause strange
        // artifacts when we unfreeze the display if some different animation
        // is running.
        if (!mDisplayFrozen && mDisplayEnabled && mPolicy.isScreenOnFully()) {
        if (okToDisplay()) {
            Animation a;
            if (mNextAppTransitionPackage != null) {
                a = loadAnimation(mNextAppTransitionPackage, enter ?
@@ -3235,6 +3225,10 @@ public class WindowManagerService extends IWindowManager.Stub
        return false;
    }
    
    boolean okToDisplay() {
        return !mDisplayFrozen && mDisplayEnabled && mPolicy.isScreenOnFully();
    }

    AppWindowToken findAppWindowToken(IBinder token) {
        WindowToken wtoken = mTokenMap.get(token);
        if (wtoken == null) {
@@ -3665,7 +3659,7 @@ public class WindowManagerService extends IWindowManager.Stub
            if (DEBUG_APP_TRANSITIONS) Slog.v(
                    TAG, "Prepare app transition: transit=" + transit
                    + " mNextAppTransition=" + mNextAppTransition);
            if (!mDisplayFrozen && mDisplayEnabled && mPolicy.isScreenOnFully()) {
            if (okToDisplay()) {
                if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
                        || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
                    mNextAppTransition = transit;
@@ -3749,7 +3743,7 @@ public class WindowManagerService extends IWindowManager.Stub
            // If the display is frozen, we won't do anything until the
            // actual window is displayed so there is no reason to put in
            // the starting window.
            if (mDisplayFrozen || !mDisplayEnabled || !mPolicy.isScreenOnFully()) {
            if (!okToDisplay()) {
                return;
            }

@@ -4039,8 +4033,7 @@ public class WindowManagerService extends IWindowManager.Stub

            // If we are preparing an app transition, then delay changing
            // the visibility of this token until we execute that transition.
            if (!mDisplayFrozen && mDisplayEnabled && mPolicy.isScreenOnFully()
                    && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
            if (okToDisplay() && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
                // Already in requested state, don't do anything more.
                if (wtoken.hiddenRequested != visible) {
                    return;
@@ -4168,7 +4161,7 @@ public class WindowManagerService extends IWindowManager.Stub
        }

        synchronized(mWindowMap) {
            if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOnFully()) {
            if (configChanges == 0 && okToDisplay()) {
                if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
                return;
            }
@@ -5476,7 +5469,7 @@ public class WindowManagerService extends IWindowManager.Stub
            }
        }

        rebuildBlackFrame(inTransaction);
        rebuildBlackFrame();

        for (int i=mWindows.size()-1; i>=0; i--) {
            WindowState w = mWindows.get(i);
@@ -7151,13 +7144,7 @@ public class WindowManagerService extends IWindowManager.Stub
        }
    }

    private void rebuildBlackFrame(boolean inTransaction) {
        if (!inTransaction) {
            if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
                    ">>> OPEN TRANSACTION rebuildBlackFrame");
            Surface.openTransaction();
        }
        try {
    private void rebuildBlackFrame() {
        if (mBlackFrame != null) {
            mBlackFrame.kill();
            mBlackFrame = null;
@@ -7185,13 +7172,6 @@ public class WindowManagerService extends IWindowManager.Stub
            } catch (Surface.OutOfResourcesException e) {
            }
        }
        } finally {
            if (!inTransaction) {
                Surface.closeTransaction();
                if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
                        "<<< CLOSE TRANSACTION rebuildBlackFrame");
            }
        }
    }

    private void readForcedDisplaySizeLocked() {
@@ -7240,7 +7220,7 @@ public class WindowManagerService extends IWindowManager.Stub
            mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
        }

        rebuildBlackFrame(false);
        rebuildBlackFrame();

        performLayoutAndPlaceSurfacesLocked();
    }
@@ -7625,7 +7605,7 @@ public class WindowManagerService extends IWindowManager.Stub
        // If the screen is currently frozen or off, then keep
        // it frozen/off until this window draws at its new
        // orientation.
        if (mDisplayFrozen || !mPolicy.isScreenOnFully()) {
        if (!okToDisplay()) {
            if (DEBUG_ORIENTATION) Slog.v(TAG,
                    "Changing surface while display frozen: " + w);
            w.mOrientationChanging = true;
@@ -7707,18 +7687,7 @@ public class WindowManagerService extends IWindowManager.Stub
            if (mDimAnimator != null && mDimAnimator.mDimShown) {
                mInnerFields.mAnimating |=
                        mDimAnimator.updateSurface(mInnerFields.mDimming, currentTime,
                            mDisplayFrozen || !mDisplayEnabled || !mPolicy.isScreenOnFully());
            }
        
            if (!mInnerFields.mBlurring && mBlurShown) {
                if (SHOW_TRANSACTIONS) Slog.i(TAG, "  BLUR " + mBlurSurface
                        + ": HIDE");
                try {
                    mBlurSurface.hide();
                } catch (IllegalArgumentException e) {
                    Slog.w(TAG, "Illegal argument exception hiding blur surface");
                }
                mBlurShown = false;
                            !okToDisplay());
            }
        
            if (mBlackFrame != null) {
@@ -7747,6 +7716,8 @@ public class WindowManagerService extends IWindowManager.Stub
     */
    private int updateWindowsAndWallpaperLocked(final long currentTime, final int dw, final int dh,
                                                final int innerDw, final int innerDh) {
        ++mTransactionSequence;

        int changes = 0;
        for (int i = mWindows.size() - 1; i >= 0; i--) {
            WindowState w = mWindows.get(i);
@@ -8301,9 +8272,9 @@ public class WindowManagerService extends IWindowManager.Stub
            // target, then the black goes *below* the wallpaper so we
            // don't cause the wallpaper to suddenly disappear.
            WindowState target = mInnerFields.mWindowAnimationBackground;
            if (mWallpaperTarget == mInnerFields.mWindowAnimationBackground
                    || mLowerWallpaperTarget == mInnerFields.mWindowAnimationBackground
                    || mUpperWallpaperTarget == mInnerFields.mWindowAnimationBackground) {
            if (mWallpaperTarget == target
                    || mLowerWallpaperTarget == target
                    || mUpperWallpaperTarget == target) {
                for (int i=0; i<mWindows.size(); i++) {
                    WindowState w = mWindows.get(i);
                    if (w.mIsWallpaper) {
@@ -8656,14 +8627,11 @@ public class WindowManagerService extends IWindowManager.Stub
        boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
        if (opaqueDrawn && w.isFullscreen(innerDw, innerDh)) {
            // This window completely covers everything behind it,
            // so we want to leave all of them as unblurred (for
            // so we want to leave all of them as undimmed (for
            // performance reasons).
            mInnerFields.mObscured = true;
        } else if (canBeSeen && (attrFlags & (FLAG_BLUR_BEHIND | FLAG_DIM_BEHIND)) != 0) {
            if (localLOGV) Slog.v(TAG, "Win " + w
                    + ": blurring=" + mInnerFields.mBlurring
                    + " obscured=" + mInnerFields.mObscured);
            if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
        } else if (canBeSeen && (attrFlags & FLAG_DIM_BEHIND) != 0) {
            if (localLOGV) Slog.v(TAG, "Win " + w + " obscured=" + mInnerFields.mObscured);
            if (!mInnerFields.mDimming) {
                //Slog.i(TAG, "DIM BEHIND: " + w);
                mInnerFields.mDimming = true;
@@ -8679,52 +8647,10 @@ public class WindowManagerService extends IWindowManager.Stub
                        w, currentTime);
            }
        }
            if ((attrFlags & FLAG_BLUR_BEHIND) != 0) {
                if (!mInnerFields.mBlurring) {
                    //Slog.i(TAG, "BLUR BEHIND: " + w);
                    mInnerFields.mBlurring = true;
                    if (mBlurSurface == null) {
                        try {
                            mBlurSurface = new Surface(mFxSession, 0,
                                    "BlurSurface",
                                    -1, 16, 16,
                                    PixelFormat.OPAQUE,
                                    Surface.FX_SURFACE_BLUR);
                        } catch (Exception e) {
                            Slog.e(TAG, "Exception creating Blur surface", e);
                        }
                        if (SHOW_TRANSACTIONS) Slog.i(TAG, "  BLUR "
                                + mBlurSurface + ": CREATE");
                    }
                    final int dw = mCurDisplayWidth;
                    final int dh = mCurDisplayHeight;
                    if (mBlurSurface != null) {
                        if (SHOW_TRANSACTIONS) Slog.i(TAG, "  BLUR "
                                + mBlurSurface + ": pos=(0,0) (" +
                                dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
                        mBlurSurface.setPosition(0, 0);
                        mBlurSurface.setSize(dw, dh);
                        mBlurSurface.setLayer(w.mAnimLayer-LAYER_OFFSET_BLUR);
                        if (!mBlurShown) {
                            try {
                                if (SHOW_TRANSACTIONS) Slog.i(TAG, "  BLUR "
                                        + mBlurSurface + ": SHOW");
                                mBlurSurface.show();
                            } catch (RuntimeException e) {
                                Slog.w(TAG, "Failure showing blur surface", e);
                            }
                            mBlurShown = true;
                        }
                    }
                }
            }
        }
    }

    private final int performAnimationsLocked(long currentTime, int dw, int dh,
            int innerDw, int innerDh) {
        ++mTransactionSequence;

        if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
                + mTransactionSequence + " mAnimating="
                + mInnerFields.mAnimating);
@@ -8895,7 +8821,6 @@ public class WindowManagerService extends IWindowManager.Stub
            final boolean someoneLosingFocus = !mLosingFocus.isEmpty();

            mInnerFields.mObscured = false;
            mInnerFields.mBlurring = false;
            mInnerFields.mDimming = false;
            mInnerFields.mSyswin = false;
            
@@ -9986,8 +9911,7 @@ public class WindowManagerService extends IWindowManager.Stub
            }
            pw.print("  mSystemBooted="); pw.print(mSystemBooted);
                    pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
            pw.print("  mLayoutNeeded="); pw.print(mLayoutNeeded);
                    pw.print(" mBlurShown="); pw.println(mBlurShown);
            pw.print("  mLayoutNeeded="); pw.println(mLayoutNeeded);
            if (mDimAnimator != null) {
                pw.println("  mDimAnimator:");
                mDimAnimator.printTo("    ", pw);
+5 −6
Original line number Diff line number Diff line
@@ -1011,7 +1011,7 @@ final class WindowState implements WindowManagerPolicy.WindowState {
        // Save the animation state as it was before this step so WindowManagerService can tell if
        // we just started or just stopped animating by comparing mWasAnimating with isAnimating().
        mWasAnimating = mAnimating;
        if (!mService.mDisplayFrozen && mService.mPolicy.isScreenOnFully()) {
        if (mService.okToDisplay()) {
            // We will run animations as long as the display isn't frozen.

            if (isDrawnLw() && mAnimation != null) {
@@ -1515,11 +1515,10 @@ final class WindowState implements WindowManagerPolicy.WindowState {
     * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
     */
    boolean shouldAnimateMove() {
        return mContentChanged && !mExiting && !mLastHidden && !mService.mDisplayFrozen
        return mContentChanged && !mExiting && !mLastHidden && mService.okToDisplay()
                && (mFrame.top != mLastFrame.top
                        || mFrame.left != mLastFrame.left)
                && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
                && mService.mPolicy.isScreenOnFully();
                && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove());
    }

    boolean isFullscreen(int screenWidth, int screenHeight) {
@@ -1606,7 +1605,7 @@ final class WindowState implements WindowManagerPolicy.WindowState {
        if (doAnimation) {
            if (DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "doAnimation: mPolicyVisibility="
                    + mPolicyVisibility + " mAnimation=" + mAnimation);
            if (mService.mDisplayFrozen || !mService.mPolicy.isScreenOnFully()) {
            if (!mService.okToDisplay()) {
                doAnimation = false;
            } else if (mPolicyVisibility && mAnimation == null) {
                // Check for the case where we are currently visible and
@@ -1632,7 +1631,7 @@ final class WindowState implements WindowManagerPolicy.WindowState {

    boolean hideLw(boolean doAnimation, boolean requestAnim) {
        if (doAnimation) {
            if (mService.mDisplayFrozen || !mService.mPolicy.isScreenOnFully()) {
            if (!mService.okToDisplay()) {
                doAnimation = false;
            }
        }