OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrConvexPolyEffect.h" | 8 #include "GrConvexPolyEffect.h" |
9 #include "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.h" |
10 #include "SkPath.h" | 10 #include "SkPath.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 const AARectEffect& aare = fp.cast<AARectEffect>(); | 115 const AARectEffect& aare = fp.cast<AARectEffect>(); |
116 const char *rectName; | 116 const char *rectName; |
117 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), | 117 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), |
118 // respectively. | 118 // respectively. |
119 fRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 119 fRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
120 kVec4f_GrSLType, | 120 kVec4f_GrSLType, |
121 kDefault_GrSLPrecision, | 121 kDefault_GrSLPrecision, |
122 "rect", | 122 "rect", |
123 &rectName); | 123 &rectName); |
124 | 124 |
125 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 125 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
126 const char* fragmentPos = fsBuilder->fragmentPosition(); | 126 const char* fragmentPos = fsBuilder->fragmentPosition(); |
127 if (GrProcessorEdgeTypeIsAA(aare.getEdgeType())) { | 127 if (GrProcessorEdgeTypeIsAA(aare.getEdgeType())) { |
128 // The amount of coverage removed in x and y by the edges is computed as
a pair of negative | 128 // The amount of coverage removed in x and y by the edges is computed as
a pair of negative |
129 // numbers, xSub and ySub. | 129 // numbers, xSub and ySub. |
130 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); | 130 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); |
131 fsBuilder->codeAppendf("\t\txSub = min(%s.x - %s.x, 0.0);\n", fragmentPo
s, rectName); | 131 fsBuilder->codeAppendf("\t\txSub = min(%s.x - %s.x, 0.0);\n", fragmentPo
s, rectName); |
132 fsBuilder->codeAppendf("\t\txSub += min(%s.z - %s.x, 0.0);\n", rectName,
fragmentPos); | 132 fsBuilder->codeAppendf("\t\txSub += min(%s.z - %s.x, 0.0);\n", rectName,
fragmentPos); |
133 fsBuilder->codeAppendf("\t\tySub = min(%s.y - %s.y, 0.0);\n", fragmentPo
s, rectName); | 133 fsBuilder->codeAppendf("\t\tySub = min(%s.y - %s.y, 0.0);\n", fragmentPo
s, rectName); |
134 fsBuilder->codeAppendf("\t\tySub += min(%s.w - %s.y, 0.0);\n", rectName,
fragmentPos); | 134 fsBuilder->codeAppendf("\t\tySub += min(%s.w - %s.y, 0.0);\n", rectName,
fragmentPos); |
135 // Now compute coverage in x and y and multiply them to get the fraction
of the pixel | 135 // Now compute coverage in x and y and multiply them to get the fraction
of the pixel |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 const TextureSamplerArray& samplers) { | 209 const TextureSamplerArray& samplers) { |
210 const GrConvexPolyEffect& cpe = fp.cast<GrConvexPolyEffect>(); | 210 const GrConvexPolyEffect& cpe = fp.cast<GrConvexPolyEffect>(); |
211 | 211 |
212 const char *edgeArrayName; | 212 const char *edgeArrayName; |
213 fEdgeUniform = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibi
lity, | 213 fEdgeUniform = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibi
lity, |
214 kVec3f_GrSLType, | 214 kVec3f_GrSLType, |
215 kDefault_GrSLPrecision, | 215 kDefault_GrSLPrecision, |
216 "edges", | 216 "edges", |
217 cpe.getEdgeCount(), | 217 cpe.getEdgeCount(), |
218 &edgeArrayName); | 218 &edgeArrayName); |
219 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 219 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
220 fsBuilder->codeAppend("\t\tfloat alpha = 1.0;\n"); | 220 fsBuilder->codeAppend("\t\tfloat alpha = 1.0;\n"); |
221 fsBuilder->codeAppend("\t\tfloat edge;\n"); | 221 fsBuilder->codeAppend("\t\tfloat edge;\n"); |
222 const char* fragmentPos = fsBuilder->fragmentPosition(); | 222 const char* fragmentPos = fsBuilder->fragmentPosition(); |
223 for (int i = 0; i < cpe.getEdgeCount(); ++i) { | 223 for (int i = 0; i < cpe.getEdgeCount(); ++i) { |
224 fsBuilder->codeAppendf("\t\tedge = dot(%s[%d], vec3(%s.x, %s.y, 1));\n", | 224 fsBuilder->codeAppendf("\t\tedge = dot(%s[%d], vec3(%s.x, %s.y, 1));\n", |
225 edgeArrayName, i, fragmentPos, fragmentPos); | 225 edgeArrayName, i, fragmentPos, fragmentPos); |
226 if (GrProcessorEdgeTypeIsAA(cpe.getEdgeType())) { | 226 if (GrProcessorEdgeTypeIsAA(cpe.getEdgeType())) { |
227 fsBuilder->codeAppend("\t\tedge = clamp(edge, 0.0, 1.0);\n"); | 227 fsBuilder->codeAppend("\t\tedge = clamp(edge, 0.0, 1.0);\n"); |
228 } else { | 228 } else { |
229 fsBuilder->codeAppend("\t\tedge = edge >= 0.5 ? 1.0 : 0.0;\n"); | 229 fsBuilder->codeAppend("\t\tedge = edge >= 0.5 ? 1.0 : 0.0;\n"); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 } | 372 } |
373 | 373 |
374 GrFragmentProcessor* fp; | 374 GrFragmentProcessor* fp; |
375 do { | 375 do { |
376 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 376 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
377 random->nextULessThan(kGrProcessorEdgeTy
peCnt)); | 377 random->nextULessThan(kGrProcessorEdgeTy
peCnt)); |
378 fp = GrConvexPolyEffect::Create(edgeType, count, edges); | 378 fp = GrConvexPolyEffect::Create(edgeType, count, edges); |
379 } while (NULL == fp); | 379 } while (NULL == fp); |
380 return fp; | 380 return fp; |
381 } | 381 } |
OLD | NEW |