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