Flutter Engine
The Flutter Engine
DecodeBench.cpp
Go to the documentation of this file.
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"
14#include "tools/DecodeUtils.h"
15#include "tools/Resources.h"
17
18class DecodeBench : public Benchmark {
19protected:
20 DecodeBench(const char* name, const char* source)
21 : fName(SkStringPrintf("decode_%s", name))
22 , fSource(source)
23 {}
24
27 }
28
29 const char* onGetName() final { return fName.c_str(); }
30
31 void onDelayedSetup() override {
32 fData = GetResourceAsData(fSource);
34 }
35
36protected:
38
39private:
40 const SkString fName;
41 const char* fSource;
42};
43
44class BitmapDecodeBench final : public DecodeBench {
45public:
46 BitmapDecodeBench(const char* name, const char* source)
48 {}
49
50 void onDraw(int loops, SkCanvas*) override {
51 while (loops-- > 0) {
52 SkBitmap bm;
54 }
55 }
56
57private:
58 using INHERITED = DecodeBench;
59};
60
61
62class SkottieDecodeBench final : public DecodeBench {
63public:
64 SkottieDecodeBench(const char* name, const char* 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
77private:
78 using INHERITED = DecodeBench;
79};
80
82public:
83 SkottiePictureDecodeBench(const char* name, const char* 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
101private:
102 using INHERITED = DecodeBench;
103};
104
105DEF_BENCH(return new SkottieDecodeBench("skottie_large", // 426593
106 "skottie/skottie-text-scale-to-fit-minmax.json"));
107DEF_BENCH(return new SkottieDecodeBench("skottie_medium", // 10947
108 "skottie/skottie-sphere-effect.json"));
109DEF_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
112DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_connecting.json", // 216x216
113 "skottie/skottie-phonehub-connecting.json"));
114DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_generic_error.json", // 216x217
115 "skottie/skottie-phonehub-generic-error.json"));
116DEF_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
120DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_connecting.json",
121 "skottie/skottie-phonehub-svgo-connecting.json"));
122DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_generic_error.json",
123 "skottie/skottie-phonehub-svgo-generic-error.json"));
124DEF_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.
131DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_no_masks_connecting.json",
132 "skottie/skottie-phonehub-svgo-no-masks-connecting.json"));
133DEF_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
140DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_no_frills_connecting.json",
141 "skottie/skottie-phonehub-svgo-no-frills-connecting.json"));
143 "skottie_phonehub_svgo_no_frills_generic_error.json",
144 "skottie/skottie-phonehub-svgo-no-frills-generic-error.json"));
145DEF_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
148DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_connecting_min.json",
149 "skottie/skottie-phonehub-connecting_min.json"));
150DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_generic_error_min.json",
151 "skottie/skottie-phonehub-generic-error_min.json"));
152DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_onboard_min.json",
153 "skottie/skottie-phonehub-onboard_min.json"));
154DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_connecting_min.json",
155 "skottie/skottie-phonehub-svgo-connecting_min.json"));
156DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_generic_error_min.json",
157 "skottie/skottie-phonehub-svgo-generic-error_min.json"));
158DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_onboard_min.json",
159 "skottie/skottie-phonehub-svgo-onboard_min.json"));
161 "skottie_phonehub_svgo_no_masks_connecting_min.json",
162 "skottie/skottie-phonehub-svgo-no-masks-connecting_min.json"));
163DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_no_masks_onboard_min.json",
164 "skottie/skottie-phonehub-svgo-no-masks-onboard_min.json"));
166 "skottie_phonehub_svgo_no_frills_connecting_min.json",
167 "skottie/skottie-phonehub-svgo-no-frills-connecting_min.json"));
169 "skottie_phonehub_svgo_no_frills_generic_error_min.json",
170 "skottie/skottie-phonehub-svgo-no-frills-generic-error_min.json"));
172 return new SkottieDecodeBench("skottie_phonehub_svgo_no_frills_onboard_min.json",
173 "skottie/skottie-phonehub-svgo-no-frills-onboard_min.json"));
174
175DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_large",
176 "skottie/skottie-text-scale-to-fit-minmax.json"));
177DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_medium",
178 "skottie/skottie-sphere-effect.json"));
179DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_small",
180 "skottie/skottie_sample_multiframe.json"));
181DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_connecting.json",
182 "skottie/skottie-phonehub-connecting.json"));
183DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_generic_error.json",
184 "skottie/skottie-phonehub-generic-error.json"));
185DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_onboard.json",
186 "skottie/skottie-phonehub-onboard.json"));
187DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_svgo_connecting.json",
188 "skottie/skottie-phonehub-svgo-connecting.json"));
189DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_svgo_generic_error.json",
190 "skottie/skottie-phonehub-svgo-generic-error.json"));
191DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_svgo_onboard.json",
192 "skottie/skottie-phonehub-svgo-onboard.json"));
194 "skottiepic_phonehub_svgo_no_masks_connecting.json",
195 "skottie/skottie-phonehub-svgo-no-masks-connecting.json"));
197 "skottiepic_phonehub_svgo_no_masks_onboard.json",
198 "skottie/skottie-phonehub-svgo-no-masks-onboard.json"));
200 "skottiepic_phonehub_svgo_no_frills_connecting.json",
201 "skottie/skottie-phonehub-svgo-no-frills-connecting.json"));
203 "skottiepic_phonehub_svgo_no_frills_generic_error.json",
204 "skottie/skottie-phonehub-svgo-no-frills-generic-error.json"));
206 "skottiepic_phonehub_svgo_no_frills_onboard.json",
207 "skottie/skottie-phonehub-svgo-no-frills-onboard.json"));
208DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_connecting_min.json",
209 "skottie/skottie-phonehub-connecting_min.json"));
210DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_generic_error_min.json",
211 "skottie/skottie-phonehub-generic-error_min.json"));
212DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_onboard_min.json",
213 "skottie/skottie-phonehub-onboard_min.json"));
215 return new SkottiePictureDecodeBench("skottiepic_phonehub_svgo_connecting_min.json",
216 "skottie/skottie-phonehub-svgo-connecting_min.json"));
218 "skottiepic_phonehub_svgo_generic_error_min.json",
219 "skottie/skottie-phonehub-svgo-generic-error_min.json"));
220DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_svgo_onboard_min.json",
221 "skottie/skottie-phonehub-svgo-onboard_min.json"));
223 "skottiepic_phonehub_svgo_no_masks_connecting_min.json",
224 "skottie/skottie-phonehub-svgo-no-masks-connecting_min.json"));
226 "skottiepic_phonehub_svgo_no_masks_onboard_min.json",
227 "skottie/skottie-phonehub-svgo-no-masks-onboard_min.json"));
229 "skottiepic_phonehub_svgo_no_frills_connecting_min.json",
230 "skottie/skottie-phonehub-svgo-no-frills-connecting_min.json"));
232 "skottiepic_phonehub_svgo_no_frills_generic_error_min.json",
233 "skottie/skottie-phonehub-svgo-no-frills-generic-error_min.json"));
235 "skottiepic_phonehub_svgo_no_frills_onboard_min.json",
236 "skottie/skottie-phonehub-svgo-no-frills-onboard_min.json"));
237
238DEF_BENCH(return new BitmapDecodeBench("png_large" /*1600x1600*/, "images/mandrill_1600.png"));
239DEF_BENCH(return new BitmapDecodeBench("png_medium" /* 512x 512*/, "images/mandrill_512.png"));
240DEF_BENCH(return new BitmapDecodeBench("png_small" /* 32x 32*/, "images/mandrill_32.png"));
241DEF_BENCH(return new BitmapDecodeBench("png_phonehub_connecting" , "images/Connecting.png"));
242DEF_BENCH(return new BitmapDecodeBench("png_phonehub_generic_error", "images/Generic_Error.png"));
243DEF_BENCH(return new BitmapDecodeBench("png_phonehub_onboard" , "images/Onboard.png"));
const char * backend
DEF_BENCH(return new SkottieDecodeBench("skottie_large", "skottie/skottie-text-scale-to-fit-minmax.json"))
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
sk_sp< SkData > GetResourceAsData(const char *resource)
Definition: Resources.cpp:42
#define SkASSERT(cond)
Definition: SkAssert.h:116
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
BitmapDecodeBench(const char *name, const char *source)
Definition: DecodeBench.cpp:46
void onDraw(int loops, SkCanvas *) override
Definition: DecodeBench.cpp:50
const char * onGetName() final
Definition: DecodeBench.cpp:29
DecodeBench(const char *name, const char *source)
Definition: DecodeBench.cpp:20
void onDelayedSetup() override
Definition: DecodeBench.cpp:31
bool isSuitableFor(Backend backend) final
Definition: DecodeBench.cpp:25
sk_sp< SkData > fData
Definition: DecodeBench.cpp:37
const void * data() const
Definition: SkData.h:37
size_t size() const
Definition: SkData.h:30
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
const char * c_str() const
Definition: SkString.h:133
SkottieDecodeBench(const char *name, const char *source)
Definition: DecodeBench.cpp:64
void onDraw(int loops, SkCanvas *) override
Definition: DecodeBench.cpp:68
SkottiePictureDecodeBench(const char *name, const char *source)
Definition: DecodeBench.cpp:83
void onDraw(int loops, SkCanvas *) override
Definition: DecodeBench.cpp:87
SkBitmap source
Definition: examples.cpp:28
bool DecodeDataToBitmap(sk_sp< SkData > data, SkBitmap *dst)
Definition: DecodeUtils.cpp:22
sk_sp< SkFontMgr > TestFontMgr()
DlVertices::Builder Builder
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32