Flutter Engine
The 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
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;
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 // We can use the raster_cache for children only when the use_save_layer is
48 // true so if use_save_layer is false we pass the layer_raster_item is
49 // nullptr which mean we don't do raster cache logic.
51 AutoCache(uses_save_layer ? layer_raster_cache_item_.get() : nullptr,
52 context, context->state_stack.transform_3x3());
53
56
57 auto mutator = context->state_stack.save();
58 ApplyClip(mutator);
59
64 } else {
66 }
67
68 // If we use a SaveLayer then we can accept opacity on behalf
69 // of our children and apply it in the saveLayer.
70 if (uses_save_layer) {
72 }
73 }
74
75 void Paint(PaintContext& context) const override {
76 FML_DCHECK(needs_painting(context));
77
78 auto mutator = context.state_stack.save();
79 ApplyClip(mutator);
80
81 if (!UsesSaveLayer()) {
82 PaintChildren(context);
83 return;
84 }
85
86 if (context.raster_cache) {
87 mutator.integralTransform();
88 auto restore_apply = context.state_stack.applyState(
90
92 if (layer_raster_cache_item_->Draw(context,
93 context.state_stack.fill(paint))) {
94 return;
95 }
96 }
97
98 mutator.saveLayer(paint_bounds());
99 PaintChildren(context);
100 }
101
102 bool UsesSaveLayer() const {
103 return clip_behavior_ == Clip::kAntiAliasWithSaveLayer;
104 }
105
106 protected:
107 virtual const SkRect& clip_shape_bounds() const = 0;
108 virtual void ApplyClip(LayerStateStack::MutatorContext& mutator) const = 0;
109 virtual ~ClipShapeLayer() = default;
110
111 const ClipShape& clip_shape() const { return clip_shape_; }
112 Clip clip_behavior() const { return clip_behavior_; }
113
114 private:
115 const ClipShape clip_shape_;
116 Clip clip_behavior_;
117
119};
120
121} // namespace flutter
122
123#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()
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 PushCullRect(const SkRect &clip)
bool IsSubtreeDirty() 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:209
static constexpr int kSaveLayerRenderFlags
Definition layer.h:131
bool needs_painting(PaintContext &context) const
Definition layer.h:231
void set_paint_bounds(const SkRect &paint_bounds)
Definition layer.h:222
const Paint & paint
#define FML_DCHECK(condition)
Definition logging.h:103
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
@ kAntiAliasWithSaveLayer
Definition layer.h:52
@ kNone
Definition layer.h:52
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
static constexpr SkRect MakeEmpty()
Definition SkRect.h:595
bool intersect(const SkRect &r)
Definition SkRect.cpp:114
LayerStateStack & state_stack
Definition layer.h:100
const RasterCache * raster_cache
Definition layer.h:114
LayerStateStack & state_stack
Definition layer.h:58