Flutter Engine
The Flutter Engine
dl_builder_benchmarks.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/benchmarking/benchmarking.h"
6#include "flutter/display_list/testing/dl_test_snippets.h"
7
8namespace flutter {
9
11 return builder.asReceiver();
12}
13
14namespace {
15
16static std::vector<testing::DisplayListInvocationGroup> allRenderingOps =
18
19enum class DisplayListBuilderBenchmarkType {
21 kBounds,
22 kRtree,
23 kBoundsAndRtree,
24};
25
26static void InvokeAllRenderingOps(DisplayListBuilder& builder) {
27 DlOpReceiver& receiver = DisplayListBuilderBenchmarkAccessor(builder);
28 for (auto& group : allRenderingOps) {
29 for (size_t i = 0; i < group.variants.size(); i++) {
30 auto& invocation = group.variants[i];
31 invocation.Invoke(receiver);
32 }
33 }
34}
35
36static void Complete(DisplayListBuilder& builder,
37 DisplayListBuilderBenchmarkType type) {
38 auto display_list = builder.Build();
39 switch (type) {
40 case DisplayListBuilderBenchmarkType::kBounds:
41 display_list->bounds();
42 break;
43 case DisplayListBuilderBenchmarkType::kRtree:
44 display_list->rtree();
45 break;
46 case DisplayListBuilderBenchmarkType::kBoundsAndRtree:
47 display_list->bounds();
48 display_list->rtree();
49 break;
51 break;
52 }
53}
54
55bool NeedPrepareRTree(DisplayListBuilderBenchmarkType type) {
56 return type == DisplayListBuilderBenchmarkType::kRtree ||
57 type == DisplayListBuilderBenchmarkType::kBoundsAndRtree;
58}
59
60} // namespace
61
63 DisplayListBuilderBenchmarkType type) {
64 bool prepare_rtree = NeedPrepareRTree(type);
65 while (state.KeepRunning()) {
66 DisplayListBuilder builder(prepare_rtree);
67 InvokeAllRenderingOps(builder);
68 Complete(builder, type);
69 }
70}
71
74 DisplayListBuilderBenchmarkType type) {
75 bool prepare_rtree = NeedPrepareRTree(type);
76 while (state.KeepRunning()) {
77 DisplayListBuilder builder(prepare_rtree);
78 builder.Scale(3.5, 3.5);
79 builder.Translate(10.3, 6.9);
80 InvokeAllRenderingOps(builder);
81 Complete(builder, type);
82 }
83}
84
87 DisplayListBuilderBenchmarkType type) {
88 bool prepare_rtree = NeedPrepareRTree(type);
89 while (state.KeepRunning()) {
90 DisplayListBuilder builder(prepare_rtree);
91 builder.TransformFullPerspective(0, 1, 0, 12, 1, 0, 0, 33, 3, 2, 5, 29, 0,
92 0, 0, 12);
93 InvokeAllRenderingOps(builder);
94 Complete(builder, type);
95 }
96}
97
100 DisplayListBuilderBenchmarkType type) {
101 SkRect clip_bounds = SkRect::MakeLTRB(6.5, 7.3, 90.2, 85.7);
102 bool prepare_rtree = NeedPrepareRTree(type);
103 while (state.KeepRunning()) {
104 DisplayListBuilder builder(prepare_rtree);
105 builder.ClipRect(clip_bounds, DlCanvas::ClipOp::kIntersect, true);
106 InvokeAllRenderingOps(builder);
107 Complete(builder, type);
108 }
109}
110
113 DisplayListBuilderBenchmarkType type) {
114 bool prepare_rtree = NeedPrepareRTree(type);
115 while (state.KeepRunning()) {
116 DisplayListBuilder builder(prepare_rtree);
117 builder.Scale(3.5, 3.5);
118 builder.Translate(10.3, 6.9);
119 builder.SaveLayer(nullptr, nullptr);
120 builder.Translate(45.3, 27.9);
122 for (auto& group : allRenderingOps) {
123 for (size_t i = 0; i < group.variants.size(); i++) {
124 auto& invocation = group.variants[i];
125 invocation.Invoke(receiver);
126 }
127 }
128 builder.Restore();
129 Complete(builder, type);
130 }
131}
132
135 DisplayListBuilderBenchmarkType type) {
136 bool prepare_rtree = NeedPrepareRTree(type);
137 while (state.KeepRunning()) {
138 DisplayListBuilder builder(prepare_rtree);
140 for (auto& group : allRenderingOps) {
141 for (size_t i = 0; i < group.variants.size(); i++) {
142 auto& invocation = group.variants[i];
143 builder.SaveLayer(nullptr, nullptr);
144 invocation.Invoke(receiver);
145 builder.Restore();
146 }
147 }
148 Complete(builder, type);
149 }
150}
151
154 DisplayListBuilderBenchmarkType type) {
155 DlPaint layer_paint;
157 SkRect layer_bounds = SkRect::MakeLTRB(6.5, 7.3, 35.2, 42.7);
158 bool prepare_rtree = NeedPrepareRTree(type);
159 while (state.KeepRunning()) {
160 DisplayListBuilder builder(prepare_rtree);
162 for (auto& group : allRenderingOps) {
163 for (size_t i = 0; i < group.variants.size(); i++) {
164 auto& invocation = group.variants[i];
165 builder.SaveLayer(&layer_bounds, &layer_paint);
166 invocation.Invoke(receiver);
167 builder.Restore();
168 }
169 }
170 Complete(builder, type);
171 }
172}
173
175 kDefault,
177 ->Unit(benchmark::kMicrosecond);
179 kBounds,
180 DisplayListBuilderBenchmarkType::kBounds)
181 ->Unit(benchmark::kMicrosecond);
183 kRtree,
184 DisplayListBuilderBenchmarkType::kRtree)
185 ->Unit(benchmark::kMicrosecond);
187 kBoundsAndRtree,
188 DisplayListBuilderBenchmarkType::kBoundsAndRtree)
189 ->Unit(benchmark::kMicrosecond);
190
192 kDefault,
194 ->Unit(benchmark::kMicrosecond);
196 kBounds,
197 DisplayListBuilderBenchmarkType::kBounds)
198 ->Unit(benchmark::kMicrosecond);
200 kRtree,
201 DisplayListBuilderBenchmarkType::kRtree)
202 ->Unit(benchmark::kMicrosecond);
204 kBoundsAndRtree,
205 DisplayListBuilderBenchmarkType::kBoundsAndRtree)
206 ->Unit(benchmark::kMicrosecond);
207
209 kDefault,
211 ->Unit(benchmark::kMicrosecond);
213 kBounds,
214 DisplayListBuilderBenchmarkType::kBounds)
215 ->Unit(benchmark::kMicrosecond);
217 kRtree,
218 DisplayListBuilderBenchmarkType::kRtree)
219 ->Unit(benchmark::kMicrosecond);
221 kBoundsAndRtree,
222 DisplayListBuilderBenchmarkType::kBoundsAndRtree)
223 ->Unit(benchmark::kMicrosecond);
224
226 kDefault,
228 ->Unit(benchmark::kMicrosecond);
230 kBounds,
231 DisplayListBuilderBenchmarkType::kBounds)
232 ->Unit(benchmark::kMicrosecond);
234 kRtree,
235 DisplayListBuilderBenchmarkType::kRtree)
236 ->Unit(benchmark::kMicrosecond);
238 kBoundsAndRtree,
239 DisplayListBuilderBenchmarkType::kBoundsAndRtree)
240 ->Unit(benchmark::kMicrosecond);
241
243 kDefault,
245 ->Unit(benchmark::kMicrosecond);
247 kBounds,
248 DisplayListBuilderBenchmarkType::kBounds)
249 ->Unit(benchmark::kMicrosecond);
251 kRtree,
252 DisplayListBuilderBenchmarkType::kRtree)
253 ->Unit(benchmark::kMicrosecond);
255 kBoundsAndRtree,
256 DisplayListBuilderBenchmarkType::kBoundsAndRtree)
257 ->Unit(benchmark::kMicrosecond);
258
260 kDefault,
262 ->Unit(benchmark::kMicrosecond);
264 kBounds,
265 DisplayListBuilderBenchmarkType::kBounds)
266 ->Unit(benchmark::kMicrosecond);
268 kRtree,
269 DisplayListBuilderBenchmarkType::kRtree)
270 ->Unit(benchmark::kMicrosecond);
272 kBoundsAndRtree,
273 DisplayListBuilderBenchmarkType::kBoundsAndRtree)
274 ->Unit(benchmark::kMicrosecond);
275
277 kDefault,
279 ->Unit(benchmark::kMicrosecond);
281 kBounds,
282 DisplayListBuilderBenchmarkType::kBounds)
283 ->Unit(benchmark::kMicrosecond);
285 kRtree,
286 DisplayListBuilderBenchmarkType::kRtree)
287 ->Unit(benchmark::kMicrosecond);
289 kBoundsAndRtree,
290 DisplayListBuilderBenchmarkType::kBoundsAndRtree)
291 ->Unit(benchmark::kMicrosecond);
292
293} // namespace flutter
GLenum type
Internal API for rendering recorded display lists to backends.
DlPaint & setImageFilter(const std::shared_ptr< const DlImageFilter > &filter)
Definition: dl_paint.h:157
AtkStateType state
@ kDefault
std::vector< DisplayListInvocationGroup > CreateAllRenderingOps()
static const DlBlurImageFilter kTestBlurImageFilter1(5.0, 5.0, DlTileMode::kClamp)
static void BM_DisplayListBuilderWithScaleAndTranslate(benchmark::State &state, DisplayListBuilderBenchmarkType type)
static void BM_DisplayListBuilderWithSaveLayer(benchmark::State &state, DisplayListBuilderBenchmarkType type)
static void BM_DisplayListBuilderDefault(benchmark::State &state, DisplayListBuilderBenchmarkType type)
static void BM_DisplayListBuilderWithClipRect(benchmark::State &state, DisplayListBuilderBenchmarkType type)
BENCHMARK_CAPTURE(BM_DisplayListBuilderDefault, kDefault, DisplayListBuilderBenchmarkType::kDefault) -> Unit(benchmark::kMicrosecond)
DlOpReceiver & DisplayListBuilderBenchmarkAccessor(DisplayListBuilder &builder)
static void BM_DisplayListBuilderWithSaveLayerAndImageFilter(benchmark::State &state, DisplayListBuilderBenchmarkType type)
static void BM_DisplayListBuilderWithGlobalSaveLayer(benchmark::State &state, DisplayListBuilderBenchmarkType type)
static void BM_DisplayListBuilderWithPerspective(benchmark::State &state, DisplayListBuilderBenchmarkType type)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646