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

Side by Side Diff: bench/PatchBench.cpp

Issue 463493002: SkCanvas::drawPatch param SkPoint[12] (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebased for SkPictureRecord 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 | gm/patch.cpp » ('j') | include/core/SkCanvas.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 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 #include "Benchmark.h"
8 #include "SkBitmap.h"
9 #include "SkCanvas.h"
10 #include "SkColorPriv.h"
11 #include "SkGradientShader.h"
12 #include "SkPaint.h"
13 #include "SkRandom.h"
14 #include "SkShader.h"
15 #include "SkString.h"
16 #include "SkTArray.h"
17
18 class PatchBench : public Benchmark {
19
20 public:
21
22 enum VertexMode {
23 kNone_VertexMode,
24 kColors_VertexMode,
25 kTexCoords_VertexMode,
26 kBoth_VertexMode
27 };
28
29 PatchBench(SkPoint scale, VertexMode vertexMode)
30 : fScale(scale)
31 , fVertexMode(vertexMode) { }
32
33 // to add name of specific class override this method
34 virtual void appendName(SkString* name) {
35 name->append("normal");
36 }
37
38 // to make other type of patches override this method
39 virtual void setCubics() {
40 const SkPoint points[SkPatchUtils::kNumCtrlPts] = {
41 //top points
42 {100,100},{150,50},{250,150}, {300,100},
43 //right points
44 {350, 150},{250,200},
45 //bottom points
46 {300,300},{250,250},{150,350},{100,300},
47 //left points
48 {50,250},{150,50}
49 };
50 memcpy(fCubics, points, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint));
51 }
52
53 virtual void setColors() {
54 const SkColor colors[SkPatchUtils::kNumCorners] = {
55 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorCYAN
56 };
57 memcpy(fColors, colors, SkPatchUtils::kNumCorners * sizeof(SkColor));
58 }
59
60 virtual void setTexCoords() {
61 const SkPoint texCoords[SkPatchUtils::kNumCorners] = {
62 {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f,1.0f}, {0.0f, 1.0f}
63 };
64 memcpy(fTexCoords, texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint ));
65 }
66
67 // override this method to change the shader
68 virtual SkShader* getShader() {
69 const SkColor colors[] = {
70 SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE,
71 SK_ColorMAGENTA, SK_ColorBLUE, SK_ColorYELLOW,
72 };
73 const SkPoint pts[] = { { 200.f / 4.f, 0.f }, { 3.f * 200.f / 4, 200.f } };
74
75 return SkGradientShader::CreateLinear(pts, colors, NULL,
76 SK_ARRAY_COUNT(colors),
77 SkShader::kMirror_TileMode);
78 }
79
80 protected:
81 virtual const char* onGetName() SK_OVERRIDE {
82 SkString vertexMode;
83 switch (fVertexMode) {
84 case kNone_VertexMode:
85 vertexMode.set("meshlines");
86 break;
87 case kColors_VertexMode:
88 vertexMode.set("colors");
89 break;
90 case kTexCoords_VertexMode:
91 vertexMode.set("texs");
92 break;
93 case kBoth_VertexMode:
94 vertexMode.set("colors&texs");
95 break;
96 default:
97 break;
98 }
99 SkString type;
100 this->appendName(&type);
101 fName.printf("patch_%s_%s_[%f,%f]", type.c_str(), vertexMode.c_str(),
102 fScale.x(), fScale.y());
103 return fName.c_str();
104 }
105
106 virtual void preDraw() {
107
108 }
109
110 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
111
112 this->setCubics();
113 this->setColors();
114 this->setTexCoords();
115 this->setupPaint(&fPaint);
116 switch (fVertexMode) {
117 case kTexCoords_VertexMode:
118 case kBoth_VertexMode:
119 fPaint.setShader(getShader());
120 break;
121 default:
122 fPaint.setShader(NULL);
123 break;
124 }
125
126 canvas->scale(fScale.x(), fScale.y());
127 for (int i = 0; i < loops; i++) {
128 switch (fVertexMode) {
129 case kNone_VertexMode:
130 canvas->drawPatch(fCubics, NULL, NULL, NULL, fPaint);
131 break;
132 case kColors_VertexMode:
133 canvas->drawPatch(fCubics, fColors, NULL, NULL, fPaint);
134 break;
135 case kTexCoords_VertexMode:
136 canvas->drawPatch(fCubics, NULL, fTexCoords, NULL, fPaint);
137 break;
138 case kBoth_VertexMode:
139 canvas->drawPatch(fCubics, fColors, fTexCoords, NULL, fPaint );
140 break;
141 default:
142 break;
143 }
144 }
145 }
146
147 SkPaint fPaint;
148 SkString fName;
149 SkVector fScale;
150 SkPoint fCubics[12];
151 SkPoint fTexCoords[4];
152 SkColor fColors[4];
153 VertexMode fVertexMode;
154
155 typedef Benchmark INHERITED;
156 };
157
158 class SquarePatchBench : public PatchBench {
159 public:
160 SquarePatchBench(SkPoint scale, VertexMode vertexMode)
161 : INHERITED(scale, vertexMode) { }
162
163 virtual void appendName(SkString* name) SK_OVERRIDE {
164 name->append("square");
165 }
166
167 virtual void setCubics() {
168 const SkPoint points[SkPatchUtils::kNumCtrlPts] = {
169 //top points
170 {100,100},{150,100},{250,100}, {300,100},
171 //right points
172 {300, 150},{300,250},
173 //bottom points
174 {300,300},{250,300},{150,300},{100,300},
175 //left points
176 {100,250},{100,150}
177 };
178 memcpy(fCubics, points, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint));
179 }
180 private:
181 typedef PatchBench INHERITED;
182 };
183
184 class LODDiffPatchBench : public PatchBench {
185 public:
186 LODDiffPatchBench(SkPoint scale, VertexMode vertexMode)
187 : INHERITED(scale, vertexMode) { }
188
189 virtual void appendName(SkString* name) SK_OVERRIDE {
190 name->append("LOD_Diff");
191 }
192
193 virtual void setCubics() {
194 const SkPoint points[SkPatchUtils::kNumCtrlPts] = {
195 //top points
196 {100,175},{150,100},{250,100}, {300,0},
197 //right points
198 {300, 150},{300,250},
199 //bottom points
200 {300,400},{250,300},{150,300},{100,225},
201 //left points
202 {100,215},{100,185}
203 };
204 memcpy(fCubics, points, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint));
205 }
206 private:
207 typedef PatchBench INHERITED;
208 };
209
210 class LoopPatchBench : public PatchBench {
211 public:
212 LoopPatchBench(SkPoint scale, VertexMode vertexMode)
213 : INHERITED(scale, vertexMode) { }
214
215 virtual void appendName(SkString* name) SK_OVERRIDE {
216 name->append("loop");
217 }
218
219 virtual void setCubics() {
220 const SkPoint points[SkPatchUtils::kNumCtrlPts] = {
221 //top points
222 {100,100},{300,200},{100,200}, {300,100},
223 //right points
224 {380, 400},{380,0},
225 //bottom points
226 {300,300},{250,250},{30,200},{100,300},
227 //left points
228 {140,325},{150,150}
229 };
230 memcpy(fCubics, points, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint));
231 }
232 private:
233 typedef PatchBench INHERITED;
234 };
235
236 ///////////////////////////////////////////////////////////////////////////////
237
238 DEF_BENCH( return new PatchBench(SkVector::Make(0.1f, 0.1f), PatchBench::kNone_V ertexMode); )
239 DEF_BENCH( return new PatchBench(SkVector::Make(0.1f, 0.1f), PatchBench::kColors _VertexMode); )
240 DEF_BENCH( return new PatchBench(SkVector::Make(0.1f, 0.1f), PatchBench::kTexCoo rds_VertexMode); )
241 DEF_BENCH( return new PatchBench(SkVector::Make(0.1f, 0.1f), PatchBench::kBoth_V ertexMode); )
242 DEF_BENCH( return new PatchBench(SkVector::Make(1.f, 1.0f), PatchBench::kNone_Ve rtexMode); )
243 DEF_BENCH( return new PatchBench(SkVector::Make(1.0f, 1.0f), PatchBench::kColors _VertexMode); )
244 DEF_BENCH( return new PatchBench(SkVector::Make(1.0f, 1.0f), PatchBench::kTexCoo rds_VertexMode); )
245 DEF_BENCH( return new PatchBench(SkVector::Make(1.0f, 1.0f), PatchBench::kBoth_V ertexMode); )
246 DEF_BENCH( return new PatchBench(SkVector::Make(3.0f, 3.0f), PatchBench::kNone_V ertexMode); )
247 DEF_BENCH( return new PatchBench(SkVector::Make(3.0f, 3.0f), PatchBench::kColors _VertexMode); )
248 DEF_BENCH( return new PatchBench(SkVector::Make(3.0f, 3.0f), PatchBench::kTexCoo rds_VertexMode); )
249 DEF_BENCH( return new PatchBench(SkVector::Make(3.0f, 3.0f), PatchBench::kBoth_V ertexMode); )
250
251 DEF_BENCH( return new SquarePatchBench(SkVector::Make(0.1f, 0.1f),
252 PatchBench::kNone_VertexMode); )
253 DEF_BENCH( return new SquarePatchBench(SkVector::Make(0.1f, 0.1f),
254 PatchBench::kColors_VertexMode); )
255 DEF_BENCH( return new SquarePatchBench(SkVector::Make(0.1f, 0.1f),
256 PatchBench::kTexCoords_VertexMode); )
257 DEF_BENCH( return new SquarePatchBench(SkVector::Make(0.1f, 0.1f),
258 PatchBench::kBoth_VertexMode); )
259 DEF_BENCH( return new SquarePatchBench(SkVector::Make(1.f, 1.0f),
260 PatchBench::kNone_VertexMode); )
261 DEF_BENCH( return new SquarePatchBench(SkVector::Make(1.0f, 1.0f),
262 PatchBench::kColors_VertexMode); )
263 DEF_BENCH( return new SquarePatchBench(SkVector::Make(1.0f, 1.0f),
264 PatchBench::kTexCoords_VertexMode); )
265 DEF_BENCH( return new SquarePatchBench(SkVector::Make(1.0f, 1.0f),
266 PatchBench::kBoth_VertexMode); )
267 DEF_BENCH( return new SquarePatchBench(SkVector::Make(3.0f, 3.0f),
268 PatchBench::kNone_VertexMode); )
269 DEF_BENCH( return new SquarePatchBench(SkVector::Make(3.0f, 3.0f),
270 PatchBench::kColors_VertexMode); )
271 DEF_BENCH( return new SquarePatchBench(SkVector::Make(3.0f, 3.0f),
272 PatchBench::kTexCoords_VertexMode); )
273 DEF_BENCH( return new SquarePatchBench(SkVector::Make(3.0f, 3.0f),
274 PatchBench::kBoth_VertexMode); )
275
276 DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(0.1f, 0.1f),
277 PatchBench::kNone_VertexMode); )
278 DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(0.1f, 0.1f),
279 PatchBench::kColors_VertexMode); )
280 DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(0.1f, 0.1f),
281 PatchBench::kTexCoords_VertexMode); )
282 DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(0.1f, 0.1f),
283 PatchBench::kBoth_VertexMode); )
284 DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(1.f, 1.0f),
285 PatchBench::kNone_VertexMode); )
286 DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(1.0f, 1.0f),
287 PatchBench::kColors_VertexMode); )
288 DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(1.0f, 1.0f),
289 PatchBench::kTexCoords_VertexMode); )
290 DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(1.0f, 1.0f),
291 PatchBench::kBoth_VertexMode); )
292 DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(3.0f, 3.0f),
293 PatchBench::kNone_VertexMode); )
294 DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(3.0f, 3.0f),
295 PatchBench::kColors_VertexMode); )
296 DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(3.0f, 3.0f),
297 PatchBench::kTexCoords_VertexMode); )
298 DEF_BENCH( return new LODDiffPatchBench(SkVector::Make(3.0f, 3.0f),
299 PatchBench::kBoth_VertexMode); )
300
301 DEF_BENCH( return new LoopPatchBench(SkVector::Make(0.1f, 0.1f),
302 PatchBench::kNone_VertexMode); )
303 DEF_BENCH( return new LoopPatchBench(SkVector::Make(0.1f, 0.1f),
304 PatchBench::kColors_VertexMode); )
305 DEF_BENCH( return new LoopPatchBench(SkVector::Make(0.1f, 0.1f),
306 PatchBench::kTexCoords_VertexMode); )
307 DEF_BENCH( return new LoopPatchBench(SkVector::Make(0.1f, 0.1f),
308 PatchBench::kBoth_VertexMode); )
309 DEF_BENCH( return new LoopPatchBench(SkVector::Make(1.f, 1.0f),
310 PatchBench::kNone_VertexMode); )
311 DEF_BENCH( return new LoopPatchBench(SkVector::Make(1.0f, 1.0f),
312 PatchBench::kColors_VertexMode); )
313 DEF_BENCH( return new LoopPatchBench(SkVector::Make(1.0f, 1.0f),
314 PatchBench::kTexCoords_VertexMode); )
315 DEF_BENCH( return new LoopPatchBench(SkVector::Make(1.0f, 1.0f),
316 PatchBench::kBoth_VertexMode); )
317 DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f),
318 PatchBench::kNone_VertexMode); )
319 DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f),
320 PatchBench::kColors_VertexMode); )
321 DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f),
322 PatchBench::kTexCoords_VertexMode); )
323 DEF_BENCH( return new LoopPatchBench(SkVector::Make(3.0f, 3.0f),
324 PatchBench::kBoth_VertexMode); )
OLDNEW
« no previous file with comments | « no previous file | gm/patch.cpp » ('j') | include/core/SkCanvas.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698