Flutter Engine
 
Loading...
Searching...
No Matches
shader_mask_layer.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
7
8namespace flutter {
9
10ShaderMaskLayer::ShaderMaskLayer(std::shared_ptr<DlColorSource> color_source,
11 const DlRect& mask_rect,
12 DlBlendMode blend_mode)
14 RasterCacheUtil::kMinimumRendersBeforeCachingFilterLayer),
15 color_source_(std::move(color_source)),
16 mask_rect_(mask_rect),
17 blend_mode_(blend_mode) {}
18
19void ShaderMaskLayer::Diff(DiffContext* context, const Layer* old_layer) {
20 DiffContext::AutoSubtreeRestore subtree(context);
21 auto* prev = static_cast<const ShaderMaskLayer*>(old_layer);
22 if (!context->IsSubtreeDirty()) {
23 FML_DCHECK(prev);
24 if (color_source_ != prev->color_source_ ||
25 mask_rect_ != prev->mask_rect_ || blend_mode_ != prev->blend_mode_) {
26 context->MarkSubtreeDirty(context->GetOldLayerPaintRegion(old_layer));
27 }
28 }
29 if (context->has_raster_cache()) {
31 }
32 DiffChildren(context, prev);
33
34 context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion());
35}
36
40#if !SLIMPELLER
41 AutoCache cache = AutoCache(layer_raster_cache_item_.get(), context,
42 context->state_stack.matrix());
43#endif // !SLIMPELLER
45 // We always paint with a saveLayer (or a cached rendering),
46 // so we can always apply opacity in any of those cases.
48}
49
51 FML_DCHECK(needs_painting(context));
52
53 auto mutator = context.state_stack.save();
54
55#if !SLIMPELLER
56 if (context.raster_cache) {
57 mutator.integralTransform();
58
59 DlPaint paint;
60 if (layer_raster_cache_item_->Draw(context,
61 context.state_stack.fill(paint))) {
62 return;
63 }
64 }
65#endif // !SLIMPELLER
66 auto shader_rect = DlRect::MakeSize(mask_rect_.GetSize());
67
68 mutator.saveLayer(paint_bounds());
69
70 PaintChildren(context);
71
72 DlPaint dl_paint;
73 dl_paint.setBlendMode(blend_mode_);
74 if (color_source_) {
75 dl_paint.setColorSource(color_source_.get());
76 }
77 context.canvas->Translate(mask_rect_.GetLeft(), mask_rect_.GetTop());
78 context.canvas->DrawRect(shader_rect, dl_paint);
79}
80
81} // namespace flutter
std::unique_ptr< LayerRasterCacheItem > layer_raster_cache_item_
void Preroll(PrerollContext *context) override
void PaintChildren(PaintContext &context) const override
virtual void DiffChildren(DiffContext *context, const ContainerLayer *old_layer)
void WillPaintWithIntegralTransform()
void SetLayerPaintRegion(const Layer *layer, const PaintRegion &region)
void MarkSubtreeDirty(const PaintRegion &previous_paint_region=PaintRegion())
PaintRegion CurrentSubtreeRegion() const
bool has_raster_cache() const
PaintRegion GetOldLayerPaintRegion(const Layer *layer) const
bool IsSubtreeDirty() const
virtual void DrawRect(const DlRect &rect, const DlPaint &paint)=0
virtual void Translate(DlScalar tx, DlScalar ty)=0
DlPaint & setBlendMode(DlBlendMode mode)
Definition dl_paint.h:85
DlPaint & setColorSource(std::nullptr_t source)
Definition dl_paint.h:131
static AutoPrerollSaveLayerState Create(PrerollContext *preroll_context, bool save_layer_is_active=true, bool layer_itself_performs_readback=false)
Definition layer.cc:37
static constexpr int kSaveLayerRenderFlags
Definition layer.h:118
bool needs_painting(PaintContext &context) const
Definition layer.h:218
const DlRect & paint_bounds() const
Definition layer.h:196
void fill(MutatorsStack *mutators)
const DlMatrix matrix() const
void Diff(DiffContext *context, const Layer *old_layer) override
ShaderMaskLayer(std::shared_ptr< DlColorSource > color_source, const DlRect &mask_rect, DlBlendMode blend_mode)
void Paint(PaintContext &context) const override
void Preroll(PrerollContext *context) override
#define FML_DCHECK(condition)
Definition logging.h:122
BlendMode
Definition color.h:58
Definition ref_ptr.h:261
DlCanvas * canvas
Definition layer.h:92
LayerStateStack & state_stack
Definition layer.h:91
LayerStateStack & state_stack
Definition layer.h:49
constexpr auto GetTop() const
Definition rect.h:353
constexpr TSize< Type > GetSize() const
Returns the size of the rectangle which may be negative in either width or height and may have been c...
Definition rect.h:327
constexpr auto GetLeft() const
Definition rect.h:351
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:150