xref: /aosp_15_r20/external/skia/bench/BitmapRegionDecoderBench.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2015 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/BitmapRegionDecoderBench.h"
9 #ifdef SK_ENABLE_ANDROID_UTILS
10 #include "bench/CodecBenchPriv.h"
11 #include "client_utils/android/BitmapRegionDecoder.h"
12 #include "include/core/SkBitmap.h"
13 #include "src/core/SkOSFile.h"
14 
BitmapRegionDecoderBench(const char * baseName,SkData * encoded,SkColorType colorType,uint32_t sampleSize,const SkIRect & subset)15 BitmapRegionDecoderBench::BitmapRegionDecoderBench(const char* baseName, SkData* encoded,
16         SkColorType colorType, uint32_t sampleSize, const SkIRect& subset)
17     : fBRD(nullptr)
18     , fData(SkRef(encoded))
19     , fColorType(colorType)
20     , fSampleSize(sampleSize)
21     , fSubset(subset)
22 {
23     // Choose a useful name for the color type
24     const char* colorName = color_type_to_str(colorType);
25 
26     fName.printf("BRD_%s_%s", baseName, colorName);
27     if (1 != sampleSize) {
28         fName.appendf("_%.3f", 1.0f / (float) sampleSize);
29     }
30 }
31 
onGetName()32 const char* BitmapRegionDecoderBench::onGetName() {
33     return fName.c_str();
34 }
35 
isSuitableFor(Backend backend)36 bool BitmapRegionDecoderBench::isSuitableFor(Backend backend) {
37     return Backend::kNonRendering == backend;
38 }
39 
onDelayedSetup()40 void BitmapRegionDecoderBench::onDelayedSetup() {
41     fBRD = android::skia::BitmapRegionDecoder::Make(fData);
42 }
43 
onDraw(int n,SkCanvas * canvas)44 void BitmapRegionDecoderBench::onDraw(int n, SkCanvas* canvas) {
45     auto ct = fBRD->computeOutputColorType(fColorType);
46     auto cs = fBRD->computeOutputColorSpace(ct, nullptr);
47     for (int i = 0; i < n; i++) {
48         SkBitmap bm;
49         SkAssertResult(fBRD->decodeRegion(&bm, nullptr, fSubset, fSampleSize, ct, false, cs));
50     }
51 }
52 #endif // SK_ENABLE_ANDROID_UTILS
53