blob: dd60b18296111ebb13bf7baf300a6ecab5f6d3fd [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,
msarettd1227a72016-05-18 06:23:57 -070014 SkColorType colorType, uint32_t sampleSize, const SkIRect& subset)
msarett7f691442015-09-22 11:56:16 -070015 : fBRD(nullptr)
16 , fData(SkRef(encoded))
msarett7f691442015-09-22 11:56:16 -070017 , fColorType(colorType)
18 , fSampleSize(sampleSize)
19 , fSubset(subset)
20{
msarett7f691442015-09-22 11:56:16 -070021 // Choose a useful name for the color type
22 const char* colorName = color_type_to_str(colorType);
23
msarettd1227a72016-05-18 06:23:57 -070024 fName.printf("BRD_%s_%s", baseName, colorName);
msarett7f691442015-09-22 11:56:16 -070025 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -080026 fName.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett7f691442015-09-22 11:56:16 -070027 }
28}
29
30const char* BitmapRegionDecoderBench::onGetName() {
31 return fName.c_str();
32}
33
34bool BitmapRegionDecoderBench::isSuitableFor(Backend backend) {
35 return kNonRendering_Backend == backend;
36}
37
joshualitt8a6697a2015-09-30 12:11:07 -070038void BitmapRegionDecoderBench::onDelayedSetup() {
reed42943c82016-09-12 12:01:44 -070039 fBRD.reset(SkBitmapRegionDecoder::Create(fData, SkBitmapRegionDecoder::kAndroidCodec_Strategy));
msarett7f691442015-09-22 11:56:16 -070040}
41
mtkleina1ebeb22015-10-01 09:43:39 -070042void BitmapRegionDecoderBench::onDraw(int n, SkCanvas* canvas) {
msarett7f691442015-09-22 11:56:16 -070043 for (int i = 0; i < n; i++) {
msarett35e5d1b2015-10-27 12:50:25 -070044 SkBitmap bm;
45 SkAssertResult(fBRD->decodeRegion(&bm, nullptr, fSubset, fSampleSize, fColorType, false));
msarett7f691442015-09-22 11:56:16 -070046 }
47}