Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit b3e866e

Browse files
authored
Call drawPath without clip if possible (#5952)
It turns out that Skia is much slower at drawing paint inside a clipped path than directly drawing that path. (Average frame time of 22ms vs 18ms in flutter_galary transition test.)
1 parent 7e0bb3b commit b3e866e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

flow/layers/physical_shape_layer.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ void PhysicalShapeLayer::Paint(PaintContext& context) const {
8787
SkColorGetA(color_) != 0xff, device_pixel_ratio_);
8888
}
8989

90+
// Call drawPath without clip if possible for better performance.
91+
SkPaint paint;
92+
paint.setColor(color_);
93+
if (clip_behavior_ != Clip::antiAliasWithSaveLayer) {
94+
context.canvas.drawPath(path_, paint);
95+
}
96+
9097
int saveCount = context.canvas.save();
9198
switch (clip_behavior_) {
9299
case Clip::hardEdge:
@@ -103,11 +110,7 @@ void PhysicalShapeLayer::Paint(PaintContext& context) const {
103110
break;
104111
}
105112

106-
SkPaint paint;
107-
paint.setColor(color_);
108-
if (clip_behavior_ == Clip::none) {
109-
context.canvas.drawPath(path_, paint);
110-
} else {
113+
if (clip_behavior_ == Clip::antiAliasWithSaveLayer) {
111114
// If we want to avoid the bleeding edge artifact
112115
// (https://github.com/flutter/flutter/issues/18057#issue-328003931)
113116
// using saveLayer, we have to call drawPaint instead of drawPath as

0 commit comments

Comments
 (0)