Debian Codegraph @

bench/DecodeBench.cpp

raw
1 /*
2 * Copyright 2016 Google Inc.
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"
9 #include "include/core/SkBitmap.h"
10 #include "include/core/SkFontMgr.h"
11 #include "include/core/SkPicture.h"
12 #include "include/core/SkPictureRecorder.h"
13 #include "modules/skottie/include/Skottie.h"
14 #include "tools/DecodeUtils.h"
15 #include "tools/Resources.h"
16 #include "tools/fonts/FontToolUtils.h"
17
18 class DecodeBench : public Benchmark {
19 protected:
20 DecodeBench(const char* name, const char* source)
21 : fName(SkStringPrintf("decode_%s", name))
22 , fSource(source)
23 {}
24
25 bool isSuitableFor(Backend backend) final {
26 return backend == Backend::kNonRendering;
27 }
28
29 const char* onGetName() final { return fName.c_str(); }
30
31 void onDelayedSetup() override {
32 fData = GetResourceAsData(fSource);
33 SkASSERT(fData);
34 }
35
36 protected:
37 sk_sp<SkData> fData;
38
39 private:
40 const SkString fName;
41 const char* fSource;
42 };
43
44 class BitmapDecodeBench final : public DecodeBench {
45 public:
46 BitmapDecodeBench(const char* name, const char* source)
47 : INHERITED(name, source)
48 {}
49
50 void onDraw(int loops, SkCanvas*) override {
51 while (loops-- > 0) {
52 SkBitmap bm;
53 SkAssertResult(ToolUtils::DecodeDataToBitmap(fData, &bm));
54 }
55 }
56
57 private:
58 using INHERITED = DecodeBench;
59 };
60
61
62 class SkottieDecodeBench final : public DecodeBench {
63 public:
64 SkottieDecodeBench(const char* name, const char* source)
65 : INHERITED(name, source)
66 {}
67
68 void onDraw(int loops, SkCanvas*) override {
69 while (loops-- > 0) {
70 const auto anim = skottie::Animation::Builder()
71 .setFontManager(ToolUtils::TestFontMgr())
72 .make(reinterpret_cast<const char*>(fData->data()),
73 fData->size());
74 }
75 }
76
77 private:
78 using INHERITED = DecodeBench;
79 };
80
81 class SkottiePictureDecodeBench final : public DecodeBench {
82 public:
83 SkottiePictureDecodeBench(const char* name, const char* source)
84 : INHERITED(name, source)
85 {}
86
87 void onDraw(int loops, SkCanvas*) override {
88 while (loops-- > 0) {
89 const auto anim = skottie::Animation::Builder()
90 .setFontManager(ToolUtils::TestFontMgr())
91 .make(reinterpret_cast<const char*>(fData->data()),
92 fData->size());
93 SkPictureRecorder recorder;
94 anim->seek(0);
95 anim->render(recorder.beginRecording(anim->size().width(), anim->size().height()));
96
97 const auto pic = recorder.finishRecordingAsPicture();
98 }
99 }
100
101 private:
102 using INHERITED = DecodeBench;
103 };
104
105 DEF_BENCH(return new SkottieDecodeBench("skottie_large", // 426593
106 "skottie/skottie-text-scale-to-fit-minmax.json"))
107 DEF_BENCH(return new SkottieDecodeBench("skottie_medium", // 10947
108 "skottie/skottie-sphere-effect.json"))
109 DEF_BENCH(return new SkottieDecodeBench("skottie_small", // 1112
110 "skottie/skottie_sample_multiframe.json"))
111 // Created from PhoneHub assets SVG source, with https://lottiefiles.com/svg-to-lottie
112 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_connecting.json", // 216x216
113 "skottie/skottie-phonehub-connecting.json"))
114 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_generic_error.json", // 216x217
115 "skottie/skottie-phonehub-generic-error.json"))
116 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_onboard.json", // 217x217
117 "skottie/skottie-phonehub-onboard.json"))
118 // Created from PhoneHub assets SVG source, with https://jakearchibald.github.io/svgomg/ and then
119 // https://lottiefiles.com/svg-to-lottie
120 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_connecting.json",
121 "skottie/skottie-phonehub-svgo-connecting.json"))
122 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_generic_error.json",
123 "skottie/skottie-phonehub-svgo-generic-error.json"))
124 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_onboard.json",
125 "skottie/skottie-phonehub-svgo-onboard.json"))
126 // Created from PhoneHub assets SVG source:
127 // 1. Manually edited to have no masks (but look the same as the original)
128 // 2. https://jakearchibald.github.io/svgomg/
129 // 3. https://lottiefiles.com/svg-to-lottie
130 // Note: The Generic Error asset is excluded here because it has no masks in the first place.
131 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_no_masks_connecting.json",
132 "skottie/skottie-phonehub-svgo-no-masks-connecting.json"))
133 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_no_masks_onboard.json",
134 "skottie/skottie-phonehub-svgo-no-masks-onboard.json"))
135 // Created from PhoneHub assets SVG source:
136 // 1. Manually edited to use only the most basic functionality of SVG (but look the same as the
137 // original)
138 // 2. https://jakearchibald.github.io/svgomg/
139 // 3. https://lottiefiles.com/svg-to-lottie
140 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_no_frills_connecting.json",
141 "skottie/skottie-phonehub-svgo-no-frills-connecting.json"))
142 DEF_BENCH(return new SkottieDecodeBench(
143 "skottie_phonehub_svgo_no_frills_generic_error.json",
144 "skottie/skottie-phonehub-svgo-no-frills-generic-error.json"))
145 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_no_frills_onboard.json",
146 "skottie/skottie-phonehub-svgo-no-frills-onboard.json"))
147 // All of the above PhoneHub benchmarks, with https://skia-review.googlesource.com/c/skia/+/141265
148 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_connecting_min.json",
149 "skottie/skottie-phonehub-connecting_min.json"))
150 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_generic_error_min.json",
151 "skottie/skottie-phonehub-generic-error_min.json"))
152 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_onboard_min.json",
153 "skottie/skottie-phonehub-onboard_min.json"))
154 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_connecting_min.json",
155 "skottie/skottie-phonehub-svgo-connecting_min.json"))
156 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_generic_error_min.json",
157 "skottie/skottie-phonehub-svgo-generic-error_min.json"))
158 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_onboard_min.json",
159 "skottie/skottie-phonehub-svgo-onboard_min.json"))
160 DEF_BENCH(return new SkottieDecodeBench(
161 "skottie_phonehub_svgo_no_masks_connecting_min.json",
162 "skottie/skottie-phonehub-svgo-no-masks-connecting_min.json"))
163 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_no_masks_onboard_min.json",
164 "skottie/skottie-phonehub-svgo-no-masks-onboard_min.json"))
165 DEF_BENCH(return new SkottieDecodeBench(
166 "skottie_phonehub_svgo_no_frills_connecting_min.json",
167 "skottie/skottie-phonehub-svgo-no-frills-connecting_min.json"))
168 DEF_BENCH(return new SkottieDecodeBench(
169 "skottie_phonehub_svgo_no_frills_generic_error_min.json",
170 "skottie/skottie-phonehub-svgo-no-frills-generic-error_min.json"))
171 DEF_BENCH(
172 return new SkottieDecodeBench("skottie_phonehub_svgo_no_frills_onboard_min.json",
173 "skottie/skottie-phonehub-svgo-no-frills-onboard_min.json"))
174
175 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_large",
176 "skottie/skottie-text-scale-to-fit-minmax.json"))
177 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_medium",
178 "skottie/skottie-sphere-effect.json"))
179 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_small",
180 "skottie/skottie_sample_multiframe.json"))
181 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_connecting.json",
182 "skottie/skottie-phonehub-connecting.json"))
183 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_generic_error.json",
184 "skottie/skottie-phonehub-generic-error.json"))
185 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_onboard.json",
186 "skottie/skottie-phonehub-onboard.json"))
187 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_svgo_connecting.json",
188 "skottie/skottie-phonehub-svgo-connecting.json"))
189 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_svgo_generic_error.json",
190 "skottie/skottie-phonehub-svgo-generic-error.json"))
191 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_svgo_onboard.json",
192 "skottie/skottie-phonehub-svgo-onboard.json"))
193 DEF_BENCH(return new SkottiePictureDecodeBench(
194 "skottiepic_phonehub_svgo_no_masks_connecting.json",
195 "skottie/skottie-phonehub-svgo-no-masks-connecting.json"))
196 DEF_BENCH(return new SkottiePictureDecodeBench(
197 "skottiepic_phonehub_svgo_no_masks_onboard.json",
198 "skottie/skottie-phonehub-svgo-no-masks-onboard.json"))
199 DEF_BENCH(return new SkottiePictureDecodeBench(
200 "skottiepic_phonehub_svgo_no_frills_connecting.json",
201 "skottie/skottie-phonehub-svgo-no-frills-connecting.json"))
202 DEF_BENCH(return new SkottiePictureDecodeBench(
203 "skottiepic_phonehub_svgo_no_frills_generic_error.json",
204 "skottie/skottie-phonehub-svgo-no-frills-generic-error.json"))
205 DEF_BENCH(return new SkottiePictureDecodeBench(
206 "skottiepic_phonehub_svgo_no_frills_onboard.json",
207 "skottie/skottie-phonehub-svgo-no-frills-onboard.json"))
208 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_connecting_min.json",
209 "skottie/skottie-phonehub-connecting_min.json"))
210 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_generic_error_min.json",
211 "skottie/skottie-phonehub-generic-error_min.json"))
212 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_onboard_min.json",
213 "skottie/skottie-phonehub-onboard_min.json"))
214 DEF_BENCH(
215 return new SkottiePictureDecodeBench("skottiepic_phonehub_svgo_connecting_min.json",
216 "skottie/skottie-phonehub-svgo-connecting_min.json"))
217 DEF_BENCH(return new SkottiePictureDecodeBench(
218 "skottiepic_phonehub_svgo_generic_error_min.json",
219 "skottie/skottie-phonehub-svgo-generic-error_min.json"))
220 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_svgo_onboard_min.json",
221 "skottie/skottie-phonehub-svgo-onboard_min.json"))
222 DEF_BENCH(return new SkottiePictureDecodeBench(
223 "skottiepic_phonehub_svgo_no_masks_connecting_min.json",
224 "skottie/skottie-phonehub-svgo-no-masks-connecting_min.json"))
225 DEF_BENCH(return new SkottiePictureDecodeBench(
226 "skottiepic_phonehub_svgo_no_masks_onboard_min.json",
227 "skottie/skottie-phonehub-svgo-no-masks-onboard_min.json"))
228 DEF_BENCH(return new SkottiePictureDecodeBench(
229 "skottiepic_phonehub_svgo_no_frills_connecting_min.json",
230 "skottie/skottie-phonehub-svgo-no-frills-connecting_min.json"))
231 DEF_BENCH(return new SkottiePictureDecodeBench(
232 "skottiepic_phonehub_svgo_no_frills_generic_error_min.json",
233 "skottie/skottie-phonehub-svgo-no-frills-generic-error_min.json"))
234 DEF_BENCH(return new SkottiePictureDecodeBench(
235 "skottiepic_phonehub_svgo_no_frills_onboard_min.json",
236 "skottie/skottie-phonehub-svgo-no-frills-onboard_min.json"))
237
238 DEF_BENCH(return new BitmapDecodeBench("png_large" /*1600x1600*/, "images/mandrill_1600.png"))
239 DEF_BENCH(return new BitmapDecodeBench("png_medium" /* 512x 512*/, "images/mandrill_512.png"))
240 DEF_BENCH(return new BitmapDecodeBench("png_small" /* 32x 32*/, "images/mandrill_32.png"))
241 DEF_BENCH(return new BitmapDecodeBench("png_phonehub_connecting" , "images/Connecting.png"))
242 DEF_BENCH(return new BitmapDecodeBench("png_phonehub_generic_error", "images/Generic_Error.png"))
243 DEF_BENCH(return new BitmapDecodeBench("png_phonehub_onboard" , "images/Onboard.png"))