Flutter Engine
 
Loading...
Searching...
No Matches
mock_raster_cache.cc
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
6
11#include "include/core/SkMatrix.h"
12
13namespace flutter {
14namespace testing {
15
17 : RasterCacheResult(nullptr, SkRect::MakeEmpty(), "RasterCacheFlow::test"),
18 device_rect_(device_rect) {}
19
21 SkMatrix ctm = SkMatrix::I();
22 DlPath path = DlPath::MakeRectLTRB(100, 100, 100 + width, 100 + height);
23 int layer_cached_threshold = 1;
24 MockCacheableLayer layer =
25 MockCacheableLayer(path, DlPaint(), layer_cached_threshold);
26 layer.Preroll(&preroll_context_);
27 layer.raster_cache_item()->TryToPrepareRasterCache(paint_context_);
28 RasterCache::Context r_context = {
29 // clang-format off
30 .gr_context = preroll_context_.gr_context,
31 .dst_color_space = preroll_context_.dst_color_space,
32 .matrix = ctm,
33 .logical_rect = ToSkRect(layer.paint_bounds()),
34 // clang-format on
35 };
38 r_context, [&](DlCanvas* canvas) {
39 SkRect cache_rect = RasterCacheUtil::GetDeviceBounds(
40 r_context.logical_rect, r_context.matrix);
41 return std::make_unique<MockRasterCacheResult>(cache_rect);
42 });
43}
44
47 SkMatrix ctm = SkMatrix::I();
48 DisplayListBuilder builder(DlRect::MakeLTRB(0, 0, 200 + width, 200 + height));
49 builder.DrawPath(DlPath::MakeRectXYWH(100, 100, width, height), DlPaint());
50 sk_sp<DisplayList> display_list = builder.Build();
51
52 FixedRefreshRateStopwatch raster_time;
54 LayerStateStack state_stack;
55 PaintContextHolder holder =
56 GetSamplePaintContextHolder(state_stack, this, &raster_time, &ui_time);
57 holder.paint_context.dst_color_space = color_space_;
58
59 DisplayListRasterCacheItem display_list_item(display_list, SkPoint(), true,
60 false);
61 for (size_t i = 0; i < access_threshold(); i++) {
62 AutoCache(&display_list_item, &preroll_context_, ToDlMatrix(ctm));
63 }
64 RasterCache::Context r_context = {
65 // clang-format off
66 .gr_context = preroll_context_.gr_context,
67 .dst_color_space = preroll_context_.dst_color_space,
68 .matrix = ctm,
69 .logical_rect = ToSkRect(display_list->GetBounds()),
70 // clang-format on
71 };
72 UpdateCacheEntry(RasterCacheKeyID(display_list->unique_id(),
74 r_context, [&](DlCanvas* canvas) {
75 SkRect cache_rect = RasterCacheUtil::GetDeviceBounds(
76 r_context.logical_rect, r_context.matrix);
77 return std::make_unique<MockRasterCacheResult>(cache_rect);
78 });
79}
80
82 LayerStateStack& state_stack,
83 RasterCache* raster_cache,
84 FixedRefreshRateStopwatch* raster_time,
86 sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();
87
88 PrerollContextHolder holder = {
89 {
90 // clang-format off
91 .raster_cache = raster_cache,
92 .gr_context = nullptr,
93 .view_embedder = nullptr,
94 .state_stack = state_stack,
95 .dst_color_space = srgb,
96 .surface_needs_readback = false,
97 .raster_time = *raster_time,
98 .ui_time = *ui_time,
99 .texture_registry = nullptr,
100 .has_platform_view = false,
101 .has_texture_layer = false,
102 .raster_cached_entries = &raster_cache_items_,
103 // clang-format on
104 },
105 srgb};
106
107 return holder;
108}
109
111 LayerStateStack& state_stack,
112 RasterCache* raster_cache,
113 FixedRefreshRateStopwatch* raster_time,
114 FixedRefreshRateStopwatch* ui_time) {
115 sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();
116 PaintContextHolder holder = {// clang-format off
117 {
118 .state_stack = state_stack,
119 .canvas = nullptr,
120 .gr_context = nullptr,
121 .dst_color_space = srgb,
122 .view_embedder = nullptr,
123 .raster_time = *raster_time,
124 .ui_time = *ui_time,
125 .texture_registry = nullptr,
126 .raster_cache = raster_cache,
127 },
128 // clang-format on
129 srgb};
130
131 return holder;
132}
133
135 DisplayListRasterCacheItem& display_list_item,
136 PrerollContext& context,
137 PaintContext& paint_context,
138 const DlMatrix& matrix) {
139 RasterCacheItemPreroll(display_list_item, context, matrix);
140 context.raster_cache->EvictUnusedCacheEntries();
141 return RasterCacheItemTryToRasterCache(display_list_item, paint_context);
142}
143
145 PrerollContext& context,
146 const DlMatrix& matrix) {
147 display_list_item.PrerollSetup(&context, matrix);
148 display_list_item.PrerollFinalize(&context, matrix);
149}
150
152 DisplayListRasterCacheItem& display_list_item,
153 PaintContext& paint_context) {
154 if (display_list_item.cache_state() ==
156 return display_list_item.TryToPrepareRasterCache(paint_context);
157 }
158 return false;
159}
160
161} // namespace testing
162} // namespace flutter
sk_sp< DisplayList > Build()
Definition dl_builder.cc:66
void DrawPath(const DlPath &path, const DlPaint &paint) override
void PrerollSetup(PrerollContext *context, const DlMatrix &matrix) override
void PrerollFinalize(PrerollContext *context, const DlMatrix &matrix) override
bool TryToPrepareRasterCache(const PaintContext &context, bool parent_cached=false) const override
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:32
static DlPath MakeRectLTRB(DlScalar left, DlScalar top, DlScalar right, DlScalar bottom)
Definition dl_path.cc:43
static DlPath MakeRectXYWH(DlScalar x, DlScalar y, DlScalar width, DlScalar height)
Definition dl_path.cc:50
Used for fixed refresh rate cases.
Definition stopwatch.h:80
const DlRect & paint_bounds() const
Definition layer.h:196
uint64_t unique_id() const
Definition layer.h:237
bool TryToPrepareRasterCache(const PaintContext &context, bool parent_cached=false) const override
size_t access_threshold() const
Return the number of frames that a picture must be prepared before it will be cached....
bool UpdateCacheEntry(const RasterCacheKeyID &id, const Context &raster_cache_context, const std::function< void(DlCanvas *)> &render_function, sk_sp< const DlRTree > rtree=nullptr) const
CacheState cache_state() const
const LayerRasterCacheItem * raster_cache_item() const
Definition mock_layer.h:164
void Preroll(PrerollContext *context) override
Definition mock_layer.cc:75
void AddMockLayer(int width, int height)
void AddMockPicture(int width, int height)
#define FML_DCHECK(condition)
Definition logging.h:122
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_
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 switch_defs.h:52
DlMatrix ToDlMatrix(const SkMatrix &matrix)
const SkRect & ToSkRect(const DlRect &rect)
int32_t height
int32_t width
sk_sp< SkColorSpace > dst_color_space
Definition layer.h:100
GrDirectContext * gr_context
Definition layer.h:47
sk_sp< SkColorSpace > dst_color_space
Definition layer.h:50
A 4x4 matrix using column-major storage.
Definition matrix.h:37
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129