Flutter Engine
The 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>
9#include "flutter/flow/layers/layer.h"
10#include "flutter/flow/raster_cache.h"
11#include "flutter/flow/raster_cache_item.h"
12#include "flutter/flow/testing/mock_layer.h"
13#include "flutter/testing/mock_canvas.h"
17
18namespace flutter {
19namespace testing {
20
21/**
22 * @brief A RasterCacheResult implementation that represents a cached Layer or
23 * DisplayList without the overhead of storage.
24 *
25 * This implementation is used by MockRasterCache only for testing proper usage
26 * of the RasterCache in layer unit tests.
27 */
29 public:
30 explicit MockRasterCacheResult(SkRect device_rect);
31
32 void draw(DlCanvas& canvas,
33 const DlPaint* paint = nullptr,
34 bool preserve_rtree = false) const override {};
35
36 SkISize image_dimensions() const override {
37 return SkSize::Make(device_rect_.width(), device_rect_.height()).toCeil();
38 };
39
40 int64_t image_bytes() const override {
41 return image_dimensions().area() *
43 }
44
45 private:
46 SkRect device_rect_;
47};
48
49static std::vector<RasterCacheItem*> raster_cache_items_;
50
51/**
52 * @brief A RasterCache implementation that simulates the act of rendering a
53 * Layer or DisplayList without the overhead of rasterization or pixel storage.
54 * This implementation is used only for testing proper usage of the RasterCache
55 * in layer unit tests.
56 */
58 public:
60 size_t access_threshold = 3,
61 size_t picture_and_display_list_cache_limit_per_frame =
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 }
68
69 void AddMockLayer(int width, int height);
70 void AddMockPicture(int width, int height);
71
72 private:
73 LayerStateStack preroll_state_stack_;
74 LayerStateStack paint_state_stack_;
75 MockCanvas mock_canvas_;
77 MutatorsStack mutators_stack_;
78 FixedRefreshRateStopwatch raster_time_;
80 std::shared_ptr<TextureRegistry> texture_registry_;
81 PrerollContext preroll_context_ = {
82 // clang-format off
83 .raster_cache = this,
84 .gr_context = nullptr,
85 .view_embedder = nullptr,
86 .state_stack = preroll_state_stack_,
87 .dst_color_space = color_space_,
88 .surface_needs_readback = false,
89 .raster_time = raster_time_,
90 .ui_time = ui_time_,
91 .texture_registry = texture_registry_,
92 .has_platform_view = false,
93 .has_texture_layer = false,
94 .raster_cached_entries = &raster_cache_items_
95 // clang-format on
96 };
97
98 PaintContext paint_context_ = {
99 // clang-format off
100 .state_stack = paint_state_stack_,
101 .canvas = nullptr,
102 .gr_context = nullptr,
103 .dst_color_space = color_space_,
104 .view_embedder = nullptr,
105 .raster_time = raster_time_,
106 .ui_time = ui_time_,
107 .texture_registry = texture_registry_,
108 .raster_cache = nullptr,
109 // clang-format on
110 };
111};
112
117
122
124 LayerStateStack& state_stack,
125 RasterCache* raster_cache,
126 FixedRefreshRateStopwatch* raster_time,
128
130 LayerStateStack& state_stack,
131 RasterCache* raster_cache,
132 FixedRefreshRateStopwatch* raster_time,
134
136 DisplayListRasterCacheItem& display_list_item,
137 PrerollContext& context,
138 PaintContext& paint_context,
139 const SkMatrix& matrix);
140
142 PrerollContext& context,
143 const SkMatrix& matrix);
144
146 DisplayListRasterCacheItem& display_list_item,
147 PaintContext& paint_context);
148
149} // namespace testing
150} // namespace flutter
151
152#endif // FLUTTER_FLOW_TESTING_MOCK_RASTER_CACHE_H_
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition SkColorType.h:26
SK_API int SkColorTypeBytesPerPixel(SkColorType ct)
static sk_sp< SkColorSpace > MakeSRGB()
static const SkMatrix & I()
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:37
Used for fixed refresh rate cases.
Definition stopwatch.h:77
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....
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
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)
const Paint & paint
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 SkMatrix &matrix)
bool RasterCacheItemPrerollAndTryToRasterCache(DisplayListRasterCacheItem &display_list_item, PrerollContext &context, PaintContext &paint_context, const SkMatrix &matrix)
PaintContextHolder GetSamplePaintContextHolder(LayerStateStack &state_stack, RasterCache *raster_cache, FixedRefreshRateStopwatch *raster_time, FixedRefreshRateStopwatch *ui_time)
static std::vector< RasterCacheItem * > raster_cache_items_
int32_t height
int32_t width
constexpr int64_t area() const
Definition SkSize.h:39
constexpr float height() const
Definition SkRect.h:769
constexpr float width() const
Definition SkRect.h:762
static constexpr SkSize Make(SkScalar w, SkScalar h)
Definition SkSize.h:56
SkISize toCeil() const
Definition SkSize.h:83
LayerStateStack & state_stack
Definition layer.h:100
RasterCache * raster_cache
Definition layer.h:55
static constexpr int kDefaultPictureAndDisplayListCacheLimitPerFrame
sk_sp< SkColorSpace > color_space_