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 "GrBezierEffect.h" | 8 #include "GrBezierEffect.h" |
9 | 9 |
10 #include "gl/GrGLProcessor.h" | 10 #include "gl/GrGLProcessor.h" |
11 #include "gl/GrGLSL.h" | 11 #include "gl/GrGLSL.h" |
12 #include "gl/GrGLGeometryProcessor.h" | 12 #include "gl/GrGLGeometryProcessor.h" |
13 #include "gl/builders/GrGLProgramBuilder.h" | 13 #include "gl/builders/GrGLProgramBuilder.h" |
14 | 14 |
| 15 struct ConicBatchTracker { |
| 16 GrGPInput fInputColorType; |
| 17 GrColor fColor; |
| 18 uint8_t fCoverageScale; |
| 19 bool fUsesLocalCoords; |
| 20 }; |
| 21 |
15 class GrGLConicEffect : public GrGLGeometryProcessor { | 22 class GrGLConicEffect : public GrGLGeometryProcessor { |
16 public: | 23 public: |
17 GrGLConicEffect(const GrGeometryProcessor&, | 24 GrGLConicEffect(const GrGeometryProcessor&, |
18 const GrBatchTracker&); | 25 const GrBatchTracker&); |
19 | 26 |
20 void onEmitCode(EmitArgs&, GrGPArgs*) override; | 27 void onEmitCode(EmitArgs&, GrGPArgs*) override; |
21 | 28 |
22 static inline void GenKey(const GrGeometryProcessor&, | 29 static inline void GenKey(const GrGeometryProcessor&, |
23 const GrBatchTracker&, | 30 const GrBatchTracker&, |
24 const GrGLSLCaps&, | 31 const GrGLSLCaps&, |
25 GrProcessorKeyBuilder*); | 32 GrProcessorKeyBuilder*); |
26 | 33 |
27 virtual void setData(const GrGLProgramDataManager& pdman, | 34 virtual void setData(const GrGLProgramDataManager& pdman, |
28 const GrPrimitiveProcessor& primProc, | 35 const GrPrimitiveProcessor& primProc, |
29 const GrBatchTracker& bt) override { | 36 const GrBatchTracker& bt) override { |
30 const GrConicEffect& ce = primProc.cast<GrConicEffect>(); | 37 const GrConicEffect& ce = primProc.cast<GrConicEffect>(); |
31 this->setUniformViewMatrix(pdman, ce.viewMatrix()); | 38 this->setUniformViewMatrix(pdman, ce.viewMatrix()); |
32 | 39 |
33 if (ce.color() != fColor) { | 40 const ConicBatchTracker& local = bt.cast<ConicBatchTracker>(); |
| 41 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
34 GrGLfloat c[4]; | 42 GrGLfloat c[4]; |
35 GrColorToRGBAFloat(ce.color(), c); | 43 GrColorToRGBAFloat(local.fColor, c); |
36 pdman.set4fv(fColorUniform, 1, c); | 44 pdman.set4fv(fColorUniform, 1, c); |
37 fColor = ce.color(); | 45 fColor = local.fColor; |
38 } | 46 } |
39 | 47 if (0xff != local.fCoverageScale && fCoverageScale != local.fCoverageSca
le) { |
40 if (ce.coverageScale() != 0xff && ce.coverageScale() != fCoverageScale)
{ | 48 pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(local.fCov
erageScale)); |
41 pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(ce.coverag
eScale())); | 49 fCoverageScale = local.fCoverageScale; |
42 fCoverageScale = ce.coverageScale(); | |
43 } | 50 } |
44 } | 51 } |
45 | 52 |
46 void setTransformData(const GrPrimitiveProcessor& primProc, | 53 void setTransformData(const GrPrimitiveProcessor& primProc, |
47 const GrGLProgramDataManager& pdman, | 54 const GrGLProgramDataManager& pdman, |
48 int index, | 55 int index, |
49 const SkTArray<const GrCoordTransform*, true>& transfo
rms) override { | 56 const SkTArray<const GrCoordTransform*, true>& transfo
rms) override { |
50 this->setTransformDataHelper<GrConicEffect>(primProc, pdman, index, tran
sforms); | 57 this->setTransformDataHelper<GrConicEffect>(primProc, pdman, index, tran
sforms); |
51 } | 58 } |
52 | 59 |
(...skipping 11 matching lines...) Expand all Loading... |
64 const GrBatchTracker& bt) | 71 const GrBatchTracker& bt) |
65 : fColor(GrColor_ILLEGAL), fCoverageScale(0xff) { | 72 : fColor(GrColor_ILLEGAL), fCoverageScale(0xff) { |
66 const GrConicEffect& ce = processor.cast<GrConicEffect>(); | 73 const GrConicEffect& ce = processor.cast<GrConicEffect>(); |
67 fEdgeType = ce.getEdgeType(); | 74 fEdgeType = ce.getEdgeType(); |
68 } | 75 } |
69 | 76 |
70 void GrGLConicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { | 77 void GrGLConicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { |
71 GrGLGPBuilder* pb = args.fPB; | 78 GrGLGPBuilder* pb = args.fPB; |
72 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 79 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
73 const GrConicEffect& gp = args.fGP.cast<GrConicEffect>(); | 80 const GrConicEffect& gp = args.fGP.cast<GrConicEffect>(); |
| 81 const ConicBatchTracker& local = args.fBT.cast<ConicBatchTracker>(); |
74 | 82 |
75 // emit attributes | 83 // emit attributes |
76 vsBuilder->emitAttributes(gp); | 84 vsBuilder->emitAttributes(gp); |
77 | 85 |
78 GrGLVertToFrag v(kVec4f_GrSLType); | 86 GrGLVertToFrag v(kVec4f_GrSLType); |
79 args.fPB->addVarying("ConicCoeffs", &v); | 87 args.fPB->addVarying("ConicCoeffs", &v); |
80 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inConicCoeffs()->fName); | 88 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inConicCoeffs()->fName); |
81 | 89 |
82 // Setup pass through color | 90 // Setup pass through color |
83 if (!gp.colorIgnored()) { | 91 this->setupColorPassThrough(args.fPB, local.fInputColorType, args.fOutputCol
or, NULL, |
84 this->setupUniformColor(args.fPB, args.fOutputColor, &fColorUniform); | 92 &fColorUniform); |
85 } | |
86 | 93 |
87 // Setup position | 94 // Setup position |
88 this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatrix()); | 95 this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatrix()); |
89 | 96 |
90 // emit transforms with position | 97 // emit transforms with position |
91 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()->fName, gp.lo
calMatrix(), | 98 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()->fName, gp.lo
calMatrix(), |
92 args.fTransformsIn, args.fTransformsOut); | 99 args.fTransformsIn, args.fTransformsOut); |
93 | 100 |
94 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 101 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
95 fsBuilder->codeAppend("float edgeAlpha;"); | 102 fsBuilder->codeAppend("float edgeAlpha;"); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 case kFillBW_GrProcessorEdgeType: { | 148 case kFillBW_GrProcessorEdgeType: { |
142 fsBuilder->codeAppendf("edgeAlpha = %s.x * %s.x - %s.y * %s.z;", v.f
sIn(), v.fsIn(), | 149 fsBuilder->codeAppendf("edgeAlpha = %s.x * %s.x - %s.y * %s.z;", v.f
sIn(), v.fsIn(), |
143 v.fsIn(), v.fsIn()); | 150 v.fsIn(), v.fsIn()); |
144 fsBuilder->codeAppend("edgeAlpha = float(edgeAlpha < 0.0);"); | 151 fsBuilder->codeAppend("edgeAlpha = float(edgeAlpha < 0.0);"); |
145 break; | 152 break; |
146 } | 153 } |
147 default: | 154 default: |
148 SkFAIL("Shouldn't get here"); | 155 SkFAIL("Shouldn't get here"); |
149 } | 156 } |
150 | 157 |
151 // TODO should we really be doing this? | 158 if (0xff != local.fCoverageScale) { |
152 if (gp.coverageScale() != 0xff) { | |
153 const char* coverageScale; | 159 const char* coverageScale; |
154 fCoverageScaleUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Vis
ibility, | 160 fCoverageScaleUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Vis
ibility, |
155 kFloat_GrSLType, | 161 kFloat_GrSLType, |
156 kDefault_GrSLPrecision, | 162 kDefault_GrSLPrecision, |
157 "Coverage", | 163 "Coverage", |
158 &coverageScale); | 164 &coverageScale); |
159 fsBuilder->codeAppendf("%s = vec4(%s * edgeAlpha);", args.fOutputCoverag
e, coverageScale); | 165 fsBuilder->codeAppendf("%s = vec4(%s * edgeAlpha);", args.fOutputCoverag
e, coverageScale); |
160 } else { | 166 } else { |
161 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); | 167 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); |
162 } | 168 } |
163 } | 169 } |
164 | 170 |
165 void GrGLConicEffect::GenKey(const GrGeometryProcessor& gp, | 171 void GrGLConicEffect::GenKey(const GrGeometryProcessor& gp, |
166 const GrBatchTracker& bt, | 172 const GrBatchTracker& bt, |
167 const GrGLSLCaps&, | 173 const GrGLSLCaps&, |
168 GrProcessorKeyBuilder* b) { | 174 GrProcessorKeyBuilder* b) { |
169 const GrConicEffect& ce = gp.cast<GrConicEffect>(); | 175 const GrConicEffect& ce = gp.cast<GrConicEffect>(); |
| 176 const ConicBatchTracker& local = bt.cast<ConicBatchTracker>(); |
170 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 177 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
171 key |= GrColor_ILLEGAL != ce.color() ? 0x4 : 0x0; | 178 key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x0; |
172 key |= 0xff != ce.coverageScale() ? 0x8 : 0x0; | 179 key |= 0xff != local.fCoverageScale ? 0x8 : 0x0; |
173 key |= ce.usesLocalCoords() && ce.localMatrix().hasPerspective() ? 0x10 : 0x
0; | 180 key |= local.fUsesLocalCoords && ce.localMatrix().hasPerspective() ? 0x10 :
0x0; |
174 key |= ComputePosKey(ce.viewMatrix()) << 5; | 181 key |= ComputePosKey(ce.viewMatrix()) << 5; |
175 b->add32(key); | 182 b->add32(key); |
176 } | 183 } |
177 | 184 |
178 ////////////////////////////////////////////////////////////////////////////// | 185 ////////////////////////////////////////////////////////////////////////////// |
179 | 186 |
180 GrConicEffect::~GrConicEffect() {} | 187 GrConicEffect::~GrConicEffect() {} |
181 | 188 |
182 void GrConicEffect::getGLProcessorKey(const GrBatchTracker& bt, | 189 void GrConicEffect::getGLProcessorKey(const GrBatchTracker& bt, |
183 const GrGLSLCaps& caps, | 190 const GrGLSLCaps& caps, |
184 GrProcessorKeyBuilder* b) const { | 191 GrProcessorKeyBuilder* b) const { |
185 GrGLConicEffect::GenKey(*this, bt, caps, b); | 192 GrGLConicEffect::GenKey(*this, bt, caps, b); |
186 } | 193 } |
187 | 194 |
188 GrGLPrimitiveProcessor* GrConicEffect::createGLInstance(const GrBatchTracker& bt
, | 195 GrGLPrimitiveProcessor* GrConicEffect::createGLInstance(const GrBatchTracker& bt
, |
189 const GrGLSLCaps&) const
{ | 196 const GrGLSLCaps&) const
{ |
190 return SkNEW_ARGS(GrGLConicEffect, (*this, bt)); | 197 return SkNEW_ARGS(GrGLConicEffect, (*this, bt)); |
191 } | 198 } |
192 | 199 |
193 GrConicEffect::GrConicEffect(GrColor color, const SkMatrix& viewMatrix, uint8_t
coverage, | 200 GrConicEffect::GrConicEffect(GrColor color, const SkMatrix& viewMatrix, uint8_t
coverage, |
194 GrPrimitiveEdgeType edgeType, const SkMatrix& local
Matrix, | 201 GrPrimitiveEdgeType edgeType, const SkMatrix& local
Matrix) |
195 bool usesLocalCoords) | |
196 : fColor(color) | 202 : fColor(color) |
197 , fViewMatrix(viewMatrix) | 203 , fViewMatrix(viewMatrix) |
198 , fLocalMatrix(viewMatrix) | 204 , fLocalMatrix(viewMatrix) |
199 , fUsesLocalCoords(usesLocalCoords) | |
200 , fCoverageScale(coverage) | 205 , fCoverageScale(coverage) |
201 , fEdgeType(edgeType) { | 206 , fEdgeType(edgeType) { |
202 this->initClassID<GrConicEffect>(); | 207 this->initClassID<GrConicEffect>(); |
203 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); | 208 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); |
204 fInConicCoeffs = &this->addVertexAttrib(Attribute("inConicCoeffs", | 209 fInConicCoeffs = &this->addVertexAttrib(Attribute("inConicCoeffs", |
205 kVec4f_GrVertexAttribType)
); | 210 kVec4f_GrVertexAttribTyp
e)); |
| 211 } |
| 212 |
| 213 void GrConicEffect::initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& i
nit) const { |
| 214 ConicBatchTracker* local = bt->cast<ConicBatchTracker>(); |
| 215 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, false); |
| 216 local->fCoverageScale = fCoverageScale; |
| 217 local->fUsesLocalCoords = init.fUsesLocalCoords; |
206 } | 218 } |
207 | 219 |
208 ////////////////////////////////////////////////////////////////////////////// | 220 ////////////////////////////////////////////////////////////////////////////// |
209 | 221 |
210 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrConicEffect); | 222 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrConicEffect); |
211 | 223 |
212 GrGeometryProcessor* GrConicEffect::TestCreate(SkRandom* random, | 224 GrGeometryProcessor* GrConicEffect::TestCreate(SkRandom* random, |
213 GrContext*, | 225 GrContext*, |
214 const GrDrawTargetCaps& caps, | 226 const GrDrawTargetCaps& caps, |
215 GrTexture*[]) { | 227 GrTexture*[]) { |
216 GrGeometryProcessor* gp; | 228 GrGeometryProcessor* gp; |
217 do { | 229 do { |
218 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 230 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
219 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); | 231 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); |
220 gp = GrConicEffect::Create(GrRandomColor(random), GrTest::TestMatrix(ran
dom), | 232 gp = GrConicEffect::Create(GrRandomColor(random), GrTest::TestMatrix(ran
dom), |
221 edgeType, caps, | 233 edgeType, caps, |
222 GrTest::TestMatrix(random), random->nextBool(
)); | 234 GrTest::TestMatrix(random)); |
223 } while (NULL == gp); | 235 } while (NULL == gp); |
224 return gp; | 236 return gp; |
225 } | 237 } |
226 | 238 |
227 ////////////////////////////////////////////////////////////////////////////// | 239 ////////////////////////////////////////////////////////////////////////////// |
228 // Quad | 240 // Quad |
229 ////////////////////////////////////////////////////////////////////////////// | 241 ////////////////////////////////////////////////////////////////////////////// |
230 | 242 |
| 243 struct QuadBatchTracker { |
| 244 GrGPInput fInputColorType; |
| 245 GrColor fColor; |
| 246 uint8_t fCoverageScale; |
| 247 bool fUsesLocalCoords; |
| 248 }; |
| 249 |
231 class GrGLQuadEffect : public GrGLGeometryProcessor { | 250 class GrGLQuadEffect : public GrGLGeometryProcessor { |
232 public: | 251 public: |
233 GrGLQuadEffect(const GrGeometryProcessor&, | 252 GrGLQuadEffect(const GrGeometryProcessor&, |
234 const GrBatchTracker&); | 253 const GrBatchTracker&); |
235 | 254 |
236 void onEmitCode(EmitArgs&, GrGPArgs*) override; | 255 void onEmitCode(EmitArgs&, GrGPArgs*) override; |
237 | 256 |
238 static inline void GenKey(const GrGeometryProcessor&, | 257 static inline void GenKey(const GrGeometryProcessor&, |
239 const GrBatchTracker&, | 258 const GrBatchTracker&, |
240 const GrGLSLCaps&, | 259 const GrGLSLCaps&, |
241 GrProcessorKeyBuilder*); | 260 GrProcessorKeyBuilder*); |
242 | 261 |
243 virtual void setData(const GrGLProgramDataManager& pdman, | 262 virtual void setData(const GrGLProgramDataManager& pdman, |
244 const GrPrimitiveProcessor& primProc, | 263 const GrPrimitiveProcessor& primProc, |
245 const GrBatchTracker& bt) override { | 264 const GrBatchTracker& bt) override { |
246 const GrQuadEffect& qe = primProc.cast<GrQuadEffect>(); | 265 const GrQuadEffect& qe = primProc.cast<GrQuadEffect>(); |
247 this->setUniformViewMatrix(pdman, qe.viewMatrix()); | 266 this->setUniformViewMatrix(pdman, qe.viewMatrix()); |
248 | 267 |
249 if (qe.color() != fColor) { | 268 const QuadBatchTracker& local = bt.cast<QuadBatchTracker>(); |
| 269 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
250 GrGLfloat c[4]; | 270 GrGLfloat c[4]; |
251 GrColorToRGBAFloat(qe.color(), c); | 271 GrColorToRGBAFloat(local.fColor, c); |
252 pdman.set4fv(fColorUniform, 1, c); | 272 pdman.set4fv(fColorUniform, 1, c); |
253 fColor = qe.color(); | 273 fColor = local.fColor; |
254 } | 274 } |
255 | 275 if (0xff != local.fCoverageScale && local.fCoverageScale != fCoverageSca
le) { |
256 if (qe.coverageScale() != 0xff && qe.coverageScale() != fCoverageScale)
{ | 276 pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(local.fCov
erageScale)); |
257 pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(qe.coverag
eScale())); | 277 fCoverageScale = local.fCoverageScale; |
258 fCoverageScale = qe.coverageScale(); | |
259 } | 278 } |
260 } | 279 } |
261 | 280 |
262 void setTransformData(const GrPrimitiveProcessor& primProc, | 281 void setTransformData(const GrPrimitiveProcessor& primProc, |
263 const GrGLProgramDataManager& pdman, | 282 const GrGLProgramDataManager& pdman, |
264 int index, | 283 int index, |
265 const SkTArray<const GrCoordTransform*, true>& transfo
rms) override { | 284 const SkTArray<const GrCoordTransform*, true>& transfo
rms) override { |
266 this->setTransformDataHelper<GrQuadEffect>(primProc, pdman, index, trans
forms); | 285 this->setTransformDataHelper<GrQuadEffect>(primProc, pdman, index, trans
forms); |
267 } | 286 } |
268 | 287 |
(...skipping 11 matching lines...) Expand all Loading... |
280 const GrBatchTracker& bt) | 299 const GrBatchTracker& bt) |
281 : fColor(GrColor_ILLEGAL), fCoverageScale(0xff) { | 300 : fColor(GrColor_ILLEGAL), fCoverageScale(0xff) { |
282 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); | 301 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); |
283 fEdgeType = ce.getEdgeType(); | 302 fEdgeType = ce.getEdgeType(); |
284 } | 303 } |
285 | 304 |
286 void GrGLQuadEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { | 305 void GrGLQuadEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { |
287 GrGLGPBuilder* pb = args.fPB; | 306 GrGLGPBuilder* pb = args.fPB; |
288 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 307 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
289 const GrQuadEffect& gp = args.fGP.cast<GrQuadEffect>(); | 308 const GrQuadEffect& gp = args.fGP.cast<GrQuadEffect>(); |
| 309 const QuadBatchTracker& local = args.fBT.cast<QuadBatchTracker>(); |
290 | 310 |
291 // emit attributes | 311 // emit attributes |
292 vsBuilder->emitAttributes(gp); | 312 vsBuilder->emitAttributes(gp); |
293 | 313 |
294 GrGLVertToFrag v(kVec4f_GrSLType); | 314 GrGLVertToFrag v(kVec4f_GrSLType); |
295 args.fPB->addVarying("HairQuadEdge", &v); | 315 args.fPB->addVarying("HairQuadEdge", &v); |
296 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inHairQuadEdge()->fName); | 316 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inHairQuadEdge()->fName); |
297 | 317 |
298 // Setup pass through color | 318 // Setup pass through color |
299 if (!gp.colorIgnored()) { | 319 this->setupColorPassThrough(args.fPB, local.fInputColorType, args.fOutputCol
or, NULL, |
300 this->setupUniformColor(args.fPB, args.fOutputColor, &fColorUniform); | 320 &fColorUniform); |
301 } | |
302 | 321 |
303 // Setup position | 322 // Setup position |
304 this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatrix()); | 323 this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatrix()); |
305 | 324 |
306 // emit transforms with position | 325 // emit transforms with position |
307 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()->fName, gp.lo
calMatrix(), | 326 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()->fName, gp.lo
calMatrix(), |
308 args.fTransformsIn, args.fTransformsOut); | 327 args.fTransformsIn, args.fTransformsOut); |
309 | 328 |
310 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 329 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
311 fsBuilder->codeAppendf("float edgeAlpha;"); | 330 fsBuilder->codeAppendf("float edgeAlpha;"); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 } | 362 } |
344 case kFillBW_GrProcessorEdgeType: { | 363 case kFillBW_GrProcessorEdgeType: { |
345 fsBuilder->codeAppendf("edgeAlpha = (%s.x * %s.x - %s.y);", v.fsIn()
, v.fsIn(), v.fsIn()); | 364 fsBuilder->codeAppendf("edgeAlpha = (%s.x * %s.x - %s.y);", v.fsIn()
, v.fsIn(), v.fsIn()); |
346 fsBuilder->codeAppend("edgeAlpha = float(edgeAlpha < 0.0);"); | 365 fsBuilder->codeAppend("edgeAlpha = float(edgeAlpha < 0.0);"); |
347 break; | 366 break; |
348 } | 367 } |
349 default: | 368 default: |
350 SkFAIL("Shouldn't get here"); | 369 SkFAIL("Shouldn't get here"); |
351 } | 370 } |
352 | 371 |
353 if (0xff != gp.coverageScale()) { | 372 if (0xff != local.fCoverageScale) { |
354 const char* coverageScale; | 373 const char* coverageScale; |
355 fCoverageScaleUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Vis
ibility, | 374 fCoverageScaleUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Vis
ibility, |
356 kFloat_GrSLType, | 375 kFloat_GrSLType, |
357 kDefault_GrSLPrecision, | 376 kDefault_GrSLPrecision, |
358 "Coverage", | 377 "Coverage", |
359 &coverageScale); | 378 &coverageScale); |
360 fsBuilder->codeAppendf("%s = vec4(%s * edgeAlpha);", args.fOutputCoverag
e, coverageScale); | 379 fsBuilder->codeAppendf("%s = vec4(%s * edgeAlpha);", args.fOutputCoverag
e, coverageScale); |
361 } else { | 380 } else { |
362 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); | 381 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage); |
363 } | 382 } |
364 } | 383 } |
365 | 384 |
366 void GrGLQuadEffect::GenKey(const GrGeometryProcessor& gp, | 385 void GrGLQuadEffect::GenKey(const GrGeometryProcessor& gp, |
367 const GrBatchTracker& bt, | 386 const GrBatchTracker& bt, |
368 const GrGLSLCaps&, | 387 const GrGLSLCaps&, |
369 GrProcessorKeyBuilder* b) { | 388 GrProcessorKeyBuilder* b) { |
370 const GrQuadEffect& ce = gp.cast<GrQuadEffect>(); | 389 const GrQuadEffect& ce = gp.cast<GrQuadEffect>(); |
| 390 const QuadBatchTracker& local = bt.cast<QuadBatchTracker>(); |
371 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 391 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
372 key |= ce.color() != GrColor_ILLEGAL ? 0x4 : 0x0; | 392 key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x0; |
373 key |= ce.coverageScale() != 0xff ? 0x8 : 0x0; | 393 key |= 0xff != local.fCoverageScale ? 0x8 : 0x0; |
374 key |= ce.usesLocalCoords() && ce.localMatrix().hasPerspective() ? 0x10 : 0x
0; | 394 key |= local.fUsesLocalCoords && ce.localMatrix().hasPerspective() ? 0x10 :
0x0; |
375 key |= ComputePosKey(ce.viewMatrix()) << 5; | 395 key |= ComputePosKey(ce.viewMatrix()) << 5; |
376 b->add32(key); | 396 b->add32(key); |
377 } | 397 } |
378 | 398 |
379 ////////////////////////////////////////////////////////////////////////////// | 399 ////////////////////////////////////////////////////////////////////////////// |
380 | 400 |
381 GrQuadEffect::~GrQuadEffect() {} | 401 GrQuadEffect::~GrQuadEffect() {} |
382 | 402 |
383 void GrQuadEffect::getGLProcessorKey(const GrBatchTracker& bt, | 403 void GrQuadEffect::getGLProcessorKey(const GrBatchTracker& bt, |
384 const GrGLSLCaps& caps, | 404 const GrGLSLCaps& caps, |
385 GrProcessorKeyBuilder* b) const { | 405 GrProcessorKeyBuilder* b) const { |
386 GrGLQuadEffect::GenKey(*this, bt, caps, b); | 406 GrGLQuadEffect::GenKey(*this, bt, caps, b); |
387 } | 407 } |
388 | 408 |
389 GrGLPrimitiveProcessor* GrQuadEffect::createGLInstance(const GrBatchTracker& bt, | 409 GrGLPrimitiveProcessor* GrQuadEffect::createGLInstance(const GrBatchTracker& bt, |
390 const GrGLSLCaps&) const
{ | 410 const GrGLSLCaps&) const
{ |
391 return SkNEW_ARGS(GrGLQuadEffect, (*this, bt)); | 411 return SkNEW_ARGS(GrGLQuadEffect, (*this, bt)); |
392 } | 412 } |
393 | 413 |
394 GrQuadEffect::GrQuadEffect(GrColor color, const SkMatrix& viewMatrix, uint8_t co
verage, | 414 GrQuadEffect::GrQuadEffect(GrColor color, const SkMatrix& viewMatrix, uint8_t co
verage, |
395 GrPrimitiveEdgeType edgeType, const SkMatrix& localMa
trix, | 415 GrPrimitiveEdgeType edgeType, const SkMatrix& localMa
trix) |
396 bool usesLocalCoords) | |
397 : fColor(color) | 416 : fColor(color) |
398 , fViewMatrix(viewMatrix) | 417 , fViewMatrix(viewMatrix) |
399 , fLocalMatrix(localMatrix) | 418 , fLocalMatrix(localMatrix) |
400 , fUsesLocalCoords(usesLocalCoords) | |
401 , fCoverageScale(coverage) | 419 , fCoverageScale(coverage) |
402 , fEdgeType(edgeType) { | 420 , fEdgeType(edgeType) { |
403 this->initClassID<GrQuadEffect>(); | 421 this->initClassID<GrQuadEffect>(); |
404 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); | 422 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); |
405 fInHairQuadEdge = &this->addVertexAttrib(Attribute("inHairQuadEdge", | 423 fInHairQuadEdge = &this->addVertexAttrib(Attribute("inHairQuadEdge", |
406 kVec4f_GrVertexAttribTyp
e)); | 424 kVec4f_GrVertexAttribTyp
e)); |
407 } | 425 } |
408 | 426 |
| 427 void GrQuadEffect::initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& in
it) const { |
| 428 QuadBatchTracker* local = bt->cast<QuadBatchTracker>(); |
| 429 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, false); |
| 430 local->fCoverageScale = fCoverageScale; |
| 431 local->fUsesLocalCoords = init.fUsesLocalCoords; |
| 432 } |
| 433 |
409 ////////////////////////////////////////////////////////////////////////////// | 434 ////////////////////////////////////////////////////////////////////////////// |
410 | 435 |
411 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrQuadEffect); | 436 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrQuadEffect); |
412 | 437 |
413 GrGeometryProcessor* GrQuadEffect::TestCreate(SkRandom* random, | 438 GrGeometryProcessor* GrQuadEffect::TestCreate(SkRandom* random, |
414 GrContext*, | 439 GrContext*, |
415 const GrDrawTargetCaps& caps, | 440 const GrDrawTargetCaps& caps, |
416 GrTexture*[]) { | 441 GrTexture*[]) { |
417 GrGeometryProcessor* gp; | 442 GrGeometryProcessor* gp; |
418 do { | 443 do { |
419 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 444 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
420 random->nextULessThan(kGrProcessorEdgeTypeCnt)); | 445 random->nextULessThan(kGrProcessorEdgeTypeCnt)); |
421 gp = GrQuadEffect::Create(GrRandomColor(random), | 446 gp = GrQuadEffect::Create(GrRandomColor(random), |
422 GrTest::TestMatrix(random), | 447 GrTest::TestMatrix(random), |
423 edgeType, caps, | 448 edgeType, caps, |
424 GrTest::TestMatrix(random), | 449 GrTest::TestMatrix(random)); |
425 random->nextBool()); | |
426 } while (NULL == gp); | 450 } while (NULL == gp); |
427 return gp; | 451 return gp; |
428 } | 452 } |
429 | 453 |
430 ////////////////////////////////////////////////////////////////////////////// | 454 ////////////////////////////////////////////////////////////////////////////// |
431 // Cubic | 455 // Cubic |
432 ////////////////////////////////////////////////////////////////////////////// | 456 ////////////////////////////////////////////////////////////////////////////// |
433 | 457 |
| 458 struct CubicBatchTracker { |
| 459 GrGPInput fInputColorType; |
| 460 GrColor fColor; |
| 461 bool fUsesLocalCoords; |
| 462 }; |
| 463 |
434 class GrGLCubicEffect : public GrGLGeometryProcessor { | 464 class GrGLCubicEffect : public GrGLGeometryProcessor { |
435 public: | 465 public: |
436 GrGLCubicEffect(const GrGeometryProcessor&, | 466 GrGLCubicEffect(const GrGeometryProcessor&, |
437 const GrBatchTracker&); | 467 const GrBatchTracker&); |
438 | 468 |
439 void onEmitCode(EmitArgs&, GrGPArgs*) override; | 469 void onEmitCode(EmitArgs&, GrGPArgs*) override; |
440 | 470 |
441 static inline void GenKey(const GrGeometryProcessor&, | 471 static inline void GenKey(const GrGeometryProcessor&, |
442 const GrBatchTracker&, | 472 const GrBatchTracker&, |
443 const GrGLSLCaps&, | 473 const GrGLSLCaps&, |
444 GrProcessorKeyBuilder*); | 474 GrProcessorKeyBuilder*); |
445 | 475 |
446 virtual void setData(const GrGLProgramDataManager& pdman, | 476 virtual void setData(const GrGLProgramDataManager& pdman, |
447 const GrPrimitiveProcessor& primProc, | 477 const GrPrimitiveProcessor& primProc, |
448 const GrBatchTracker& bt) override { | 478 const GrBatchTracker& bt) override { |
449 const GrCubicEffect& ce = primProc.cast<GrCubicEffect>(); | 479 const GrCubicEffect& ce = primProc.cast<GrCubicEffect>(); |
450 this->setUniformViewMatrix(pdman, ce.viewMatrix()); | 480 this->setUniformViewMatrix(pdman, ce.viewMatrix()); |
451 | 481 |
452 if (ce.color() != fColor) { | 482 const CubicBatchTracker& local = bt.cast<CubicBatchTracker>(); |
| 483 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
453 GrGLfloat c[4]; | 484 GrGLfloat c[4]; |
454 GrColorToRGBAFloat(ce.color(), c); | 485 GrColorToRGBAFloat(local.fColor, c); |
455 pdman.set4fv(fColorUniform, 1, c); | 486 pdman.set4fv(fColorUniform, 1, c); |
456 fColor = ce.color(); | 487 fColor = local.fColor; |
457 } | 488 } |
458 } | 489 } |
459 | 490 |
460 private: | 491 private: |
461 GrColor fColor; | 492 GrColor fColor; |
462 GrPrimitiveEdgeType fEdgeType; | 493 GrPrimitiveEdgeType fEdgeType; |
463 UniformHandle fColorUniform; | 494 UniformHandle fColorUniform; |
464 | 495 |
465 typedef GrGLGeometryProcessor INHERITED; | 496 typedef GrGLGeometryProcessor INHERITED; |
466 }; | 497 }; |
467 | 498 |
468 GrGLCubicEffect::GrGLCubicEffect(const GrGeometryProcessor& processor, | 499 GrGLCubicEffect::GrGLCubicEffect(const GrGeometryProcessor& processor, |
469 const GrBatchTracker&) | 500 const GrBatchTracker&) |
470 : fColor(GrColor_ILLEGAL) { | 501 : fColor(GrColor_ILLEGAL) { |
471 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); | 502 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); |
472 fEdgeType = ce.getEdgeType(); | 503 fEdgeType = ce.getEdgeType(); |
473 } | 504 } |
474 | 505 |
475 void GrGLCubicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { | 506 void GrGLCubicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { |
476 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 507 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
477 const GrCubicEffect& gp = args.fGP.cast<GrCubicEffect>(); | 508 const GrCubicEffect& gp = args.fGP.cast<GrCubicEffect>(); |
| 509 const CubicBatchTracker& local = args.fBT.cast<CubicBatchTracker>(); |
478 | 510 |
479 // emit attributes | 511 // emit attributes |
480 vsBuilder->emitAttributes(gp); | 512 vsBuilder->emitAttributes(gp); |
481 | 513 |
482 GrGLVertToFrag v(kVec4f_GrSLType); | 514 GrGLVertToFrag v(kVec4f_GrSLType); |
483 args.fPB->addVarying("CubicCoeffs", &v, kHigh_GrSLPrecision); | 515 args.fPB->addVarying("CubicCoeffs", &v, kHigh_GrSLPrecision); |
484 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inCubicCoeffs()->fName); | 516 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), gp.inCubicCoeffs()->fName); |
485 | 517 |
486 // Setup pass through color | 518 // Setup pass through color |
487 if (!gp.colorIgnored()) { | 519 this->setupColorPassThrough(args.fPB, local.fInputColorType, args.fOutputCol
or, NULL, |
488 this->setupUniformColor(args.fPB, args.fOutputColor, &fColorUniform); | 520 &fColorUniform); |
489 } | |
490 | 521 |
491 // Setup position | 522 // Setup position |
492 this->setupPosition(args.fPB, gpArgs, gp.inPosition()->fName, gp.viewMatrix(
)); | 523 this->setupPosition(args.fPB, gpArgs, gp.inPosition()->fName, gp.viewMatrix(
)); |
493 | 524 |
494 // emit transforms with position | 525 // emit transforms with position |
495 this->emitTransforms(args.fPB, gpArgs->fPositionVar, gp.inPosition()->fName,
args.fTransformsIn, | 526 this->emitTransforms(args.fPB, gpArgs->fPositionVar, gp.inPosition()->fName,
args.fTransformsIn, |
496 args.fTransformsOut); | 527 args.fTransformsOut); |
497 | 528 |
498 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 529 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
499 | 530 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 | 611 |
581 | 612 |
582 fsBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, edgeAlpha.c_s
tr()); | 613 fsBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, edgeAlpha.c_s
tr()); |
583 } | 614 } |
584 | 615 |
585 void GrGLCubicEffect::GenKey(const GrGeometryProcessor& gp, | 616 void GrGLCubicEffect::GenKey(const GrGeometryProcessor& gp, |
586 const GrBatchTracker& bt, | 617 const GrBatchTracker& bt, |
587 const GrGLSLCaps&, | 618 const GrGLSLCaps&, |
588 GrProcessorKeyBuilder* b) { | 619 GrProcessorKeyBuilder* b) { |
589 const GrCubicEffect& ce = gp.cast<GrCubicEffect>(); | 620 const GrCubicEffect& ce = gp.cast<GrCubicEffect>(); |
| 621 const CubicBatchTracker& local = bt.cast<CubicBatchTracker>(); |
590 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 622 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
591 key |= ce.color() != GrColor_ILLEGAL ? 0x4 : 0x8; | 623 key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x8; |
592 key |= ComputePosKey(ce.viewMatrix()) << 5; | 624 key |= ComputePosKey(ce.viewMatrix()) << 5; |
593 b->add32(key); | 625 b->add32(key); |
594 } | 626 } |
595 | 627 |
596 ////////////////////////////////////////////////////////////////////////////// | 628 ////////////////////////////////////////////////////////////////////////////// |
597 | 629 |
598 GrCubicEffect::~GrCubicEffect() {} | 630 GrCubicEffect::~GrCubicEffect() {} |
599 | 631 |
600 void GrCubicEffect::getGLProcessorKey(const GrBatchTracker& bt, | 632 void GrCubicEffect::getGLProcessorKey(const GrBatchTracker& bt, |
601 const GrGLSLCaps& caps, | 633 const GrGLSLCaps& caps, |
(...skipping 10 matching lines...) Expand all Loading... |
612 GrPrimitiveEdgeType edgeType) | 644 GrPrimitiveEdgeType edgeType) |
613 : fColor(color) | 645 : fColor(color) |
614 , fViewMatrix(viewMatrix) | 646 , fViewMatrix(viewMatrix) |
615 , fEdgeType(edgeType) { | 647 , fEdgeType(edgeType) { |
616 this->initClassID<GrCubicEffect>(); | 648 this->initClassID<GrCubicEffect>(); |
617 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); | 649 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); |
618 fInCubicCoeffs = &this->addVertexAttrib(Attribute("inCubicCoeffs", | 650 fInCubicCoeffs = &this->addVertexAttrib(Attribute("inCubicCoeffs", |
619 kVec4f_GrVertexAttribTyp
e)); | 651 kVec4f_GrVertexAttribTyp
e)); |
620 } | 652 } |
621 | 653 |
| 654 void GrCubicEffect::initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& i
nit) const { |
| 655 CubicBatchTracker* local = bt->cast<CubicBatchTracker>(); |
| 656 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, false); |
| 657 local->fUsesLocalCoords = init.fUsesLocalCoords; |
| 658 } |
| 659 |
622 ////////////////////////////////////////////////////////////////////////////// | 660 ////////////////////////////////////////////////////////////////////////////// |
623 | 661 |
624 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCubicEffect); | 662 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCubicEffect); |
625 | 663 |
626 GrGeometryProcessor* GrCubicEffect::TestCreate(SkRandom* random, | 664 GrGeometryProcessor* GrCubicEffect::TestCreate(SkRandom* random, |
627 GrContext*, | 665 GrContext*, |
628 const GrDrawTargetCaps& caps, | 666 const GrDrawTargetCaps& caps, |
629 GrTexture*[]) { | 667 GrTexture*[]) { |
630 GrGeometryProcessor* gp; | 668 GrGeometryProcessor* gp; |
631 do { | 669 do { |
632 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 670 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
633 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); | 671 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); |
634 gp = GrCubicEffect::Create(GrRandomColor(random), | 672 gp = GrCubicEffect::Create(GrRandomColor(random), |
635 GrTest::TestMatrix(random), edgeType, caps); | 673 GrTest::TestMatrix(random), edgeType, caps); |
636 } while (NULL == gp); | 674 } while (NULL == gp); |
637 return gp; | 675 return gp; |
638 } | 676 } |
639 | 677 |
OLD | NEW |