| 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 |
| 11 #include "gm.h" | 11 #include "gm.h" |
| 12 | 12 |
| 13 #if SK_SUPPORT_GPU | 13 #if SK_SUPPORT_GPU |
| 14 | 14 |
| 15 #include "GrContext.h" | 15 #include "GrContext.h" |
| 16 #include "GrPathUtils.h" | 16 #include "GrPathUtils.h" |
| 17 #include "GrTest.h" | 17 #include "GrTest.h" |
| 18 #include "SkColorPriv.h" | 18 #include "SkColorPriv.h" |
| 19 #include "SkDevice.h" | 19 #include "SkDevice.h" |
| 20 #include "SkGeometry.h" | 20 #include "SkGeometry.h" |
| 21 | 21 |
| 22 #include "effects/GrBezierEffect.h" | 22 #include "effects/GrBezierEffect.h" |
| 23 | 23 |
| 24 // Position & KLM line eq values. These are the vertex attributes for Bezier cur
ves. The last value | |
| 25 // of the Vec4f is ignored. | |
| 26 namespace { | |
| 27 extern const GrVertexAttrib kAttribs[] = { | |
| 28 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, | |
| 29 {kVec4f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexAttr
ibBinding} | |
| 30 }; | |
| 31 } | |
| 32 | |
| 33 static inline SkScalar eval_line(const SkPoint& p, const SkScalar lineEq[3], SkS
calar sign) { | 24 static inline SkScalar eval_line(const SkPoint& p, const SkScalar lineEq[3], SkS
calar sign) { |
| 34 return sign * (lineEq[0] * p.fX + lineEq[1] * p.fY + lineEq[2]); | 25 return sign * (lineEq[0] * p.fX + lineEq[1] * p.fY + lineEq[2]); |
| 35 } | 26 } |
| 36 | 27 |
| 37 namespace skiagm { | 28 namespace skiagm { |
| 38 /** | 29 /** |
| 39 * This GM directly exercises effects that draw Bezier curves in the GPU backend
. | 30 * This GM directly exercises effects that draw Bezier curves in the GPU backend
. |
| 40 */ | 31 */ |
| 41 class BezierCubicEffects : public GM { | 32 class BezierCubicEffects : public GM { |
| 42 public: | 33 public: |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 boundsPaint.setColor(0xff808080); | 143 boundsPaint.setColor(0xff808080); |
| 153 boundsPaint.setStrokeWidth(0); | 144 boundsPaint.setStrokeWidth(0); |
| 154 boundsPaint.setStyle(SkPaint::kStroke_Style); | 145 boundsPaint.setStyle(SkPaint::kStroke_Style); |
| 155 canvas->drawRect(bounds, boundsPaint); | 146 canvas->drawRect(bounds, boundsPaint); |
| 156 | 147 |
| 157 GrTestTarget tt; | 148 GrTestTarget tt; |
| 158 context->getTestTarget(&tt); | 149 context->getTestTarget(&tt); |
| 159 SkASSERT(tt.target()); | 150 SkASSERT(tt.target()); |
| 160 | 151 |
| 161 GrDrawState ds; | 152 GrDrawState ds; |
| 162 ds.setVertexAttribs<kAttribs>(2, sizeof(Vertex)); | |
| 163 | 153 |
| 164 GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, ds.get
VertexStride(), 0); | 154 GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->ge
tVertexStride(), 0); |
| 155 SkASSERT(gp->getVertexStride() == sizeof(Vertex)); |
| 165 Vertex* verts = reinterpret_cast<Vertex*>(geo.vertices()); | 156 Vertex* verts = reinterpret_cast<Vertex*>(geo.vertices()); |
| 166 | 157 |
| 167 verts[0].fPosition.setRectFan(bounds.fLeft, bounds.fTop, | 158 verts[0].fPosition.setRectFan(bounds.fLeft, bounds.fTop, |
| 168 bounds.fRight, bounds.fBottom, | 159 bounds.fRight, bounds.fBottom, |
| 169 sizeof(Vertex)); | 160 sizeof(Vertex)); |
| 170 for (int v = 0; v < 4; ++v) { | 161 for (int v = 0; v < 4; ++v) { |
| 171 verts[v].fKLM[0] = eval_line(verts[v].fPosition, klmEqs
+ 0, klmSigns[c]); | 162 verts[v].fKLM[0] = eval_line(verts[v].fPosition, klmEqs
+ 0, klmSigns[c]); |
| 172 verts[v].fKLM[1] = eval_line(verts[v].fPosition, klmEqs
+ 3, klmSigns[c]); | 163 verts[v].fKLM[1] = eval_line(verts[v].fPosition, klmEqs
+ 3, klmSigns[c]); |
| 173 verts[v].fKLM[2] = eval_line(verts[v].fPosition, klmEqs
+ 6, 1.f); | 164 verts[v].fKLM[2] = eval_line(verts[v].fPosition, klmEqs
+ 6, 1.f); |
| 174 } | 165 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 boundsPaint.setColor(0xff808080); | 300 boundsPaint.setColor(0xff808080); |
| 310 boundsPaint.setStrokeWidth(0); | 301 boundsPaint.setStrokeWidth(0); |
| 311 boundsPaint.setStyle(SkPaint::kStroke_Style); | 302 boundsPaint.setStyle(SkPaint::kStroke_Style); |
| 312 canvas->drawRect(bounds, boundsPaint); | 303 canvas->drawRect(bounds, boundsPaint); |
| 313 | 304 |
| 314 GrTestTarget tt; | 305 GrTestTarget tt; |
| 315 context->getTestTarget(&tt); | 306 context->getTestTarget(&tt); |
| 316 SkASSERT(tt.target()); | 307 SkASSERT(tt.target()); |
| 317 | 308 |
| 318 GrDrawState ds; | 309 GrDrawState ds; |
| 319 ds.setVertexAttribs<kAttribs>(2, sizeof(Vertex)); | |
| 320 | 310 |
| 321 GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, ds.get
VertexStride(), 0); | 311 GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->ge
tVertexStride(), 0); |
| 312 SkASSERT(gp->getVertexStride() == sizeof(Vertex)); |
| 322 Vertex* verts = reinterpret_cast<Vertex*>(geo.vertices()); | 313 Vertex* verts = reinterpret_cast<Vertex*>(geo.vertices()); |
| 323 | 314 |
| 324 verts[0].fPosition.setRectFan(bounds.fLeft, bounds.fTop, | 315 verts[0].fPosition.setRectFan(bounds.fLeft, bounds.fTop, |
| 325 bounds.fRight, bounds.fBottom, | 316 bounds.fRight, bounds.fBottom, |
| 326 sizeof(Vertex)); | 317 sizeof(Vertex)); |
| 327 for (int v = 0; v < 4; ++v) { | 318 for (int v = 0; v < 4; ++v) { |
| 328 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); |
| 329 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); |
| 330 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); |
| 331 } | 322 } |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 boundsPaint.setColor(0xff808080); | 488 boundsPaint.setColor(0xff808080); |
| 498 boundsPaint.setStrokeWidth(0); | 489 boundsPaint.setStrokeWidth(0); |
| 499 boundsPaint.setStyle(SkPaint::kStroke_Style); | 490 boundsPaint.setStyle(SkPaint::kStroke_Style); |
| 500 canvas->drawRect(bounds, boundsPaint); | 491 canvas->drawRect(bounds, boundsPaint); |
| 501 | 492 |
| 502 GrTestTarget tt; | 493 GrTestTarget tt; |
| 503 context->getTestTarget(&tt); | 494 context->getTestTarget(&tt); |
| 504 SkASSERT(tt.target()); | 495 SkASSERT(tt.target()); |
| 505 | 496 |
| 506 GrDrawState ds; | 497 GrDrawState ds; |
| 507 ds.setVertexAttribs<kAttribs>(2, sizeof(Vertex)); | |
| 508 | 498 |
| 509 GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, ds.get
VertexStride(), 0); | 499 GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->ge
tVertexStride(), 0); |
| 500 SkASSERT(gp->getVertexStride() == sizeof(Vertex)); |
| 510 Vertex* verts = reinterpret_cast<Vertex*>(geo.vertices()); | 501 Vertex* verts = reinterpret_cast<Vertex*>(geo.vertices()); |
| 511 | 502 |
| 512 verts[0].fPosition.setRectFan(bounds.fLeft, bounds.fTop, | 503 verts[0].fPosition.setRectFan(bounds.fLeft, bounds.fTop, |
| 513 bounds.fRight, bounds.fBottom, | 504 bounds.fRight, bounds.fBottom, |
| 514 sizeof(Vertex)); | 505 sizeof(Vertex)); |
| 515 | 506 |
| 516 GrPathUtils::QuadUVMatrix DevToUV(pts); | 507 GrPathUtils::QuadUVMatrix DevToUV(pts); |
| 517 DevToUV.apply<4, sizeof(Vertex), sizeof(SkPoint)>(verts); | 508 DevToUV.apply<4, sizeof(Vertex), sizeof(SkPoint)>(verts); |
| 518 | 509 |
| 519 ds.setGeometryProcessor(gp); | 510 ds.setGeometryProcessor(gp); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 536 typedef GM INHERITED; | 527 typedef GM INHERITED; |
| 537 }; | 528 }; |
| 538 | 529 |
| 539 DEF_GM( return SkNEW(BezierCubicEffects); ) | 530 DEF_GM( return SkNEW(BezierCubicEffects); ) |
| 540 DEF_GM( return SkNEW(BezierConicEffects); ) | 531 DEF_GM( return SkNEW(BezierConicEffects); ) |
| 541 DEF_GM( return SkNEW(BezierQuadEffects); ) | 532 DEF_GM( return SkNEW(BezierQuadEffects); ) |
| 542 | 533 |
| 543 } | 534 } |
| 544 | 535 |
| 545 #endif | 536 #endif |
| OLD | NEW |