From: Tony Huang Date: Fri, 18 May 2018 09:38:54 +0000 (+0800) Subject: Refactor for tuning gfx-max-frame-time-99 X-Git-Tag: android-x86-9.0-r1~103^2~14^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=c092c439c270df73a158544befdd28afbae7437d;p=android-x86%2Fframeworks-base.git 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 --- diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java b/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java index 364ed80638de..6a387971500e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java @@ -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. * diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java index b010199b119e..885ecbbc0647 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java @@ -2790,6 +2790,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) { NotificationContentView contentView = (NotificationContentView) child; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableOutlineView.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableOutlineView.java index 67268c00a4ce..edfa61b4ddc2 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableOutlineView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableOutlineView.java @@ -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; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationBackgroundView.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationBackgroundView.java index 0ff4dde580b7..969e9d97a1f0 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationBackgroundView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationBackgroundView.java @@ -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;