Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 "SkBitmap.h" | |
| 10 #include "SkOSFile.h" | |
| 11 | |
| 12 // FIXME (msarett): How can we share this code with DM? | |
| 13 static float get_scale_from_sample_size(uint32_t sampleSize) { | |
| 14 return 1.0f / (float) sampleSize; | |
| 15 } | |
| 16 | |
| 17 BitmapRegionDecoderBench::BitmapRegionDecoderBench(SkString baseName, SkData* en coded, | |
| 18 SkBitmapRegionDecoderInterface::Strategy strategy, SkColorType colorType , | |
| 19 uint32_t sampleSize, const SkIRect& subset) | |
| 20 : fData(SkRef(encoded)) | |
| 21 , fStrategy(strategy) | |
| 22 , fColorType(colorType) | |
| 23 , fSampleSize(sampleSize) | |
| 24 , fSubset(subset) | |
| 25 { | |
| 26 // Choose a useful name for the region decoding strategy | |
| 27 const char* strategyName; | |
| 28 switch (strategy) { | |
| 29 case SkBitmapRegionDecoderInterface::kOriginal_Strategy: | |
| 30 strategyName = "Original"; | |
| 31 break; | |
| 32 case SkBitmapRegionDecoderInterface::kCanvas_Strategy: | |
| 33 strategyName = "Canvas"; | |
| 34 break; | |
| 35 default: | |
| 36 SkASSERT(false); | |
| 37 strategyName = ""; | |
| 38 break; | |
| 39 } | |
| 40 | |
| 41 // Choose a useful name for the color type | |
| 42 const char* colorName; | |
| 43 switch (colorType) { | |
| 44 case kN32_SkColorType: | |
|
scroggo
2015/09/17 20:05:38
This switch statement shows up a lot. Maybe we can
msarett
2015/09/18 13:22:30
I moved something into tools, but, on second look,
mtklein
2015/09/18 13:26:51
If the function's defined in the header, you'll wa
msarett
2015/09/18 17:41:17
Thanks for your explanation!
| |
| 45 colorName = "N32"; | |
| 46 break; | |
| 47 case kRGB_565_SkColorType: | |
| 48 colorName = "565"; | |
| 49 break; | |
| 50 case kGray_8_SkColorType: | |
| 51 colorName = "Gray8"; | |
| 52 break; | |
| 53 case kIndex_8_SkColorType: | |
| 54 colorName = "Index8"; | |
| 55 break; | |
| 56 default: | |
| 57 colorName = "Unknown"; | |
| 58 } | |
| 59 if (1 == sampleSize) { | |
| 60 fName.printf("BRD_%s_%s_%s", baseName.c_str(), strategyName, colorName); | |
| 61 } else { | |
| 62 fName.printf("BRD_%s_%s_%s_%.3f", baseName.c_str(), strategyName, colorN ame, | |
| 63 get_scale_from_sample_size(sampleSize)); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 const char* BitmapRegionDecoderBench::onGetName() { | |
| 68 return fName.c_str(); | |
| 69 } | |
| 70 | |
| 71 bool BitmapRegionDecoderBench::isSuitableFor(Backend backend) { | |
| 72 return kNonRendering_Backend == backend; | |
| 73 } | |
| 74 | |
| 75 void BitmapRegionDecoderBench::onDraw(const int n, SkCanvas* canvas) { | |
| 76 SkAutoTDelete<SkBitmapRegionDecoderInterface> brd; | |
| 77 SkAutoTDelete<SkBitmap> bitmap; | |
| 78 for (int i = 0; i < n; i++) { | |
| 79 SkStreamRewindable* stream = new SkMemoryStream(fData); | |
| 80 brd.reset(SkBitmapRegionDecoderInterface::CreateBitmapRegionDecoder(stre am, fStrategy)); | |
| 81 bitmap.reset(brd->decodeRegion(fSubset.left(), fSubset.top(), fSubset.wi dth(), | |
| 82 fSubset.height(), fSampleSize, fColorType)); | |
| 83 SkASSERT(nullptr != bitmap.get()); | |
| 84 } | |
| 85 } | |
| OLD | NEW |