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 "CodecBenchPriv.h" | 8 #include "CodecBenchPriv.h" |
9 #include "DecodingBench.h" | 9 #include "DecodingBench.h" |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
11 #include "SkData.h" | 11 #include "SkData.h" |
12 #include "SkImageDecoder.h" | 12 #include "SkImageDecoder.h" |
13 #include "SkMallocPixelRef.h" | 13 #include "SkMallocPixelRef.h" |
14 #include "SkOSFile.h" | 14 #include "SkOSFile.h" |
15 #include "SkStream.h" | 15 #include "SkStream.h" |
16 | 16 |
17 /* | 17 /* |
18 * | 18 * |
19 * This benchmark is designed to test the performance of image decoding. | 19 * This benchmark is designed to test the performance of image decoding. |
20 * It is invoked from the nanobench.cpp file. | 20 * It is invoked from the nanobench.cpp file. |
21 * | 21 * |
22 */ | 22 */ |
23 DecodingBench::DecodingBench(SkString path, SkColorType colorType) | 23 DecodingBench::DecodingBench(SkString path, SkColorType colorType) |
24 : fColorType(colorType) | 24 : fColorType(colorType) |
25 , fData(SkData::NewFromFileName(path.c_str())) | 25 , fData(SkData::NewFromFileName(path.c_str())) |
26 { | 26 { |
27 // Parse filename and the color type to give the benchmark a useful name | 27 // Parse filename and the color type to give the benchmark a useful name |
28 SkString baseName = SkOSPath::Basename(path.c_str()); | 28 SkString baseName = SkOSPath::Basename(path.c_str()); |
29 fName.printf("Decode_%s_%s", baseName.c_str(), color_type_to_str(colorType))
; | 29 fName.printf("Decode_%s_%s", baseName.c_str(), color_type_to_str(colorType))
; |
30 | 30 |
31 #ifdef SK_DEBUG | 31 #ifdef SK_DEBUG |
32 // Ensure that we can create a decoder. | 32 // Ensure that we can create a decoder. |
33 SkAutoTDelete<SkStreamRewindable> stream(new SkMemoryStream(fData)); | 33 SkAutoTDelete<SkStreamRewindable> stream(new SkMemoryStream(fData)); |
34 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream)); | 34 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream)); |
35 SkASSERT(decoder != nullptr); | 35 SkASSERT(decoder != nullptr); |
36 #endif | 36 #endif |
37 } | 37 } |
38 | 38 |
39 const char* DecodingBench::onGetName() { | 39 const char* DecodingBench::onGetName() { |
40 return fName.c_str(); | 40 return fName.c_str(); |
(...skipping 30 matching lines...) Expand all Loading... |
71 // fPixelStorage. | 71 // fPixelStorage. |
72 bm->setPixelRef(SkMallocPixelRef::NewDirect(bm->info(), | 72 bm->setPixelRef(SkMallocPixelRef::NewDirect(bm->info(), |
73 fPixelStorage, bm->rowBytes(), ct))->unref(); | 73 fPixelStorage, bm->rowBytes(), ct))->unref(); |
74 return true; | 74 return true; |
75 } | 75 } |
76 | 76 |
77 private: | 77 private: |
78 void* fPixelStorage; // Unowned. DecodingBench owns this. | 78 void* fPixelStorage; // Unowned. DecodingBench owns this. |
79 }; | 79 }; |
80 | 80 |
81 void DecodingBench::onDraw(const int n, SkCanvas* canvas) { | 81 void DecodingBench::onDraw(int n, SkCanvas* canvas) { |
82 SkBitmap bitmap; | 82 SkBitmap bitmap; |
83 // Declare the allocator before the decoder, so it will outlive the | 83 // Declare the allocator before the decoder, so it will outlive the |
84 // decoder, which will unref it. | 84 // decoder, which will unref it. |
85 TargetAllocator allocator(fPixelStorage.get()); | 85 TargetAllocator allocator(fPixelStorage.get()); |
86 SkAutoTDelete<SkImageDecoder> decoder; | 86 SkAutoTDelete<SkImageDecoder> decoder; |
87 SkAutoTDelete<SkStreamRewindable> stream; | 87 SkAutoTDelete<SkStreamRewindable> stream; |
88 for (int i = 0; i < n; i++) { | 88 for (int i = 0; i < n; i++) { |
89 // create a new stream and a new decoder to mimic the behavior of | 89 // create a new stream and a new decoder to mimic the behavior of |
90 // CodecBench. | 90 // CodecBench. |
91 stream.reset(new SkMemoryStream(fData)); | 91 stream.reset(new SkMemoryStream(fData)); |
92 decoder.reset(SkImageDecoder::Factory(stream)); | 92 decoder.reset(SkImageDecoder::Factory(stream)); |
93 decoder->setAllocator(&allocator); | 93 decoder->setAllocator(&allocator); |
94 decoder->decode(stream, &bitmap, fColorType, | 94 decoder->decode(stream, &bitmap, fColorType, |
95 SkImageDecoder::kDecodePixels_Mode); | 95 SkImageDecoder::kDecodePixels_Mode); |
96 } | 96 } |
97 } | 97 } |
OLD | NEW |