OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrAARectRenderer.h" | 8 #include "GrAARectRenderer.h" |
9 #include "GrRefCnt.h" | 9 #include "GrRefCnt.h" |
10 #include "GrGpu.h" | 10 #include "GrGpu.h" |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 270 |
271 static void set_aa_rect_vertex_attributes(GrDrawState* drawState, bool useCovera
ge) { | 271 static void set_aa_rect_vertex_attributes(GrDrawState* drawState, bool useCovera
ge) { |
272 if (useCoverage) { | 272 if (useCoverage) { |
273 drawState->setVertexAttribs<gAARectCoverageAttribs>(SK_ARRAY_COUNT(gAARe
ctCoverageAttribs)); | 273 drawState->setVertexAttribs<gAARectCoverageAttribs>(SK_ARRAY_COUNT(gAARe
ctCoverageAttribs)); |
274 } else { | 274 } else { |
275 drawState->setVertexAttribs<gAARectColorAttribs>(SK_ARRAY_COUNT(gAARectC
olorAttribs)); | 275 drawState->setVertexAttribs<gAARectColorAttribs>(SK_ARRAY_COUNT(gAARectC
olorAttribs)); |
276 } | 276 } |
277 } | 277 } |
278 | 278 |
279 static void set_inset_fan(GrPoint* pts, size_t stride, | 279 static void set_inset_fan(GrPoint* pts, size_t stride, |
280 const GrRect& r, SkScalar dx, SkScalar dy) { | 280 const SkRect& r, SkScalar dx, SkScalar dy) { |
281 pts->setRectFan(r.fLeft + dx, r.fTop + dy, | 281 pts->setRectFan(r.fLeft + dx, r.fTop + dy, |
282 r.fRight - dx, r.fBottom - dy, stride); | 282 r.fRight - dx, r.fBottom - dy, stride); |
283 } | 283 } |
284 | 284 |
285 }; | 285 }; |
286 | 286 |
287 void GrAARectRenderer::reset() { | 287 void GrAARectRenderer::reset() { |
288 GrSafeSetNull(fAAFillRectIndexBuffer); | 288 GrSafeSetNull(fAAFillRectIndexBuffer); |
289 GrSafeSetNull(fAAStrokeRectIndexBuffer); | 289 GrSafeSetNull(fAAStrokeRectIndexBuffer); |
290 } | 290 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 fAAStrokeRectIndexBuffer->updateData(gStrokeAARectIdx, | 369 fAAStrokeRectIndexBuffer->updateData(gStrokeAARectIdx, |
370 sizeof(gStrokeAARectIdx)); | 370 sizeof(gStrokeAARectIdx)); |
371 GR_DEBUGASSERT(updated); | 371 GR_DEBUGASSERT(updated); |
372 } | 372 } |
373 } | 373 } |
374 return fAAStrokeRectIndexBuffer; | 374 return fAAStrokeRectIndexBuffer; |
375 } | 375 } |
376 | 376 |
377 void GrAARectRenderer::geometryFillAARect(GrGpu* gpu, | 377 void GrAARectRenderer::geometryFillAARect(GrGpu* gpu, |
378 GrDrawTarget* target, | 378 GrDrawTarget* target, |
379 const GrRect& rect, | 379 const SkRect& rect, |
380 const SkMatrix& combinedMatrix, | 380 const SkMatrix& combinedMatrix, |
381 const GrRect& devRect, | 381 const SkRect& devRect, |
382 bool useVertexCoverage) { | 382 bool useVertexCoverage) { |
383 GrDrawState* drawState = target->drawState(); | 383 GrDrawState* drawState = target->drawState(); |
384 | 384 |
385 set_aa_rect_vertex_attributes(drawState, useVertexCoverage); | 385 set_aa_rect_vertex_attributes(drawState, useVertexCoverage); |
386 | 386 |
387 GrDrawTarget::AutoReleaseGeometry geo(target, 8, 0); | 387 GrDrawTarget::AutoReleaseGeometry geo(target, 8, 0); |
388 if (!geo.succeeded()) { | 388 if (!geo.succeeded()) { |
389 GrPrintf("Failed to get space for vertices!\n"); | 389 GrPrintf("Failed to get space for vertices!\n"); |
390 return; | 390 return; |
391 } | 391 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 // Axis Aligned | 518 // Axis Aligned |
519 extern const GrVertexAttrib gAAAARectVertexAttribs[] = { | 519 extern const GrVertexAttrib gAAAARectVertexAttribs[] = { |
520 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing }, | 520 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing }, |
521 { kVec4f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBindin
g }, | 521 { kVec4f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBindin
g }, |
522 }; | 522 }; |
523 | 523 |
524 }; | 524 }; |
525 | 525 |
526 void GrAARectRenderer::shaderFillAARect(GrGpu* gpu, | 526 void GrAARectRenderer::shaderFillAARect(GrGpu* gpu, |
527 GrDrawTarget* target, | 527 GrDrawTarget* target, |
528 const GrRect& rect, | 528 const SkRect& rect, |
529 const SkMatrix& combinedMatrix) { | 529 const SkMatrix& combinedMatrix) { |
530 GrDrawState* drawState = target->drawState(); | 530 GrDrawState* drawState = target->drawState(); |
531 | 531 |
532 SkPoint center = SkPoint::Make(rect.centerX(), rect.centerY()); | 532 SkPoint center = SkPoint::Make(rect.centerX(), rect.centerY()); |
533 combinedMatrix.mapPoints(¢er, 1); | 533 combinedMatrix.mapPoints(¢er, 1); |
534 | 534 |
535 // compute transformed (0, 1) vector | 535 // compute transformed (0, 1) vector |
536 SkVector dir = { combinedMatrix[SkMatrix::kMSkewX], combinedMatrix[SkMatrix:
:kMScaleY] }; | 536 SkVector dir = { combinedMatrix[SkMatrix::kMSkewX], combinedMatrix[SkMatrix:
:kMScaleY] }; |
537 dir.normalize(); | 537 dir.normalize(); |
538 | 538 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 verts[2].fPos = SkPoint::Make(devBounds.fRight, devBounds.fBottom); | 582 verts[2].fPos = SkPoint::Make(devBounds.fRight, devBounds.fBottom); |
583 verts[3].fPos = SkPoint::Make(devBounds.fRight, devBounds.fTop); | 583 verts[3].fPos = SkPoint::Make(devBounds.fRight, devBounds.fTop); |
584 | 584 |
585 target->setIndexSourceToBuffer(gpu->getContext()->getQuadIndexBuffer()); | 585 target->setIndexSourceToBuffer(gpu->getContext()->getQuadIndexBuffer()); |
586 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6); | 586 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6); |
587 target->resetIndexSource(); | 587 target->resetIndexSource(); |
588 } | 588 } |
589 | 589 |
590 void GrAARectRenderer::shaderFillAlignedAARect(GrGpu* gpu, | 590 void GrAARectRenderer::shaderFillAlignedAARect(GrGpu* gpu, |
591 GrDrawTarget* target, | 591 GrDrawTarget* target, |
592 const GrRect& rect, | 592 const SkRect& rect, |
593 const SkMatrix& combinedMatrix) { | 593 const SkMatrix& combinedMatrix) { |
594 GrDrawState* drawState = target->drawState(); | 594 GrDrawState* drawState = target->drawState(); |
595 SkASSERT(combinedMatrix.rectStaysRect()); | 595 SkASSERT(combinedMatrix.rectStaysRect()); |
596 | 596 |
597 drawState->setVertexAttribs<gAAAARectVertexAttribs>(SK_ARRAY_COUNT(gAAAARect
VertexAttribs)); | 597 drawState->setVertexAttribs<gAAAARectVertexAttribs>(SK_ARRAY_COUNT(gAAAARect
VertexAttribs)); |
598 GrAssert(sizeof(AARectVertex) == drawState->getVertexSize()); | 598 GrAssert(sizeof(AARectVertex) == drawState->getVertexSize()); |
599 | 599 |
600 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); | 600 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); |
601 if (!geo.succeeded()) { | 601 if (!geo.succeeded()) { |
602 GrPrintf("Failed to get space for vertices!\n"); | 602 GrPrintf("Failed to get space for vertices!\n"); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 verts[3].fOffset = SkPoint::Make(widthHeight.fX, -widthHeight.fY); | 640 verts[3].fOffset = SkPoint::Make(widthHeight.fX, -widthHeight.fY); |
641 verts[3].fWidthHeight = widthHeight; | 641 verts[3].fWidthHeight = widthHeight; |
642 | 642 |
643 target->setIndexSourceToBuffer(gpu->getContext()->getQuadIndexBuffer()); | 643 target->setIndexSourceToBuffer(gpu->getContext()->getQuadIndexBuffer()); |
644 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6); | 644 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6); |
645 target->resetIndexSource(); | 645 target->resetIndexSource(); |
646 } | 646 } |
647 | 647 |
648 void GrAARectRenderer::strokeAARect(GrGpu* gpu, | 648 void GrAARectRenderer::strokeAARect(GrGpu* gpu, |
649 GrDrawTarget* target, | 649 GrDrawTarget* target, |
650 const GrRect& rect, | 650 const SkRect& rect, |
651 const SkMatrix& combinedMatrix, | 651 const SkMatrix& combinedMatrix, |
652 const GrRect& devRect, | 652 const SkRect& devRect, |
653 SkScalar width, | 653 SkScalar width, |
654 bool useVertexCoverage) { | 654 bool useVertexCoverage) { |
655 GrVec devStrokeSize; | 655 GrVec devStrokeSize; |
656 if (width > 0) { | 656 if (width > 0) { |
657 devStrokeSize.set(width, width); | 657 devStrokeSize.set(width, width); |
658 combinedMatrix.mapVectors(&devStrokeSize, 1); | 658 combinedMatrix.mapVectors(&devStrokeSize, 1); |
659 devStrokeSize.setAbs(devStrokeSize); | 659 devStrokeSize.setAbs(devStrokeSize); |
660 } else { | 660 } else { |
661 devStrokeSize.set(SK_Scalar1, SK_Scalar1); | 661 devStrokeSize.set(SK_Scalar1, SK_Scalar1); |
662 } | 662 } |
(...skipping 11 matching lines...) Expand all Loading... |
674 combinedMatrix.mapRect(&devRect, rect); | 674 combinedMatrix.mapRect(&devRect, rect); |
675 #endif | 675 #endif |
676 | 676 |
677 SkScalar spare; | 677 SkScalar spare; |
678 { | 678 { |
679 SkScalar w = devRect.width() - dx; | 679 SkScalar w = devRect.width() - dx; |
680 SkScalar h = devRect.height() - dy; | 680 SkScalar h = devRect.height() - dy; |
681 spare = GrMin(w, h); | 681 spare = GrMin(w, h); |
682 } | 682 } |
683 | 683 |
684 GrRect devOutside(devRect); | 684 SkRect devOutside(devRect); |
685 devOutside.outset(rx, ry); | 685 devOutside.outset(rx, ry); |
686 | 686 |
687 if (spare <= 0) { | 687 if (spare <= 0) { |
688 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), | 688 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), |
689 devOutside, useVertexCoverage); | 689 devOutside, useVertexCoverage); |
690 return; | 690 return; |
691 } | 691 } |
692 | 692 |
693 SkRect devInside(devRect); | 693 SkRect devInside(devRect); |
694 devInside.inset(rx, ry); | 694 devInside.inset(rx, ry); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 // can't call mapRect for devInside since it calls sort | 803 // can't call mapRect for devInside since it calls sort |
804 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; | 804 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; |
805 | 805 |
806 if (devInside.isEmpty()) { | 806 if (devInside.isEmpty()) { |
807 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use
VertexCoverage); | 807 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use
VertexCoverage); |
808 return; | 808 return; |
809 } | 809 } |
810 | 810 |
811 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove
rage); | 811 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove
rage); |
812 } | 812 } |
OLD | NEW |