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

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: Move buildTileIndex to onPreDraw 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 "SkOSFile.h"
12
13 // FIXME (msarett): How can we share this code with DM?
14 static float get_scale_from_sample_size(uint32_t sampleSize) {
15 return 1.0f / (float) sampleSize;
16 }
17
18 BitmapRegionDecoderBench::BitmapRegionDecoderBench(const char* baseName, SkData* encoded,
19 SkBitmapRegionDecoderInterface::Strategy strategy, SkColorType colorType ,
20 uint32_t sampleSize, const SkIRect& subset)
21 : fBRD(nullptr)
22 , fData(SkRef(encoded))
23 , fStrategy(strategy)
24 , fColorType(colorType)
25 , fSampleSize(sampleSize)
26 , fSubset(subset)
27 {
28 // Choose a useful name for the region decoding strategy
29 const char* strategyName;
30 switch (strategy) {
31 case SkBitmapRegionDecoderInterface::kOriginal_Strategy:
32 strategyName = "Original";
33 break;
34 case SkBitmapRegionDecoderInterface::kCanvas_Strategy:
35 strategyName = "Canvas";
36 break;
37 default:
38 SkASSERT(false);
39 strategyName = "";
40 break;
41 }
42
43 // Choose a useful name for the color type
44 const char* colorName = color_type_to_str(colorType);
45
46 if (1 == sampleSize) {
47 fName.printf("BRD_%s_%s_%s", baseName, strategyName, colorName);
48 } else {
49 fName.printf("BRD_%s_%s_%s_%.3f", baseName, strategyName, colorName,
50 get_scale_from_sample_size(sampleSize));
51 }
52 }
53
54 const char* BitmapRegionDecoderBench::onGetName() {
55 return fName.c_str();
56 }
57
58 bool BitmapRegionDecoderBench::isSuitableFor(Backend backend) {
59 return kNonRendering_Backend == backend;
60 }
61
62 void BitmapRegionDecoderBench::onPreDraw() {
63 SkStreamRewindable* stream = new SkMemoryStream(fData);
64 fBRD.reset(SkBitmapRegionDecoderInterface::CreateBitmapRegionDecoder(stream, fStrategy));
65 }
66
67 void BitmapRegionDecoderBench::onDraw(const int n, SkCanvas* canvas) {
68 SkAutoTDelete<SkBitmap> bitmap;
69 for (int i = 0; i < n; i++) {
70 bitmap.reset(fBRD->decodeRegion(fSubset.left(), fSubset.top(), fSubset.w idth(),
71 fSubset.height(), fSampleSize, fColorType));
72 SkASSERT(nullptr != bitmap.get());
73 }
74 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698