Chromium Code Reviews| 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 | |
|
mtklein
2015/04/01 15:17:22
Seems fine in Release too.
scroggo
2015/04/01 17:18:04
Sure. Just unnecessary, since we do not actually d
| |
| 37 // Ensure that we can create an SkCodec from this stream. | |
| 38 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate())); | |
| 39 SkASSERT(codec); | |
| 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::onDraw(const int n, SkCanvas* canvas) { | |
| 52 SkBitmap bitmap; | |
| 53 SkAutoTDelete<SkCodec> codec; | |
| 54 for (int i = 0; i < n; i++) { | |
| 55 // We need to create a duplicate of fStream since SkCodec takes | |
| 56 // ownership | |
| 57 codec.reset(SkCodec::NewFromStream(fStream->duplicate())); | |
|
msarett
2015/04/01 14:44:36
It's unfortunate that we have to duplicate the str
scroggo
2015/04/01 14:59:49
My guess would be not much. For an SkMemoryStream,
mtklein
2015/04/01 15:17:22
Think things look more clearly cheap if we use SkC
scroggo
2015/04/01 17:18:04
NewFromData calls NewFromStream, so I don't think
mtklein
2015/04/01 17:22:19
Yeah, seems like it, if only because the nanobench
scroggo
2015/04/01 17:40:53
Done.
| |
| 58 bitmap.allocPixels(codec->getInfo()); | |
|
mtklein
2015/04/01 15:17:22
Unless you need this to make a fair apples-to-appl
scroggo
2015/04/01 17:18:04
Yes, this makes it a more fair comparison. Come to
| |
| 59 #ifdef SK_DEBUG | |
| 60 const SkImageGenerator::Result result = | |
| 61 #endif | |
| 62 codec->getPixels(bitmap.info(), bitmap.getPixels(), bitmap.rowBytes()); | |
| 63 SkASSERT(result == SkImageGenerator::kSuccess | |
| 64 || result == SkImageGenerator::kIncompleteInput); | |
| 65 } | |
| 66 } | |
| OLD | NEW |