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

#include <display_list_raster_cache_item.h>

Inheritance diagram for flutter::DisplayListRasterCacheItem:
flutter::RasterCacheItem

Public Member Functions

 DisplayListRasterCacheItem (const sk_sp< DisplayList > &display_list, const SkPoint &offset, bool is_complex=true, bool will_change=false)
 
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 ModifyMatrix (SkPoint offset) const
 
const DisplayListdisplay_list () 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< DisplayListRasterCacheItemMake (const sk_sp< DisplayList > &, const SkPoint &offset, bool is_complex, bool will_change)
 

Additional Inherited Members

- Public Types inherited from flutter::RasterCacheItem
enum  CacheState { kNone = 0 , kCurrent , kChildren }
 
- Protected Attributes inherited from flutter::RasterCacheItem
RasterCacheKeyID key_id_
 
CacheState cache_state_ = CacheState::kNone
 
SkMatrix matrix_
 
unsigned child_items_
 

Detailed Description

Definition at line 21 of file display_list_raster_cache_item.h.

Constructor & Destructor Documentation

◆ DisplayListRasterCacheItem()

flutter::DisplayListRasterCacheItem::DisplayListRasterCacheItem ( const sk_sp< DisplayList > &  display_list,
const SkPoint offset,
bool  is_complex = true,
bool  will_change = false 
)

Definition at line 51 of file display_list_raster_cache_item.cc.

56 : RasterCacheItem(RasterCacheKeyID(display_list->unique_id(),
58 CacheState::kCurrent),
59 display_list_(display_list),
60 offset_(offset),
61 is_complex_(is_complex),
62 will_change_(will_change) {}
uint32_t unique_id() const
Definition: display_list.h:292
RasterCacheItem(RasterCacheKeyID key_id, CacheState cache_state=CacheState::kNone, unsigned child_entries=0)
SeparatedVector2 offset

Member Function Documentation

◆ display_list()

const DisplayList * flutter::DisplayListRasterCacheItem::display_list ( ) const
inline

Definition at line 52 of file display_list_raster_cache_item.h.

52{ return display_list_.get(); }

◆ Draw() [1/2]

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

Implements flutter::RasterCacheItem.

Definition at line 126 of file display_list_raster_cache_item.cc.

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

◆ Draw() [2/2]

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

Implements flutter::RasterCacheItem.

Definition at line 131 of file display_list_raster_cache_item.cc.

133 {
134 if (!context.raster_cache || !canvas) {
135 return false;
136 }
137 if (cache_state_ == CacheState::kCurrent) {
138 return context.raster_cache->Draw(key_id_, *canvas, paint,
139 context.rendering_above_platform_view);
140 }
141 return false;
142}

◆ Make()

std::unique_ptr< DisplayListRasterCacheItem > flutter::DisplayListRasterCacheItem::Make ( const sk_sp< DisplayList > &  display_list,
const SkPoint offset,
bool  is_complex,
bool  will_change 
)
static

Definition at line 64 of file display_list_raster_cache_item.cc.

68 {
69 return std::make_unique<DisplayListRasterCacheItem>(display_list, offset,
70 is_complex, will_change);
71}

◆ ModifyMatrix()

void flutter::DisplayListRasterCacheItem::ModifyMatrix ( SkPoint  offset) const
inline

Definition at line 48 of file display_list_raster_cache_item.h.

48 {
50 }
SkMatrix & preTranslate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.cpp:263

◆ PrerollFinalize()

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

Implements flutter::RasterCacheItem.

Definition at line 102 of file display_list_raster_cache_item.cc.

103 {
104 if (cache_state_ == CacheState::kNone || !context->raster_cache ||
105 !context->raster_cached_entries) {
106 return;
107 }
108 auto* raster_cache = context->raster_cache;
109 SkRect bounds = display_list_->bounds().makeOffset(offset_.x(), offset_.y());
110 bool visible = !context->state_stack.content_culled(bounds);
111 RasterCache::CacheInfo cache_info =
112 raster_cache->MarkSeen(key_id_, matrix, visible);
113 if (!visible ||
114 cache_info.accesses_since_visible <= raster_cache->access_threshold()) {
116 } else {
117 if (cache_info.has_image) {
118 context->renderable_state_flags |=
120 }
122 }
123 return;
124}
static constexpr int kCallerCanApplyOpacity
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
Optional< SkRect > bounds
Definition: SkRecords.h:189
@ kNone
Definition: layer.h:53
constexpr float y() const
Definition: SkPoint_impl.h:187
constexpr float x() const
Definition: SkPoint_impl.h:181

◆ PrerollSetup()

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

Implements flutter::RasterCacheItem.

Definition at line 73 of file display_list_raster_cache_item.cc.

74 {
76 DisplayListComplexityCalculator* complexity_calculator =
78 context->gr_context->backend())
79 : DisplayListComplexityCalculator::GetForSoftware();
80
81 if (!IsDisplayListWorthRasterizing(display_list(), will_change_, is_complex_,
82 complexity_calculator)) {
83 // We only deal with display lists that are worthy of rasterization.
84 return;
85 }
86
87 transformation_matrix_ = matrix;
88 transformation_matrix_.preTranslate(offset_.x(), offset_.y());
89
90 if (!transformation_matrix_.invert(nullptr)) {
91 // The matrix was singular. No point in going further.
92 return;
93 }
94
95 if (context->raster_cached_entries && context->raster_cache) {
96 context->raster_cached_entries->push_back(this);
97 cache_state_ = CacheState::kCurrent;
98 }
99 return;
100}
bool invert(SkMatrix *inverse) const
Definition: SkMatrix.h:1206
static DisplayListComplexityCalculator * GetForBackend(GrBackendApi backend)
static bool IsDisplayListWorthRasterizing(const DisplayList *display_list, bool will_change, bool is_complex, DisplayListComplexityCalculator *complexity_calculator)

◆ TryToPrepareRasterCache()

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

Implements flutter::RasterCacheItem.

Definition at line 146 of file display_list_raster_cache_item.cc.

148 {
149 // If we don't have raster_cache we should not cache the current display_list.
150 // If the current node's ancestor has been cached we also should not cache the
151 // current node. In the current frame, the raster_cache will collect all
152 // display_list or picture_list to calculate the memory they used, we
153 // shouldn't cache the current node if the memory is more significant than the
154 // limit.
155 auto id = GetId();
156 FML_DCHECK(id.has_value());
157 if (cache_state_ == kNone || !context.raster_cache || parent_cached ||
158 !context.raster_cache->GenerateNewCacheInThisFrame() || !id.has_value()) {
159 return false;
160 }
161 SkRect bounds = display_list_->bounds().makeOffset(offset_.x(), offset_.y());
162 RasterCache::Context r_context = {
163 // clang-format off
164 .gr_context = context.gr_context,
165 .dst_color_space = context.dst_color_space,
166 .matrix = transformation_matrix_,
167 .logical_rect = bounds,
168 .flow_type = flow_type,
169 // clang-format on
170 };
171 return context.raster_cache->UpdateCacheEntry(
172 id.value(), r_context,
173 [display_list = display_list_](DlCanvas* canvas) {
174 canvas->DrawDisplayList(display_list);
175 },
176 display_list_->rtree());
177}
virtual std::optional< RasterCacheKeyID > GetId() const
uint8_t value
#define FML_DCHECK(condition)
Definition: logging.h:103
static const auto * flow_type
flutter::DlCanvas DlCanvas

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