blob: c762373f62ff03f787ce40d3eca6c23a2238fd5e [file] [log] [blame]
msarett7f691442015-09-22 11:56:16 -07001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "bench/BitmapRegionDecoderBench.h"
Leon Scroggins III87caae62020-05-04 10:02:45 -04009#ifdef SK_ENABLE_ANDROID_UTILS
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "bench/CodecBenchPriv.h"
Leon Scroggins III87caae62020-05-04 10:02:45 -040011#include "client_utils/android/BitmapRegionDecoder.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/core/SkBitmap.h"
13#include "src/core/SkOSFile.h"
msarett7f691442015-09-22 11:56:16 -070014
15BitmapRegionDecoderBench::BitmapRegionDecoderBench(const char* baseName, SkData* encoded,
msarettd1227a72016-05-18 06:23:57 -070016 SkColorType colorType, uint32_t sampleSize, const SkIRect& subset)
msarett7f691442015-09-22 11:56:16 -070017 : fBRD(nullptr)
18 , fData(SkRef(encoded))
msarett7f691442015-09-22 11:56:16 -070019 , fColorType(colorType)
20 , fSampleSize(sampleSize)
21 , fSubset(subset)
22{
msarett7f691442015-09-22 11:56:16 -070023 // Choose a useful name for the color type
24 const char* colorName = color_type_to_str(colorType);
25
msarettd1227a72016-05-18 06:23:57 -070026 fName.printf("BRD_%s_%s", baseName, colorName);
msarett7f691442015-09-22 11:56:16 -070027 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -080028 fName.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett7f691442015-09-22 11:56:16 -070029 }
30}
31
32const char* BitmapRegionDecoderBench::onGetName() {
33 return fName.c_str();
34}
35
36bool BitmapRegionDecoderBench::isSuitableFor(Backend backend) {
37 return kNonRendering_Backend == backend;
38}
39
joshualitt8a6697a2015-09-30 12:11:07 -070040void BitmapRegionDecoderBench::onDelayedSetup() {
Leon Scroggins III87caae62020-05-04 10:02:45 -040041 fBRD = android::skia::BitmapRegionDecoder::Make(fData);
msarett7f691442015-09-22 11:56:16 -070042}
43
mtkleina1ebeb22015-10-01 09:43:39 -070044void BitmapRegionDecoderBench::onDraw(int n, SkCanvas* canvas) {
Leon Scroggins III0118e972018-03-13 11:14:33 -040045 auto ct = fBRD->computeOutputColorType(fColorType);
46 auto cs = fBRD->computeOutputColorSpace(ct, nullptr);
msarett7f691442015-09-22 11:56:16 -070047 for (int i = 0; i < n; i++) {
msarett35e5d1b2015-10-27 12:50:25 -070048 SkBitmap bm;
Leon Scroggins III0118e972018-03-13 11:14:33 -040049 SkAssertResult(fBRD->decodeRegion(&bm, nullptr, fSubset, fSampleSize, ct, false, cs));
msarett7f691442015-09-22 11:56:16 -070050 }
51}
Leon Scroggins III87caae62020-05-04 10:02:45 -040052#endif // SK_ENABLE_ANDROID_UTILS