Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "BitmapRegionDecoderBench.h" | 8 #include "BitmapRegionDecoderBench.h" |
| 9 #include "CodecBenchPriv.h" | 9 #include "CodecBenchPriv.h" |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| 11 #include "SkCodecTools.h" | 11 #include "SkCodecTools.h" |
| 12 #include "SkOSFile.h" | 12 #include "SkOSFile.h" |
| 13 | 13 |
| 14 BitmapRegionDecoderBench::BitmapRegionDecoderBench(const char* baseName, SkData* encoded, | 14 BitmapRegionDecoderBench::BitmapRegionDecoderBench(const char* baseName, SkData* encoded, |
| 15 SkBitmapRegionDecoderInterface::Strategy strategy, SkColorType colorType , | 15 SkBitmapRegionDecoderInterface::Strategy strategy, SkColorType colorType , |
| 16 uint32_t sampleSize, const SkIRect& subset) | 16 uint32_t sampleSize, const SkIRect& subset) |
| 17 : fBRD(nullptr) | 17 : fBRD(nullptr) |
| 18 , fData(SkRef(encoded)) | 18 , fData(SkRef(encoded)) |
| 19 , fStrategy(strategy) | 19 , fStrategy(strategy) |
| 20 , fColorType(colorType) | 20 , fColorType(colorType) |
| 21 , fSampleSize(sampleSize) | 21 , fSampleSize(sampleSize) |
| 22 , fSubset(subset) | 22 , fSubset(subset) |
| 23 , fColorTable(nullptr) | |
| 23 { | 24 { |
| 24 // Choose a useful name for the region decoding strategy | 25 // Choose a useful name for the region decoding strategy |
| 25 const char* strategyName; | 26 const char* strategyName; |
| 26 switch (strategy) { | 27 switch (strategy) { |
| 27 case SkBitmapRegionDecoderInterface::kOriginal_Strategy: | 28 case SkBitmapRegionDecoderInterface::kOriginal_Strategy: |
| 28 strategyName = "Original"; | 29 strategyName = "Original"; |
| 29 break; | 30 break; |
| 30 case SkBitmapRegionDecoderInterface::kCanvas_Strategy: | 31 case SkBitmapRegionDecoderInterface::kCanvas_Strategy: |
| 31 strategyName = "Canvas"; | 32 strategyName = "Canvas"; |
| 32 break; | 33 break; |
| 33 case SkBitmapRegionDecoderInterface::kAndroidCodec_Strategy: | 34 case SkBitmapRegionDecoderInterface::kAndroidCodec_Strategy: |
| 34 strategyName = "AndroidCodec"; | 35 strategyName = "AndroidCodec"; |
| 35 break; | 36 break; |
| 36 default: | 37 default: |
| 37 SkASSERT(false); | 38 SkASSERT(false); |
| 38 strategyName = ""; | 39 strategyName = ""; |
| 39 break; | 40 break; |
| 40 } | 41 } |
| 41 | 42 |
| 42 // Choose a useful name for the color type | 43 // Choose a useful name for the color type |
| 43 const char* colorName = color_type_to_str(colorType); | 44 const char* colorName = color_type_to_str(colorType); |
| 44 | 45 |
| 45 fName.printf("BRD_%s_%s_%s", baseName, strategyName, colorName); | 46 fName.printf("BRD_%s_%s_%s", baseName, strategyName, colorName); |
| 46 if (1 != sampleSize) { | 47 if (1 != sampleSize) { |
| 47 fName.appendf("_%.3f", get_scale_from_sample_size(sampleSize)); | 48 fName.appendf("_%.3f", get_scale_from_sample_size(sampleSize)); |
| 48 } | 49 } |
| 50 | |
| 51 if (kIndex_8_SkColorType == fColorType) { | |
| 52 SkPMColor colors[256]; | |
| 53 fColorTable.reset(new SkColorTable(colors, 256)); | |
| 54 } | |
| 49 } | 55 } |
| 50 | 56 |
| 51 const char* BitmapRegionDecoderBench::onGetName() { | 57 const char* BitmapRegionDecoderBench::onGetName() { |
| 52 return fName.c_str(); | 58 return fName.c_str(); |
| 53 } | 59 } |
| 54 | 60 |
| 55 bool BitmapRegionDecoderBench::isSuitableFor(Backend backend) { | 61 bool BitmapRegionDecoderBench::isSuitableFor(Backend backend) { |
| 56 return kNonRendering_Backend == backend; | 62 return kNonRendering_Backend == backend; |
| 57 } | 63 } |
| 58 | 64 |
| 59 void BitmapRegionDecoderBench::onDelayedSetup() { | 65 void BitmapRegionDecoderBench::onDelayedSetup() { |
| 60 fBRD.reset(SkBitmapRegionDecoderInterface::CreateBitmapRegionDecoder(fData, fStrategy)); | 66 fBRD.reset(SkBitmapRegionDecoderInterface::CreateBitmapRegionDecoder(fData, fStrategy)); |
| 61 } | 67 } |
| 62 | 68 |
| 63 void BitmapRegionDecoderBench::onDraw(int n, SkCanvas* canvas) { | 69 void BitmapRegionDecoderBench::onDraw(int n, SkCanvas* canvas) { |
| 64 SkAutoTDelete<SkBitmap> bitmap; | |
| 65 for (int i = 0; i < n; i++) { | 70 for (int i = 0; i < n; i++) { |
| 66 bitmap.reset(fBRD->decodeRegion(fSubset.left(), fSubset.top(), fSubset.w idth(), | 71 SkImageInfo info; |
| 67 fSubset.height(), fSampleSize, fColorType)); | 72 #ifdef SK_DEBUG |
| 68 SkASSERT(nullptr != bitmap.get()); | 73 bool result = |
| 74 #endif | |
| 75 fBRD->prepareRegion(fSubset, fSampleSize, fColorType, false, &info); | |
|
scroggo
2015/10/27 15:00:50
You could also change this to:
SkAssertResult(f
| |
| 76 SkASSERT(result); | |
| 77 | |
| 78 SkBitmap bitmap; | |
| 79 if (SkBitmapRegionDecoderInterface::kOriginal_Strategy != fStrategy) { | |
| 80 bitmap.allocPixels(info, nullptr, fColorTable); | |
| 81 } | |
| 82 | |
| 83 #ifdef SK_DEBUG | |
| 84 result = | |
| 85 #endif | |
| 86 fBRD->decodeRegion(bitmap); | |
| 87 SkASSERT(result); | |
| 69 } | 88 } |
| 70 } | 89 } |
| OLD | NEW |