2 * Copyright 2016 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
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"
14 class DecodeBench : public Benchmark {
16 DecodeBench(const char* name, const char* source)
17 : fName(SkStringPrintf("decode_%s", name))
21 bool isSuitableFor(Backend backend) final {
22 return backend == kNonRendering_Backend;
25 const char* onGetName() final { return fName.c_str(); }
27 void onDelayedSetup() override {
28 fData = GetResourceAsData(fSource);
40 class BitmapDecodeBench final : public DecodeBench {
42 BitmapDecodeBench(const char* name, const char* source)
43 : INHERITED(name, source)
46 void onDraw(int loops, SkCanvas*) override {
49 SkAssertResult(DecodeDataToBitmap(fData, &bm));
54 using INHERITED = DecodeBench;
58 class SkottieDecodeBench final : public DecodeBench {
60 SkottieDecodeBench(const char* name, const char* source)
61 : INHERITED(name, source)
64 void onDraw(int loops, SkCanvas*) override {
66 const auto anim = skottie::Animation::Make(reinterpret_cast<const char*>(fData->data()),
72 using INHERITED = DecodeBench;
75 class SkottiePictureDecodeBench final : public DecodeBench {
77 SkottiePictureDecodeBench(const char* name, const char* source)
78 : INHERITED(name, source)
81 void onDraw(int loops, SkCanvas*) override {
83 const auto anim = skottie::Animation::Make(reinterpret_cast<const char*>(fData->data()),
85 SkPictureRecorder recorder;
87 anim->render(recorder.beginRecording(anim->size().width(), anim->size().height()));
89 const auto pic = recorder.finishRecordingAsPicture();
94 using INHERITED = DecodeBench;
97 DEF_BENCH(return new SkottieDecodeBench("skottie_large", // 426593
98 "skottie/skottie-text-scale-to-fit-minmax.json"));
99 DEF_BENCH(return new SkottieDecodeBench("skottie_medium", // 10947
100 "skottie/skottie-sphere-effect.json"));
101 DEF_BENCH(return new SkottieDecodeBench("skottie_small", // 1112
102 "skottie/skottie_sample_multiframe.json"));
103 // Created from PhoneHub assets SVG source, with https://lottiefiles.com/svg-to-lottie
104 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_connecting.json", // 216x216
105 "skottie/skottie-phonehub-connecting.json"));
106 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_generic_error.json", // 216x217
107 "skottie/skottie-phonehub-generic-error.json"));
108 DEF_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
112 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_connecting.json",
113 "skottie/skottie-phonehub-svgo-connecting.json"));
114 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_generic_error.json",
115 "skottie/skottie-phonehub-svgo-generic-error.json"));
116 DEF_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.
123 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_no_masks_connecting.json",
124 "skottie/skottie-phonehub-svgo-no-masks-connecting.json"));
125 DEF_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
130 // 2. https://jakearchibald.github.io/svgomg/
131 // 3. https://lottiefiles.com/svg-to-lottie
132 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_no_frills_connecting.json",
133 "skottie/skottie-phonehub-svgo-no-frills-connecting.json"));
134 DEF_BENCH(return new SkottieDecodeBench(
135 "skottie_phonehub_svgo_no_frills_generic_error.json",
136 "skottie/skottie-phonehub-svgo-no-frills-generic-error.json"));
137 DEF_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
140 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_connecting_min.json",
141 "skottie/skottie-phonehub-connecting_min.json"));
142 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_generic_error_min.json",
143 "skottie/skottie-phonehub-generic-error_min.json"));
144 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_onboard_min.json",
145 "skottie/skottie-phonehub-onboard_min.json"));
146 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_connecting_min.json",
147 "skottie/skottie-phonehub-svgo-connecting_min.json"));
148 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_generic_error_min.json",
149 "skottie/skottie-phonehub-svgo-generic-error_min.json"));
150 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_onboard_min.json",
151 "skottie/skottie-phonehub-svgo-onboard_min.json"));
152 DEF_BENCH(return new SkottieDecodeBench(
153 "skottie_phonehub_svgo_no_masks_connecting_min.json",
154 "skottie/skottie-phonehub-svgo-no-masks-connecting_min.json"));
155 DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_no_masks_onboard_min.json",
156 "skottie/skottie-phonehub-svgo-no-masks-onboard_min.json"));
157 DEF_BENCH(return new SkottieDecodeBench(
158 "skottie_phonehub_svgo_no_frills_connecting_min.json",
159 "skottie/skottie-phonehub-svgo-no-frills-connecting_min.json"));
160 DEF_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"));
164 return new SkottieDecodeBench("skottie_phonehub_svgo_no_frills_onboard_min.json",
165 "skottie/skottie-phonehub-svgo-no-frills-onboard_min.json"));
167 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_large",
168 "skottie/skottie-text-scale-to-fit-minmax.json"));
169 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_medium",
170 "skottie/skottie-sphere-effect.json"));
171 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_small",
172 "skottie/skottie_sample_multiframe.json"));
173 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_connecting.json",
174 "skottie/skottie-phonehub-connecting.json"));
175 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_generic_error.json",
176 "skottie/skottie-phonehub-generic-error.json"));
177 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_onboard.json",
178 "skottie/skottie-phonehub-onboard.json"));
179 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_svgo_connecting.json",
180 "skottie/skottie-phonehub-svgo-connecting.json"));
181 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_svgo_generic_error.json",
182 "skottie/skottie-phonehub-svgo-generic-error.json"));
183 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_svgo_onboard.json",
184 "skottie/skottie-phonehub-svgo-onboard.json"));
185 DEF_BENCH(return new SkottiePictureDecodeBench(
186 "skottiepic_phonehub_svgo_no_masks_connecting.json",
187 "skottie/skottie-phonehub-svgo-no-masks-connecting.json"));
188 DEF_BENCH(return new SkottiePictureDecodeBench(
189 "skottiepic_phonehub_svgo_no_masks_onboard.json",
190 "skottie/skottie-phonehub-svgo-no-masks-onboard.json"));
191 DEF_BENCH(return new SkottiePictureDecodeBench(
192 "skottiepic_phonehub_svgo_no_frills_connecting.json",
193 "skottie/skottie-phonehub-svgo-no-frills-connecting.json"));
194 DEF_BENCH(return new SkottiePictureDecodeBench(
195 "skottiepic_phonehub_svgo_no_frills_generic_error.json",
196 "skottie/skottie-phonehub-svgo-no-frills-generic-error.json"));
197 DEF_BENCH(return new SkottiePictureDecodeBench(
198 "skottiepic_phonehub_svgo_no_frills_onboard.json",
199 "skottie/skottie-phonehub-svgo-no-frills-onboard.json"));
200 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_connecting_min.json",
201 "skottie/skottie-phonehub-connecting_min.json"));
202 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_generic_error_min.json",
203 "skottie/skottie-phonehub-generic-error_min.json"));
204 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_onboard_min.json",
205 "skottie/skottie-phonehub-onboard_min.json"));
207 return new SkottiePictureDecodeBench("skottiepic_phonehub_svgo_connecting_min.json",
208 "skottie/skottie-phonehub-svgo-connecting_min.json"));
209 DEF_BENCH(return new SkottiePictureDecodeBench(
210 "skottiepic_phonehub_svgo_generic_error_min.json",
211 "skottie/skottie-phonehub-svgo-generic-error_min.json"));
212 DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_svgo_onboard_min.json",
213 "skottie/skottie-phonehub-svgo-onboard_min.json"));
214 DEF_BENCH(return new SkottiePictureDecodeBench(
215 "skottiepic_phonehub_svgo_no_masks_connecting_min.json",
216 "skottie/skottie-phonehub-svgo-no-masks-connecting_min.json"));
217 DEF_BENCH(return new SkottiePictureDecodeBench(
218 "skottiepic_phonehub_svgo_no_masks_onboard_min.json",
219 "skottie/skottie-phonehub-svgo-no-masks-onboard_min.json"));
220 DEF_BENCH(return new SkottiePictureDecodeBench(
221 "skottiepic_phonehub_svgo_no_frills_connecting_min.json",
222 "skottie/skottie-phonehub-svgo-no-frills-connecting_min.json"));
223 DEF_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"));
226 DEF_BENCH(return new SkottiePictureDecodeBench(
227 "skottiepic_phonehub_svgo_no_frills_onboard_min.json",
228 "skottie/skottie-phonehub-svgo-no-frills-onboard_min.json"));
230 DEF_BENCH(return new BitmapDecodeBench("png_large" /*1600x1600*/, "images/mandrill_1600.png"));
231 DEF_BENCH(return new BitmapDecodeBench("png_medium" /* 512x 512*/, "images/mandrill_512.png"));
232 DEF_BENCH(return new BitmapDecodeBench("png_small" /* 32x 32*/, "images/mandrill_32.png"));
233 DEF_BENCH(return new BitmapDecodeBench("png_phonehub_connecting" , "images/Connecting.png"));
234 DEF_BENCH(return new BitmapDecodeBench("png_phonehub_generic_error", "images/Generic_Error.png"));
235 DEF_BENCH(return new BitmapDecodeBench("png_phonehub_onboard" , "images/Onboard.png"));