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