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#ifndef BitmapRegionDecoderBench_DEFINED
9#define BitmapRegionDecoderBench_DEFINED
10
11#include "bench/Benchmark.h"
12#ifdef SK_ENABLE_ANDROID_UTILS
13#include "include/core/SkData.h"
14#include "include/core/SkImageInfo.h"
15#include "include/core/SkRefCnt.h"
16#include "include/core/SkString.h"
17
18namespace android {
19namespace skia {
20class BitmapRegionDecoder;
21}  // namespace skia
22}  // namespace android
23
24/**
25 *  Benchmark Android's BitmapRegionDecoder for a particular colorType, sampleSize, and subset.
26 *
27 *  nanobench.cpp handles creating benchmarks for interesting scaled subsets.  We strive to test
28 *  on real use cases.
29 */
30class BitmapRegionDecoderBench : public Benchmark {
31public:
32    // Calls encoded->ref()
33    BitmapRegionDecoderBench(const char* basename, SkData* encoded, SkColorType colorType,
34            uint32_t sampleSize, const SkIRect& subset);
35
36protected:
37    const char* onGetName() override;
38    bool isSuitableFor(Backend backend) override;
39    void onDraw(int n, SkCanvas* canvas) override;
40    void onDelayedSetup() override;
41
42private:
43    SkString                                            fName;
44    std::unique_ptr<android::skia::BitmapRegionDecoder> fBRD;
45    sk_sp<SkData>                                       fData;
46    const SkColorType                                   fColorType;
47    const uint32_t                                      fSampleSize;
48    const SkIRect                                       fSubset;
49    using INHERITED = Benchmark;
50};
51#endif // SK_ENABLE_ANDROID_UTILS
52#endif // BitmapRegionDecoderBench_DEFINED
53