2015-09-22 18:56:16 +00:00
|
|
|
/*
|
|
|
|
* 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 "SkOSFile.h"
|
|
|
|
|
|
|
|
BitmapRegionDecoderBench::BitmapRegionDecoderBench(const char* baseName, SkData* encoded,
|
2016-05-18 13:23:57 +00:00
|
|
|
SkColorType colorType, uint32_t sampleSize, const SkIRect& subset)
|
2015-09-22 18:56:16 +00:00
|
|
|
: fBRD(nullptr)
|
|
|
|
, fData(SkRef(encoded))
|
|
|
|
, fColorType(colorType)
|
|
|
|
, fSampleSize(sampleSize)
|
|
|
|
, fSubset(subset)
|
|
|
|
{
|
|
|
|
// Choose a useful name for the color type
|
|
|
|
const char* colorName = color_type_to_str(colorType);
|
|
|
|
|
2016-05-18 13:23:57 +00:00
|
|
|
fName.printf("BRD_%s_%s", baseName, colorName);
|
2015-09-22 18:56:16 +00:00
|
|
|
if (1 != sampleSize) {
|
2015-11-13 17:59:11 +00:00
|
|
|
fName.appendf("_%.3f", 1.0f / (float) sampleSize);
|
2015-09-22 18:56:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* BitmapRegionDecoderBench::onGetName() {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BitmapRegionDecoderBench::isSuitableFor(Backend backend) {
|
|
|
|
return kNonRendering_Backend == backend;
|
|
|
|
}
|
|
|
|
|
2015-09-30 19:11:07 +00:00
|
|
|
void BitmapRegionDecoderBench::onDelayedSetup() {
|
2016-09-12 19:01:44 +00:00
|
|
|
fBRD.reset(SkBitmapRegionDecoder::Create(fData, SkBitmapRegionDecoder::kAndroidCodec_Strategy));
|
2015-09-22 18:56:16 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void BitmapRegionDecoderBench::onDraw(int n, SkCanvas* canvas) {
|
2018-03-13 15:14:33 +00:00
|
|
|
auto ct = fBRD->computeOutputColorType(fColorType);
|
|
|
|
auto cs = fBRD->computeOutputColorSpace(ct, nullptr);
|
2015-09-22 18:56:16 +00:00
|
|
|
for (int i = 0; i < n; i++) {
|
2015-10-27 19:50:25 +00:00
|
|
|
SkBitmap bm;
|
2018-03-13 15:14:33 +00:00
|
|
|
SkAssertResult(fBRD->decodeRegion(&bm, nullptr, fSubset, fSampleSize, ct, false, cs));
|
2015-09-22 18:56:16 +00:00
|
|
|
}
|
|
|
|
}
|