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

Commit c092c439 authored by Tony Huang's avatar Tony Huang Committed by Selim Cinek
Browse files

Refactor for tuning gfx-max-frame-time-99

Because canvas.clipPath() is heavy operation for GPU, draw roundness
background on notification row which need clip. However, some case
still can not handle will use clipPath as current design

Bug: 71900748
Test: atest SystemUITests & SystemUiJankTests#testNotificationListScroll
Change-Id: Ibc776ebd2f0dce5db7a2eb953ee6fac1747dea5a
parent 645c8671
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -515,6 +515,13 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
        }
    }

    @Override
    public void setDistanceToTopRoundness(float distanceToTopRoundness) {
        super.setDistanceToTopRoundness(distanceToTopRoundness);
        mBackgroundNormal.setDistanceToTopRoundness(distanceToTopRoundness);
        mBackgroundDimmed.setDistanceToTopRoundness(distanceToTopRoundness);
    }

    /**
     * Set an override tint color that is used for the background.
     *
+18 −0
Original line number Diff line number Diff line
@@ -2789,6 +2789,24 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        }
    }

    @Override
    public boolean topAmountNeedsClipping() {
        if (isGroupExpanded()) {
            return true;
        }
        if (isGroupExpansionChanging()) {
            return true;
        }
        if (getShowingLayout().shouldClipToRounding(true /* topRounded */,
                false /* bottomRounded */)) {
            return true;
        }
        if (mGuts != null && mGuts.getAlpha() != 0.0f) {
            return true;
        }
        return false;
    }

    @Override
    protected boolean childNeedsClipping(View child) {
        if (child instanceof NotificationContentView) {
+17 −8
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ public abstract class ExpandableOutlineView extends ExpandableView {
     * it is moved. Otherwise, the translation is set on the {@code ExpandableOutlineView} itself.
     */
    protected boolean mShouldTranslateContents;
    private boolean mClipRoundedToClipTopAmount;
    private boolean mTopAmountRounded;
    private float mDistanceToTopRoundness = -1;
    private float mExtraWidthForClipping;
    private int mMinimumHeightForClipping = 0;
@@ -85,7 +85,8 @@ public abstract class ExpandableOutlineView extends ExpandableView {
        @Override
        public void getOutline(View view, Outline outline) {
            if (!mCustomOutline && mCurrentTopRoundness == 0.0f
                    && mCurrentBottomRoundness == 0.0f && !mAlwaysRoundBothCorners) {
                    && mCurrentBottomRoundness == 0.0f && !mAlwaysRoundBothCorners
                    && !mTopAmountRounded) {
                int translation = mShouldTranslateContents ? (int) getTranslation() : 0;
                int left = Math.max(translation, 0);
                int top = mClipTopAmount + mBackgroundTop;
@@ -145,9 +146,9 @@ public abstract class ExpandableOutlineView extends ExpandableView {
            return EMPTY_PATH;
        }
        float topRoundness = mAlwaysRoundBothCorners
                ? mOutlineRadius : mCurrentTopRoundness * mOutlineRadius;
                ? mOutlineRadius : getCurrentBackgroundRadiusTop();
        float bottomRoundness = mAlwaysRoundBothCorners
                ? mOutlineRadius : mCurrentBottomRoundness * mOutlineRadius;
                ? mOutlineRadius : getCurrentBackgroundRadiusBottom();
        if (topRoundness + bottomRoundness > height) {
            float overShoot = topRoundness + bottomRoundness - height;
            topRoundness -= overShoot * mCurrentTopRoundness
@@ -203,7 +204,7 @@ public abstract class ExpandableOutlineView extends ExpandableView {
    protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
        canvas.save();
        Path intersectPath = null;
        if (mClipRoundedToClipTopAmount) {
        if (mTopAmountRounded && topAmountNeedsClipping()) {
            int left = (int) (- mExtraWidthForClipping / 2.0f);
            int top = (int) (mClipTopAmount - mDistanceToTopRoundness);
            int right = getWidth() + (int) (mExtraWidthForClipping + left);
@@ -248,9 +249,9 @@ public abstract class ExpandableOutlineView extends ExpandableView {
    public void setDistanceToTopRoundness(float distanceToTopRoundness) {
        super.setDistanceToTopRoundness(distanceToTopRoundness);
        if (distanceToTopRoundness != mDistanceToTopRoundness) {
            mClipRoundedToClipTopAmount = distanceToTopRoundness >= 0;
            mTopAmountRounded = distanceToTopRoundness >= 0;
            mDistanceToTopRoundness = distanceToTopRoundness;
            invalidate();
            applyRoundness();
        }
    }

@@ -258,9 +259,12 @@ public abstract class ExpandableOutlineView extends ExpandableView {
        return false;
    }

    public boolean topAmountNeedsClipping() {
        return true;
    }

    protected boolean isClippingNeeded() {
        return mAlwaysRoundBothCorners || mCustomOutline || getTranslation() != 0 ;

    }

    private void initDimens() {
@@ -296,6 +300,11 @@ public abstract class ExpandableOutlineView extends ExpandableView {
    }

    public float getCurrentBackgroundRadiusTop() {
        // If this view is top amount notification view, it should always has round corners on top.
        // It will be applied with applyRoundness()
        if (mTopAmountRounded) {
            return mOutlineRadius;
        }
        return mCurrentTopRoundness * mOutlineRadius;
    }

+23 −1
Original line number Diff line number Diff line
@@ -53,6 +53,9 @@ public class NotificationBackgroundView extends View {
    private int mDrawableAlpha = 255;
    private boolean mIsPressedAllowed;

    private boolean mTopAmountRounded;
    private float mDistanceToTopRoundness;

    public NotificationBackgroundView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mDontModifyCorners = getResources().getBoolean(
@@ -74,6 +77,7 @@ public class NotificationBackgroundView extends View {

    private void draw(Canvas canvas, Drawable drawable) {
        if (drawable != null) {
            int top = mBackgroundTop;
            int bottom = mActualHeight;
            if (mBottomIsRounded && mBottomAmountClips && !mExpandAnimationRunning) {
                bottom -= mClipBottomAmount;
@@ -84,7 +88,14 @@ public class NotificationBackgroundView extends View {
                left = (int) ((getWidth() - mActualWidth) / 2.0f);
                right = (int) (left + mActualWidth);
            }
            drawable.setBounds(left, mBackgroundTop, right, bottom);
            if (mTopAmountRounded) {
                int clipTop = (int) (mClipTopAmount - mDistanceToTopRoundness);
                top += clipTop;
                if (clipTop >= 0) {
                    bottom += clipTop;
                }
            }
            drawable.setBounds(left, top, right, bottom);
            drawable.draw(canvas);
        }
    }
@@ -165,6 +176,14 @@ public class NotificationBackgroundView extends View {
        invalidate();
    }

    public void setDistanceToTopRoundness(float distanceToTopRoundness) {
        if (distanceToTopRoundness != mDistanceToTopRoundness) {
            mTopAmountRounded = distanceToTopRoundness >= 0;
            mDistanceToTopRoundness = distanceToTopRoundness;
            invalidate();
        }
    }

    @Override
    public boolean hasOverlappingRendering() {

@@ -198,6 +217,9 @@ public class NotificationBackgroundView extends View {
    }

    public void setRoundness(float topRoundness, float bottomRoundNess) {
        if (topRoundness == mCornerRadii[0] && bottomRoundNess == mCornerRadii[4]) {
            return;
        }
        mBottomIsRounded = bottomRoundNess != 0.0f;
        mCornerRadii[0] = topRoundness;
        mCornerRadii[1] = topRoundness;