| 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 "CodecBench.h" | 8 #include "CodecBench.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkCodec.h" | 10 #include "SkCodec.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 const char* CodecBench::onGetName() { | 41 const char* CodecBench::onGetName() { |
| 42 return fName.c_str(); | 42 return fName.c_str(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 bool CodecBench::isSuitableFor(Backend backend) { | 45 bool CodecBench::isSuitableFor(Backend backend) { |
| 46 return kNonRendering_Backend == backend; | 46 return kNonRendering_Backend == backend; |
| 47 } | 47 } |
| 48 | 48 |
| 49 void CodecBench::onPreDraw() { | 49 void CodecBench::onPreDraw() { |
| 50 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fData)); | 50 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fData)); |
| 51 fBitmap.allocPixels(codec->getInfo().makeColorType(fColorType)); | 51 |
| 52 fInfo = codec->getInfo().makeColorType(fColorType); |
| 53 SkAlphaType alphaType; |
| 54 // Caller should not have created this CodecBench if the alpha type was |
| 55 // invalid. |
| 56 SkAssertResult(SkColorTypeValidateAlphaType(fColorType, fInfo.alphaType(), |
| 57 &alphaType)); |
| 58 if (alphaType != fInfo.alphaType()) { |
| 59 fInfo = fInfo.makeAlphaType(alphaType); |
| 60 } |
| 61 |
| 62 fStorage.reset(fInfo.getSafeSize(fInfo.minRowBytes())); |
| 52 } | 63 } |
| 53 | 64 |
| 54 void CodecBench::onDraw(const int n, SkCanvas* canvas) { | 65 void CodecBench::onDraw(const int n, SkCanvas* canvas) { |
| 55 SkAutoTDelete<SkCodec> codec; | 66 SkAutoTDelete<SkCodec> codec; |
| 67 SkPMColor colorTable[256]; |
| 68 int colorCount; |
| 56 for (int i = 0; i < n; i++) { | 69 for (int i = 0; i < n; i++) { |
| 70 colorCount = 256; |
| 57 codec.reset(SkCodec::NewFromData(fData)); | 71 codec.reset(SkCodec::NewFromData(fData)); |
| 58 #ifdef SK_DEBUG | 72 #ifdef SK_DEBUG |
| 59 const SkImageGenerator::Result result = | 73 const SkImageGenerator::Result result = |
| 60 #endif | 74 #endif |
| 61 // fBitmap.info() was set to use fColorType in onPreDraw. | 75 codec->getPixels(fInfo, fStorage.get(), fInfo.minRowBytes(), |
| 62 codec->getPixels(fBitmap.info(), fBitmap.getPixels(), fBitmap.rowBytes()
); | 76 NULL, colorTable, &colorCount); |
| 63 SkASSERT(result == SkImageGenerator::kSuccess | 77 SkASSERT(result == SkImageGenerator::kSuccess |
| 64 || result == SkImageGenerator::kIncompleteInput); | 78 || result == SkImageGenerator::kIncompleteInput); |
| 65 } | 79 } |
| 66 } | 80 } |
| OLD | NEW |