OLD | NEW |
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 // This test only works with the GPU backend. | 8 // This test only works with the GPU backend. |
9 | 9 |
10 #include "gm.h" | 10 #include "gm.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 verts[v].fKLM[1] = eval_line(verts[v].fPosition, fKlmEqs + 3, fSign)
; | 67 verts[v].fKLM[1] = eval_line(verts[v].fPosition, fKlmEqs + 3, fSign)
; |
68 verts[v].fKLM[2] = eval_line(verts[v].fPosition, fKlmEqs + 6, 1.f); | 68 verts[v].fKLM[2] = eval_line(verts[v].fPosition, fKlmEqs + 6, 1.f); |
69 } | 69 } |
70 helper.recordDraw(target, fGeometryProcessor.get()); | 70 helper.recordDraw(target, fGeometryProcessor.get()); |
71 } | 71 } |
72 | 72 |
73 SkScalar fKlmEqs[9]; | 73 SkScalar fKlmEqs[9]; |
74 SkScalar fSign; | 74 SkScalar fSign; |
75 sk_sp<GrGeometryProcessor> fGeometryProcessor; | 75 sk_sp<GrGeometryProcessor> fGeometryProcessor; |
76 | 76 |
77 static const int kVertsPerCubic = 4; | 77 static constexpr int kVertsPerCubic = 4; |
78 static const int kIndicesPerCubic = 6; | 78 static constexpr int kIndicesPerCubic = 6; |
79 | 79 |
80 typedef GrTestBatch INHERITED; | 80 typedef GrTestBatch INHERITED; |
81 }; | 81 }; |
82 | 82 |
83 /** | 83 /** |
84 * This GM directly exercises effects that draw Bezier curves in the GPU backend
. | 84 * This GM directly exercises effects that draw Bezier curves in the GPU backend
. |
85 */ | 85 */ |
86 class BezierCubicEffects : public GM { | 86 class BezierCubicEffects : public GM { |
87 public: | 87 public: |
88 BezierCubicEffects() { | 88 BezierCubicEffects() { |
(...skipping 19 matching lines...) Expand all Loading... |
108 GrContext* context = canvas->getGrContext(); | 108 GrContext* context = canvas->getGrContext(); |
109 if (!context) { | 109 if (!context) { |
110 return; | 110 return; |
111 } | 111 } |
112 | 112 |
113 struct Vertex { | 113 struct Vertex { |
114 SkPoint fPosition; | 114 SkPoint fPosition; |
115 float fKLM[4]; // The last value is ignored. The effect expects a
vec4f. | 115 float fKLM[4]; // The last value is ignored. The effect expects a
vec4f. |
116 }; | 116 }; |
117 | 117 |
118 static const int kNumCubics = 15; | 118 constexpr int kNumCubics = 15; |
119 SkRandom rand; | 119 SkRandom rand; |
120 | 120 |
121 // Mult by 3 for each edge effect type | 121 // Mult by 3 for each edge effect type |
122 int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumCubics*3)
)); | 122 int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumCubics*3)
)); |
123 int numRows = SkScalarCeilToInt(SkIntToScalar(kNumCubics*3) / numCols); | 123 int numRows = SkScalarCeilToInt(SkIntToScalar(kNumCubics*3) / numCols); |
124 SkScalar w = SkIntToScalar(drawContext->width()) / numCols; | 124 SkScalar w = SkIntToScalar(drawContext->width()) / numCols; |
125 SkScalar h = SkIntToScalar(drawContext->height()) / numRows; | 125 SkScalar h = SkIntToScalar(drawContext->height()) / numRows; |
126 int row = 0; | 126 int row = 0; |
127 int col = 0; | 127 int col = 0; |
128 static const GrColor color = 0xff000000; | 128 constexpr GrColor color = 0xff000000; |
129 | 129 |
130 for (int i = 0; i < kNumCubics; ++i) { | 130 for (int i = 0; i < kNumCubics; ++i) { |
131 SkPoint baseControlPts[] = { | 131 SkPoint baseControlPts[] = { |
132 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, | 132 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
133 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, | 133 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
134 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, | 134 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
135 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} | 135 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} |
136 }; | 136 }; |
137 for(int edgeType = 0; edgeType < kGrProcessorEdgeTypeCnt; ++edgeType
) { | 137 for(int edgeType = 0; edgeType < kGrProcessorEdgeTypeCnt; ++edgeType
) { |
138 sk_sp<GrGeometryProcessor> gp; | 138 sk_sp<GrGeometryProcessor> gp; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 GrContext* context = canvas->getGrContext(); | 240 GrContext* context = canvas->getGrContext(); |
241 if (!context) { | 241 if (!context) { |
242 return; | 242 return; |
243 } | 243 } |
244 | 244 |
245 struct Vertex { | 245 struct Vertex { |
246 SkPoint fPosition; | 246 SkPoint fPosition; |
247 float fKLM[4]; // The last value is ignored. The effect expects a
vec4f. | 247 float fKLM[4]; // The last value is ignored. The effect expects a
vec4f. |
248 }; | 248 }; |
249 | 249 |
250 static const int kNumConics = 10; | 250 constexpr int kNumConics = 10; |
251 SkRandom rand; | 251 SkRandom rand; |
252 | 252 |
253 // Mult by 3 for each edge effect type | 253 // Mult by 3 for each edge effect type |
254 int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumConics*3)
)); | 254 int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumConics*3)
)); |
255 int numRows = SkScalarCeilToInt(SkIntToScalar(kNumConics*3) / numCols); | 255 int numRows = SkScalarCeilToInt(SkIntToScalar(kNumConics*3) / numCols); |
256 SkScalar w = SkIntToScalar(drawContext->width()) / numCols; | 256 SkScalar w = SkIntToScalar(drawContext->width()) / numCols; |
257 SkScalar h = SkIntToScalar(drawContext->height()) / numRows; | 257 SkScalar h = SkIntToScalar(drawContext->height()) / numRows; |
258 int row = 0; | 258 int row = 0; |
259 int col = 0; | 259 int col = 0; |
260 static const GrColor color = 0xff000000; | 260 constexpr GrColor color = 0xff000000; |
261 | 261 |
262 for (int i = 0; i < kNumConics; ++i) { | 262 for (int i = 0; i < kNumConics; ++i) { |
263 SkPoint baseControlPts[] = { | 263 SkPoint baseControlPts[] = { |
264 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, | 264 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
265 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, | 265 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
266 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} | 266 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} |
267 }; | 267 }; |
268 SkScalar weight = rand.nextRangeF(0.f, 2.f); | 268 SkScalar weight = rand.nextRangeF(0.f, 2.f); |
269 for(int edgeType = 0; edgeType < kGrProcessorEdgeTypeCnt; ++edgeType
) { | 269 for(int edgeType = 0; edgeType < kGrProcessorEdgeTypeCnt; ++edgeType
) { |
270 sk_sp<GrGeometryProcessor> gp; | 270 sk_sp<GrGeometryProcessor> gp; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 const SkRect& bounds = this->bounds(); | 409 const SkRect& bounds = this->bounds(); |
410 verts[0].fPosition.setRectFan(bounds.fLeft, bounds.fTop, bounds.fRight,
bounds.fBottom, | 410 verts[0].fPosition.setRectFan(bounds.fLeft, bounds.fTop, bounds.fRight,
bounds.fBottom, |
411 sizeof(Vertex)); | 411 sizeof(Vertex)); |
412 fDevToUV.apply<4, sizeof(Vertex), sizeof(SkPoint)>(verts); | 412 fDevToUV.apply<4, sizeof(Vertex), sizeof(SkPoint)>(verts); |
413 helper.recordDraw(target, fGeometryProcessor.get()); | 413 helper.recordDraw(target, fGeometryProcessor.get()); |
414 } | 414 } |
415 | 415 |
416 GrPathUtils::QuadUVMatrix fDevToUV; | 416 GrPathUtils::QuadUVMatrix fDevToUV; |
417 sk_sp<GrGeometryProcessor> fGeometryProcessor; | 417 sk_sp<GrGeometryProcessor> fGeometryProcessor; |
418 | 418 |
419 static const int kVertsPerCubic = 4; | 419 static constexpr int kVertsPerCubic = 4; |
420 static const int kIndicesPerCubic = 6; | 420 static constexpr int kIndicesPerCubic = 6; |
421 | 421 |
422 typedef GrTestBatch INHERITED; | 422 typedef GrTestBatch INHERITED; |
423 }; | 423 }; |
424 | 424 |
425 /** | 425 /** |
426 * This GM directly exercises effects that draw Bezier quad curves in the GPU ba
ckend. | 426 * This GM directly exercises effects that draw Bezier quad curves in the GPU ba
ckend. |
427 */ | 427 */ |
428 class BezierQuadEffects : public GM { | 428 class BezierQuadEffects : public GM { |
429 public: | 429 public: |
430 BezierQuadEffects() { | 430 BezierQuadEffects() { |
(...skipping 20 matching lines...) Expand all Loading... |
451 GrContext* context = canvas->getGrContext(); | 451 GrContext* context = canvas->getGrContext(); |
452 if (!context) { | 452 if (!context) { |
453 return; | 453 return; |
454 } | 454 } |
455 | 455 |
456 struct Vertex { | 456 struct Vertex { |
457 SkPoint fPosition; | 457 SkPoint fPosition; |
458 float fUV[4]; // The last two values are ignored. The effect expec
ts a vec4f. | 458 float fUV[4]; // The last two values are ignored. The effect expec
ts a vec4f. |
459 }; | 459 }; |
460 | 460 |
461 static const int kNumQuads = 5; | 461 constexpr int kNumQuads = 5; |
462 SkRandom rand; | 462 SkRandom rand; |
463 | 463 |
464 int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumQuads*3))
); | 464 int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumQuads*3))
); |
465 int numRows = SkScalarCeilToInt(SkIntToScalar(kNumQuads*3) / numCols); | 465 int numRows = SkScalarCeilToInt(SkIntToScalar(kNumQuads*3) / numCols); |
466 SkScalar w = SkIntToScalar(drawContext->width()) / numCols; | 466 SkScalar w = SkIntToScalar(drawContext->width()) / numCols; |
467 SkScalar h = SkIntToScalar(drawContext->height()) / numRows; | 467 SkScalar h = SkIntToScalar(drawContext->height()) / numRows; |
468 int row = 0; | 468 int row = 0; |
469 int col = 0; | 469 int col = 0; |
470 static const GrColor color = 0xff000000; | 470 constexpr GrColor color = 0xff000000; |
471 | 471 |
472 for (int i = 0; i < kNumQuads; ++i) { | 472 for (int i = 0; i < kNumQuads; ++i) { |
473 SkPoint baseControlPts[] = { | 473 SkPoint baseControlPts[] = { |
474 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, | 474 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
475 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, | 475 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
476 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} | 476 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} |
477 }; | 477 }; |
478 for(int edgeType = 0; edgeType < kGrProcessorEdgeTypeCnt; ++edgeType
) { | 478 for(int edgeType = 0; edgeType < kGrProcessorEdgeTypeCnt; ++edgeType
) { |
479 sk_sp<GrGeometryProcessor> gp; | 479 sk_sp<GrGeometryProcessor> gp; |
480 GrPrimitiveEdgeType et = (GrPrimitiveEdgeType)edgeType; | 480 GrPrimitiveEdgeType et = (GrPrimitiveEdgeType)edgeType; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 private: | 547 private: |
548 typedef GM INHERITED; | 548 typedef GM INHERITED; |
549 }; | 549 }; |
550 | 550 |
551 DEF_GM(return new BezierCubicEffects;) | 551 DEF_GM(return new BezierCubicEffects;) |
552 DEF_GM(return new BezierConicEffects;) | 552 DEF_GM(return new BezierConicEffects;) |
553 DEF_GM(return new BezierQuadEffects;) | 553 DEF_GM(return new BezierQuadEffects;) |
554 } | 554 } |
555 | 555 |
556 #endif | 556 #endif |
OLD | NEW |