| 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 "GrPathProcessor.h" | 8 #include "GrPathProcessor.h" |
| 9 | 9 |
| 10 #include "gl/GrGLGpu.h" | 10 #include "gl/GrGLGpu.h" |
| 11 #include "glsl/GrGLSLCaps.h" | 11 #include "glsl/GrGLSLCaps.h" |
| 12 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 12 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 13 #include "glsl/GrGLSLProcessorTypes.h" | 13 #include "glsl/GrGLSLProcessorTypes.h" |
| 14 #include "glsl/GrGLSLProgramBuilder.h" | 14 #include "glsl/GrGLSLProgramBuilder.h" |
| 15 #include "glsl/GrGLSLVarying.h" |
| 15 | 16 |
| 16 class GrGLPathProcessor : public GrGLSLPrimitiveProcessor { | 17 class GrGLPathProcessor : public GrGLSLPrimitiveProcessor { |
| 17 public: | 18 public: |
| 18 GrGLPathProcessor() : fColor(GrColor_ILLEGAL) {} | 19 GrGLPathProcessor() : fColor(GrColor_ILLEGAL) {} |
| 19 | 20 |
| 20 static void GenKey(const GrPathProcessor& pathProc, | 21 static void GenKey(const GrPathProcessor& pathProc, |
| 21 const GrGLSLCaps&, | 22 const GrGLSLCaps&, |
| 22 GrProcessorKeyBuilder* b) { | 23 GrProcessorKeyBuilder* b) { |
| 23 b->add32(SkToInt(pathProc.opts().readsColor()) | | 24 b->add32(SkToInt(pathProc.opts().readsColor()) | |
| 24 SkToInt(pathProc.opts().readsCoverage()) << 16); | 25 SkToInt(pathProc.opts().readsCoverage()) << 16); |
| 25 } | 26 } |
| 26 | 27 |
| 27 void emitCode(EmitArgs& args) override { | 28 void emitCode(EmitArgs& args) override { |
| 28 GrGLSLGPBuilder* pb = args.fPB; | 29 GrGLSLGPBuilder* pb = args.fPB; |
| 29 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 30 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 30 const GrPathProcessor& pathProc = args.fGP.cast<GrPathProcessor>(); | 31 const GrPathProcessor& pathProc = args.fGP.cast<GrPathProcessor>(); |
| 31 | 32 |
| 32 // emit transforms | 33 // emit transforms |
| 33 this->emitTransforms(args.fPB, args.fTransformsIn, args.fTransformsOut); | 34 this->emitTransforms(args.fVaryingHandler, args.fTransformsIn, args.fTra
nsformsOut); |
| 34 | 35 |
| 35 // Setup uniform color | 36 // Setup uniform color |
| 36 if (pathProc.opts().readsColor()) { | 37 if (pathProc.opts().readsColor()) { |
| 37 const char* stagedLocalVarName; | 38 const char* stagedLocalVarName; |
| 38 fColorUniform = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visib
ility, | 39 fColorUniform = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visib
ility, |
| 39 kVec4f_GrSLType, | 40 kVec4f_GrSLType, |
| 40 kDefault_GrSLPrecision, | 41 kDefault_GrSLPrecision, |
| 41 "Color", | 42 "Color", |
| 42 &stagedLocalVarName); | 43 &stagedLocalVarName); |
| 43 fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, stagedLocalV
arName); | 44 fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, stagedLocalV
arName); |
| 44 } | 45 } |
| 45 | 46 |
| 46 // setup constant solid coverage | 47 // setup constant solid coverage |
| 47 if (pathProc.opts().readsCoverage()) { | 48 if (pathProc.opts().readsCoverage()) { |
| 48 fragBuilder->codeAppendf("%s = vec4(1);", args.fOutputCoverage); | 49 fragBuilder->codeAppendf("%s = vec4(1);", args.fOutputCoverage); |
| 49 } | 50 } |
| 50 } | 51 } |
| 51 | 52 |
| 52 void emitTransforms(GrGLSLGPBuilder* pb, const TransformsIn& tin, Transforms
Out* tout) { | 53 void emitTransforms(GrGLSLVaryingHandler* varyingHandler, |
| 54 const TransformsIn& tin, |
| 55 TransformsOut* tout) { |
| 53 tout->push_back_n(tin.count()); | 56 tout->push_back_n(tin.count()); |
| 54 fInstalledTransforms.push_back_n(tin.count()); | 57 fInstalledTransforms.push_back_n(tin.count()); |
| 55 for (int i = 0; i < tin.count(); i++) { | 58 for (int i = 0; i < tin.count(); i++) { |
| 56 const ProcCoords& coordTransforms = tin[i]; | 59 const ProcCoords& coordTransforms = tin[i]; |
| 57 fInstalledTransforms[i].push_back_n(coordTransforms.count()); | 60 fInstalledTransforms[i].push_back_n(coordTransforms.count()); |
| 58 for (int t = 0; t < coordTransforms.count(); t++) { | 61 for (int t = 0; t < coordTransforms.count(); t++) { |
| 59 GrSLType varyingType = | 62 GrSLType varyingType = |
| 60 coordTransforms[t]->getMatrix().hasPerspective() ? kVec3
f_GrSLType : | 63 coordTransforms[t]->getMatrix().hasPerspective() ? kVec3
f_GrSLType : |
| 61 kVec2
f_GrSLType; | 64 kVec2
f_GrSLType; |
| 62 | 65 |
| 63 SkString strVaryingName("MatrixCoord"); | 66 SkString strVaryingName("MatrixCoord"); |
| 64 strVaryingName.appendf("_%i_%i", i, t); | 67 strVaryingName.appendf("_%i_%i", i, t); |
| 65 GrGLSLVertToFrag v(varyingType); | 68 GrGLSLVertToFrag v(varyingType); |
| 69 GrGLVaryingHandler* glVaryingHandler = (GrGLVaryingHandler*) var
yingHandler; |
| 66 fInstalledTransforms[i][t].fHandle = | 70 fInstalledTransforms[i][t].fHandle = |
| 67 pb->addSeparableVarying(strVaryingName.c_str(), &v).toIn
dex(); | 71 glVaryingHandler->addPathProcessingVarying(strVaryingNam
e.c_str(), |
| 72 &v).toIndex()
; |
| 68 fInstalledTransforms[i][t].fType = varyingType; | 73 fInstalledTransforms[i][t].fType = varyingType; |
| 69 | 74 |
| 70 SkNEW_APPEND_TO_TARRAY(&(*tout)[i], GrGLSLTransformedCoords, | 75 SkNEW_APPEND_TO_TARRAY(&(*tout)[i], GrGLSLTransformedCoords, |
| 71 (SkString(v.fsIn()), varyingType)); | 76 (SkString(v.fsIn()), varyingType)); |
| 72 } | 77 } |
| 73 } | 78 } |
| 74 } | 79 } |
| 75 | 80 |
| 76 void setData(const GrGLSLProgramDataManager& pd, | 81 void setData(const GrGLSLProgramDataManager& pd, |
| 77 const GrPrimitiveProcessor& primProc) override { | 82 const GrPrimitiveProcessor& primProc) override { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 133 |
| 129 void GrPathProcessor::getGLSLProcessorKey(const GrGLSLCaps& caps, | 134 void GrPathProcessor::getGLSLProcessorKey(const GrGLSLCaps& caps, |
| 130 GrProcessorKeyBuilder* b) const { | 135 GrProcessorKeyBuilder* b) const { |
| 131 GrGLPathProcessor::GenKey(*this, caps, b); | 136 GrGLPathProcessor::GenKey(*this, caps, b); |
| 132 } | 137 } |
| 133 | 138 |
| 134 GrGLSLPrimitiveProcessor* GrPathProcessor::createGLSLInstance(const GrGLSLCaps&
caps) const { | 139 GrGLSLPrimitiveProcessor* GrPathProcessor::createGLSLInstance(const GrGLSLCaps&
caps) const { |
| 135 SkASSERT(caps.pathRenderingSupport()); | 140 SkASSERT(caps.pathRenderingSupport()); |
| 136 return new GrGLPathProcessor(); | 141 return new GrGLPathProcessor(); |
| 137 } | 142 } |
| OLD | NEW |