| 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 "SkPathPriv.h" | 10 #include "SkPathPriv.h" |
| 11 #include "glsl/GrGLSLFragmentProcessor.h" | 11 #include "glsl/GrGLSLFragmentProcessor.h" |
| 12 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 12 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 13 #include "glsl/GrGLSLProgramBuilder.h" | |
| 14 #include "glsl/GrGLSLProgramDataManager.h" | 13 #include "glsl/GrGLSLProgramDataManager.h" |
| 14 #include "glsl/GrGLSLUniformHandler.h" |
| 15 | 15 |
| 16 ////////////////////////////////////////////////////////////////////////////// | 16 ////////////////////////////////////////////////////////////////////////////// |
| 17 class AARectEffect : public GrFragmentProcessor { | 17 class AARectEffect : public GrFragmentProcessor { |
| 18 public: | 18 public: |
| 19 const SkRect& getRect() const { return fRect; } | 19 const SkRect& getRect() const { return fRect; } |
| 20 | 20 |
| 21 static GrFragmentProcessor* Create(GrPrimitiveEdgeType edgeType, const SkRec
t& rect) { | 21 static GrFragmentProcessor* Create(GrPrimitiveEdgeType edgeType, const SkRec
t& rect) { |
| 22 return new AARectEffect(edgeType, rect); | 22 return new AARectEffect(edgeType, rect); |
| 23 } | 23 } |
| 24 | 24 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 GLAARectEffect::GLAARectEffect(const GrProcessor& effect) { | 99 GLAARectEffect::GLAARectEffect(const GrProcessor& effect) { |
| 100 fPrevRect.fLeft = SK_ScalarNaN; | 100 fPrevRect.fLeft = SK_ScalarNaN; |
| 101 } | 101 } |
| 102 | 102 |
| 103 void GLAARectEffect::emitCode(EmitArgs& args) { | 103 void GLAARectEffect::emitCode(EmitArgs& args) { |
| 104 const AARectEffect& aare = args.fFp.cast<AARectEffect>(); | 104 const AARectEffect& aare = args.fFp.cast<AARectEffect>(); |
| 105 const char *rectName; | 105 const char *rectName; |
| 106 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), | 106 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), |
| 107 // respectively. | 107 // respectively. |
| 108 fRectUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Vis
ibility, | 108 fRectUniform = args.fUniformHandler->addUniform(GrGLSLUniformHandler::kFragm
ent_Visibility, |
| 109 kVec4f_GrSLType, | 109 kVec4f_GrSLType, |
| 110 kDefault_GrSLPrecision, | 110 kDefault_GrSLPrecision, |
| 111 "rect", | 111 "rect", |
| 112 &rectName); | 112 &rectName); |
| 113 | 113 |
| 114 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 114 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 115 const char* fragmentPos = fragBuilder->fragmentPosition(); | 115 const char* fragmentPos = fragBuilder->fragmentPosition(); |
| 116 if (GrProcessorEdgeTypeIsAA(aare.getEdgeType())) { | 116 if (GrProcessorEdgeTypeIsAA(aare.getEdgeType())) { |
| 117 // The amount of coverage removed in x and y by the edges is computed as
a pair of negative | 117 // The amount of coverage removed in x and y by the edges is computed as
a pair of negative |
| 118 // numbers, xSub and ySub. | 118 // numbers, xSub and ySub. |
| 119 fragBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); | 119 fragBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); |
| 120 fragBuilder->codeAppendf("\t\txSub = min(%s.x - %s.x, 0.0);\n", fragment
Pos, rectName); | 120 fragBuilder->codeAppendf("\t\txSub = min(%s.x - %s.x, 0.0);\n", fragment
Pos, rectName); |
| 121 fragBuilder->codeAppendf("\t\txSub += min(%s.z - %s.x, 0.0);\n", rectNam
e, fragmentPos); | 121 fragBuilder->codeAppendf("\t\txSub += min(%s.z - %s.x, 0.0);\n", rectNam
e, fragmentPos); |
| 122 fragBuilder->codeAppendf("\t\tySub = min(%s.y - %s.y, 0.0);\n", fragment
Pos, rectName); | 122 fragBuilder->codeAppendf("\t\tySub = min(%s.y - %s.y, 0.0);\n", fragment
Pos, rectName); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 }; | 184 }; |
| 185 | 185 |
| 186 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrProcessor&) { | 186 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrProcessor&) { |
| 187 fPrevEdges[0] = SK_ScalarNaN; | 187 fPrevEdges[0] = SK_ScalarNaN; |
| 188 } | 188 } |
| 189 | 189 |
| 190 void GrGLConvexPolyEffect::emitCode(EmitArgs& args) { | 190 void GrGLConvexPolyEffect::emitCode(EmitArgs& args) { |
| 191 const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>(); | 191 const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>(); |
| 192 | 192 |
| 193 const char *edgeArrayName; | 193 const char *edgeArrayName; |
| 194 fEdgeUniform = args.fBuilder->addUniformArray(GrGLSLProgramBuilder::kFragmen
t_Visibility, | 194 fEdgeUniform = args.fUniformHandler->addUniformArray(GrGLSLUniformHandler::k
Fragment_Visibility, |
| 195 kVec3f_GrSLType, | 195 kVec3f_GrSLType, |
| 196 kDefault_GrSLPrecision, | 196 kDefault_GrSLPrecision, |
| 197 "edges", | 197 "edges", |
| 198 cpe.getEdgeCount(), | 198 cpe.getEdgeCount(), |
| 199 &edgeArrayName); | 199 &edgeArrayName); |
| 200 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 200 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 201 fragBuilder->codeAppend("\t\tfloat alpha = 1.0;\n"); | 201 fragBuilder->codeAppend("\t\tfloat alpha = 1.0;\n"); |
| 202 fragBuilder->codeAppend("\t\tfloat edge;\n"); | 202 fragBuilder->codeAppend("\t\tfloat edge;\n"); |
| 203 const char* fragmentPos = fragBuilder->fragmentPosition(); | 203 const char* fragmentPos = fragBuilder->fragmentPosition(); |
| 204 for (int i = 0; i < cpe.getEdgeCount(); ++i) { | 204 for (int i = 0; i < cpe.getEdgeCount(); ++i) { |
| 205 fragBuilder->codeAppendf("\t\tedge = dot(%s[%d], vec3(%s.x, %s.y, 1));\n
", | 205 fragBuilder->codeAppendf("\t\tedge = dot(%s[%d], vec3(%s.x, %s.y, 1));\n
", |
| 206 edgeArrayName, i, fragmentPos, fragmentPos); | 206 edgeArrayName, i, fragmentPos, fragmentPos); |
| 207 if (GrProcessorEdgeTypeIsAA(cpe.getEdgeType())) { | 207 if (GrProcessorEdgeTypeIsAA(cpe.getEdgeType())) { |
| 208 fragBuilder->codeAppend("\t\tedge = clamp(edge, 0.0, 1.0);\n"); | 208 fragBuilder->codeAppend("\t\tedge = clamp(edge, 0.0, 1.0);\n"); |
| 209 } else { | 209 } else { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 } | 346 } |
| 347 | 347 |
| 348 GrFragmentProcessor* fp; | 348 GrFragmentProcessor* fp; |
| 349 do { | 349 do { |
| 350 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 350 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
| 351 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); | 351 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); |
| 352 fp = GrConvexPolyEffect::Create(edgeType, count, edges); | 352 fp = GrConvexPolyEffect::Create(edgeType, count, edges); |
| 353 } while (nullptr == fp); | 353 } while (nullptr == fp); |
| 354 return fp; | 354 return fp; |
| 355 } | 355 } |
| OLD | NEW |