diff --git a/engine/src/flutter/flow/BUILD.gn b/engine/src/flutter/flow/BUILD.gn index 7bd885cff2..bd2b485b89 100644 --- a/engine/src/flutter/flow/BUILD.gn +++ b/engine/src/flutter/flow/BUILD.gn @@ -8,6 +8,8 @@ source_set("flow") { "checkerboard.h", "instrumentation.cc", "instrumentation.h", + "layers/backdrop_filter_layer.cc", + "layers/backdrop_filter_layer.h", "layers/child_scene_layer.cc", "layers/child_scene_layer.h", "layers/clip_path_layer.cc", diff --git a/engine/src/flutter/flow/layers/backdrop_filter_layer.cc b/engine/src/flutter/flow/layers/backdrop_filter_layer.cc new file mode 100644 index 0000000000..8db214c101 --- /dev/null +++ b/engine/src/flutter/flow/layers/backdrop_filter_layer.cc @@ -0,0 +1,28 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flow/layers/backdrop_filter_layer.h" + +namespace flow { + +BackdropFilterLayer::BackdropFilterLayer() { +} + +BackdropFilterLayer::~BackdropFilterLayer() { +} + +void BackdropFilterLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { + ContainerLayer::Preroll(context, matrix); + set_paint_bounds(context->child_paint_bounds); +} + +void BackdropFilterLayer::Paint(PaintContext::ScopedFrame& frame) { + SkCanvas& canvas = frame.canvas(); + SkAutoCanvasRestore save(&canvas, false); + canvas.saveLayer(SkCanvas::SaveLayerRec{ + &paint_bounds(), nullptr, filter_.get(), 0}); + PaintChildren(frame); +} + +} // namespace flow diff --git a/engine/src/flutter/flow/layers/backdrop_filter_layer.h b/engine/src/flutter/flow/layers/backdrop_filter_layer.h new file mode 100644 index 0000000000..1659df07b0 --- /dev/null +++ b/engine/src/flutter/flow/layers/backdrop_filter_layer.h @@ -0,0 +1,31 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLOW_LAYERS_BACKDROP_FILTER_LAYER_H_ +#define FLOW_LAYERS_BACKDROP_FILTER_LAYER_H_ + +#include "flow/layers/container_layer.h" + +namespace flow { + +class BackdropFilterLayer : public ContainerLayer { + public: + BackdropFilterLayer(); + ~BackdropFilterLayer() override; + + void set_filter(SkImageFilter* filter) { filter_ = skia::SharePtr(filter); } + + protected: + void Preroll(PrerollContext* context, const SkMatrix& matrix) override; + void Paint(PaintContext::ScopedFrame& frame) override; + + private: + skia::RefPtr filter_; + + DISALLOW_COPY_AND_ASSIGN(BackdropFilterLayer); +}; + +} // namespace flow + +#endif // FLOW_LAYERS_BACKDROP_FILTER_LAYER_H_