Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions flow/layers/shader_mask_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

namespace flutter {

ShaderMaskLayer::ShaderMaskLayer(std::shared_ptr<DlColorSource> shader,
ShaderMaskLayer::ShaderMaskLayer(std::shared_ptr<DlColorSource> color_source,
const SkRect& mask_rect,
DlBlendMode blend_mode)
: CacheableContainerLayer(
RasterCacheUtil::kMinimumRendersBeforeCachingFilterLayer),
shader_(std::move(shader)),
color_source_(std::move(color_source)),
mask_rect_(mask_rect),
blend_mode_(blend_mode) {}

Expand All @@ -21,8 +21,8 @@ void ShaderMaskLayer::Diff(DiffContext* context, const Layer* old_layer) {
auto* prev = static_cast<const ShaderMaskLayer*>(old_layer);
if (!context->IsSubtreeDirty()) {
FML_DCHECK(prev);
if (shader_ != prev->shader_ || mask_rect_ != prev->mask_rect_ ||
blend_mode_ != prev->blend_mode_) {
if (color_source_ != prev->color_source_ ||
mask_rect_ != prev->mask_rect_ || blend_mode_ != prev->blend_mode_) {
context->MarkSubtreeDirty(context->GetOldLayerPaintRegion(old_layer));
}
}
Expand Down Expand Up @@ -54,19 +54,33 @@ void ShaderMaskLayer::Paint(PaintContext& context) const {
return;
}
}
auto shader_rect = SkRect::MakeWH(mask_rect_.width(), mask_rect_.height());

Layer::AutoSaveLayer save = Layer::AutoSaveLayer::Create(
context, paint_bounds(), cache_paint.sk_paint());
PaintChildren(context);
if (context.leaf_nodes_builder) {
context.builder_multiplexer->saveLayer(&paint_bounds(),
cache_paint.dl_paint());
PaintChildren(context);

SkPaint paint;
paint.setBlendMode(ToSk(blend_mode_));
if (shader_) {
paint.setShader(shader_->skia_object());
DlPaint dl_paint;
dl_paint.setBlendMode(blend_mode_);
if (color_source_) {
dl_paint.setColorSource(color_source_.get());
}
context.leaf_nodes_builder->translate(mask_rect_.left(), mask_rect_.top());
context.leaf_nodes_builder->drawRect(shader_rect, dl_paint);
context.builder_multiplexer->restore();
} else {
Layer::AutoSaveLayer save = Layer::AutoSaveLayer::Create(
context, paint_bounds(), cache_paint.sk_paint());
PaintChildren(context);
SkPaint paint;
paint.setBlendMode(ToSk(blend_mode_));
if (color_source_) {
paint.setShader(color_source_->skia_object());
}
context.leaf_nodes_canvas->translate(mask_rect_.left(), mask_rect_.top());
context.leaf_nodes_canvas->drawRect(shader_rect, paint);
}
context.leaf_nodes_canvas->translate(mask_rect_.left(), mask_rect_.top());
context.leaf_nodes_canvas->drawRect(
SkRect::MakeWH(mask_rect_.width(), mask_rect_.height()), paint);
}

} // namespace flutter
4 changes: 2 additions & 2 deletions flow/layers/shader_mask_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace flutter {

class ShaderMaskLayer : public CacheableContainerLayer {
public:
ShaderMaskLayer(std::shared_ptr<DlColorSource> shader,
ShaderMaskLayer(std::shared_ptr<DlColorSource> color_source,
const SkRect& mask_rect,
DlBlendMode blend_mode);

Expand All @@ -23,7 +23,7 @@ class ShaderMaskLayer : public CacheableContainerLayer {
void Paint(PaintContext& context) const override;

private:
std::shared_ptr<DlColorSource> shader_;
std::shared_ptr<DlColorSource> color_source_;
SkRect mask_rect_;
DlBlendMode blend_mode_;

Expand Down
11 changes: 5 additions & 6 deletions flow/layers/shader_mask_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -373,17 +373,16 @@ TEST_F(ShaderMaskLayerTest, OpacityInheritance) {
{
expected_builder.translate(offset.fX, offset.fY);
/* ShaderMaskLayer::Paint() */ {
expected_builder.setColor(opacity_alpha << 24);
expected_builder.saveLayer(&child_path.getBounds(), true);
DlPaint sl_paint = DlPaint().setColor(opacity_alpha << 24);
expected_builder.saveLayer(&child_path.getBounds(), &sl_paint);
{
/* child layer paint */ {
expected_builder.setColor(0xFF000000);
expected_builder.drawPath(child_path);
expected_builder.drawPath(child_path, DlPaint());
}
expected_builder.translate(mask_rect.fLeft, mask_rect.fTop);
expected_builder.setBlendMode(DlBlendMode::kSrc);
expected_builder.drawRect(
SkRect::MakeWH(mask_rect.width(), mask_rect.height()));
SkRect::MakeWH(mask_rect.width(), mask_rect.height()),
DlPaint().setBlendMode(DlBlendMode::kSrc));
}
expected_builder.restore();
}
Expand Down