OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 // This test only works with the GPU backend. | 9 // This test only works with the GPU backend. |
10 | 10 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 int row = 0; | 86 int row = 0; |
87 int col = 0; | 87 int col = 0; |
88 | 88 |
89 for (int i = 0; i < kNumCubics; ++i) { | 89 for (int i = 0; i < kNumCubics; ++i) { |
90 SkPoint baseControlPts[] = { | 90 SkPoint baseControlPts[] = { |
91 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, | 91 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
92 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, | 92 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
93 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, | 93 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
94 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} | 94 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} |
95 }; | 95 }; |
96 for(int edgeType = kFillAA_GrBezierEdgeType; edgeType < 3; ++edgeTyp
e) { | 96 for(int edgeType = 0; edgeType < kGrEffectEdgeTypeCnt; ++edgeType) { |
| 97 SkAutoTUnref<GrEffectRef> effect; |
| 98 { // scope to contain GrTestTarget |
| 99 GrTestTarget tt; |
| 100 context->getTestTarget(&tt); |
| 101 if (NULL == tt.target()) { |
| 102 continue; |
| 103 } |
| 104 GrEffectEdgeType et = (GrEffectEdgeType)edgeType; |
| 105 effect.reset(GrCubicEffect::Create(et, *tt.target()->caps())
); |
| 106 if (!effect) { |
| 107 continue; |
| 108 } |
| 109 } |
| 110 |
97 SkScalar x = SkScalarMul(col, w); | 111 SkScalar x = SkScalarMul(col, w); |
98 SkScalar y = SkScalarMul(row, h); | 112 SkScalar y = SkScalarMul(row, h); |
99 SkPoint controlPts[] = { | 113 SkPoint controlPts[] = { |
100 {x + baseControlPts[0].fX, y + baseControlPts[0].fY}, | 114 {x + baseControlPts[0].fX, y + baseControlPts[0].fY}, |
101 {x + baseControlPts[1].fX, y + baseControlPts[1].fY}, | 115 {x + baseControlPts[1].fX, y + baseControlPts[1].fY}, |
102 {x + baseControlPts[2].fX, y + baseControlPts[2].fY}, | 116 {x + baseControlPts[2].fX, y + baseControlPts[2].fY}, |
103 {x + baseControlPts[3].fX, y + baseControlPts[3].fY} | 117 {x + baseControlPts[3].fX, y + baseControlPts[3].fY} |
104 }; | 118 }; |
105 SkPoint chopped[10]; | 119 SkPoint chopped[10]; |
106 SkScalar klmEqs[9]; | 120 SkScalar klmEqs[9]; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 bounds.fRight, bounds.fBottom, | 160 bounds.fRight, bounds.fBottom, |
147 sizeof(Vertex)); | 161 sizeof(Vertex)); |
148 for (int v = 0; v < 4; ++v) { | 162 for (int v = 0; v < 4; ++v) { |
149 verts[v].fKLM[0] = eval_line(verts[v].fPosition, klmEqs
+ 0, klmSigns[c]); | 163 verts[v].fKLM[0] = eval_line(verts[v].fPosition, klmEqs
+ 0, klmSigns[c]); |
150 verts[v].fKLM[1] = eval_line(verts[v].fPosition, klmEqs
+ 3, klmSigns[c]); | 164 verts[v].fKLM[1] = eval_line(verts[v].fPosition, klmEqs
+ 3, klmSigns[c]); |
151 verts[v].fKLM[2] = eval_line(verts[v].fPosition, klmEqs
+ 6, 1.f); | 165 verts[v].fKLM[2] = eval_line(verts[v].fPosition, klmEqs
+ 6, 1.f); |
152 } | 166 } |
153 | 167 |
154 GrTestTarget tt; | 168 GrTestTarget tt; |
155 context->getTestTarget(&tt); | 169 context->getTestTarget(&tt); |
156 if (NULL == tt.target()) { | 170 SkASSERT(NULL != tt.target()); |
157 continue; | |
158 } | |
159 GrDrawState* drawState = tt.target()->drawState(); | 171 GrDrawState* drawState = tt.target()->drawState(); |
160 drawState->setVertexAttribs<kAttribs>(2); | 172 drawState->setVertexAttribs<kAttribs>(2); |
161 | 173 |
162 SkAutoTUnref<GrEffectRef> effect(GrCubicEffect::Create( | |
163 GrBezierEdgeType(edgeType), *tt.target()->caps())); | |
164 if (!effect) { | |
165 continue; | |
166 } | |
167 drawState->addCoverageEffect(effect, 1); | 174 drawState->addCoverageEffect(effect, 1); |
168 drawState->setRenderTarget(rt); | 175 drawState->setRenderTarget(rt); |
169 drawState->setColor(0xff000000); | 176 drawState->setColor(0xff000000); |
170 | 177 |
171 tt.target()->setVertexSourceToArray(verts, 4); | 178 tt.target()->setVertexSourceToArray(verts, 4); |
172 tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuf
fer()); | 179 tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuf
fer()); |
173 tt.target()->drawIndexed(kTriangleFan_GrPrimitiveType, 0, 0,
4, 6); | 180 tt.target()->drawIndexed(kTriangleFan_GrPrimitiveType, 0, 0,
4, 6); |
174 } | 181 } |
175 ++col; | 182 ++col; |
176 if (numCols == col) { | 183 if (numCols == col) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 int row = 0; | 245 int row = 0; |
239 int col = 0; | 246 int col = 0; |
240 | 247 |
241 for (int i = 0; i < kNumConics; ++i) { | 248 for (int i = 0; i < kNumConics; ++i) { |
242 SkPoint baseControlPts[] = { | 249 SkPoint baseControlPts[] = { |
243 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, | 250 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
244 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, | 251 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
245 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} | 252 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} |
246 }; | 253 }; |
247 SkScalar weight = rand.nextRangeF(0.f, 2.f); | 254 SkScalar weight = rand.nextRangeF(0.f, 2.f); |
248 for(int edgeType = kFillAA_GrBezierEdgeType; edgeType < 3; ++edgeTyp
e) { | 255 for(int edgeType = 0; edgeType < kGrEffectEdgeTypeCnt; ++edgeType) { |
| 256 SkAutoTUnref<GrEffectRef> effect; |
| 257 { // scope to contain GrTestTarget |
| 258 GrTestTarget tt; |
| 259 context->getTestTarget(&tt); |
| 260 if (NULL == tt.target()) { |
| 261 continue; |
| 262 } |
| 263 GrEffectEdgeType et = (GrEffectEdgeType)edgeType; |
| 264 effect.reset(GrConicEffect::Create(et, *tt.target()->caps())
); |
| 265 if (!effect) { |
| 266 continue; |
| 267 } |
| 268 } |
| 269 |
249 SkScalar x = SkScalarMul(col, w); | 270 SkScalar x = SkScalarMul(col, w); |
250 SkScalar y = SkScalarMul(row, h); | 271 SkScalar y = SkScalarMul(row, h); |
251 SkPoint controlPts[] = { | 272 SkPoint controlPts[] = { |
252 {x + baseControlPts[0].fX, y + baseControlPts[0].fY}, | 273 {x + baseControlPts[0].fX, y + baseControlPts[0].fY}, |
253 {x + baseControlPts[1].fX, y + baseControlPts[1].fY}, | 274 {x + baseControlPts[1].fX, y + baseControlPts[1].fY}, |
254 {x + baseControlPts[2].fX, y + baseControlPts[2].fY} | 275 {x + baseControlPts[2].fX, y + baseControlPts[2].fY} |
255 }; | 276 }; |
256 SkConic dst[4]; | 277 SkConic dst[4]; |
257 SkScalar klmEqs[9]; | 278 SkScalar klmEqs[9]; |
258 int cnt = chop_conic(controlPts, dst, weight); | 279 int cnt = chop_conic(controlPts, dst, weight); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 bounds.fRight, bounds.fBottom, | 316 bounds.fRight, bounds.fBottom, |
296 sizeof(Vertex)); | 317 sizeof(Vertex)); |
297 for (int v = 0; v < 4; ++v) { | 318 for (int v = 0; v < 4; ++v) { |
298 verts[v].fKLM[0] = eval_line(verts[v].fPosition, klmEqs
+ 0, 1.f); | 319 verts[v].fKLM[0] = eval_line(verts[v].fPosition, klmEqs
+ 0, 1.f); |
299 verts[v].fKLM[1] = eval_line(verts[v].fPosition, klmEqs
+ 3, 1.f); | 320 verts[v].fKLM[1] = eval_line(verts[v].fPosition, klmEqs
+ 3, 1.f); |
300 verts[v].fKLM[2] = eval_line(verts[v].fPosition, klmEqs
+ 6, 1.f); | 321 verts[v].fKLM[2] = eval_line(verts[v].fPosition, klmEqs
+ 6, 1.f); |
301 } | 322 } |
302 | 323 |
303 GrTestTarget tt; | 324 GrTestTarget tt; |
304 context->getTestTarget(&tt); | 325 context->getTestTarget(&tt); |
305 if (NULL == tt.target()) { | 326 SkASSERT(NULL != tt.target()); |
306 continue; | |
307 } | |
308 GrDrawState* drawState = tt.target()->drawState(); | 327 GrDrawState* drawState = tt.target()->drawState(); |
309 drawState->setVertexAttribs<kAttribs>(2); | 328 drawState->setVertexAttribs<kAttribs>(2); |
310 | 329 |
311 SkAutoTUnref<GrEffectRef> effect(GrConicEffect::Create( | |
312 GrBezierEdgeType(edgeType), *tt.target()->caps())); | |
313 if (!effect) { | |
314 continue; | |
315 } | |
316 drawState->addCoverageEffect(effect, 1); | 330 drawState->addCoverageEffect(effect, 1); |
317 drawState->setRenderTarget(rt); | 331 drawState->setRenderTarget(rt); |
318 drawState->setColor(0xff000000); | 332 drawState->setColor(0xff000000); |
319 | 333 |
320 tt.target()->setVertexSourceToArray(verts, 4); | 334 tt.target()->setVertexSourceToArray(verts, 4); |
321 tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuf
fer()); | 335 tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuf
fer()); |
322 tt.target()->drawIndexed(kTriangleFan_GrPrimitiveType, 0, 0,
4, 6); | 336 tt.target()->drawIndexed(kTriangleFan_GrPrimitiveType, 0, 0,
4, 6); |
323 } | 337 } |
324 ++col; | 338 ++col; |
325 if (numCols == col) { | 339 if (numCols == col) { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 SkScalar h = SkIntToScalar(rt->height()) / numRows; | 435 SkScalar h = SkIntToScalar(rt->height()) / numRows; |
422 int row = 0; | 436 int row = 0; |
423 int col = 0; | 437 int col = 0; |
424 | 438 |
425 for (int i = 0; i < kNumQuads; ++i) { | 439 for (int i = 0; i < kNumQuads; ++i) { |
426 SkPoint baseControlPts[] = { | 440 SkPoint baseControlPts[] = { |
427 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, | 441 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
428 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, | 442 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
429 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} | 443 {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} |
430 }; | 444 }; |
431 for(int edgeType = kFillAA_GrBezierEdgeType; edgeType < 3; ++edgeTyp
e) { | 445 for(int edgeType = 0; edgeType < kGrEffectEdgeTypeCnt; ++edgeType) { |
| 446 SkAutoTUnref<GrEffectRef> effect; |
| 447 { // scope to contain GrTestTarget |
| 448 GrTestTarget tt; |
| 449 context->getTestTarget(&tt); |
| 450 if (NULL == tt.target()) { |
| 451 continue; |
| 452 } |
| 453 GrEffectEdgeType et = (GrEffectEdgeType)edgeType; |
| 454 effect.reset(GrQuadEffect::Create(et, *tt.target()->caps()))
; |
| 455 if (!effect) { |
| 456 continue; |
| 457 } |
| 458 } |
| 459 |
432 SkScalar x = SkScalarMul(col, w); | 460 SkScalar x = SkScalarMul(col, w); |
433 SkScalar y = SkScalarMul(row, h); | 461 SkScalar y = SkScalarMul(row, h); |
434 SkPoint controlPts[] = { | 462 SkPoint controlPts[] = { |
435 {x + baseControlPts[0].fX, y + baseControlPts[0].fY}, | 463 {x + baseControlPts[0].fX, y + baseControlPts[0].fY}, |
436 {x + baseControlPts[1].fX, y + baseControlPts[1].fY}, | 464 {x + baseControlPts[1].fX, y + baseControlPts[1].fY}, |
437 {x + baseControlPts[2].fX, y + baseControlPts[2].fY} | 465 {x + baseControlPts[2].fX, y + baseControlPts[2].fY} |
438 }; | 466 }; |
439 SkPoint chopped[5]; | 467 SkPoint chopped[5]; |
440 int cnt = SkChopQuadAtMaxCurvature(controlPts, chopped); | 468 int cnt = SkChopQuadAtMaxCurvature(controlPts, chopped); |
441 | 469 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 Vertex verts[4]; | 501 Vertex verts[4]; |
474 verts[0].fPosition.setRectFan(bounds.fLeft, bounds.fTop, | 502 verts[0].fPosition.setRectFan(bounds.fLeft, bounds.fTop, |
475 bounds.fRight, bounds.fBottom, | 503 bounds.fRight, bounds.fBottom, |
476 sizeof(Vertex)); | 504 sizeof(Vertex)); |
477 | 505 |
478 GrPathUtils::QuadUVMatrix DevToUV(pts); | 506 GrPathUtils::QuadUVMatrix DevToUV(pts); |
479 DevToUV.apply<4, sizeof(Vertex), sizeof(GrPoint)>(verts); | 507 DevToUV.apply<4, sizeof(Vertex), sizeof(GrPoint)>(verts); |
480 | 508 |
481 GrTestTarget tt; | 509 GrTestTarget tt; |
482 context->getTestTarget(&tt); | 510 context->getTestTarget(&tt); |
483 if (NULL == tt.target()) { | 511 SkASSERT(NULL != tt.target()); |
484 continue; | |
485 } | |
486 GrDrawState* drawState = tt.target()->drawState(); | 512 GrDrawState* drawState = tt.target()->drawState(); |
487 drawState->setVertexAttribs<kAttribs>(2); | 513 drawState->setVertexAttribs<kAttribs>(2); |
488 SkAutoTUnref<GrEffectRef> effect(GrQuadEffect::Create( | 514 |
489 GrBezierEdgeType(edgeType), *tt.target()->caps())); | |
490 if (!effect) { | |
491 continue; | |
492 } | |
493 drawState->addCoverageEffect(effect, 1); | 515 drawState->addCoverageEffect(effect, 1); |
494 drawState->setRenderTarget(rt); | 516 drawState->setRenderTarget(rt); |
495 drawState->setColor(0xff000000); | 517 drawState->setColor(0xff000000); |
496 | 518 |
497 tt.target()->setVertexSourceToArray(verts, 4); | 519 tt.target()->setVertexSourceToArray(verts, 4); |
498 tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuf
fer()); | 520 tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuf
fer()); |
499 tt.target()->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 4
, 6); | 521 tt.target()->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 4
, 6); |
500 } | 522 } |
501 ++col; | 523 ++col; |
502 if (numCols == col) { | 524 if (numCols == col) { |
503 col = 0; | 525 col = 0; |
504 ++row; | 526 ++row; |
505 } | 527 } |
506 } | 528 } |
507 } | 529 } |
508 } | 530 } |
509 | 531 |
510 private: | 532 private: |
511 typedef GM INHERITED; | 533 typedef GM INHERITED; |
512 }; | 534 }; |
513 | 535 |
514 DEF_GM( return SkNEW(BezierCubicEffects); ) | 536 DEF_GM( return SkNEW(BezierCubicEffects); ) |
515 DEF_GM( return SkNEW(BezierConicEffects); ) | 537 DEF_GM( return SkNEW(BezierConicEffects); ) |
516 DEF_GM( return SkNEW(BezierQuadEffects); ) | 538 DEF_GM( return SkNEW(BezierQuadEffects); ) |
517 | 539 |
518 } | 540 } |
519 | 541 |
520 #endif | 542 #endif |
OLD | NEW |