From 200bd061960a25d497a5cf1232ab0b0ea86979f1 Mon Sep 17 00:00:00 2001 From: liyuqian Date: Wed, 30 May 2018 12:50:12 -0700 Subject: [PATCH] Remove unnecessary saveLayer (#5420) saveLayer is slow so we should avoid it as much as possible. If there are artifacts without saveLayer, then we should report that to Skia for the fix instead of slowing the performance with saveLayer. This PQ makes average rasterizer time drop from 25ms to 18ms in flutter_gallery transitions perf test on a Nexus 5X. This partially fixes flutter/flutter#13736 . We probably still need some work in the opacity layer to squize all the performance improvements. --- flow/layers/clip_path_layer.cc | 2 +- flow/layers/clip_rrect_layer.cc | 2 +- flow/layers/physical_shape_layer.cc | 6 +----- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/flow/layers/clip_path_layer.cc b/flow/layers/clip_path_layer.cc index e1ab3112aec19..06dd30bd3630a 100644 --- a/flow/layers/clip_path_layer.cc +++ b/flow/layers/clip_path_layer.cc @@ -48,7 +48,7 @@ void ClipPathLayer::Paint(PaintContext& context) const { TRACE_EVENT0("flutter", "ClipPathLayer::Paint"); FXL_DCHECK(needs_painting()); - Layer::AutoSaveLayer save(context, paint_bounds(), nullptr); + SkAutoCanvasRestore save(&context.canvas, true); context.canvas.clipPath(clip_path_, true); PaintChildren(context); } diff --git a/flow/layers/clip_rrect_layer.cc b/flow/layers/clip_rrect_layer.cc index e72590edb372b..cef687dfcfb8a 100644 --- a/flow/layers/clip_rrect_layer.cc +++ b/flow/layers/clip_rrect_layer.cc @@ -46,7 +46,7 @@ void ClipRRectLayer::Paint(PaintContext& context) const { TRACE_EVENT0("flutter", "ClipRRectLayer::Paint"); FXL_DCHECK(needs_painting()); - Layer::AutoSaveLayer save(context, paint_bounds(), nullptr); + SkAutoCanvasRestore save(&context.canvas, true); context.canvas.clipRRect(clip_rrect_, true); PaintChildren(context); } diff --git a/flow/layers/physical_shape_layer.cc b/flow/layers/physical_shape_layer.cc index a730f9a8f96aa..b793132cc89e2 100644 --- a/flow/layers/physical_shape_layer.cc +++ b/flow/layers/physical_shape_layer.cc @@ -91,11 +91,7 @@ void PhysicalShapeLayer::Paint(PaintContext& context) const { context.canvas.drawPath(path_, paint); SkAutoCanvasRestore save(&context.canvas, false); - if (isRect_) { - context.canvas.save(); - } else { - context.canvas.saveLayer(path_.getBounds(), nullptr); - } + context.canvas.save(); context.canvas.clipPath(path_, true); PaintChildren(context); if (context.checkerboard_offscreen_layers && !isRect_)