• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 "bench/AndroidCodecBench.h"
9 #include "bench/CodecBenchPriv.h"
10 #include "include/codec/SkAndroidCodec.h"
11 #include "include/core/SkBitmap.h"
12 #include "src/core/SkOSFile.h"
13 #include "tools/flags/CommandLineFlags.h"
14 
AndroidCodecBench(SkString baseName,SkData * encoded,int sampleSize)15 AndroidCodecBench::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 
onGetName()23 const char* AndroidCodecBench::onGetName() {
24     return fName.c_str();
25 }
26 
isSuitableFor(Backend backend)27 bool AndroidCodecBench::isSuitableFor(Backend backend) {
28     return kNonRendering_Backend == backend;
29 }
30 
onDelayedSetup()31 void AndroidCodecBench::onDelayedSetup() {
32     std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(fData));
33     SkISize scaledSize = codec->getSampledDimensions(fSampleSize);
34 
35     fInfo = codec->getInfo().makeDimensions(scaledSize).makeColorType(kN32_SkColorType);
36     if (kUnpremul_SkAlphaType == fInfo.alphaType()) {
37         fInfo = fInfo.makeAlphaType(kPremul_SkAlphaType);
38     }
39 
40     fPixelStorage.reset(fInfo.computeMinByteSize());
41 }
42 
onDraw(int n,SkCanvas * canvas)43 void AndroidCodecBench::onDraw(int n, SkCanvas* canvas) {
44     std::unique_ptr<SkAndroidCodec> codec;
45     SkAndroidCodec::AndroidOptions options;
46     options.fSampleSize = fSampleSize;
47     for (int i = 0; i < n; i++) {
48         codec = SkAndroidCodec::MakeFromData(fData);
49 #ifdef SK_DEBUG
50         const SkCodec::Result result =
51 #endif
52         codec->getAndroidPixels(fInfo, fPixelStorage.get(), fInfo.minRowBytes(), &options);
53         SkASSERT(result == SkCodec::kSuccess || result == SkCodec::kIncompleteInput);
54     }
55 }
56