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

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

Issue 21877006: Add blend optimization helpers and use to convert rect draws to clears. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: change src to rect in comment Created 7 years, 4 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/GrBlend.cpp ('k') | src/gpu/GrDrawState.h » ('j') | 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 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 } 673 }
674 674
675 static bool isIRect(const SkRect& r) { 675 static bool isIRect(const SkRect& r) {
676 return SkScalarIsInt(r.fLeft) && SkScalarIsInt(r.fTop) && 676 return SkScalarIsInt(r.fLeft) && SkScalarIsInt(r.fTop) &&
677 SkScalarIsInt(r.fRight) && SkScalarIsInt(r.fBottom); 677 SkScalarIsInt(r.fRight) && SkScalarIsInt(r.fBottom);
678 } 678 }
679 679
680 static bool apply_aa_to_rect(GrDrawTarget* target, 680 static bool apply_aa_to_rect(GrDrawTarget* target,
681 const SkRect& rect, 681 const SkRect& rect,
682 SkScalar strokeWidth, 682 SkScalar strokeWidth,
683 const SkMatrix* matrix, 683 const SkMatrix& combinedMatrix,
684 SkMatrix* combinedMatrix, 684 SkRect* devBoundRect,
685 SkRect* devRect,
686 bool* useVertexCoverage) { 685 bool* useVertexCoverage) {
687 // we use a simple coverage ramp to do aa on axis-aligned rects 686 // we use a simple coverage ramp to do aa on axis-aligned rects
688 // we check if the rect will be axis-aligned, and the rect won't land on 687 // we check if the rect will be axis-aligned, and the rect won't land on
689 // integer coords. 688 // integer coords.
690 689
691 // we are keeping around the "tweak the alpha" trick because 690 // we are keeping around the "tweak the alpha" trick because
692 // it is our only hope for the fixed-pipe implementation. 691 // it is our only hope for the fixed-pipe implementation.
693 // In a shader implementation we can give a separate coverage input 692 // In a shader implementation we can give a separate coverage input
694 // TODO: remove this ugliness when we drop the fixed-pipe impl 693 // TODO: remove this ugliness when we drop the fixed-pipe impl
695 *useVertexCoverage = false; 694 *useVertexCoverage = false;
(...skipping 12 matching lines...) Expand all
708 return false; 707 return false;
709 } 708 }
710 709
711 if (0 == strokeWidth && target->willUseHWAALines()) { 710 if (0 == strokeWidth && target->willUseHWAALines()) {
712 return false; 711 return false;
713 } 712 }
714 713
715 #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT) 714 #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT)
716 if (strokeWidth >= 0) { 715 if (strokeWidth >= 0) {
717 #endif 716 #endif
718 if (!drawState.getViewMatrix().preservesAxisAlignment()) { 717 if (!combinedMatrix.preservesAxisAlignment()) {
719 return false; 718 return false;
720 } 719 }
721 720
722 if (NULL != matrix && !matrix->preservesAxisAlignment()) {
723 return false;
724 }
725 #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT) 721 #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT)
726 } else { 722 } else {
727 if (!drawState.getViewMatrix().preservesAxisAlignment() && 723 if (!combinedMatrix.preservesRightAngles()) {
728 !drawState.getViewMatrix().preservesRightAngles()) {
729 return false;
730 }
731
732 if (NULL != matrix && !matrix->preservesRightAngles()) {
733 return false; 724 return false;
734 } 725 }
735 } 726 }
736 #endif 727 #endif
737 728
738 *combinedMatrix = drawState.getViewMatrix(); 729 combinedMatrix.mapRect(devBoundRect, rect);
739 if (NULL != matrix) {
740 combinedMatrix->preConcat(*matrix);
741
742 #if GR_DEBUG
743 #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT)
744 if (strokeWidth >= 0) {
745 #endif
746 GrAssert(combinedMatrix->preservesAxisAlignment());
747 #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT)
748 } else {
749 GrAssert(combinedMatrix->preservesRightAngles());
750 }
751 #endif
752 #endif
753 }
754
755 combinedMatrix->mapRect(devRect, rect);
756 730
757 if (strokeWidth < 0) { 731 if (strokeWidth < 0) {
758 return !isIRect(*devRect); 732 return !isIRect(*devBoundRect);
759 } else { 733 } else {
760 return true; 734 return true;
761 } 735 }
762 } 736 }
763 737
738 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po int) {
739 return point.fX >= rect.fLeft && point.fX <= rect.fRight &&
740 point.fY >= rect.fTop && point.fY <= rect.fBottom;
741 }
742
764 void GrContext::drawRect(const GrPaint& paint, 743 void GrContext::drawRect(const GrPaint& paint,
765 const SkRect& rect, 744 const SkRect& rect,
766 SkScalar width, 745 SkScalar width,
767 const SkMatrix* matrix) { 746 const SkMatrix* matrix) {
768 SK_TRACE_EVENT0("GrContext::drawRect"); 747 SK_TRACE_EVENT0("GrContext::drawRect");
769 748
770 AutoRestoreEffects are; 749 AutoRestoreEffects are;
771 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are); 750 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are);
772 751
773 SkRect devRect; 752 SkMatrix combinedMatrix = target->drawState()->getViewMatrix();
774 SkMatrix combinedMatrix; 753 if (NULL != matrix) {
754 combinedMatrix.preConcat(*matrix);
755 }
756
757 // Check if this is a full RT draw and can be replaced with a clear.
758 SkRect rtRect;
759 target->getDrawState().getRenderTarget()->getBoundsRect(&rtRect);
760 SkRect clipSpaceRTRect = rtRect;
761 bool checkClip = false;
762 if (NULL != this->getClip()) {
763 checkClip = true;
764 clipSpaceRTRect.offset(SkIntToScalar(this->getClip()->fOrigin.fX),
765 SkIntToScalar(this->getClip()->fOrigin.fY));
766 }
767 // Does the clip contain the entire RT?
768 if (!checkClip || target->getClip()->fClipStack->quickContains(clipSpaceRTRe ct)) {
769 SkMatrix invM;
770 if (!combinedMatrix.invert(&invM)) {
771 return;
772 }
773 // Does the rect bound the RT?
774 SkPoint srcSpaceRTQuad[4];
775 invM.mapRectToQuad(srcSpaceRTQuad, rtRect);
776 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) &&
777 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) &&
778 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) &&
779 rect_contains_inclusive(rect, srcSpaceRTQuad[3])) {
780 // Will it blend?
781 GrColor clearColor;
782 if (paint.isOpaqueAndConstantColor(&clearColor)) {
783 target->clear(NULL, clearColor);
784 return;
785 }
786 }
787 }
788
789 SkRect devBoundRect;
775 bool useVertexCoverage; 790 bool useVertexCoverage;
776 bool needAA = paint.isAntiAlias() && 791 bool needAA = paint.isAntiAlias() &&
777 !target->getDrawState().getRenderTarget()->isMultisampled(); 792 !target->getDrawState().getRenderTarget()->isMultisampled();
778 bool doAA = needAA && apply_aa_to_rect(target, rect, width, matrix, 793 bool doAA = needAA && apply_aa_to_rect(target, rect, width, combinedMatrix, &devBoundRect,
779 &combinedMatrix, &devRect,
780 &useVertexCoverage); 794 &useVertexCoverage);
781 if (doAA) { 795 if (doAA) {
782 GrDrawState::AutoViewMatrixRestore avmr; 796 GrDrawState::AutoViewMatrixRestore avmr;
783 if (!avmr.setIdentity(target->drawState())) { 797 if (!avmr.setIdentity(target->drawState())) {
784 return; 798 return;
785 } 799 }
786 if (width >= 0) { 800 if (width >= 0) {
787 fAARectRenderer->strokeAARect(this->getGpu(), target, 801 fAARectRenderer->strokeAARect(this->getGpu(), target,
788 rect, combinedMatrix, devRect, 802 rect, combinedMatrix, devBoundRect,
789 width, useVertexCoverage); 803 width, useVertexCoverage);
790 } else { 804 } else {
791 // filled AA rect 805 // filled AA rect
792 fAARectRenderer->fillAARect(this->getGpu(), target, 806 fAARectRenderer->fillAARect(this->getGpu(), target,
793 rect, combinedMatrix, devRect, 807 rect, combinedMatrix, devBoundRect,
794 useVertexCoverage); 808 useVertexCoverage);
795 } 809 }
796 return; 810 return;
797 } 811 }
798 812
799 if (width >= 0) { 813 if (width >= 0) {
800 // TODO: consider making static vertex buffers for these cases. 814 // TODO: consider making static vertex buffers for these cases.
801 // Hairline could be done by just adding closing vertex to 815 // Hairline could be done by just adding closing vertex to
802 // unitSquareVertexBuffer() 816 // unitSquareVertexBuffer()
803 817
(...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after
1705 return NULL; 1719 return NULL;
1706 } 1720 }
1707 } 1721 }
1708 1722
1709 /////////////////////////////////////////////////////////////////////////////// 1723 ///////////////////////////////////////////////////////////////////////////////
1710 #if GR_CACHE_STATS 1724 #if GR_CACHE_STATS
1711 void GrContext::printCacheStats() const { 1725 void GrContext::printCacheStats() const {
1712 fTextureCache->printStats(); 1726 fTextureCache->printStats();
1713 } 1727 }
1714 #endif 1728 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrBlend.cpp ('k') | src/gpu/GrDrawState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698