Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
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 SkRect &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. More...
 
size_t EstimateLayerCacheByteSize () const
 Estimate how much memory is used by layer raster cache entries in bytes. More...
 
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. More...
 
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. More...
 
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 57 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 59 of file mock_raster_cache.h.

64 picture_and_display_list_cache_limit_per_frame) {
65 preroll_state_stack_.set_preroll_delegate(SkMatrix::I());
66 paint_state_stack_.set_delegate(&mock_canvas_);
67 }
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
void set_preroll_delegate(const SkRect &cull_rect, const SkMatrix &matrix)
void set_delegate(DlCanvas *canvas)
size_t access_threshold() const
Return the number of frames that a picture must be prepared before it will be cached....
Definition: raster_cache.h:216
RasterCache(size_t access_threshold=3, size_t picture_and_display_list_cache_limit_per_frame=RasterCacheUtil::kDefaultPictureAndDisplayListCacheLimitPerFrame)
Definition: raster_cache.cc:73

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();
23 path.addRect(100, 100, 100 + width, 100 + height);
24 int layer_cached_threshold = 1;
25 MockCacheableLayer layer =
26 MockCacheableLayer(path, DlPaint(), layer_cached_threshold);
27 layer.Preroll(&preroll_context_);
28 layer.raster_cache_item()->TryToPrepareRasterCache(paint_context_);
29 RasterCache::Context r_context = {
30 // clang-format off
31 .gr_context = preroll_context_.gr_context,
32 .dst_color_space = preroll_context_.dst_color_space,
33 .matrix = ctm,
34 .logical_rect = layer.paint_bounds(),
35 // clang-format on
36 };
38 RasterCacheKeyID(layer.unique_id(), RasterCacheKeyType::kLayer),
39 r_context, [&](DlCanvas* canvas) {
40 SkRect cache_rect = RasterCacheUtil::GetDeviceBounds(
41 r_context.logical_rect, r_context.matrix);
42 return std::make_unique<MockRasterCacheResult>(cache_rect);
43 });
44}
Definition: SkPath.h:59
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: switches.h:57
flutter::DlCanvas DlCanvas
flutter::DlPaint DlPaint
int32_t height
int32_t width
GrDirectContext * gr_context
Definition: layer.h:57
sk_sp< SkColorSpace > dst_color_space
Definition: layer.h:60

◆ AddMockPicture()

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

Definition at line 46 of file mock_raster_cache.cc.

46 {
48 SkMatrix ctm = SkMatrix::I();
49 DisplayListBuilder builder(SkRect::MakeLTRB(0, 0, 200 + width, 200 + height));
51 path.addRect(100, 100, 100 + width, 100 + height);
52 builder.DrawPath(path, DlPaint());
53 sk_sp<DisplayList> display_list = builder.Build();
54
55 FixedRefreshRateStopwatch raster_time;
56 FixedRefreshRateStopwatch ui_time;
57 LayerStateStack state_stack;
58 PaintContextHolder holder =
59 GetSamplePaintContextHolder(state_stack, this, &raster_time, &ui_time);
60 holder.paint_context.dst_color_space = color_space_;
61
62 DisplayListRasterCacheItem display_list_item(display_list, SkPoint(), true,
63 false);
64 for (size_t i = 0; i < access_threshold(); i++) {
65 AutoCache(&display_list_item, &preroll_context_, ctm);
66 }
67 RasterCache::Context r_context = {
68 // clang-format off
69 .gr_context = preroll_context_.gr_context,
70 .dst_color_space = preroll_context_.dst_color_space,
71 .matrix = ctm,
72 .logical_rect = display_list->bounds(),
73 // clang-format on
74 };
75 UpdateCacheEntry(RasterCacheKeyID(display_list->unique_id(),
77 r_context, [&](DlCanvas* canvas) {
78 SkRect cache_rect = RasterCacheUtil::GetDeviceBounds(
79 r_context.logical_rect, r_context.matrix);
80 return std::make_unique<MockRasterCacheResult>(cache_rect);
81 });
82}
#define FML_DCHECK(condition)
Definition: logging.h:103
PaintContextHolder GetSamplePaintContextHolder(LayerStateStack &state_stack, RasterCache *raster_cache, FixedRefreshRateStopwatch *raster_time, FixedRefreshRateStopwatch *ui_time)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646

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