1 /* 2 * Copyright 2024 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 <memory> 9 #include "bench/Benchmark.h" 10 #include "include/codec/SkCodec.h" 11 #include "include/codec/SkWebpDecoder.h" 12 #include "include/private/base/SkAssert.h" 13 #include "src/base/SkAutoMalloc.h" 14 #include "tools/Resources.h" 15 16 namespace { 17 18 class WebpBlendBench final : public Benchmark { 19 public: onGetName()20 const char* onGetName() override { 21 return "webp_blend_bench"; 22 } 23 isSuitableFor(Backend backend)24 bool isSuitableFor(Backend backend) override { 25 return Backend::kNonRendering == backend; 26 } 27 onDelayedSetup()28 void onDelayedSetup() override { 29 auto data = GetResourceAsData("images/blendBG.webp"); 30 SkASSERT(data); 31 32 SkCodec::Result result; 33 fCodec = SkWebpDecoder::Decode(data, &result); 34 SkASSERT(result == SkCodec::kSuccess); 35 36 fStorage.reset(fCodec->getInfo().computeMinByteSize()); 37 } 38 onDraw(int n,SkCanvas * canvas)39 void onDraw(int n, SkCanvas* canvas) override { 40 const SkImageInfo info = fCodec->getInfo(); 41 42 SkCodec::Options options; 43 options.fFrameIndex = 1; // frame known to blend with prev 44 45 for (int i = 0; i < n; ++i) { 46 fCodec->getPixels(info, fStorage.get(), info.minRowBytes(), &options); 47 } 48 } 49 50 private: 51 std::unique_ptr<SkCodec> fCodec; 52 SkAutoMalloc fStorage; 53 }; 54 55 } // namespace 56 57 DEF_BENCH( return new WebpBlendBench(); ) 58