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