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

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

Issue 509153002: Initial change to create GeometryProcessor (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: last warning Created 6 years, 3 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
« no previous file with comments | « src/gpu/GrDrawTarget.cpp ('k') | src/gpu/GrRODrawState.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 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 "gl/builders/GrGLProgramBuilder.h" 8 #include "gl/builders/GrGLProgramBuilder.h"
9 #include "GrOvalRenderer.h" 9 #include "GrOvalRenderer.h"
10 10
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 } 546 }
547 547
548 outerRadius += halfWidth; 548 outerRadius += halfWidth;
549 if (isStrokeOnly) { 549 if (isStrokeOnly) {
550 innerRadius = radius - halfWidth; 550 innerRadius = radius - halfWidth;
551 } 551 }
552 } 552 }
553 553
554 GrEffect* effect = CircleEdgeEffect::Create(isStrokeOnly && innerRadius > 0) ; 554 GrEffect* effect = CircleEdgeEffect::Create(isStrokeOnly && innerRadius > 0) ;
555 static const int kCircleEdgeAttrIndex = 1; 555 static const int kCircleEdgeAttrIndex = 1;
556 drawState->addCoverageEffect(effect, kCircleEdgeAttrIndex)->unref(); 556 drawState->setGeometryProcessor(effect, kCircleEdgeAttrIndex)->unref();
557 557
558 // The radii are outset for two reasons. First, it allows the shader to simp ly perform 558 // The radii are outset for two reasons. First, it allows the shader to simp ly perform
559 // clamp(distance-to-center - radius, 0, 1). Second, the outer radius is use d to compute the 559 // clamp(distance-to-center - radius, 0, 1). Second, the outer radius is use d to compute the
560 // verts of the bounding box that is rendered and the outset ensures the box will cover all 560 // verts of the bounding box that is rendered and the outset ensures the box will cover all
561 // pixels partially covered by the circle. 561 // pixels partially covered by the circle.
562 outerRadius += SK_ScalarHalf; 562 outerRadius += SK_ScalarHalf;
563 innerRadius -= SK_ScalarHalf; 563 innerRadius -= SK_ScalarHalf;
564 564
565 SkRect bounds = SkRect::MakeLTRB( 565 SkRect bounds = SkRect::MakeLTRB(
566 center.fX - outerRadius, 566 center.fX - outerRadius,
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 return false; 689 return false;
690 } 690 }
691 691
692 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices()); 692 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices());
693 693
694 GrEffect* effect = EllipseEdgeEffect::Create(isStrokeOnly && 694 GrEffect* effect = EllipseEdgeEffect::Create(isStrokeOnly &&
695 innerXRadius > 0 && innerYRadiu s > 0); 695 innerXRadius > 0 && innerYRadiu s > 0);
696 696
697 static const int kEllipseCenterAttrIndex = 1; 697 static const int kEllipseCenterAttrIndex = 1;
698 static const int kEllipseEdgeAttrIndex = 2; 698 static const int kEllipseEdgeAttrIndex = 2;
699 drawState->addCoverageEffect(effect, kEllipseCenterAttrIndex, kEllipseEdgeAt trIndex)->unref(); 699 drawState->setGeometryProcessor(effect, kEllipseCenterAttrIndex, kEllipseEdg eAttrIndex)->unref();
700 700
701 // Compute the reciprocals of the radii here to save time in the shader 701 // Compute the reciprocals of the radii here to save time in the shader
702 SkScalar xRadRecip = SkScalarInvert(xRadius); 702 SkScalar xRadRecip = SkScalarInvert(xRadius);
703 SkScalar yRadRecip = SkScalarInvert(yRadius); 703 SkScalar yRadRecip = SkScalarInvert(yRadius);
704 SkScalar xInnerRadRecip = SkScalarInvert(innerXRadius); 704 SkScalar xInnerRadRecip = SkScalarInvert(innerXRadius);
705 SkScalar yInnerRadRecip = SkScalarInvert(innerYRadius); 705 SkScalar yInnerRadRecip = SkScalarInvert(innerYRadius);
706 706
707 // We've extended the outer x radius out half a pixel to antialias. 707 // We've extended the outer x radius out half a pixel to antialias.
708 // This will also expand the rect so all the pixels will be captured. 708 // This will also expand the rect so all the pixels will be captured.
709 // TODO: Consider if we should use sqrt(2)/2 instead 709 // TODO: Consider if we should use sqrt(2)/2 instead
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 GrPrintf("Failed to get space for vertices!\n"); 807 GrPrintf("Failed to get space for vertices!\n");
808 return false; 808 return false;
809 } 809 }
810 810
811 DIEllipseVertex* verts = reinterpret_cast<DIEllipseVertex*>(geo.vertices()); 811 DIEllipseVertex* verts = reinterpret_cast<DIEllipseVertex*>(geo.vertices());
812 812
813 GrEffect* effect = DIEllipseEdgeEffect::Create(mode); 813 GrEffect* effect = DIEllipseEdgeEffect::Create(mode);
814 814
815 static const int kEllipseOuterOffsetAttrIndex = 1; 815 static const int kEllipseOuterOffsetAttrIndex = 1;
816 static const int kEllipseInnerOffsetAttrIndex = 2; 816 static const int kEllipseInnerOffsetAttrIndex = 2;
817 drawState->addCoverageEffect(effect, kEllipseOuterOffsetAttrIndex, 817 drawState->setGeometryProcessor(effect, kEllipseOuterOffsetAttrIndex,
818 kEllipseInnerOffsetAttrIndex)->unref(); 818 kEllipseInnerOffsetAttrIndex)->unref();
819 819
820 // This expands the outer rect so that after CTM we end up with a half-pixel border 820 // This expands the outer rect so that after CTM we end up with a half-pixel border
821 SkScalar a = vm[SkMatrix::kMScaleX]; 821 SkScalar a = vm[SkMatrix::kMScaleX];
822 SkScalar b = vm[SkMatrix::kMSkewX]; 822 SkScalar b = vm[SkMatrix::kMSkewX];
823 SkScalar c = vm[SkMatrix::kMSkewY]; 823 SkScalar c = vm[SkMatrix::kMSkewY];
824 SkScalar d = vm[SkMatrix::kMScaleY]; 824 SkScalar d = vm[SkMatrix::kMScaleY];
825 SkScalar geoDx = SkScalarDiv(SK_ScalarHalf, SkScalarSqrt(a*a + c*c)); 825 SkScalar geoDx = SkScalarDiv(SK_ScalarHalf, SkScalarSqrt(a*a + c*c));
826 SkScalar geoDy = SkScalarDiv(SK_ScalarHalf, SkScalarSqrt(b*b + d*d)); 826 SkScalar geoDy = SkScalarDiv(SK_ScalarHalf, SkScalarSqrt(b*b + d*d));
827 // This adjusts the "radius" to include the half-pixel border 827 // This adjusts the "radius" to include the half-pixel border
828 SkScalar offsetDx = SkScalarDiv(geoDx, xRadius); 828 SkScalar offsetDx = SkScalarDiv(geoDx, xRadius);
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 innerRadius = xRadius - halfWidth; 1056 innerRadius = xRadius - halfWidth;
1057 } 1057 }
1058 outerRadius += halfWidth; 1058 outerRadius += halfWidth;
1059 bounds.outset(halfWidth, halfWidth); 1059 bounds.outset(halfWidth, halfWidth);
1060 } 1060 }
1061 1061
1062 isStrokeOnly = (isStrokeOnly && innerRadius >= 0); 1062 isStrokeOnly = (isStrokeOnly && innerRadius >= 0);
1063 1063
1064 GrEffect* effect = CircleEdgeEffect::Create(isStrokeOnly); 1064 GrEffect* effect = CircleEdgeEffect::Create(isStrokeOnly);
1065 static const int kCircleEdgeAttrIndex = 1; 1065 static const int kCircleEdgeAttrIndex = 1;
1066 drawState->addCoverageEffect(effect, kCircleEdgeAttrIndex)->unref(); 1066 drawState->setGeometryProcessor(effect, kCircleEdgeAttrIndex)->unref();
1067 1067
1068 // The radii are outset for two reasons. First, it allows the shader to simply perform 1068 // The radii are outset for two reasons. First, it allows the shader to simply perform
1069 // clamp(distance-to-center - radius, 0, 1). Second, the outer radius is used to compute the 1069 // clamp(distance-to-center - radius, 0, 1). Second, the outer radius is used to compute the
1070 // verts of the bounding box that is rendered and the outset ensures the box will cover all 1070 // verts of the bounding box that is rendered and the outset ensures the box will cover all
1071 // pixels partially covered by the circle. 1071 // pixels partially covered by the circle.
1072 outerRadius += SK_ScalarHalf; 1072 outerRadius += SK_ScalarHalf;
1073 innerRadius -= SK_ScalarHalf; 1073 innerRadius -= SK_ScalarHalf;
1074 1074
1075 // Expand the rect so all the pixels will be captured. 1075 // Expand the rect so all the pixels will be captured.
1076 bounds.outset(SK_ScalarHalf, SK_ScalarHalf); 1076 bounds.outset(SK_ScalarHalf, SK_ScalarHalf);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0); 1161 GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0);
1162 if (!geo.succeeded()) { 1162 if (!geo.succeeded()) {
1163 GrPrintf("Failed to get space for vertices!\n"); 1163 GrPrintf("Failed to get space for vertices!\n");
1164 return false; 1164 return false;
1165 } 1165 }
1166 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices()); 1166 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices());
1167 1167
1168 GrEffect* effect = EllipseEdgeEffect::Create(isStrokeOnly); 1168 GrEffect* effect = EllipseEdgeEffect::Create(isStrokeOnly);
1169 static const int kEllipseOffsetAttrIndex = 1; 1169 static const int kEllipseOffsetAttrIndex = 1;
1170 static const int kEllipseRadiiAttrIndex = 2; 1170 static const int kEllipseRadiiAttrIndex = 2;
1171 drawState->addCoverageEffect(effect, 1171 drawState->setGeometryProcessor(effect,
1172 kEllipseOffsetAttrIndex, kEllipseRadiiAttrI ndex)->unref(); 1172 kEllipseOffsetAttrIndex,
1173 kEllipseRadiiAttrIndex)->unref();
1173 1174
1174 // Compute the reciprocals of the radii here to save time in the shader 1175 // Compute the reciprocals of the radii here to save time in the shader
1175 SkScalar xRadRecip = SkScalarInvert(xRadius); 1176 SkScalar xRadRecip = SkScalarInvert(xRadius);
1176 SkScalar yRadRecip = SkScalarInvert(yRadius); 1177 SkScalar yRadRecip = SkScalarInvert(yRadius);
1177 SkScalar xInnerRadRecip = SkScalarInvert(innerXRadius); 1178 SkScalar xInnerRadRecip = SkScalarInvert(innerXRadius);
1178 SkScalar yInnerRadRecip = SkScalarInvert(innerYRadius); 1179 SkScalar yInnerRadRecip = SkScalarInvert(innerYRadius);
1179 1180
1180 // Extend the radii out half a pixel to antialias. 1181 // Extend the radii out half a pixel to antialias.
1181 SkScalar xOuterRadius = xRadius + SK_ScalarHalf; 1182 SkScalar xOuterRadius = xRadius + SK_ScalarHalf;
1182 SkScalar yOuterRadius = yRadius + SK_ScalarHalf; 1183 SkScalar yOuterRadius = yRadius + SK_ScalarHalf;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 1226
1226 // drop out the middle quad if we're stroked 1227 // drop out the middle quad if we're stroked
1227 int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 : 1228 int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 :
1228 SK_ARRAY_COUNT(gRRectIndices); 1229 SK_ARRAY_COUNT(gRRectIndices);
1229 target->setIndexSourceToBuffer(indexBuffer); 1230 target->setIndexSourceToBuffer(indexBuffer);
1230 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou nds); 1231 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou nds);
1231 } 1232 }
1232 1233
1233 return true; 1234 return true;
1234 } 1235 }
OLDNEW
« no previous file with comments | « src/gpu/GrDrawTarget.cpp ('k') | src/gpu/GrRODrawState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698