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