| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 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 #include "GrAAConvexPathRenderer.h" | 9 #include "GrAAConvexPathRenderer.h" |
| 10 | 10 |
| 11 #include "GrContext.h" | 11 #include "GrContext.h" |
| 12 #include "GrDrawState.h" | 12 #include "GrDrawState.h" |
| 13 #include "GrPathUtils.h" | 13 #include "GrPathUtils.h" |
| 14 #include "SkString.h" | 14 #include "SkString.h" |
| 15 #include "SkStrokeRec.h" | 15 #include "SkStrokeRec.h" |
| 16 #include "SkTrace.h" | 16 #include "SkTrace.h" |
| 17 | 17 |
| 18 #include "effects/GrEdgeEffect.h" |
| 19 |
| 18 GrAAConvexPathRenderer::GrAAConvexPathRenderer() { | 20 GrAAConvexPathRenderer::GrAAConvexPathRenderer() { |
| 19 } | 21 } |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 struct Segment { | 25 struct Segment { |
| 24 enum { | 26 enum { |
| 25 // These enum values are assumed in member functions below. | 27 // These enum values are assumed in member functions below. |
| 26 kLine = 0, | 28 kLine = 0, |
| 27 kQuad = 1, | 29 kQuad = 1, |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 | 440 |
| 439 bool GrAAConvexPathRenderer::onDrawPath(const SkPath& origPath, | 441 bool GrAAConvexPathRenderer::onDrawPath(const SkPath& origPath, |
| 440 const SkStrokeRec&, | 442 const SkStrokeRec&, |
| 441 GrDrawTarget* target, | 443 GrDrawTarget* target, |
| 442 bool antiAlias) { | 444 bool antiAlias) { |
| 443 | 445 |
| 444 const SkPath* path = &origPath; | 446 const SkPath* path = &origPath; |
| 445 if (path->isEmpty()) { | 447 if (path->isEmpty()) { |
| 446 return true; | 448 return true; |
| 447 } | 449 } |
| 450 |
| 451 GrDrawTarget::AutoStateRestore asr(target, GrDrawTarget::kPreserve_ASRInit); |
| 448 GrDrawState* drawState = target->drawState(); | 452 GrDrawState* drawState = target->drawState(); |
| 449 | 453 |
| 450 GrDrawState::AutoDeviceCoordDraw adcd(drawState); | 454 GrDrawState::AutoDeviceCoordDraw adcd(drawState); |
| 451 if (!adcd.succeeded()) { | 455 if (!adcd.succeeded()) { |
| 452 return false; | 456 return false; |
| 453 } | 457 } |
| 454 const SkMatrix* vm = &adcd.getOriginalMatrix(); | 458 const SkMatrix* vm = &adcd.getOriginalMatrix(); |
| 455 | 459 |
| 456 // We use the fact that SkPath::transform path does subdivision based on | 460 // We use the fact that SkPath::transform path does subdivision based on |
| 457 // perspective. Otherwise, we apply the view matrix when copying to the | 461 // perspective. Otherwise, we apply the view matrix when copying to the |
| (...skipping 18 matching lines...) Expand all Loading... |
| 476 | 480 |
| 477 if (!get_segments(*path, *vm, &segments, &fanPt, &vCount, &iCount)) { | 481 if (!get_segments(*path, *vm, &segments, &fanPt, &vCount, &iCount)) { |
| 478 return false; | 482 return false; |
| 479 } | 483 } |
| 480 | 484 |
| 481 // position + edge | 485 // position + edge |
| 482 static const GrVertexAttrib kAttribs[] = { | 486 static const GrVertexAttrib kAttribs[] = { |
| 483 {kVec2f_GrVertexAttribType, 0}, | 487 {kVec2f_GrVertexAttribType, 0}, |
| 484 {kVec4f_GrVertexAttribType, sizeof(GrPoint)} | 488 {kVec4f_GrVertexAttribType, sizeof(GrPoint)} |
| 485 }; | 489 }; |
| 486 static const GrAttribBindings bindings = GrDrawState::kEdge_AttribBindingsBi
t; | |
| 487 | 490 |
| 488 drawState->setVertexAttribs(kAttribs, SK_ARRAY_COUNT(kAttribs)); | 491 drawState->setVertexAttribs(kAttribs, SK_ARRAY_COUNT(kAttribs)); |
| 489 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0); | 492 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0); |
| 490 drawState->setAttribIndex(GrDrawState::kEdge_AttribIndex, 1); | 493 drawState->setAttribBindings(GrDrawState::kDefault_AttribBindings); |
| 491 drawState->setAttribBindings(bindings); | 494 |
| 495 enum { |
| 496 // the edge effects share this stage with glyph rendering |
| 497 // (kGlyphMaskStage in GrTextContext) && SW path rendering |
| 498 // (kPathMaskStage in GrSWMaskHelper) |
| 499 kEdgeEffectStage = GrPaint::kTotalStages, |
| 500 }; |
| 501 static const int kEdgeAttrIndex = 1; |
| 502 GrEffectRef* quadEffect = GrEdgeEffect::Create(GrEdgeEffect::kQuad_EdgeType)
; |
| 503 drawState->setEffect(kEdgeEffectStage, quadEffect, kEdgeAttrIndex)->unref(); |
| 504 |
| 492 GrDrawTarget::AutoReleaseGeometry arg(target, vCount, iCount); | 505 GrDrawTarget::AutoReleaseGeometry arg(target, vCount, iCount); |
| 493 if (!arg.succeeded()) { | 506 if (!arg.succeeded()) { |
| 494 return false; | 507 return false; |
| 495 } | 508 } |
| 496 GrAssert(sizeof(QuadVertex) == drawState->getVertexSize()); | 509 GrAssert(sizeof(QuadVertex) == drawState->getVertexSize()); |
| 497 verts = reinterpret_cast<QuadVertex*>(arg.vertices()); | 510 verts = reinterpret_cast<QuadVertex*>(arg.vertices()); |
| 498 idxs = reinterpret_cast<uint16_t*>(arg.indices()); | 511 idxs = reinterpret_cast<uint16_t*>(arg.indices()); |
| 499 | 512 |
| 500 create_vertices(segments, fanPt, verts, idxs); | 513 create_vertices(segments, fanPt, verts, idxs); |
| 501 | 514 |
| 502 GrDrawState::VertexEdgeType oldEdgeType = drawState->getVertexEdgeType(); | |
| 503 drawState->setVertexEdgeType(GrDrawState::kQuad_EdgeType); | |
| 504 target->drawIndexed(kTriangles_GrPrimitiveType, | 515 target->drawIndexed(kTriangles_GrPrimitiveType, |
| 505 0, // start vertex | 516 0, // start vertex |
| 506 0, // start index | 517 0, // start index |
| 507 vCount, | 518 vCount, |
| 508 iCount); | 519 iCount); |
| 509 drawState->setVertexEdgeType(oldEdgeType); | |
| 510 | 520 |
| 511 return true; | 521 return true; |
| 512 } | 522 } |
| OLD | NEW |