提交 9949c8aa 编写于 作者: A Adam Barth

Add ShaderLayer to Flutter compositor

We need this to implement RenderShaderMask properly. See #1155.
上级 ca0941bf
......@@ -34,6 +34,8 @@ source_set("compositor") {
"raster_cache.h",
"performance_overlay_layer.cc",
"performance_overlay_layer.h",
"shader_layer.cc",
"shader_layer.h",
"transform_layer.cc",
"transform_layer.h",
]
......
......@@ -15,10 +15,10 @@ ClipPathLayer::~ClipPathLayer() {
void ClipPathLayer::Paint(PaintContext::ScopedFrame& frame) {
SkCanvas& canvas = frame.canvas();
SkAutoCanvasRestore save(&canvas, false);
canvas.saveLayer(&clip_path_.getBounds(), nullptr);
canvas.clipPath(clip_path_);
PaintChildren(frame);
canvas.restore();
}
} // namespace compositor
......
......@@ -15,10 +15,9 @@ ClipRectLayer::~ClipRectLayer() {
void ClipRectLayer::Paint(PaintContext::ScopedFrame& frame) {
SkCanvas& canvas = frame.canvas();
canvas.save();
SkAutoCanvasRestore save(&canvas, true);
canvas.clipRect(clip_rect_);
PaintChildren(frame);
canvas.restore();
}
} // namespace compositor
......
......@@ -15,10 +15,10 @@ ClipRRectLayer::~ClipRRectLayer() {
void ClipRRectLayer::Paint(PaintContext::ScopedFrame& frame) {
SkCanvas& canvas = frame.canvas();
SkAutoCanvasRestore save(&canvas, false);
canvas.saveLayer(&clip_rrect_.getBounds(), nullptr);
canvas.clipRRect(clip_rrect_);
PaintChildren(frame);
canvas.restore();
}
} // namespace compositor
......
......@@ -23,10 +23,11 @@ void ColorFilterLayer::Paint(PaintContext::ScopedFrame& frame) {
adoptRef(SkColorFilter::CreateModeFilter(color_, transfer_mode_));
SkPaint paint;
paint.setColorFilter(color_filter.get());
SkCanvas& canvas = frame.canvas();
SkAutoCanvasRestore save(&canvas, false);
canvas.saveLayer(&paint_bounds(), &paint);
PaintChildren(frame);
canvas.restore();
}
} // namespace compositor
......
......@@ -22,10 +22,11 @@ void OpacityLayer::Paint(PaintContext::ScopedFrame& frame) {
SkPaint paint;
paint.setColor(SkColorSetARGB(alpha_, 0, 0, 0));
paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
SkCanvas& canvas = frame.canvas();
SkAutoCanvasRestore save(&canvas, false);
canvas.saveLayer(&paint_bounds(), &paint);
PaintChildren(frame);
canvas.restore();
}
} // namespace compositor
......
// 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 "sky/compositor/shader_layer.h"
namespace sky {
namespace compositor {
ShaderLayer::ShaderLayer() {
}
ShaderLayer::~ShaderLayer() {
}
void ShaderLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
ContainerLayer::Preroll(context, matrix);
set_paint_bounds(context->child_paint_bounds);
}
void ShaderLayer::Paint(PaintContext::ScopedFrame& frame) {
SkPaint paint;
paint.setXfermodeMode(transfer_mode_);
paint.setShader(shader_.get());
SkCanvas& canvas = frame.canvas();
SkAutoCanvasRestore save(&canvas, false);
canvas.saveLayer(&paint_bounds(), &paint);
PaintChildren(frame);
}
} // namespace compositor
} // namespace sky
// 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 SKY_COMPOSITOR_SHADER_LAYER_H_
#define SKY_COMPOSITOR_SHADER_LAYER_H_
#include "sky/compositor/container_layer.h"
#include "third_party/skia/include/core/SkShader.h"
namespace sky {
namespace compositor {
class ShaderLayer : public ContainerLayer {
public:
ShaderLayer();
~ShaderLayer() override;
void set_shader(SkShader* shader) { shader_ = shader; }
void set_transfer_mode(SkXfermode::Mode transfer_mode) {
transfer_mode_ = transfer_mode;
}
protected:
void Preroll(PrerollContext* context, const SkMatrix& matrix) override;
void Paint(PaintContext::ScopedFrame& frame) override;
private:
RefPtr<SkShader> shader_;
SkXfermode::Mode transfer_mode_;
DISALLOW_COPY_AND_ASSIGN(ShaderLayer);
};
} // namespace compositor
} // namespace sky
#endif // SKY_COMPOSITOR_SHADER_LAYER_H_
......@@ -22,10 +22,9 @@ void TransformLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
void TransformLayer::Paint(PaintContext::ScopedFrame& frame) {
SkCanvas& canvas = frame.canvas();
canvas.save();
SkAutoCanvasRestore save(&canvas, true);
canvas.concat(transform_);
PaintChildren(frame);
canvas.restore();
}
} // namespace compositor
......
......@@ -6,6 +6,7 @@
#include "third_party/skia/include/core/SkColorFilter.h"
#include "sky/engine/core/painting/Matrix.h"
#include "sky/engine/core/painting/Shader.h"
#include "sky/compositor/clip_path_layer.h"
#include "sky/compositor/clip_rect_layer.h"
#include "sky/compositor/clip_rrect_layer.h"
......@@ -14,6 +15,7 @@
#include "sky/compositor/opacity_layer.h"
#include "sky/compositor/picture_layer.h"
#include "sky/compositor/performance_overlay_layer.h"
#include "sky/compositor/shader_layer.h"
#include "sky/compositor/transform_layer.h"
#include "sky/engine/tonic/dart_args.h"
#include "sky/engine/tonic/dart_binding_macros.h"
......@@ -45,6 +47,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, SceneBuilder);
V(SceneBuilder, pushClipPath) \
V(SceneBuilder, pushOpacity) \
V(SceneBuilder, pushColorFilter) \
V(SceneBuilder, pushShader) \
V(SceneBuilder, pop) \
V(SceneBuilder, addPicture) \
V(SceneBuilder, addPerformanceOverlay) \
......@@ -88,28 +91,28 @@ void SceneBuilder::pushClipRect(const Rect& rect)
addLayer(std::move(layer));
}
void SceneBuilder::pushClipRRect(const RRect& rrect, const Rect& bounds)
void SceneBuilder::pushClipRRect(const RRect& rrect)
{
std::unique_ptr<sky::compositor::ClipRRectLayer> layer(new sky::compositor::ClipRRectLayer());
layer->set_clip_rrect(rrect.sk_rrect);
addLayer(std::move(layer));
}
void SceneBuilder::pushClipPath(const CanvasPath* path, const Rect& bounds)
void SceneBuilder::pushClipPath(const CanvasPath* path)
{
std::unique_ptr<sky::compositor::ClipPathLayer> layer(new sky::compositor::ClipPathLayer());
layer->set_clip_path(path->path());
addLayer(std::move(layer));
}
void SceneBuilder::pushOpacity(int alpha, const Rect& bounds)
void SceneBuilder::pushOpacity(int alpha)
{
std::unique_ptr<sky::compositor::OpacityLayer> layer(new sky::compositor::OpacityLayer());
layer->set_alpha(alpha);
addLayer(std::move(layer));
}
void SceneBuilder::pushColorFilter(CanvasColor color, TransferMode transferMode, const Rect& bounds)
void SceneBuilder::pushColorFilter(CanvasColor color, TransferMode transferMode)
{
std::unique_ptr<sky::compositor::ColorFilterLayer> layer(new sky::compositor::ColorFilterLayer());
layer->set_color(color);
......@@ -117,6 +120,14 @@ void SceneBuilder::pushColorFilter(CanvasColor color, TransferMode transferMode,
addLayer(std::move(layer));
}
void SceneBuilder::pushShader(Shader* shader, TransferMode transferMode)
{
std::unique_ptr<sky::compositor::ShaderLayer> layer(new sky::compositor::ShaderLayer());
layer->set_shader(shader->shader());
layer->set_transfer_mode(transferMode);
addLayer(std::move(layer));
}
void SceneBuilder::addLayer(std::unique_ptr<sky::compositor::ContainerLayer> layer)
{
DCHECK(layer);
......@@ -140,7 +151,7 @@ void SceneBuilder::pop()
m_currentLayer = m_currentLayer->parent();
}
void SceneBuilder::addPicture(const Offset& offset, Picture* picture, const Rect& paintBounds)
void SceneBuilder::addPicture(const Offset& offset, Picture* picture)
{
if (!m_currentLayer)
return;
......
......@@ -37,14 +37,15 @@ public:
void pushTransform(const Float64List& matrix4, ExceptionState&);
void pushClipRect(const Rect& rect);
void pushClipRRect(const RRect& rrect, const Rect& bounds);
void pushClipPath(const CanvasPath* path, const Rect& bounds);
void pushOpacity(int alpha, const Rect& bounds);
void pushColorFilter(CanvasColor color, TransferMode transferMode, const Rect& bounds);
void pushClipRRect(const RRect& rrect);
void pushClipPath(const CanvasPath* path);
void pushOpacity(int alpha);
void pushColorFilter(CanvasColor color, TransferMode transferMode);
void pushShader(Shader* shader, TransferMode transferMode);
void pop();
void addPicture(const Offset& offset, Picture* picture, const Rect& bounds);
void addPerformanceOverlay(uint64_t enabledOptions, const Rect& bounds);
void addPicture(const Offset& offset, Picture* picture);
void setRasterizerTracingThreshold(uint32_t frameInterval);
......
......@@ -14,16 +14,34 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
void pushTransform(Float64List matrix4) native "SceneBuilder_pushTransform";
void pushClipRect(Rect rect) native "SceneBuilder_pushClipRect";
void pushClipRRect(RRect rrect, Rect bounds) native "SceneBuilder_pushClipRRect";
void pushClipPath(Path path, Rect bounds) native "SceneBuilder_pushClipPath";
void pushOpacity(int alpha, Rect bounds) native "SceneBuilder_pushOpacity";
void pushColorFilter(Color color, TransferMode transferMode, Rect bounds) native "SceneBuilder_pushColorFilter";
void _pushClipRRect(RRect rrect) native "SceneBuilder_pushClipRRect";
void _pushClipPath(Path path) native "SceneBuilder_pushClipPath";
void _pushOpacity(int alpha) native "SceneBuilder_pushOpacity";
void _pushColorFilter(Color color, TransferMode transferMode) native "SceneBuilder_pushColorFilter";
void pushShader(Shader shader, TransferMode transferMode) native "SceneBuilder_pushShader";
void pop() native "SceneBuilder_pop";
void addPicture(Offset offset, Picture picture, Rect bounds) native "SceneBuilder_addPicture";
void addPerformanceOverlay(int enabledOptions, Rect bounds) native "SceneBuilder_addPerformanceOverlay";
void _addPicture(Offset offset, Picture picture) native "SceneBuilder_addPicture";
void setRasterizerTracingThreshold(int frameInterval) native "SceneBuilder_setRasterizerTracingThreshold";
Scene build() native "SceneBuilder_build";
// TODO(abarth): Remove these once clients stop passing bounds.
void pushClipRRect(RRect rrect, [ Rect bounds ]) {
_pushClipRRect(rrect);
}
void pushClipPath(Path path, [ Rect bounds ]) {
_pushClipPath(path);
}
void pushOpacity(int alpha, [ Rect bounds ]) {
_pushOpacity(alpha);
}
void pushColorFilter(Color color, TransferMode transferMode, [ Rect bounds ]) {
_pushColorFilter(color, transferMode);
}
void addPicture(Offset offset, Picture picture, [ Rect bounds ]) {
_addPicture(offset, picture);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册