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

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: Addressed some code review issues Created 7 years, 6 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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 int scale; 463 int scale;
464 if (inset < SK_ScalarHalf) { 464 if (inset < SK_ScalarHalf) {
465 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf)); 465 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf));
466 SkASSERT(scale >= 0 && scale <= 255); 466 SkASSERT(scale >= 0 && scale <= 255);
467 } else { 467 } else {
468 scale = 0xff; 468 scale = 0xff;
469 } 469 }
470 470
471 GrColor innerColor; 471 GrColor innerColor;
472 if (useVertexCoverage) { 472 if (useVertexCoverage) {
473 innerColor = scale | (scale << 8) | (scale << 16) | (scale << 24); 473 innerColor = GrColorPackRGBA(scale, scale, scale, scale);
474 } else { 474 } else {
475 if (0xff == scale) { 475 innerColor = SkAlphaMulQ(target->getDrawState().getColor(), scale);
476 innerColor = target->getDrawState().getColor();
477 } else {
478 innerColor = SkAlphaMulQ(target->getDrawState().getColor(), scale);
479 }
480 } 476 }
481 477
482 verts += 4 * vsize; 478 verts += 4 * vsize;
483 for (int i = 0; i < 4; ++i) { 479 for (int i = 0; i < 4; ++i) {
484 *reinterpret_cast<GrColor*>(verts + i * vsize) = innerColor; 480 *reinterpret_cast<GrColor*>(verts + i * vsize) = innerColor;
485 } 481 }
486 482
487 target->setIndexSourceToBuffer(indexBuffer); 483 target->setIndexSourceToBuffer(indexBuffer);
488 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 484 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1,
489 kVertsPerAAFillRect, 485 kVertsPerAAFillRect,
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 GrAssert(sizeof(GrPoint) + sizeof(GrColor) == vsize); 717 GrAssert(sizeof(GrPoint) + sizeof(GrColor) == vsize);
722 718
723 // We create vertices for four nested rectangles. There are two ramps from 0 to full 719 // 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 . 720 // 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. 721 // The following pointers refer to the four rects, from outermost to innermo st.
726 GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts); 722 GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts);
727 GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + 4 * vsize); 723 GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + 4 * vsize);
728 GrPoint* fan2Pos = reinterpret_cast<GrPoint*>(verts + 8 * vsize); 724 GrPoint* fan2Pos = reinterpret_cast<GrPoint*>(verts + 8 * vsize);
729 GrPoint* fan3Pos = reinterpret_cast<GrPoint*>(verts + 12 * vsize); 725 GrPoint* fan3Pos = reinterpret_cast<GrPoint*>(verts + 12 * vsize);
730 726
727 // TODO: this only really works if the X & Y margins are the same all around
728 // the rect
729 SkScalar inset = SkMinScalar(SK_Scalar1, devOutside.fRight - devInside.fRigh t);
730 inset = SkMinScalar(inset, devInside.fLeft - devOutside.fLeft);
731 inset = SkMinScalar(inset, devInside.fTop - devOutside.fTop);
732 inset = SK_ScalarHalf * SkMinScalar(inset, devOutside.fBottom - devInside.fB ottom);
733 SkASSERT(inset >= 0);
734
731 // outermost 735 // outermost
732 set_inset_fan(fan0Pos, vsize, devOutside, -SK_ScalarHalf, -SK_ScalarHalf); 736 set_inset_fan(fan0Pos, vsize, devOutside, -SK_ScalarHalf, -SK_ScalarHalf);
733 set_inset_fan(fan1Pos, vsize, devOutside, SK_ScalarHalf, SK_ScalarHalf); 737 // inner two
734 set_inset_fan(fan2Pos, vsize, devInside, -SK_ScalarHalf, -SK_ScalarHalf); 738 set_inset_fan(fan1Pos, vsize, devOutside, inset, inset);
739 set_inset_fan(fan2Pos, vsize, devInside, -inset, -inset);
735 // innermost 740 // innermost
736 set_inset_fan(fan3Pos, vsize, devInside, SK_ScalarHalf, SK_ScalarHalf); 741 set_inset_fan(fan3Pos, vsize, devInside, SK_ScalarHalf, SK_ScalarHalf);
737 742
738 // The outermost rect has 0 coverage 743 // The outermost rect has 0 coverage
739 verts += sizeof(GrPoint); 744 verts += sizeof(GrPoint);
740 for (int i = 0; i < 4; ++i) { 745 for (int i = 0; i < 4; ++i) {
741 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; 746 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0;
742 } 747 }
743 748
749 int scale;
750 if (inset < SK_ScalarHalf) {
751 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf));
752 SkASSERT(scale >= 0 && scale <= 255);
753 } else {
754 scale = 0xff;
755 }
756
744 // The inner two rects have full coverage 757 // The inner two rects have full coverage
745 GrColor innerColor; 758 GrColor innerColor;
746 if (useVertexCoverage) { 759 if (useVertexCoverage) {
747 innerColor = 0xffffffff; 760 innerColor = GrColorPackRGBA(scale, scale, scale, scale);
748 } else { 761 } else {
749 innerColor = target->getDrawState().getColor(); 762 innerColor = SkAlphaMulQ(target->getDrawState().getColor(), scale);
750 } 763 }
764
751 verts += 4 * vsize; 765 verts += 4 * vsize;
752 for (int i = 0; i < 8; ++i) { 766 for (int i = 0; i < 8; ++i) {
753 *reinterpret_cast<GrColor*>(verts + i * vsize) = innerColor; 767 *reinterpret_cast<GrColor*>(verts + i * vsize) = innerColor;
754 } 768 }
755 769
756 // The innermost rect has 0 coverage 770 // The innermost rect has 0 coverage
757 verts += 8 * vsize; 771 verts += 8 * vsize;
758 for (int i = 0; i < 4; ++i) { 772 for (int i = 0; i < 4; ++i) {
759 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; 773 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0;
760 } 774 }
(...skipping 16 matching lines...) Expand all
777 // can't call mapRect for devInside since it calls sort 791 // can't call mapRect for devInside since it calls sort
778 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ; 792 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ;
779 793
780 if (devInside.isEmpty()) { 794 if (devInside.isEmpty()) {
781 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use VertexCoverage); 795 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use VertexCoverage);
782 return; 796 return;
783 } 797 }
784 798
785 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove rage); 799 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove rage);
786 } 800 }
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