Flutter Engine
 
Loading...
Searching...
No Matches
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 DlMatrix &matrix) override
 
void PrerollFinalize (PrerollContext *context, const DlMatrix &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 DlMatrix &matrix)
 
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 SkRect * GetPaintBoundsFromLayer () 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)

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

References flutter::PaintContext::canvas.

Referenced by flutter::testing::TEST_F().

◆ 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_

References flutter::RasterCacheItem::kChildren, flutter::RasterCacheItem::kCurrent, flutter::RasterCacheItem::kNone, and flutter::PaintContext::rendering_above_platform_view.

◆ 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_) {
94 return &ToSkRect(layer_->paint_bounds());
98 default:
100 return nullptr;
101 }
102}
const DlRect & child_paint_bounds() const
const DlRect & paint_bounds() const
Definition layer.h:196
virtual const ContainerLayer * as_container_layer() const
Definition layer.h:244
#define FML_DCHECK(condition)
Definition logging.h:122
const SkRect & ToSkRect(const DlRect &rect)

References FML_DCHECK, and flutter::ToSkRect().

◆ IsCacheChildren()

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

◆ 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}

Referenced by flutter::CacheableContainerLayer::CacheableContainerLayer().

◆ MarkCacheChildren()

void flutter::LayerRasterCacheItem::MarkCacheChildren ( )
inline

Definition at line 50 of file layer_raster_cache_item.h.

50{ can_cache_children_ = true; }

References can_cache_children_.

◆ MarkNotCacheChildren()

void flutter::LayerRasterCacheItem::MarkNotCacheChildren ( )
inline

Definition at line 52 of file layer_raster_cache_item.h.

52{ can_cache_children_ = false; }

References can_cache_children_.

◆ PrerollFinalize()

void flutter::LayerRasterCacheItem::PrerollFinalize ( PrerollContext context,
const DlMatrix 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
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 }
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)

References flutter::LayerStateStack::content_culled(), flutter::PrerollContext::has_platform_view, flutter::PrerollContext::has_texture_layer, flutter::kLayerChildren, flutter::RasterCacheKeyID::LayerChildrenIds(), flutter::PrerollContext::raster_cached_entries, and flutter::PrerollContext::state_stack.

Referenced by flutter::testing::TEST_F().

◆ PrerollSetup()

void flutter::LayerRasterCacheItem::PrerollSetup ( PrerollContext context,
const DlMatrix 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();
32 set_matrix(matrix);
33 }
34}
void set_matrix(const DlMatrix &matrix)

References flutter::PrerollContext::raster_cached_entries.

Referenced by flutter::testing::TEST_F().

◆ 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 const 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)

References flutter::PaintContext::dst_color_space, flutter::flow_type, flutter::PaintContext::gr_context, flutter::RasterCache::Context::gr_context, flutter::kNone, and flutter::Rasterize().

Referenced by flutter::testing::MockRasterCache::AddMockLayer(), and flutter::testing::TEST_F().

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.

Referenced by MarkCacheChildren(), and MarkNotCacheChildren().

◆ 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: