blob: 886e875c6dd85ad116353314ad9edd6c97f5676f [file] [log] [blame]
msarett84451022016-02-11 06:45:51 -08001/*
2 * Copyright 2016 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 "AndroidCodecBench.h"
9#include "CodecBenchPriv.h"
10#include "SkBitmap.h"
11#include "SkAndroidCodec.h"
12#include "SkCommandLineFlags.h"
13#include "SkOSFile.h"
14
15AndroidCodecBench::AndroidCodecBench(SkString baseName, SkData* encoded, int sampleSize)
16 : fData(SkRef(encoded))
17 , fSampleSize(sampleSize)
18{
19 // Parse filename and the color type to give the benchmark a useful name
20 fName.printf("AndroidCodec_%s_SampleSize%d", baseName.c_str(), sampleSize);
21}
22
23const char* AndroidCodecBench::onGetName() {
24 return fName.c_str();
25}
26
27bool AndroidCodecBench::isSuitableFor(Backend backend) {
28 return kNonRendering_Backend == backend;
29}
30
31void AndroidCodecBench::onDelayedSetup() {
Mike Reedede7bac2017-07-23 15:30:02 -040032 std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(fData));
msarett84451022016-02-11 06:45:51 -080033 SkISize scaledSize = codec->getSampledDimensions(fSampleSize);
34
35 fInfo = codec->getInfo().makeWH(scaledSize.width(), scaledSize.height())
36 .makeColorType(kN32_SkColorType);
37 if (kUnpremul_SkAlphaType == fInfo.alphaType()) {
38 fInfo = fInfo.makeAlphaType(kPremul_SkAlphaType);
39 }
40
Mike Reedf0ffb892017-10-03 14:47:21 -040041 fPixelStorage.reset(fInfo.computeMinByteSize());
msarett84451022016-02-11 06:45:51 -080042}
43
44void AndroidCodecBench::onDraw(int n, SkCanvas* canvas) {
Ben Wagner145dbcd2016-11-03 14:40:50 -040045 std::unique_ptr<SkAndroidCodec> codec;
msarett84451022016-02-11 06:45:51 -080046 SkAndroidCodec::AndroidOptions options;
47 options.fSampleSize = fSampleSize;
48 for (int i = 0; i < n; i++) {
Mike Reedede7bac2017-07-23 15:30:02 -040049 codec = SkAndroidCodec::MakeFromData(fData);
msarett84451022016-02-11 06:45:51 -080050#ifdef SK_DEBUG
51 const SkCodec::Result result =
52#endif
53 codec->getAndroidPixels(fInfo, fPixelStorage.get(), fInfo.minRowBytes(), &options);
54 SkASSERT(result == SkCodec::kSuccess || result == SkCodec::kIncompleteInput);
55 }
56}