Flutter Engine
The Flutter Engine
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
8#include "flutter/flow/layers/cacheable_layer.h"
9#include "flutter/flow/layers/container_layer.h"
10#include "flutter/flow/paint_utils.h"
11
12namespace flutter {
13
14template <class T>
16 public:
17 using ClipShape = T;
20 clip_shape_(clip_shape),
21 clip_behavior_(clip_behavior) {
23 }
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()) {
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.
52 AutoCache(uses_save_layer ? layer_raster_cache_item_.get() : nullptr,
53 context, context->state_stack.transform_3x3());
54#endif // !SLIMPELLER
55
58
59 auto mutator = context->state_stack.save();
60 ApplyClip(mutator);
61
66 } else {
68 }
69
70 // If we use a SaveLayer then we can accept opacity on behalf
71 // of our children and apply it in the saveLayer.
72 if (uses_save_layer) {
74 }
75 }
76
77 void Paint(PaintContext& context) const override {
78 FML_DCHECK(needs_painting(context));
79
80 auto mutator = context.state_stack.save();
81 ApplyClip(mutator);
82
83 if (!UsesSaveLayer()) {
84 PaintChildren(context);
85 return;
86 }
87
88#if !SLIMPELLER
89 if (context.raster_cache) {
90 mutator.integralTransform();
91 auto restore_apply = context.state_stack.applyState(
93
95 if (layer_raster_cache_item_->Draw(context,
96 context.state_stack.fill(paint))) {
97 return;
98 }
99 }
100#endif // !SLIMPELLER
101
102 mutator.saveLayer(paint_bounds());
103 PaintChildren(context);
104 }
105
106 bool UsesSaveLayer() const {
107 return clip_behavior_ == Clip::kAntiAliasWithSaveLayer;
108 }
109
110 protected:
111 virtual const SkRect& clip_shape_bounds() const = 0;
112 virtual void ApplyClip(LayerStateStack::MutatorContext& mutator) const = 0;
113 virtual ~ClipShapeLayer() = default;
114
115 const ClipShape& clip_shape() const { return clip_shape_; }
116 Clip clip_behavior() const { return clip_behavior_; }
117
118 private:
119 const ClipShape clip_shape_;
120 Clip clip_behavior_;
121
122 FML_DISALLOW_COPY_AND_ASSIGN(ClipShapeLayer);
123};
124
125} // namespace flutter
126
127#endif // FLUTTER_FLOW_LAYERS_CLIP_SHAPE_LAYER_H_
static float prev(float f)
std::unique_ptr< LayerRasterCacheItem > layer_raster_cache_item_
void Paint(PaintContext &context) const override
const ClipShape & clip_shape() const
void Preroll(PrerollContext *context) override
virtual ~ClipShapeLayer()=default
virtual void ApplyClip(LayerStateStack::MutatorContext &mutator) const =0
ClipShapeLayer(const ClipShape &clip_shape, Clip clip_behavior)
virtual const SkRect & clip_shape_bounds() const =0
void Diff(DiffContext *context, const Layer *old_layer) override
void PrerollChildren(PrerollContext *context, SkRect *child_paint_bounds)
void PaintChildren(PaintContext &context) const override
virtual void DiffChildren(DiffContext *context, const ContainerLayer *old_layer)
const SkRect & child_paint_bounds() const
void WillPaintWithIntegralTransform()
Definition: diff_context.h:89
void SetLayerPaintRegion(const Layer *layer, const PaintRegion &region)
void MarkSubtreeDirty(const PaintRegion &previous_paint_region=PaintRegion())
PaintRegion CurrentSubtreeRegion() const
bool has_raster_cache() const
Definition: diff_context.h:167
PaintRegion GetOldLayerPaintRegion(const Layer *layer) const
bool PushCullRect(const SkRect &clip)
bool IsSubtreeDirty() const
Definition: diff_context.h:108
SkMatrix transform_3x3() const
void fill(MutatorsStack *mutators)
AutoRestore applyState(const SkRect &bounds, int can_apply_flags)
static constexpr int kCallerCanApplyOpacity
static AutoPrerollSaveLayerState Create(PrerollContext *preroll_context, bool save_layer_is_active=true, bool layer_itself_performs_readback=false)
Definition: layer.cc:40
const SkRect & paint_bounds() const
Definition: layer.h:210
static constexpr int kSaveLayerRenderFlags
Definition: layer.h:132
bool needs_painting(PaintContext &context) const
Definition: layer.h:232
void set_paint_bounds(const SkRect &paint_bounds)
Definition: layer.h:223
const Paint & paint
Definition: color_source.cc:38
#define FML_DCHECK(condition)
Definition: logging.h:103
Clip
Definition: layer.h:53
@ kAntiAliasWithSaveLayer
Definition: layer.h:53
@ kNone
Definition: layer.h:53
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache
Definition: switches.h:191
#define T
Definition: precompiler.cc:65
static constexpr SkRect MakeEmpty()
Definition: SkRect.h:595
bool intersect(const SkRect &r)
Definition: SkRect.cpp:114
LayerStateStack & state_stack
Definition: layer.h:101
LayerStateStack & state_stack
Definition: layer.h:59
int renderable_state_flags
Definition: layer.h:83