aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/BitmapRegionDecoderBench.cpp
blob: a98dbb0cc5fb1942f87a5649ded8d4ff6eff5735 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "BitmapRegionDecoderBench.h"
#include "CodecBenchPriv.h"
#include "SkBitmap.h"
#include "SkBitmapRegionDecoderPriv.h"
#include "SkOSFile.h"

BitmapRegionDecoderBench::BitmapRegionDecoderBench(const char* baseName, SkData* encoded,
        SkBitmapRegionDecoder::Strategy strategy, SkColorType colorType,
        uint32_t sampleSize, const SkIRect& subset)
    : fBRD(nullptr)
    , fData(SkRef(encoded))
    , fStrategy(strategy)
    , fColorType(colorType)
    , fSampleSize(sampleSize)
    , fSubset(subset)
{
    // Choose a useful name for the region decoding strategy
    const char* strategyName;
    switch (strategy) {
        case SkBitmapRegionDecoder::kCanvas_Strategy:
            strategyName = "Canvas";
            break;
        case SkBitmapRegionDecoder::kAndroidCodec_Strategy:
            strategyName = "AndroidCodec";
            break;
        default:
            SkASSERT(false);
            strategyName = "";
            break;
    }

    // Choose a useful name for the color type
    const char* colorName = color_type_to_str(colorType);

    fName.printf("BRD_%s_%s_%s", baseName, strategyName, colorName);
    if (1 != sampleSize) {
        fName.appendf("_%.3f", get_scale_from_sample_size(sampleSize));
    }
}

const char* BitmapRegionDecoderBench::onGetName() {
    return fName.c_str();
}

bool BitmapRegionDecoderBench::isSuitableFor(Backend backend) {
    return kNonRendering_Backend == backend;
}

void BitmapRegionDecoderBench::onDelayedSetup() {
    fBRD.reset(SkBitmapRegionDecoder::Create(fData, fStrategy));
}

void BitmapRegionDecoderBench::onDraw(int n, SkCanvas* canvas) {
    for (int i = 0; i < n; i++) {
        SkBitmap bm;
        SkAssertResult(fBRD->decodeRegion(&bm, nullptr, fSubset, fSampleSize, fColorType, false));
    }
}