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 "SkCodecTools.h"
|
|
|
|
#include "SkOSFile.h"
|
|
|
|
|
|
|
|
BitmapRegionDecoderBench::BitmapRegionDecoderBench(const char* baseName, SkData* encoded,
|
2015-11-06 16:56:32 +00:00
|
|
|
SkBitmapRegionDecoder::Strategy strategy, SkColorType colorType,
|
2015-09-22 18:56:16 +00:00
|
|
|
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) {
|
2015-11-06 16:56:32 +00:00
|
|
|
case SkBitmapRegionDecoder::kOriginal_Strategy:
|
2015-09-22 18:56:16 +00:00
|
|
|
strategyName = "Original";
|
|
|
|
break;
|
2015-11-06 16:56:32 +00:00
|
|
|
case SkBitmapRegionDecoder::kCanvas_Strategy:
|
2015-09-22 18:56:16 +00:00
|
|
|
strategyName = "Canvas";
|
|
|
|
break;
|
2015-11-06 16:56:32 +00:00
|
|
|
case SkBitmapRegionDecoder::kAndroidCodec_Strategy:
|
2015-10-22 14:29:19 +00:00
|
|
|
strategyName = "AndroidCodec";
|
|
|
|
break;
|
2015-09-22 18:56:16 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-09-30 19:11:07 +00:00
|
|
|
void BitmapRegionDecoderBench::onDelayedSetup() {
|
2015-11-06 16:56:32 +00:00
|
|
|
fBRD.reset(SkBitmapRegionDecoder::Create(fData, fStrategy));
|
2015-09-22 18:56:16 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void BitmapRegionDecoderBench::onDraw(int n, SkCanvas* canvas) {
|
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;
|
|
|
|
SkAssertResult(fBRD->decodeRegion(&bm, nullptr, fSubset, fSampleSize, fColorType, false));
|
2015-09-22 18:56:16 +00:00
|
|
|
}
|
|
|
|
}
|