scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 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" |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 9 | #include "CodecBenchPriv.h" |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 10 | #include "SkBitmap.h" |
| 11 | #include "SkCodec.h" |
mtklein | c146aa6 | 2016-01-08 14:20:36 -0800 | [diff] [blame] | 12 | #include "SkCommandLineFlags.h" |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 13 | #include "SkOSFile.h" |
| 14 | |
mtklein | c146aa6 | 2016-01-08 14:20:36 -0800 | [diff] [blame] | 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, simulating Android?"); |
| 17 | |
msarett | c7796b9 | 2016-01-07 14:20:20 -0800 | [diff] [blame] | 18 | CodecBench::CodecBench(SkString baseName, SkData* encoded, SkColorType colorType, |
| 19 | SkAlphaType alphaType) |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 20 | : fColorType(colorType) |
msarett | c7796b9 | 2016-01-07 14:20:20 -0800 | [diff] [blame] | 21 | , fAlphaType(alphaType) |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 22 | , fData(SkRef(encoded)) |
| 23 | { |
| 24 | // Parse filename and the color type to give the benchmark a useful name |
msarett | c7796b9 | 2016-01-07 14:20:20 -0800 | [diff] [blame] | 25 | fName.printf("Codec_%s_%s%s", baseName.c_str(), color_type_to_str(colorType), |
| 26 | alpha_type_to_str(alphaType)); |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 27 | // Ensure that we can create an SkCodec from this data. |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame^] | 28 | SkASSERT(SkCodec::MakeFromData(fData)); |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | const char* CodecBench::onGetName() { |
| 32 | return fName.c_str(); |
| 33 | } |
| 34 | |
| 35 | bool CodecBench::isSuitableFor(Backend backend) { |
| 36 | return kNonRendering_Backend == backend; |
| 37 | } |
| 38 | |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 39 | void CodecBench::onDelayedSetup() { |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame^] | 40 | std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(fData); |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 41 | |
msarett | 50ce1f2 | 2016-07-29 06:23:33 -0700 | [diff] [blame] | 42 | fInfo = codec->getInfo().makeColorType(fColorType) |
| 43 | .makeAlphaType(fAlphaType) |
| 44 | .makeColorSpace(nullptr); |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 45 | |
| 46 | fPixelStorage.reset(fInfo.getSafeSize(fInfo.minRowBytes())); |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 47 | } |
| 48 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 49 | void CodecBench::onDraw(int n, SkCanvas* canvas) { |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 50 | std::unique_ptr<SkCodec> codec; |
mtklein | c146aa6 | 2016-01-08 14:20:36 -0800 | [diff] [blame] | 51 | SkCodec::Options options; |
| 52 | if (FLAGS_zero_init) { |
| 53 | options.fZeroInitialized = SkCodec::kYes_ZeroInitialized; |
| 54 | } |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 55 | for (int i = 0; i < n; i++) { |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame^] | 56 | codec = SkCodec::MakeFromData(fData); |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 57 | #ifdef SK_DEBUG |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 58 | const SkCodec::Result result = |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 59 | #endif |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 60 | codec->getPixels(fInfo, fPixelStorage.get(), fInfo.minRowBytes(), |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 61 | &options); |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 62 | SkASSERT(result == SkCodec::kSuccess |
| 63 | || result == SkCodec::kIncompleteInput); |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 64 | } |
| 65 | } |