| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #include "GrAAHairLinePathRenderer.h" | 8 #include "GrAAHairLinePathRenderer.h" |
| 9 | 9 |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 case SkPath::kClose_Verb: | 416 case SkPath::kClose_Verb: |
| 417 break; | 417 break; |
| 418 case SkPath::kDone_Verb: | 418 case SkPath::kDone_Verb: |
| 419 return totalQuadCount; | 419 return totalQuadCount; |
| 420 } | 420 } |
| 421 } | 421 } |
| 422 } | 422 } |
| 423 | 423 |
| 424 struct LineVertex { | 424 struct LineVertex { |
| 425 SkPoint fPos; | 425 SkPoint fPos; |
| 426 GrColor fCoverage; | 426 float fCoverage; |
| 427 }; | 427 }; |
| 428 | 428 |
| 429 struct BezierVertex { | 429 struct BezierVertex { |
| 430 SkPoint fPos; | 430 SkPoint fPos; |
| 431 union { | 431 union { |
| 432 struct { | 432 struct { |
| 433 SkScalar fK; | 433 SkScalar fK; |
| 434 SkScalar fL; | 434 SkScalar fL; |
| 435 SkScalar fM; | 435 SkScalar fM; |
| 436 } fConic; | 436 } fConic; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 add_quads(newP + 2, subdiv-1, toDevice, toSrc, vert, devBounds); | 587 add_quads(newP + 2, subdiv-1, toDevice, toSrc, vert, devBounds); |
| 588 } else { | 588 } else { |
| 589 bloat_quad(p, toDevice, toSrc, *vert, devBounds); | 589 bloat_quad(p, toDevice, toSrc, *vert, devBounds); |
| 590 set_uv_quad(p, *vert); | 590 set_uv_quad(p, *vert); |
| 591 *vert += kQuadNumVertices; | 591 *vert += kQuadNumVertices; |
| 592 } | 592 } |
| 593 } | 593 } |
| 594 | 594 |
| 595 void add_line(const SkPoint p[2], | 595 void add_line(const SkPoint p[2], |
| 596 const SkMatrix* toSrc, | 596 const SkMatrix* toSrc, |
| 597 GrColor coverage, | 597 uint8_t coverage, |
| 598 LineVertex** vert) { | 598 LineVertex** vert) { |
| 599 const SkPoint& a = p[0]; | 599 const SkPoint& a = p[0]; |
| 600 const SkPoint& b = p[1]; | 600 const SkPoint& b = p[1]; |
| 601 | 601 |
| 602 SkVector ortho, vec = b; | 602 SkVector ortho, vec = b; |
| 603 vec -= a; | 603 vec -= a; |
| 604 | 604 |
| 605 if (vec.setLength(SK_ScalarHalf)) { | 605 if (vec.setLength(SK_ScalarHalf)) { |
| 606 // Create a vector orthogonal to 'vec' and of unit length | 606 // Create a vector orthogonal to 'vec' and of unit length |
| 607 ortho.fX = 2.0f * vec.fY; | 607 ortho.fX = 2.0f * vec.fY; |
| 608 ortho.fY = -2.0f * vec.fX; | 608 ortho.fY = -2.0f * vec.fX; |
| 609 | 609 |
| 610 float floatCoverage = GrNormalizeByteToFloat(coverage); |
| 611 |
| 610 (*vert)[0].fPos = a; | 612 (*vert)[0].fPos = a; |
| 611 (*vert)[0].fCoverage = coverage; | 613 (*vert)[0].fCoverage = floatCoverage; |
| 612 (*vert)[1].fPos = b; | 614 (*vert)[1].fPos = b; |
| 613 (*vert)[1].fCoverage = coverage; | 615 (*vert)[1].fCoverage = floatCoverage; |
| 614 (*vert)[2].fPos = a - vec + ortho; | 616 (*vert)[2].fPos = a - vec + ortho; |
| 615 (*vert)[2].fCoverage = 0; | 617 (*vert)[2].fCoverage = 0; |
| 616 (*vert)[3].fPos = b + vec + ortho; | 618 (*vert)[3].fPos = b + vec + ortho; |
| 617 (*vert)[3].fCoverage = 0; | 619 (*vert)[3].fCoverage = 0; |
| 618 (*vert)[4].fPos = a - vec - ortho; | 620 (*vert)[4].fPos = a - vec - ortho; |
| 619 (*vert)[4].fCoverage = 0; | 621 (*vert)[4].fCoverage = 0; |
| 620 (*vert)[5].fPos = b + vec - ortho; | 622 (*vert)[5].fPos = b + vec - ortho; |
| 621 (*vert)[5].fCoverage = 0; | 623 (*vert)[5].fCoverage = 0; |
| 622 | 624 |
| 623 if (toSrc) { | 625 if (toSrc) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 643 | 645 |
| 644 // position + edge | 646 // position + edge |
| 645 extern const GrVertexAttrib gHairlineBezierAttribs[] = { | 647 extern const GrVertexAttrib gHairlineBezierAttribs[] = { |
| 646 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing}, | 648 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing}, |
| 647 {kVec4f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexA
ttribBinding} | 649 {kVec4f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexA
ttribBinding} |
| 648 }; | 650 }; |
| 649 | 651 |
| 650 // position + coverage | 652 // position + coverage |
| 651 extern const GrVertexAttrib gHairlineLineAttribs[] = { | 653 extern const GrVertexAttrib gHairlineLineAttribs[] = { |
| 652 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindin
g}, | 654 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindin
g}, |
| 653 {kUByte_GrVertexAttribType, sizeof(SkPoint), kCoverage_GrVertexAttribBinding
}, | 655 {kFloat_GrVertexAttribType, sizeof(SkPoint), kCoverage_GrVertexAttribBinding
}, |
| 654 }; | 656 }; |
| 655 | 657 |
| 656 }; | 658 }; |
| 657 | 659 |
| 658 bool GrAAHairLinePathRenderer::createLineGeom(const SkPath& path, | 660 bool GrAAHairLinePathRenderer::createLineGeom(const SkPath& path, |
| 659 GrDrawTarget* target, | 661 GrDrawTarget* target, |
| 660 const PtArray& lines, | 662 const PtArray& lines, |
| 661 int lineCnt, | 663 int lineCnt, |
| 662 GrDrawTarget::AutoReleaseGeometry*
arg, | 664 GrDrawTarget::AutoReleaseGeometry*
arg, |
| 663 SkRect* devBounds) { | 665 SkRect* devBounds) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 679 const SkMatrix* toSrc = NULL; | 681 const SkMatrix* toSrc = NULL; |
| 680 SkMatrix ivm; | 682 SkMatrix ivm; |
| 681 | 683 |
| 682 if (viewM.hasPerspective()) { | 684 if (viewM.hasPerspective()) { |
| 683 if (viewM.invert(&ivm)) { | 685 if (viewM.invert(&ivm)) { |
| 684 toSrc = &ivm; | 686 toSrc = &ivm; |
| 685 } | 687 } |
| 686 } | 688 } |
| 687 devBounds->set(lines.begin(), lines.count()); | 689 devBounds->set(lines.begin(), lines.count()); |
| 688 for (int i = 0; i < lineCnt; ++i) { | 690 for (int i = 0; i < lineCnt; ++i) { |
| 689 add_line(&lines[2*i], toSrc, drawState->getCoverageColor(), &verts); | 691 add_line(&lines[2*i], toSrc, drawState->getCoverage(), &verts); |
| 690 } | 692 } |
| 691 // All the verts computed by add_line are within sqrt(1^2 + 0.5^2) of the en
d points. | 693 // All the verts computed by add_line are within sqrt(1^2 + 0.5^2) of the en
d points. |
| 692 static const SkScalar kSqrtOfOneAndAQuarter = 1.118f; | 694 static const SkScalar kSqrtOfOneAndAQuarter = 1.118f; |
| 693 // Add a little extra to account for vector normalization precision. | 695 // Add a little extra to account for vector normalization precision. |
| 694 static const SkScalar kOutset = kSqrtOfOneAndAQuarter + SK_Scalar1 / 20; | 696 static const SkScalar kOutset = kSqrtOfOneAndAQuarter + SK_Scalar1 / 20; |
| 695 devBounds->outset(kOutset, kOutset); | 697 devBounds->outset(kOutset, kOutset); |
| 696 | 698 |
| 697 return true; | 699 return true; |
| 698 } | 700 } |
| 699 | 701 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 &devBounds); | 969 &devBounds); |
| 968 conics += n; | 970 conics += n; |
| 969 } | 971 } |
| 970 } | 972 } |
| 971 } | 973 } |
| 972 | 974 |
| 973 target->resetIndexSource(); | 975 target->resetIndexSource(); |
| 974 | 976 |
| 975 return true; | 977 return true; |
| 976 } | 978 } |
| OLD | NEW |