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" |
| 11 | #include "SkCodecTools.h" |
| 12 | #include "SkOSFile.h" |
| 13 | |
| 14 | BitmapRegionDecoderBench::BitmapRegionDecoderBench(const char* baseName, SkData* encoded, |
| 15 | SkBitmapRegionDecoderInterface::Strategy strategy, SkColorType colorType, |
| 16 | uint32_t sampleSize, const SkIRect& subset) |
| 17 | : fBRD(nullptr) |
| 18 | , fData(SkRef(encoded)) |
| 19 | , fStrategy(strategy) |
| 20 | , fColorType(colorType) |
| 21 | , fSampleSize(sampleSize) |
| 22 | , fSubset(subset) |
| 23 | { |
| 24 | // Choose a useful name for the region decoding strategy |
| 25 | const char* strategyName; |
| 26 | switch (strategy) { |
| 27 | case SkBitmapRegionDecoderInterface::kOriginal_Strategy: |
| 28 | strategyName = "Original"; |
| 29 | break; |
| 30 | case SkBitmapRegionDecoderInterface::kCanvas_Strategy: |
| 31 | strategyName = "Canvas"; |
| 32 | break; |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 33 | case SkBitmapRegionDecoderInterface::kAndroidCodec_Strategy: |
| 34 | strategyName = "AndroidCodec"; |
| 35 | break; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 36 | default: |
| 37 | SkASSERT(false); |
| 38 | strategyName = ""; |
| 39 | break; |
| 40 | } |
| 41 | |
| 42 | // Choose a useful name for the color type |
| 43 | const char* colorName = color_type_to_str(colorType); |
| 44 | |
| 45 | fName.printf("BRD_%s_%s_%s", baseName, strategyName, colorName); |
| 46 | if (1 != sampleSize) { |
| 47 | fName.appendf("_%.3f", get_scale_from_sample_size(sampleSize)); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | const char* BitmapRegionDecoderBench::onGetName() { |
| 52 | return fName.c_str(); |
| 53 | } |
| 54 | |
| 55 | bool BitmapRegionDecoderBench::isSuitableFor(Backend backend) { |
| 56 | return kNonRendering_Backend == backend; |
| 57 | } |
| 58 | |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 59 | void BitmapRegionDecoderBench::onDelayedSetup() { |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 60 | fBRD.reset(SkBitmapRegionDecoderInterface::CreateBitmapRegionDecoder(fData, fStrategy)); |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 61 | } |
| 62 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 63 | void BitmapRegionDecoderBench::onDraw(int n, SkCanvas* canvas) { |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 64 | for (int i = 0; i < n; i++) { |
msarett | 35e5d1b | 2015-10-27 12:50:25 -0700 | [diff] [blame] | 65 | SkBitmap bm; |
| 66 | SkAssertResult(fBRD->decodeRegion(&bm, nullptr, fSubset, fSampleSize, fColorType, false)); |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 67 | } |
| 68 | } |