Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit e38f624

Browse files
author
George Wright
committed
add DrawPath benchmark
1 parent 6fb2caf commit e38f624

File tree

1 file changed

+159
-59
lines changed

1 file changed

+159
-59
lines changed

flow/display_list_benchmarks.cc

Lines changed: 159 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -269,99 +269,199 @@ BENCHMARK_TEMPLATE(DrawCircle, MetalCanvasProvider)
269269
->UseRealTime()
270270
->Unit(benchmark::kMillisecond);
271271

272-
static SkRRect CreateSymmetricRRect(int width, int height) {
273-
SkScalar xRadius = width / 5.0f;
274-
SkScalar yRadius = height / 5.0f;
275-
return SkRRect::MakeRectXY(SkRect::MakeWH(width, height), xRadius, yRadius);
272+
// static SkRRect CreateSymmetricRRect(int width, int height) {
273+
// SkScalar xRadius = width / 5.0f;
274+
// SkScalar yRadius = height / 5.0f;
275+
// return SkRRect::MakeRectXY(SkRect::MakeWH(width, height), xRadius,
276+
// yRadius);
277+
// }
278+
279+
// static SkRRect CreateNinePatchRRect(int width, int height) {
280+
// SkScalar xRadius = width / 5.0f;
281+
// SkScalar yRadius = height / 5.0f;
282+
// return SkRRect::MakeRectXY(SkRect::MakeWH(width, height), xRadius,
283+
// yRadius);
284+
// }
285+
286+
// template <class T>
287+
// void DrawRRect(benchmark::State& state) {
288+
// DisplayListBuilder builder;
289+
// size_t length = state.range(0);
290+
// T canvas_provider(length, length);
291+
// auto canvas = canvas_provider.GetSurface()->getCanvas();
292+
293+
// float multiplier = length / 16;
294+
// SkVector radii[4];
295+
// switch (state.range(1)) {
296+
// // Symmetric in both x and y
297+
// case 0:
298+
// radii[0] = SkVector::Make(5.0f, 5.0f);
299+
// radii[1] = SkVector::Make(5.0f, 5.0f);
300+
// radii[2] = SkVector::Make(5.0f, 5.0f);
301+
// radii[3] = SkVector::Make(5.0f, 5.0f);
302+
// state.SetLabel("Symmetric");
303+
// break;
304+
// // "nine patch" type
305+
// case 1:
306+
// radii[0] = SkVector::Make(5.0f, 2.0f);
307+
// radii[1] = SkVector::Make(3.0f, 2.0f);
308+
// radii[2] = SkVector::Make(3.0f, 4.0f);
309+
// radii[3] = SkVector::Make(5.0f, 4.0f);
310+
// state.SetLabel("Nine patch");
311+
// break;
312+
// // Not symmetric at all
313+
// case 2:
314+
// radii[0] = SkVector::Make(5.0f, 4.0f);
315+
// radii[1] = SkVector::Make(4.0f, 5.0f);
316+
// radii[2] = SkVector::Make(3.0f, 6.0f);
317+
// radii[3] = SkVector::Make(2.0f, 7.0f);
318+
// state.SetLabel("Complex");
319+
// break;
320+
// }
321+
322+
// // The rects will shrink by the inset constant for each iteration. The
323+
// // inset constant is 0.5 to test non-axis-aligned rasterisation.
324+
// const SkScalar inset = 0.5;
325+
// SkRect rect = SkRect::MakeLTRB(0, 0, length, length);
326+
// SkRRect rrect;
327+
// SkVector setRadii[4];
328+
329+
// // Always draw 5000 rects regardless of the rect size requested
330+
// for (size_t i = 0; i < 15000; i++) {
331+
// for (int i = 0; i < 4; i++) {
332+
// setRadii[i] = radii[i] * multiplier;
333+
// }
334+
// // As rects have SkScalar dimensions, we want to ensure that we also
335+
// // draw non-axis-aligned rects with scalar position and size
336+
// rrect.setRectRadii(rect, setRadii);
337+
// builder.drawRRect(rrect);
338+
// rect.inset(inset, inset);
339+
// if (rect.width() == 0) {
340+
// rect = SkRect::MakeLTRB(0, 0, length, length);
341+
// }
342+
// multiplier = rrect.width() / 16.0f;
343+
// }
344+
345+
// auto displaylist = builder.Build();
346+
347+
// // We only want to time the actual rasterization.
348+
// for (auto _ : state) {
349+
// canvas->discard();
350+
// displaylist->RenderTo(canvas);
351+
// canvas_provider.GetSurface()->flushAndSubmit(true);
352+
// }
353+
354+
// auto filename = canvas_provider.BackendName() + "-DrawRRect-" +
355+
// std::to_string(state.range(0)) + ".png";
356+
// canvas_provider.Snapshot(filename);
357+
// }
358+
359+
// BENCHMARK_TEMPLATE(DrawRRect, SoftwareCanvasProvider)
360+
// // ->Args({16, 0})
361+
// // ->Args({16, 1})
362+
// // ->Args({16, 2})
363+
// // ->Args({128, 0})
364+
// // ->Args({128, 1})
365+
// // ->Args({128, 2})
366+
// // ->Args({512, 0})
367+
// // ->Args({512, 1})
368+
// // ->Args({512, 2})
369+
// ->Args({1024, 0})
370+
// ->Args({1024, 1})
371+
// ->Args({1024, 2})
372+
// ->Unit(benchmark::kMillisecond);
373+
374+
void GetLinesPath(SkPath& path, size_t length) {
375+
for (int i = 0; i < 100000; i++) {
376+
path.lineTo(i % length, 0);
377+
path.lineTo(length - i % length, length);
378+
}
379+
}
380+
381+
void GetQuadsPath(SkPath& path, size_t length) {
382+
for (int i = 0; i < 100000; i++) {
383+
path.quadTo(i % length, length / 2.0, i % length, 0);
384+
path.quadTo(i % length, length / 2.0, length - i % length, length);
385+
}
386+
}
387+
388+
void GetConicsPath(SkPath& path, size_t length) {
389+
for (int i = 0; i < 100000; i++) {
390+
path.conicTo(i % length, length / 2.0, i % length, 0, (SkScalar)i / length);
391+
path.conicTo(i % length, length / 2.0, length - i % length, length,
392+
(SkScalar)i / length);
393+
}
276394
}
277395

396+
void GetCubicsPath(SkPath& path, size_t length) {
397+
for (int i = 0; i < 100000; i++) {
398+
path.cubicTo(i / 3 % length, length / 3.0, (2 * i / 3) % length,
399+
length / 3.0 * 2.0, length - i % length, length);
400+
path.cubicTo(i / 3 % length, length / 3.0, (2 * i / 3) % length,
401+
length / 3.0 * 2.0, length - i % length, length);
402+
}
403+
}
278404

279405
template <class T>
280-
void DrawRRect(benchmark::State& state) {
406+
void DrawPath(benchmark::State& state) {
281407
DisplayListBuilder builder;
282408
size_t length = state.range(0);
283409
T canvas_provider(length, length);
284410
auto canvas = canvas_provider.GetSurface()->getCanvas();
285411

286-
float multiplier = length / 16;
287-
SkVector radii[4];
412+
SkPath path;
413+
builder.setAntiAlias(true);
414+
builder.setStyle(SkPaint::kStroke_Style);
415+
416+
std::string label;
417+
288418
switch (state.range(1)) {
289-
// Symmetric in both x and y
290419
case 0:
291-
radii[0] = SkVector::Make(5.0f, 5.0f);
292-
radii[1] = SkVector::Make(5.0f, 5.0f);
293-
radii[2] = SkVector::Make(5.0f, 5.0f);
294-
radii[3] = SkVector::Make(5.0f, 5.0f);
295-
state.SetLabel("Symmetric");
420+
GetLinesPath(path, length);
421+
label = "Lines";
296422
break;
297-
// "nine patch" type
298423
case 1:
299-
radii[0] = SkVector::Make(5.0f, 2.0f);
300-
radii[1] = SkVector::Make(3.0f, 2.0f);
301-
radii[2] = SkVector::Make(3.0f, 4.0f);
302-
radii[3] = SkVector::Make(5.0f, 4.0f);
303-
state.SetLabel("Nine patch");
424+
GetQuadsPath(path, length);
425+
label = "Quads";
304426
break;
305-
// Not symmetric at all
306427
case 2:
307-
radii[0] = SkVector::Make(5.0f, 4.0f);
308-
radii[1] = SkVector::Make(4.0f, 5.0f);
309-
radii[2] = SkVector::Make(3.0f, 6.0f);
310-
radii[3] = SkVector::Make(2.0f, 7.0f);
311-
state.SetLabel("Complex");
428+
GetConicsPath(path, length);
429+
label = "Conics";
430+
break;
431+
case 3:
432+
GetCubicsPath(path, length);
433+
label = "Cubics";
312434
break;
313435
}
314436

315-
// The rects will shrink by the inset constant for each iteration. The
316-
// inset constant is 0.5 to test non-axis-aligned rasterisation.
317-
const SkScalar inset = 0.5;
318-
SkRect rect = SkRect::MakeLTRB(0, 0, length, length);
319-
SkRRect rrect;
320-
SkVector setRadii[4];
321-
322-
// Always draw 5000 rects regardless of the rect size requested
323-
for (size_t i = 0; i < 15000; i++) {
324-
for (int i = 0; i < 4; i++) {
325-
setRadii[i] = radii[i] * multiplier;
326-
}
327-
// As rects have SkScalar dimensions, we want to ensure that we also
328-
// draw non-axis-aligned rects with scalar position and size
329-
rrect.setRectRadii(rect, setRadii);
330-
builder.drawRRect(rrect);
331-
rect.inset(inset, inset);
332-
if (rect.width() == 0) {
333-
rect = SkRect::MakeLTRB(0, 0, length, length);
334-
}
335-
multiplier = rrect.width() / 16.0f;
336-
}
437+
state.SetLabel(label);
337438

439+
builder.drawPath(path);
338440
auto displaylist = builder.Build();
339441

340442
// We only want to time the actual rasterization.
341443
for (auto _ : state) {
342-
canvas->discard();
343444
displaylist->RenderTo(canvas);
344445
canvas_provider.GetSurface()->flushAndSubmit(true);
345446
}
346447

347-
auto filename = canvas_provider.BackendName() + "-DrawRRect-" +
448+
auto filename = canvas_provider.BackendName() + "-DrawPath-" + label + "-" +
348449
std::to_string(state.range(0)) + ".png";
349450
canvas_provider.Snapshot(filename);
350451
}
351452

352-
BENCHMARK_TEMPLATE(DrawRRect, SoftwareCanvasProvider)
353-
// ->Args({16, 0})
354-
// ->Args({16, 1})
355-
// ->Args({16, 2})
356-
// ->Args({128, 0})
357-
// ->Args({128, 1})
358-
// ->Args({128, 2})
359-
// ->Args({512, 0})
360-
// ->Args({512, 1})
361-
// ->Args({512, 2})
453+
BENCHMARK_TEMPLATE(DrawPath, SoftwareCanvasProvider)
454+
->Args({1024, 0})
455+
->Args({1024, 1})
456+
->Args({1024, 2})
457+
->Args({1024, 3})
458+
->Unit(benchmark::kMillisecond);
459+
460+
BENCHMARK_TEMPLATE(DrawPath, MetalCanvasProvider)
362461
->Args({1024, 0})
363462
->Args({1024, 1})
364463
->Args({1024, 2})
464+
->Args({1024, 3})
365465
->Unit(benchmark::kMillisecond);
366466

367467
} // namespace testing

0 commit comments

Comments
 (0)