| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 if (tiled && !caps->npotTextureTileSupport()) { | 566 if (tiled && !caps->npotTextureTileSupport()) { |
| 567 return false; | 567 return false; |
| 568 } | 568 } |
| 569 } | 569 } |
| 570 return true; | 570 return true; |
| 571 } | 571 } |
| 572 | 572 |
| 573 | 573 |
| 574 //////////////////////////////////////////////////////////////////////////////// | 574 //////////////////////////////////////////////////////////////////////////////// |
| 575 | 575 |
| 576 void GrContext::clear(const GrIRect* rect, | 576 void GrContext::clear(const SkIRect* rect, |
| 577 const GrColor color, | 577 const GrColor color, |
| 578 GrRenderTarget* target) { | 578 GrRenderTarget* target) { |
| 579 AutoRestoreEffects are; | 579 AutoRestoreEffects are; |
| 580 this->prepareToDraw(NULL, BUFFERED_DRAW, &are)->clear(rect, color, target); | 580 this->prepareToDraw(NULL, BUFFERED_DRAW, &are)->clear(rect, color, target); |
| 581 } | 581 } |
| 582 | 582 |
| 583 void GrContext::drawPaint(const GrPaint& origPaint) { | 583 void GrContext::drawPaint(const GrPaint& origPaint) { |
| 584 // set rect to be big enough to fill the space, but not super-huge, so we | 584 // set rect to be big enough to fill the space, but not super-huge, so we |
| 585 // don't overflow fixed-point implementations | 585 // don't overflow fixed-point implementations |
| 586 GrRect r; | 586 SkRect r; |
| 587 r.setLTRB(0, 0, | 587 r.setLTRB(0, 0, |
| 588 SkIntToScalar(getRenderTarget()->width()), | 588 SkIntToScalar(getRenderTarget()->width()), |
| 589 SkIntToScalar(getRenderTarget()->height())); | 589 SkIntToScalar(getRenderTarget()->height())); |
| 590 SkMatrix inverse; | 590 SkMatrix inverse; |
| 591 SkTCopyOnFirstWrite<GrPaint> paint(origPaint); | 591 SkTCopyOnFirstWrite<GrPaint> paint(origPaint); |
| 592 AutoMatrix am; | 592 AutoMatrix am; |
| 593 | 593 |
| 594 // We attempt to map r by the inverse matrix and draw that. mapRect will | 594 // We attempt to map r by the inverse matrix and draw that. mapRect will |
| 595 // map the four corners and bound them with a new rect. This will not | 595 // map the four corners and bound them with a new rect. This will not |
| 596 // produce a correct result for some perspective matrices. | 596 // produce a correct result for some perspective matrices. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 621 } | 621 } |
| 622 } | 622 } |
| 623 | 623 |
| 624 //////////////////////////////////////////////////////////////////////////////// | 624 //////////////////////////////////////////////////////////////////////////////// |
| 625 | 625 |
| 626 /* create a triangle strip that strokes the specified triangle. There are 8 | 626 /* create a triangle strip that strokes the specified triangle. There are 8 |
| 627 unique vertices, but we repreat the last 2 to close up. Alternatively we | 627 unique vertices, but we repreat the last 2 to close up. Alternatively we |
| 628 could use an indices array, and then only send 8 verts, but not sure that | 628 could use an indices array, and then only send 8 verts, but not sure that |
| 629 would be faster. | 629 would be faster. |
| 630 */ | 630 */ |
| 631 static void setStrokeRectStrip(GrPoint verts[10], GrRect rect, | 631 static void setStrokeRectStrip(GrPoint verts[10], SkRect rect, |
| 632 SkScalar width) { | 632 SkScalar width) { |
| 633 const SkScalar rad = SkScalarHalf(width); | 633 const SkScalar rad = SkScalarHalf(width); |
| 634 rect.sort(); | 634 rect.sort(); |
| 635 | 635 |
| 636 verts[0].set(rect.fLeft + rad, rect.fTop + rad); | 636 verts[0].set(rect.fLeft + rad, rect.fTop + rad); |
| 637 verts[1].set(rect.fLeft - rad, rect.fTop - rad); | 637 verts[1].set(rect.fLeft - rad, rect.fTop - rad); |
| 638 verts[2].set(rect.fRight - rad, rect.fTop + rad); | 638 verts[2].set(rect.fRight - rad, rect.fTop + rad); |
| 639 verts[3].set(rect.fRight + rad, rect.fTop - rad); | 639 verts[3].set(rect.fRight + rad, rect.fTop - rad); |
| 640 verts[4].set(rect.fRight - rad, rect.fBottom - rad); | 640 verts[4].set(rect.fRight - rad, rect.fBottom - rad); |
| 641 verts[5].set(rect.fRight + rad, rect.fBottom + rad); | 641 verts[5].set(rect.fRight + rad, rect.fBottom + rad); |
| 642 verts[6].set(rect.fLeft + rad, rect.fBottom - rad); | 642 verts[6].set(rect.fLeft + rad, rect.fBottom - rad); |
| 643 verts[7].set(rect.fLeft - rad, rect.fBottom + rad); | 643 verts[7].set(rect.fLeft - rad, rect.fBottom + rad); |
| 644 verts[8] = verts[0]; | 644 verts[8] = verts[0]; |
| 645 verts[9] = verts[1]; | 645 verts[9] = verts[1]; |
| 646 } | 646 } |
| 647 | 647 |
| 648 static bool isIRect(const GrRect& r) { | 648 static bool isIRect(const SkRect& r) { |
| 649 return SkScalarIsInt(r.fLeft) && SkScalarIsInt(r.fTop) && | 649 return SkScalarIsInt(r.fLeft) && SkScalarIsInt(r.fTop) && |
| 650 SkScalarIsInt(r.fRight) && SkScalarIsInt(r.fBottom); | 650 SkScalarIsInt(r.fRight) && SkScalarIsInt(r.fBottom); |
| 651 } | 651 } |
| 652 | 652 |
| 653 static bool apply_aa_to_rect(GrDrawTarget* target, | 653 static bool apply_aa_to_rect(GrDrawTarget* target, |
| 654 const GrRect& rect, | 654 const SkRect& rect, |
| 655 SkScalar strokeWidth, | 655 SkScalar strokeWidth, |
| 656 const SkMatrix* matrix, | 656 const SkMatrix* matrix, |
| 657 SkMatrix* combinedMatrix, | 657 SkMatrix* combinedMatrix, |
| 658 GrRect* devRect, | 658 SkRect* devRect, |
| 659 bool* useVertexCoverage) { | 659 bool* useVertexCoverage) { |
| 660 // we use a simple coverage ramp to do aa on axis-aligned rects | 660 // we use a simple coverage ramp to do aa on axis-aligned rects |
| 661 // we check if the rect will be axis-aligned, and the rect won't land on | 661 // we check if the rect will be axis-aligned, and the rect won't land on |
| 662 // integer coords. | 662 // integer coords. |
| 663 | 663 |
| 664 // we are keeping around the "tweak the alpha" trick because | 664 // we are keeping around the "tweak the alpha" trick because |
| 665 // it is our only hope for the fixed-pipe implementation. | 665 // it is our only hope for the fixed-pipe implementation. |
| 666 // In a shader implementation we can give a separate coverage input | 666 // In a shader implementation we can give a separate coverage input |
| 667 // TODO: remove this ugliness when we drop the fixed-pipe impl | 667 // TODO: remove this ugliness when we drop the fixed-pipe impl |
| 668 *useVertexCoverage = false; | 668 *useVertexCoverage = false; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 combinedMatrix->mapRect(devRect, rect); | 728 combinedMatrix->mapRect(devRect, rect); |
| 729 | 729 |
| 730 if (strokeWidth < 0) { | 730 if (strokeWidth < 0) { |
| 731 return !isIRect(*devRect); | 731 return !isIRect(*devRect); |
| 732 } else { | 732 } else { |
| 733 return true; | 733 return true; |
| 734 } | 734 } |
| 735 } | 735 } |
| 736 | 736 |
| 737 void GrContext::drawRect(const GrPaint& paint, | 737 void GrContext::drawRect(const GrPaint& paint, |
| 738 const GrRect& rect, | 738 const SkRect& rect, |
| 739 SkScalar width, | 739 SkScalar width, |
| 740 const SkMatrix* matrix) { | 740 const SkMatrix* matrix) { |
| 741 SK_TRACE_EVENT0("GrContext::drawRect"); | 741 SK_TRACE_EVENT0("GrContext::drawRect"); |
| 742 | 742 |
| 743 AutoRestoreEffects are; | 743 AutoRestoreEffects are; |
| 744 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are); | 744 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are); |
| 745 | 745 |
| 746 GrRect devRect; | 746 SkRect devRect; |
| 747 SkMatrix combinedMatrix; | 747 SkMatrix combinedMatrix; |
| 748 bool useVertexCoverage; | 748 bool useVertexCoverage; |
| 749 bool needAA = paint.isAntiAlias() && | 749 bool needAA = paint.isAntiAlias() && |
| 750 !target->getDrawState().getRenderTarget()->isMultisampled(); | 750 !target->getDrawState().getRenderTarget()->isMultisampled(); |
| 751 bool doAA = needAA && apply_aa_to_rect(target, rect, width, matrix, | 751 bool doAA = needAA && apply_aa_to_rect(target, rect, width, matrix, |
| 752 &combinedMatrix, &devRect, | 752 &combinedMatrix, &devRect, |
| 753 &useVertexCoverage); | 753 &useVertexCoverage); |
| 754 if (doAA) { | 754 if (doAA) { |
| 755 GrDrawState::AutoViewMatrixRestore avmr; | 755 GrDrawState::AutoViewMatrixRestore avmr; |
| 756 if (!avmr.setIdentity(target->drawState())) { | 756 if (!avmr.setIdentity(target->drawState())) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 } | 809 } |
| 810 | 810 |
| 811 target->drawNonIndexed(primType, 0, vertCount); | 811 target->drawNonIndexed(primType, 0, vertCount); |
| 812 } else { | 812 } else { |
| 813 // filled BW rect | 813 // filled BW rect |
| 814 target->drawSimpleRect(rect, matrix); | 814 target->drawSimpleRect(rect, matrix); |
| 815 } | 815 } |
| 816 } | 816 } |
| 817 | 817 |
| 818 void GrContext::drawRectToRect(const GrPaint& paint, | 818 void GrContext::drawRectToRect(const GrPaint& paint, |
| 819 const GrRect& dstRect, | 819 const SkRect& dstRect, |
| 820 const GrRect& localRect, | 820 const SkRect& localRect, |
| 821 const SkMatrix* dstMatrix, | 821 const SkMatrix* dstMatrix, |
| 822 const SkMatrix* localMatrix) { | 822 const SkMatrix* localMatrix) { |
| 823 SK_TRACE_EVENT0("GrContext::drawRectToRect"); | 823 SK_TRACE_EVENT0("GrContext::drawRectToRect"); |
| 824 AutoRestoreEffects are; | 824 AutoRestoreEffects are; |
| 825 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are); | 825 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are); |
| 826 | 826 |
| 827 target->drawRect(dstRect, dstMatrix, &localRect, localMatrix); | 827 target->drawRect(dstRect, dstMatrix, &localRect, localMatrix); |
| 828 } | 828 } |
| 829 | 829 |
| 830 namespace { | 830 namespace { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 if (!fOvalRenderer->drawSimpleRRect(target, this, useAA, rect, stroke)) { | 936 if (!fOvalRenderer->drawSimpleRRect(target, this, useAA, rect, stroke)) { |
| 937 SkPath path; | 937 SkPath path; |
| 938 path.addRRect(rect); | 938 path.addRRect(rect); |
| 939 this->internalDrawPath(target, useAA, path, stroke); | 939 this->internalDrawPath(target, useAA, path, stroke); |
| 940 } | 940 } |
| 941 } | 941 } |
| 942 | 942 |
| 943 /////////////////////////////////////////////////////////////////////////////// | 943 /////////////////////////////////////////////////////////////////////////////// |
| 944 | 944 |
| 945 void GrContext::drawOval(const GrPaint& paint, | 945 void GrContext::drawOval(const GrPaint& paint, |
| 946 const GrRect& oval, | 946 const SkRect& oval, |
| 947 const SkStrokeRec& stroke) { | 947 const SkStrokeRec& stroke) { |
| 948 | 948 |
| 949 AutoRestoreEffects are; | 949 AutoRestoreEffects are; |
| 950 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are); | 950 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are); |
| 951 | 951 |
| 952 bool useAA = paint.isAntiAlias() && | 952 bool useAA = paint.isAntiAlias() && |
| 953 !target->getDrawState().getRenderTarget()->isMultisampled() && | 953 !target->getDrawState().getRenderTarget()->isMultisampled() && |
| 954 !disable_coverage_aa_for_blend(target); | 954 !disable_coverage_aa_for_blend(target); |
| 955 | 955 |
| 956 if (!fOvalRenderer->drawOval(target, this, useAA, oval, stroke)) { | 956 if (!fOvalRenderer->drawOval(target, this, useAA, oval, stroke)) { |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1310 | 1310 |
| 1311 // We protect the existing geometry here since it may not be | 1311 // We protect the existing geometry here since it may not be |
| 1312 // clear to the caller that a draw operation (i.e., drawSimpleRe
ct) | 1312 // clear to the caller that a draw operation (i.e., drawSimpleRe
ct) |
| 1313 // can be invoked in this method | 1313 // can be invoked in this method |
| 1314 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget:
:kReset_ASRInit); | 1314 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget:
:kReset_ASRInit); |
| 1315 GrDrawState* drawState = fGpu->drawState(); | 1315 GrDrawState* drawState = fGpu->drawState(); |
| 1316 GrAssert(effect); | 1316 GrAssert(effect); |
| 1317 drawState->addColorEffect(effect); | 1317 drawState->addColorEffect(effect); |
| 1318 | 1318 |
| 1319 drawState->setRenderTarget(texture->asRenderTarget()); | 1319 drawState->setRenderTarget(texture->asRenderTarget()); |
| 1320 GrRect rect = GrRect::MakeWH(SkIntToScalar(width), SkIntToScalar
(height)); | 1320 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar
(height)); |
| 1321 fGpu->drawSimpleRect(rect, NULL); | 1321 fGpu->drawSimpleRect(rect, NULL); |
| 1322 // we want to read back from the scratch's origin | 1322 // we want to read back from the scratch's origin |
| 1323 left = 0; | 1323 left = 0; |
| 1324 top = 0; | 1324 top = 0; |
| 1325 target = texture->asRenderTarget(); | 1325 target = texture->asRenderTarget(); |
| 1326 } | 1326 } |
| 1327 } | 1327 } |
| 1328 } | 1328 } |
| 1329 if (!fGpu->readPixels(target, | 1329 if (!fGpu->readPixels(target, |
| 1330 left, top, width, height, | 1330 left, top, width, height, |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1504 // drawing a rect) so preserve the current geometry. | 1504 // drawing a rect) so preserve the current geometry. |
| 1505 SkMatrix matrix; | 1505 SkMatrix matrix; |
| 1506 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); | 1506 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
| 1507 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_ASRI
nit, &matrix); | 1507 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_ASRI
nit, &matrix); |
| 1508 GrDrawState* drawState = fGpu->drawState(); | 1508 GrDrawState* drawState = fGpu->drawState(); |
| 1509 GrAssert(effect); | 1509 GrAssert(effect); |
| 1510 drawState->addColorEffect(effect); | 1510 drawState->addColorEffect(effect); |
| 1511 | 1511 |
| 1512 drawState->setRenderTarget(target); | 1512 drawState->setRenderTarget(target); |
| 1513 | 1513 |
| 1514 fGpu->drawSimpleRect(GrRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heig
ht)), NULL); | 1514 fGpu->drawSimpleRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heig
ht)), NULL); |
| 1515 return true; | 1515 return true; |
| 1516 } | 1516 } |
| 1517 //////////////////////////////////////////////////////////////////////////////// | 1517 //////////////////////////////////////////////////////////////////////////////// |
| 1518 | 1518 |
| 1519 GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, | 1519 GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, |
| 1520 BufferedDraw buffered, | 1520 BufferedDraw buffered, |
| 1521 AutoRestoreEffects* are) { | 1521 AutoRestoreEffects* are) { |
| 1522 // All users of this draw state should be freeing up all effects when they'r
e done. | 1522 // All users of this draw state should be freeing up all effects when they'r
e done. |
| 1523 // Otherwise effects that own resources may keep those resources alive indef
initely. | 1523 // Otherwise effects that own resources may keep those resources alive indef
initely. |
| 1524 GrAssert(0 == fDrawState->numColorStages() && 0 == fDrawState->numCoverageSt
ages()); | 1524 GrAssert(0 == fDrawState->numColorStages() && 0 == fDrawState->numCoverageSt
ages()); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1678 return NULL; | 1678 return NULL; |
| 1679 } | 1679 } |
| 1680 } | 1680 } |
| 1681 | 1681 |
| 1682 /////////////////////////////////////////////////////////////////////////////// | 1682 /////////////////////////////////////////////////////////////////////////////// |
| 1683 #if GR_CACHE_STATS | 1683 #if GR_CACHE_STATS |
| 1684 void GrContext::printCacheStats() const { | 1684 void GrContext::printCacheStats() const { |
| 1685 fTextureCache->printStats(); | 1685 fTextureCache->printStats(); |
| 1686 } | 1686 } |
| 1687 #endif | 1687 #endif |
| OLD | NEW |