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 "DecodingSubsetBench.h" |
| 9 #include "SkData.h" |
| 10 #include "SkImageDecoder.h" |
| 11 #include "SkOSFile.h" |
| 12 #include "SkStream.h" |
| 13 |
| 14 /* |
| 15 * |
| 16 * This benchmark is designed to test the performance of image subset decoding. |
| 17 * It is invoked from the nanobench.cpp file. |
| 18 * |
| 19 */ |
| 20 DecodingSubsetBench::DecodingSubsetBench(SkString path, SkColorType colorType, |
| 21 const int divisor) |
| 22 : fColorType(colorType) |
| 23 , fDivisor(divisor) |
| 24 { |
| 25 // Parse filename and the color type to give the benchmark a useful name |
| 26 SkString baseName = SkOSPath::Basename(path.c_str()); |
| 27 const char* colorName; |
| 28 switch(colorType) { |
| 29 case kN32_SkColorType: |
| 30 colorName = "N32"; |
| 31 break; |
| 32 case kRGB_565_SkColorType: |
| 33 colorName = "565"; |
| 34 break; |
| 35 case kAlpha_8_SkColorType: |
| 36 colorName = "Alpha8"; |
| 37 break; |
| 38 default: |
| 39 colorName = "Unknown"; |
| 40 } |
| 41 fName.printf("DecodeSubset_%dx%d_%s_%s", fDivisor, fDivisor, |
| 42 baseName.c_str(), colorName); |
| 43 |
| 44 // Perform the decode setup |
| 45 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| 46 fStream.reset(new SkMemoryStream(encoded)); |
| 47 fDecoder.reset(SkImageDecoder::Factory(fStream)); |
| 48 } |
| 49 |
| 50 const char* DecodingSubsetBench::onGetName() { |
| 51 return fName.c_str(); |
| 52 } |
| 53 |
| 54 bool DecodingSubsetBench::isSuitableFor(Backend backend) { |
| 55 return kNonRendering_Backend == backend; |
| 56 } |
| 57 |
| 58 void DecodingSubsetBench::onDraw(const int n, SkCanvas* canvas) { |
| 59 for (int i = 0; i < n; i++) { |
| 60 int w, h; |
| 61 fDecoder->buildTileIndex(fStream->duplicate(), &w, &h); |
| 62 // Divide the image into subsets and decode each subset |
| 63 const int sW = w / fDivisor; |
| 64 const int sH = h / fDivisor; |
| 65 for (int y = 0; y < h; y += sH) { |
| 66 for (int x = 0; x < w; x += sW) { |
| 67 SkBitmap bitmap; |
| 68 SkIRect rect = SkIRect::MakeXYWH(x, y, sW, sH); |
| 69 fDecoder->decodeSubset(&bitmap, rect, fColorType); |
| 70 } |
| 71 } |
| 72 } |
| 73 } |
OLD | NEW |