diff --git a/flow/layers/backdrop_filter_layer.cc b/flow/layers/backdrop_filter_layer.cc index b8d04803f19..1b93b9cabb9 100644 --- a/flow/layers/backdrop_filter_layer.cc +++ b/flow/layers/backdrop_filter_layer.cc @@ -16,8 +16,9 @@ void BackdropFilterLayer::Paint(PaintContext& context) const { TRACE_EVENT0("flutter", "BackdropFilterLayer::Paint"); FML_DCHECK(needs_painting()); - Layer::AutoSaveLayer(context, SkCanvas::SaveLayerRec{&paint_bounds(), nullptr, - filter_.get(), 0}); + Layer::AutoSaveLayer save = Layer::AutoSaveLayer::Create( + context, + SkCanvas::SaveLayerRec{&paint_bounds(), nullptr, filter_.get(), 0}); PaintChildren(context); } diff --git a/flow/layers/color_filter_layer.cc b/flow/layers/color_filter_layer.cc index a3c678aa153..287507d179f 100644 --- a/flow/layers/color_filter_layer.cc +++ b/flow/layers/color_filter_layer.cc @@ -19,7 +19,8 @@ void ColorFilterLayer::Paint(PaintContext& context) const { SkPaint paint; paint.setColorFilter(std::move(color_filter)); - Layer::AutoSaveLayer(context, paint_bounds(), &paint); + Layer::AutoSaveLayer save = + Layer::AutoSaveLayer::Create(context, paint_bounds(), &paint); PaintChildren(context); } diff --git a/flow/layers/layer.cc b/flow/layers/layer.cc index 67148dc0c08..c1d91872127 100644 --- a/flow/layers/layer.cc +++ b/flow/layers/layer.cc @@ -35,6 +35,19 @@ Layer::AutoSaveLayer::AutoSaveLayer(const PaintContext& paint_context, paint_context_.canvas.saveLayer(layer_rec); } +Layer::AutoSaveLayer Layer::AutoSaveLayer::Create( + const PaintContext& paint_context, + const SkRect& bounds, + const SkPaint* paint) { + return Layer::AutoSaveLayer(paint_context, bounds, paint); +} + +Layer::AutoSaveLayer Layer::AutoSaveLayer::Create( + const PaintContext& paint_context, + const SkCanvas::SaveLayerRec& layer_rec) { + return Layer::AutoSaveLayer(paint_context, layer_rec); +} + Layer::AutoSaveLayer::~AutoSaveLayer() { if (paint_context_.checkerboard_offscreen_layers) { DrawCheckerboard(&paint_context_.canvas, bounds_); diff --git a/flow/layers/layer.h b/flow/layers/layer.h index 173c2890b6a..a52f6e04aa8 100644 --- a/flow/layers/layer.h +++ b/flow/layers/layer.h @@ -12,6 +12,7 @@ #include "flutter/flow/raster_cache.h" #include "flutter/flow/texture.h" #include "flutter/fml/build_config.h" +#include "flutter/fml/compiler_specific.h" #include "flutter/fml/logging.h" #include "flutter/fml/macros.h" #include "flutter/fml/trace_event.h" @@ -67,6 +68,18 @@ class Layer { // draws a checkerboard over the layer if that is enabled in the PaintContext. class AutoSaveLayer { public: + FML_WARN_UNUSED_RESULT static AutoSaveLayer Create( + const PaintContext& paint_context, + const SkRect& bounds, + const SkPaint* paint); + + FML_WARN_UNUSED_RESULT static AutoSaveLayer Create( + const PaintContext& paint_context, + const SkCanvas::SaveLayerRec& layer_rec); + + ~AutoSaveLayer(); + + private: AutoSaveLayer(const PaintContext& paint_context, const SkRect& bounds, const SkPaint* paint); @@ -74,9 +87,6 @@ class Layer { AutoSaveLayer(const PaintContext& paint_context, const SkCanvas::SaveLayerRec& layer_rec); - ~AutoSaveLayer(); - - private: const PaintContext& paint_context_; const SkRect bounds_; }; diff --git a/flow/layers/opacity_layer.cc b/flow/layers/opacity_layer.cc index 84b8bd64c02..2272e790938 100644 --- a/flow/layers/opacity_layer.cc +++ b/flow/layers/opacity_layer.cc @@ -17,7 +17,8 @@ void OpacityLayer::Paint(PaintContext& context) const { SkPaint paint; paint.setAlpha(alpha_); - Layer::AutoSaveLayer save(context, paint_bounds(), &paint); + Layer::AutoSaveLayer save = + Layer::AutoSaveLayer::Create(context, paint_bounds(), &paint); PaintChildren(context); } diff --git a/flow/layers/shader_mask_layer.cc b/flow/layers/shader_mask_layer.cc index 3ea69322fcd..6cb73bbf648 100644 --- a/flow/layers/shader_mask_layer.cc +++ b/flow/layers/shader_mask_layer.cc @@ -14,7 +14,8 @@ void ShaderMaskLayer::Paint(PaintContext& context) const { TRACE_EVENT0("flutter", "ShaderMaskLayer::Paint"); FML_DCHECK(needs_painting()); - Layer::AutoSaveLayer(context, paint_bounds(), nullptr); + Layer::AutoSaveLayer save = + Layer::AutoSaveLayer::Create(context, paint_bounds(), nullptr); PaintChildren(context); SkPaint paint;