Flutter Engine
flutter::testing::MockRasterCache Class Reference

A RasterCache implementation that simulates the act of rendering a Layer or SkPicture 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=kDefaultPictureAndDispLayListCacheLimitPerFrame)
 
std::unique_ptr< RasterCacheResultRasterizePicture (SkPicture *picture, GrDirectContext *context, const SkMatrix &ctm, SkColorSpace *dst_color_space, bool checkerboard) const override
 Rasterize a picture object and produce a RasterCacheResult to be stored in the cache. More...
 
std::unique_ptr< RasterCacheResultRasterizeLayer (PrerollContext *context, Layer *layer, const SkMatrix &ctm, bool checkerboard) const override
 Rasterize an engine Layer and produce a RasterCacheResult to be stored in the cache. More...
 
void AddMockLayer (int width, int height)
 
void AddMockPicture (int width, int height)
 
- Public Member Functions inherited from flutter::RasterCache
 RasterCache (size_t access_threshold=3, size_t picture_and_display_list_cache_limit_per_frame=kDefaultPictureAndDispLayListCacheLimitPerFrame)
 
virtual ~RasterCache ()=default
 
virtual std::unique_ptr< RasterCacheResultRasterizeDisplayList (DisplayList *display_list, GrDirectContext *context, const SkMatrix &ctm, SkColorSpace *dst_color_space, bool checkerboard) const
 
bool Prepare (PrerollContext *context, SkPicture *picture, bool is_complex, bool will_change, const SkMatrix &untranslated_matrix, const SkPoint &offset=SkPoint())
 
bool Prepare (PrerollContext *context, DisplayList *display_list, bool is_complex, bool will_change, const SkMatrix &untranslated_matrix, const SkPoint &offset=SkPoint())
 
void Prepare (PrerollContext *context, Layer *layer, const SkMatrix &ctm)
 
bool Draw (const SkPicture &picture, SkCanvas &canvas) const
 
bool Draw (const DisplayList &display_list, SkCanvas &canvas) const
 
bool Draw (const Layer *layer, SkCanvas &canvas, SkPaint *paint=nullptr) const
 
void SweepAfterFrame ()
 
void Clear ()
 
void SetCheckboardCacheImages (bool checkerboard)
 
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, including cache entries in the SkPicture cache and the DisplayList cache. More...
 
size_t EstimateLayerCacheByteSize () const
 Estimate how much memory is used by layer raster cache entries in bytes. More...
 
int sweep_count () const
 Return the count of cache sweeps that have occured. More...
 
int 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...
 

Additional Inherited Members

- Static Public Member Functions inherited from flutter::RasterCache
static SkIRect GetDeviceBounds (const SkRect &rect, const SkMatrix &ctm)
 
static SkMatrix GetIntegralTransCTM (const SkMatrix &ctm)
 Snap the translation components of the matrix to integers. More...
 
- Static Public Attributes inherited from flutter::RasterCache
static constexpr int kDefaultPictureAndDispLayListCacheLimitPerFrame = 3
 

Detailed Description

A RasterCache implementation that simulates the act of rendering a Layer or SkPicture 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 48 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 = kDefaultPictureAndDispLayListCacheLimitPerFrame 
)
inlineexplicit

Definition at line 50 of file mock_raster_cache.h.

References color_space_, height, flutter::kGiantRect, and width.

55  picture_and_display_list_cache_limit_per_frame) {}
RasterCache(size_t access_threshold=3, size_t picture_and_display_list_cache_limit_per_frame=kDefaultPictureAndDispLayListCacheLimitPerFrame)
Definition: raster_cache.cc:39
int 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.
Definition: raster_cache.h:227

Member Function Documentation

◆ AddMockLayer()

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

Definition at line 39 of file mock_raster_cache.cc.

References flutter::path, and flutter::testing::MockLayer::Preroll().

Referenced by flutter::testing::TEST().

39  {
40  SkMatrix ctm = SkMatrix::I();
41  SkPath path;
42  path.addRect(100, 100, 100 + width, 100 + height);
43  MockLayer layer = MockLayer(path);
44  layer.Preroll(&preroll_context_, ctm);
45  Prepare(&preroll_context_, &layer, ctm);
46 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
bool Prepare(PrerollContext *context, SkPicture *picture, bool is_complex, bool will_change, const SkMatrix &untranslated_matrix, const SkPoint &offset=SkPoint())
int32_t width
int32_t height

◆ AddMockPicture()

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

Definition at line 48 of file mock_raster_cache.cc.

References color_space_, flutter::PrerollContext::dst_color_space, FML_DCHECK, flutter::testing::GetSamplePrerollContextHolder(), flutter::path, and flutter::testing::PrerollContextHolder::preroll_context.

Referenced by flutter::testing::TEST().

48  {
50  SkMatrix ctm = SkMatrix::I();
51  SkPictureRecorder skp_recorder;
52  SkRTreeFactory rtree_factory;
53  SkPath path;
54  path.addRect(100, 100, 100 + width, 100 + height);
55  SkCanvas* recorder_canvas = skp_recorder.beginRecording(
56  SkRect::MakeLTRB(0, 0, 200 + width, 200 + height), &rtree_factory);
57  recorder_canvas->drawPath(path, SkPaint());
58  sk_sp<SkPicture> picture = skp_recorder.finishRecordingAsPicture();
59  PrerollContextHolder holder = GetSamplePrerollContextHolder();
60  holder.preroll_context.dst_color_space = color_space_;
61  for (int i = 0; i < access_threshold(); i++) {
62  Prepare(&holder.preroll_context, picture.get(), true, false, ctm);
63  Draw(*picture, mock_canvas_);
64  }
65  Prepare(&holder.preroll_context, picture.get(), true, false, ctm);
66 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
#define FML_DCHECK(condition)
Definition: logging.h:86
sk_sp< SkColorSpace > color_space_
bool Prepare(PrerollContext *context, SkPicture *picture, bool is_complex, bool will_change, const SkMatrix &untranslated_matrix, const SkPoint &offset=SkPoint())
int 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.
Definition: raster_cache.h:227
PrerollContextHolder GetSamplePrerollContextHolder()
int32_t width
bool Draw(const SkPicture &picture, SkCanvas &canvas) const
int32_t height

◆ RasterizeLayer()

std::unique_ptr< RasterCacheResult > flutter::testing::MockRasterCache::RasterizeLayer ( PrerollContext context,
Layer layer,
const SkMatrix &  ctm,
bool  checkerboard 
) const
overridevirtual

Rasterize an engine Layer and produce a RasterCacheResult to be stored in the cache.

Parameters
contextthe PrerollContext containing important information needed for rendering a layer.
layerthe Layer object to be cached.
ctmthe transformation matrix used for rendering.
checkerboarda flag indicating whether or not a checkerboard pattern should be rendered into the cached image for debug analysis
Returns
a RasterCacheResult that can draw the rendered layer into the destination using a simple image blit

Reimplemented from flutter::RasterCache.

Definition at line 28 of file mock_raster_cache.cc.

References flutter::RasterCache::GetDeviceBounds(), and flutter::Layer::paint_bounds().

32  {
33  SkRect logical_rect = layer->paint_bounds();
34  SkIRect cache_rect = RasterCache::GetDeviceBounds(logical_rect, ctm);
35 
36  return std::make_unique<MockRasterCacheResult>(cache_rect);
37 }
static SkIRect GetDeviceBounds(const SkRect &rect, const SkMatrix &ctm)
Definition: raster_cache.h:105

◆ RasterizePicture()

std::unique_ptr< RasterCacheResult > flutter::testing::MockRasterCache::RasterizePicture ( SkPicture *  picture,
GrDirectContext *  context,
const SkMatrix &  ctm,
SkColorSpace *  dst_color_space,
bool  checkerboard 
) const
overridevirtual

Rasterize a picture object and produce a RasterCacheResult to be stored in the cache.

Parameters
picturethe SkPicture object to be cached.
contextthe GrDirectContext used for rendering.
ctmthe transformation matrix used for rendering.
dst_color_spacethe destination color space that the cached rendering will be drawn into
checkerboarda flag indicating whether or not a checkerboard pattern should be rendered into the cached image for debug analysis
Returns
a RasterCacheResult that can draw the rendered picture into the destination using a simple image blit

Reimplemented from flutter::RasterCache.

Definition at line 16 of file mock_raster_cache.cc.

References flutter::RasterCache::GetDeviceBounds().

21  {
22  SkRect logical_rect = picture->cullRect();
23  SkIRect cache_rect = RasterCache::GetDeviceBounds(logical_rect, ctm);
24 
25  return std::make_unique<MockRasterCacheResult>(cache_rect);
26 }
static SkIRect GetDeviceBounds(const SkRect &rect, const SkMatrix &ctm)
Definition: raster_cache.h:105

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