Flutter Engine
 
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 auto mutator = context->state_stack.save();
60 ApplyClip(mutator);
61
66
67 // If we use a SaveLayer then we can accept opacity on behalf
68 // of our children and apply it in the saveLayer.
69 if (uses_save_layer) {
71 }
72 }
73
74 void Paint(PaintContext& context) const override {
75 FML_DCHECK(needs_painting(context));
76
77 auto mutator = context.state_stack.save();
78 ApplyClip(mutator);
79
80 if (!UsesSaveLayer()) {
81 PaintChildren(context);
82 return;
83 }
84
85#if !SLIMPELLER
86 if (context.raster_cache) {
87 mutator.integralTransform();
88 auto restore_apply = context.state_stack.applyState(
90
91 DlPaint paint;
92 if (layer_raster_cache_item_->Draw(context,
93 context.state_stack.fill(paint))) {
94 return;
95 }
96 }
97#endif // !SLIMPELLER
98
99 mutator.saveLayer(paint_bounds());
100 PaintChildren(context);
101 }
102
103 bool UsesSaveLayer() const {
104 return clip_behavior_ == Clip::kAntiAliasWithSaveLayer;
105 }
106
107 protected:
108 virtual const DlRect clip_shape_bounds() const = 0;
109 virtual void ApplyClip(LayerStateStack::MutatorContext& mutator) const = 0;
110 virtual ~ClipShapeLayer() = default;
111
112 const ClipShape& clip_shape() const { return clip_shape_; }
113 Clip clip_behavior() const { return clip_behavior_; }
114
115 private:
116 const ClipShape clip_shape_;
117 Clip clip_behavior_;
118
120};
121
122} // namespace flutter
123
124#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 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
constexpr TRect IntersectionOrEmpty(const TRect &o) const
Definition rect.h:542