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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 extern const GrVertexAttrib gAAAARectVertexAttribs[] = { | 480 extern const GrVertexAttrib gAAAARectVertexAttribs[] = { |
481 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing }, | 481 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing }, |
482 { kVec4f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBindin
g }, | 482 { kVec4f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBindin
g }, |
483 }; | 483 }; |
484 | 484 |
485 }; | 485 }; |
486 | 486 |
487 void GrAARectRenderer::shaderFillAARect(GrGpu* gpu, | 487 void GrAARectRenderer::shaderFillAARect(GrGpu* gpu, |
488 GrDrawTarget* target, | 488 GrDrawTarget* target, |
489 const GrRect& rect, | 489 const GrRect& rect, |
490 const SkMatrix& combinedMatrix, | 490 const SkMatrix& combinedMatrix) { |
491 const GrRect& devRect) { | |
492 GrDrawState* drawState = target->drawState(); | 491 GrDrawState* drawState = target->drawState(); |
493 | 492 |
494 SkPoint center = SkPoint::Make(rect.centerX(), rect.centerY()); | 493 SkPoint center = SkPoint::Make(rect.centerX(), rect.centerY()); |
495 combinedMatrix.mapPoints(¢er, 1); | 494 combinedMatrix.mapPoints(¢er, 1); |
496 | 495 |
497 // compute transformed (0, 1) vector | 496 // compute transformed (0, 1) vector |
498 SkVector dir = { combinedMatrix[SkMatrix::kMSkewX], combinedMatrix[SkMatrix:
:kMScaleY] }; | 497 SkVector dir = { combinedMatrix[SkMatrix::kMSkewX], combinedMatrix[SkMatrix:
:kMScaleY] }; |
499 dir.normalize(); | 498 dir.normalize(); |
500 | 499 |
501 // compute transformed (width, 0) and (0, height) vectors | 500 // compute transformed (width, 0) and (0, height) vectors |
(...skipping 27 matching lines...) Expand all Loading... |
529 static const int kWidthIndex = 2; | 528 static const int kWidthIndex = 2; |
530 drawState->setEffect(kEdgeEffectStage, effect, kRectAttrIndex, kWidthIndex)-
>unref(); | 529 drawState->setEffect(kEdgeEffectStage, effect, kRectAttrIndex, kWidthIndex)-
>unref(); |
531 | 530 |
532 for (int i = 0; i < 4; ++i) { | 531 for (int i = 0; i < 4; ++i) { |
533 verts[i].fCenter = center; | 532 verts[i].fCenter = center; |
534 verts[i].fDir = dir; | 533 verts[i].fDir = dir; |
535 verts[i].fWidthHeight.fX = newWidth; | 534 verts[i].fWidthHeight.fX = newWidth; |
536 verts[i].fWidthHeight.fY = newHeight; | 535 verts[i].fWidthHeight.fY = newHeight; |
537 } | 536 } |
538 | 537 |
| 538 SkRect devRect; |
| 539 combinedMatrix.mapRect(&devRect, rect); |
| 540 |
539 SkRect devBounds = { | 541 SkRect devBounds = { |
540 devRect.fLeft - SK_ScalarHalf, | 542 devRect.fLeft - SK_ScalarHalf, |
541 devRect.fTop - SK_ScalarHalf, | 543 devRect.fTop - SK_ScalarHalf, |
542 devRect.fRight + SK_ScalarHalf, | 544 devRect.fRight + SK_ScalarHalf, |
543 devRect.fBottom + SK_ScalarHalf | 545 devRect.fBottom + SK_ScalarHalf |
544 }; | 546 }; |
545 | 547 |
546 verts[0].fPos = SkPoint::Make(devBounds.fLeft, devBounds.fTop); | 548 verts[0].fPos = SkPoint::Make(devBounds.fLeft, devBounds.fTop); |
547 verts[1].fPos = SkPoint::Make(devBounds.fLeft, devBounds.fBottom); | 549 verts[1].fPos = SkPoint::Make(devBounds.fLeft, devBounds.fBottom); |
548 verts[2].fPos = SkPoint::Make(devBounds.fRight, devBounds.fBottom); | 550 verts[2].fPos = SkPoint::Make(devBounds.fRight, devBounds.fBottom); |
549 verts[3].fPos = SkPoint::Make(devBounds.fRight, devBounds.fTop); | 551 verts[3].fPos = SkPoint::Make(devBounds.fRight, devBounds.fTop); |
550 | 552 |
551 target->setIndexSourceToBuffer(gpu->getContext()->getQuadIndexBuffer()); | 553 target->setIndexSourceToBuffer(gpu->getContext()->getQuadIndexBuffer()); |
552 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6); | 554 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6); |
553 target->resetIndexSource(); | 555 target->resetIndexSource(); |
554 } | 556 } |
555 | 557 |
556 void GrAARectRenderer::shaderFillAlignedAARect(GrGpu* gpu, | 558 void GrAARectRenderer::shaderFillAlignedAARect(GrGpu* gpu, |
557 GrDrawTarget* target, | 559 GrDrawTarget* target, |
558 const GrRect& rect, | 560 const GrRect& rect, |
559 const SkMatrix& combinedMatrix, | 561 const SkMatrix& combinedMatrix) { |
560 const GrRect& devRect) { | |
561 GrDrawState* drawState = target->drawState(); | 562 GrDrawState* drawState = target->drawState(); |
562 SkASSERT(combinedMatrix.rectStaysRect()); | 563 SkASSERT(combinedMatrix.rectStaysRect()); |
563 | 564 |
564 drawState->setVertexAttribs<gAAAARectVertexAttribs>(SK_ARRAY_COUNT(gAAAARect
VertexAttribs)); | 565 drawState->setVertexAttribs<gAAAARectVertexAttribs>(SK_ARRAY_COUNT(gAAAARect
VertexAttribs)); |
565 GrAssert(sizeof(AARectVertex) == drawState->getVertexSize()); | 566 GrAssert(sizeof(AARectVertex) == drawState->getVertexSize()); |
566 | 567 |
567 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); | 568 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); |
568 if (!geo.succeeded()) { | 569 if (!geo.succeeded()) { |
569 GrPrintf("Failed to get space for vertices!\n"); | 570 GrPrintf("Failed to get space for vertices!\n"); |
570 return; | 571 return; |
571 } | 572 } |
572 | 573 |
573 AARectVertex* verts = reinterpret_cast<AARectVertex*>(geo.vertices()); | 574 AARectVertex* verts = reinterpret_cast<AARectVertex*>(geo.vertices()); |
574 | 575 |
575 enum { | 576 enum { |
576 // the edge effects share this stage with glyph rendering | 577 // the edge effects share this stage with glyph rendering |
577 // (kGlyphMaskStage in GrTextContext) && SW path rendering | 578 // (kGlyphMaskStage in GrTextContext) && SW path rendering |
578 // (kPathMaskStage in GrSWMaskHelper) | 579 // (kPathMaskStage in GrSWMaskHelper) |
579 kEdgeEffectStage = GrPaint::kTotalStages, | 580 kEdgeEffectStage = GrPaint::kTotalStages, |
580 }; | 581 }; |
581 | 582 |
582 GrEffectRef* effect = GrAlignedRectEffect::Create(); | 583 GrEffectRef* effect = GrAlignedRectEffect::Create(); |
583 static const int kOffsetIndex = 1; | 584 static const int kOffsetIndex = 1; |
584 drawState->setEffect(kEdgeEffectStage, effect, kOffsetIndex)->unref(); | 585 drawState->setEffect(kEdgeEffectStage, effect, kOffsetIndex)->unref(); |
585 | 586 |
| 587 SkRect devRect; |
| 588 combinedMatrix.mapRect(&devRect, rect); |
| 589 |
586 SkRect devBounds = { | 590 SkRect devBounds = { |
587 devRect.fLeft - SK_ScalarHalf, | 591 devRect.fLeft - SK_ScalarHalf, |
588 devRect.fTop - SK_ScalarHalf, | 592 devRect.fTop - SK_ScalarHalf, |
589 devRect.fRight + SK_ScalarHalf, | 593 devRect.fRight + SK_ScalarHalf, |
590 devRect.fBottom + SK_ScalarHalf | 594 devRect.fBottom + SK_ScalarHalf |
591 }; | 595 }; |
592 | 596 |
593 GrPoint widthHeight = { | 597 GrPoint widthHeight = { |
594 SkScalarHalf(devRect.width()) + SK_ScalarHalf, | 598 SkScalarHalf(devRect.width()) + SK_ScalarHalf, |
595 SkScalarHalf(devRect.height()) + SK_ScalarHalf | 599 SkScalarHalf(devRect.height()) + SK_ScalarHalf |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 // The innermost rect has full coverage | 704 // The innermost rect has full coverage |
701 verts += 8 * vsize; | 705 verts += 8 * vsize; |
702 for (int i = 0; i < 4; ++i) { | 706 for (int i = 0; i < 4; ++i) { |
703 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; | 707 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; |
704 } | 708 } |
705 | 709 |
706 target->setIndexSourceToBuffer(indexBuffer); | 710 target->setIndexSourceToBuffer(indexBuffer); |
707 target->drawIndexed(kTriangles_GrPrimitiveType, | 711 target->drawIndexed(kTriangles_GrPrimitiveType, |
708 0, 0, 16, aaStrokeRectIndexCount()); | 712 0, 0, 16, aaStrokeRectIndexCount()); |
709 } | 713 } |
OLD | NEW |