Chromium Code Reviews| 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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 GR_DEBUGASSERT(updated); | 357 GR_DEBUGASSERT(updated); |
| 358 } | 358 } |
| 359 } | 359 } |
| 360 return fAAStrokeRectIndexBuffer; | 360 return fAAStrokeRectIndexBuffer; |
| 361 } | 361 } |
| 362 | 362 |
| 363 void GrAARectRenderer::geometryFillAARect(GrGpu* gpu, | 363 void GrAARectRenderer::geometryFillAARect(GrGpu* gpu, |
| 364 GrDrawTarget* target, | 364 GrDrawTarget* target, |
| 365 const GrRect& rect, | 365 const GrRect& rect, |
| 366 const SkMatrix& combinedMatrix, | 366 const SkMatrix& combinedMatrix, |
| 367 const GrRect& devRect, | |
| 367 bool useVertexCoverage) { | 368 bool useVertexCoverage) { |
| 368 GrDrawState* drawState = target->drawState(); | 369 GrDrawState* drawState = target->drawState(); |
| 369 | 370 |
| 370 set_aa_rect_vertex_attributes(drawState, useVertexCoverage); | 371 set_aa_rect_vertex_attributes(drawState, useVertexCoverage); |
| 371 | 372 |
| 372 GrDrawTarget::AutoReleaseGeometry geo(target, 8, 0); | 373 GrDrawTarget::AutoReleaseGeometry geo(target, 8, 0); |
| 373 if (!geo.succeeded()) { | 374 if (!geo.succeeded()) { |
| 374 GrPrintf("Failed to get space for vertices!\n"); | 375 GrPrintf("Failed to get space for vertices!\n"); |
| 375 return; | 376 return; |
| 376 } | 377 } |
| 377 | 378 |
| 378 GrIndexBuffer* indexBuffer = this->aaFillRectIndexBuffer(gpu); | 379 GrIndexBuffer* indexBuffer = this->aaFillRectIndexBuffer(gpu); |
| 379 if (NULL == indexBuffer) { | 380 if (NULL == indexBuffer) { |
| 380 GrPrintf("Failed to create index buffer!\n"); | 381 GrPrintf("Failed to create index buffer!\n"); |
| 381 return; | 382 return; |
| 382 } | 383 } |
| 383 | 384 |
| 384 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); | 385 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); |
| 385 size_t vsize = drawState->getVertexSize(); | 386 size_t vsize = drawState->getVertexSize(); |
| 386 GrAssert(sizeof(GrPoint) + sizeof(GrColor) == vsize); | 387 GrAssert(sizeof(GrPoint) + sizeof(GrColor) == vsize); |
| 387 | 388 |
| 388 GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts); | 389 GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts); |
| 389 GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + 4 * vsize); | 390 GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + 4 * vsize); |
| 390 | 391 |
| 391 if (combinedMatrix.rectStaysRect()) { | 392 if (combinedMatrix.rectStaysRect()) { |
| 393 #if 0 | |
|
bsalomon
2013/05/14 19:36:27
Maybe a comment here (and below) about why this wa
robertphillips
2013/05/14 19:48:05
Done.
| |
| 392 SkRect devRect; | 394 SkRect devRect; |
| 393 combinedMatrix.mapRect(&devRect, rect); | 395 combinedMatrix.mapRect(&devRect, rect); |
| 396 #endif | |
| 394 | 397 |
| 395 set_inset_fan(fan0Pos, vsize, devRect, -SK_ScalarHalf, -SK_ScalarHalf); | 398 set_inset_fan(fan0Pos, vsize, devRect, -SK_ScalarHalf, -SK_ScalarHalf); |
| 396 set_inset_fan(fan1Pos, vsize, devRect, SK_ScalarHalf, SK_ScalarHalf); | 399 set_inset_fan(fan1Pos, vsize, devRect, SK_ScalarHalf, SK_ScalarHalf); |
| 397 } else { | 400 } else { |
| 398 // compute transformed (1, 0) and (0, 1) vectors | 401 // compute transformed (1, 0) and (0, 1) vectors |
| 399 SkVector vec[2] = { | 402 SkVector vec[2] = { |
| 400 { combinedMatrix[SkMatrix::kMScaleX], combinedMatrix[SkMatrix::kMSkewY ] }, | 403 { combinedMatrix[SkMatrix::kMScaleX], combinedMatrix[SkMatrix::kMSkewY ] }, |
| 401 { combinedMatrix[SkMatrix::kMSkewX], combinedMatrix[SkMatrix::kMScale Y] } | 404 { combinedMatrix[SkMatrix::kMSkewX], combinedMatrix[SkMatrix::kMScale Y] } |
| 402 }; | 405 }; |
| 403 | 406 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 621 | 624 |
| 622 target->setIndexSourceToBuffer(gpu->getContext()->getQuadIndexBuffer()); | 625 target->setIndexSourceToBuffer(gpu->getContext()->getQuadIndexBuffer()); |
| 623 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6); | 626 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6); |
| 624 target->resetIndexSource(); | 627 target->resetIndexSource(); |
| 625 } | 628 } |
| 626 | 629 |
| 627 void GrAARectRenderer::strokeAARect(GrGpu* gpu, | 630 void GrAARectRenderer::strokeAARect(GrGpu* gpu, |
| 628 GrDrawTarget* target, | 631 GrDrawTarget* target, |
| 629 const GrRect& rect, | 632 const GrRect& rect, |
| 630 const SkMatrix& combinedMatrix, | 633 const SkMatrix& combinedMatrix, |
| 634 const GrRect& devRect, | |
| 631 const GrVec& devStrokeSize, | 635 const GrVec& devStrokeSize, |
| 632 bool useVertexCoverage) { | 636 bool useVertexCoverage) { |
| 633 GrDrawState* drawState = target->drawState(); | 637 GrDrawState* drawState = target->drawState(); |
| 634 | 638 |
| 635 const SkScalar dx = devStrokeSize.fX; | 639 const SkScalar dx = devStrokeSize.fX; |
| 636 const SkScalar dy = devStrokeSize.fY; | 640 const SkScalar dy = devStrokeSize.fY; |
| 637 const SkScalar rx = SkScalarMul(dx, SK_ScalarHalf); | 641 const SkScalar rx = SkScalarMul(dx, SK_ScalarHalf); |
| 638 const SkScalar ry = SkScalarMul(dy, SK_ScalarHalf); | 642 const SkScalar ry = SkScalarMul(dy, SK_ScalarHalf); |
| 639 | 643 |
| 644 #if 0 | |
| 640 SkRect devRect; | 645 SkRect devRect; |
| 641 combinedMatrix.mapRect(&devRect, rect); | 646 combinedMatrix.mapRect(&devRect, rect); |
| 647 #endif | |
| 642 | 648 |
| 643 SkScalar spare; | 649 SkScalar spare; |
| 644 { | 650 { |
| 645 SkScalar w = devRect.width() - dx; | 651 SkScalar w = devRect.width() - dx; |
| 646 SkScalar h = devRect.height() - dy; | 652 SkScalar h = devRect.height() - dy; |
| 647 spare = GrMin(w, h); | 653 spare = GrMin(w, h); |
| 648 } | 654 } |
| 649 | 655 |
| 650 if (spare <= 0) { | 656 if (spare <= 0) { |
| 651 devRect.inset(-rx, -ry); | 657 GrRect r(devRect); |
| 652 this->fillAARect(gpu, target, devRect, SkMatrix::I(), useVertexCoverage) ; | 658 r.outset(rx, ry); |
| 659 this->fillAARect(gpu, target, r, SkMatrix::I(), r, useVertexCoverage); | |
| 653 return; | 660 return; |
| 654 } | 661 } |
| 655 | 662 |
| 656 set_aa_rect_vertex_attributes(drawState, useVertexCoverage); | 663 set_aa_rect_vertex_attributes(drawState, useVertexCoverage); |
| 657 | 664 |
| 658 GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0); | 665 GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0); |
| 659 if (!geo.succeeded()) { | 666 if (!geo.succeeded()) { |
| 660 GrPrintf("Failed to get space for vertices!\n"); | 667 GrPrintf("Failed to get space for vertices!\n"); |
| 661 return; | 668 return; |
| 662 } | 669 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 708 // The innermost rect has full coverage | 715 // The innermost rect has full coverage |
| 709 verts += 8 * vsize; | 716 verts += 8 * vsize; |
| 710 for (int i = 0; i < 4; ++i) { | 717 for (int i = 0; i < 4; ++i) { |
| 711 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; | 718 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; |
| 712 } | 719 } |
| 713 | 720 |
| 714 target->setIndexSourceToBuffer(indexBuffer); | 721 target->setIndexSourceToBuffer(indexBuffer); |
| 715 target->drawIndexed(kTriangles_GrPrimitiveType, | 722 target->drawIndexed(kTriangles_GrPrimitiveType, |
| 716 0, 0, 16, aaStrokeRectIndexCount()); | 723 0, 0, 16, aaStrokeRectIndexCount()); |
| 717 } | 724 } |
| OLD | NEW |