OLD | NEW |
---|---|
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 "GrOvalRenderer.h" | 8 #include "GrOvalRenderer.h" |
9 | 9 |
10 #include "GrEffect.h" | 10 #include "GrEffect.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 | 214 |
215 builder->addVarying(kVec4f_GrSLType, "EllipseRadii", &vsRadiiName, & fsRadiiName); | 215 builder->addVarying(kVec4f_GrSLType, "EllipseRadii", &vsRadiiName, & fsRadiiName); |
216 const SkString* attr1Name = | 216 const SkString* attr1Name = |
217 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice s()[1]); | 217 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice s()[1]); |
218 builder->vsCodeAppendf("\t%s = %s;\n", vsRadiiName, attr1Name->c_str ()); | 218 builder->vsCodeAppendf("\t%s = %s;\n", vsRadiiName, attr1Name->c_str ()); |
219 | 219 |
220 // for outer curve | 220 // for outer curve |
221 builder->fsCodeAppendf("\tvec2 scaledOffset = %s*%s.xy;\n", fsOffset Name, fsRadiiName); | 221 builder->fsCodeAppendf("\tvec2 scaledOffset = %s*%s.xy;\n", fsOffset Name, fsRadiiName); |
222 builder->fsCodeAppend("\tfloat test = dot(scaledOffset, scaledOffset ) - 1.0;\n"); | 222 builder->fsCodeAppend("\tfloat test = dot(scaledOffset, scaledOffset ) - 1.0;\n"); |
223 builder->fsCodeAppendf("\tvec2 grad = 2.0*scaledOffset*%s.xy;\n", fs RadiiName); | 223 builder->fsCodeAppendf("\tvec2 grad = 2.0*scaledOffset*%s.xy;\n", fs RadiiName); |
224 builder->fsCodeAppend("\tfloat invlen = inversesqrt(dot(grad, grad)) ;\n"); | 224 builder->fsCodeAppend("\tfloat grad_dot = dot(grad, grad);\n"); |
robertphillips
2013/07/01 18:35:41
comment here as to why we're doing this?
| |
225 builder->fsCodeAppend("\tgrad_dot = max(grad_dot, 1.0e-4);\n"); | |
bsalomon
2013/07/01 18:36:03
Could use a comment here about why this number was
| |
226 builder->fsCodeAppend("\tfloat invlen = inversesqrt(grad_dot);\n"); | |
225 builder->fsCodeAppend("\tfloat edgeAlpha = clamp(0.5-test*invlen, 0. 0, 1.0);\n"); | 227 builder->fsCodeAppend("\tfloat edgeAlpha = clamp(0.5-test*invlen, 0. 0, 1.0);\n"); |
226 | 228 |
227 // for inner curve | 229 // for inner curve |
228 if (ellipseEffect.isStroked()) { | 230 if (ellipseEffect.isStroked()) { |
229 builder->fsCodeAppendf("\tscaledOffset = %s*%s.zw;\n", fsOffsetN ame, fsRadiiName); | 231 builder->fsCodeAppendf("\tscaledOffset = %s*%s.zw;\n", fsOffsetN ame, fsRadiiName); |
230 builder->fsCodeAppend("\ttest = dot(scaledOffset, scaledOffset) - 1.0;\n"); | 232 builder->fsCodeAppend("\ttest = dot(scaledOffset, scaledOffset) - 1.0;\n"); |
231 builder->fsCodeAppendf("\tgrad = 2.0*scaledOffset*%s.zw;\n", fsR adiiName); | 233 builder->fsCodeAppendf("\tgrad = 2.0*scaledOffset*%s.zw;\n", fsR adiiName); |
232 builder->fsCodeAppend("\tinvlen = inversesqrt(dot(grad, grad));\ n"); | 234 builder->fsCodeAppend("\tinvlen = inversesqrt(dot(grad, grad));\ n"); |
233 builder->fsCodeAppend("\tedgeAlpha *= clamp(0.5+test*invlen, 0.0 , 1.0);\n"); | 235 builder->fsCodeAppend("\tedgeAlpha *= clamp(0.5+test*invlen, 0.0 , 1.0);\n"); |
234 } | 236 } |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
801 // Expand the rect so all the pixels will be captured. | 803 // Expand the rect so all the pixels will be captured. |
802 bounds.outset(SK_ScalarHalf, SK_ScalarHalf); | 804 bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
803 | 805 |
804 SkScalar yCoords[4] = { | 806 SkScalar yCoords[4] = { |
805 bounds.fTop, | 807 bounds.fTop, |
806 bounds.fTop + yOuterRadius, | 808 bounds.fTop + yOuterRadius, |
807 bounds.fBottom - yOuterRadius, | 809 bounds.fBottom - yOuterRadius, |
808 bounds.fBottom | 810 bounds.fBottom |
809 }; | 811 }; |
810 SkScalar yOuterOffsets[4] = { | 812 SkScalar yOuterOffsets[4] = { |
811 -yOuterRadius, | 813 yOuterRadius, |
812 SK_ScalarNearlyZero, // we're using inversesqrt() in the shader, so can't be exactly 0 | 814 SK_ScalarNearlyZero, // we're using inversesqrt() in the shader, so can't be exactly 0 |
813 SK_ScalarNearlyZero, | 815 SK_ScalarNearlyZero, |
814 yOuterRadius | 816 yOuterRadius |
815 }; | 817 }; |
816 | 818 |
817 for (int i = 0; i < 4; ++i) { | 819 for (int i = 0; i < 4; ++i) { |
818 verts->fPos = SkPoint::Make(bounds.fLeft, yCoords[i]); | 820 verts->fPos = SkPoint::Make(bounds.fLeft, yCoords[i]); |
819 verts->fOffset = SkPoint::Make(-xOuterRadius, yOuterOffsets[i]); | 821 verts->fOffset = SkPoint::Make(xOuterRadius, yOuterOffsets[i]); |
820 verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 822 verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
821 verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); | 823 verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
822 verts++; | 824 verts++; |
823 | 825 |
824 verts->fPos = SkPoint::Make(bounds.fLeft + xOuterRadius, yCoords[i]) ; | 826 verts->fPos = SkPoint::Make(bounds.fLeft + xOuterRadius, yCoords[i]) ; |
825 verts->fOffset = SkPoint::Make(SK_ScalarNearlyZero, yOuterOffsets[i] ); | 827 verts->fOffset = SkPoint::Make(SK_ScalarNearlyZero, yOuterOffsets[i] ); |
826 verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 828 verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
827 verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); | 829 verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip); |
828 verts++; | 830 verts++; |
829 | 831 |
(...skipping 11 matching lines...) Expand all Loading... | |
841 } | 843 } |
842 | 844 |
843 // drop out the middle quad if we're stroked | 845 // drop out the middle quad if we're stroked |
844 int indexCnt = isStroked ? GR_ARRAY_COUNT(gRRectIndices)-6 : GR_ARRAY_CO UNT(gRRectIndices); | 846 int indexCnt = isStroked ? GR_ARRAY_COUNT(gRRectIndices)-6 : GR_ARRAY_CO UNT(gRRectIndices); |
845 target->setIndexSourceToBuffer(indexBuffer); | 847 target->setIndexSourceToBuffer(indexBuffer); |
846 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou nds); | 848 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou nds); |
847 } | 849 } |
848 | 850 |
849 return true; | 851 return true; |
850 } | 852 } |
OLD | NEW |