Add support for backdrop filters in the compositor

Particularly, add support for blur filters to implement backdrop blur effects.
This commit is contained in:
Adam Barth
2016-04-01 17:15:36 -07:00
parent c7526e2aee
commit 424df08728
3 changed files with 61 additions and 0 deletions

View File

@@ -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",

View File

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

View File

@@ -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<SkImageFilter> filter_;
DISALLOW_COPY_AND_ASSIGN(BackdropFilterLayer);
};
} // namespace flow
#endif // FLOW_LAYERS_BACKDROP_FILTER_LAYER_H_