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

Side by Side Diff: bench/DisplacementBench.cpp

Issue 47553005: Cleanup displacement bench (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "SkBenchmark.h" 7 #include "SkBenchmark.h"
8 #include "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkBitmapSource.h" 9 #include "SkBitmapSource.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkDisplacementMapEffect.h" 11 #include "SkDisplacementMapEffect.h"
12 12
13 #define FILTER_WIDTH_SMALL 32 13 #define FILTER_WIDTH_SMALL 32
14 #define FILTER_HEIGHT_SMALL 32 14 #define FILTER_HEIGHT_SMALL 32
15 #define FILTER_WIDTH_LARGE 256 15 #define FILTER_WIDTH_LARGE 256
16 #define FILTER_HEIGHT_LARGE 256 16 #define FILTER_HEIGHT_LARGE 256
17 17
18 class DisplacementBaseBench : public SkBenchmark { 18 class DisplacementBaseBench : public SkBenchmark {
19 public: 19 public:
20 DisplacementBaseBench(bool small) : 20 DisplacementBaseBench(bool small) :
21 fInitialized(false), fIsSmall(small) { 21 fInitialized(false), fIsSmall(small) {
22 } 22 }
23 23
24 protected: 24 protected:
25 virtual void onPreDraw() SK_OVERRIDE { 25 virtual void onPreDraw() SK_OVERRIDE {
26 if (!fInitialized) { 26 if (!fInitialized) {
27 make_bitmap(); 27 this->makeBitmap();
28 make_checkerboard(); 28 this->makeCheckerboard();
29 fInitialized = true; 29 fInitialized = true;
30 } 30 }
31 } 31 }
32 32
33 void make_bitmap() { 33 void makeBitmap() {
34 const int w = isSmall() ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; 34 const int w = this->isSmall() ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE;
35 const int h = isSmall() ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; 35 const int h = this->isSmall() ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARG E;
36 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h); 36 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h);
37 fBitmap.allocPixels(); 37 fBitmap.allocPixels();
38 SkBitmapDevice device(fBitmap); 38 SkBitmapDevice device(fBitmap);
39 SkCanvas canvas(&device); 39 SkCanvas canvas(&device);
40 canvas.clear(0x00000000); 40 canvas.clear(0x00000000);
41 SkPaint paint; 41 SkPaint paint;
42 paint.setAntiAlias(true); 42 paint.setAntiAlias(true);
43 paint.setColor(0xFF884422); 43 paint.setColor(0xFF884422);
44 paint.setTextSize(SkIntToScalar(96)); 44 paint.setTextSize(SkIntToScalar(96));
45 const char* str = "g"; 45 const char* str = "g";
46 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(55), paint); 46 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(55), paint);
47 } 47 }
48 48
49 void make_checkerboard() { 49 void makeCheckerboard() {
50 const int w = isSmall() ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; 50 const int w = this->isSmall() ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE;
51 const int h = isSmall() ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; 51 const int h = this->isSmall() ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARG E;
52 fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, w, h); 52 fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, w, h);
53 fCheckerboard.allocPixels(); 53 fCheckerboard.allocPixels();
54 SkBitmapDevice device(fCheckerboard); 54 SkBitmapDevice device(fCheckerboard);
55 SkCanvas canvas(&device); 55 SkCanvas canvas(&device);
56 canvas.clear(0x00000000); 56 canvas.clear(0x00000000);
57 SkPaint darkPaint; 57 SkPaint darkPaint;
58 darkPaint.setColor(0xFF804020); 58 darkPaint.setColor(0xFF804020);
59 SkPaint lightPaint; 59 SkPaint lightPaint;
60 lightPaint.setColor(0xFF244484); 60 lightPaint.setColor(0xFF244484);
61 for (int y = 0; y < h; y += 16) { 61 for (int y = 0; y < h; y += 16) {
62 for (int x = 0; x < w; x += 16) { 62 for (int x = 0; x < w; x += 16) {
63 canvas.save(); 63 canvas.save();
64 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); 64 canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
65 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); 65 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
66 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); 66 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
67 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); 67 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
68 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); 68 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
69 canvas.restore(); 69 canvas.restore();
70 } 70 }
71 } 71 }
72 } 72 }
73 73
74 void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) { 74 void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) {
75 canvas->save(); 75 canvas->save();
76 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), 76 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
77 SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height()))); 77 SkIntToScalar(fBitmap.width()),
78 SkIntToScalar(fBitmap.height())));
78 canvas->drawBitmap(fBitmap, SkIntToScalar(x), SkIntToScalar(y), &paint); 79 canvas->drawBitmap(fBitmap, SkIntToScalar(x), SkIntToScalar(y), &paint);
79 canvas->restore(); 80 canvas->restore();
80 } 81 }
81 82
82 inline bool isSmall() const { return fIsSmall; } 83 inline bool isSmall() const { return fIsSmall; }
83 84
84 SkBitmap fBitmap, fCheckerboard; 85 SkBitmap fBitmap, fCheckerboard;
85 private: 86 private:
86 bool fInitialized; 87 bool fInitialized;
87 bool fIsSmall; 88 bool fIsSmall;
88 typedef SkBenchmark INHERITED; 89 typedef SkBenchmark INHERITED;
89 }; 90 };
90 91
91 class DisplacementZeroBench : public DisplacementBaseBench { 92 class DisplacementZeroBench : public DisplacementBaseBench {
92 public: 93 public:
93 DisplacementZeroBench(bool small) : INHERITED(small) { 94 DisplacementZeroBench(bool small) : INHERITED(small) {
94 } 95 }
95 96
96 protected: 97 protected:
97 virtual const char* onGetName() SK_OVERRIDE { 98 virtual const char* onGetName() SK_OVERRIDE {
98 return isSmall() ? "displacement_zero_small" : "displacement_zero_large" ; 99 return this->isSmall() ? "displacement_zero_small" : "displacement_zero_ large";
99 } 100 }
100 101
101 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 102 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
102 SkPaint paint; 103 SkPaint paint;
103 SkAutoTUnref<SkImageFilter> displ(SkNEW_ARGS(SkBitmapSource, (fCheckerbo ard))); 104 SkAutoTUnref<SkImageFilter> displ(SkNEW_ARGS(SkBitmapSource, (fCheckerbo ard)));
104 // No displacement effect 105 // No displacement effect
105 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 106 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
106 (SkDisplacementMapEffect::kR_ChannelSelectorType, 107 (SkDisplacementMapEffect::kR_ChannelSelectorType,
107 SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ)))->un ref(); 108 SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ)))->un ref();
108 109
109 for (int i = 0; i < this->getLoops(); i++) { 110 for (int i = 0; i < this->getLoops(); i++) {
110 drawClippedBitmap(canvas, 0, 0, paint); 111 this->drawClippedBitmap(canvas, 0, 0, paint);
111 } 112 }
112 } 113 }
113 114
114 private: 115 private:
115 typedef DisplacementBaseBench INHERITED; 116 typedef DisplacementBaseBench INHERITED;
116 }; 117 };
117 118
118 class DisplacementAlphaBench : public DisplacementBaseBench { 119 class DisplacementAlphaBench : public DisplacementBaseBench {
119 public: 120 public:
120 DisplacementAlphaBench(bool small) : INHERITED(small) { 121 DisplacementAlphaBench(bool small) : INHERITED(small) {
(...skipping 30 matching lines...) Expand all
151 return isSmall() ? "displacement_full_small" : "displacement_full_large" ; 152 return isSmall() ? "displacement_full_small" : "displacement_full_large" ;
152 } 153 }
153 154
154 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 155 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
155 SkPaint paint; 156 SkPaint paint;
156 SkAutoTUnref<SkImageFilter> displ(SkNEW_ARGS(SkBitmapSource, (fCheckerbo ard))); 157 SkAutoTUnref<SkImageFilter> displ(SkNEW_ARGS(SkBitmapSource, (fCheckerbo ard)));
157 // Displacement, with 2 non-alpha components 158 // Displacement, with 2 non-alpha components
158 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 159 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
159 (SkDisplacementMapEffect::kR_ChannelSelectorType, 160 (SkDisplacementMapEffect::kR_ChannelSelectorType,
160 SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ)))->u nref(); 161 SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ)))->u nref();
161 for (int i = 0; i < this->getLoops(); i++) { 162 for (int i = 0; i < this->getLoops(); ++i) {
162 drawClippedBitmap(canvas, 200, 0, paint); 163 this->drawClippedBitmap(canvas, 200, 0, paint);
163 } 164 }
164 } 165 }
165 166
166 private: 167 private:
167 typedef DisplacementBaseBench INHERITED; 168 typedef DisplacementBaseBench INHERITED;
168 }; 169 };
169 170
170 /////////////////////////////////////////////////////////////////////////////// 171 ///////////////////////////////////////////////////////////////////////////////
171 172
172 DEF_BENCH( return new DisplacementZeroBench(true); ) 173 DEF_BENCH( return new DisplacementZeroBench(true); )
173 DEF_BENCH( return new DisplacementAlphaBench(true); ) 174 DEF_BENCH( return new DisplacementAlphaBench(true); )
174 DEF_BENCH( return new DisplacementFullBench(true); ) 175 DEF_BENCH( return new DisplacementFullBench(true); )
175 DEF_BENCH( return new DisplacementZeroBench(false); ) 176 DEF_BENCH( return new DisplacementZeroBench(false); )
176 DEF_BENCH( return new DisplacementAlphaBench(false); ) 177 DEF_BENCH( return new DisplacementAlphaBench(false); )
177 DEF_BENCH( return new DisplacementFullBench(false); ) 178 DEF_BENCH( return new DisplacementFullBench(false); )
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698