Ensure that Layer::AutoSaveLayer objects are not immediately destructed (#6264)

Fixes https://github.com/flutter/flutter/issues/20859
This commit is contained in:
Jason Simmons 2018-09-17 11:43:41 -07:00 committed by GitHub
parent b0b19d6ce1
commit ba7752917f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 8 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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_);

View File

@ -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_;
};

View File

@ -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);
}

View File

@ -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;