Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: src/gpu/GrContext.cpp

Issue 14890021: Remove isIRect "optimization" & defer computation of device Rect in AA rect rendering (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/gpu/GrClipMaskManager.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 682
683 /** 683 /**
684 * Returns true if the rects edges are integer-aligned. 684 * Returns true if the rects edges are integer-aligned.
685 */ 685 */
686 static bool isIRect(const GrRect& r) { 686 static bool isIRect(const GrRect& r) {
687 return SkScalarIsInt(r.fLeft) && SkScalarIsInt(r.fTop) && 687 return SkScalarIsInt(r.fLeft) && SkScalarIsInt(r.fTop) &&
688 SkScalarIsInt(r.fRight) && SkScalarIsInt(r.fBottom); 688 SkScalarIsInt(r.fRight) && SkScalarIsInt(r.fBottom);
689 } 689 }
690 690
691 static bool apply_aa_to_rect(GrDrawTarget* target, 691 static bool apply_aa_to_rect(GrDrawTarget* target,
692 const GrRect& rect,
693 SkScalar strokeWidth, 692 SkScalar strokeWidth,
694 const SkMatrix* matrix, 693 const SkMatrix* matrix,
695 SkMatrix* combinedMatrix, 694 SkMatrix* combinedMatrix,
696 GrRect* devRect,
697 bool* useVertexCoverage) { 695 bool* useVertexCoverage) {
698 // we use a simple coverage ramp to do aa on axis-aligned rects 696 // we use a simple coverage ramp to do aa on axis-aligned rects
699 // we check if the rect will be axis-aligned, and the rect won't land on 697 // we check if the rect will be axis-aligned, and the rect won't land on
700 // integer coords. 698 // integer coords.
701 699
702 // we are keeping around the "tweak the alpha" trick because 700 // we are keeping around the "tweak the alpha" trick because
703 // it is our only hope for the fixed-pipe implementation. 701 // it is our only hope for the fixed-pipe implementation.
704 // In a shader implementation we can give a separate coverage input 702 // In a shader implementation we can give a separate coverage input
705 // TODO: remove this ugliness when we drop the fixed-pipe impl 703 // TODO: remove this ugliness when we drop the fixed-pipe impl
706 *useVertexCoverage = false; 704 *useVertexCoverage = false;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 #endif 754 #endif
757 GrAssert(combinedMatrix->preservesAxisAlignment()); 755 GrAssert(combinedMatrix->preservesAxisAlignment());
758 #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT) 756 #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT)
759 } else { 757 } else {
760 GrAssert(combinedMatrix->preservesRightAngles()); 758 GrAssert(combinedMatrix->preservesRightAngles());
761 } 759 }
762 #endif 760 #endif
763 #endif 761 #endif
764 } 762 }
765 763
766 combinedMatrix->mapRect(devRect, rect); 764 return true;
767
768 if (strokeWidth < 0
769 #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT)
770 && drawState.getViewMatrix().preservesAxisAlignment()
771 #endif
772 ) {
773 return !isIRect(*devRect);
774 } else {
775 return true;
776 }
777 } 765 }
778 766
779 void GrContext::drawRect(const GrPaint& paint, 767 void GrContext::drawRect(const GrPaint& paint,
780 const GrRect& rect, 768 const GrRect& rect,
781 SkScalar width, 769 SkScalar width,
782 const SkMatrix* matrix) { 770 const SkMatrix* matrix) {
783 SK_TRACE_EVENT0("GrContext::drawRect"); 771 SK_TRACE_EVENT0("GrContext::drawRect");
784 772
785 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); 773 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW);
786 GrDrawState::AutoStageDisable atr(fDrawState); 774 GrDrawState::AutoStageDisable atr(fDrawState);
787 775
788 GrRect devRect;
789 SkMatrix combinedMatrix; 776 SkMatrix combinedMatrix;
790 bool useVertexCoverage; 777 bool useVertexCoverage;
791 bool needAA = paint.isAntiAlias() && 778 bool needAA = paint.isAntiAlias() &&
792 !this->getRenderTarget()->isMultisampled(); 779 !this->getRenderTarget()->isMultisampled();
793 bool doAA = needAA && apply_aa_to_rect(target, rect, width, matrix, 780 bool doAA = needAA && apply_aa_to_rect(target, width, matrix,
794 &combinedMatrix, &devRect, 781 &combinedMatrix,
795 &useVertexCoverage); 782 &useVertexCoverage);
796 if (doAA) { 783 if (doAA) {
797 GrDrawState::AutoDeviceCoordDraw adcd(target->drawState()); 784 GrDrawState::AutoDeviceCoordDraw adcd(target->drawState());
798 if (!adcd.succeeded()) { 785 if (!adcd.succeeded()) {
799 return; 786 return;
800 } 787 }
801 if (width >= 0) { 788 if (width >= 0) {
802 GrVec strokeSize; 789 GrVec strokeSize;
803 if (width > 0) { 790 if (width > 0) {
804 strokeSize.set(width, width); 791 strokeSize.set(width, width);
805 combinedMatrix.mapVectors(&strokeSize, 1); 792 combinedMatrix.mapVectors(&strokeSize, 1);
806 strokeSize.setAbs(strokeSize); 793 strokeSize.setAbs(strokeSize);
807 } else { 794 } else {
808 strokeSize.set(SK_Scalar1, SK_Scalar1); 795 strokeSize.set(SK_Scalar1, SK_Scalar1);
809 } 796 }
810 fAARectRenderer->strokeAARect(this->getGpu(), target, devRect, 797 fAARectRenderer->strokeAARect(this->getGpu(), target,
798 rect, combinedMatrix,
811 strokeSize, useVertexCoverage); 799 strokeSize, useVertexCoverage);
812 } else { 800 } else {
813 // filled AA rect 801 // filled AA rect
814 fAARectRenderer->fillAARect(this->getGpu(), target, 802 fAARectRenderer->fillAARect(this->getGpu(), target,
815 rect, combinedMatrix, devRect, 803 rect, combinedMatrix,
816 useVertexCoverage); 804 useVertexCoverage);
817 } 805 }
818 return; 806 return;
819 } 807 }
820 808
821 if (width >= 0) { 809 if (width >= 0) {
822 // TODO: consider making static vertex buffers for these cases. 810 // TODO: consider making static vertex buffers for these cases.
823 // Hairline could be done by just adding closing vertex to 811 // Hairline could be done by just adding closing vertex to
824 // unitSquareVertexBuffer() 812 // unitSquareVertexBuffer()
825 813
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after
1806 return srcTexture; 1794 return srcTexture;
1807 } 1795 }
1808 } 1796 }
1809 1797
1810 /////////////////////////////////////////////////////////////////////////////// 1798 ///////////////////////////////////////////////////////////////////////////////
1811 #if GR_CACHE_STATS 1799 #if GR_CACHE_STATS
1812 void GrContext::printCacheStats() const { 1800 void GrContext::printCacheStats() const {
1813 fTextureCache->printStats(); 1801 fTextureCache->printStats();
1814 } 1802 }
1815 #endif 1803 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrClipMaskManager.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698