blob: 125c4a84cf887a0624ed7e4d0632c2188614f70f [file] [log] [blame]
msarett7f691442015-09-22 11:56:16 -07001/*
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"
msarett7f691442015-09-22 11:56:16 -070011#include "SkOSFile.h"
12
13BitmapRegionDecoderBench::BitmapRegionDecoderBench(const char* baseName, SkData* encoded,
msarett5cb48852015-11-06 08:56:32 -080014 SkBitmapRegionDecoder::Strategy strategy, SkColorType colorType,
msarett7f691442015-09-22 11:56:16 -070015 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) {
msarett5cb48852015-11-06 08:56:32 -080026 case SkBitmapRegionDecoder::kCanvas_Strategy:
msarett7f691442015-09-22 11:56:16 -070027 strategyName = "Canvas";
28 break;
msarett5cb48852015-11-06 08:56:32 -080029 case SkBitmapRegionDecoder::kAndroidCodec_Strategy:
msarett26ad17b2015-10-22 07:29:19 -070030 strategyName = "AndroidCodec";
31 break;
msarett7f691442015-09-22 11:56:16 -070032 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) {
msarett4b0778e2015-11-13 09:59:11 -080043 fName.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett7f691442015-09-22 11:56:16 -070044 }
45}
46
47const char* BitmapRegionDecoderBench::onGetName() {
48 return fName.c_str();
49}
50
51bool BitmapRegionDecoderBench::isSuitableFor(Backend backend) {
52 return kNonRendering_Backend == backend;
53}
54
joshualitt8a6697a2015-09-30 12:11:07 -070055void BitmapRegionDecoderBench::onDelayedSetup() {
msarett5cb48852015-11-06 08:56:32 -080056 fBRD.reset(SkBitmapRegionDecoder::Create(fData, fStrategy));
msarett7f691442015-09-22 11:56:16 -070057}
58
mtkleina1ebeb22015-10-01 09:43:39 -070059void BitmapRegionDecoderBench::onDraw(int n, SkCanvas* canvas) {
msarett7f691442015-09-22 11:56:16 -070060 for (int i = 0; i < n; i++) {
msarett35e5d1b2015-10-27 12:50:25 -070061 SkBitmap bm;
62 SkAssertResult(fBRD->decodeRegion(&bm, nullptr, fSubset, fSampleSize, fColorType, false));
msarett7f691442015-09-22 11:56:16 -070063 }
64}