Flutter Engine
 
Loading...
Searching...
No Matches
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 FLUTTER_FLOW_TESTING_MOCK_RASTER_CACHE_H_
6#define FLUTTER_FLOW_TESTING_MOCK_RASTER_CACHE_H_
7
8#include <vector>
13#include "third_party/skia/include/core/SkColorSpace.h"
14#include "third_party/skia/include/core/SkSize.h"
15
16namespace flutter {
17namespace testing {
18
19/**
20 * @brief A RasterCacheResult implementation that represents a cached Layer or
21 * DisplayList without the overhead of storage.
22 *
23 * This implementation is used by MockRasterCache only for testing proper usage
24 * of the RasterCache in layer unit tests.
25 */
27 public:
28 explicit MockRasterCacheResult(SkRect device_rect);
29
30 void draw(DlCanvas& canvas,
31 const DlPaint* paint = nullptr,
32 bool preserve_rtree = false) const override {};
33
34 SkISize image_dimensions() const override {
35 return SkSize::Make(device_rect_.width(), device_rect_.height()).toCeil();
36 };
37
38 int64_t image_bytes() const override {
39 return image_dimensions().area() *
40 SkColorTypeBytesPerPixel(kBGRA_8888_SkColorType);
41 }
42
43 private:
44 SkRect device_rect_;
45};
46
47static std::vector<RasterCacheItem*> raster_cache_items_;
48
49/**
50 * @brief A RasterCache implementation that simulates the act of rendering a
51 * Layer or DisplayList without the overhead of rasterization or pixel storage.
52 * This implementation is used only for testing proper usage of the RasterCache
53 * in layer unit tests.
54 */
56 public:
58 size_t access_threshold = 3,
59 size_t picture_and_display_list_cache_limit_per_frame =
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 }
66
67 void AddMockLayer(int width, int height);
68 void AddMockPicture(int width, int height);
69
70 private:
71 LayerStateStack preroll_state_stack_;
72 LayerStateStack paint_state_stack_;
73 DisplayListBuilder builder_;
74 sk_sp<SkColorSpace> color_space_ = SkColorSpace::MakeSRGB();
75 MutatorsStack mutators_stack_;
76 FixedRefreshRateStopwatch raster_time_;
78 std::shared_ptr<TextureRegistry> texture_registry_;
79 PrerollContext preroll_context_ = {
80 // clang-format off
81 .raster_cache = this,
82 .gr_context = nullptr,
83 .view_embedder = nullptr,
84 .state_stack = preroll_state_stack_,
85 .dst_color_space = color_space_,
86 .surface_needs_readback = false,
87 .raster_time = raster_time_,
88 .ui_time = ui_time_,
89 .texture_registry = texture_registry_,
90 .has_platform_view = false,
91 .has_texture_layer = false,
92 .raster_cached_entries = &raster_cache_items_
93 // clang-format on
94 };
95
96 PaintContext paint_context_ = {
97 // clang-format off
98 .state_stack = paint_state_stack_,
99 .canvas = nullptr,
100 .gr_context = nullptr,
101 .dst_color_space = color_space_,
102 .view_embedder = nullptr,
103 .raster_time = raster_time_,
104 .ui_time = ui_time_,
105 .texture_registry = texture_registry_,
106 .raster_cache = nullptr,
107 // clang-format on
108 };
109};
110
115
118 sk_sp<SkColorSpace> srgb;
119};
120
122 LayerStateStack& state_stack,
123 RasterCache* raster_cache,
124 FixedRefreshRateStopwatch* raster_time,
126
128 LayerStateStack& state_stack,
129 RasterCache* raster_cache,
130 FixedRefreshRateStopwatch* raster_time,
132
134 DisplayListRasterCacheItem& display_list_item,
135 PrerollContext& context,
136 PaintContext& paint_context,
137 const DlMatrix& matrix);
138
140 PrerollContext& context,
141 const DlMatrix& matrix);
142
144 DisplayListRasterCacheItem& display_list_item,
145 PaintContext& paint_context);
146
147} // namespace testing
148} // namespace flutter
149
150#endif // FLUTTER_FLOW_TESTING_MOCK_RASTER_CACHE_H_
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:32
Used for fixed refresh rate cases.
Definition stopwatch.h:80
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....
A RasterCache implementation that simulates the act of rendering a Layer or DisplayList without the o...
void AddMockLayer(int width, int height)
MockRasterCache(size_t access_threshold=3, size_t picture_and_display_list_cache_limit_per_frame=RasterCacheUtil::kDefaultPictureAndDisplayListCacheLimitPerFrame)
void AddMockPicture(int width, int height)
A RasterCacheResult implementation that represents a cached Layer or DisplayList without the overhead...
void draw(DlCanvas &canvas, const DlPaint *paint=nullptr, bool preserve_rtree=false) const override
bool RasterCacheItemTryToRasterCache(DisplayListRasterCacheItem &display_list_item, PaintContext &paint_context)
PrerollContextHolder GetSamplePrerollContextHolder(LayerStateStack &state_stack, RasterCache *raster_cache, FixedRefreshRateStopwatch *raster_time, FixedRefreshRateStopwatch *ui_time)
void RasterCacheItemPreroll(DisplayListRasterCacheItem &display_list_item, PrerollContext &context, const DlMatrix &matrix)
PaintContextHolder GetSamplePaintContextHolder(LayerStateStack &state_stack, RasterCache *raster_cache, FixedRefreshRateStopwatch *raster_time, FixedRefreshRateStopwatch *ui_time)
bool RasterCacheItemPrerollAndTryToRasterCache(DisplayListRasterCacheItem &display_list_item, PrerollContext &context, PaintContext &paint_context, const DlMatrix &matrix)
static std::vector< RasterCacheItem * > raster_cache_items_
impeller::Matrix DlMatrix
int32_t height
int32_t width
LayerStateStack & state_stack
Definition layer.h:91
GrDirectContext * gr_context
Definition layer.h:47
static constexpr int kDefaultPictureAndDisplayListCacheLimitPerFrame
A 4x4 matrix using column-major storage.
Definition matrix.h:37
sk_sp< SkColorSpace > color_space_