Flutter Engine
 
Loading...
Searching...
No Matches
backdrop_filter_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
6
7namespace flutter {
8
10 const std::shared_ptr<DlImageFilter>& filter,
11 DlBlendMode blend_mode,
12 std::optional<int64_t> backdrop_id)
13 : filter_(filter), blend_mode_(blend_mode), backdrop_id_(backdrop_id) {}
14
15void BackdropFilterLayer::Diff(DiffContext* context, const Layer* old_layer) {
16 DiffContext::AutoSubtreeRestore subtree(context);
17 auto* prev = static_cast<const BackdropFilterLayer*>(old_layer);
18 if (!context->IsSubtreeDirty()) {
19 FML_DCHECK(prev);
20 if (NotEquals(filter_, prev->filter_)) {
21 context->MarkSubtreeDirty(context->GetOldLayerPaintRegion(old_layer));
22 }
23 }
24
25 // Backdrop filter paints everywhere in cull rect
26 auto paint_bounds = context->GetCullRect();
28
29 if (filter_) {
31 auto filter_target_bounds = DlIRect::RoundOut(paint_bounds);
32 DlIRect filter_input_bounds; // in screen coordinates
33 filter_->get_input_device_bounds(filter_target_bounds, context->GetMatrix(),
34 filter_input_bounds);
35 context->AddReadbackRegion(filter_target_bounds, filter_input_bounds);
36 }
37
38 DiffChildren(context, prev);
39
40 context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion());
41}
42
57
59 FML_DCHECK(needs_painting(context));
60
61 auto mutator = context.state_stack.save();
62 mutator.applyBackdropFilter(paint_bounds(), filter_, blend_mode_,
63 backdrop_id_);
64
65 PaintChildren(context);
66}
67
68} // namespace flutter
void Preroll(PrerollContext *context) override
BackdropFilterLayer(const std::shared_ptr< DlImageFilter > &filter, DlBlendMode blend_mode, std::optional< int64_t > backdrop_id=std::nullopt)
void Paint(PaintContext &context) const override
void Diff(DiffContext *context, const Layer *old_layer) override
const DlRect & child_paint_bounds() const
void PrerollChildren(PrerollContext *context, DlRect *child_paint_bounds)
void PaintChildren(PaintContext &context) const override
virtual void DiffChildren(DiffContext *context, const ContainerLayer *old_layer)
DlRect GetCullRect() const
DlRect MapRect(const DlRect &rect)
void SetLayerPaintRegion(const Layer *layer, const PaintRegion &region)
void MarkSubtreeDirty(const PaintRegion &previous_paint_region=PaintRegion())
void AddReadbackRegion(const DlIRect &paint_rect, const DlIRect &readback_rect)
PaintRegion CurrentSubtreeRegion() const
PaintRegion GetOldLayerPaintRegion(const Layer *layer) const
const DlMatrix & GetMatrix() const
bool IsSubtreeDirty() const
void AddLayerBounds(const DlRect &rect)
virtual void PushFilterToVisitedPlatformViews(const std::shared_ptr< DlImageFilter > &filter, const DlRect &filter_rect)
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
void set_paint_bounds(const DlRect &paint_bounds)
Definition layer.h:209
bool needs_painting(PaintContext &context) const
Definition layer.h:218
const DlRect & paint_bounds() const
Definition layer.h:196
void applyBackdropFilter(const DlRect &bounds, const std::shared_ptr< DlImageFilter > &filter, DlBlendMode blend_mode, std::optional< int64_t > backdrop_id)
#define FML_DCHECK(condition)
Definition logging.h:122
bool NotEquals(const T *a, const U *b)
BlendMode
Definition color.h:58
LayerStateStack & state_stack
Definition layer.h:91
LayerStateStack & state_stack
Definition layer.h:49
ExternalViewEmbedder * view_embedder
Definition layer.h:48
constexpr TRect Union(const TRect &o) const
Definition rect.h:513
RoundOut(const TRect< U > &r)
Definition rect.h:679