Flutter Engine
 
Loading...
Searching...
No Matches
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 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 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 std::optional< RasterCacheKeyIDGetId () const
 
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< 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 52 of file display_list_raster_cache_item.cc.

57 : RasterCacheItem(RasterCacheKeyID(display_list->unique_id(),
60 display_list_(display_list),
61 offset_(offset),
62 is_complex_(is_complex),
63 will_change_(will_change) {}
uint32_t unique_id() const
RasterCacheItem(RasterCacheKeyID key_id, CacheState cache_state=CacheState::kNone, unsigned child_entries=0)

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(); }

Referenced by Make(), PrerollSetup(), and TryToPrepareRasterCache().

◆ Draw() [1/2]

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

◆ Draw() [2/2]

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

Implements flutter::RasterCacheItem.

Definition at line 132 of file display_list_raster_cache_item.cc.

134 {
135 if (!context.raster_cache || !canvas) {
136 return false;
137 }
139 return context.raster_cache->Draw(key_id_, *canvas, paint,
140 context.rendering_above_platform_view);
141 }
142 return false;
143}

References flutter::RasterCacheItem::cache_state_, flutter::RasterCacheItem::kCurrent, flutter::RasterCacheItem::key_id_, and flutter::PaintContext::rendering_above_platform_view.

◆ 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 65 of file display_list_raster_cache_item.cc.

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

References display_list().

Referenced by flutter::DisplayListLayer::DisplayListLayer().

◆ ModifyMatrix()

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

Definition at line 48 of file display_list_raster_cache_item.h.

48 {
49 matrix_ = matrix_.preTranslate(offset.x(), offset.y());
50 }

References flutter::RasterCacheItem::matrix_.

◆ PrerollFinalize()

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

Implements flutter::RasterCacheItem.

Definition at line 103 of file display_list_raster_cache_item.cc.

104 {
105 if (cache_state_ == CacheState::kNone || !context->raster_cache ||
106 !context->raster_cached_entries) {
107 return;
108 }
109 auto* raster_cache = context->raster_cache;
110 DlRect bounds = display_list_->GetBounds().Shift(offset_.x(), offset_.y());
111 bool visible = !context->state_stack.content_culled(bounds);
112 RasterCache::CacheInfo cache_info =
113 raster_cache->MarkSeen(key_id_, ToSkMatrix(matrix), visible);
114 if (!visible ||
115 cache_info.accesses_since_visible <= raster_cache->access_threshold()) {
117 } else {
118 if (cache_info.has_image) {
119 context->renderable_state_flags |=
121 }
123 }
124 return;
125}
static constexpr int kCallerCanApplyOpacity
impeller::Rect DlRect
SkMatrix ToSkMatrix(const DlMatrix &matrix)

References flutter::RasterCache::CacheInfo::accesses_since_visible, flutter::RasterCacheItem::cache_state_, flutter::LayerStateStack::content_culled(), flutter::RasterCache::CacheInfo::has_image, flutter::LayerStateStack::kCallerCanApplyOpacity, flutter::RasterCacheItem::kCurrent, flutter::RasterCacheItem::key_id_, flutter::RasterCacheItem::kNone, flutter::PrerollContext::raster_cached_entries, flutter::PrerollContext::renderable_state_flags, flutter::PrerollContext::state_stack, and flutter::ToSkMatrix().

Referenced by flutter::testing::RasterCacheItemPreroll(), and flutter::testing::TEST_F().

◆ PrerollSetup()

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

Implements flutter::RasterCacheItem.

Definition at line 74 of file display_list_raster_cache_item.cc.

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

References flutter::RasterCacheItem::cache_state_, display_list(), flutter::DisplayListComplexityCalculator::GetForBackend(), flutter::DisplayListComplexityCalculator::GetForSoftware(), flutter::PrerollContext::gr_context, flutter::IsDisplayListWorthRasterizing(), flutter::RasterCacheItem::kCurrent, flutter::RasterCacheItem::kNone, flutter::PrerollContext::raster_cached_entries, and flutter::ToSkMatrix().

Referenced by flutter::testing::RasterCacheItemPreroll(), and flutter::testing::TEST_F().

◆ TryToPrepareRasterCache()

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

Implements flutter::RasterCacheItem.

Definition at line 147 of file display_list_raster_cache_item.cc.

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

References flutter::RasterCacheItem::cache_state_, display_list(), flutter::DlCanvas::DrawDisplayList(), flutter::PaintContext::dst_color_space, flutter::flow_type, FML_DCHECK, flutter::RasterCacheItem::GetId(), flutter::PaintContext::gr_context, flutter::RasterCache::Context::gr_context, flutter::RasterCacheItem::kNone, flutter::ToSkRect(), and value.

Referenced by flutter::testing::RasterCacheItemTryToRasterCache(), and flutter::testing::TEST_F().


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