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

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

Issue 17845003: GPU "fix" for thin stroked rects (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 5 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 | « no previous file | 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 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrAARectRenderer.h" 8 #include "GrAARectRenderer.h"
9 #include "GrRefCnt.h" 9 #include "GrRefCnt.h"
10 #include "GrGpu.h" 10 #include "GrGpu.h"
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 GrAssert(sizeof(GrPoint) + sizeof(GrColor) == vsize); 721 GrAssert(sizeof(GrPoint) + sizeof(GrColor) == vsize);
722 722
723 // We create vertices for four nested rectangles. There are two ramps from 0 to full 723 // We create vertices for four nested rectangles. There are two ramps from 0 to full
724 // coverage, one on the exterior of the stroke and the other on the interior . 724 // coverage, one on the exterior of the stroke and the other on the interior .
725 // The following pointers refer to the four rects, from outermost to innermo st. 725 // The following pointers refer to the four rects, from outermost to innermo st.
726 GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts); 726 GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts);
727 GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + 4 * vsize); 727 GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + 4 * vsize);
728 GrPoint* fan2Pos = reinterpret_cast<GrPoint*>(verts + 8 * vsize); 728 GrPoint* fan2Pos = reinterpret_cast<GrPoint*>(verts + 8 * vsize);
729 GrPoint* fan3Pos = reinterpret_cast<GrPoint*>(verts + 12 * vsize); 729 GrPoint* fan3Pos = reinterpret_cast<GrPoint*>(verts + 12 * vsize);
730 730
731 // TODO: this only really works if the X & Y margins are the same all around
732 // the rect
733 SkScalar inset = SkMinScalar(SK_Scalar1, devOutside.fRight - devInside.fRigh t);
bsalomon 2013/06/26 15:47:49 As in square scale? Have we checked that anywhere?
robertphillips 2013/06/26 17:33:05 This code path explicitly expects non-uniform stro
734 inset = SkMinScalar(inset, devInside.fLeft - devOutside.fLeft);
735 inset = SkMinScalar(inset, devInside.fTop - devOutside.fTop);
736 inset = SK_ScalarHalf * SkMinScalar(inset, devOutside.fBottom - devInside.fB ottom);
737 SkASSERT(inset >= 0);
738
731 // outermost 739 // outermost
732 set_inset_fan(fan0Pos, vsize, devOutside, -SK_ScalarHalf, -SK_ScalarHalf); 740 set_inset_fan(fan0Pos, vsize, devOutside, -SK_ScalarHalf, -SK_ScalarHalf);
733 set_inset_fan(fan1Pos, vsize, devOutside, SK_ScalarHalf, SK_ScalarHalf); 741 // inner two
734 set_inset_fan(fan2Pos, vsize, devInside, -SK_ScalarHalf, -SK_ScalarHalf); 742 set_inset_fan(fan1Pos, vsize, devOutside, inset, inset);
743 set_inset_fan(fan2Pos, vsize, devInside, -inset, -inset);
735 // innermost 744 // innermost
736 set_inset_fan(fan3Pos, vsize, devInside, SK_ScalarHalf, SK_ScalarHalf); 745 set_inset_fan(fan3Pos, vsize, devInside, SK_ScalarHalf, SK_ScalarHalf);
737 746
738 // The outermost rect has 0 coverage 747 // The outermost rect has 0 coverage
739 verts += sizeof(GrPoint); 748 verts += sizeof(GrPoint);
740 for (int i = 0; i < 4; ++i) { 749 for (int i = 0; i < 4; ++i) {
741 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; 750 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0;
742 } 751 }
743 752
753 int scale;
754 if (inset < SK_ScalarHalf) {
755 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf));
756 SkASSERT(scale >= 0 && scale <= 255);
757 } else {
758 scale = 0xff;
759 }
760
744 // The inner two rects have full coverage 761 // The inner two rects have full coverage
745 GrColor innerColor; 762 GrColor innerColor;
746 if (useVertexCoverage) { 763 if (useVertexCoverage) {
747 innerColor = 0xffffffff; 764 innerColor = scale | (scale << 8) | (scale << 16) | (scale << 24);
bsalomon 2013/06/26 15:47:49 Can we use GrColorParckRGBA()?
robertphillips 2013/06/26 17:33:05 Done.
748 } else { 765 } else {
749 innerColor = target->getDrawState().getColor(); 766 if (0xff == scale) {
767 innerColor = target->getDrawState().getColor();
768 } else {
769 innerColor = SkAlphaMulQ(target->getDrawState().getColor(), scale);
bsalomon 2013/06/26 15:47:49 maybe just call this unconditionally?
robertphillips 2013/06/26 17:33:05 Done.
770 }
750 } 771 }
772
751 verts += 4 * vsize; 773 verts += 4 * vsize;
752 for (int i = 0; i < 8; ++i) { 774 for (int i = 0; i < 8; ++i) {
753 *reinterpret_cast<GrColor*>(verts + i * vsize) = innerColor; 775 *reinterpret_cast<GrColor*>(verts + i * vsize) = innerColor;
754 } 776 }
755 777
756 // The innermost rect has 0 coverage 778 // The innermost rect has 0 coverage
757 verts += 8 * vsize; 779 verts += 8 * vsize;
758 for (int i = 0; i < 4; ++i) { 780 for (int i = 0; i < 4; ++i) {
759 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; 781 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0;
760 } 782 }
(...skipping 16 matching lines...) Expand all
777 // can't call mapRect for devInside since it calls sort 799 // can't call mapRect for devInside since it calls sort
778 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ; 800 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ;
779 801
780 if (devInside.isEmpty()) { 802 if (devInside.isEmpty()) {
781 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use VertexCoverage); 803 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use VertexCoverage);
782 return; 804 return;
783 } 805 }
784 806
785 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove rage); 807 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove rage);
786 } 808 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698