msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 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 "BitmapRegionDecoderBench.h" |
| 9 | #include "CodecBenchPriv.h" |
| 10 | #include "SkBitmap.h" |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 11 | #include "SkOSFile.h" |
| 12 | |
| 13 | BitmapRegionDecoderBench::BitmapRegionDecoderBench(const char* baseName, SkData* encoded, |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 14 | SkColorType colorType, uint32_t sampleSize, const SkIRect& subset) |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 15 | : fBRD(nullptr) |
| 16 | , fData(SkRef(encoded)) |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 17 | , fColorType(colorType) |
| 18 | , fSampleSize(sampleSize) |
| 19 | , fSubset(subset) |
| 20 | { |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 21 | // Choose a useful name for the color type |
| 22 | const char* colorName = color_type_to_str(colorType); |
| 23 | |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 24 | fName.printf("BRD_%s_%s", baseName, colorName); |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 25 | if (1 != sampleSize) { |
msarett | 4b0778e | 2015-11-13 09:59:11 -0800 | [diff] [blame] | 26 | fName.appendf("_%.3f", 1.0f / (float) sampleSize); |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 27 | } |
| 28 | } |
| 29 | |
| 30 | const char* BitmapRegionDecoderBench::onGetName() { |
| 31 | return fName.c_str(); |
| 32 | } |
| 33 | |
| 34 | bool BitmapRegionDecoderBench::isSuitableFor(Backend backend) { |
| 35 | return kNonRendering_Backend == backend; |
| 36 | } |
| 37 | |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 38 | void BitmapRegionDecoderBench::onDelayedSetup() { |
reed | 42943c8 | 2016-09-12 12:01:44 -0700 | [diff] [blame] | 39 | fBRD.reset(SkBitmapRegionDecoder::Create(fData, SkBitmapRegionDecoder::kAndroidCodec_Strategy)); |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 40 | } |
| 41 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 42 | void BitmapRegionDecoderBench::onDraw(int n, SkCanvas* canvas) { |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 43 | for (int i = 0; i < n; i++) { |
msarett | 35e5d1b | 2015-10-27 12:50:25 -0700 | [diff] [blame] | 44 | SkBitmap bm; |
| 45 | SkAssertResult(fBRD->decodeRegion(&bm, nullptr, fSubset, fSampleSize, fColorType, false)); |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 46 | } |
| 47 | } |