1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
// A benchmark designed to isolate the constant overheads of picture recording.
// We record an empty picture and a picture with one draw op to force memory allocation.
#include "Benchmark.h"
#include "SkCanvas.h"
#include "SkLiteDL.h"
#include "SkLiteRecorder.h"
#include "SkPictureRecorder.h"
template <int kDraws, bool kLite>
struct PictureOverheadBench : public Benchmark {
PictureOverheadBench() {
fName.appendf("picture_overhead_%d%s", kDraws, kLite ? "_lite" : "");
}
const char* onGetName() override { return fName.c_str(); }
bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
void onDraw(int loops, SkCanvas*) override {
SkLiteRecorder lite;
SkPictureRecorder rec;
SkIRect iBounds = {0,0, 2000,3000};
SkRect bounds = SkRect::Make(iBounds);
for (int i = 0; i < loops; i++) {
SkLiteDL liteDL;
SkCanvas* canvas;
if (kLite) {
lite.reset(&liteDL, iBounds);
canvas = &lite;
} else {
rec.beginRecording(bounds);
canvas = rec.getRecordingCanvas();
}
for (int i = 0; i < kDraws; i++) {
canvas->drawRect({10,10, 1000, 1000}, SkPaint{});
}
if (!kLite) {
(void)rec.finishRecordingAsPicture();
}
}
}
SkString fName;
};
DEF_BENCH(return (new PictureOverheadBench<0, false>);)
DEF_BENCH(return (new PictureOverheadBench<1, false>);)
DEF_BENCH(return (new PictureOverheadBench<2, false>);)
DEF_BENCH(return (new PictureOverheadBench<10,false>);)
DEF_BENCH(return (new PictureOverheadBench<0, true>);)
DEF_BENCH(return (new PictureOverheadBench<1, true>);)
DEF_BENCH(return (new PictureOverheadBench<2, true>);)
DEF_BENCH(return (new PictureOverheadBench<10, true>);)
///////////////////////////////////////////////////////////////////////////////////////////////////
class ClipOverheadRecordingBench : public Benchmark {
SkString fName;
const bool fDoLite;
public:
ClipOverheadRecordingBench(bool doLite) : fDoLite(doLite) {
fName.printf("clip_overhead_recording_%s", doLite ? "lite" : "std");
}
protected:
const char* onGetName() override { return fName.c_str(); }
bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
void onDraw(int loops, SkCanvas*) override {
SkLiteRecorder lite;
SkPictureRecorder rec;
SkIRect iBounds = {0,0, 2000,3000};
SkRect bounds = SkRect::Make(iBounds);
for (int i = 0; i < loops; i++) {
SkLiteDL liteDL;
SkCanvas* canvas;
if (fDoLite) {
lite.reset(&liteDL, iBounds);
canvas = &lite;
} else {
rec.beginRecording(bounds);
canvas = rec.getRecordingCanvas();
}
SkPaint paint;
SkRRect rrect;
rrect.setOval({0, 0, 1000, 1000});
for (int i = 0; i < 1000; i++) {
canvas->save();
canvas->translate(10, 10);
canvas->clipRect({10,10, 1000, 1000});
canvas->drawRRect(rrect, paint);
canvas->restore();
}
if (!fDoLite) {
(void)rec.finishRecordingAsPicture();
}
}
}
};
DEF_BENCH( return new ClipOverheadRecordingBench(true); )
DEF_BENCH( return new ClipOverheadRecordingBench(false); )
|