Skip to content

Commit e1a103e

Browse files
pekingmehunterstich
authored andcommitted
[Shape] Optimized getOutline().
PiperOrigin-RevId: 655217170
1 parent 8e63e7f commit e1a103e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/java/com/google/android/material/shape/MaterialShapeDrawable.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,20 +1394,22 @@ public void getOutline(@NonNull Outline outline) {
13941394
return;
13951395
}
13961396

1397-
if (pathDirty) {
1398-
calculatePath(getBoundsAsRectF(), path);
1399-
pathDirty = false;
1397+
RectF bounds = getBoundsAsRectF();
1398+
if (bounds.isEmpty()) {
1399+
// Don't set the outline if the bounds are empty.
1400+
return;
14001401
}
1401-
14021402
// Calculates the radius of a round rect, if the stroke shape can be drawn as a round rect.
14031403
float roundRectRadius =
14041404
calculateRoundRectCornerSize(
1405-
getBoundsInsetByStroke(),
1406-
drawableState.shapeAppearanceModel,
1407-
springAnimatedCornerSizes);
1405+
bounds, drawableState.shapeAppearanceModel, springAnimatedCornerSizes);
14081406
if (roundRectRadius >= 0) {
14091407
outline.setRoundRect(getBounds(), roundRectRadius * drawableState.interpolation);
14101408
} else {
1409+
if (pathDirty) {
1410+
calculatePath(bounds, path);
1411+
pathDirty = false;
1412+
}
14111413
DrawableUtils.setOutlineToPath(outline, path);
14121414
}
14131415
}

0 commit comments

Comments
 (0)