Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
CanvasSaveRestoreBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "bench/Benchmark.h"
10
12public:
13 CanvasSaveRestoreBench(int depth) : fDepth(depth) {
14 fName.printf("canvas_save_restore_%d", fDepth);
15 }
16
17protected:
18 const char* onGetName() override { return fName.c_str(); }
19 bool isSuitableFor(Backend backend) override { return backend == Backend::kRaster; }
20 SkISize onGetSize() override { return { 1, 1 }; }
21
22 void onDraw(int loops, SkCanvas* canvas) override {
23 SkM44 m = SkM44::Rotate({0, 0, 1}, 1);
24
25 for (int i = 0; i < loops; ++i) {
26 for (int j = 0; j < fDepth; ++j) {
27 canvas->save();
28 canvas->concat(m);
29 }
31 for (int j = 0; j < fDepth; ++j) {
32 canvas->restore();
33 }
34 }
35 }
36
37private:
38 const int fDepth;
39 SkString fName;
40
41 using INHERITED = Benchmark;
42};
43
44// Performance remains roughly constant up to 32 (the number of preallocated save records).
45// After that, the cost of additional malloc/free calls starts to be measurable.
46DEF_BENCH( return new CanvasSaveRestoreBench(8);)
47DEF_BENCH( return new CanvasSaveRestoreBench(32);)
48DEF_BENCH( return new CanvasSaveRestoreBench(128);)
49DEF_BENCH( return new CanvasSaveRestoreBench(512);)
#define DEF_BENCH(code)
Definition Benchmark.h:20
const char * backend
const char * onGetName() override
bool isSuitableFor(Backend backend) override
void onDraw(int loops, SkCanvas *canvas) override
void restore()
Definition SkCanvas.cpp:465
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition SkCanvas.h:1182
int save()
Definition SkCanvas.cpp:451
void concat(const SkMatrix &matrix)
Definition SkM44.h:150
static SkM44 Rotate(SkV3 axis, SkScalar radians)
Definition SkM44.h:239
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:534
const char * c_str() const
Definition SkString.h:133
constexpr SkColor4f kCyan
Definition SkColor.h:444