Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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)
 
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.
 

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 15 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 13 of file layer_raster_cache_item.cc.

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

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

◆ 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 78 of file layer_raster_cache_item.cc.

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

◆ GetPaintBoundsFromLayer()

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

Definition at line 89 of file layer_raster_cache_item.cc.

89 {
90 switch (cache_state_) {
92 return &(layer_->paint_bounds());
96 default:
98 return nullptr;
99 }
100}
const SkRect & child_paint_bounds() const
const SkRect & paint_bounds() const
Definition layer.h:209
virtual const ContainerLayer * as_container_layer() const
Definition layer.h:255
#define FML_DCHECK(condition)
Definition logging.h:103

◆ IsCacheChildren()

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

Definition at line 52 of file layer_raster_cache_item.h.

◆ 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 34 of file layer_raster_cache_item.cc.

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

◆ MarkCacheChildren()

void flutter::LayerRasterCacheItem::MarkCacheChildren ( )
inline

Definition at line 48 of file layer_raster_cache_item.h.

48{ can_cache_children_ = true; }

◆ MarkNotCacheChildren()

void flutter::LayerRasterCacheItem::MarkNotCacheChildren ( )
inline

Definition at line 50 of file layer_raster_cache_item.h.

50{ can_cache_children_ = false; }

◆ PrerollFinalize()

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

Implements flutter::RasterCacheItem.

Definition at line 42 of file layer_raster_cache_item.cc.

43 {
44 if (!context->raster_cache || !context->raster_cached_entries) {
45 return;
46 }
47 // We've marked the cache entry that we would like to cache so it stays
48 // alive, but if the following conditions apply then we need to set our
49 // state back to kDoNotCache so that we don't populate the entry later.
50 if (context->has_platform_view || context->has_texture_layer ||
51 context->state_stack.content_culled(layer_->paint_bounds())) {
52 return;
53 }
54 child_items_ = context->raster_cached_entries->size() - child_items_;
56 // the layer can be cached
58 context->raster_cache->MarkSeen(key_id_, matrix_, true);
59 } else {
61 // access current layer
63 if (!layer_children_id_.has_value()) {
65 if (!ids.has_value()) {
66 return;
67 }
68 layer_children_id_.emplace(std::move(ids.value()),
70 }
72 context->raster_cache->MarkSeen(layer_children_id_.value(), matrix_,
73 true);
74 }
75 }
76}
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 24 of file layer_raster_cache_item.cc.

25 {
27 if (context->raster_cache && context->raster_cached_entries) {
28 context->raster_cached_entries->push_back(this);
29 child_items_ = context->raster_cached_entries->size();
31 }
32}
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)

Member Data Documentation

◆ can_cache_children_

bool flutter::LayerRasterCacheItem::can_cache_children_ = false
protected

Definition at line 65 of file layer_raster_cache_item.h.

◆ layer_

Layer* flutter::LayerRasterCacheItem::layer_
protected

Definition at line 57 of file layer_raster_cache_item.h.

◆ layer_cached_threshold_

int flutter::LayerRasterCacheItem::layer_cached_threshold_ = 1
protected

Definition at line 62 of file layer_raster_cache_item.h.

◆ layer_children_id_

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

Definition at line 60 of file layer_raster_cache_item.h.

◆ num_cache_attempts_

int flutter::LayerRasterCacheItem::num_cache_attempts_ = 1
mutableprotected

Definition at line 67 of file layer_raster_cache_item.h.


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