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 #ifndef GrGLGeometryProcessor_DEFINED | 8 #ifndef GrGLGeometryProcessor_DEFINED |
9 #define GrGLGeometryProcessor_DEFINED | 9 #define GrGLGeometryProcessor_DEFINED |
10 | 10 |
11 #include "GrGLProcessor.h" | 11 #include "GrGLProcessor.h" |
12 | 12 |
13 class GrBatchTracker; | 13 class GrBatchTracker; |
14 class GrFragmentProcessor; | |
14 class GrGLGPBuilder; | 15 class GrGLGPBuilder; |
15 | 16 |
16 /** | 17 class GrGLPrimitiveProcessor { |
17 * If a GL effect needs a GrGLFullShaderBuilder* object to emit vertex code, the n it must inherit | |
18 * from this class. Since paths don't have vertices, this class is only meant to be used internally | |
19 * by skia, for special cases. | |
20 */ | |
21 class GrGLGeometryProcessor { | |
22 public: | 18 public: |
23 GrGLGeometryProcessor() : fViewMatrixName(NULL) { fViewMatrix = SkMatrix::In validMatrix(); } | 19 GrGLPrimitiveProcessor() : fViewMatrixName(NULL) { fViewMatrix = SkMatrix::I nvalidMatrix(); } |
24 virtual ~GrGLGeometryProcessor() {} | 20 virtual ~GrGLPrimitiveProcessor() {} |
25 | 21 |
26 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 22 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
27 typedef GrGLProcessor::TextureSamplerArray TextureSamplerArray; | 23 typedef GrGLProcessor::TextureSamplerArray TextureSamplerArray; |
28 | 24 |
25 typedef SkSTArray<2, const GrCoordTransform*, true> ProcCoords; | |
26 typedef SkSTArray<8, ProcCoords> TransformsIn; | |
27 typedef SkSTArray<8, GrGLProcessor::TransformedCoordsArray> TransformsOut; | |
28 | |
29 struct EmitArgs { | 29 struct EmitArgs { |
30 EmitArgs(GrGLGPBuilder* pb, | 30 EmitArgs(GrGLGPBuilder* pb, |
31 const GrPrimitiveProcessor& gp, | 31 const GrPrimitiveProcessor& gp, |
32 const GrBatchTracker& bt, | 32 const GrBatchTracker& bt, |
33 const char* outputColor, | 33 const char* outputColor, |
34 const char* outputCoverage, | 34 const char* outputCoverage, |
35 const TextureSamplerArray& samplers) | 35 const TextureSamplerArray& samplers, |
36 const TransformsIn& transformsIn, | |
37 TransformsOut* transformsOut) | |
36 : fPB(pb) | 38 : fPB(pb) |
37 , fGP(gp) | 39 , fGP(gp) |
38 , fBT(bt) | 40 , fBT(bt) |
39 , fOutputColor(outputColor) | 41 , fOutputColor(outputColor) |
40 , fOutputCoverage(outputCoverage) | 42 , fOutputCoverage(outputCoverage) |
41 , fSamplers(samplers) {} | 43 , fSamplers(samplers) |
44 , fTransformsIn(transformsIn) | |
45 , fTransformsOut(transformsOut) {} | |
42 GrGLGPBuilder* fPB; | 46 GrGLGPBuilder* fPB; |
43 const GrPrimitiveProcessor& fGP; | 47 const GrPrimitiveProcessor& fGP; |
44 const GrBatchTracker& fBT; | 48 const GrBatchTracker& fBT; |
45 const char* fOutputColor; | 49 const char* fOutputColor; |
46 const char* fOutputCoverage; | 50 const char* fOutputCoverage; |
47 const TextureSamplerArray& fSamplers; | 51 const TextureSamplerArray& fSamplers; |
52 const TransformsIn& fTransformsIn; | |
53 TransformsOut* fTransformsOut; | |
48 }; | 54 }; |
49 | 55 |
50 /** | 56 /** |
51 * This is similar to emitCode() in the base class, except it takes a full s hader builder. | 57 * This is similar to emitCode() in the base class, except it takes a full s hader builder. |
52 * This allows the effect subclass to emit vertex code. | 58 * This allows the effect subclass to emit vertex code. |
53 */ | 59 */ |
54 virtual void emitCode(const EmitArgs&) = 0; | 60 virtual void emitCode(EmitArgs&) = 0; |
55 | 61 |
56 /** A GrGLGeometryProcessor instance can be reused with any GrGLGeometryProc essor that produces | 62 |
57 the same stage key; this function reads data from a GrGLGeometryProcesso r and uploads any | 63 /** A GrGLPrimitiveProcessor instance can be reused with any GrGLPrimitivePr ocessor that |
58 uniform variables required by the shaders created in emitCode(). The Gr GeometryProcessor | 64 produces the same stage key; this function reads data from a GrGLPrimiti veProcessor and |
59 parameter is guaranteed to be of the same type that created this GrGLGeo metryProcessor and | 65 uploads any uniform variables required by the shaders created in emitCo de(). The |
60 to have an identical processor key as the one that created this GrGLGeom etryProcessor. */ | 66 GrPrimitiveProcessor parameter is guaranteed to be of the same type that created this |
67 GrGLPrimitiveProcessor and to have an identical processor key as the one that created this | |
68 GrGLPrimitiveProcessor. */ | |
61 virtual void setData(const GrGLProgramDataManager&, | 69 virtual void setData(const GrGLProgramDataManager&, |
62 const GrPrimitiveProcessor&, | 70 const GrPrimitiveProcessor&, |
63 const GrBatchTracker&) = 0; | 71 const GrBatchTracker&) = 0; |
64 | 72 |
73 static SkMatrix GetTransformMatrix(const SkMatrix& localMatrix, const GrCoor dTransform&); | |
74 | |
65 protected: | 75 protected: |
66 /** a helper which can setup vertex, constant, or uniform color depending on inputType. | 76 /** a helper which can setup vertex, constant, or uniform color depending on inputType. |
67 * This function will only do the minimum required to emit the correct shad er code. If | 77 * This function will only do the minimum required to emit the correct shad er code. If |
68 * inputType == attribute, then colorAttr must not be NULL. Likewise, if i nputType == Uniform | 78 * inputType == attribute, then colorAttr must not be NULL. Likewise, if i nputType == Uniform |
69 * then colorUniform must not be NULL. | 79 * then colorUniform must not be NULL. |
70 */ | 80 */ |
71 void setupColorPassThrough(GrGLGPBuilder* pb, | 81 void setupColorPassThrough(GrGLGPBuilder* pb, |
72 GrGPInput inputType, | 82 GrGPInput inputType, |
73 const char* inputName, | 83 const char* inputName, |
74 const GrGeometryProcessor::GrAttribute* colorAttr , | 84 const GrGeometryProcessor::GrAttribute* colorAttr , |
75 UniformHandle* colorUniform); | 85 UniformHandle* colorUniform); |
76 | 86 |
77 const char* uViewM() const { return fViewMatrixName; } | 87 const char* uViewM() const { return fViewMatrixName; } |
78 | 88 |
79 /** a helper function to setup the uniform handle for the uniform view matri x */ | 89 /** a helper function to setup the uniform handle for the uniform view matri x */ |
80 void addUniformViewMatrix(GrGLGPBuilder*); | 90 void addUniformViewMatrix(GrGLGPBuilder*); |
81 | 91 |
82 | 92 |
83 /** a helper function to upload a uniform viewmatrix. | 93 /** a helper function to upload a uniform viewmatrix. |
84 * TODO we can remove this function when we have deferred geometry in place | 94 * TODO we can remove this function when we have deferred geometry in place |
85 */ | 95 */ |
86 void setUniformViewMatrix(const GrGLProgramDataManager&, | 96 void setUniformViewMatrix(const GrGLProgramDataManager&, |
87 const SkMatrix& viewMatrix); | 97 const SkMatrix& viewMatrix); |
88 | 98 |
99 class ShaderVarHandle { | |
100 public: | |
101 bool isValid() const { return fHandle > -1; } | |
102 ShaderVarHandle() : fHandle(-1) {} | |
103 ShaderVarHandle(int value) : fHandle(value) { SkASSERT(this->isValid()); } | |
104 int handle() const { SkASSERT(this->isValid()); return fHandle; } | |
105 UniformHandle convertToUniformHandle() { | |
106 SkASSERT(this->isValid()); | |
107 return GrGLProgramDataManager::UniformHandle::CreateFromUniformIndex (fHandle); | |
108 } | |
109 | |
110 private: | |
111 int fHandle; | |
112 }; | |
113 | |
114 struct Transform { | |
115 Transform() : fType(kVoid_GrSLType) { fCurrentValue = SkMatrix::InvalidM atrix(); } | |
116 ShaderVarHandle fHandle; | |
117 SkMatrix fCurrentValue; | |
118 GrSLType fType; | |
119 }; | |
120 | |
121 SkSTArray<8, SkSTArray<2, Transform, true> > fInstalledTransforms; | |
122 | |
89 private: | 123 private: |
90 UniformHandle fViewMatrixUniform; | 124 UniformHandle fViewMatrixUniform; |
91 SkMatrix fViewMatrix; | 125 SkMatrix fViewMatrix; |
92 const char* fViewMatrixName; | 126 const char* fViewMatrixName; |
127 }; | |
93 | 128 |
94 typedef GrGLProcessor INHERITED; | 129 class GrGLPathRendering; |
130 /** | |
131 * If a GL effect needs a GrGLFullShaderBuilder* object to emit vertex code, the n it must inherit | |
132 * from this class. Since paths don't have vertices, this class is only meant to be used internally | |
133 * by skia, for special cases. | |
134 */ | |
135 class GrGLGeometryProcessor : public GrGLPrimitiveProcessor { | |
136 public: | |
137 /* Any general emit code goes in the base class emitCode. Subclasses overri de onEmitCode */ | |
138 void emitCode(EmitArgs&) SK_OVERRIDE; | |
139 virtual void onEmitCode(EmitArgs&) = 0; | |
bsalomon
2015/01/13 21:55:13
Shoulnd't onEmitCode be private?
| |
140 | |
141 void setTransformData(const GrPrimitiveProcessor*, | |
142 const GrGLProgramDataManager&, | |
143 int index, | |
144 const SkTArray<const GrCoordTransform*, true>& transfo rms); | |
145 | |
146 protected: | |
147 const char* position() const { return "pos3"; } | |
148 | |
149 // Many GrGeometryProcessors do not need explicit local coords | |
150 void emitTransforms(GrGLGPBuilder* gp, | |
151 const char* position, | |
152 const SkMatrix& localMatrix, | |
153 const TransformsIn& tin, | |
154 TransformsOut* tout) { | |
155 this->emitTransforms(gp, position, position, localMatrix, tin, tout); | |
156 } | |
157 | |
158 void emitTransforms(GrGLGPBuilder*, | |
159 const char* position, | |
160 const char* localCoords, | |
161 const SkMatrix& localMatrix, | |
162 const TransformsIn&, | |
163 TransformsOut*); | |
164 | |
165 private: | |
166 typedef GrGLPrimitiveProcessor INHERITED; | |
167 }; | |
168 | |
169 class GrGLGpu; | |
170 | |
171 class GrGLPathProcessor : public GrGLPrimitiveProcessor { | |
172 public: | |
173 GrGLPathProcessor(const GrPathProcessor&, const GrBatchTracker&); | |
174 | |
175 static void GenKey(const GrPathProcessor&, | |
176 const GrBatchTracker& bt, | |
177 const GrGLCaps&, | |
178 GrProcessorKeyBuilder* b); | |
179 | |
180 void emitCode(EmitArgs&) SK_OVERRIDE; | |
181 | |
182 virtual void emitTransforms(GrGLGPBuilder*, const TransformsIn&, TransformsO ut*) = 0; | |
183 | |
184 virtual void resolveSeparableVaryings(GrGLGpu* gpu, GrGLuint programId) {} | |
185 | |
186 void setData(const GrGLProgramDataManager&, | |
187 const GrPrimitiveProcessor&, | |
188 const GrBatchTracker&) SK_OVERRIDE; | |
189 | |
190 virtual void setTransformData(const GrPrimitiveProcessor*, | |
191 int index, | |
192 const SkTArray<const GrCoordTransform*, true>& transforms, | |
193 GrGLPathRendering*, | |
194 GrGLuint programID) = 0; | |
195 | |
196 virtual void didSetData(GrGLPathRendering*) {} | |
197 | |
198 private: | |
199 UniformHandle fColorUniform; | |
200 GrColor fColor; | |
201 | |
202 typedef GrGLPrimitiveProcessor INHERITED; | |
95 }; | 203 }; |
96 | 204 |
97 #endif | 205 #endif |
OLD | NEW |