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

Commit 7e1bb6e4 authored by Galia Peycheva's avatar Galia Peycheva
Browse files

Move background blur to Dim layer

The way background blur is expected to work is the same as the dim
layer - it should be cropped to the task/displayArea bounds and dim
layers shouldn't stack on top of each other. This CL makes the
background blur benefit from that and sets it on the dim surface
control.

Bug: 171679369
Test: m && flash
Test: atest DimmerTests

Change-Id: If64cc585a8a74ab5f3dc0757e25556fd89b5eaec
parent 0e75d9e4
Loading
Loading
Loading
Loading
+11 −8
Original line number Original line Diff line number Diff line
@@ -204,7 +204,7 @@ class Dimmer {
    }
    }


    private void dim(SurfaceControl.Transaction t, WindowContainer container, int relativeLayer,
    private void dim(SurfaceControl.Transaction t, WindowContainer container, int relativeLayer,
            float alpha) {
            float alpha, int blurRadius) {
        final DimState d = getDimState(container);
        final DimState d = getDimState(container);


        if (d == null) {
        if (d == null) {
@@ -220,6 +220,7 @@ class Dimmer {
            t.setLayer(d.mDimLayer, Integer.MAX_VALUE);
            t.setLayer(d.mDimLayer, Integer.MAX_VALUE);
        }
        }
        t.setAlpha(d.mDimLayer, alpha);
        t.setAlpha(d.mDimLayer, alpha);
        t.setBackgroundBlurRadius(d.mDimLayer, blurRadius);


        d.mDimming = true;
        d.mDimming = true;
    }
    }
@@ -247,7 +248,7 @@ class Dimmer {
     * @param alpha The alpha at which to Dim.
     * @param alpha The alpha at which to Dim.
     */
     */
    void dimAbove(SurfaceControl.Transaction t, float alpha) {
    void dimAbove(SurfaceControl.Transaction t, float alpha) {
        dim(t, null, 1, alpha);
        dim(t, null, 1, alpha, 0);
    }
    }


    /**
    /**
@@ -260,7 +261,7 @@ class Dimmer {
     * @param alpha     The alpha at which to Dim.
     * @param alpha     The alpha at which to Dim.
     */
     */
    void dimAbove(SurfaceControl.Transaction t, WindowContainer container, float alpha) {
    void dimAbove(SurfaceControl.Transaction t, WindowContainer container, float alpha) {
        dim(t, container, 1, alpha);
        dim(t, container, 1, alpha, 0);
    }
    }


    /**
    /**
@@ -269,10 +270,12 @@ class Dimmer {
     * @param t          A transaction in which to apply the Dim.
     * @param t          A transaction in which to apply the Dim.
     * @param container  The container which to dim below. Should be a child of our host.
     * @param container  The container which to dim below. Should be a child of our host.
     * @param alpha      The alpha at which to Dim.
     * @param alpha      The alpha at which to Dim.
     * @param blurRadius The amount of blur added to the Dim.
     */
     */


    void dimBelow(SurfaceControl.Transaction t, WindowContainer container, float alpha) {
    void dimBelow(SurfaceControl.Transaction t, WindowContainer container, float alpha,
        dim(t, container, -1, alpha);
                  int blurRadius) {
        dim(t, container, -1, alpha, blurRadius);
    }
    }


    /**
    /**
+7 −4
Original line number Original line Diff line number Diff line
@@ -5228,14 +5228,17 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        if (!mAnimatingExit && mAppDied) {
        if (!mAnimatingExit && mAppDied) {
            mIsDimming = true;
            mIsDimming = true;
            getDimmer().dimAbove(getSyncTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW);
            getDimmer().dimAbove(getSyncTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW);
        } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 && isVisibleNow() && !mHidden) {
        } else if (((mAttrs.flags & FLAG_DIM_BEHIND) != 0 || mAttrs.backgroundBlurRadius != 0)
            // Only show a dim behind when the following is satisfied:
                   && isVisibleNow() && !mHidden) {
            // 1. The window has the flag FLAG_DIM_BEHIND
            // Only show the Dimmer when the following is satisfied:
            // 1. The window has the flag FLAG_DIM_BEHIND or background blur is requested
            // 2. The WindowToken is not hidden so dims aren't shown when the window is exiting.
            // 2. The WindowToken is not hidden so dims aren't shown when the window is exiting.
            // 3. The WS is considered visible according to the isVisible() method
            // 3. The WS is considered visible according to the isVisible() method
            // 4. The WS is not hidden.
            // 4. The WS is not hidden.
            mIsDimming = true;
            mIsDimming = true;
            getDimmer().dimBelow(getSyncTransaction(), this, mAttrs.dimAmount);
            final float dimAmount = (mAttrs.flags & FLAG_DIM_BEHIND) != 0 ? mAttrs.dimAmount : 0;
            getDimmer().dimBelow(
                    getSyncTransaction(), this, mAttrs.dimAmount, mAttrs.backgroundBlurRadius);
        }
        }
    }
    }


+0 −1
Original line number Original line Diff line number Diff line
@@ -795,7 +795,6 @@ class WindowStateAnimator {


        if (displayed) {
        if (displayed) {
            w.mToken.hasVisible = true;
            w.mToken.hasVisible = true;
            mSurfaceController.setBackgroundBlurRadius(w.mAttrs.backgroundBlurRadius);
        }
        }
    }
    }


+0 −22
Original line number Original line Diff line number Diff line
@@ -64,8 +64,6 @@ class WindowSurfaceController {
    private float mLastDsdy = 0;
    private float mLastDsdy = 0;
    private float mLastDtdy = 1;
    private float mLastDtdy = 1;


    private int mLastBackgroundBlurRadius = 0;

    private float mSurfaceAlpha = 0;
    private float mSurfaceAlpha = 0;


    private int mSurfaceLayer = 0;
    private int mSurfaceLayer = 0;
@@ -242,26 +240,6 @@ class WindowSurfaceController {
        }
        }
    }
    }


    void setBackgroundBlurRadius(int radius) {
        ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE backgroundBlur=%o: %s", radius, title);

        if (mSurfaceControl == null || radius == mLastBackgroundBlurRadius) {
            return;
        }
        mLastBackgroundBlurRadius = radius;

        if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setBackgroundBlurRadius");
        mService.openSurfaceTransaction();
        try {
            getGlobalTransaction().setBackgroundBlurRadius(mSurfaceControl, radius);
        } finally {
            mService.closeSurfaceTransaction("setBackgroundBlurRadius");
            if (SHOW_LIGHT_TRANSACTIONS) {
                Slog.i(TAG, "<<< CLOSE TRANSACTION setBackgroundBlurRadius");
            }
        }
    }

    void setSecure(boolean isSecure) {
    void setSecure(boolean isSecure) {
        ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE isSecure=%b: %s", isSecure, title);
        ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE isSecure=%b: %s", isSecure, title);


+1 −1
Original line number Original line Diff line number Diff line
@@ -199,7 +199,7 @@ public class DimmerTests extends WindowTestsBase {
        mHost.addChild(child, 0);
        mHost.addChild(child, 0);


        final float alpha = 0.8f;
        final float alpha = 0.8f;
        mDimmer.dimBelow(mTransaction, child, alpha);
        mDimmer.dimBelow(mTransaction, child, alpha, 0);
        SurfaceControl dimLayer = getDimLayer();
        SurfaceControl dimLayer = getDimLayer();


        assertNotNull("Dimmer should have created a surface", dimLayer);
        assertNotNull("Dimmer should have created a surface", dimLayer);
Loading