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

Side by Side Diff: bench/BitmapFractionalBench.cpp

Issue 491793003: Benchmark designed to exercise fractional image scale/translation (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Nits, add downscaling, and add low/medium/high versions Created 6 years, 4 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
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 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 "Benchmark.h"
9 #include "SkBlurMask.h"
10 #include "SkCanvas.h"
11 #include "SkPaint.h"
12 #include "SkRandom.h"
13 #include "SkShader.h"
14 #include "SkString.h"
15
16 class BitmapFractionalBench: public Benchmark {
17 int fInputSize;
18 int fOutputSize;
19 SkPaint::FilterLevel fFilterLevel;
20 SkString fName;
21
22 public:
23 BitmapFractionalBench( int is, const char *name, SkPaint::FilterLevel filter Level ) {
24 fInputSize = is;
25 fOutputSize = 2*is;
26 fFilterLevel = filterLevel;
27 fName.printf( "bitmap_fractional_bench_%s", name );
28 }
29
30 protected:
31
32 SkBitmap fInputBitmap, fOutputBitmap;
33 SkMatrix fMatrix;
34
35 virtual const char* onGetName() {
36 return fName.c_str();
37 }
38
39 int inputSize() const {
40 return fInputSize;
41 }
42
43 int outputSize() const {
44 return fOutputSize;
45 }
46
47 SkIPoint onGetSize() SK_OVERRIDE {
48 return SkIPoint::Make( fOutputSize, fOutputSize );
49 }
50
51 virtual void onPreDraw() {
52 fInputBitmap.allocN32Pixels(fInputSize, fInputSize, true);
53 fInputBitmap.eraseColor(SK_ColorWHITE);
54
55 fOutputBitmap.allocN32Pixels(fOutputSize, fOutputSize, true);
56 }
57
58 virtual void onDraw(const int loops, SkCanvas*) {
59 SkPaint paint;
60 this->setupPaint(&paint);
61
62 preBenchSetup();
63
64 SkCanvas canvas( fOutputBitmap );
65 paint.setFilterLevel(fFilterLevel);
66 fInputBitmap.notifyPixelsChanged();
67
68 for (int i = 0; i < loops; i++) {
69 // up-scale the image by a variety of close, fractional scales
70 for (int j = 0 ; j < 20 ; j++) {
71 fMatrix = SkMatrix::I();
72 fMatrix.setScale( 1 + j/500.f, 1 + j/500.f );
73 canvas.drawBitmapMatrix( fInputBitmap, fMatrix, &paint );
74 }
75 // down-scale the image by a variety of close, fractional scales
76 for (int j = 0 ; j < 20 ; j++) {
77 fMatrix = SkMatrix::I();
78 fMatrix.setScale( 1 - j/500.f, 1 - j/500.f );
79 canvas.drawBitmapMatrix( fInputBitmap, fMatrix, &paint );
80 }
81 // Now try some fractional translates
82 for (int j = 0 ; j < 20 ; j++) {
83 fMatrix = SkMatrix::I();
84 fMatrix.setTranslate( j/3.f, j/3.f );
85 canvas.drawBitmapMatrix( fInputBitmap, fMatrix, &paint );
86 }
87 // Finally, some fractional translates with non-identity scale.
88 for (int j = 0 ; j < 20 ; j++) {
89 fMatrix = SkMatrix::I();
90 fMatrix.setTranslate( j/3.f, j/3.f );
91 fMatrix.preScale( 1.5f, 1.5f );
92 canvas.drawBitmapMatrix( fInputBitmap, fMatrix, &paint );
93 }
94 }
95 }
96
97 virtual void preBenchSetup() {}
98 private:
99 typedef Benchmark INHERITED;
100 };
101
102 DEF_BENCH(return new BitmapFractionalBench(256, "high", SkPaint::kHigh_FilterLev el);)
103 DEF_BENCH(return new BitmapFractionalBench(256, "medium", SkPaint::kMedium_Filte rLevel);)
104 DEF_BENCH(return new BitmapFractionalBench(256, "low", SkPaint::kLow_FilterLevel );)
OLDNEW
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698