Skip to content

Commit

Permalink
Call drawPath without clip if possible (flutter#5952)
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
liyuqian authored Aug 7, 2018
1 parent 7e0bb3b commit b3e866e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions flow/layers/physical_shape_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ void PhysicalShapeLayer::Paint(PaintContext& context) const {
SkColorGetA(color_) != 0xff, device_pixel_ratio_);
}

// Call drawPath without clip if possible for better performance.
SkPaint paint;
paint.setColor(color_);
if (clip_behavior_ != Clip::antiAliasWithSaveLayer) {
context.canvas.drawPath(path_, paint);
}

int saveCount = context.canvas.save();
switch (clip_behavior_) {
case Clip::hardEdge:
Expand All @@ -103,11 +110,7 @@ void PhysicalShapeLayer::Paint(PaintContext& context) const {
break;
}

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

0 comments on commit b3e866e

Please sign in to comment.