Flutter Engine
mock_raster_cache.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLOW_TESTING_MOCK_RASTER_CACHE_H_
6 #define FLOW_TESTING_MOCK_RASTER_CACHE_H_
7 
8 #include "flutter/flow/layers/layer.h"
9 #include "flutter/flow/raster_cache.h"
10 #include "flutter/flow/testing/mock_layer.h"
11 #include "flutter/testing/mock_canvas.h"
12 #include "third_party/skia/include/core/SkImage.h"
13 #include "third_party/skia/include/core/SkPicture.h"
14 
15 namespace flutter {
16 namespace testing {
17 
18 /**
19  * @brief A RasterCacheResult implementation that represents a cached Layer or
20  * SkPicture without the overhead of storage.
21  *
22  * This implementation is used by MockRasterCache only for testing proper usage
23  * of the RasterCache in layer unit tests.
24  */
26  public:
27  MockRasterCacheResult(SkIRect device_rect);
28 
29  void draw(SkCanvas& canvas, const SkPaint* paint = nullptr) const override{};
30 
31  SkISize image_dimensions() const override { return device_rect_.size(); };
32 
33  int64_t image_bytes() const override {
34  return image_dimensions().area() *
35  SkColorTypeBytesPerPixel(kBGRA_8888_SkColorType);
36  }
37 
38  private:
39  SkIRect device_rect_;
40 };
41 
42 /**
43  * @brief A RasterCache implementation that simulates the act of rendering a
44  * Layer or SkPicture without the overhead of rasterization or pixel storage.
45  * This implementation is used only for testing proper usage of the RasterCache
46  * in layer unit tests.
47  */
48 class MockRasterCache : public RasterCache {
49  public:
50  explicit MockRasterCache(
51  size_t access_threshold = 3,
52  size_t picture_and_display_list_cache_limit_per_frame =
53  kDefaultPictureAndDispLayListCacheLimitPerFrame)
54  : RasterCache(access_threshold,
55  picture_and_display_list_cache_limit_per_frame) {}
56 
57  std::unique_ptr<RasterCacheResult> RasterizePicture(
58  SkPicture* picture,
59  GrDirectContext* context,
60  const SkMatrix& ctm,
61  SkColorSpace* dst_color_space,
62  bool checkerboard) const override;
63 
64  std::unique_ptr<RasterCacheResult> RasterizeLayer(
65  PrerollContext* context,
66  Layer* layer,
67  const SkMatrix& ctm,
68  bool checkerboard) const override;
69 
70  void AddMockLayer(int width, int height);
71  void AddMockPicture(int width, int height);
72 
73  private:
74  MockCanvas mock_canvas_;
75  SkColorSpace* color_space_ = mock_canvas_.imageInfo().colorSpace();
76  MutatorsStack mutators_stack_;
77  Stopwatch raster_time_;
78  Stopwatch ui_time_;
79  TextureRegistry texture_registry_;
80  PrerollContext preroll_context_ = {
81  nullptr, /* raster_cache */
82  nullptr, /* gr_context */
83  nullptr, /* external_view_embedder */
84  mutators_stack_, /* mutators_stack */
85  color_space_, /* color_space */
86  kGiantRect, /* cull_rect */
87  false, /* layer reads from surface */
88  raster_time_, /* raster stopwatch */
89  ui_time_, /* frame build stopwatch */
90  texture_registry_, /* texture_registry */
91  false, /* checkerboard_offscreen_layers */
92  1.0f, /* frame_device_pixel_ratio */
93  false, /* has_platform_view */
94  false, /* has_texture_layer */
95  };
96 };
97 
100  sk_sp<SkColorSpace> srgb;
101 };
102 
104 
105 } // namespace testing
106 } // namespace flutter
107 
108 #endif // FLOW_TESTING_MOCK_RASTER_CACHE_H_
A RasterCache implementation that simulates the act of rendering a Layer or SkPicture without the ove...
sk_sp< SkColorSpace > color_space_
void draw(SkCanvas &canvas, const SkPaint *paint=nullptr) const override
static constexpr SkRect kGiantRect
Definition: layer.h:37
MockRasterCache(size_t access_threshold=3, size_t picture_and_display_list_cache_limit_per_frame=kDefaultPictureAndDispLayListCacheLimitPerFrame)
PrerollContextHolder GetSamplePrerollContextHolder()
int32_t width
int32_t height
SkISize image_dimensions() const override
A RasterCacheResult implementation that represents a cached Layer or SkPicture without the overhead o...