Flutter Engine
The 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
5#include "flutter/flow/testing/mock_raster_cache.h"
6
7#include "flutter/flow/layers/display_list_raster_cache_item.h"
8#include "flutter/flow/layers/layer.h"
9#include "flutter/flow/raster_cache.h"
10#include "flutter/flow/raster_cache_item.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();
23 path.addRect(100, 100, 100 + width, 100 + height);
24 int layer_cached_threshold = 1;
25 MockCacheableLayer layer =
26 MockCacheableLayer(path, DlPaint(), layer_cached_threshold);
27 layer.Preroll(&preroll_context_);
28 layer.raster_cache_item()->TryToPrepareRasterCache(paint_context_);
29 RasterCache::Context r_context = {
30 // clang-format off
31 .gr_context = preroll_context_.gr_context,
32 .dst_color_space = preroll_context_.dst_color_space,
33 .matrix = ctm,
34 .logical_rect = layer.paint_bounds(),
35 // clang-format on
36 };
39 r_context, [&](DlCanvas* canvas) {
40 SkRect cache_rect = RasterCacheUtil::GetDeviceBounds(
41 r_context.logical_rect, r_context.matrix);
42 return std::make_unique<MockRasterCacheResult>(cache_rect);
43 });
44}
45
48 SkMatrix ctm = SkMatrix::I();
49 DisplayListBuilder builder(SkRect::MakeLTRB(0, 0, 200 + width, 200 + height));
51 path.addRect(100, 100, 100 + width, 100 + height);
52 builder.DrawPath(path, DlPaint());
53 sk_sp<DisplayList> display_list = builder.Build();
54
55 FixedRefreshRateStopwatch raster_time;
57 LayerStateStack state_stack;
58 PaintContextHolder holder =
59 GetSamplePaintContextHolder(state_stack, this, &raster_time, &ui_time);
60 holder.paint_context.dst_color_space = color_space_;
61
62 DisplayListRasterCacheItem display_list_item(display_list, SkPoint(), true,
63 false);
64 for (size_t i = 0; i < access_threshold(); i++) {
65 AutoCache(&display_list_item, &preroll_context_, ctm);
66 }
67 RasterCache::Context r_context = {
68 // clang-format off
69 .gr_context = preroll_context_.gr_context,
70 .dst_color_space = preroll_context_.dst_color_space,
71 .matrix = ctm,
72 .logical_rect = display_list->bounds(),
73 // clang-format on
74 };
75 UpdateCacheEntry(RasterCacheKeyID(display_list->unique_id(),
77 r_context, [&](DlCanvas* canvas) {
78 SkRect cache_rect = RasterCacheUtil::GetDeviceBounds(
79 r_context.logical_rect, r_context.matrix);
80 return std::make_unique<MockRasterCacheResult>(cache_rect);
81 });
82}
83
85 LayerStateStack& state_stack,
86 RasterCache* raster_cache,
87 FixedRefreshRateStopwatch* raster_time,
90
91 PrerollContextHolder holder = {
92 {
93 // clang-format off
94 .raster_cache = raster_cache,
95 .gr_context = nullptr,
96 .view_embedder = nullptr,
97 .state_stack = state_stack,
98 .dst_color_space = srgb,
99 .surface_needs_readback = false,
100 .raster_time = *raster_time,
101 .ui_time = *ui_time,
102 .texture_registry = nullptr,
103 .has_platform_view = false,
104 .has_texture_layer = false,
105 .raster_cached_entries = &raster_cache_items_,
106 // clang-format on
107 },
108 srgb};
109
110 return holder;
111}
112
114 LayerStateStack& state_stack,
115 RasterCache* raster_cache,
116 FixedRefreshRateStopwatch* raster_time,
117 FixedRefreshRateStopwatch* ui_time) {
119 PaintContextHolder holder = {// clang-format off
120 {
121 .state_stack = state_stack,
122 .canvas = nullptr,
123 .gr_context = nullptr,
124 .dst_color_space = srgb,
125 .view_embedder = nullptr,
126 .raster_time = *raster_time,
127 .ui_time = *ui_time,
128 .texture_registry = nullptr,
129 .raster_cache = raster_cache,
130 },
131 // clang-format on
132 srgb};
133
134 return holder;
135}
136
138 DisplayListRasterCacheItem& display_list_item,
139 PrerollContext& context,
140 PaintContext& paint_context,
141 const SkMatrix& matrix) {
142 RasterCacheItemPreroll(display_list_item, context, matrix);
144 return RasterCacheItemTryToRasterCache(display_list_item, paint_context);
145}
146
148 PrerollContext& context,
149 const SkMatrix& matrix) {
150 display_list_item.PrerollSetup(&context, matrix);
151 display_list_item.PrerollFinalize(&context, matrix);
152}
153
155 DisplayListRasterCacheItem& display_list_item,
156 PaintContext& paint_context) {
157 if (display_list_item.cache_state() ==
159 return display_list_item.TryToPrepareRasterCache(paint_context);
160 }
161 return false;
162}
163
164} // namespace testing
165} // namespace flutter
static sk_sp< SkColorSpace > MakeSRGB()
static const SkMatrix & I()
SkPath & addRect(const SkRect &rect, SkPathDirection dir, unsigned start)
Definition SkPath.cpp:854
bool TryToPrepareRasterCache(const PaintContext &context, bool parent_cached=false) const override
void PrerollSetup(PrerollContext *context, const SkMatrix &matrix) override
void PrerollFinalize(PrerollContext *context, const SkMatrix &matrix) override
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:37
Used for fixed refresh rate cases.
Definition stopwatch.h:77
bool TryToPrepareRasterCache(const PaintContext &context, bool parent_cached=false) const override
const SkRect & paint_bounds() const
Definition layer.h:209
uint64_t unique_id() const
Definition layer.h:250
CacheState cache_state() const
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
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:103
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_
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 switches.h:57
int32_t height
int32_t width
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646
sk_sp< SkColorSpace > dst_color_space
Definition layer.h:109
GrDirectContext * gr_context
Definition layer.h:56
sk_sp< SkColorSpace > dst_color_space
Definition layer.h:59
RasterCache * raster_cache
Definition layer.h:55