Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1128)

Side by Side Diff: bench/BitmapRegionDecoderBench.cpp

Issue 1344993003: Add nanobench tests for BitmapRegionDecoder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Benchmarks for more real use cases Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 "SkBitmap.h"
10 #include "SkCodecBenchPriv.h"
11 #include "SkCodecTools.h"
12 #include "SkOSFile.h"
13
14 BitmapRegionDecoderBench::BitmapRegionDecoderBench(const char* baseName, SkData* encoded,
15 SkBitmapRegionDecoderInterface::Strategy strategy, SkColorType colorType ,
16 uint32_t sampleSize, const SkIRect& subset)
17 : fBRD(nullptr)
18 , fData(SkRef(encoded))
19 , fStrategy(strategy)
20 , fColorType(colorType)
21 , fSampleSize(sampleSize)
22 , fSubset(subset)
23 {
24 // Choose a useful name for the region decoding strategy
25 const char* strategyName;
26 switch (strategy) {
27 case SkBitmapRegionDecoderInterface::kOriginal_Strategy:
28 strategyName = "Original";
29 break;
30 case SkBitmapRegionDecoderInterface::kCanvas_Strategy:
31 strategyName = "Canvas";
32 break;
33 default:
34 SkASSERT(false);
35 strategyName = "";
36 break;
37 }
38
39 // Choose a useful name for the color type
40 const char* colorName = color_type_to_str(colorType);
41
42 if (1 == sampleSize) {
43 fName.printf("BRD_%s_%s_%s", baseName, strategyName, colorName);
scroggo 2015/09/22 12:13:08 nit: You could do this always, and then appendf if
msarett 2015/09/22 15:27:19 Done.
44 } else {
45 fName.printf("BRD_%s_%s_%s_%.3f", baseName, strategyName, colorName,
46 get_scale_from_sample_size(sampleSize));
47 }
48 }
49
50 const char* BitmapRegionDecoderBench::onGetName() {
51 return fName.c_str();
52 }
53
54 bool BitmapRegionDecoderBench::isSuitableFor(Backend backend) {
55 return kNonRendering_Backend == backend;
56 }
57
58 void BitmapRegionDecoderBench::onPreDraw() {
59 SkStreamRewindable* stream = new SkMemoryStream(fData);
60 fBRD.reset(SkBitmapRegionDecoderInterface::CreateBitmapRegionDecoder(stream, fStrategy));
61 }
62
63 void BitmapRegionDecoderBench::onDraw(const int n, SkCanvas* canvas) {
64 SkAutoTDelete<SkBitmap> bitmap;
65 for (int i = 0; i < n; i++) {
66 bitmap.reset(fBRD->decodeRegion(fSubset.left(), fSubset.top(), fSubset.w idth(),
67 fSubset.height(), fSampleSize, fColorType));
68 SkASSERT(nullptr != bitmap.get());
69 }
70 }
OLDNEW
« no previous file with comments | « bench/BitmapRegionDecoderBench.h ('k') | bench/CodecBench.cpp » ('j') | bench/SkCodecBenchPriv.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698