Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
flutter::LayerRasterCacheItem Class Reference

#include <layer_raster_cache_item.h>

Inheritance diagram for flutter::LayerRasterCacheItem:
flutter::RasterCacheItem flutter::testing::MockLayerCacheableItem

Public Member Functions

 LayerRasterCacheItem (Layer *layer, int layer_cached_threshold=1, bool can_cache_children=false)
 
std::optional< RasterCacheKeyIDGetId () const override
 
void PrerollSetup (PrerollContext *context, const SkMatrix &matrix) override
 
void PrerollFinalize (PrerollContext *context, const SkMatrix &matrix) override
 
bool Draw (const PaintContext &context, const DlPaint *paint) const override
 
bool Draw (const PaintContext &context, DlCanvas *canvas, const DlPaint *paint) const override
 
bool TryToPrepareRasterCache (const PaintContext &context, bool parent_cached=false) const override
 
void MarkCacheChildren ()
 
void MarkNotCacheChildren ()
 
bool IsCacheChildren () const
 
- Public Member Functions inherited from flutter::RasterCacheItem
 RasterCacheItem (RasterCacheKeyID key_id, CacheState cache_state=CacheState::kNone, unsigned child_entries=0)
 
virtual void PrerollSetup (PrerollContext *context, const SkMatrix &matrix)=0
 
virtual void PrerollFinalize (PrerollContext *context, const SkMatrix &matrix)=0
 
virtual bool Draw (const PaintContext &context, const DlPaint *paint) const =0
 
virtual bool Draw (const PaintContext &context, DlCanvas *canvas, const DlPaint *paint) const =0
 
virtual std::optional< RasterCacheKeyIDGetId () const
 
virtual bool TryToPrepareRasterCache (const PaintContext &context, bool parent_cached=false) const =0
 
unsigned child_items () const
 
void set_matrix (const SkMatrix &matrix)
 
CacheState cache_state () const
 
bool need_caching () const
 
virtual ~RasterCacheItem ()=default
 

Static Public Member Functions

static std::unique_ptr< LayerRasterCacheItemMake (Layer *, int layer_cache_threshold, bool can_cache_children=false)
 Create a LayerRasterCacheItem, connect a layer and manage the Layer's raster cache. More...
 

Protected Member Functions

const SkRectGetPaintBoundsFromLayer () const
 

Protected Attributes

Layerlayer_
 
std::optional< RasterCacheKeyIDlayer_children_id_
 
int layer_cached_threshold_ = 1
 
bool can_cache_children_ = false
 
int num_cache_attempts_ = 1
 
- Protected Attributes inherited from flutter::RasterCacheItem
RasterCacheKeyID key_id_
 
CacheState cache_state_ = CacheState::kNone
 
SkMatrix matrix_
 
unsigned child_items_
 

Additional Inherited Members

- Public Types inherited from flutter::RasterCacheItem
enum  CacheState { kNone = 0 , kCurrent , kChildren }
 

Detailed Description

Definition at line 17 of file layer_raster_cache_item.h.

Constructor & Destructor Documentation

◆ LayerRasterCacheItem()

flutter::LayerRasterCacheItem::LayerRasterCacheItem ( Layer layer,
int  layer_cached_threshold = 1,
bool  can_cache_children = false 
)
explicit

Definition at line 15 of file layer_raster_cache_item.cc.

19 RasterCacheKeyID(layer->unique_id(), RasterCacheKeyType::kLayer),
20 // The layer raster_cache_item's cache state default value is none.
22 layer_(layer),
23 layer_cached_threshold_(layer_cached_threshold),
24 can_cache_children_(can_cache_children) {}
RasterCacheItem(RasterCacheKeyID key_id, CacheState cache_state=CacheState::kNone, unsigned child_entries=0)
@ kNone
Definition: layer.h:53

Member Function Documentation

◆ Draw() [1/2]

bool flutter::LayerRasterCacheItem::Draw ( const PaintContext context,
const DlPaint paint 
) const
overridevirtual

Implements flutter::RasterCacheItem.

Definition at line 171 of file layer_raster_cache_item.cc.

172 {
173 return Draw(context, context.canvas, paint);
174}
bool Draw(const PaintContext &context, const DlPaint *paint) const override
const Paint & paint
Definition: color_source.cc:38

◆ Draw() [2/2]

bool flutter::LayerRasterCacheItem::Draw ( const PaintContext context,
DlCanvas canvas,
const DlPaint paint 
) const
overridevirtual

Implements flutter::RasterCacheItem.

Definition at line 176 of file layer_raster_cache_item.cc.

178 {
179 if (!context.raster_cache || !canvas) {
180 return false;
181 }
182 switch (cache_state_) {
184 return false;
186 return context.raster_cache->Draw(key_id_, *canvas, paint,
187 context.rendering_above_platform_view);
188 }
190 if (!layer_children_id_.has_value()) {
191 return false;
192 }
193 return context.raster_cache->Draw(layer_children_id_.value(), *canvas,
194 paint,
195 context.rendering_above_platform_view);
196 }
197 }
198}
std::optional< RasterCacheKeyID > layer_children_id_

◆ GetId()

std::optional< RasterCacheKeyID > flutter::LayerRasterCacheItem::GetId ( ) const
overridevirtual

Reimplemented from flutter::RasterCacheItem.

Definition at line 80 of file layer_raster_cache_item.cc.

80 {
81 switch (cache_state_) {
82 case kCurrent:
83 return key_id_;
84 case kChildren:
85 return layer_children_id_;
86 default:
87 return {};
88 }
89}

◆ GetPaintBoundsFromLayer()

const SkRect * flutter::LayerRasterCacheItem::GetPaintBoundsFromLayer ( ) const
protected

Definition at line 91 of file layer_raster_cache_item.cc.

91 {
92 switch (cache_state_) {
93 case CacheState::kCurrent:
94 return &(layer_->paint_bounds());
95 case CacheState::kChildren:
98 default:
100 return nullptr;
101 }
102}
const SkRect & child_paint_bounds() const
const SkRect & paint_bounds() const
Definition: layer.h:210
virtual const ContainerLayer * as_container_layer() const
Definition: layer.h:258
#define FML_DCHECK(condition)
Definition: logging.h:103

◆ IsCacheChildren()

bool flutter::LayerRasterCacheItem::IsCacheChildren ( ) const
inline

Definition at line 54 of file layer_raster_cache_item.h.

54{ return cache_state_ == CacheState::kChildren; }

◆ Make()

std::unique_ptr< LayerRasterCacheItem > flutter::LayerRasterCacheItem::Make ( Layer layer,
int  layer_cache_threshold,
bool  can_cache_children = false 
)
static

Create a LayerRasterCacheItem, connect a layer and manage the Layer's raster cache.

Parameters
layer_cache_thresholdafter how many frames to start trying to cache the layer self
can_cache_childrenthe layer can do a cache for his children

Definition at line 36 of file layer_raster_cache_item.cc.

39 {
40 return std::make_unique<LayerRasterCacheItem>(layer, layer_cache_threshold,
41 can_cache_children);
42}

◆ MarkCacheChildren()

void flutter::LayerRasterCacheItem::MarkCacheChildren ( )
inline

Definition at line 50 of file layer_raster_cache_item.h.

50{ can_cache_children_ = true; }

◆ MarkNotCacheChildren()

void flutter::LayerRasterCacheItem::MarkNotCacheChildren ( )
inline

Definition at line 52 of file layer_raster_cache_item.h.

52{ can_cache_children_ = false; }

◆ PrerollFinalize()

void flutter::LayerRasterCacheItem::PrerollFinalize ( PrerollContext context,
const SkMatrix matrix 
)
overridevirtual

Implements flutter::RasterCacheItem.

Definition at line 44 of file layer_raster_cache_item.cc.

45 {
46 if (!context->raster_cache || !context->raster_cached_entries) {
47 return;
48 }
49 // We've marked the cache entry that we would like to cache so it stays
50 // alive, but if the following conditions apply then we need to set our
51 // state back to kDoNotCache so that we don't populate the entry later.
52 if (context->has_platform_view || context->has_texture_layer ||
53 context->state_stack.content_culled(layer_->paint_bounds())) {
54 return;
55 }
56 child_items_ = context->raster_cached_entries->size() - child_items_;
58 // the layer can be cached
59 cache_state_ = CacheState::kCurrent;
60 context->raster_cache->MarkSeen(key_id_, matrix_, true);
61 } else {
63 // access current layer
65 if (!layer_children_id_.has_value()) {
67 if (!ids.has_value()) {
68 return;
69 }
70 layer_children_id_.emplace(std::move(ids.value()),
72 }
73 cache_state_ = CacheState::kChildren;
74 context->raster_cache->MarkSeen(layer_children_id_.value(), matrix_,
75 true);
76 }
77 }
78}
static std::optional< std::vector< RasterCacheKeyID > > LayerChildrenIds(const Layer *layer)

◆ PrerollSetup()

void flutter::LayerRasterCacheItem::PrerollSetup ( PrerollContext context,
const SkMatrix matrix 
)
overridevirtual

Implements flutter::RasterCacheItem.

Definition at line 26 of file layer_raster_cache_item.cc.

27 {
29 if (context->raster_cache && context->raster_cached_entries) {
30 context->raster_cached_entries->push_back(this);
31 child_items_ = context->raster_cached_entries->size();
33 }
34}
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258

◆ TryToPrepareRasterCache()

bool flutter::LayerRasterCacheItem::TryToPrepareRasterCache ( const PaintContext context,
bool  parent_cached = false 
) const
overridevirtual

Implements flutter::RasterCacheItem.

Definition at line 142 of file layer_raster_cache_item.cc.

143 {
144 auto maybe_id = GetId();
145 if (!maybe_id.has_value() || !context.raster_cache || parent_cached) {
146 return false;
147 }
148 if (cache_state_ != kNone) {
149 if (const SkRect* paint_bounds = GetPaintBoundsFromLayer()) {
150 RasterCache::Context r_context = {
151 // clang-format off
152 .gr_context = context.gr_context,
153 .dst_color_space = context.dst_color_space,
154 .matrix = matrix_,
155 .logical_rect = *paint_bounds,
156 .flow_type = flow_type,
157 // clang-format on
158 };
159 auto id = maybe_id.value();
160 return context.raster_cache->UpdateCacheEntry(
161 id, r_context,
162 [ctx = context, cache_state = cache_state_,
163 layer = layer_](DlCanvas* canvas) {
164 Rasterize(cache_state, layer, ctx, canvas);
165 });
166 }
167 }
168 return false;
169}
std::optional< RasterCacheKeyID > GetId() const override
const SkRect * GetPaintBoundsFromLayer() const
CacheState cache_state() const
static const auto * flow_type
bool Rasterize(RasterCacheItem::CacheState cache_state, Layer *layer, const PaintContext &paint_context, DlCanvas *canvas)
flutter::DlCanvas DlCanvas

Member Data Documentation

◆ can_cache_children_

bool flutter::LayerRasterCacheItem::can_cache_children_ = false
protected

Definition at line 67 of file layer_raster_cache_item.h.

◆ layer_

Layer* flutter::LayerRasterCacheItem::layer_
protected

Definition at line 59 of file layer_raster_cache_item.h.

◆ layer_cached_threshold_

int flutter::LayerRasterCacheItem::layer_cached_threshold_ = 1
protected

Definition at line 64 of file layer_raster_cache_item.h.

◆ layer_children_id_

std::optional<RasterCacheKeyID> flutter::LayerRasterCacheItem::layer_children_id_
protected

Definition at line 62 of file layer_raster_cache_item.h.

◆ num_cache_attempts_

int flutter::LayerRasterCacheItem::num_cache_attempts_ = 1
mutableprotected

Definition at line 69 of file layer_raster_cache_item.h.


The documentation for this class was generated from the following files: