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 "BitmapRegionDecoderBench.h"
9 #include "CodecBenchPriv.h"
10 #include "SkBitmap.h"
11 #include "SkOSFile.h"
12 
BitmapRegionDecoderBench(const char * baseName,SkData * encoded,SkBitmapRegionDecoder::Strategy strategy,SkColorType colorType,uint32_t sampleSize,const SkIRect & subset)13 BitmapRegionDecoderBench::BitmapRegionDecoderBench(const char* baseName, SkData* encoded,
14         SkBitmapRegionDecoder::Strategy strategy, SkColorType colorType,
15         uint32_t sampleSize, const SkIRect& subset)
16     : fBRD(nullptr)
17     , fData(SkRef(encoded))
18     , fStrategy(strategy)
19     , fColorType(colorType)
20     , fSampleSize(sampleSize)
21     , fSubset(subset)
22 {
23     // Choose a useful name for the region decoding strategy
24     const char* strategyName;
25     switch (strategy) {
26         case SkBitmapRegionDecoder::kCanvas_Strategy:
27             strategyName = "Canvas";
28             break;
29         case SkBitmapRegionDecoder::kAndroidCodec_Strategy:
30             strategyName = "AndroidCodec";
31             break;
32         default:
33             SkASSERT(false);
34             strategyName = "";
35             break;
36     }
37 
38     // Choose a useful name for the color type
39     const char* colorName = color_type_to_str(colorType);
40 
41     fName.printf("BRD_%s_%s_%s", baseName, strategyName, colorName);
42     if (1 != sampleSize) {
43         fName.appendf("_%.3f", 1.0f / (float) sampleSize);
44     }
45 }
46 
onGetName()47 const char* BitmapRegionDecoderBench::onGetName() {
48     return fName.c_str();
49 }
50 
isSuitableFor(Backend backend)51 bool BitmapRegionDecoderBench::isSuitableFor(Backend backend) {
52     return kNonRendering_Backend == backend;
53 }
54 
onDelayedSetup()55 void BitmapRegionDecoderBench::onDelayedSetup() {
56     fBRD.reset(SkBitmapRegionDecoder::Create(fData, fStrategy));
57 }
58 
onDraw(int n,SkCanvas * canvas)59 void BitmapRegionDecoderBench::onDraw(int n, SkCanvas* canvas) {
60     for (int i = 0; i < n; i++) {
61         SkBitmap bm;
62         SkAssertResult(fBRD->decodeRegion(&bm, nullptr, fSubset, fSampleSize, fColorType, false));
63     }
64 }
65