Skip to content

Commit

Permalink
Ensure that Layer::AutoSaveLayer objects are not immediately destruct…
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-simmons committed Sep 17, 2018
1 parent b0b19d6 commit ba77529
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
5 changes: 3 additions & 2 deletions flow/layers/backdrop_filter_layer.cc
Expand Up @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion flow/layers/color_filter_layer.cc
Expand Up @@ -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);
}

Expand Down
13 changes: 13 additions & 0 deletions flow/layers/layer.cc
Expand Up @@ -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_);
Expand Down
16 changes: 13 additions & 3 deletions flow/layers/layer.h
Expand Up @@ -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"
Expand Down Expand Up @@ -67,16 +68,25 @@ 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);

AutoSaveLayer(const PaintContext& paint_context,
const SkCanvas::SaveLayerRec& layer_rec);

~AutoSaveLayer();

private:
const PaintContext& paint_context_;
const SkRect bounds_;
};
Expand Down
3 changes: 2 additions & 1 deletion flow/layers/opacity_layer.cc
Expand Up @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion flow/layers/shader_mask_layer.cc
Expand Up @@ -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;
Expand Down

0 comments on commit ba77529

Please sign in to comment.