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

Side by Side Diff: bench/DisplacementBench.cpp

Issue 1343123002: Convert unit tests, GMs from SkBitmapSource to SkImagesource (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: review comments 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
« no previous file with comments | « no previous file | bench/MergeBench.cpp » ('j') | 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 7
8 #include "Benchmark.h" 8 #include "Benchmark.h"
9 #include "SkBitmapSource.h"
10 #include "SkCanvas.h" 9 #include "SkCanvas.h"
11 #include "SkDisplacementMapEffect.h" 10 #include "SkDisplacementMapEffect.h"
11 #include "SkImageSource.h"
12 #include "SkSurface.h"
12 13
13 #define FILTER_WIDTH_SMALL 32 14 #define FILTER_WIDTH_SMALL 32
14 #define FILTER_HEIGHT_SMALL 32 15 #define FILTER_HEIGHT_SMALL 32
15 #define FILTER_WIDTH_LARGE 256 16 #define FILTER_WIDTH_LARGE 256
16 #define FILTER_HEIGHT_LARGE 256 17 #define FILTER_HEIGHT_LARGE 256
17 18
18 class DisplacementBaseBench : public Benchmark { 19 class DisplacementBaseBench : public Benchmark {
19 public: 20 public:
20 DisplacementBaseBench(bool small) : 21 DisplacementBaseBench(bool small) :
21 fInitialized(false), fIsSmall(small) { 22 fInitialized(false), fIsSmall(small) {
(...skipping 18 matching lines...) Expand all
40 paint.setAntiAlias(true); 41 paint.setAntiAlias(true);
41 paint.setColor(0xFF884422); 42 paint.setColor(0xFF884422);
42 paint.setTextSize(SkIntToScalar(96)); 43 paint.setTextSize(SkIntToScalar(96));
43 const char* str = "g"; 44 const char* str = "g";
44 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(55), paint); 45 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(55), paint);
45 } 46 }
46 47
47 void makeCheckerboard() { 48 void makeCheckerboard() {
48 const int w = this->isSmall() ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; 49 const int w = this->isSmall() ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE;
49 const int h = this->isSmall() ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARG E; 50 const int h = this->isSmall() ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARG E;
50 fCheckerboard.allocN32Pixels(w, h); 51 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(w, h));
51 SkCanvas canvas(fCheckerboard); 52 SkCanvas* canvas = surface->getCanvas();
52 canvas.clear(0x00000000); 53 canvas->clear(0x00000000);
53 SkPaint darkPaint; 54 SkPaint darkPaint;
54 darkPaint.setColor(0xFF804020); 55 darkPaint.setColor(0xFF804020);
55 SkPaint lightPaint; 56 SkPaint lightPaint;
56 lightPaint.setColor(0xFF244484); 57 lightPaint.setColor(0xFF244484);
57 for (int y = 0; y < h; y += 16) { 58 for (int y = 0; y < h; y += 16) {
58 for (int x = 0; x < w; x += 16) { 59 for (int x = 0; x < w; x += 16) {
59 canvas.save(); 60 canvas->save();
60 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); 61 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
61 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); 62 canvas->drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
62 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); 63 canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
63 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); 64 canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
64 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); 65 canvas->drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
65 canvas.restore(); 66 canvas->restore();
66 } 67 }
67 } 68 }
69
70 fCheckerboard.reset(surface->newImageSnapshot());
68 } 71 }
69 72
70 void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) { 73 void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) {
71 canvas->save(); 74 canvas->save();
72 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), 75 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
73 SkIntToScalar(fBitmap.width()), 76 SkIntToScalar(fBitmap.width()),
74 SkIntToScalar(fBitmap.height()))); 77 SkIntToScalar(fBitmap.height())));
75 canvas->drawBitmap(fBitmap, SkIntToScalar(x), SkIntToScalar(y), &paint); 78 canvas->drawBitmap(fBitmap, SkIntToScalar(x), SkIntToScalar(y), &paint);
76 canvas->restore(); 79 canvas->restore();
77 } 80 }
78 81
79 inline bool isSmall() const { return fIsSmall; } 82 inline bool isSmall() const { return fIsSmall; }
80 83
81 SkBitmap fBitmap, fCheckerboard; 84 SkBitmap fBitmap;
85 SkAutoTUnref<SkImage> fCheckerboard;
86
82 private: 87 private:
83 bool fInitialized; 88 bool fInitialized;
84 bool fIsSmall; 89 bool fIsSmall;
85 typedef Benchmark INHERITED; 90 typedef Benchmark INHERITED;
86 }; 91 };
87 92
88 class DisplacementZeroBench : public DisplacementBaseBench { 93 class DisplacementZeroBench : public DisplacementBaseBench {
89 public: 94 public:
90 DisplacementZeroBench(bool small) : INHERITED(small) { 95 DisplacementZeroBench(bool small) : INHERITED(small) {
91 } 96 }
92 97
93 protected: 98 protected:
94 const char* onGetName() override { 99 const char* onGetName() override {
95 return this->isSmall() ? "displacement_zero_small" : "displacement_zero_ large"; 100 return this->isSmall() ? "displacement_zero_small" : "displacement_zero_ large";
96 } 101 }
97 102
98 void onDraw(const int loops, SkCanvas* canvas) override { 103 void onDraw(const int loops, SkCanvas* canvas) override {
99 SkPaint paint; 104 SkPaint paint;
100 SkAutoTUnref<SkImageFilter> displ(SkBitmapSource::Create(fCheckerboard)) ; 105 SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard));
101 // No displacement effect 106 // No displacement effect
102 paint.setImageFilter(SkDisplacementMapEffect::Create( 107 paint.setImageFilter(SkDisplacementMapEffect::Create(
103 SkDisplacementMapEffect::kR_ChannelSelectorType, 108 SkDisplacementMapEffect::kR_ChannelSelectorType,
104 SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ))->unre f(); 109 SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ))->unre f();
105 110
106 for (int i = 0; i < loops; i++) { 111 for (int i = 0; i < loops; i++) {
107 this->drawClippedBitmap(canvas, 0, 0, paint); 112 this->drawClippedBitmap(canvas, 0, 0, paint);
108 } 113 }
109 } 114 }
110 115
111 private: 116 private:
112 typedef DisplacementBaseBench INHERITED; 117 typedef DisplacementBaseBench INHERITED;
113 }; 118 };
114 119
115 class DisplacementAlphaBench : public DisplacementBaseBench { 120 class DisplacementAlphaBench : public DisplacementBaseBench {
116 public: 121 public:
117 DisplacementAlphaBench(bool small) : INHERITED(small) { 122 DisplacementAlphaBench(bool small) : INHERITED(small) {
118 } 123 }
119 124
120 protected: 125 protected:
121 const char* onGetName() override { 126 const char* onGetName() override {
122 return isSmall() ? "displacement_alpha_small" : "displacement_alpha_larg e"; 127 return isSmall() ? "displacement_alpha_small" : "displacement_alpha_larg e";
123 } 128 }
124 129
125 void onDraw(const int loops, SkCanvas* canvas) override { 130 void onDraw(const int loops, SkCanvas* canvas) override {
126 SkPaint paint; 131 SkPaint paint;
127 SkAutoTUnref<SkImageFilter> displ(SkBitmapSource::Create(fCheckerboard)) ; 132 SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard));
128 // Displacement, with 1 alpha component (which isn't pre-multiplied) 133 // Displacement, with 1 alpha component (which isn't pre-multiplied)
129 paint.setImageFilter(SkDisplacementMapEffect::Create( 134 paint.setImageFilter(SkDisplacementMapEffect::Create(
130 SkDisplacementMapEffect::kB_ChannelSelectorType, 135 SkDisplacementMapEffect::kB_ChannelSelectorType,
131 SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ))->unr ef(); 136 SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ))->unr ef();
132 for (int i = 0; i < loops; i++) { 137 for (int i = 0; i < loops; i++) {
133 drawClippedBitmap(canvas, 100, 0, paint); 138 drawClippedBitmap(canvas, 100, 0, paint);
134 } 139 }
135 } 140 }
136 141
137 private: 142 private:
138 typedef DisplacementBaseBench INHERITED; 143 typedef DisplacementBaseBench INHERITED;
139 }; 144 };
140 145
141 class DisplacementFullBench : public DisplacementBaseBench { 146 class DisplacementFullBench : public DisplacementBaseBench {
142 public: 147 public:
143 DisplacementFullBench(bool small) : INHERITED(small) { 148 DisplacementFullBench(bool small) : INHERITED(small) {
144 } 149 }
145 150
146 protected: 151 protected:
147 const char* onGetName() override { 152 const char* onGetName() override {
148 return isSmall() ? "displacement_full_small" : "displacement_full_large" ; 153 return isSmall() ? "displacement_full_small" : "displacement_full_large" ;
149 } 154 }
150 155
151 void onDraw(const int loops, SkCanvas* canvas) override { 156 void onDraw(const int loops, SkCanvas* canvas) override {
152 SkPaint paint; 157 SkPaint paint;
153 SkAutoTUnref<SkImageFilter> displ(SkBitmapSource::Create(fCheckerboard)) ; 158 SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard));
154 // Displacement, with 2 non-alpha components 159 // Displacement, with 2 non-alpha components
155 paint.setImageFilter(SkDisplacementMapEffect::Create( 160 paint.setImageFilter(SkDisplacementMapEffect::Create(
156 SkDisplacementMapEffect::kR_ChannelSelectorType, 161 SkDisplacementMapEffect::kR_ChannelSelectorType,
157 SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ))->unr ef(); 162 SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ))->unr ef();
158 for (int i = 0; i < loops; ++i) { 163 for (int i = 0; i < loops; ++i) {
159 this->drawClippedBitmap(canvas, 200, 0, paint); 164 this->drawClippedBitmap(canvas, 200, 0, paint);
160 } 165 }
161 } 166 }
162 167
163 private: 168 private:
164 typedef DisplacementBaseBench INHERITED; 169 typedef DisplacementBaseBench INHERITED;
165 }; 170 };
166 171
167 /////////////////////////////////////////////////////////////////////////////// 172 ///////////////////////////////////////////////////////////////////////////////
168 173
169 DEF_BENCH( return new DisplacementZeroBench(true); ) 174 DEF_BENCH( return new DisplacementZeroBench(true); )
170 DEF_BENCH( return new DisplacementAlphaBench(true); ) 175 DEF_BENCH( return new DisplacementAlphaBench(true); )
171 DEF_BENCH( return new DisplacementFullBench(true); ) 176 DEF_BENCH( return new DisplacementFullBench(true); )
172 DEF_BENCH( return new DisplacementZeroBench(false); ) 177 DEF_BENCH( return new DisplacementZeroBench(false); )
173 DEF_BENCH( return new DisplacementAlphaBench(false); ) 178 DEF_BENCH( return new DisplacementAlphaBench(false); )
174 DEF_BENCH( return new DisplacementFullBench(false); ) 179 DEF_BENCH( return new DisplacementFullBench(false); )
OLDNEW
« no previous file with comments | « no previous file | bench/MergeBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698