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/GrGLSLProcessorTypes.h" | 12 #include "glsl/GrGLSLProcessorTypes.h" |
13 | 13 |
14 class GrGLPathProcessor : public GrGLPrimitiveProcessor { | 14 class GrGLPathProcessor : public GrGLPrimitiveProcessor { |
15 public: | 15 public: |
16 GrGLPathProcessor() : fColor(GrColor_ILLEGAL) {} | 16 GrGLPathProcessor() : fColor(GrColor_ILLEGAL) {} |
17 | 17 |
18 static void GenKey(const GrPathProcessor& pathProc, | 18 static void GenKey(const GrPathProcessor& pathProc, |
19 const GrGLSLCaps&, | 19 const GrGLSLCaps&, |
20 GrProcessorKeyBuilder* b) { | 20 GrProcessorKeyBuilder* b) { |
21 b->add32(SkToInt(pathProc.opts().readsColor()) | | 21 b->add32(SkToInt(pathProc.opts().readsColor()) | |
22 SkToInt(pathProc.opts().readsCoverage()) << 16); | 22 SkToInt(pathProc.opts().readsCoverage()) << 16); |
23 } | 23 } |
24 | 24 |
25 void emitCode(EmitArgs& args) override { | 25 void emitCode(EmitArgs& args) override { |
26 GrGLGPBuilder* pb = args.fPB; | 26 GrGLSLGPBuilder* pb = args.fPB; |
27 GrGLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder(); | 27 GrGLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder(); |
28 const GrPathProcessor& pathProc = args.fGP.cast<GrPathProcessor>(); | 28 const GrPathProcessor& pathProc = args.fGP.cast<GrPathProcessor>(); |
29 | 29 |
30 // emit transforms | 30 // emit transforms |
31 this->emitTransforms(args.fPB, args.fTransformsIn, args.fTransformsOut); | 31 this->emitTransforms(args.fPB, args.fTransformsIn, args.fTransformsOut); |
32 | 32 |
33 // Setup uniform color | 33 // Setup uniform color |
34 if (pathProc.opts().readsColor()) { | 34 if (pathProc.opts().readsColor()) { |
35 const char* stagedLocalVarName; | 35 const char* stagedLocalVarName; |
36 fColorUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Visibil
ity, | 36 fColorUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Visibil
ity, |
37 kVec4f_GrSLType, | 37 kVec4f_GrSLType, |
38 kDefault_GrSLPrecision, | 38 kDefault_GrSLPrecision, |
39 "Color", | 39 "Color", |
40 &stagedLocalVarName); | 40 &stagedLocalVarName); |
41 fs->codeAppendf("%s = %s;", args.fOutputColor, stagedLocalVarName); | 41 fs->codeAppendf("%s = %s;", args.fOutputColor, stagedLocalVarName); |
42 } | 42 } |
43 | 43 |
44 // setup constant solid coverage | 44 // setup constant solid coverage |
45 if (pathProc.opts().readsCoverage()) { | 45 if (pathProc.opts().readsCoverage()) { |
46 fs->codeAppendf("%s = vec4(1);", args.fOutputCoverage); | 46 fs->codeAppendf("%s = vec4(1);", args.fOutputCoverage); |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 void emitTransforms(GrGLGPBuilder* pb, const TransformsIn& tin, TransformsOu
t* tout) { | 50 void emitTransforms(GrGLSLGPBuilder* pb, const TransformsIn& tin, Transforms
Out* tout) { |
51 tout->push_back_n(tin.count()); | 51 tout->push_back_n(tin.count()); |
52 fInstalledTransforms.push_back_n(tin.count()); | 52 fInstalledTransforms.push_back_n(tin.count()); |
53 for (int i = 0; i < tin.count(); i++) { | 53 for (int i = 0; i < tin.count(); i++) { |
54 const ProcCoords& coordTransforms = tin[i]; | 54 const ProcCoords& coordTransforms = tin[i]; |
55 fInstalledTransforms[i].push_back_n(coordTransforms.count()); | 55 fInstalledTransforms[i].push_back_n(coordTransforms.count()); |
56 for (int t = 0; t < coordTransforms.count(); t++) { | 56 for (int t = 0; t < coordTransforms.count(); t++) { |
57 GrSLType varyingType = | 57 GrSLType varyingType = |
58 coordTransforms[t]->getMatrix().hasPerspective() ? kVec3
f_GrSLType : | 58 coordTransforms[t]->getMatrix().hasPerspective() ? kVec3
f_GrSLType : |
59 kVec2
f_GrSLType; | 59 kVec2
f_GrSLType; |
60 | 60 |
61 SkString strVaryingName("MatrixCoord"); | 61 SkString strVaryingName("MatrixCoord"); |
62 strVaryingName.appendf("_%i_%i", i, t); | 62 strVaryingName.appendf("_%i_%i", i, t); |
63 GrGLVertToFrag v(varyingType); | 63 GrGLSLVertToFrag v(varyingType); |
64 fInstalledTransforms[i][t].fHandle = | 64 fInstalledTransforms[i][t].fHandle = |
65 pb->addSeparableVarying(strVaryingName.c_str(), &v).toIn
dex(); | 65 pb->addSeparableVarying(strVaryingName.c_str(), &v).toIn
dex(); |
66 fInstalledTransforms[i][t].fType = varyingType; | 66 fInstalledTransforms[i][t].fType = varyingType; |
67 | 67 |
68 SkNEW_APPEND_TO_TARRAY(&(*tout)[i], GrGLSLTransformedCoords, | 68 SkNEW_APPEND_TO_TARRAY(&(*tout)[i], GrGLSLTransformedCoords, |
69 (SkString(v.fsIn()), varyingType)); | 69 (SkString(v.fsIn()), varyingType)); |
70 } | 70 } |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 126 |
127 void GrPathProcessor::getGLProcessorKey(const GrGLSLCaps& caps, | 127 void GrPathProcessor::getGLProcessorKey(const GrGLSLCaps& caps, |
128 GrProcessorKeyBuilder* b) const { | 128 GrProcessorKeyBuilder* b) const { |
129 GrGLPathProcessor::GenKey(*this, caps, b); | 129 GrGLPathProcessor::GenKey(*this, caps, b); |
130 } | 130 } |
131 | 131 |
132 GrGLPrimitiveProcessor* GrPathProcessor::createGLInstance(const GrGLSLCaps& caps
) const { | 132 GrGLPrimitiveProcessor* GrPathProcessor::createGLInstance(const GrGLSLCaps& caps
) const { |
133 SkASSERT(caps.pathRenderingSupport()); | 133 SkASSERT(caps.pathRenderingSupport()); |
134 return new GrGLPathProcessor(); | 134 return new GrGLPathProcessor(); |
135 } | 135 } |
OLD | NEW |