Flutter Engine
 
Loading...
Searching...
No Matches
flutter::testing::MockRasterCache Class Reference

A RasterCache implementation that simulates the act of rendering a Layer or DisplayList without the overhead of rasterization or pixel storage. This implementation is used only for testing proper usage of the RasterCache in layer unit tests. More...

#include <mock_raster_cache.h>

Inheritance diagram for flutter::testing::MockRasterCache:
flutter::RasterCache

Public Member Functions

 MockRasterCache (size_t access_threshold=3, size_t picture_and_display_list_cache_limit_per_frame=RasterCacheUtil::kDefaultPictureAndDisplayListCacheLimitPerFrame)
 
void AddMockLayer (int width, int height)
 
void AddMockPicture (int width, int height)
 
- Public Member Functions inherited from flutter::RasterCache
std::unique_ptr< RasterCacheResultRasterize (const RasterCache::Context &context, sk_sp< const DlRTree > rtree, const std::function< void(DlCanvas *)> &draw_function, const std::function< void(DlCanvas *, const DlRect &rect)> &draw_checkerboard) const
 
 RasterCache (size_t access_threshold=3, size_t picture_and_display_list_cache_limit_per_frame=RasterCacheUtil::kDefaultPictureAndDisplayListCacheLimitPerFrame)
 
virtual ~RasterCache ()=default
 
bool Draw (const RasterCacheKeyID &id, DlCanvas &canvas, const DlPaint *paint, bool preserve_rtree=false) const
 
bool HasEntry (const RasterCacheKeyID &id, const SkMatrix &) const
 
void BeginFrame ()
 
void EvictUnusedCacheEntries ()
 
void EndFrame ()
 
void Clear ()
 
const RasterCacheMetricspicture_metrics () const
 
const RasterCacheMetricslayer_metrics () const
 
size_t GetCachedEntriesCount () const
 
size_t GetLayerCachedEntriesCount () const
 
size_t GetPictureCachedEntriesCount () const
 
size_t EstimatePictureCacheByteSize () const
 Estimate how much memory is used by picture raster cache entries in bytes.
 
size_t EstimateLayerCacheByteSize () const
 Estimate how much memory is used by layer raster cache entries in bytes.
 
size_t access_threshold () const
 Return the number of frames that a picture must be prepared before it will be cached. If the number is 0, then no picture will ever be cached.
 
bool GenerateNewCacheInThisFrame () const
 
CacheInfo MarkSeen (const RasterCacheKeyID &id, const SkMatrix &matrix, bool visible) const
 The entry whose RasterCacheKey is generated by RasterCacheKeyID and matrix is marked as encountered by the current frame. The entry will be created if it does not exist. Optionally the entry will be marked as visible in the current frame if the caller determines that it intersects the cull rect. The access_count of the entry will be increased if it is visible, or if it was ever visible.
 
int GetAccessCount (const RasterCacheKeyID &id, const SkMatrix &matrix) const
 
bool UpdateCacheEntry (const RasterCacheKeyID &id, const Context &raster_cache_context, const std::function< void(DlCanvas *)> &render_function, sk_sp< const DlRTree > rtree=nullptr) const
 

Detailed Description

A RasterCache implementation that simulates the act of rendering a Layer or DisplayList without the overhead of rasterization or pixel storage. This implementation is used only for testing proper usage of the RasterCache in layer unit tests.

Definition at line 55 of file mock_raster_cache.h.

Constructor & Destructor Documentation

◆ MockRasterCache()

flutter::testing::MockRasterCache::MockRasterCache ( size_t  access_threshold = 3,
size_t  picture_and_display_list_cache_limit_per_frame = RasterCacheUtil::kDefaultPictureAndDisplayListCacheLimitPerFrame 
)
inlineexplicit

Definition at line 57 of file mock_raster_cache.h.

62 picture_and_display_list_cache_limit_per_frame) {
63 preroll_state_stack_.set_preroll_delegate(DlMatrix());
64 paint_state_stack_.set_delegate(&builder_);
65 }
void set_delegate(DlCanvas *canvas)
void set_preroll_delegate(const DlRect &cull_rect, const DlMatrix &matrix)
size_t access_threshold() const
Return the number of frames that a picture must be prepared before it will be cached....
RasterCache(size_t access_threshold=3, size_t picture_and_display_list_cache_limit_per_frame=RasterCacheUtil::kDefaultPictureAndDisplayListCacheLimitPerFrame)
impeller::Matrix DlMatrix

References flutter::LayerStateStack::set_delegate(), and flutter::LayerStateStack::set_preroll_delegate().

Member Function Documentation

◆ AddMockLayer()

void flutter::testing::MockRasterCache::AddMockLayer ( int  width,
int  height 
)

Definition at line 20 of file mock_raster_cache.cc.

20 {
21 SkMatrix ctm = SkMatrix::I();
22 DlPath path = DlPath::MakeRectLTRB(100, 100, 100 + width, 100 + height);
23 int layer_cached_threshold = 1;
24 MockCacheableLayer layer =
25 MockCacheableLayer(path, DlPaint(), layer_cached_threshold);
26 layer.Preroll(&preroll_context_);
27 layer.raster_cache_item()->TryToPrepareRasterCache(paint_context_);
28 RasterCache::Context r_context = {
29 // clang-format off
30 .gr_context = preroll_context_.gr_context,
31 .dst_color_space = preroll_context_.dst_color_space,
32 .matrix = ctm,
33 .logical_rect = ToSkRect(layer.paint_bounds()),
34 // clang-format on
35 };
37 RasterCacheKeyID(layer.unique_id(), RasterCacheKeyType::kLayer),
38 r_context, [&](DlCanvas* canvas) {
39 SkRect cache_rect = RasterCacheUtil::GetDeviceBounds(
40 r_context.logical_rect, r_context.matrix);
41 return std::make_unique<MockRasterCacheResult>(cache_rect);
42 });
43}
static DlPath MakeRectLTRB(DlScalar left, DlScalar top, DlScalar right, DlScalar bottom)
Definition dl_path.cc:43
bool UpdateCacheEntry(const RasterCacheKeyID &id, const Context &raster_cache_context, const std::function< void(DlCanvas *)> &render_function, sk_sp< const DlRTree > rtree=nullptr) const
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switch_defs.h:52
const SkRect & ToSkRect(const DlRect &rect)
flutter::DlPath DlPath
flutter::DlPaint DlPaint
int32_t height
int32_t width
GrDirectContext * gr_context
Definition layer.h:47
sk_sp< SkColorSpace > dst_color_space
Definition layer.h:50

References flutter::PrerollContext::dst_color_space, flutter::PrerollContext::gr_context, flutter::RasterCache::Context::gr_context, height, flutter::kLayer, flutter::DlPath::MakeRectLTRB(), flutter::Layer::paint_bounds(), flutter::path, flutter::testing::MockCacheableLayer::Preroll(), flutter::testing::MockCacheableLayer::raster_cache_item(), flutter::ToSkRect(), flutter::LayerRasterCacheItem::TryToPrepareRasterCache(), flutter::Layer::unique_id(), flutter::RasterCache::UpdateCacheEntry(), and width.

Referenced by flutter::TEST(), and flutter::TEST().

◆ AddMockPicture()

void flutter::testing::MockRasterCache::AddMockPicture ( int  width,
int  height 
)

Definition at line 45 of file mock_raster_cache.cc.

45 {
47 SkMatrix ctm = SkMatrix::I();
48 DisplayListBuilder builder(DlRect::MakeLTRB(0, 0, 200 + width, 200 + height));
49 builder.DrawPath(DlPath::MakeRectXYWH(100, 100, width, height), DlPaint());
50 sk_sp<DisplayList> display_list = builder.Build();
51
52 FixedRefreshRateStopwatch raster_time;
53 FixedRefreshRateStopwatch ui_time;
54 LayerStateStack state_stack;
55 PaintContextHolder holder =
56 GetSamplePaintContextHolder(state_stack, this, &raster_time, &ui_time);
57 holder.paint_context.dst_color_space = color_space_;
58
59 DisplayListRasterCacheItem display_list_item(display_list, SkPoint(), true,
60 false);
61 for (size_t i = 0; i < access_threshold(); i++) {
62 AutoCache(&display_list_item, &preroll_context_, ToDlMatrix(ctm));
63 }
64 RasterCache::Context r_context = {
65 // clang-format off
66 .gr_context = preroll_context_.gr_context,
67 .dst_color_space = preroll_context_.dst_color_space,
68 .matrix = ctm,
69 .logical_rect = ToSkRect(display_list->GetBounds()),
70 // clang-format on
71 };
72 UpdateCacheEntry(RasterCacheKeyID(display_list->unique_id(),
74 r_context, [&](DlCanvas* canvas) {
75 SkRect cache_rect = RasterCacheUtil::GetDeviceBounds(
76 r_context.logical_rect, r_context.matrix);
77 return std::make_unique<MockRasterCacheResult>(cache_rect);
78 });
79}
static DlPath MakeRectXYWH(DlScalar x, DlScalar y, DlScalar width, DlScalar height)
Definition dl_path.cc:50
#define FML_DCHECK(condition)
Definition logging.h:122
PaintContextHolder GetSamplePaintContextHolder(LayerStateStack &state_stack, RasterCache *raster_cache, FixedRefreshRateStopwatch *raster_time, FixedRefreshRateStopwatch *ui_time)
DlMatrix ToDlMatrix(const SkMatrix &matrix)
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129

References flutter::RasterCache::access_threshold(), flutter::DisplayListBuilder::Build(), flutter::DisplayListBuilder::DrawPath(), flutter::PrerollContext::dst_color_space, flutter::PaintContext::dst_color_space, FML_DCHECK, flutter::testing::GetSamplePaintContextHolder(), flutter::PrerollContext::gr_context, flutter::RasterCache::Context::gr_context, height, i, flutter::kDisplayList, impeller::TRect< Scalar >::MakeLTRB(), flutter::DlPath::MakeRectXYWH(), flutter::testing::PaintContextHolder::paint_context, flutter::ToDlMatrix(), flutter::ToSkRect(), flutter::RasterCache::UpdateCacheEntry(), and width.

Referenced by flutter::TEST(), and flutter::TEST().


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