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 "CodecBench.h" | |
9 #include "SkBitmap.h" | |
10 #include "SkCodec.h" | |
11 #include "SkData.h" | |
12 #include "SkImageGenerator.h" | |
13 #include "SkOSFile.h" | |
14 #include "SkStream.h" | |
15 | |
16 CodecBench::CodecBench(SkString baseName, SkData* encoded, SkColorType colorType ) | |
17 : fColorType(colorType) | |
18 , fStream(new SkMemoryStream(encoded)) | |
19 { | |
20 // Parse filename and the color type to give the benchmark a useful name | |
21 const char* colorName; | |
22 switch(colorType) { | |
23 case kN32_SkColorType: | |
24 colorName = "N32"; | |
25 break; | |
26 case kRGB_565_SkColorType: | |
27 colorName = "565"; | |
28 break; | |
29 case kAlpha_8_SkColorType: | |
30 colorName = "Alpha8"; | |
31 break; | |
32 default: | |
33 colorName = "Unknown"; | |
34 } | |
35 fName.printf("Codec_%s_%s", baseName.c_str(), colorName); | |
36 #ifdef SK_DEBUG | |
37 // Ensure that we can create an SkCodec from this stream. | |
38 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate())); | |
39 SkASSERT(codec); | |
djsollen
2015/04/01 17:23:50
do the assert on line 52 to avoid the extra work.
scroggo
2015/04/01 17:40:54
You think that's better than failing earlier?
| |
40 #endif | |
41 } | |
42 | |
43 const char* CodecBench::onGetName() { | |
44 return fName.c_str(); | |
45 } | |
46 | |
47 bool CodecBench::isSuitableFor(Backend backend) { | |
48 return kNonRendering_Backend == backend; | |
49 } | |
50 | |
51 void CodecBench::onPreDraw() { | |
52 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate())); | |
53 fBitmap.allocPixels(codec->getInfo()); | |
54 } | |
55 | |
56 void CodecBench::onDraw(const int n, SkCanvas* canvas) { | |
57 SkAutoTDelete<SkCodec> codec; | |
58 for (int i = 0; i < n; i++) { | |
59 // We need to create a duplicate of fStream since SkCodec takes | |
60 // ownership | |
61 codec.reset(SkCodec::NewFromStream(fStream->duplicate())); | |
62 #ifdef SK_DEBUG | |
63 const SkImageGenerator::Result result = | |
64 #endif | |
65 codec->getPixels(fBitmap.info(), fBitmap.getPixels(), fBitmap.rowBytes() ); | |
66 SkASSERT(result == SkImageGenerator::kSuccess | |
67 || result == SkImageGenerator::kIncompleteInput); | |
68 } | |
69 } | |
OLD | NEW |