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

Commit 7128c6aa authored by Evan Laird's avatar Evan Laird
Browse files

[Decor] Support ScreenDecorCommand in ScreenDecorations

This CL ties together the debug support added earlier to the
ScreenDecorCommand that now exists. It also makes the following changes:

1. Allow for nullable top/bottom rounded drawables in the ScreenDecorHwcLayer
2. Make ScreenDecorHwcLayer support dynamic color

Test: manual
Test: existing screendecor and command line tests
Bug: 285941724
Change-Id: I945e5086735b78718fbe388e5567c5f312834ae2
parent 92701259
Loading
Loading
Loading
Loading
+29 −3
Original line number Diff line number Diff line
@@ -56,9 +56,14 @@ class ScreenDecorHwcLayer(
) : DisplayCutoutBaseView(context) {
    val colorMode: Int
    private val useInvertedAlphaColor: Boolean
    private val color: Int
    private var color: Int = Color.BLACK
        set(value) {
            field = value
            paint.color = value
        }

    private val bgColor: Int
    private val cornerFilter: ColorFilter
    private var cornerFilter: ColorFilter
    private val cornerBgFilter: ColorFilter
    private val clearPaint: Paint
    @JvmField val transparentRect: Rect = Rect()
@@ -109,10 +114,16 @@ class ScreenDecorHwcLayer(
    override fun onAttachedToWindow() {
        super.onAttachedToWindow()
        parent.requestTransparentRegion(this)
        updateColors()
    }

    private fun updateColors() {
        if (!debug) {
            viewRootImpl.setDisplayDecoration(true)
        }

        cornerFilter = PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN)

        if (useInvertedAlphaColor) {
            paint.set(clearPaint)
        } else {
@@ -121,6 +132,21 @@ class ScreenDecorHwcLayer(
        }
    }

    fun setDebugColor(color: Int) {
        if (!debug) {
            return
        }

        if (this.color == color) {
            return
        }

        this.color = color

        updateColors()
        invalidate()
    }

    override fun onUpdate() {
        parent.requestTransparentRegion(this)
    }
@@ -367,7 +393,7 @@ class ScreenDecorHwcLayer(
    /**
     * Update the rounded corner drawables.
     */
    fun updateRoundedCornerDrawable(top: Drawable, bottom: Drawable) {
    fun updateRoundedCornerDrawable(top: Drawable?, bottom: Drawable?) {
        roundedCornerDrawableTop = top
        roundedCornerDrawableBottom = bottom
        updateRoundedCornerDrawableBounds()
+38 −2
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.decor.CutoutDecorProviderFactory;
import com.android.systemui.decor.DebugRoundedCornerDelegate;
import com.android.systemui.decor.DebugRoundedCornerModel;
import com.android.systemui.decor.DecorProvider;
import com.android.systemui.decor.DecorProviderFactory;
import com.android.systemui.decor.DecorProviderKt;
@@ -356,7 +357,42 @@ public class ScreenDecorations implements CoreStartable, Dumpable {
    };

    private final ScreenDecorCommand.Callback mScreenDecorCommandCallback = (cmd, pw) -> {
        android.util.Log.d(TAG, cmd.toString());
        // If we are exiting debug mode, we can set it (false) and bail, otherwise we will
        // ensure that debug mode is set
        if (cmd.getDebug() != null && !cmd.getDebug()) {
            setDebug(false);
            return;
        } else {
            // setDebug is idempotent
            setDebug(true);
        }

        if (cmd.getColor() != null) {
            mDebugColor = cmd.getColor();
            mExecutor.execute(() -> {
                if (mScreenDecorHwcLayer != null) {
                    mScreenDecorHwcLayer.setDebugColor(cmd.getColor());
                }
                updateColorInversionDefault();
            });
        }

        DebugRoundedCornerModel roundedTop = null;
        DebugRoundedCornerModel roundedBottom = null;
        if (cmd.getRoundedTop() != null) {
            roundedTop = cmd.getRoundedTop().toRoundedCornerDebugModel();
        }
        if (cmd.getRoundedBottom() != null) {
            roundedBottom = cmd.getRoundedBottom().toRoundedCornerDebugModel();
        }
        if (roundedTop != null || roundedBottom != null) {
            mDebugRoundedCornerDelegate.applyNewDebugCorners(roundedTop, roundedBottom);
            mExecutor.execute(() -> {
                removeAllOverlays();
                removeHwcOverlay();
                setupDecorations();
            });
        }
    };

    @Override
@@ -1239,7 +1275,7 @@ public class ScreenDecorations implements CoreStartable, Dumpable {
            bottomDrawable = mDebugRoundedCornerDelegate.getBottomRoundedDrawable();
        }

        if (topDrawable == null || bottomDrawable == null) {
        if (topDrawable == null && bottomDrawable == null) {
            return;
        }
        mScreenDecorHwcLayer.updateRoundedCornerDrawable(topDrawable, bottomDrawable);
+22 −8
Original line number Diff line number Diff line
@@ -77,16 +77,30 @@ class DebugRoundedCornerDelegate : RoundedCornerResDelegate {
    }

    fun applyNewDebugCorners(
        topCorner: DebugRoundedCornerModel,
        bottomCorner: DebugRoundedCornerModel,
        topCorner: DebugRoundedCornerModel?,
        bottomCorner: DebugRoundedCornerModel?,
    ) {
        topCorner?.let {
            hasTop = true
        topRoundedDrawable = topCorner.toPathDrawable(paint)
        topRoundedSize = topCorner.size()
            topRoundedDrawable = it.toPathDrawable(paint)
            topRoundedSize = it.size()
        }
            ?: {
                hasTop = false
                topRoundedDrawable = null
                topRoundedSize = Size(0, 0)
            }

        bottomCorner?.let {
            hasBottom = true
        bottomRoundedDrawable = bottomCorner.toPathDrawable(paint)
        bottomRoundedSize = bottomCorner.size()
            bottomRoundedDrawable = it.toPathDrawable(paint)
            bottomRoundedSize = it.size()
        }
            ?: {
                hasBottom = false
                bottomRoundedDrawable = null
                bottomRoundedSize = Size(0, 0)
            }
    }

    /**