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 "CodecBench.h" | 8 #include "CodecBench.h" |
9 #include "CodecBenchPriv.h" | 9 #include "CodecBenchPriv.h" |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
11 #include "SkCodec.h" | 11 #include "SkCodec.h" |
12 #include "SkOSFile.h" | 12 #include "SkOSFile.h" |
13 | 13 |
14 CodecBench::CodecBench(SkString baseName, SkData* encoded, SkColorType colorType ) | 14 CodecBench::CodecBench(SkString baseName, SkData* encoded, SkColorType colorType , |
15 SkAlphaType alphaType) | |
15 : fColorType(colorType) | 16 : fColorType(colorType) |
17 , fAlphaType(alphaType) | |
16 , fData(SkRef(encoded)) | 18 , fData(SkRef(encoded)) |
17 { | 19 { |
18 // Parse filename and the color type to give the benchmark a useful name | 20 // Parse filename and the color type to give the benchmark a useful name |
19 fName.printf("Codec_%s_%s", baseName.c_str(), color_type_to_str(colorType)); | 21 fName.printf("Codec_%s_%s%s", baseName.c_str(), color_type_to_str(colorType) , |
scroggo
2016/01/07 20:41:18
So for a premul, the name will be something like
msarett
2016/01/07 21:00:55
Yeah it's actually:
N32Premul
N32Unpremul
Index8Pr
| |
22 alpha_type_to_str(alphaType)); | |
20 #ifdef SK_DEBUG | 23 #ifdef SK_DEBUG |
21 // Ensure that we can create an SkCodec from this data. | 24 // Ensure that we can create an SkCodec from this data. |
22 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fData)); | 25 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fData)); |
23 SkASSERT(codec); | 26 SkASSERT(codec); |
24 #endif | 27 #endif |
25 } | 28 } |
26 | 29 |
27 const char* CodecBench::onGetName() { | 30 const char* CodecBench::onGetName() { |
28 return fName.c_str(); | 31 return fName.c_str(); |
29 } | 32 } |
30 | 33 |
31 bool CodecBench::isSuitableFor(Backend backend) { | 34 bool CodecBench::isSuitableFor(Backend backend) { |
32 return kNonRendering_Backend == backend; | 35 return kNonRendering_Backend == backend; |
33 } | 36 } |
34 | 37 |
35 void CodecBench::onDelayedSetup() { | 38 void CodecBench::onDelayedSetup() { |
36 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fData)); | 39 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fData)); |
37 | 40 |
38 fInfo = codec->getInfo().makeColorType(fColorType); | 41 fInfo = codec->getInfo().makeColorType(fColorType).makeAlphaType(fAlphaType) ; |
39 SkAlphaType alphaType; | |
40 // Caller should not have created this CodecBench if the alpha type was | |
41 // invalid. | |
42 SkAssertResult(SkColorTypeValidateAlphaType(fColorType, fInfo.alphaType(), | |
43 &alphaType)); | |
44 if (alphaType != fInfo.alphaType()) { | |
45 fInfo = fInfo.makeAlphaType(alphaType); | |
46 } | |
47 | 42 |
48 fPixelStorage.reset(fInfo.getSafeSize(fInfo.minRowBytes())); | 43 fPixelStorage.reset(fInfo.getSafeSize(fInfo.minRowBytes())); |
49 } | 44 } |
50 | 45 |
51 void CodecBench::onDraw(int n, SkCanvas* canvas) { | 46 void CodecBench::onDraw(int n, SkCanvas* canvas) { |
52 SkAutoTDelete<SkCodec> codec; | 47 SkAutoTDelete<SkCodec> codec; |
53 SkPMColor colorTable[256]; | 48 SkPMColor colorTable[256]; |
54 int colorCount; | 49 int colorCount; |
55 for (int i = 0; i < n; i++) { | 50 for (int i = 0; i < n; i++) { |
56 colorCount = 256; | 51 colorCount = 256; |
57 codec.reset(SkCodec::NewFromData(fData)); | 52 codec.reset(SkCodec::NewFromData(fData)); |
58 #ifdef SK_DEBUG | 53 #ifdef SK_DEBUG |
59 const SkCodec::Result result = | 54 const SkCodec::Result result = |
60 #endif | 55 #endif |
61 codec->getPixels(fInfo, fPixelStorage.get(), fInfo.minRowBytes(), | 56 codec->getPixels(fInfo, fPixelStorage.get(), fInfo.minRowBytes(), |
62 nullptr, colorTable, &colorCount); | 57 nullptr, colorTable, &colorCount); |
63 SkASSERT(result == SkCodec::kSuccess | 58 SkASSERT(result == SkCodec::kSuccess |
64 || result == SkCodec::kIncompleteInput); | 59 || result == SkCodec::kIncompleteInput); |
65 } | 60 } |
66 } | 61 } |
OLD | NEW |