Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Side by Side Diff: bench/CodecBench.cpp

Issue 2212493002: Convert SkAutoTUnref<SkData> to sk_sp<SkData>. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « bench/CodecBench.h ('k') | bench/EncoderBench.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkCommandLineFlags.h" 12 #include "SkCommandLineFlags.h"
13 #include "SkOSFile.h" 13 #include "SkOSFile.h"
14 14
15 // Actually zeroing the memory would throw off timing, so we just lie. 15 // Actually zeroing the memory would throw off timing, so we just lie.
16 DEFINE_bool(zero_init, false, "Pretend our destination is zero-intialized, simul ating Android?"); 16 DEFINE_bool(zero_init, false, "Pretend our destination is zero-intialized, simul ating Android?");
17 17
18 CodecBench::CodecBench(SkString baseName, SkData* encoded, SkColorType colorType , 18 CodecBench::CodecBench(SkString baseName, SkData* encoded, SkColorType colorType ,
19 SkAlphaType alphaType) 19 SkAlphaType alphaType)
20 : fColorType(colorType) 20 : fColorType(colorType)
21 , fAlphaType(alphaType) 21 , fAlphaType(alphaType)
22 , fData(SkRef(encoded)) 22 , fData(SkRef(encoded))
23 { 23 {
24 // Parse filename and the color type to give the benchmark a useful name 24 // Parse filename and the color type to give the benchmark a useful name
25 fName.printf("Codec_%s_%s%s", baseName.c_str(), color_type_to_str(colorType) , 25 fName.printf("Codec_%s_%s%s", baseName.c_str(), color_type_to_str(colorType) ,
26 alpha_type_to_str(alphaType)); 26 alpha_type_to_str(alphaType));
27 #ifdef SK_DEBUG 27 #ifdef SK_DEBUG
28 // Ensure that we can create an SkCodec from this data. 28 // Ensure that we can create an SkCodec from this data.
29 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fData)); 29 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fData.get()));
30 SkASSERT(codec); 30 SkASSERT(codec);
31 #endif 31 #endif
32 } 32 }
33 33
34 const char* CodecBench::onGetName() { 34 const char* CodecBench::onGetName() {
35 return fName.c_str(); 35 return fName.c_str();
36 } 36 }
37 37
38 bool CodecBench::isSuitableFor(Backend backend) { 38 bool CodecBench::isSuitableFor(Backend backend) {
39 return kNonRendering_Backend == backend; 39 return kNonRendering_Backend == backend;
40 } 40 }
41 41
42 void CodecBench::onDelayedSetup() { 42 void CodecBench::onDelayedSetup() {
43 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fData)); 43 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fData.get()));
44 44
45 fInfo = codec->getInfo().makeColorType(fColorType) 45 fInfo = codec->getInfo().makeColorType(fColorType)
46 .makeAlphaType(fAlphaType) 46 .makeAlphaType(fAlphaType)
47 .makeColorSpace(nullptr); 47 .makeColorSpace(nullptr);
48 48
49 fPixelStorage.reset(fInfo.getSafeSize(fInfo.minRowBytes())); 49 fPixelStorage.reset(fInfo.getSafeSize(fInfo.minRowBytes()));
50 } 50 }
51 51
52 void CodecBench::onDraw(int n, SkCanvas* canvas) { 52 void CodecBench::onDraw(int n, SkCanvas* canvas) {
53 SkAutoTDelete<SkCodec> codec; 53 SkAutoTDelete<SkCodec> codec;
54 SkPMColor colorTable[256]; 54 SkPMColor colorTable[256];
55 int colorCount; 55 int colorCount;
56 SkCodec::Options options; 56 SkCodec::Options options;
57 if (FLAGS_zero_init) { 57 if (FLAGS_zero_init) {
58 options.fZeroInitialized = SkCodec::kYes_ZeroInitialized; 58 options.fZeroInitialized = SkCodec::kYes_ZeroInitialized;
59 } 59 }
60 for (int i = 0; i < n; i++) { 60 for (int i = 0; i < n; i++) {
61 colorCount = 256; 61 colorCount = 256;
62 codec.reset(SkCodec::NewFromData(fData)); 62 codec.reset(SkCodec::NewFromData(fData.get()));
63 #ifdef SK_DEBUG 63 #ifdef SK_DEBUG
64 const SkCodec::Result result = 64 const SkCodec::Result result =
65 #endif 65 #endif
66 codec->getPixels(fInfo, fPixelStorage.get(), fInfo.minRowBytes(), 66 codec->getPixels(fInfo, fPixelStorage.get(), fInfo.minRowBytes(),
67 &options, colorTable, &colorCount); 67 &options, colorTable, &colorCount);
68 SkASSERT(result == SkCodec::kSuccess 68 SkASSERT(result == SkCodec::kSuccess
69 || result == SkCodec::kIncompleteInput); 69 || result == SkCodec::kIncompleteInput);
70 } 70 }
71 } 71 }
OLDNEW
« no previous file with comments | « bench/CodecBench.h ('k') | bench/EncoderBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698