7#include "flutter/flow/layers/layer_raster_cache_item.h"
8#include "flutter/flow/layers/container_layer.h"
9#include "flutter/flow/raster_cache_item.h"
10#include "flutter/flow/raster_cache_util.h"
16 int layer_cached_threshold,
17 bool can_cache_children)
23 layer_cached_threshold_(layer_cached_threshold),
24 can_cache_children_(can_cache_children) {}
38 int layer_cache_threshold,
39 bool can_cache_children) {
40 return std::make_unique<LayerRasterCacheItem>(layer, layer_cache_threshold,
57 if (num_cache_attempts_ >= layer_cached_threshold_) {
59 cache_state_ = CacheState::kCurrent;
60 context->raster_cache->MarkSeen(key_id_, matrix_,
true);
62 num_cache_attempts_++;
64 if (can_cache_children_) {
65 if (!layer_children_id_.has_value()) {
67 if (!ids.has_value()) {
70 layer_children_id_.emplace(std::move(ids.value()),
73 cache_state_ = CacheState::kChildren;
74 context->raster_cache->MarkSeen(layer_children_id_.value(), matrix_,
81 switch (cache_state_) {
85 return layer_children_id_;
92 switch (cache_state_) {
93 case CacheState::kCurrent:
94 return &(layer_->paint_bounds());
95 case CacheState::kChildren:
97 return &(layer_->as_container_layer()->child_paint_bounds());
119 .ui_time = paint_context.
ui_time,
121 .raster_cache = paint_context.raster_cache,
125 switch (cache_state) {
126 case RasterCacheItem::CacheState::kCurrent:
128 layer->
Paint(context);
130 case RasterCacheItem::CacheState::kChildren:
143 bool parent_cached)
const {
144 auto maybe_id = GetId();
145 if (!maybe_id.has_value() || !context.raster_cache || parent_cached) {
148 if (cache_state_ !=
kNone) {
149 if (
const SkRect* paint_bounds = GetPaintBoundsFromLayer()) {
155 .logical_rect = *paint_bounds,
159 auto id = maybe_id.value();
160 return context.raster_cache->UpdateCacheEntry(
162 [ctx = context, cache_state = cache_state_,
164 Rasterize(cache_state, layer, ctx, canvas);
179 if (!context.raster_cache || !canvas) {
182 switch (cache_state_) {
186 return context.raster_cache->Draw(key_id_, *canvas,
paint,
190 if (!layer_children_id_.has_value()) {
193 return context.raster_cache->Draw(layer_children_id_.value(), *canvas,
Developer-facing API for rendering anything within the engine.
static std::unique_ptr< LayerRasterCacheItem > Make(Layer *, int layer_cache_threshold, bool can_cache_children=false)
Create a LayerRasterCacheItem, connect a layer and manage the Layer's raster cache.
std::optional< RasterCacheKeyID > GetId() const override
void PrerollSetup(PrerollContext *context, const SkMatrix &matrix) override
LayerRasterCacheItem(Layer *layer, int layer_cached_threshold=1, bool can_cache_children=false)
bool Draw(const PaintContext &context, const DlPaint *paint) const override
bool TryToPrepareRasterCache(const PaintContext &context, bool parent_cached=false) const override
const SkRect * GetPaintBoundsFromLayer() const
void PrerollFinalize(PrerollContext *context, const SkMatrix &matrix) override
void set_delegate(DlCanvas *canvas)
bool content_culled(const SkRect &content_bounds) const
virtual void PaintChildren(PaintContext &context) const
bool needs_painting(PaintContext &context) const
virtual void Paint(PaintContext &context) const =0
static std::optional< std::vector< RasterCacheKeyID > > LayerChildrenIds(const Layer *layer)
static void Draw(SkCanvas *canvas, const SkRect &rect)
#define FML_DCHECK(condition)
unsigned useCenter Optional< SkMatrix > matrix
static const auto * flow_type
bool Rasterize(RasterCacheItem::CacheState cache_state, Layer *layer, const PaintContext &paint_context, DlCanvas *canvas)
ExternalViewEmbedder * view_embedder
bool rendering_above_platform_view
sk_sp< SkColorSpace > dst_color_space
const Stopwatch & raster_time
const Stopwatch & ui_time
std::shared_ptr< TextureRegistry > texture_registry
GrDirectContext * gr_context
LayerStateStack & state_stack
std::vector< RasterCacheItem * > * raster_cached_entries
LayerStateStack & state_stack
GrDirectContext * gr_context