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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/BitmapRegionDecoderBench.h"
|
2020-05-04 14:02:45 +00:00
|
|
|
#ifdef SK_ENABLE_ANDROID_UTILS
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/CodecBenchPriv.h"
|
2020-05-04 14:02:45 +00:00
|
|
|
#include "client_utils/android/BitmapRegionDecoder.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "src/core/SkOSFile.h"
|
2015-09-22 18:56:16 +00:00
|
|
|
|
|
|
|
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() {
|
2020-05-04 14:02:45 +00:00
|
|
|
fBRD = android::skia::BitmapRegionDecoder::Make(fData);
|
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
|
|
|
}
|
|
|
|
}
|
2020-05-04 14:02:45 +00:00
|
|
|
#endif // SK_ENABLE_ANDROID_UTILS
|