• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 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 "BitmapRegionDecoderBench.h"
9 #include "CodecBenchPriv.h"
10 #include "SkBitmap.h"
11 #include "SkOSFile.h"
12 
BitmapRegionDecoderBench(const char * baseName,SkData * encoded,SkColorType colorType,uint32_t sampleSize,const SkIRect & subset)13 BitmapRegionDecoderBench::BitmapRegionDecoderBench(const char* baseName, SkData* encoded,
14         SkColorType colorType, uint32_t sampleSize, const SkIRect& subset)
15     : fBRD(nullptr)
16     , fData(SkRef(encoded))
17     , fColorType(colorType)
18     , fSampleSize(sampleSize)
19     , fSubset(subset)
20 {
21     // Choose a useful name for the color type
22     const char* colorName = color_type_to_str(colorType);
23 
24     fName.printf("BRD_%s_%s", baseName, colorName);
25     if (1 != sampleSize) {
26         fName.appendf("_%.3f", 1.0f / (float) sampleSize);
27     }
28 }
29 
onGetName()30 const char* BitmapRegionDecoderBench::onGetName() {
31     return fName.c_str();
32 }
33 
isSuitableFor(Backend backend)34 bool BitmapRegionDecoderBench::isSuitableFor(Backend backend) {
35     return kNonRendering_Backend == backend;
36 }
37 
onDelayedSetup()38 void BitmapRegionDecoderBench::onDelayedSetup() {
39     fBRD.reset(SkBitmapRegionDecoder::Create(fData, SkBitmapRegionDecoder::kAndroidCodec_Strategy));
40 }
41 
onDraw(int n,SkCanvas * canvas)42 void BitmapRegionDecoderBench::onDraw(int n, SkCanvas* canvas) {
43     auto ct = fBRD->computeOutputColorType(fColorType);
44     auto cs = fBRD->computeOutputColorSpace(ct, nullptr);
45     for (int i = 0; i < n; i++) {
46         SkBitmap bm;
47         SkAssertResult(fBRD->decodeRegion(&bm, nullptr, fSubset, fSampleSize, ct, false, cs));
48     }
49 }
50