Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
clip_shape_layer.h
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
5#ifndef FLUTTER_FLOW_LAYERS_CLIP_SHAPE_LAYER_H_
6#define FLUTTER_FLOW_LAYERS_CLIP_SHAPE_LAYER_H_
7
11
12namespace flutter {
13
14template <class T>
16 public:
17 using ClipShape = T;
24
25 void Diff(DiffContext* context, const Layer* old_layer) override {
26 DiffContext::AutoSubtreeRestore subtree(context);
27 auto* prev = static_cast<const ClipShapeLayer<ClipShape>*>(old_layer);
28 if (!context->IsSubtreeDirty()) {
29 FML_DCHECK(prev);
30 if (clip_behavior_ != prev->clip_behavior_ ||
31 clip_shape_ != prev->clip_shape_) {
32 context->MarkSubtreeDirty(context->GetOldLayerPaintRegion(old_layer));
33 }
34 }
35 if (UsesSaveLayer() && context->has_raster_cache()) {
37 }
38 if (context->PushCullRect(clip_shape_bounds())) {
39 DiffChildren(context, prev);
40 }
41 context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion());
42 }
43
44 void Preroll(PrerollContext* context) override {
45 bool uses_save_layer = UsesSaveLayer();
46
47#if !SLIMPELLER
48 // We can use the raster_cache for children only when the use_save_layer is
49 // true so if use_save_layer is false we pass the layer_raster_item is
50 // nullptr which mean we don't do raster cache logic.
51 AutoCache cache =
52 AutoCache(uses_save_layer ? layer_raster_cache_item_.get() : nullptr,
53 context, context->state_stack.matrix());
54#endif // !SLIMPELLER
55
58
59 ExternalViewEmbedder* view_embedder = context->view_embedder;
60 if (view_embedder) {
62 }
63
64 auto mutator = context->state_stack.save();
65 ApplyClip(mutator);
66
71
72 // If we use a SaveLayer then we can accept opacity on behalf
73 // of our children and apply it in the saveLayer.
74 if (uses_save_layer) {
76 }
77 }
78
79 void Paint(PaintContext& context) const override {
80 FML_DCHECK(needs_painting(context));
81
82 auto mutator = context.state_stack.save();
83 ApplyClip(mutator);
84
85 if (!UsesSaveLayer()) {
86 PaintChildren(context);
87 return;
88 }
89
90#if !SLIMPELLER
91 if (context.raster_cache) {
92 mutator.integralTransform();
93 auto restore_apply = context.state_stack.applyState(
95
96 DlPaint paint;
97 if (layer_raster_cache_item_->Draw(context,
98 context.state_stack.fill(paint))) {
99 return;
100 }
101 }
102#endif // !SLIMPELLER
103
104 mutator.saveLayer(paint_bounds());
105 PaintChildren(context);
106 }
107
108 bool UsesSaveLayer() const {
109 return clip_behavior_ == Clip::kAntiAliasWithSaveLayer;
110 }
111
112 protected:
113 virtual const DlRect clip_shape_bounds() const = 0;
114 virtual void ApplyClip(LayerStateStack::MutatorContext& mutator) const = 0;
116 ExternalViewEmbedder* view_embedder) const = 0;
117 virtual ~ClipShapeLayer() = default;
118
119 const ClipShape& clip_shape() const { return clip_shape_; }
120 Clip clip_behavior() const { return clip_behavior_; }
121
122 private:
123 const ClipShape clip_shape_;
124 Clip clip_behavior_;
125
127};
128
129} // namespace flutter
130
131#endif // FLUTTER_FLOW_LAYERS_CLIP_SHAPE_LAYER_H_
std::unique_ptr< LayerRasterCacheItem > layer_raster_cache_item_
void Paint(PaintContext &context) const override
const ClipShape & clip_shape() const
virtual const DlRect clip_shape_bounds() const =0
void Preroll(PrerollContext *context) override
virtual ~ClipShapeLayer()=default
virtual void PushClipToEmbeddedNativeViewMutatorStack(ExternalViewEmbedder *view_embedder) const =0
virtual void ApplyClip(LayerStateStack::MutatorContext &mutator) const =0
ClipShapeLayer(const ClipShape &clip_shape, Clip clip_behavior)
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)
void WillPaintWithIntegralTransform()
bool PushCullRect(const DlRect &clip)
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
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 fill(MutatorsStack *mutators)
AutoRestore applyState(const DlRect &bounds, int can_apply_flags)
const DlMatrix matrix() const
static constexpr int kCallerCanApplyOpacity
#define FML_DCHECK(condition)
Definition logging.h:122
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
@ kAntiAliasWithSaveLayer
Definition layer.h:43
@ kNone
Definition layer.h:43
LayerStateStack & state_stack
Definition layer.h:91
LayerStateStack & state_stack
Definition layer.h:49
ExternalViewEmbedder * view_embedder
Definition layer.h:48
constexpr TRect IntersectionOrEmpty(const TRect &o) const
Definition rect.h:542