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

Side by Side Diff: bench/PatchGridBench.cpp

Issue 1842753002: Style bikeshed - remove extraneous whitespace (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 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 | « bench/PatchBench.cpp ('k') | bench/PathIterBench.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 2014 Google Inc. 2 * Copyright 2014 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 "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkGradientShader.h" 10 #include "SkGradientShader.h"
11 #include "SkPaint.h" 11 #include "SkPaint.h"
12 #include "SkPatchGrid.h" 12 #include "SkPatchGrid.h"
13 #include "SkString.h" 13 #include "SkString.h"
14 14
15 /** 15 /**
16 * This bench measures the rendering time of a gridof patches. 16 * This bench measures the rendering time of a gridof patches.
17 * This bench also tests the different combination of optional parameters for th e function 17 * This bench also tests the different combination of optional parameters for th e function
18 * (passing texture coordinates and colors, only textures coordinates, only colo rs or none). 18 * (passing texture coordinates and colors, only textures coordinates, only colo rs or none).
19 * Finally, it also has 3 possible sizes small, medium and big to test if the si ze of the patches 19 * Finally, it also has 3 possible sizes small, medium and big to test if the si ze of the patches
20 * in the grid affects time. 20 * in the grid affects time.
21 */ 21 */
22 22
23 class PatchGridBench : public Benchmark { 23 class PatchGridBench : public Benchmark {
24 24
25 public: 25 public:
26 26
27 enum Size { 27 enum Size {
28 kSmall_Size, 28 kSmall_Size,
29 kMedium_Size, 29 kMedium_Size,
30 kBig_Size 30 kBig_Size
31 }; 31 };
32 32
33 enum VertexMode { 33 enum VertexMode {
34 kNone_VertexMode, 34 kNone_VertexMode,
35 kColors_VertexMode, 35 kColors_VertexMode,
36 kTexCoords_VertexMode, 36 kTexCoords_VertexMode,
37 kBoth_VertexMode 37 kBoth_VertexMode
38 }; 38 };
39 39
40 PatchGridBench(Size size, VertexMode vertexMode) 40 PatchGridBench(Size size, VertexMode vertexMode)
41 : fVertexMode(vertexMode) 41 : fVertexMode(vertexMode)
42 , fSize(size) { } 42 , fSize(size) { }
43 43
44 void setScale(SkCanvas* canvas){ 44 void setScale(SkCanvas* canvas){
45 switch (fSize) { 45 switch (fSize) {
46 case kSmall_Size: 46 case kSmall_Size:
47 canvas->scale(0.1f, 0.1f); 47 canvas->scale(0.1f, 0.1f);
48 break; 48 break;
49 case kMedium_Size: 49 case kMedium_Size:
50 canvas->scale(1.0f, 1.0f); 50 canvas->scale(1.0f, 1.0f);
51 break; 51 break;
52 case kBig_Size: 52 case kBig_Size:
53 canvas->scale(3.0f, 3.0f); 53 canvas->scale(3.0f, 3.0f);
54 break; 54 break;
55 } 55 }
56 } 56 }
57 57
58 void setGrid() { 58 void setGrid() {
59 SkPoint vertices[4][5] = { 59 SkPoint vertices[4][5] = {
60 {{50,50}, {150,50}, {250,50},{350,50},{450,50}}, 60 {{50,50}, {150,50}, {250,50},{350,50},{450,50}},
61 {{50,150}, {120,120}, {250,150},{350,150},{450,150}}, 61 {{50,150}, {120,120}, {250,150},{350,150},{450,150}},
62 {{50,250}, {150,250}, {250,250},{350,250},{450,250}}, 62 {{50,250}, {150,250}, {250,250},{350,250},{450,250}},
63 {{100,300}, {150,350}, {250,350},{350,350},{450,350}} 63 {{100,300}, {150,350}, {250,350},{350,350},{450,350}}
64 }; 64 };
65 65
66 SkColor cornerColors[4][5] = { 66 SkColor cornerColors[4][5] = {
67 {SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE} , 67 {SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE} ,
68 {SK_ColorRED, SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE, SK_ColorRED}, 68 {SK_ColorRED, SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE, SK_ColorRED},
69 {SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE} , 69 {SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE} ,
70 {SK_ColorRED, SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE, SK_ColorRED}, 70 {SK_ColorRED, SK_ColorBLUE, SK_ColorRED, SK_ColorBLUE, SK_ColorRED},
71 }; 71 };
72 72
73 SkPoint texCoords[4][5] = { 73 SkPoint texCoords[4][5] = {
74 {{0.0f,0.0f}, {1.0f,0.0f}, {2.0f,0.0f}, {3.0f,0.0f}, {4.0f,0.0f}}, 74 {{0.0f,0.0f}, {1.0f,0.0f}, {2.0f,0.0f}, {3.0f,0.0f}, {4.0f,0.0f}},
75 {{0.0f,1.0f}, {1.0f,1.0f}, {2.0f,1.0f}, {3.0f,1.0f}, {4.0f,1.0f}}, 75 {{0.0f,1.0f}, {1.0f,1.0f}, {2.0f,1.0f}, {3.0f,1.0f}, {4.0f,1.0f}},
76 {{0.0f,2.0f}, {1.0f,2.0f}, {2.0f,2.0f}, {3.0f,2.0f}, {4.0f,2.0f}}, 76 {{0.0f,2.0f}, {1.0f,2.0f}, {2.0f,2.0f}, {3.0f,2.0f}, {4.0f,2.0f}},
77 {{0.0f,3.0f}, {1.0f,3.0f}, {2.0f,3.0f}, {3.0f,3.0f}, {4.0f,3.0f}}, 77 {{0.0f,3.0f}, {1.0f,3.0f}, {2.0f,3.0f}, {3.0f,3.0f}, {4.0f,3.0f}},
78 }; 78 };
79 79
80 SkPoint hrzCtrl[4][8] = { 80 SkPoint hrzCtrl[4][8] = {
81 {{75,30},{125,45},{175,70},{225,20},{275,50},{325,50},{375,5},{425,9 0}}, 81 {{75,30},{125,45},{175,70},{225,20},{275,50},{325,50},{375,5},{425,9 0}},
82 {{75,150},{125,150},{175,150},{225,150},{275,150},{325,150},{375,150 },{425,150}}, 82 {{75,150},{125,150},{175,150},{225,150},{275,150},{325,150},{375,150 },{425,150}},
83 {{75,250},{125,250},{175,250},{225,250},{275,200},{325,150},{375,250 },{425,250}}, 83 {{75,250},{125,250},{175,250},{225,250},{275,200},{325,150},{375,250 },{425,250}},
84 {{75,350},{125,350},{175,350},{225,350},{275,350},{325,350},{375,350 },{425,350}} 84 {{75,350},{125,350},{175,350},{225,350},{275,350},{325,350},{375,350 },{425,350}}
85 }; 85 };
86 86
87 SkPoint vrtCtrl[6][5] = { 87 SkPoint vrtCtrl[6][5] = {
88 {{50,75},{150,75},{250,75},{350,75},{450,75}}, 88 {{50,75},{150,75},{250,75},{350,75},{450,75}},
89 {{50,125},{150,125},{250,125},{350,125},{450,125}}, 89 {{50,125},{150,125},{250,125},{350,125},{450,125}},
90 {{50,175},{150,175},{220,225},{350,175},{470,225}}, 90 {{50,175},{150,175},{220,225},{350,175},{470,225}},
91 {{50,225},{150,225},{220,175},{350,225},{470,155}}, 91 {{50,225},{150,225},{220,175},{350,225},{470,155}},
92 {{50,275},{150,275},{250,275},{350,275},{400,305}}, 92 {{50,275},{150,275},{250,275},{350,275},{400,305}},
93 {{50,325},{150,325},{250,325},{350,325},{450,325}} 93 {{50,325},{150,325},{250,325},{350,325},{450,325}}
94 }; 94 };
95 95
96 static const int kRows = 3; 96 static const int kRows = 3;
97 static const int kCols = 4; 97 static const int kCols = 4;
98 98
99 fGrid.reset(kRows, kCols, SkPatchGrid::kColors_VertexType, nullptr); 99 fGrid.reset(kRows, kCols, SkPatchGrid::kColors_VertexType, nullptr);
100 for (int i = 0; i < kRows; i++) { 100 for (int i = 0; i < kRows; i++) {
101 for (int j = 0; j < kCols; j++) { 101 for (int j = 0; j < kCols; j++) {
102 SkPoint points[12]; 102 SkPoint points[12];
103 103
104 //set corners 104 //set corners
105 points[SkPatchUtils::kTopP0_CubicCtrlPts] = vertices[i][j]; 105 points[SkPatchUtils::kTopP0_CubicCtrlPts] = vertices[i][j];
106 points[SkPatchUtils::kTopP3_CubicCtrlPts] = vertices[i][j + 1]; 106 points[SkPatchUtils::kTopP3_CubicCtrlPts] = vertices[i][j + 1];
107 points[SkPatchUtils::kBottomP0_CubicCtrlPts] = vertices[i + 1][j ]; 107 points[SkPatchUtils::kBottomP0_CubicCtrlPts] = vertices[i + 1][j ];
108 points[SkPatchUtils::kBottomP3_CubicCtrlPts] = vertices[i + 1][j + 1]; 108 points[SkPatchUtils::kBottomP3_CubicCtrlPts] = vertices[i + 1][j + 1];
109 109
110 points[SkPatchUtils::kTopP1_CubicCtrlPts] = hrzCtrl[i][j * 2]; 110 points[SkPatchUtils::kTopP1_CubicCtrlPts] = hrzCtrl[i][j * 2];
111 points[SkPatchUtils::kTopP2_CubicCtrlPts] = hrzCtrl[i][j * 2 + 1 ]; 111 points[SkPatchUtils::kTopP2_CubicCtrlPts] = hrzCtrl[i][j * 2 + 1 ];
112 points[SkPatchUtils::kBottomP1_CubicCtrlPts] = hrzCtrl[i + 1][j * 2]; 112 points[SkPatchUtils::kBottomP1_CubicCtrlPts] = hrzCtrl[i + 1][j * 2];
113 points[SkPatchUtils::kBottomP2_CubicCtrlPts] = hrzCtrl[i + 1][j * 2 + 1]; 113 points[SkPatchUtils::kBottomP2_CubicCtrlPts] = hrzCtrl[i + 1][j * 2 + 1];
114 114
115 points[SkPatchUtils::kLeftP1_CubicCtrlPts] = vrtCtrl[i * 2][j]; 115 points[SkPatchUtils::kLeftP1_CubicCtrlPts] = vrtCtrl[i * 2][j];
116 points[SkPatchUtils::kLeftP2_CubicCtrlPts] = vrtCtrl[i * 2 + 1][ j]; 116 points[SkPatchUtils::kLeftP2_CubicCtrlPts] = vrtCtrl[i * 2 + 1][ j];
117 points[SkPatchUtils::kRightP1_CubicCtrlPts] = vrtCtrl[i * 2][j + 1]; 117 points[SkPatchUtils::kRightP1_CubicCtrlPts] = vrtCtrl[i * 2][j + 1];
118 points[SkPatchUtils::kRightP2_CubicCtrlPts] = vrtCtrl[i * 2 + 1] [j + 1]; 118 points[SkPatchUtils::kRightP2_CubicCtrlPts] = vrtCtrl[i * 2 + 1] [j + 1];
119 119
120 SkColor colors[4]; 120 SkColor colors[4];
121 colors[0] = cornerColors[i][j]; 121 colors[0] = cornerColors[i][j];
122 colors[1] = cornerColors[i][j + 1]; 122 colors[1] = cornerColors[i][j + 1];
123 colors[3] = cornerColors[i + 1][j]; 123 colors[3] = cornerColors[i + 1][j];
124 colors[2] = cornerColors[i + 1][j + 1]; 124 colors[2] = cornerColors[i + 1][j + 1];
125 125
126 SkPoint texs[4]; 126 SkPoint texs[4];
127 texs[0] = texCoords[i][j]; 127 texs[0] = texCoords[i][j];
128 texs[1] = texCoords[i][j + 1]; 128 texs[1] = texCoords[i][j + 1];
129 texs[3] = texCoords[i + 1][j]; 129 texs[3] = texCoords[i + 1][j];
130 texs[2] = texCoords[i + 1][j + 1]; 130 texs[2] = texCoords[i + 1][j + 1];
131 131
132 switch (fVertexMode) { 132 switch (fVertexMode) {
133 case kNone_VertexMode: 133 case kNone_VertexMode:
134 fGrid.setPatch(j, i, points, nullptr, nullptr); 134 fGrid.setPatch(j, i, points, nullptr, nullptr);
135 break; 135 break;
136 case kColors_VertexMode: 136 case kColors_VertexMode:
137 fGrid.setPatch(j, i, points, colors, nullptr); 137 fGrid.setPatch(j, i, points, colors, nullptr);
138 break; 138 break;
139 case kTexCoords_VertexMode: 139 case kTexCoords_VertexMode:
140 fGrid.setPatch(j, i, points, nullptr, texs); 140 fGrid.setPatch(j, i, points, nullptr, texs);
141 break; 141 break;
142 case kBoth_VertexMode: 142 case kBoth_VertexMode:
143 fGrid.setPatch(j, i, points, colors, texs); 143 fGrid.setPatch(j, i, points, colors, texs);
144 break; 144 break;
145 default: 145 default:
146 break; 146 break;
147 } 147 }
148 } 148 }
149 } 149 }
150 } 150 }
151 151
152 // override this method to change the shader 152 // override this method to change the shader
153 sk_sp<SkShader> createShader() { 153 sk_sp<SkShader> createShader() {
154 const SkColor colors[] = { 154 const SkColor colors[] = {
155 SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE, 155 SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE,
156 SK_ColorMAGENTA, SK_ColorBLUE, SK_ColorYELLOW, 156 SK_ColorMAGENTA, SK_ColorBLUE, SK_ColorYELLOW,
157 }; 157 };
158 const SkPoint pts[] = { { 200.f / 4.f, 0.f }, { 3.f * 200.f / 4, 200.f } }; 158 const SkPoint pts[] = { { 200.f / 4.f, 0.f }, { 3.f * 200.f / 4, 200.f } };
159 159
160 return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT (colors), 160 return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT (colors),
161 SkShader::kMirror_TileMode); 161 SkShader::kMirror_TileMode);
162 } 162 }
163 163
164 protected: 164 protected:
165 const char* onGetName() override { 165 const char* onGetName() override {
166 SkString vertexMode; 166 SkString vertexMode;
167 switch (fVertexMode) { 167 switch (fVertexMode) {
168 case kNone_VertexMode: 168 case kNone_VertexMode:
169 vertexMode.set("meshlines"); 169 vertexMode.set("meshlines");
170 break; 170 break;
171 case kColors_VertexMode: 171 case kColors_VertexMode:
172 vertexMode.set("colors"); 172 vertexMode.set("colors");
173 break; 173 break;
174 case kTexCoords_VertexMode: 174 case kTexCoords_VertexMode:
175 vertexMode.set("texs"); 175 vertexMode.set("texs");
176 break; 176 break;
177 case kBoth_VertexMode: 177 case kBoth_VertexMode:
178 vertexMode.set("colors_texs"); 178 vertexMode.set("colors_texs");
179 break; 179 break;
180 default: 180 default:
181 break; 181 break;
182 } 182 }
183 183
184 SkString size; 184 SkString size;
185 switch (fSize) { 185 switch (fSize) {
186 case kSmall_Size: 186 case kSmall_Size:
187 size.set("small"); 187 size.set("small");
188 break; 188 break;
189 case kMedium_Size: 189 case kMedium_Size:
190 size.set("medium"); 190 size.set("medium");
191 break; 191 break;
192 case kBig_Size: 192 case kBig_Size:
193 size.set("big"); 193 size.set("big");
194 break; 194 break;
195 default: 195 default:
196 break; 196 break;
197 } 197 }
198 fName.printf("patch_grid_%s_%s", vertexMode.c_str(), size.c_str()); 198 fName.printf("patch_grid_%s_%s", vertexMode.c_str(), size.c_str());
199 return fName.c_str(); 199 return fName.c_str();
200 } 200 }
201 201
202 void onDelayedSetup() override { 202 void onDelayedSetup() override {
203 this->setGrid(); 203 this->setGrid();
204 switch (fVertexMode) { 204 switch (fVertexMode) {
205 case kTexCoords_VertexMode: 205 case kTexCoords_VertexMode:
206 case kBoth_VertexMode: 206 case kBoth_VertexMode:
207 fPaint.setShader(createShader()); 207 fPaint.setShader(createShader());
208 break; 208 break;
209 default: 209 default:
210 fPaint.setShader(nullptr); 210 fPaint.setShader(nullptr);
211 break; 211 break;
212 } 212 }
213 this->setupPaint(&fPaint); 213 this->setupPaint(&fPaint);
214 } 214 }
215 215
216 void onDraw(int loops, SkCanvas* canvas) override { 216 void onDraw(int loops, SkCanvas* canvas) override {
217 this->setScale(canvas); 217 this->setScale(canvas);
218 for (int i = 0; i < loops; i++) { 218 for (int i = 0; i < loops; i++) {
219 fGrid.draw(canvas, fPaint); 219 fGrid.draw(canvas, fPaint);
220 } 220 }
221 } 221 }
222 222
223 SkPaint fPaint; 223 SkPaint fPaint;
224 SkString fName; 224 SkString fName;
225 SkPatchGrid fGrid; 225 SkPatchGrid fGrid;
226 VertexMode fVertexMode; 226 VertexMode fVertexMode;
227 Size fSize; 227 Size fSize;
228 228
229 typedef Benchmark INHERITED; 229 typedef Benchmark INHERITED;
230 }; 230 };
231 231
232 232
233 /////////////////////////////////////////////////////////////////////////////// 233 ///////////////////////////////////////////////////////////////////////////////
234 234
235 DEF_BENCH( return new PatchGridBench(PatchGridBench::kSmall_Size, 235 DEF_BENCH( return new PatchGridBench(PatchGridBench::kSmall_Size,
236 PatchGridBench::kNone_VertexMode); ) 236 PatchGridBench::kNone_VertexMode); )
237 DEF_BENCH( return new PatchGridBench(PatchGridBench::kSmall_Size, 237 DEF_BENCH( return new PatchGridBench(PatchGridBench::kSmall_Size,
238 PatchGridBench::kColors_VertexMode); ) 238 PatchGridBench::kColors_VertexMode); )
(...skipping 10 matching lines...) Expand all
249 DEF_BENCH( return new PatchGridBench(PatchGridBench::kMedium_Size, 249 DEF_BENCH( return new PatchGridBench(PatchGridBench::kMedium_Size,
250 PatchGridBench::kBoth_VertexMode); ) 250 PatchGridBench::kBoth_VertexMode); )
251 DEF_BENCH( return new PatchGridBench(PatchGridBench::kBig_Size, 251 DEF_BENCH( return new PatchGridBench(PatchGridBench::kBig_Size,
252 PatchGridBench::kNone_VertexMode); ) 252 PatchGridBench::kNone_VertexMode); )
253 DEF_BENCH( return new PatchGridBench(PatchGridBench::kBig_Size, 253 DEF_BENCH( return new PatchGridBench(PatchGridBench::kBig_Size,
254 PatchGridBench::kColors_VertexMode); ) 254 PatchGridBench::kColors_VertexMode); )
255 DEF_BENCH( return new PatchGridBench(PatchGridBench::kBig_Size, 255 DEF_BENCH( return new PatchGridBench(PatchGridBench::kBig_Size,
256 PatchGridBench::kTexCoords_VertexMode); ) 256 PatchGridBench::kTexCoords_VertexMode); )
257 DEF_BENCH( return new PatchGridBench(PatchGridBench::kBig_Size, 257 DEF_BENCH( return new PatchGridBench(PatchGridBench::kBig_Size,
258 PatchGridBench::kBoth_VertexMode); ) 258 PatchGridBench::kBoth_VertexMode); )
OLDNEW
« no previous file with comments | « bench/PatchBench.cpp ('k') | bench/PathIterBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698