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 | 15 |
16 class GrGLPathProcessor : public GrGLSLPrimitiveProcessor { | 16 class GrGLPathProcessor : public GrGLSLPrimitiveProcessor { |
17 public: | 17 public: |
18 GrGLPathProcessor() : fColor(GrColor_ILLEGAL) {} | 18 GrGLPathProcessor() : fColor(GrColor_ILLEGAL) {} |
19 | 19 |
20 static void GenKey(const GrPathProcessor& pathProc, | 20 static void GenKey(const GrPathProcessor& pathProc, |
21 const GrGLSLCaps&, | 21 const GrGLSLCaps&, |
22 GrProcessorKeyBuilder* b) { | 22 GrProcessorKeyBuilder* b) { |
23 b->add32(SkToInt(pathProc.opts().readsColor()) | | 23 b->add32(SkToInt(pathProc.opts().readsColor()) | |
24 SkToInt(pathProc.opts().readsCoverage()) << 16); | 24 SkToInt(pathProc.opts().readsCoverage()) << 16); |
25 } | 25 } |
26 | 26 |
27 void emitCode(EmitArgs& args) override { | 27 void emitCode(EmitArgs& args) override { |
28 GrGLSLGPBuilder* pb = args.fPB; | 28 GrGLSLGPBuilder* pb = args.fPB; |
29 GrGLSLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder(); | 29 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
30 const GrPathProcessor& pathProc = args.fGP.cast<GrPathProcessor>(); | 30 const GrPathProcessor& pathProc = args.fGP.cast<GrPathProcessor>(); |
31 | 31 |
32 // emit transforms | 32 // emit transforms |
33 this->emitTransforms(args.fPB, args.fTransformsIn, args.fTransformsOut); | 33 this->emitTransforms(args.fPB, args.fTransformsIn, args.fTransformsOut); |
34 | 34 |
35 // Setup uniform color | 35 // Setup uniform color |
36 if (pathProc.opts().readsColor()) { | 36 if (pathProc.opts().readsColor()) { |
37 const char* stagedLocalVarName; | 37 const char* stagedLocalVarName; |
38 fColorUniform = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visib
ility, | 38 fColorUniform = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visib
ility, |
39 kVec4f_GrSLType, | 39 kVec4f_GrSLType, |
40 kDefault_GrSLPrecision, | 40 kDefault_GrSLPrecision, |
41 "Color", | 41 "Color", |
42 &stagedLocalVarName); | 42 &stagedLocalVarName); |
43 fs->codeAppendf("%s = %s;", args.fOutputColor, stagedLocalVarName); | 43 fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, stagedLocalV
arName); |
44 } | 44 } |
45 | 45 |
46 // setup constant solid coverage | 46 // setup constant solid coverage |
47 if (pathProc.opts().readsCoverage()) { | 47 if (pathProc.opts().readsCoverage()) { |
48 fs->codeAppendf("%s = vec4(1);", args.fOutputCoverage); | 48 fragBuilder->codeAppendf("%s = vec4(1);", args.fOutputCoverage); |
49 } | 49 } |
50 } | 50 } |
51 | 51 |
52 void emitTransforms(GrGLSLGPBuilder* pb, const TransformsIn& tin, Transforms
Out* tout) { | 52 void emitTransforms(GrGLSLGPBuilder* pb, const TransformsIn& tin, Transforms
Out* tout) { |
53 tout->push_back_n(tin.count()); | 53 tout->push_back_n(tin.count()); |
54 fInstalledTransforms.push_back_n(tin.count()); | 54 fInstalledTransforms.push_back_n(tin.count()); |
55 for (int i = 0; i < tin.count(); i++) { | 55 for (int i = 0; i < tin.count(); i++) { |
56 const ProcCoords& coordTransforms = tin[i]; | 56 const ProcCoords& coordTransforms = tin[i]; |
57 fInstalledTransforms[i].push_back_n(coordTransforms.count()); | 57 fInstalledTransforms[i].push_back_n(coordTransforms.count()); |
58 for (int t = 0; t < coordTransforms.count(); t++) { | 58 for (int t = 0; t < coordTransforms.count(); t++) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 128 |
129 void GrPathProcessor::getGLSLProcessorKey(const GrGLSLCaps& caps, | 129 void GrPathProcessor::getGLSLProcessorKey(const GrGLSLCaps& caps, |
130 GrProcessorKeyBuilder* b) const { | 130 GrProcessorKeyBuilder* b) const { |
131 GrGLPathProcessor::GenKey(*this, caps, b); | 131 GrGLPathProcessor::GenKey(*this, caps, b); |
132 } | 132 } |
133 | 133 |
134 GrGLSLPrimitiveProcessor* GrPathProcessor::createGLSLInstance(const GrGLSLCaps&
caps) const { | 134 GrGLSLPrimitiveProcessor* GrPathProcessor::createGLSLInstance(const GrGLSLCaps&
caps) const { |
135 SkASSERT(caps.pathRenderingSupport()); | 135 SkASSERT(caps.pathRenderingSupport()); |
136 return new GrGLPathProcessor(); | 136 return new GrGLPathProcessor(); |
137 } | 137 } |
OLD | NEW |