| 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" |
| 11 #include "GrDrawState.h" | 11 #include "GrDrawState.h" |
| 12 #include "GrDrawTargetCaps.h" | 12 #include "GrDrawTargetCaps.h" |
| 13 #include "GrProcessor.h" | 13 #include "GrProcessor.h" |
| 14 #include "GrGpu.h" | 14 #include "GrGpu.h" |
| 15 #include "GrIndexBuffer.h" | 15 #include "GrIndexBuffer.h" |
| 16 #include "GrPathUtils.h" | 16 #include "GrPathUtils.h" |
| 17 #include "GrTBackendProcessorFactory.h" | 17 #include "GrTBackendProcessorFactory.h" |
| 18 #include "SkGeometry.h" | 18 #include "SkGeometry.h" |
| 19 #include "SkStroke.h" | 19 #include "SkStroke.h" |
| 20 #include "SkTemplates.h" | 20 #include "SkTemplates.h" |
| 21 | 21 |
| 22 #include "effects/GrBezierEffect.h" | 22 #include "effects/GrBezierEffect.h" |
| 23 | 23 |
| 24 namespace { |
| 24 // quadratics are rendered as 5-sided polys in order to bound the | 25 // quadratics are rendered as 5-sided polys in order to bound the |
| 25 // AA stroke around the center-curve. See comments in push_quad_index_buffer and | 26 // AA stroke around the center-curve. See comments in push_quad_index_buffer and |
| 26 // bloat_quad. Quadratics and conics share an index buffer | 27 // bloat_quad. Quadratics and conics share an index buffer |
| 28 static const int kVertsPerQuad = 5; |
| 29 static const int kIdxsPerQuad = 9; |
| 27 | 30 |
| 28 // lines are rendered as: | 31 // lines are rendered as: |
| 29 // *______________* | 32 // *______________* |
| 30 // |\ -_______ /| | 33 // |\ -_______ /| |
| 31 // | \ \ / | | 34 // | \ \ / | |
| 32 // | *--------* | | 35 // | *--------* | |
| 33 // | / ______/ \ | | 36 // | / ______/ \ | |
| 34 // */_-__________\* | 37 // */_-__________\* |
| 35 // For: 6 vertices and 18 indices (for 6 triangles) | 38 // For: 6 vertices and 18 indices (for 6 triangles) |
| 39 static const int kVertsPerLineSeg = 6; |
| 40 static const int kIdxsPerLineSeg = 18; |
| 36 | 41 |
| 37 // Each quadratic is rendered as a five sided polygon. This poly bounds | 42 static const int kNumQuadsInIdxBuffer = 256; |
| 38 // the quadratic's bounding triangle but has been expanded so that the | 43 static const size_t kQuadIdxSBufize = kIdxsPerQuad * |
| 39 // 1-pixel wide area around the curve is inside the poly. | 44 sizeof(uint16_t) * |
| 40 // If a,b,c are the original control points then the poly a0,b0,c0,c1,a1 | 45 kNumQuadsInIdxBuffer; |
| 41 // that is rendered would look like this: | |
| 42 // b0 | |
| 43 // b | |
| 44 // | |
| 45 // a0 c0 | |
| 46 // a c | |
| 47 // a1 c1 | |
| 48 // Each is drawn as three triangles specified by these 9 indices: | |
| 49 static const uint16_t kQuadIdxBufPattern[] = { | |
| 50 0, 1, 2, | |
| 51 2, 4, 3, | |
| 52 1, 4, 2 | |
| 53 }; | |
| 54 | 46 |
| 55 static const int kIdxsPerQuad = SK_ARRAY_COUNT(kQuadIdxBufPattern); | 47 static const int kNumLineSegsInIdxBuffer = 256; |
| 56 static const int kQuadNumVertices = 5; | 48 static const size_t kLineSegIdxSBufize = kIdxsPerLineSeg * |
| 57 static const int kQuadsNumInIdxBuffer = 256; | 49 sizeof(uint16_t) * |
| 50 kNumLineSegsInIdxBuffer; |
| 58 | 51 |
| 52 static bool push_quad_index_data(GrIndexBuffer* qIdxBuffer) { |
| 53 uint16_t* data = (uint16_t*) qIdxBuffer->map(); |
| 54 bool tempData = NULL == data; |
| 55 if (tempData) { |
| 56 data = SkNEW_ARRAY(uint16_t, kNumQuadsInIdxBuffer * kIdxsPerQuad); |
| 57 } |
| 58 for (int i = 0; i < kNumQuadsInIdxBuffer; ++i) { |
| 59 | 59 |
| 60 // Each line segment is rendered as two quads and two triangles. | 60 // Each quadratic is rendered as a five sided polygon. This poly bounds |
| 61 // p0 and p1 have alpha = 1 while all other points have alpha = 0. | 61 // the quadratic's bounding triangle but has been expanded so that the |
| 62 // The four external points are offset 1 pixel perpendicular to the | 62 // 1-pixel wide area around the curve is inside the poly. |
| 63 // line and half a pixel parallel to the line. | 63 // If a,b,c are the original control points then the poly a0,b0,c0,c1,a1 |
| 64 // | 64 // that is rendered would look like this: |
| 65 // p4 p5 | 65 // b0 |
| 66 // p0 p1 | 66 // b |
| 67 // p2 p3 | 67 // |
| 68 // | 68 // a0 c0 |
| 69 // Each is drawn as six triangles specified by these 18 indices: | 69 // a c |
| 70 // a1 c1 |
| 71 // Each is drawn as three triangles specified by these 9 indices: |
| 72 int baseIdx = i * kIdxsPerQuad; |
| 73 uint16_t baseVert = (uint16_t)(i * kVertsPerQuad); |
| 74 data[0 + baseIdx] = baseVert + 0; // a0 |
| 75 data[1 + baseIdx] = baseVert + 1; // a1 |
| 76 data[2 + baseIdx] = baseVert + 2; // b0 |
| 77 data[3 + baseIdx] = baseVert + 2; // b0 |
| 78 data[4 + baseIdx] = baseVert + 4; // c1 |
| 79 data[5 + baseIdx] = baseVert + 3; // c0 |
| 80 data[6 + baseIdx] = baseVert + 1; // a1 |
| 81 data[7 + baseIdx] = baseVert + 4; // c1 |
| 82 data[8 + baseIdx] = baseVert + 2; // b0 |
| 83 } |
| 84 if (tempData) { |
| 85 bool ret = qIdxBuffer->updateData(data, kQuadIdxSBufize); |
| 86 delete[] data; |
| 87 return ret; |
| 88 } else { |
| 89 qIdxBuffer->unmap(); |
| 90 return true; |
| 91 } |
| 92 } |
| 70 | 93 |
| 71 static const uint16_t kLineSegIdxBufPattern[] = { | 94 static bool push_line_index_data(GrIndexBuffer* lIdxBuffer) { |
| 72 0, 1, 3, | 95 uint16_t* data = (uint16_t*) lIdxBuffer->map(); |
| 73 0, 3, 2, | 96 bool tempData = NULL == data; |
| 74 0, 4, 5, | 97 if (tempData) { |
| 75 0, 5, 1, | 98 data = SkNEW_ARRAY(uint16_t, kNumLineSegsInIdxBuffer * kIdxsPerLineSeg); |
| 76 0, 2, 4, | 99 } |
| 77 1, 5, 3 | 100 for (int i = 0; i < kNumLineSegsInIdxBuffer; ++i) { |
| 78 }; | 101 // Each line segment is rendered as two quads and two triangles. |
| 102 // p0 and p1 have alpha = 1 while all other points have alpha = 0. |
| 103 // The four external points are offset 1 pixel perpendicular to the |
| 104 // line and half a pixel parallel to the line. |
| 105 // |
| 106 // p4 p5 |
| 107 // p0 p1 |
| 108 // p2 p3 |
| 109 // |
| 110 // Each is drawn as six triangles specified by these 18 indices: |
| 111 int baseIdx = i * kIdxsPerLineSeg; |
| 112 uint16_t baseVert = (uint16_t)(i * kVertsPerLineSeg); |
| 113 data[0 + baseIdx] = baseVert + 0; |
| 114 data[1 + baseIdx] = baseVert + 1; |
| 115 data[2 + baseIdx] = baseVert + 3; |
| 79 | 116 |
| 80 static const int kIdxsPerLineSeg = SK_ARRAY_COUNT(kLineSegIdxBufPattern); | 117 data[3 + baseIdx] = baseVert + 0; |
| 81 static const int kLineSegNumVertices = 6; | 118 data[4 + baseIdx] = baseVert + 3; |
| 82 static const int kLineSegsNumInIdxBuffer = 256; | 119 data[5 + baseIdx] = baseVert + 2; |
| 120 |
| 121 data[6 + baseIdx] = baseVert + 0; |
| 122 data[7 + baseIdx] = baseVert + 4; |
| 123 data[8 + baseIdx] = baseVert + 5; |
| 124 |
| 125 data[9 + baseIdx] = baseVert + 0; |
| 126 data[10+ baseIdx] = baseVert + 5; |
| 127 data[11+ baseIdx] = baseVert + 1; |
| 128 |
| 129 data[12 + baseIdx] = baseVert + 0; |
| 130 data[13 + baseIdx] = baseVert + 2; |
| 131 data[14 + baseIdx] = baseVert + 4; |
| 132 |
| 133 data[15 + baseIdx] = baseVert + 1; |
| 134 data[16 + baseIdx] = baseVert + 5; |
| 135 data[17 + baseIdx] = baseVert + 3; |
| 136 } |
| 137 if (tempData) { |
| 138 bool ret = lIdxBuffer->updateData(data, kLineSegIdxSBufize); |
| 139 delete[] data; |
| 140 return ret; |
| 141 } else { |
| 142 lIdxBuffer->unmap(); |
| 143 return true; |
| 144 } |
| 145 } |
| 146 } |
| 83 | 147 |
| 84 GrPathRenderer* GrAAHairLinePathRenderer::Create(GrContext* context) { | 148 GrPathRenderer* GrAAHairLinePathRenderer::Create(GrContext* context) { |
| 85 GrGpu* gpu = context->getGpu(); | 149 GrGpu* gpu = context->getGpu(); |
| 86 GrIndexBuffer* qIdxBuf = gpu->createInstancedIndexBuffer(kQuadIdxBufPattern, | 150 GrIndexBuffer* qIdxBuf = gpu->createIndexBuffer(kQuadIdxSBufize, false); |
| 87 kIdxsPerQuad, | |
| 88 kQuadsNumInIdxBuffe
r, | |
| 89 kQuadNumVertices); | |
| 90 SkAutoTUnref<GrIndexBuffer> qIdxBuffer(qIdxBuf); | 151 SkAutoTUnref<GrIndexBuffer> qIdxBuffer(qIdxBuf); |
| 91 GrIndexBuffer* lIdxBuf = gpu->createInstancedIndexBuffer(kLineSegIdxBufPatte
rn, | 152 if (NULL == qIdxBuf || !push_quad_index_data(qIdxBuf)) { |
| 92 kIdxsPerLineSeg, | 153 return NULL; |
| 93 kLineSegsNumInIdxBu
ffer, | 154 } |
| 94 kLineSegNumVertices
); | 155 GrIndexBuffer* lIdxBuf = gpu->createIndexBuffer(kLineSegIdxSBufize, false); |
| 95 SkAutoTUnref<GrIndexBuffer> lIdxBuffer(lIdxBuf); | 156 SkAutoTUnref<GrIndexBuffer> lIdxBuffer(lIdxBuf); |
| 157 if (NULL == lIdxBuf || !push_line_index_data(lIdxBuf)) { |
| 158 return NULL; |
| 159 } |
| 96 return SkNEW_ARGS(GrAAHairLinePathRenderer, | 160 return SkNEW_ARGS(GrAAHairLinePathRenderer, |
| 97 (context, lIdxBuf, qIdxBuf)); | 161 (context, lIdxBuf, qIdxBuf)); |
| 98 } | 162 } |
| 99 | 163 |
| 100 GrAAHairLinePathRenderer::GrAAHairLinePathRenderer( | 164 GrAAHairLinePathRenderer::GrAAHairLinePathRenderer( |
| 101 const GrContext* context, | 165 const GrContext* context, |
| 102 const GrIndexBuffer* linesIndexBuffer, | 166 const GrIndexBuffer* linesIndexBuffer, |
| 103 const GrIndexBuffer* quadsIndexBuffer) { | 167 const GrIndexBuffer* quadsIndexBuffer) { |
| 104 fLinesIndexBuffer = linesIndexBuffer; | 168 fLinesIndexBuffer = linesIndexBuffer; |
| 105 linesIndexBuffer->ref(); | 169 linesIndexBuffer->ref(); |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 SkScalarMul(normA.fY, normB.fX); | 518 SkScalarMul(normA.fY, normB.fX); |
| 455 wInv = SkScalarInvert(wInv); | 519 wInv = SkScalarInvert(wInv); |
| 456 | 520 |
| 457 result->fX = SkScalarMul(normA.fY, lineBW) - SkScalarMul(lineAW, normB.fY); | 521 result->fX = SkScalarMul(normA.fY, lineBW) - SkScalarMul(lineAW, normB.fY); |
| 458 result->fX = SkScalarMul(result->fX, wInv); | 522 result->fX = SkScalarMul(result->fX, wInv); |
| 459 | 523 |
| 460 result->fY = SkScalarMul(lineAW, normB.fX) - SkScalarMul(normA.fX, lineBW); | 524 result->fY = SkScalarMul(lineAW, normB.fX) - SkScalarMul(normA.fX, lineBW); |
| 461 result->fY = SkScalarMul(result->fY, wInv); | 525 result->fY = SkScalarMul(result->fY, wInv); |
| 462 } | 526 } |
| 463 | 527 |
| 464 void set_uv_quad(const SkPoint qpts[3], BezierVertex verts[kQuadNumVertices]) { | 528 void set_uv_quad(const SkPoint qpts[3], BezierVertex verts[kVertsPerQuad]) { |
| 465 // this should be in the src space, not dev coords, when we have perspective | 529 // this should be in the src space, not dev coords, when we have perspective |
| 466 GrPathUtils::QuadUVMatrix DevToUV(qpts); | 530 GrPathUtils::QuadUVMatrix DevToUV(qpts); |
| 467 DevToUV.apply<kQuadNumVertices, sizeof(BezierVertex), sizeof(SkPoint)>(verts
); | 531 DevToUV.apply<kVertsPerQuad, sizeof(BezierVertex), sizeof(SkPoint)>(verts); |
| 468 } | 532 } |
| 469 | 533 |
| 470 void bloat_quad(const SkPoint qpts[3], const SkMatrix* toDevice, | 534 void bloat_quad(const SkPoint qpts[3], const SkMatrix* toDevice, |
| 471 const SkMatrix* toSrc, BezierVertex verts[kQuadNumVertices], | 535 const SkMatrix* toSrc, BezierVertex verts[kVertsPerQuad], |
| 472 SkRect* devBounds) { | 536 SkRect* devBounds) { |
| 473 SkASSERT(!toDevice == !toSrc); | 537 SkASSERT(!toDevice == !toSrc); |
| 474 // original quad is specified by tri a,b,c | 538 // original quad is specified by tri a,b,c |
| 475 SkPoint a = qpts[0]; | 539 SkPoint a = qpts[0]; |
| 476 SkPoint b = qpts[1]; | 540 SkPoint b = qpts[1]; |
| 477 SkPoint c = qpts[2]; | 541 SkPoint c = qpts[2]; |
| 478 | 542 |
| 479 if (toDevice) { | 543 if (toDevice) { |
| 480 toDevice->mapPoints(&a, 1); | 544 toDevice->mapPoints(&a, 1); |
| 481 toDevice->mapPoints(&b, 1); | 545 toDevice->mapPoints(&b, 1); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 a0.fPos += abN; | 591 a0.fPos += abN; |
| 528 a1.fPos = a; | 592 a1.fPos = a; |
| 529 a1.fPos -= abN; | 593 a1.fPos -= abN; |
| 530 | 594 |
| 531 c0.fPos = c; | 595 c0.fPos = c; |
| 532 c0.fPos += cbN; | 596 c0.fPos += cbN; |
| 533 c1.fPos = c; | 597 c1.fPos = c; |
| 534 c1.fPos -= cbN; | 598 c1.fPos -= cbN; |
| 535 | 599 |
| 536 intersect_lines(a0.fPos, abN, c0.fPos, cbN, &b0.fPos); | 600 intersect_lines(a0.fPos, abN, c0.fPos, cbN, &b0.fPos); |
| 537 devBounds->growToInclude(&verts[0].fPos, sizeof(BezierVertex), kQuadNumVerti
ces); | 601 devBounds->growToInclude(&verts[0].fPos, sizeof(BezierVertex), kVertsPerQuad
); |
| 538 | 602 |
| 539 if (toSrc) { | 603 if (toSrc) { |
| 540 toSrc->mapPointsWithStride(&verts[0].fPos, sizeof(BezierVertex), kQuadNu
mVertices); | 604 toSrc->mapPointsWithStride(&verts[0].fPos, sizeof(BezierVertex), kVertsP
erQuad); |
| 541 } | 605 } |
| 542 } | 606 } |
| 543 | 607 |
| 544 // Equations based off of Loop-Blinn Quadratic GPU Rendering | 608 // Equations based off of Loop-Blinn Quadratic GPU Rendering |
| 545 // Input Parametric: | 609 // Input Parametric: |
| 546 // P(t) = (P0*(1-t)^2 + 2*w*P1*t*(1-t) + P2*t^2) / (1-t)^2 + 2*w*t*(1-t) + t^2) | 610 // P(t) = (P0*(1-t)^2 + 2*w*P1*t*(1-t) + P2*t^2) / (1-t)^2 + 2*w*t*(1-t) + t^2) |
| 547 // Output Implicit: | 611 // Output Implicit: |
| 548 // f(x, y, w) = f(P) = K^2 - LM | 612 // f(x, y, w) = f(P) = K^2 - LM |
| 549 // K = dot(k, P), L = dot(l, P), M = dot(m, P) | 613 // K = dot(k, P), L = dot(l, P), M = dot(m, P) |
| 550 // k, l, m are calculated in function GrPathUtils::getConicKLM | 614 // k, l, m are calculated in function GrPathUtils::getConicKLM |
| 551 void set_conic_coeffs(const SkPoint p[3], BezierVertex verts[kQuadNumVertices], | 615 void set_conic_coeffs(const SkPoint p[3], BezierVertex verts[kVertsPerQuad], |
| 552 const SkScalar weight) { | 616 const SkScalar weight) { |
| 553 SkScalar klm[9]; | 617 SkScalar klm[9]; |
| 554 | 618 |
| 555 GrPathUtils::getConicKLM(p, weight, klm); | 619 GrPathUtils::getConicKLM(p, weight, klm); |
| 556 | 620 |
| 557 for (int i = 0; i < kQuadNumVertices; ++i) { | 621 for (int i = 0; i < kVertsPerQuad; ++i) { |
| 558 const SkPoint pnt = verts[i].fPos; | 622 const SkPoint pnt = verts[i].fPos; |
| 559 verts[i].fConic.fK = pnt.fX * klm[0] + pnt.fY * klm[1] + klm[2]; | 623 verts[i].fConic.fK = pnt.fX * klm[0] + pnt.fY * klm[1] + klm[2]; |
| 560 verts[i].fConic.fL = pnt.fX * klm[3] + pnt.fY * klm[4] + klm[5]; | 624 verts[i].fConic.fL = pnt.fX * klm[3] + pnt.fY * klm[4] + klm[5]; |
| 561 verts[i].fConic.fM = pnt.fX * klm[6] + pnt.fY * klm[7] + klm[8]; | 625 verts[i].fConic.fM = pnt.fX * klm[6] + pnt.fY * klm[7] + klm[8]; |
| 562 } | 626 } |
| 563 } | 627 } |
| 564 | 628 |
| 565 void add_conics(const SkPoint p[3], | 629 void add_conics(const SkPoint p[3], |
| 566 const SkScalar weight, | 630 const SkScalar weight, |
| 567 const SkMatrix* toDevice, | 631 const SkMatrix* toDevice, |
| 568 const SkMatrix* toSrc, | 632 const SkMatrix* toSrc, |
| 569 BezierVertex** vert, | 633 BezierVertex** vert, |
| 570 SkRect* devBounds) { | 634 SkRect* devBounds) { |
| 571 bloat_quad(p, toDevice, toSrc, *vert, devBounds); | 635 bloat_quad(p, toDevice, toSrc, *vert, devBounds); |
| 572 set_conic_coeffs(p, *vert, weight); | 636 set_conic_coeffs(p, *vert, weight); |
| 573 *vert += kQuadNumVertices; | 637 *vert += kVertsPerQuad; |
| 574 } | 638 } |
| 575 | 639 |
| 576 void add_quads(const SkPoint p[3], | 640 void add_quads(const SkPoint p[3], |
| 577 int subdiv, | 641 int subdiv, |
| 578 const SkMatrix* toDevice, | 642 const SkMatrix* toDevice, |
| 579 const SkMatrix* toSrc, | 643 const SkMatrix* toSrc, |
| 580 BezierVertex** vert, | 644 BezierVertex** vert, |
| 581 SkRect* devBounds) { | 645 SkRect* devBounds) { |
| 582 SkASSERT(subdiv >= 0); | 646 SkASSERT(subdiv >= 0); |
| 583 if (subdiv) { | 647 if (subdiv) { |
| 584 SkPoint newP[5]; | 648 SkPoint newP[5]; |
| 585 SkChopQuadAtHalf(p, newP); | 649 SkChopQuadAtHalf(p, newP); |
| 586 add_quads(newP + 0, subdiv-1, toDevice, toSrc, vert, devBounds); | 650 add_quads(newP + 0, subdiv-1, toDevice, toSrc, vert, devBounds); |
| 587 add_quads(newP + 2, subdiv-1, toDevice, toSrc, vert, devBounds); | 651 add_quads(newP + 2, subdiv-1, toDevice, toSrc, vert, devBounds); |
| 588 } else { | 652 } else { |
| 589 bloat_quad(p, toDevice, toSrc, *vert, devBounds); | 653 bloat_quad(p, toDevice, toSrc, *vert, devBounds); |
| 590 set_uv_quad(p, *vert); | 654 set_uv_quad(p, *vert); |
| 591 *vert += kQuadNumVertices; | 655 *vert += kVertsPerQuad; |
| 592 } | 656 } |
| 593 } | 657 } |
| 594 | 658 |
| 595 void add_line(const SkPoint p[2], | 659 void add_line(const SkPoint p[2], |
| 596 const SkMatrix* toSrc, | 660 const SkMatrix* toSrc, |
| 597 GrColor coverage, | 661 GrColor coverage, |
| 598 LineVertex** vert) { | 662 LineVertex** vert) { |
| 599 const SkPoint& a = p[0]; | 663 const SkPoint& a = p[0]; |
| 600 const SkPoint& b = p[1]; | 664 const SkPoint& b = p[1]; |
| 601 | 665 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 616 (*vert)[3].fPos = b + vec + ortho; | 680 (*vert)[3].fPos = b + vec + ortho; |
| 617 (*vert)[3].fCoverage = 0; | 681 (*vert)[3].fCoverage = 0; |
| 618 (*vert)[4].fPos = a - vec - ortho; | 682 (*vert)[4].fPos = a - vec - ortho; |
| 619 (*vert)[4].fCoverage = 0; | 683 (*vert)[4].fCoverage = 0; |
| 620 (*vert)[5].fPos = b + vec - ortho; | 684 (*vert)[5].fPos = b + vec - ortho; |
| 621 (*vert)[5].fCoverage = 0; | 685 (*vert)[5].fCoverage = 0; |
| 622 | 686 |
| 623 if (toSrc) { | 687 if (toSrc) { |
| 624 toSrc->mapPointsWithStride(&(*vert)->fPos, | 688 toSrc->mapPointsWithStride(&(*vert)->fPos, |
| 625 sizeof(LineVertex), | 689 sizeof(LineVertex), |
| 626 kLineSegNumVertices); | 690 kVertsPerLineSeg); |
| 627 } | 691 } |
| 628 } else { | 692 } else { |
| 629 // just make it degenerate and likely offscreen | 693 // just make it degenerate and likely offscreen |
| 630 for (int i = 0; i < kLineSegNumVertices; ++i) { | 694 for (int i = 0; i < kVertsPerLineSeg; ++i) { |
| 631 (*vert)[i].fPos.set(SK_ScalarMax, SK_ScalarMax); | 695 (*vert)[i].fPos.set(SK_ScalarMax, SK_ScalarMax); |
| 632 } | 696 } |
| 633 } | 697 } |
| 634 | 698 |
| 635 *vert += kLineSegNumVertices; | 699 *vert += kVertsPerLineSeg; |
| 636 } | 700 } |
| 637 | 701 |
| 638 } | 702 } |
| 639 | 703 |
| 640 /////////////////////////////////////////////////////////////////////////////// | 704 /////////////////////////////////////////////////////////////////////////////// |
| 641 | 705 |
| 642 namespace { | 706 namespace { |
| 643 | 707 |
| 644 // position + edge | 708 // position + edge |
| 645 extern const GrVertexAttrib gHairlineBezierAttribs[] = { | 709 extern const GrVertexAttrib gHairlineBezierAttribs[] = { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 658 bool GrAAHairLinePathRenderer::createLineGeom(const SkPath& path, | 722 bool GrAAHairLinePathRenderer::createLineGeom(const SkPath& path, |
| 659 GrDrawTarget* target, | 723 GrDrawTarget* target, |
| 660 const PtArray& lines, | 724 const PtArray& lines, |
| 661 int lineCnt, | 725 int lineCnt, |
| 662 GrDrawTarget::AutoReleaseGeometry*
arg, | 726 GrDrawTarget::AutoReleaseGeometry*
arg, |
| 663 SkRect* devBounds) { | 727 SkRect* devBounds) { |
| 664 GrDrawState* drawState = target->drawState(); | 728 GrDrawState* drawState = target->drawState(); |
| 665 | 729 |
| 666 const SkMatrix& viewM = drawState->getViewMatrix(); | 730 const SkMatrix& viewM = drawState->getViewMatrix(); |
| 667 | 731 |
| 668 int vertCnt = kLineSegNumVertices * lineCnt; | 732 int vertCnt = kVertsPerLineSeg * lineCnt; |
| 669 | 733 |
| 670 drawState->setVertexAttribs<gHairlineLineAttribs>(SK_ARRAY_COUNT(gHairlineLi
neAttribs), | 734 drawState->setVertexAttribs<gHairlineLineAttribs>(SK_ARRAY_COUNT(gHairlineLi
neAttribs), |
| 671 sizeof(LineVertex)); | 735 sizeof(LineVertex)); |
| 672 | 736 |
| 673 if (!arg->set(target, vertCnt, 0)) { | 737 if (!arg->set(target, vertCnt, 0)) { |
| 674 return false; | 738 return false; |
| 675 } | 739 } |
| 676 | 740 |
| 677 LineVertex* verts = reinterpret_cast<LineVertex*>(arg->vertices()); | 741 LineVertex* verts = reinterpret_cast<LineVertex*>(arg->vertices()); |
| 678 | 742 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 705 const PtArray& conics, | 769 const PtArray& conics, |
| 706 int conicCnt, | 770 int conicCnt, |
| 707 const IntArray& qSubdivs, | 771 const IntArray& qSubdivs, |
| 708 const FloatArray& cWeights, | 772 const FloatArray& cWeights, |
| 709 GrDrawTarget::AutoReleaseGeometry* arg
, | 773 GrDrawTarget::AutoReleaseGeometry* arg
, |
| 710 SkRect* devBounds) { | 774 SkRect* devBounds) { |
| 711 GrDrawState* drawState = target->drawState(); | 775 GrDrawState* drawState = target->drawState(); |
| 712 | 776 |
| 713 const SkMatrix& viewM = drawState->getViewMatrix(); | 777 const SkMatrix& viewM = drawState->getViewMatrix(); |
| 714 | 778 |
| 715 int vertCnt = kQuadNumVertices * quadCnt + kQuadNumVertices * conicCnt; | 779 int vertCnt = kVertsPerQuad * quadCnt + kVertsPerQuad * conicCnt; |
| 716 | 780 |
| 717 int vAttribCnt = SK_ARRAY_COUNT(gHairlineBezierAttribs); | 781 int vAttribCnt = SK_ARRAY_COUNT(gHairlineBezierAttribs); |
| 718 target->drawState()->setVertexAttribs<gHairlineBezierAttribs>(vAttribCnt, si
zeof(BezierVertex)); | 782 target->drawState()->setVertexAttribs<gHairlineBezierAttribs>(vAttribCnt, si
zeof(BezierVertex)); |
| 719 | 783 |
| 720 if (!arg->set(target, vertCnt, 0)) { | 784 if (!arg->set(target, vertCnt, 0)) { |
| 721 return false; | 785 return false; |
| 722 } | 786 } |
| 723 | 787 |
| 724 BezierVertex* verts = reinterpret_cast<BezierVertex*>(arg->vertices()); | 788 BezierVertex* verts = reinterpret_cast<BezierVertex*>(arg->vertices()); |
| 725 | 789 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 // perspective. | 935 // perspective. |
| 872 if (target->getDrawState().getViewMatrix().hasPerspective()) { | 936 if (target->getDrawState().getViewMatrix().hasPerspective()) { |
| 873 asr.set(target, GrDrawTarget::kPreserve_ASRInit); | 937 asr.set(target, GrDrawTarget::kPreserve_ASRInit); |
| 874 } else if (!asr.setIdentity(target, GrDrawTarget::kPreserve_ASRInit)) { | 938 } else if (!asr.setIdentity(target, GrDrawTarget::kPreserve_ASRInit)) { |
| 875 return false; | 939 return false; |
| 876 } | 940 } |
| 877 GrDrawState* drawState = target->drawState(); | 941 GrDrawState* drawState = target->drawState(); |
| 878 | 942 |
| 879 // Check devBounds | 943 // Check devBounds |
| 880 SkASSERT(check_bounds<LineVertex>(drawState, devBounds, arg.vertices(), | 944 SkASSERT(check_bounds<LineVertex>(drawState, devBounds, arg.vertices(), |
| 881 kLineSegNumVertices * lineCnt)); | 945 kVertsPerLineSeg * lineCnt)); |
| 882 | 946 |
| 883 { | 947 { |
| 884 GrDrawState::AutoRestoreEffects are(drawState); | 948 GrDrawState::AutoRestoreEffects are(drawState); |
| 885 target->setIndexSourceToBuffer(fLinesIndexBuffer); | 949 target->setIndexSourceToBuffer(fLinesIndexBuffer); |
| 886 int lines = 0; | 950 int lines = 0; |
| 887 while (lines < lineCnt) { | 951 while (lines < lineCnt) { |
| 888 int n = SkTMin(lineCnt - lines, kLineSegsNumInIdxBuffer); | 952 int n = SkTMin(lineCnt - lines, kNumLineSegsInIdxBuffer); |
| 889 target->drawIndexed(kTriangles_GrPrimitiveType, | 953 target->drawIndexed(kTriangles_GrPrimitiveType, |
| 890 kLineSegNumVertices*lines, // startV | 954 kVertsPerLineSeg*lines, // startV |
| 891 0, // startI | 955 0, // startI |
| 892 kLineSegNumVertices*n, // vCount | 956 kVertsPerLineSeg*n, // vCount |
| 893 kIdxsPerLineSeg*n, // iCount | 957 kIdxsPerLineSeg*n, // iCount |
| 894 &devBounds); | 958 &devBounds); |
| 895 lines += n; | 959 lines += n; |
| 896 } | 960 } |
| 897 } | 961 } |
| 898 } | 962 } |
| 899 | 963 |
| 900 // then quadratics/conics | 964 // then quadratics/conics |
| 901 if (quadCnt || conicCnt) { | 965 if (quadCnt || conicCnt) { |
| 902 GrDrawTarget::AutoReleaseGeometry arg; | 966 GrDrawTarget::AutoReleaseGeometry arg; |
| 903 SkRect devBounds; | 967 SkRect devBounds; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 921 // perspective. | 985 // perspective. |
| 922 if (target->getDrawState().getViewMatrix().hasPerspective()) { | 986 if (target->getDrawState().getViewMatrix().hasPerspective()) { |
| 923 asr.set(target, GrDrawTarget::kPreserve_ASRInit); | 987 asr.set(target, GrDrawTarget::kPreserve_ASRInit); |
| 924 } else if (!asr.setIdentity(target, GrDrawTarget::kPreserve_ASRInit)) { | 988 } else if (!asr.setIdentity(target, GrDrawTarget::kPreserve_ASRInit)) { |
| 925 return false; | 989 return false; |
| 926 } | 990 } |
| 927 GrDrawState* drawState = target->drawState(); | 991 GrDrawState* drawState = target->drawState(); |
| 928 | 992 |
| 929 // Check devBounds | 993 // Check devBounds |
| 930 SkASSERT(check_bounds<BezierVertex>(drawState, devBounds, arg.vertices()
, | 994 SkASSERT(check_bounds<BezierVertex>(drawState, devBounds, arg.vertices()
, |
| 931 kQuadNumVertices * quadCnt + kQuadNu
mVertices * conicCnt)); | 995 kVertsPerQuad * quadCnt + kVertsPerQ
uad * conicCnt)); |
| 932 | 996 |
| 933 if (quadCnt > 0) { | 997 if (quadCnt > 0) { |
| 934 GrGeometryProcessor* hairQuadProcessor = | 998 GrGeometryProcessor* hairQuadProcessor = |
| 935 GrQuadEffect::Create(kHairlineAA_GrProcessorEdgeType, *targe
t->caps()); | 999 GrQuadEffect::Create(kHairlineAA_GrProcessorEdgeType, *targe
t->caps()); |
| 936 SkASSERT(hairQuadProcessor); | 1000 SkASSERT(hairQuadProcessor); |
| 937 GrDrawState::AutoRestoreEffects are(drawState); | 1001 GrDrawState::AutoRestoreEffects are(drawState); |
| 938 target->setIndexSourceToBuffer(fQuadsIndexBuffer); | 1002 target->setIndexSourceToBuffer(fQuadsIndexBuffer); |
| 939 drawState->setGeometryProcessor(hairQuadProcessor)->unref(); | 1003 drawState->setGeometryProcessor(hairQuadProcessor)->unref(); |
| 940 int quads = 0; | 1004 int quads = 0; |
| 941 while (quads < quadCnt) { | 1005 while (quads < quadCnt) { |
| 942 int n = SkTMin(quadCnt - quads, kQuadsNumInIdxBuffer); | 1006 int n = SkTMin(quadCnt - quads, kNumQuadsInIdxBuffer); |
| 943 target->drawIndexed(kTriangles_GrPrimitiveType, | 1007 target->drawIndexed(kTriangles_GrPrimitiveType, |
| 944 kQuadNumVertices*quads, // sta
rtV | 1008 kVertsPerQuad*quads, // startV |
| 945 0, // sta
rtI | 1009 0, // startI |
| 946 kQuadNumVertices*n, // vCo
unt | 1010 kVertsPerQuad*n, // vCount |
| 947 kIdxsPerQuad*n, // iCo
unt | 1011 kIdxsPerQuad*n, // iCount |
| 948 &devBounds); | 1012 &devBounds); |
| 949 quads += n; | 1013 quads += n; |
| 950 } | 1014 } |
| 951 } | 1015 } |
| 952 | 1016 |
| 953 if (conicCnt > 0) { | 1017 if (conicCnt > 0) { |
| 954 GrDrawState::AutoRestoreEffects are(drawState); | 1018 GrDrawState::AutoRestoreEffects are(drawState); |
| 955 GrGeometryProcessor* hairConicProcessor = GrConicEffect::Create( | 1019 GrGeometryProcessor* hairConicProcessor = GrConicEffect::Create( |
| 956 kHairlineAA_GrProcessorEdgeType, *target->caps()); | 1020 kHairlineAA_GrProcessorEdgeType, *target->caps()); |
| 957 SkASSERT(hairConicProcessor); | 1021 SkASSERT(hairConicProcessor); |
| 958 drawState->setGeometryProcessor(hairConicProcessor)->unref(); | 1022 drawState->setGeometryProcessor(hairConicProcessor)->unref(); |
| 959 int conics = 0; | 1023 int conics = 0; |
| 960 while (conics < conicCnt) { | 1024 while (conics < conicCnt) { |
| 961 int n = SkTMin(conicCnt - conics, kQuadsNumInIdxBuffer); | 1025 int n = SkTMin(conicCnt - conics, kNumQuadsInIdxBuffer); |
| 962 target->drawIndexed(kTriangles_GrPrimitiveType, | 1026 target->drawIndexed(kTriangles_GrPrimitiveType, |
| 963 kQuadNumVertices*(quadCnt + conics), // sta
rtV | 1027 kVertsPerQuad*(quadCnt + conics), // startV |
| 964 0, // sta
rtI | 1028 0, // startI |
| 965 kQuadNumVertices*n, // vCo
unt | 1029 kVertsPerQuad*n, // vCount |
| 966 kIdxsPerQuad*n, // iCo
unt | 1030 kIdxsPerQuad*n, // iCount |
| 967 &devBounds); | 1031 &devBounds); |
| 968 conics += n; | 1032 conics += n; |
| 969 } | 1033 } |
| 970 } | 1034 } |
| 971 } | 1035 } |
| 972 | 1036 |
| 973 target->resetIndexSource(); | 1037 target->resetIndexSource(); |
| 974 | 1038 |
| 975 return true; | 1039 return true; |
| 976 } | 1040 } |
| OLD | NEW |