| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 const char* outputColor, | 111 const char* outputColor, |
| 112 const char* inputColor, | 112 const char* inputColor, |
| 113 const TransformedCoordsArray&, | 113 const TransformedCoordsArray&, |
| 114 const TextureSamplerArray& samplers) { | 114 const TextureSamplerArray& samplers) { |
| 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 "rect", | 122 "rect", |
| 122 &rectName); | 123 &rectName); |
| 123 | 124 |
| 124 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 125 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
| 125 const char* fragmentPos = fsBuilder->fragmentPosition(); | 126 const char* fragmentPos = fsBuilder->fragmentPosition(); |
| 126 if (GrProcessorEdgeTypeIsAA(aare.getEdgeType())) { | 127 if (GrProcessorEdgeTypeIsAA(aare.getEdgeType())) { |
| 127 // 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 |
| 128 // numbers, xSub and ySub. | 129 // numbers, xSub and ySub. |
| 129 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); | 130 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); |
| 130 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); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 const GrFragmentProcessor& fp, | 205 const GrFragmentProcessor& fp, |
| 205 const char* outputColor, | 206 const char* outputColor, |
| 206 const char* inputColor, | 207 const char* inputColor, |
| 207 const TransformedCoordsArray&, | 208 const TransformedCoordsArray&, |
| 208 const TextureSamplerArray& samplers) { | 209 const TextureSamplerArray& samplers) { |
| 209 const GrConvexPolyEffect& cpe = fp.cast<GrConvexPolyEffect>(); | 210 const GrConvexPolyEffect& cpe = fp.cast<GrConvexPolyEffect>(); |
| 210 | 211 |
| 211 const char *edgeArrayName; | 212 const char *edgeArrayName; |
| 212 fEdgeUniform = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibi
lity, | 213 fEdgeUniform = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibi
lity, |
| 213 kVec3f_GrSLType, | 214 kVec3f_GrSLType, |
| 214 "edges", | 215 kDefault_GrSLPrecision, |
| 216 "edges", |
| 215 cpe.getEdgeCount(), | 217 cpe.getEdgeCount(), |
| 216 &edgeArrayName); | 218 &edgeArrayName); |
| 217 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 219 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
| 218 fsBuilder->codeAppend("\t\tfloat alpha = 1.0;\n"); | 220 fsBuilder->codeAppend("\t\tfloat alpha = 1.0;\n"); |
| 219 fsBuilder->codeAppend("\t\tfloat edge;\n"); | 221 fsBuilder->codeAppend("\t\tfloat edge;\n"); |
| 220 const char* fragmentPos = fsBuilder->fragmentPosition(); | 222 const char* fragmentPos = fsBuilder->fragmentPosition(); |
| 221 for (int i = 0; i < cpe.getEdgeCount(); ++i) { | 223 for (int i = 0; i < cpe.getEdgeCount(); ++i) { |
| 222 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", |
| 223 edgeArrayName, i, fragmentPos, fragmentPos); | 225 edgeArrayName, i, fragmentPos, fragmentPos); |
| 224 if (GrProcessorEdgeTypeIsAA(cpe.getEdgeType())) { | 226 if (GrProcessorEdgeTypeIsAA(cpe.getEdgeType())) { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 } | 372 } |
| 371 | 373 |
| 372 GrFragmentProcessor* fp; | 374 GrFragmentProcessor* fp; |
| 373 do { | 375 do { |
| 374 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 376 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
| 375 random->nextULessThan(kGrProcessorEdgeTy
peCnt)); | 377 random->nextULessThan(kGrProcessorEdgeTy
peCnt)); |
| 376 fp = GrConvexPolyEffect::Create(edgeType, count, edges); | 378 fp = GrConvexPolyEffect::Create(edgeType, count, edges); |
| 377 } while (NULL == fp); | 379 } while (NULL == fp); |
| 378 return fp; | 380 return fp; |
| 379 } | 381 } |
| OLD | NEW |