| 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 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 /** | 675 /** |
| 676 * Returns true if the rects edges are integer-aligned. | 676 * Returns true if the rects edges are integer-aligned. |
| 677 */ | 677 */ |
| 678 static bool isIRect(const GrRect& r) { | 678 static bool isIRect(const GrRect& r) { |
| 679 return SkScalarIsInt(r.fLeft) && SkScalarIsInt(r.fTop) && | 679 return SkScalarIsInt(r.fLeft) && SkScalarIsInt(r.fTop) && |
| 680 SkScalarIsInt(r.fRight) && SkScalarIsInt(r.fBottom); | 680 SkScalarIsInt(r.fRight) && SkScalarIsInt(r.fBottom); |
| 681 } | 681 } |
| 682 | 682 |
| 683 static bool apply_aa_to_rect(GrDrawTarget* target, | 683 static bool apply_aa_to_rect(GrDrawTarget* target, |
| 684 const GrRect& rect, | 684 const GrRect& rect, |
| 685 SkScalar width, | 685 SkScalar strokeWidth, |
| 686 const SkMatrix* matrix, | 686 const SkMatrix* matrix, |
| 687 SkMatrix* combinedMatrix, | 687 SkMatrix* combinedMatrix, |
| 688 GrRect* devRect, | 688 GrRect* devRect, |
| 689 bool* useVertexCoverage) { | 689 bool* useVertexCoverage) { |
| 690 // we use a simple coverage ramp to do aa on axis-aligned rects | 690 // we use a simple coverage ramp to do aa on axis-aligned rects |
| 691 // we check if the rect will be axis-aligned, and the rect won't land on | 691 // we check if the rect will be axis-aligned, and the rect won't land on |
| 692 // integer coords. | 692 // integer coords. |
| 693 | 693 |
| 694 // we are keeping around the "tweak the alpha" trick because | 694 // we are keeping around the "tweak the alpha" trick because |
| 695 // it is our only hope for the fixed-pipe implementation. | 695 // it is our only hope for the fixed-pipe implementation. |
| 696 // In a shader implementation we can give a separate coverage input | 696 // In a shader implementation we can give a separate coverage input |
| 697 // TODO: remove this ugliness when we drop the fixed-pipe impl | 697 // TODO: remove this ugliness when we drop the fixed-pipe impl |
| 698 *useVertexCoverage = false; | 698 *useVertexCoverage = false; |
| 699 if (!target->getDrawState().canTweakAlphaForCoverage()) { | 699 if (!target->getDrawState().canTweakAlphaForCoverage()) { |
| 700 if (disable_coverage_aa_for_blend(target)) { | 700 if (disable_coverage_aa_for_blend(target)) { |
| 701 #if GR_DEBUG | 701 #if GR_DEBUG |
| 702 //GrPrintf("Turning off AA to correctly apply blend.\n"); | 702 //GrPrintf("Turning off AA to correctly apply blend.\n"); |
| 703 #endif | 703 #endif |
| 704 return false; | 704 return false; |
| 705 } else { | 705 } else { |
| 706 *useVertexCoverage = true; | 706 *useVertexCoverage = true; |
| 707 } | 707 } |
| 708 } | 708 } |
| 709 const GrDrawState& drawState = target->getDrawState(); | 709 const GrDrawState& drawState = target->getDrawState(); |
| 710 if (drawState.getRenderTarget()->isMultisampled()) { | 710 if (drawState.getRenderTarget()->isMultisampled()) { |
| 711 return false; | 711 return false; |
| 712 } | 712 } |
| 713 | 713 |
| 714 if (0 == width && target->willUseHWAALines()) { | 714 if (0 == strokeWidth && target->willUseHWAALines()) { |
| 715 return false; | 715 return false; |
| 716 } | 716 } |
| 717 | 717 |
| 718 if (!drawState.getViewMatrix().preservesAxisAlignment()) { | 718 #ifdef SHADER_AA_FILL_RECT |
| 719 return false; | 719 if (strokeWidth >= 0) { |
| 720 #endif |
| 721 if (!drawState.getViewMatrix().preservesAxisAlignment()) { |
| 722 return false; |
| 723 } |
| 724 |
| 725 if (NULL != matrix && !matrix->preservesAxisAlignment()) { |
| 726 return false; |
| 727 } |
| 728 #ifdef SHADER_AA_FILL_RECT |
| 729 } else { |
| 730 if (!drawState.getViewMatrix().preservesAxisAlignment() && |
| 731 !drawState.getViewMatrix().preservesRightAngles()) { |
| 732 return false; |
| 733 } |
| 734 |
| 735 if (NULL != matrix && !matrix->preservesRightAngles()) { |
| 736 return false; |
| 737 } |
| 720 } | 738 } |
| 721 | 739 #endif |
| 722 if (NULL != matrix && | |
| 723 !matrix->preservesAxisAlignment()) { | |
| 724 return false; | |
| 725 } | |
| 726 | 740 |
| 727 *combinedMatrix = drawState.getViewMatrix(); | 741 *combinedMatrix = drawState.getViewMatrix(); |
| 728 if (NULL != matrix) { | 742 if (NULL != matrix) { |
| 729 combinedMatrix->preConcat(*matrix); | 743 combinedMatrix->preConcat(*matrix); |
| 730 GrAssert(combinedMatrix->preservesAxisAlignment()); | 744 |
| 745 #if GR_DEBUG |
| 746 #ifdef SHADER_AA_FILL_RECT |
| 747 if (strokeWidth >= 0) { |
| 748 #endif |
| 749 GrAssert(combinedMatrix->preservesAxisAlignment()); |
| 750 #ifdef SHADER_AA_FILL_RECT |
| 751 } else { |
| 752 GrAssert(combinedMatrix->preservesRightAngles()); |
| 753 } |
| 754 #endif |
| 755 #endif |
| 731 } | 756 } |
| 732 | 757 |
| 733 combinedMatrix->mapRect(devRect, rect); | 758 combinedMatrix->mapRect(devRect, rect); |
| 734 devRect->sort(); | 759 devRect->sort(); |
| 735 | 760 |
| 736 if (width < 0) { | 761 if (strokeWidth < 0) { |
| 737 return !isIRect(*devRect); | 762 return !isIRect(*devRect); |
| 738 } else { | 763 } else { |
| 739 return true; | 764 return true; |
| 740 } | 765 } |
| 741 } | 766 } |
| 742 | 767 |
| 743 void GrContext::drawRect(const GrPaint& paint, | 768 void GrContext::drawRect(const GrPaint& paint, |
| 744 const GrRect& rect, | 769 const GrRect& rect, |
| 745 SkScalar width, | 770 SkScalar width, |
| 746 const SkMatrix* matrix) { | 771 const SkMatrix* matrix) { |
| 747 SK_TRACE_EVENT0("GrContext::drawRect"); | 772 SK_TRACE_EVENT0("GrContext::drawRect"); |
| 748 | 773 |
| 749 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); | 774 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); |
| 750 GrDrawState::AutoStageDisable atr(fDrawState); | 775 GrDrawState::AutoStageDisable atr(fDrawState); |
| 751 | 776 |
| 752 GrRect devRect = rect; | 777 GrRect devRect = rect; |
| 753 SkMatrix combinedMatrix; | 778 SkMatrix combinedMatrix; |
| 754 bool useVertexCoverage; | 779 bool useVertexCoverage; |
| 755 bool needAA = paint.isAntiAlias() && | 780 bool needAA = paint.isAntiAlias() && |
| 756 !this->getRenderTarget()->isMultisampled(); | 781 !this->getRenderTarget()->isMultisampled(); |
| 757 bool doAA = needAA && apply_aa_to_rect(target, rect, width, matrix, | 782 bool doAA = needAA && apply_aa_to_rect(target, rect, width, matrix, |
| 758 &combinedMatrix, &devRect, | 783 &combinedMatrix, &devRect, |
| 759 &useVertexCoverage); | 784 &useVertexCoverage); |
| 760 | |
| 761 if (doAA) { | 785 if (doAA) { |
| 762 GrDrawState::AutoDeviceCoordDraw adcd(target->drawState()); | 786 GrDrawState::AutoDeviceCoordDraw adcd(target->drawState()); |
| 763 if (!adcd.succeeded()) { | 787 if (!adcd.succeeded()) { |
| 764 return; | 788 return; |
| 765 } | 789 } |
| 766 if (width >= 0) { | 790 if (width >= 0) { |
| 767 GrVec strokeSize; | 791 GrVec strokeSize; |
| 768 if (width > 0) { | 792 if (width > 0) { |
| 769 strokeSize.set(width, width); | 793 strokeSize.set(width, width); |
| 770 combinedMatrix.mapVectors(&strokeSize, 1); | 794 combinedMatrix.mapVectors(&strokeSize, 1); |
| 771 strokeSize.setAbs(strokeSize); | 795 strokeSize.setAbs(strokeSize); |
| 772 } else { | 796 } else { |
| 773 strokeSize.set(SK_Scalar1, SK_Scalar1); | 797 strokeSize.set(SK_Scalar1, SK_Scalar1); |
| 774 } | 798 } |
| 775 fAARectRenderer->strokeAARect(this->getGpu(), target, devRect, | 799 fAARectRenderer->strokeAARect(this->getGpu(), target, devRect, |
| 776 strokeSize, useVertexCoverage); | 800 strokeSize, useVertexCoverage); |
| 777 } else { | 801 } else { |
| 802 // filled AA rect |
| 803 #ifdef SHADER_AA_FILL_RECT |
| 804 fAARectRenderer->shaderFillAARect(this->getGpu(), target, |
| 805 rect, combinedMatrix, devRect, |
| 806 useVertexCoverage); |
| 807 #else |
| 778 fAARectRenderer->fillAARect(this->getGpu(), target, | 808 fAARectRenderer->fillAARect(this->getGpu(), target, |
| 779 devRect, useVertexCoverage); | 809 devRect, useVertexCoverage); |
| 810 #endif |
| 780 } | 811 } |
| 781 return; | 812 return; |
| 782 } | 813 } |
| 783 | 814 |
| 784 if (width >= 0) { | 815 if (width >= 0) { |
| 785 // TODO: consider making static vertex buffers for these cases. | 816 // TODO: consider making static vertex buffers for these cases. |
| 786 // Hairline could be done by just adding closing vertex to | 817 // Hairline could be done by just adding closing vertex to |
| 787 // unitSquareVertexBuffer() | 818 // unitSquareVertexBuffer() |
| 788 | 819 |
| 789 static const int worstCaseVertCount = 10; | 820 static const int worstCaseVertCount = 10; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 815 } | 846 } |
| 816 | 847 |
| 817 GrDrawState::AutoViewMatrixRestore avmr; | 848 GrDrawState::AutoViewMatrixRestore avmr; |
| 818 if (NULL != matrix) { | 849 if (NULL != matrix) { |
| 819 GrDrawState* drawState = target->drawState(); | 850 GrDrawState* drawState = target->drawState(); |
| 820 avmr.set(drawState, *matrix); | 851 avmr.set(drawState, *matrix); |
| 821 } | 852 } |
| 822 | 853 |
| 823 target->drawNonIndexed(primType, 0, vertCount); | 854 target->drawNonIndexed(primType, 0, vertCount); |
| 824 } else { | 855 } else { |
| 856 // filled BW rect |
| 825 #if GR_STATIC_RECT_VB | 857 #if GR_STATIC_RECT_VB |
| 826 const GrVertexBuffer* sqVB = fGpu->getUnitSquareVertexBuffer(); | 858 const GrVertexBuffer* sqVB = fGpu->getUnitSquareVertexBuffer(); |
| 827 if (NULL == sqVB) { | 859 if (NULL == sqVB) { |
| 828 GrPrintf("Failed to create static rect vb.\n"); | 860 GrPrintf("Failed to create static rect vb.\n"); |
| 829 return; | 861 return; |
| 830 } | 862 } |
| 831 | 863 |
| 832 GrDrawState* drawState = target->drawState(); | 864 GrDrawState* drawState = target->drawState(); |
| 833 target->drawState()->setDefaultVertexAttribs(); | 865 target->drawState()->setDefaultVertexAttribs(); |
| 834 target->setVertexSourceToBuffer(sqVB); | 866 target->setVertexSourceToBuffer(sqVB); |
| (...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1799 return srcTexture; | 1831 return srcTexture; |
| 1800 } | 1832 } |
| 1801 } | 1833 } |
| 1802 | 1834 |
| 1803 /////////////////////////////////////////////////////////////////////////////// | 1835 /////////////////////////////////////////////////////////////////////////////// |
| 1804 #if GR_CACHE_STATS | 1836 #if GR_CACHE_STATS |
| 1805 void GrContext::printCacheStats() const { | 1837 void GrContext::printCacheStats() const { |
| 1806 fTextureCache->printStats(); | 1838 fTextureCache->printStats(); |
| 1807 } | 1839 } |
| 1808 #endif | 1840 #endif |
| OLD | NEW |