| 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 "GrGpu.h" | 9 #include "GrGpu.h" |
| 10 #include "gl/GrGLEffect.h" | 10 #include "gl/GrGLEffect.h" |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 GrTexture* textures[]) { | 254 GrTexture* textures[]) { |
| 255 return GrRectEffect::Create(); | 255 return GrRectEffect::Create(); |
| 256 } | 256 } |
| 257 | 257 |
| 258 /////////////////////////////////////////////////////////////////////////////// | 258 /////////////////////////////////////////////////////////////////////////////// |
| 259 | 259 |
| 260 namespace { | 260 namespace { |
| 261 | 261 |
| 262 extern const GrVertexAttrib gAARectCoverageAttribs[] = { | 262 extern const GrVertexAttrib gAARectCoverageAttribs[] = { |
| 263 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindin
g}, | 263 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindin
g}, |
| 264 {kVec4ub_GrVertexAttribType, sizeof(GrPoint), kCoverage_GrVertexAttribBindin
g}, | 264 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kCoverage_GrVertexAttribBindin
g}, |
| 265 }; | 265 }; |
| 266 | 266 |
| 267 extern const GrVertexAttrib gAARectColorAttribs[] = { | 267 extern const GrVertexAttrib gAARectColorAttribs[] = { |
| 268 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindin
g}, | 268 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindin
g}, |
| 269 {kVec4ub_GrVertexAttribType, sizeof(GrPoint), kColor_GrVertexAttribBinding}, | 269 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVertexAttribBinding}, |
| 270 }; | 270 }; |
| 271 | 271 |
| 272 static void set_aa_rect_vertex_attributes(GrDrawState* drawState, bool useCovera
ge) { | 272 static void set_aa_rect_vertex_attributes(GrDrawState* drawState, bool useCovera
ge) { |
| 273 if (useCoverage) { | 273 if (useCoverage) { |
| 274 drawState->setVertexAttribs<gAARectCoverageAttribs>(SK_ARRAY_COUNT(gAARe
ctCoverageAttribs)); | 274 drawState->setVertexAttribs<gAARectCoverageAttribs>(SK_ARRAY_COUNT(gAARe
ctCoverageAttribs)); |
| 275 } else { | 275 } else { |
| 276 drawState->setVertexAttribs<gAARectColorAttribs>(SK_ARRAY_COUNT(gAARectC
olorAttribs)); | 276 drawState->setVertexAttribs<gAARectColorAttribs>(SK_ARRAY_COUNT(gAARectC
olorAttribs)); |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 | 279 |
| 280 static void set_inset_fan(GrPoint* pts, size_t stride, | 280 static void set_inset_fan(SkPoint* pts, size_t stride, |
| 281 const SkRect& r, SkScalar dx, SkScalar dy) { | 281 const SkRect& r, SkScalar dx, SkScalar dy) { |
| 282 pts->setRectFan(r.fLeft + dx, r.fTop + dy, | 282 pts->setRectFan(r.fLeft + dx, r.fTop + dy, |
| 283 r.fRight - dx, r.fBottom - dy, stride); | 283 r.fRight - dx, r.fBottom - dy, stride); |
| 284 } | 284 } |
| 285 | 285 |
| 286 }; | 286 }; |
| 287 | 287 |
| 288 void GrAARectRenderer::reset() { | 288 void GrAARectRenderer::reset() { |
| 289 SkSafeSetNull(fAAFillRectIndexBuffer); | 289 SkSafeSetNull(fAAFillRectIndexBuffer); |
| 290 SkSafeSetNull(fAAMiterStrokeRectIndexBuffer); | 290 SkSafeSetNull(fAAMiterStrokeRectIndexBuffer); |
| 291 SkSafeSetNull(fAABevelStrokeRectIndexBuffer); | 291 SkSafeSetNull(fAABevelStrokeRectIndexBuffer); |
| 292 } | 292 } |
| 293 | 293 |
| 294 static const uint16_t gFillAARectIdx[] = { | 294 static const uint16_t gFillAARectIdx[] = { |
| 295 0, 1, 5, 5, 4, 0, | 295 0, 1, 5, 5, 4, 0, |
| 296 1, 2, 6, 6, 5, 1, | 296 1, 2, 6, 6, 5, 1, |
| 297 2, 3, 7, 7, 6, 2, | 297 2, 3, 7, 7, 6, 2, |
| 298 3, 0, 4, 4, 7, 3, | 298 3, 0, 4, 4, 7, 3, |
| 299 4, 5, 6, 6, 7, 4, | 299 4, 5, 6, 6, 7, 4, |
| 300 }; | 300 }; |
| 301 | 301 |
| 302 static const int kIndicesPerAAFillRect = GR_ARRAY_COUNT(gFillAARectIdx); | 302 static const int kIndicesPerAAFillRect = SK_ARRAY_COUNT(gFillAARectIdx); |
| 303 static const int kVertsPerAAFillRect = 8; | 303 static const int kVertsPerAAFillRect = 8; |
| 304 static const int kNumAAFillRectsInIndexBuffer = 256; | 304 static const int kNumAAFillRectsInIndexBuffer = 256; |
| 305 | 305 |
| 306 GrIndexBuffer* GrAARectRenderer::aaFillRectIndexBuffer(GrGpu* gpu) { | 306 GrIndexBuffer* GrAARectRenderer::aaFillRectIndexBuffer(GrGpu* gpu) { |
| 307 static const size_t kAAFillRectIndexBufferSize = kIndicesPerAAFillRect * | 307 static const size_t kAAFillRectIndexBufferSize = kIndicesPerAAFillRect * |
| 308 sizeof(uint16_t) * | 308 sizeof(uint16_t) * |
| 309 kNumAAFillRectsInIndexBuffe
r; | 309 kNumAAFillRectsInIndexBuffe
r; |
| 310 | 310 |
| 311 if (NULL == fAAFillRectIndexBuffer) { | 311 if (NULL == fAAFillRectIndexBuffer) { |
| 312 fAAFillRectIndexBuffer = gpu->createIndexBuffer(kAAFillRectIndexBufferSi
ze, false); | 312 fAAFillRectIndexBuffer = gpu->createIndexBuffer(kAAFillRectIndexBufferSi
ze, false); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 4 + 8, 0 + 8, 8 + 8, | 407 4 + 8, 0 + 8, 8 + 8, |
| 408 | 408 |
| 409 // Draw the inner AA, from inner edge to inner AA line, shift is 16. | 409 // Draw the inner AA, from inner edge to inner AA line, shift is 16. |
| 410 0 + 16, 1 + 16, 5 + 16, 5 + 16, 4 + 16, 0 + 16, | 410 0 + 16, 1 + 16, 5 + 16, 5 + 16, 4 + 16, 0 + 16, |
| 411 1 + 16, 2 + 16, 6 + 16, 6 + 16, 5 + 16, 1 + 16, | 411 1 + 16, 2 + 16, 6 + 16, 6 + 16, 5 + 16, 1 + 16, |
| 412 2 + 16, 3 + 16, 7 + 16, 7 + 16, 6 + 16, 2 + 16, | 412 2 + 16, 3 + 16, 7 + 16, 7 + 16, 6 + 16, 2 + 16, |
| 413 3 + 16, 0 + 16, 4 + 16, 4 + 16, 7 + 16, 3 + 16, | 413 3 + 16, 0 + 16, 4 + 16, 4 + 16, 7 + 16, 3 + 16, |
| 414 }; | 414 }; |
| 415 | 415 |
| 416 int GrAARectRenderer::aaStrokeRectIndexCount(bool miterStroke) { | 416 int GrAARectRenderer::aaStrokeRectIndexCount(bool miterStroke) { |
| 417 return miterStroke ? GR_ARRAY_COUNT(gMiterStrokeAARectIdx) : | 417 return miterStroke ? SK_ARRAY_COUNT(gMiterStrokeAARectIdx) : |
| 418 GR_ARRAY_COUNT(gBevelStrokeAARectIdx); | 418 SK_ARRAY_COUNT(gBevelStrokeAARectIdx); |
| 419 } | 419 } |
| 420 | 420 |
| 421 GrIndexBuffer* GrAARectRenderer::aaStrokeRectIndexBuffer(GrGpu* gpu, bool miterS
troke) { | 421 GrIndexBuffer* GrAARectRenderer::aaStrokeRectIndexBuffer(GrGpu* gpu, bool miterS
troke) { |
| 422 if (miterStroke) { | 422 if (miterStroke) { |
| 423 if (NULL == fAAMiterStrokeRectIndexBuffer) { | 423 if (NULL == fAAMiterStrokeRectIndexBuffer) { |
| 424 fAAMiterStrokeRectIndexBuffer = | 424 fAAMiterStrokeRectIndexBuffer = |
| 425 gpu->createIndexBuffer(sizeof(gMiterStrokeAARectIdx), false); | 425 gpu->createIndexBuffer(sizeof(gMiterStrokeAARectIdx), false); |
| 426 if (NULL != fAAMiterStrokeRectIndexBuffer) { | 426 if (NULL != fAAMiterStrokeRectIndexBuffer) { |
| 427 #ifdef SK_DEBUG | 427 #ifdef SK_DEBUG |
| 428 bool updated = | 428 bool updated = |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 } | 467 } |
| 468 | 468 |
| 469 GrIndexBuffer* indexBuffer = this->aaFillRectIndexBuffer(gpu); | 469 GrIndexBuffer* indexBuffer = this->aaFillRectIndexBuffer(gpu); |
| 470 if (NULL == indexBuffer) { | 470 if (NULL == indexBuffer) { |
| 471 GrPrintf("Failed to create index buffer!\n"); | 471 GrPrintf("Failed to create index buffer!\n"); |
| 472 return; | 472 return; |
| 473 } | 473 } |
| 474 | 474 |
| 475 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); | 475 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); |
| 476 size_t vsize = drawState->getVertexSize(); | 476 size_t vsize = drawState->getVertexSize(); |
| 477 SkASSERT(sizeof(GrPoint) + sizeof(GrColor) == vsize); | 477 SkASSERT(sizeof(SkPoint) + sizeof(GrColor) == vsize); |
| 478 | 478 |
| 479 GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts); | 479 SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts); |
| 480 GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + 4 * vsize); | 480 SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + 4 * vsize); |
| 481 | 481 |
| 482 SkScalar inset = SkMinScalar(devRect.width(), SK_Scalar1); | 482 SkScalar inset = SkMinScalar(devRect.width(), SK_Scalar1); |
| 483 inset = SK_ScalarHalf * SkMinScalar(inset, devRect.height()); | 483 inset = SK_ScalarHalf * SkMinScalar(inset, devRect.height()); |
| 484 | 484 |
| 485 if (combinedMatrix.rectStaysRect()) { | 485 if (combinedMatrix.rectStaysRect()) { |
| 486 // Temporarily #if'ed out. We don't want to pass in the devRect but | 486 // Temporarily #if'ed out. We don't want to pass in the devRect but |
| 487 // right now it is computed in GrContext::apply_aa_to_rect and we don't | 487 // right now it is computed in GrContext::apply_aa_to_rect and we don't |
| 488 // want to throw away the work | 488 // want to throw away the work |
| 489 #if 0 | 489 #if 0 |
| 490 SkRect devRect; | 490 SkRect devRect; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 // BR | 524 // BR |
| 525 *((SkPoint*)((intptr_t)fan1Pos + 2 * vsize)) = | 525 *((SkPoint*)((intptr_t)fan1Pos + 2 * vsize)) = |
| 526 *((SkPoint*)((intptr_t)fan0Pos + 2 * vsize)) - vec[0] - vec[1]; | 526 *((SkPoint*)((intptr_t)fan0Pos + 2 * vsize)) - vec[0] - vec[1]; |
| 527 *((SkPoint*)((intptr_t)fan0Pos + 2 * vsize)) += vec[0] + vec[1]; | 527 *((SkPoint*)((intptr_t)fan0Pos + 2 * vsize)) += vec[0] + vec[1]; |
| 528 // TR | 528 // TR |
| 529 *((SkPoint*)((intptr_t)fan1Pos + 3 * vsize)) = | 529 *((SkPoint*)((intptr_t)fan1Pos + 3 * vsize)) = |
| 530 *((SkPoint*)((intptr_t)fan0Pos + 3 * vsize)) - vec[0] + vec[1]; | 530 *((SkPoint*)((intptr_t)fan0Pos + 3 * vsize)) - vec[0] + vec[1]; |
| 531 *((SkPoint*)((intptr_t)fan0Pos + 3 * vsize)) += vec[0] - vec[1]; | 531 *((SkPoint*)((intptr_t)fan0Pos + 3 * vsize)) += vec[0] - vec[1]; |
| 532 } | 532 } |
| 533 | 533 |
| 534 verts += sizeof(GrPoint); | 534 verts += sizeof(SkPoint); |
| 535 for (int i = 0; i < 4; ++i) { | 535 for (int i = 0; i < 4; ++i) { |
| 536 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; | 536 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; |
| 537 } | 537 } |
| 538 | 538 |
| 539 int scale; | 539 int scale; |
| 540 if (inset < SK_ScalarHalf) { | 540 if (inset < SK_ScalarHalf) { |
| 541 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf)); | 541 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf)); |
| 542 SkASSERT(scale >= 0 && scale <= 255); | 542 SkASSERT(scale >= 0 && scale <= 255); |
| 543 } else { | 543 } else { |
| 544 scale = 0xff; | 544 scale = 0xff; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 564 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, | 564 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, |
| 565 kVertsPerAAFillRect, | 565 kVertsPerAAFillRect, |
| 566 kIndicesPerAAFillRect); | 566 kIndicesPerAAFillRect); |
| 567 target->resetIndexSource(); | 567 target->resetIndexSource(); |
| 568 } | 568 } |
| 569 | 569 |
| 570 namespace { | 570 namespace { |
| 571 | 571 |
| 572 // Rotated | 572 // Rotated |
| 573 struct RectVertex { | 573 struct RectVertex { |
| 574 GrPoint fPos; | 574 SkPoint fPos; |
| 575 GrPoint fCenter; | 575 SkPoint fCenter; |
| 576 GrPoint fDir; | 576 SkPoint fDir; |
| 577 GrPoint fWidthHeight; | 577 SkPoint fWidthHeight; |
| 578 }; | 578 }; |
| 579 | 579 |
| 580 // Rotated | 580 // Rotated |
| 581 extern const GrVertexAttrib gAARectVertexAttribs[] = { | 581 extern const GrVertexAttrib gAARectVertexAttribs[] = { |
| 582 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing }, | 582 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing }, |
| 583 { kVec4f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBindin
g }, | 583 { kVec4f_GrVertexAttribType, sizeof(SkPoint), kEffect_GrVertexAttribBindin
g }, |
| 584 { kVec2f_GrVertexAttribType, 3*sizeof(GrPoint), kEffect_GrVertexAttribBindin
g } | 584 { kVec2f_GrVertexAttribType, 3*sizeof(SkPoint), kEffect_GrVertexAttribBindin
g } |
| 585 }; | 585 }; |
| 586 | 586 |
| 587 // Axis Aligned | 587 // Axis Aligned |
| 588 struct AARectVertex { | 588 struct AARectVertex { |
| 589 GrPoint fPos; | 589 SkPoint fPos; |
| 590 GrPoint fOffset; | 590 SkPoint fOffset; |
| 591 GrPoint fWidthHeight; | 591 SkPoint fWidthHeight; |
| 592 }; | 592 }; |
| 593 | 593 |
| 594 // Axis Aligned | 594 // Axis Aligned |
| 595 extern const GrVertexAttrib gAAAARectVertexAttribs[] = { | 595 extern const GrVertexAttrib gAAAARectVertexAttribs[] = { |
| 596 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing }, | 596 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing }, |
| 597 { kVec4f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBindin
g }, | 597 { kVec4f_GrVertexAttribType, sizeof(SkPoint), kEffect_GrVertexAttribBindin
g }, |
| 598 }; | 598 }; |
| 599 | 599 |
| 600 }; | 600 }; |
| 601 | 601 |
| 602 void GrAARectRenderer::shaderFillAARect(GrGpu* gpu, | 602 void GrAARectRenderer::shaderFillAARect(GrGpu* gpu, |
| 603 GrDrawTarget* target, | 603 GrDrawTarget* target, |
| 604 const SkRect& rect, | 604 const SkRect& rect, |
| 605 const SkMatrix& combinedMatrix) { | 605 const SkMatrix& combinedMatrix) { |
| 606 GrDrawState* drawState = target->drawState(); | 606 GrDrawState* drawState = target->drawState(); |
| 607 | 607 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 SkRect devRect; | 688 SkRect devRect; |
| 689 combinedMatrix.mapRect(&devRect, rect); | 689 combinedMatrix.mapRect(&devRect, rect); |
| 690 | 690 |
| 691 SkRect devBounds = { | 691 SkRect devBounds = { |
| 692 devRect.fLeft - SK_ScalarHalf, | 692 devRect.fLeft - SK_ScalarHalf, |
| 693 devRect.fTop - SK_ScalarHalf, | 693 devRect.fTop - SK_ScalarHalf, |
| 694 devRect.fRight + SK_ScalarHalf, | 694 devRect.fRight + SK_ScalarHalf, |
| 695 devRect.fBottom + SK_ScalarHalf | 695 devRect.fBottom + SK_ScalarHalf |
| 696 }; | 696 }; |
| 697 | 697 |
| 698 GrPoint widthHeight = { | 698 SkPoint widthHeight = { |
| 699 SkScalarHalf(devRect.width()) + SK_ScalarHalf, | 699 SkScalarHalf(devRect.width()) + SK_ScalarHalf, |
| 700 SkScalarHalf(devRect.height()) + SK_ScalarHalf | 700 SkScalarHalf(devRect.height()) + SK_ScalarHalf |
| 701 }; | 701 }; |
| 702 | 702 |
| 703 verts[0].fPos = SkPoint::Make(devBounds.fLeft, devBounds.fTop); | 703 verts[0].fPos = SkPoint::Make(devBounds.fLeft, devBounds.fTop); |
| 704 verts[0].fOffset = SkPoint::Make(-widthHeight.fX, -widthHeight.fY); | 704 verts[0].fOffset = SkPoint::Make(-widthHeight.fX, -widthHeight.fY); |
| 705 verts[0].fWidthHeight = widthHeight; | 705 verts[0].fWidthHeight = widthHeight; |
| 706 | 706 |
| 707 verts[1].fPos = SkPoint::Make(devBounds.fLeft, devBounds.fBottom); | 707 verts[1].fPos = SkPoint::Make(devBounds.fLeft, devBounds.fBottom); |
| 708 verts[1].fOffset = SkPoint::Make(-widthHeight.fX, widthHeight.fY); | 708 verts[1].fOffset = SkPoint::Make(-widthHeight.fX, widthHeight.fY); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 721 target->resetIndexSource(); | 721 target->resetIndexSource(); |
| 722 } | 722 } |
| 723 | 723 |
| 724 void GrAARectRenderer::strokeAARect(GrGpu* gpu, | 724 void GrAARectRenderer::strokeAARect(GrGpu* gpu, |
| 725 GrDrawTarget* target, | 725 GrDrawTarget* target, |
| 726 const SkRect& rect, | 726 const SkRect& rect, |
| 727 const SkMatrix& combinedMatrix, | 727 const SkMatrix& combinedMatrix, |
| 728 const SkRect& devRect, | 728 const SkRect& devRect, |
| 729 const SkStrokeRec* stroke, | 729 const SkStrokeRec* stroke, |
| 730 bool useVertexCoverage) { | 730 bool useVertexCoverage) { |
| 731 GrVec devStrokeSize; | 731 SkVector devStrokeSize; |
| 732 SkScalar width = stroke->getWidth(); | 732 SkScalar width = stroke->getWidth(); |
| 733 if (width > 0) { | 733 if (width > 0) { |
| 734 devStrokeSize.set(width, width); | 734 devStrokeSize.set(width, width); |
| 735 combinedMatrix.mapVectors(&devStrokeSize, 1); | 735 combinedMatrix.mapVectors(&devStrokeSize, 1); |
| 736 devStrokeSize.setAbs(devStrokeSize); | 736 devStrokeSize.setAbs(devStrokeSize); |
| 737 } else { | 737 } else { |
| 738 devStrokeSize.set(SK_Scalar1, SK_Scalar1); | 738 devStrokeSize.set(SK_Scalar1, SK_Scalar1); |
| 739 } | 739 } |
| 740 | 740 |
| 741 const SkScalar dx = devStrokeSize.fX; | 741 const SkScalar dx = devStrokeSize.fX; |
| 742 const SkScalar dy = devStrokeSize.fY; | 742 const SkScalar dy = devStrokeSize.fY; |
| 743 const SkScalar rx = SkScalarMul(dx, SK_ScalarHalf); | 743 const SkScalar rx = SkScalarMul(dx, SK_ScalarHalf); |
| 744 const SkScalar ry = SkScalarMul(dy, SK_ScalarHalf); | 744 const SkScalar ry = SkScalarMul(dy, SK_ScalarHalf); |
| 745 | 745 |
| 746 // Temporarily #if'ed out. We don't want to pass in the devRect but | 746 // Temporarily #if'ed out. We don't want to pass in the devRect but |
| 747 // right now it is computed in GrContext::apply_aa_to_rect and we don't | 747 // right now it is computed in GrContext::apply_aa_to_rect and we don't |
| 748 // want to throw away the work | 748 // want to throw away the work |
| 749 #if 0 | 749 #if 0 |
| 750 SkRect devRect; | 750 SkRect devRect; |
| 751 combinedMatrix.mapRect(&devRect, rect); | 751 combinedMatrix.mapRect(&devRect, rect); |
| 752 #endif | 752 #endif |
| 753 | 753 |
| 754 SkScalar spare; | 754 SkScalar spare; |
| 755 { | 755 { |
| 756 SkScalar w = devRect.width() - dx; | 756 SkScalar w = devRect.width() - dx; |
| 757 SkScalar h = devRect.height() - dy; | 757 SkScalar h = devRect.height() - dy; |
| 758 spare = GrMin(w, h); | 758 spare = SkTMin(w, h); |
| 759 } | 759 } |
| 760 | 760 |
| 761 SkRect devOutside(devRect); | 761 SkRect devOutside(devRect); |
| 762 devOutside.outset(rx, ry); | 762 devOutside.outset(rx, ry); |
| 763 | 763 |
| 764 bool miterStroke = true; | 764 bool miterStroke = true; |
| 765 // small miter limit means right angles show bevel... | 765 // small miter limit means right angles show bevel... |
| 766 if (stroke->getJoin() != SkPaint::kMiter_Join || stroke->getMiter() < SK_Sca
larSqrt2) { | 766 if (stroke->getJoin() != SkPaint::kMiter_Join || stroke->getMiter() < SK_Sca
larSqrt2) { |
| 767 miterStroke = false; | 767 miterStroke = false; |
| 768 } | 768 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 return; | 811 return; |
| 812 } | 812 } |
| 813 GrIndexBuffer* indexBuffer = this->aaStrokeRectIndexBuffer(gpu, miterStroke)
; | 813 GrIndexBuffer* indexBuffer = this->aaStrokeRectIndexBuffer(gpu, miterStroke)
; |
| 814 if (NULL == indexBuffer) { | 814 if (NULL == indexBuffer) { |
| 815 GrPrintf("Failed to create index buffer!\n"); | 815 GrPrintf("Failed to create index buffer!\n"); |
| 816 return; | 816 return; |
| 817 } | 817 } |
| 818 | 818 |
| 819 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); | 819 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); |
| 820 size_t vsize = drawState->getVertexSize(); | 820 size_t vsize = drawState->getVertexSize(); |
| 821 SkASSERT(sizeof(GrPoint) + sizeof(GrColor) == vsize); | 821 SkASSERT(sizeof(SkPoint) + sizeof(GrColor) == vsize); |
| 822 | 822 |
| 823 // We create vertices for four nested rectangles. There are two ramps from 0
to full | 823 // We create vertices for four nested rectangles. There are two ramps from 0
to full |
| 824 // coverage, one on the exterior of the stroke and the other on the interior
. | 824 // coverage, one on the exterior of the stroke and the other on the interior
. |
| 825 // The following pointers refer to the four rects, from outermost to innermo
st. | 825 // The following pointers refer to the four rects, from outermost to innermo
st. |
| 826 GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts); | 826 SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts); |
| 827 GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + outerVertexNum * vsize
); | 827 SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + outerVertexNum * vsize
); |
| 828 GrPoint* fan2Pos = reinterpret_cast<GrPoint*>(verts + 2 * outerVertexNum * v
size); | 828 SkPoint* fan2Pos = reinterpret_cast<SkPoint*>(verts + 2 * outerVertexNum * v
size); |
| 829 GrPoint* fan3Pos = reinterpret_cast<GrPoint*>(verts + (2 * outerVertexNum +
innerVertexNum) * vsize); | 829 SkPoint* fan3Pos = reinterpret_cast<SkPoint*>(verts + (2 * outerVertexNum +
innerVertexNum) * vsize); |
| 830 | 830 |
| 831 #ifndef SK_IGNORE_THIN_STROKED_RECT_FIX | 831 #ifndef SK_IGNORE_THIN_STROKED_RECT_FIX |
| 832 // TODO: this only really works if the X & Y margins are the same all around | 832 // TODO: this only really works if the X & Y margins are the same all around |
| 833 // the rect | 833 // the rect |
| 834 SkScalar inset = SkMinScalar(SK_Scalar1, devOutside.fRight - devInside.fRigh
t); | 834 SkScalar inset = SkMinScalar(SK_Scalar1, devOutside.fRight - devInside.fRigh
t); |
| 835 inset = SkMinScalar(inset, devInside.fLeft - devOutside.fLeft); | 835 inset = SkMinScalar(inset, devInside.fLeft - devOutside.fLeft); |
| 836 inset = SkMinScalar(inset, devInside.fTop - devOutside.fTop); | 836 inset = SkMinScalar(inset, devInside.fTop - devOutside.fTop); |
| 837 if (miterStroke) { | 837 if (miterStroke) { |
| 838 inset = SK_ScalarHalf * SkMinScalar(inset, devOutside.fBottom - devInsid
e.fBottom); | 838 inset = SK_ScalarHalf * SkMinScalar(inset, devOutside.fBottom - devInsid
e.fBottom); |
| 839 } else { | 839 } else { |
| 840 inset = SK_ScalarHalf * SkMinScalar(inset, devOutsideAssist.fBottom - de
vInside.fBottom); | 840 inset = SK_ScalarHalf * SkMinScalar(inset, devOutsideAssist.fBottom - de
vInside.fBottom); |
| 841 } | 841 } |
| 842 SkASSERT(inset >= 0); | 842 SkASSERT(inset >= 0); |
| 843 #else | 843 #else |
| 844 SkScalar inset = SK_ScalarHalf; | 844 SkScalar inset = SK_ScalarHalf; |
| 845 #endif | 845 #endif |
| 846 | 846 |
| 847 if (miterStroke) { | 847 if (miterStroke) { |
| 848 // outermost | 848 // outermost |
| 849 set_inset_fan(fan0Pos, vsize, devOutside, -SK_ScalarHalf, -SK_ScalarHalf
); | 849 set_inset_fan(fan0Pos, vsize, devOutside, -SK_ScalarHalf, -SK_ScalarHalf
); |
| 850 // inner two | 850 // inner two |
| 851 set_inset_fan(fan1Pos, vsize, devOutside, inset, inset); | 851 set_inset_fan(fan1Pos, vsize, devOutside, inset, inset); |
| 852 set_inset_fan(fan2Pos, vsize, devInside, -inset, -inset); | 852 set_inset_fan(fan2Pos, vsize, devInside, -inset, -inset); |
| 853 // innermost | 853 // innermost |
| 854 set_inset_fan(fan3Pos, vsize, devInside, SK_ScalarHalf, SK_ScalarHalf
); | 854 set_inset_fan(fan3Pos, vsize, devInside, SK_ScalarHalf, SK_ScalarHalf
); |
| 855 } else { | 855 } else { |
| 856 GrPoint* fan0AssistPos = reinterpret_cast<GrPoint*>(verts + 4 * vsize); | 856 SkPoint* fan0AssistPos = reinterpret_cast<SkPoint*>(verts + 4 * vsize); |
| 857 GrPoint* fan1AssistPos = reinterpret_cast<GrPoint*>(verts + (outerVertex
Num + 4) * vsize); | 857 SkPoint* fan1AssistPos = reinterpret_cast<SkPoint*>(verts + (outerVertex
Num + 4) * vsize); |
| 858 // outermost | 858 // outermost |
| 859 set_inset_fan(fan0Pos, vsize, devOutside, -SK_ScalarHalf, -SK_ScalarHalf
); | 859 set_inset_fan(fan0Pos, vsize, devOutside, -SK_ScalarHalf, -SK_ScalarHalf
); |
| 860 set_inset_fan(fan0AssistPos, vsize, devOutsideAssist, -SK_ScalarHalf, -S
K_ScalarHalf); | 860 set_inset_fan(fan0AssistPos, vsize, devOutsideAssist, -SK_ScalarHalf, -S
K_ScalarHalf); |
| 861 // outer one of the inner two | 861 // outer one of the inner two |
| 862 set_inset_fan(fan1Pos, vsize, devOutside, inset, inset); | 862 set_inset_fan(fan1Pos, vsize, devOutside, inset, inset); |
| 863 set_inset_fan(fan1AssistPos, vsize, devOutsideAssist, inset, inset); | 863 set_inset_fan(fan1AssistPos, vsize, devOutsideAssist, inset, inset); |
| 864 // inner one of the inner two | 864 // inner one of the inner two |
| 865 set_inset_fan(fan2Pos, vsize, devInside, -inset, -inset); | 865 set_inset_fan(fan2Pos, vsize, devInside, -inset, -inset); |
| 866 // innermost | 866 // innermost |
| 867 set_inset_fan(fan3Pos, vsize, devInside, SK_ScalarHalf, SK_ScalarHalf
); | 867 set_inset_fan(fan3Pos, vsize, devInside, SK_ScalarHalf, SK_ScalarHalf
); |
| 868 } | 868 } |
| 869 | 869 |
| 870 // The outermost rect has 0 coverage | 870 // The outermost rect has 0 coverage |
| 871 verts += sizeof(GrPoint); | 871 verts += sizeof(SkPoint); |
| 872 for (int i = 0; i < outerVertexNum; ++i) { | 872 for (int i = 0; i < outerVertexNum; ++i) { |
| 873 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; | 873 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; |
| 874 } | 874 } |
| 875 | 875 |
| 876 int scale; | 876 int scale; |
| 877 if (inset < SK_ScalarHalf) { | 877 if (inset < SK_ScalarHalf) { |
| 878 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf)); | 878 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf)); |
| 879 SkASSERT(scale >= 0 && scale <= 255); | 879 SkASSERT(scale >= 0 && scale <= 255); |
| 880 } else { | 880 } else { |
| 881 scale = 0xff; | 881 scale = 0xff; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; | 923 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; |
| 924 | 924 |
| 925 if (devInside.isEmpty()) { | 925 if (devInside.isEmpty()) { |
| 926 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use
VertexCoverage); | 926 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use
VertexCoverage); |
| 927 return; | 927 return; |
| 928 } | 928 } |
| 929 | 929 |
| 930 this->geometryStrokeAARect(gpu, target, devOutside, devOutsideAssist, | 930 this->geometryStrokeAARect(gpu, target, devOutside, devOutsideAssist, |
| 931 devInside, useVertexCoverage, true); | 931 devInside, useVertexCoverage, true); |
| 932 } | 932 } |
| OLD | NEW |