skia2/bench/DecodeBench.cpp
Avery Musbach 92ae58f338 Reland "bench: Add PhoneHub assets to skottie-vs-png decode bench"
This is a reland of 0541a983ef

This time with Generic_Error.png instead of Generic Error.png, because
the space caused problems.

Original change's description:
> bench: Add PhoneHub assets to skottie-vs-png decode bench
>
> The skottie-vs-png decode bench is intended to facilitate comparison
> between Lottie and PNG, but such a comparison cannot really be made when
> the Lottie files are unrelated to the PNG files (Lottie files chosen to
> represent a range of vector graphic complexity, versus PNG files chosen
> to represent a range of image dimensions). This CL adds PhoneHub assets
> in PNG and Lottie, including various Lottie files created using
> different optimization strategies (see added code comments for details).
>
> Change-Id: I1a4357ab0af22b9db7b7ce83fd07d48c77db7680
> Bug: chromium:1128684
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/442476
> Reviewed-by: Avery Musbach <amusbach@google.com>
> Reviewed-by: Florin Malita <fmalita@google.com>
> Commit-Queue: Florin Malita <fmalita@google.com>

Bug: chromium:1128684
Change-Id: I1a5e21f67f52b03fa1c06192ef7190f41b04e3dc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/452300
Reviewed-by: Florin Malita <fmalita@google.com>
Commit-Queue: Florin Malita <fmalita@google.com>
Commit-Queue: Avery Musbach <amusbach@chromium.org>
2021-09-23 17:40:09 +00:00

236 lines
13 KiB
C++

/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "bench/Benchmark.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkPictureRecorder.h"
#include "modules/skottie/include/Skottie.h"
#include "tools/Resources.h"
class DecodeBench : public Benchmark {
protected:
DecodeBench(const char* name, const char* source)
: fName(SkStringPrintf("decode_%s", name))
, fSource(source)
{}
bool isSuitableFor(Backend backend) final {
return backend == kNonRendering_Backend;
}
const char* onGetName() final { return fName.c_str(); }
void onDelayedSetup() override {
fData = GetResourceAsData(fSource);
SkASSERT(fData);
}
protected:
sk_sp<SkData> fData;
private:
const SkString fName;
const char* fSource;
};
class BitmapDecodeBench final : public DecodeBench {
public:
BitmapDecodeBench(const char* name, const char* source)
: INHERITED(name, source)
{}
void onDraw(int loops, SkCanvas*) override {
while (loops-- > 0) {
SkBitmap bm;
SkAssertResult(DecodeDataToBitmap(fData, &bm));
}
}
private:
using INHERITED = DecodeBench;
};
class SkottieDecodeBench final : public DecodeBench {
public:
SkottieDecodeBench(const char* name, const char* source)
: INHERITED(name, source)
{}
void onDraw(int loops, SkCanvas*) override {
while (loops-- > 0) {
const auto anim = skottie::Animation::Make(reinterpret_cast<const char*>(fData->data()),
fData->size());
}
}
private:
using INHERITED = DecodeBench;
};
class SkottiePictureDecodeBench final : public DecodeBench {
public:
SkottiePictureDecodeBench(const char* name, const char* source)
: INHERITED(name, source)
{}
void onDraw(int loops, SkCanvas*) override {
while (loops-- > 0) {
const auto anim = skottie::Animation::Make(reinterpret_cast<const char*>(fData->data()),
fData->size());
SkPictureRecorder recorder;
anim->seek(0);
anim->render(recorder.beginRecording(anim->size().width(), anim->size().height()));
const auto pic = recorder.finishRecordingAsPicture();
}
}
private:
using INHERITED = DecodeBench;
};
DEF_BENCH(return new SkottieDecodeBench("skottie_large", // 426593
"skottie/skottie-text-scale-to-fit-minmax.json"));
DEF_BENCH(return new SkottieDecodeBench("skottie_medium", // 10947
"skottie/skottie-sphere-effect.json"));
DEF_BENCH(return new SkottieDecodeBench("skottie_small", // 1112
"skottie/skottie_sample_multiframe.json"));
// Created from PhoneHub assets SVG source, with https://lottiefiles.com/svg-to-lottie
DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_connecting.json", // 216x216
"skottie/skottie-phonehub-connecting.json"));
DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_generic_error.json", // 216x217
"skottie/skottie-phonehub-generic-error.json"));
DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_onboard.json", // 217x217
"skottie/skottie-phonehub-onboard.json"));
// Created from PhoneHub assets SVG source, with https://jakearchibald.github.io/svgomg/ and then
// https://lottiefiles.com/svg-to-lottie
DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_connecting.json",
"skottie/skottie-phonehub-svgo-connecting.json"));
DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_generic_error.json",
"skottie/skottie-phonehub-svgo-generic-error.json"));
DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_onboard.json",
"skottie/skottie-phonehub-svgo-onboard.json"));
// Created from PhoneHub assets SVG source:
// 1. Manually edited to have no masks (but look the same as the original)
// 2. https://jakearchibald.github.io/svgomg/
// 3. https://lottiefiles.com/svg-to-lottie
// Note: The Generic Error asset is excluded here because it has no masks in the first place.
DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_no_masks_connecting.json",
"skottie/skottie-phonehub-svgo-no-masks-connecting.json"));
DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_no_masks_onboard.json",
"skottie/skottie-phonehub-svgo-no-masks-onboard.json"));
// Created from PhoneHub assets SVG source:
// 1. Manually edited to use only the most basic functionality of SVG (but look the same as the
// original)
// 2. https://jakearchibald.github.io/svgomg/
// 3. https://lottiefiles.com/svg-to-lottie
DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_no_frills_connecting.json",
"skottie/skottie-phonehub-svgo-no-frills-connecting.json"));
DEF_BENCH(return new SkottieDecodeBench(
"skottie_phonehub_svgo_no_frills_generic_error.json",
"skottie/skottie-phonehub-svgo-no-frills-generic-error.json"));
DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_no_frills_onboard.json",
"skottie/skottie-phonehub-svgo-no-frills-onboard.json"));
// All of the above PhoneHub benchmarks, with https://skia-review.googlesource.com/c/skia/+/141265
DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_connecting_min.json",
"skottie/skottie-phonehub-connecting_min.json"));
DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_generic_error_min.json",
"skottie/skottie-phonehub-generic-error_min.json"));
DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_onboard_min.json",
"skottie/skottie-phonehub-onboard_min.json"));
DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_connecting_min.json",
"skottie/skottie-phonehub-svgo-connecting_min.json"));
DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_generic_error_min.json",
"skottie/skottie-phonehub-svgo-generic-error_min.json"));
DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_onboard_min.json",
"skottie/skottie-phonehub-svgo-onboard_min.json"));
DEF_BENCH(return new SkottieDecodeBench(
"skottie_phonehub_svgo_no_masks_connecting_min.json",
"skottie/skottie-phonehub-svgo-no-masks-connecting_min.json"));
DEF_BENCH(return new SkottieDecodeBench("skottie_phonehub_svgo_no_masks_onboard_min.json",
"skottie/skottie-phonehub-svgo-no-masks-onboard_min.json"));
DEF_BENCH(return new SkottieDecodeBench(
"skottie_phonehub_svgo_no_frills_connecting_min.json",
"skottie/skottie-phonehub-svgo-no-frills-connecting_min.json"));
DEF_BENCH(return new SkottieDecodeBench(
"skottie_phonehub_svgo_no_frills_generic_error_min.json",
"skottie/skottie-phonehub-svgo-no-frills-generic-error_min.json"));
DEF_BENCH(
return new SkottieDecodeBench("skottie_phonehub_svgo_no_frills_onboard_min.json",
"skottie/skottie-phonehub-svgo-no-frills-onboard_min.json"));
DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_large",
"skottie/skottie-text-scale-to-fit-minmax.json"));
DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_medium",
"skottie/skottie-sphere-effect.json"));
DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_small",
"skottie/skottie_sample_multiframe.json"));
DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_connecting.json",
"skottie/skottie-phonehub-connecting.json"));
DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_generic_error.json",
"skottie/skottie-phonehub-generic-error.json"));
DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_onboard.json",
"skottie/skottie-phonehub-onboard.json"));
DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_svgo_connecting.json",
"skottie/skottie-phonehub-svgo-connecting.json"));
DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_svgo_generic_error.json",
"skottie/skottie-phonehub-svgo-generic-error.json"));
DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_svgo_onboard.json",
"skottie/skottie-phonehub-svgo-onboard.json"));
DEF_BENCH(return new SkottiePictureDecodeBench(
"skottiepic_phonehub_svgo_no_masks_connecting.json",
"skottie/skottie-phonehub-svgo-no-masks-connecting.json"));
DEF_BENCH(return new SkottiePictureDecodeBench(
"skottiepic_phonehub_svgo_no_masks_onboard.json",
"skottie/skottie-phonehub-svgo-no-masks-onboard.json"));
DEF_BENCH(return new SkottiePictureDecodeBench(
"skottiepic_phonehub_svgo_no_frills_connecting.json",
"skottie/skottie-phonehub-svgo-no-frills-connecting.json"));
DEF_BENCH(return new SkottiePictureDecodeBench(
"skottiepic_phonehub_svgo_no_frills_generic_error.json",
"skottie/skottie-phonehub-svgo-no-frills-generic-error.json"));
DEF_BENCH(return new SkottiePictureDecodeBench(
"skottiepic_phonehub_svgo_no_frills_onboard.json",
"skottie/skottie-phonehub-svgo-no-frills-onboard.json"));
DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_connecting_min.json",
"skottie/skottie-phonehub-connecting_min.json"));
DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_generic_error_min.json",
"skottie/skottie-phonehub-generic-error_min.json"));
DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_onboard_min.json",
"skottie/skottie-phonehub-onboard_min.json"));
DEF_BENCH(
return new SkottiePictureDecodeBench("skottiepic_phonehub_svgo_connecting_min.json",
"skottie/skottie-phonehub-svgo-connecting_min.json"));
DEF_BENCH(return new SkottiePictureDecodeBench(
"skottiepic_phonehub_svgo_generic_error_min.json",
"skottie/skottie-phonehub-svgo-generic-error_min.json"));
DEF_BENCH(return new SkottiePictureDecodeBench("skottiepic_phonehub_svgo_onboard_min.json",
"skottie/skottie-phonehub-svgo-onboard_min.json"));
DEF_BENCH(return new SkottiePictureDecodeBench(
"skottiepic_phonehub_svgo_no_masks_connecting_min.json",
"skottie/skottie-phonehub-svgo-no-masks-connecting_min.json"));
DEF_BENCH(return new SkottiePictureDecodeBench(
"skottiepic_phonehub_svgo_no_masks_onboard_min.json",
"skottie/skottie-phonehub-svgo-no-masks-onboard_min.json"));
DEF_BENCH(return new SkottiePictureDecodeBench(
"skottiepic_phonehub_svgo_no_frills_connecting_min.json",
"skottie/skottie-phonehub-svgo-no-frills-connecting_min.json"));
DEF_BENCH(return new SkottiePictureDecodeBench(
"skottiepic_phonehub_svgo_no_frills_generic_error_min.json",
"skottie/skottie-phonehub-svgo-no-frills-generic-error_min.json"));
DEF_BENCH(return new SkottiePictureDecodeBench(
"skottiepic_phonehub_svgo_no_frills_onboard_min.json",
"skottie/skottie-phonehub-svgo-no-frills-onboard_min.json"));
DEF_BENCH(return new BitmapDecodeBench("png_large" /*1600x1600*/, "images/mandrill_1600.png"));
DEF_BENCH(return new BitmapDecodeBench("png_medium" /* 512x 512*/, "images/mandrill_512.png"));
DEF_BENCH(return new BitmapDecodeBench("png_small" /* 32x 32*/, "images/mandrill_32.png"));
DEF_BENCH(return new BitmapDecodeBench("png_phonehub_connecting" , "images/Connecting.png"));
DEF_BENCH(return new BitmapDecodeBench("png_phonehub_generic_error", "images/Generic_Error.png"));
DEF_BENCH(return new BitmapDecodeBench("png_phonehub_onboard" , "images/Onboard.png"));