Flutter Engine
The Flutter Engine
canvas_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
8
9namespace impeller {
10
11namespace {
12
13using CanvasCallback = size_t (*)(Canvas&);
14
15size_t DrawRect(Canvas& canvas) {
16 for (auto i = 0; i < 500; i++) {
17 canvas.DrawRect(Rect::MakeLTRB(0, 0, 100, 100),
18 {.color = Color::DarkKhaki()});
19 }
20 return 500;
21}
22
23size_t DrawCircle(Canvas& canvas) {
24 for (auto i = 0; i < 500; i++) {
25 canvas.DrawCircle({100, 100}, 5, {.color = Color::DarkKhaki()});
26 }
27 return 500;
28}
29
30size_t DrawLine(Canvas& canvas) {
31 for (auto i = 0; i < 500; i++) {
32 canvas.DrawLine({0, 0}, {100, 100}, {.color = Color::DarkKhaki()});
33 }
34 return 500;
35}
36} // namespace
37
38// A set of benchmarks that measures the CPU cost of encoding canvas operations.
39// These benchmarks do not measure the cost of conversion through the HAL, no
40// do they measure the GPU side cost of executing the required shader programs.
41template <class... Args>
42static void BM_CanvasRecord(benchmark::State& state, Args&&... args) {
43 auto args_tuple = std::make_tuple(std::move(args)...);
44 auto test_proc = std::get<CanvasCallback>(args_tuple);
45
46 size_t op_count = 0u;
47 size_t canvas_count = 0u;
48 while (state.KeepRunning()) {
49 // A new canvas is allocated for each iteration to avoid the benchmark
50 // becoming a measurement of only the entity vector re-allocation time.
51 Canvas canvas;
52 op_count += test_proc(canvas);
53 canvas_count++;
54 }
55 state.counters["TotalOpCount"] = op_count;
56 state.counters["TotalCanvasCount"] = canvas_count;
57}
58
60BENCHMARK_CAPTURE(BM_CanvasRecord, draw_circle, &DrawCircle);
62
63} // namespace impeller
static void test_proc(skiatest::Reporter *reporter, void(*proc)(skiatest::Reporter *, const SkRegion &a, const SkRegion &))
Definition: RegionTest.cpp:205
AtkStateType state
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static void draw_line(SkCanvas *canvas, SkImage *, const SkRect &r, sk_sp< SkImageFilter > imf)
BENCHMARK_CAPTURE(BM_CanvasRecord, draw_rect, &DrawRect)
static void BM_CanvasRecord(benchmark::State &state, Args &&... args)
static void draw_rect(SkCanvas *canvas, const SkRect &r, const SkPaint &p)
static constexpr Color DarkKhaki()
Definition: color.h:384
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition: rect.h:129