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

Commit 89341c12 authored by Marzia Favaro's avatar Marzia Favaro
Browse files

Do not create dim layer until it gets a valid dimming request

If a window requests a dim of 0 and no blur, the dim surface gets created (because
technically someone is requesting to dim) and then immediately
destroyed (because alpha=0, blur=0 means that this layer should be destroyed as
it's useless). We can postpone creating a new surface until the window
requests a non 0 value.

Bug: 401449608
Test: DimmerTests
Flag: EXEMPT minor change
Change-Id: I11c97ae6401e3151df4941a5ec6ad42bb94357ce
parent b4a1b07e
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -211,15 +211,18 @@ class Dimmer {
     * child should call setAppearance again to request the Dim to continue.
     * If multiple containers call this method, only the changes relative to the topmost will be
     * applied.
     * The creation of the dim layer is delayed if the requested dim and blur are 0.
     * @param dimmingContainer  Container requesting the dim
     * @param alpha      Dim amount
     * @param blurRadius Blur amount
     */
    protected void adjustAppearance(@NonNull WindowState dimmingContainer,
                                    float alpha, int blurRadius) {
        if (mDimState != null || (alpha != 0 || blurRadius != 0)) {
            final DimState d = obtainDimState(dimmingContainer);
            d.prepareLookChange(alpha, blurRadius);
        }
    }

    /**
     * Position the dim relatively to the dimming container.
+29 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static com.android.server.wm.utils.LastCallVerifier.lastCall;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
@@ -432,4 +433,32 @@ public class DimmerTests extends WindowTestsBase {
        verify(mTransaction, never()).setAlpha(dimLayer, 0.5f);
        verify(mTransaction).setAlpha(dimLayer, 0.9f);
    }

    /**
     * A window requesting to dim to 0 and without blur would cause the dim to be created and
     * destroyed continuously.
     * Ensure the dim layer is not created until the window is requesting valid values.
     */
    @Test
    public void testDimNotCreatedIfNoAlphaNoBlur() {
        mDimmer.adjustAppearance(mChild1, 0.0f, 0);
        mDimmer.adjustPosition(mChild1, mChild1);
        assertNull(mDimmer.getDimLayer());
        mDimmer.updateDims(mTransaction);
        assertNull(mDimmer.getDimLayer());

        mDimmer.adjustAppearance(mChild1, 0.9f, 0);
        mDimmer.adjustPosition(mChild1, mChild1);
        assertNotNull(mDimmer.getDimLayer());
    }

    /**
     * If there is a blur, then the dim layer is created even though alpha is 0
     */
    @Test
    public void testDimCreatedIfNoAlphaButHasBlur() {
        mDimmer.adjustAppearance(mChild1, 0.0f, 10);
        mDimmer.adjustPosition(mChild1, mChild1);
        assertNotNull(mDimmer.getDimLayer());
    }
}