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 "GrDistanceFieldGeoProc.h" | 8 #include "GrDistanceFieldGeoProc.h" |
9 #include "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.h" |
10 #include "GrTexture.h" | 10 #include "GrTexture.h" |
11 | 11 |
12 #include "SkDistanceFieldGen.h" | 12 #include "SkDistanceFieldGen.h" |
13 | 13 |
14 #include "gl/GrGLFragmentProcessor.h" | 14 #include "gl/GrGLFragmentProcessor.h" |
15 #include "gl/GrGLTexture.h" | 15 #include "gl/GrGLTexture.h" |
16 #include "gl/GrGLGeometryProcessor.h" | 16 #include "gl/GrGLGeometryProcessor.h" |
17 #include "gl/builders/GrGLProgramBuilder.h" | 17 #include "gl/builders/GrGLProgramBuilder.h" |
18 | 18 |
19 // Assuming a radius of a little less than the diagonal of the fragment | 19 // Assuming a radius of a little less than the diagonal of the fragment |
20 #define SK_DistanceFieldAAFactor "0.65" | 20 #define SK_DistanceFieldAAFactor "0.65" |
21 | 21 |
22 class GrGLDistanceFieldA8TextGeoProc : public GrGLGeometryProcessor { | 22 class GrGLDistanceFieldA8TextGeoProc : public GrGLGeometryProcessor { |
23 public: | 23 public: |
24 GrGLDistanceFieldA8TextGeoProc(const GrGeometryProcessor&, | 24 GrGLDistanceFieldA8TextGeoProc() |
25 const GrBatchTracker&) | |
26 : fViewMatrix(SkMatrix::InvalidMatrix()) | 25 : fViewMatrix(SkMatrix::InvalidMatrix()) |
27 , fColor(GrColor_ILLEGAL) | 26 , fColor(GrColor_ILLEGAL) |
28 #ifdef SK_GAMMA_APPLY_TO_A8 | 27 #ifdef SK_GAMMA_APPLY_TO_A8 |
29 , fDistanceAdjust(-1.0f) | 28 , fDistanceAdjust(-1.0f) |
30 #endif | 29 #endif |
31 {} | 30 {} |
32 | 31 |
33 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 32 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
34 const GrDistanceFieldA8TextGeoProc& dfTexEffect = | 33 const GrDistanceFieldA8TextGeoProc& dfTexEffect = |
35 args.fGP.cast<GrDistanceFieldA8TextGeoProc>(); | 34 args.fGP.cast<GrDistanceFieldA8TextGeoProc>(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 fsBuilder->codeAppend(" dist_grad.x*Jdx.y + dist_gra d.y*Jdy.y);"); | 136 fsBuilder->codeAppend(" dist_grad.x*Jdx.y + dist_gra d.y*Jdy.y);"); |
138 | 137 |
139 // this gives us a smooth step across approximately one fragment | 138 // this gives us a smooth step across approximately one fragment |
140 fsBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*length (grad);"); | 139 fsBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*length (grad);"); |
141 } | 140 } |
142 fsBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, distanc e);"); | 141 fsBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, distanc e);"); |
143 | 142 |
144 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); | 143 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); |
145 } | 144 } |
146 | 145 |
147 virtual void setData(const GrGLProgramDataManager& pdman, | 146 virtual void setData(const GrGLProgramDataManager& pdman, |
bsalomon
2015/09/10 18:55:32
one line? -virtual?
joshualitt
2015/09/10 20:08:06
Acknowledged.
| |
148 const GrPrimitiveProcessor& proc, | 147 const GrPrimitiveProcessor& proc) override { |
149 const GrBatchTracker& bt) override { | |
150 #ifdef SK_GAMMA_APPLY_TO_A8 | 148 #ifdef SK_GAMMA_APPLY_TO_A8 |
151 const GrDistanceFieldA8TextGeoProc& dfTexEffect = proc.cast<GrDistanceFi eldA8TextGeoProc>(); | 149 const GrDistanceFieldA8TextGeoProc& dfTexEffect = proc.cast<GrDistanceFi eldA8TextGeoProc>(); |
152 float distanceAdjust = dfTexEffect.getDistanceAdjust(); | 150 float distanceAdjust = dfTexEffect.getDistanceAdjust(); |
153 if (distanceAdjust != fDistanceAdjust) { | 151 if (distanceAdjust != fDistanceAdjust) { |
154 pdman.set1f(fDistanceAdjustUni, distanceAdjust); | 152 pdman.set1f(fDistanceAdjustUni, distanceAdjust); |
155 fDistanceAdjust = distanceAdjust; | 153 fDistanceAdjust = distanceAdjust; |
156 } | 154 } |
157 #endif | 155 #endif |
158 const GrDistanceFieldA8TextGeoProc& dfa8gp = proc.cast<GrDistanceFieldA8 TextGeoProc>(); | 156 const GrDistanceFieldA8TextGeoProc& dfa8gp = proc.cast<GrDistanceFieldA8 TextGeoProc>(); |
159 | 157 |
160 if (!dfa8gp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfa8g p.viewMatrix())) { | 158 if (!dfa8gp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfa8g p.viewMatrix())) { |
161 fViewMatrix = dfa8gp.viewMatrix(); | 159 fViewMatrix = dfa8gp.viewMatrix(); |
162 GrGLfloat viewMatrix[3 * 3]; | 160 GrGLfloat viewMatrix[3 * 3]; |
163 GrGLGetMatrix<3>(viewMatrix, fViewMatrix); | 161 GrGLGetMatrix<3>(viewMatrix, fViewMatrix); |
164 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 162 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
165 } | 163 } |
166 | 164 |
167 if (dfa8gp.color() != fColor && !dfa8gp.hasVertexColor()) { | 165 if (dfa8gp.color() != fColor && !dfa8gp.hasVertexColor()) { |
168 GrGLfloat c[4]; | 166 GrGLfloat c[4]; |
169 GrColorToRGBAFloat(dfa8gp.color(), c); | 167 GrColorToRGBAFloat(dfa8gp.color(), c); |
170 pdman.set4fv(fColorUniform, 1, c); | 168 pdman.set4fv(fColorUniform, 1, c); |
171 fColor = dfa8gp.color(); | 169 fColor = dfa8gp.color(); |
172 } | 170 } |
173 } | 171 } |
174 | 172 |
175 static inline void GenKey(const GrGeometryProcessor& gp, | 173 static inline void GenKey(const GrGeometryProcessor& gp, |
176 const GrBatchTracker& bt, | |
177 const GrGLSLCaps&, | 174 const GrGLSLCaps&, |
178 GrProcessorKeyBuilder* b) { | 175 GrProcessorKeyBuilder* b) { |
179 const GrDistanceFieldA8TextGeoProc& dfTexEffect = gp.cast<GrDistanceFiel dA8TextGeoProc>(); | 176 const GrDistanceFieldA8TextGeoProc& dfTexEffect = gp.cast<GrDistanceFiel dA8TextGeoProc>(); |
180 uint32_t key = dfTexEffect.getFlags(); | 177 uint32_t key = dfTexEffect.getFlags(); |
181 key |= dfTexEffect.hasVertexColor() << 16; | 178 key |= dfTexEffect.hasVertexColor() << 16; |
182 key |= dfTexEffect.colorIgnored() << 17; | 179 key |= dfTexEffect.colorIgnored() << 17; |
183 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; | 180 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
184 b->add32(key); | 181 b->add32(key); |
185 | 182 |
186 // Currently we hardcode numbers to convert atlas coordinates to normali zed floating point | 183 // Currently we hardcode numbers to convert atlas coordinates to normali zed floating point |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType, | 226 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType, |
230 kHigh_GrSLPrecision)); | 227 kHigh_GrSLPrecision)); |
231 if (flags & kColorAttr_DistanceFieldEffectFlag) { | 228 if (flags & kColorAttr_DistanceFieldEffectFlag) { |
232 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA ttribType)); | 229 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA ttribType)); |
233 } | 230 } |
234 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 231 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
235 kVec2s_GrVertexAttribT ype)); | 232 kVec2s_GrVertexAttribT ype)); |
236 this->addTextureAccess(&fTextureAccess); | 233 this->addTextureAccess(&fTextureAccess); |
237 } | 234 } |
238 | 235 |
239 void GrDistanceFieldA8TextGeoProc::getGLProcessorKey(const GrBatchTracker& bt, | 236 void GrDistanceFieldA8TextGeoProc::getGLProcessorKey(const GrGLSLCaps& caps, |
240 const GrGLSLCaps& caps, | |
241 GrProcessorKeyBuilder* b) c onst { | 237 GrProcessorKeyBuilder* b) c onst { |
242 GrGLDistanceFieldA8TextGeoProc::GenKey(*this, bt, caps, b); | 238 GrGLDistanceFieldA8TextGeoProc::GenKey(*this, caps, b); |
243 } | 239 } |
244 | 240 |
245 GrGLPrimitiveProcessor* | 241 GrGLPrimitiveProcessor* |
bsalomon
2015/09/10 18:55:32
one line?
| |
246 GrDistanceFieldA8TextGeoProc::createGLInstance(const GrBatchTracker& bt, | 242 GrDistanceFieldA8TextGeoProc::createGLInstance(const GrGLSLCaps&) const { |
247 const GrGLSLCaps&) const { | 243 return new GrGLDistanceFieldA8TextGeoProc(); |
248 return new GrGLDistanceFieldA8TextGeoProc(*this, bt); | |
249 } | 244 } |
250 | 245 |
251 /////////////////////////////////////////////////////////////////////////////// | 246 /////////////////////////////////////////////////////////////////////////////// |
252 | 247 |
253 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldA8TextGeoProc); | 248 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldA8TextGeoProc); |
254 | 249 |
255 const GrGeometryProcessor* GrDistanceFieldA8TextGeoProc::TestCreate(GrProcessorT estData* d) { | 250 const GrGeometryProcessor* GrDistanceFieldA8TextGeoProc::TestCreate(GrProcessorT estData* d) { |
256 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : | 251 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : |
257 GrProcessorUnitTest::kAlphaTextureIdx; | 252 GrProcessorUnitTest::kAlphaTextureIdx; |
258 static const SkShader::TileMode kTileModes[] = { | 253 static const SkShader::TileMode kTileModes[] = { |
(...skipping 16 matching lines...) Expand all Loading... | |
275 #endif | 270 #endif |
276 d->fRandom->nextBool() ? | 271 d->fRandom->nextBool() ? |
277 kSimilarity_DistanceFieldEff ectFlag : 0, | 272 kSimilarity_DistanceFieldEff ectFlag : 0, |
278 d->fRandom->nextBool()); | 273 d->fRandom->nextBool()); |
279 } | 274 } |
280 | 275 |
281 /////////////////////////////////////////////////////////////////////////////// | 276 /////////////////////////////////////////////////////////////////////////////// |
282 | 277 |
283 class GrGLDistanceFieldPathGeoProc : public GrGLGeometryProcessor { | 278 class GrGLDistanceFieldPathGeoProc : public GrGLGeometryProcessor { |
284 public: | 279 public: |
285 GrGLDistanceFieldPathGeoProc(const GrGeometryProcessor&, | 280 GrGLDistanceFieldPathGeoProc() |
286 const GrBatchTracker&) | |
287 : fViewMatrix(SkMatrix::InvalidMatrix()) | 281 : fViewMatrix(SkMatrix::InvalidMatrix()) |
288 , fColor(GrColor_ILLEGAL) | 282 , fColor(GrColor_ILLEGAL) |
289 , fTextureSize(SkISize::Make(-1, -1)) {} | 283 , fTextureSize(SkISize::Make(-1, -1)) {} |
290 | 284 |
291 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 285 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
292 const GrDistanceFieldPathGeoProc& dfTexEffect = args.fGP.cast<GrDistance FieldPathGeoProc>(); | 286 const GrDistanceFieldPathGeoProc& dfTexEffect = args.fGP.cast<GrDistance FieldPathGeoProc>(); |
293 | 287 |
294 GrGLGPBuilder* pb = args.fPB; | 288 GrGLGPBuilder* pb = args.fPB; |
295 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 289 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
296 SkAssertResult(fsBuilder->enableFeature( | 290 SkAssertResult(fsBuilder->enableFeature( |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 fsBuilder->codeAppend(" dist_grad.x*Jdx.y + dist_gra d.y*Jdy.y);"); | 365 fsBuilder->codeAppend(" dist_grad.x*Jdx.y + dist_gra d.y*Jdy.y);"); |
372 | 366 |
373 // this gives us a smooth step across approximately one fragment | 367 // this gives us a smooth step across approximately one fragment |
374 fsBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*length (grad);"); | 368 fsBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*length (grad);"); |
375 } | 369 } |
376 fsBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, distanc e);"); | 370 fsBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, distanc e);"); |
377 | 371 |
378 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); | 372 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); |
379 } | 373 } |
380 | 374 |
381 virtual void setData(const GrGLProgramDataManager& pdman, | 375 virtual void setData(const GrGLProgramDataManager& pdman, |
bsalomon
2015/09/10 18:55:32
one line? -virtual?
joshualitt
2015/09/10 20:08:06
Acknowledged.
| |
382 const GrPrimitiveProcessor& proc, | 376 const GrPrimitiveProcessor& proc) override { |
383 const GrBatchTracker& bt) override { | |
384 SkASSERT(fTextureSizeUni.isValid()); | 377 SkASSERT(fTextureSizeUni.isValid()); |
385 | 378 |
386 GrTexture* texture = proc.texture(0); | 379 GrTexture* texture = proc.texture(0); |
387 if (texture->width() != fTextureSize.width() || | 380 if (texture->width() != fTextureSize.width() || |
388 texture->height() != fTextureSize.height()) { | 381 texture->height() != fTextureSize.height()) { |
389 fTextureSize = SkISize::Make(texture->width(), texture->height()); | 382 fTextureSize = SkISize::Make(texture->width(), texture->height()); |
390 pdman.set2f(fTextureSizeUni, | 383 pdman.set2f(fTextureSizeUni, |
391 SkIntToScalar(fTextureSize.width()), | 384 SkIntToScalar(fTextureSize.width()), |
392 SkIntToScalar(fTextureSize.height())); | 385 SkIntToScalar(fTextureSize.height())); |
393 } | 386 } |
394 | 387 |
395 const GrDistanceFieldPathGeoProc& dfpgp = proc.cast<GrDistanceFieldPathG eoProc>(); | 388 const GrDistanceFieldPathGeoProc& dfpgp = proc.cast<GrDistanceFieldPathG eoProc>(); |
396 | 389 |
397 if (!dfpgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfpgp. viewMatrix())) { | 390 if (!dfpgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfpgp. viewMatrix())) { |
398 fViewMatrix = dfpgp.viewMatrix(); | 391 fViewMatrix = dfpgp.viewMatrix(); |
399 GrGLfloat viewMatrix[3 * 3]; | 392 GrGLfloat viewMatrix[3 * 3]; |
400 GrGLGetMatrix<3>(viewMatrix, fViewMatrix); | 393 GrGLGetMatrix<3>(viewMatrix, fViewMatrix); |
401 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 394 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
402 } | 395 } |
403 | 396 |
404 if (dfpgp.color() != fColor) { | 397 if (dfpgp.color() != fColor) { |
405 GrGLfloat c[4]; | 398 GrGLfloat c[4]; |
406 GrColorToRGBAFloat(dfpgp.color(), c); | 399 GrColorToRGBAFloat(dfpgp.color(), c); |
407 pdman.set4fv(fColorUniform, 1, c); | 400 pdman.set4fv(fColorUniform, 1, c); |
408 fColor = dfpgp.color(); | 401 fColor = dfpgp.color(); |
409 } | 402 } |
410 } | 403 } |
411 | 404 |
412 static inline void GenKey(const GrGeometryProcessor& gp, | 405 static inline void GenKey(const GrGeometryProcessor& gp, |
413 const GrBatchTracker& bt, | |
414 const GrGLSLCaps&, | 406 const GrGLSLCaps&, |
415 GrProcessorKeyBuilder* b) { | 407 GrProcessorKeyBuilder* b) { |
416 const GrDistanceFieldPathGeoProc& dfTexEffect = gp.cast<GrDistanceFieldP athGeoProc>(); | 408 const GrDistanceFieldPathGeoProc& dfTexEffect = gp.cast<GrDistanceFieldP athGeoProc>(); |
417 | 409 |
418 uint32_t key = dfTexEffect.getFlags(); | 410 uint32_t key = dfTexEffect.getFlags(); |
419 key |= dfTexEffect.colorIgnored() << 16; | 411 key |= dfTexEffect.colorIgnored() << 16; |
420 key |= dfTexEffect.hasVertexColor() << 17; | 412 key |= dfTexEffect.hasVertexColor() << 17; |
421 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; | 413 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
422 b->add32(key); | 414 b->add32(key); |
423 } | 415 } |
(...skipping 29 matching lines...) Expand all Loading... | |
453 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType, | 445 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType, |
454 kHigh_GrSLPrecision)); | 446 kHigh_GrSLPrecision)); |
455 if (flags & kColorAttr_DistanceFieldEffectFlag) { | 447 if (flags & kColorAttr_DistanceFieldEffectFlag) { |
456 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA ttribType)); | 448 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA ttribType)); |
457 } | 449 } |
458 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 450 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
459 kVec2f_GrVertexAttribTyp e)); | 451 kVec2f_GrVertexAttribTyp e)); |
460 this->addTextureAccess(&fTextureAccess); | 452 this->addTextureAccess(&fTextureAccess); |
461 } | 453 } |
462 | 454 |
463 void GrDistanceFieldPathGeoProc::getGLProcessorKey(const GrBatchTracker& bt, | 455 void GrDistanceFieldPathGeoProc::getGLProcessorKey(const GrGLSLCaps& caps, |
464 const GrGLSLCaps& caps, | |
465 GrProcessorKeyBuilder* b) con st { | 456 GrProcessorKeyBuilder* b) con st { |
466 GrGLDistanceFieldPathGeoProc::GenKey(*this, bt, caps, b); | 457 GrGLDistanceFieldPathGeoProc::GenKey(*this, caps, b); |
467 } | 458 } |
468 | 459 |
469 GrGLPrimitiveProcessor* | 460 GrGLPrimitiveProcessor* |
bsalomon
2015/09/10 18:55:32
one line?
joshualitt
2015/09/10 20:08:06
Acknowledged.
| |
470 GrDistanceFieldPathGeoProc::createGLInstance(const GrBatchTracker& bt, const GrG LSLCaps&) const { | 461 GrDistanceFieldPathGeoProc::createGLInstance(const GrGLSLCaps&) const { |
471 return new GrGLDistanceFieldPathGeoProc(*this, bt); | 462 return new GrGLDistanceFieldPathGeoProc(); |
472 } | 463 } |
473 | 464 |
474 /////////////////////////////////////////////////////////////////////////////// | 465 /////////////////////////////////////////////////////////////////////////////// |
475 | 466 |
476 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldPathGeoProc); | 467 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldPathGeoProc); |
477 | 468 |
478 const GrGeometryProcessor* GrDistanceFieldPathGeoProc::TestCreate(GrProcessorTes tData* d) { | 469 const GrGeometryProcessor* GrDistanceFieldPathGeoProc::TestCreate(GrProcessorTes tData* d) { |
479 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx | 470 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx |
480 : GrProcessorUnitTest::kAlphaTextureIdx; | 471 : GrProcessorUnitTest::kAlphaTextureIdx; |
481 static const SkShader::TileMode kTileModes[] = { | 472 static const SkShader::TileMode kTileModes[] = { |
(...skipping 14 matching lines...) Expand all Loading... | |
496 params, | 487 params, |
497 d->fRandom->nextBool() ? | 488 d->fRandom->nextBool() ? |
498 kSimilarity_DistanceFieldE ffectFlag : 0, | 489 kSimilarity_DistanceFieldE ffectFlag : 0, |
499 d->fRandom->nextBool()); | 490 d->fRandom->nextBool()); |
500 } | 491 } |
501 | 492 |
502 /////////////////////////////////////////////////////////////////////////////// | 493 /////////////////////////////////////////////////////////////////////////////// |
503 | 494 |
504 class GrGLDistanceFieldLCDTextGeoProc : public GrGLGeometryProcessor { | 495 class GrGLDistanceFieldLCDTextGeoProc : public GrGLGeometryProcessor { |
505 public: | 496 public: |
506 GrGLDistanceFieldLCDTextGeoProc(const GrGeometryProcessor&, const GrBatchTra cker&) | 497 GrGLDistanceFieldLCDTextGeoProc() |
507 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL) { | 498 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL) { |
508 fDistanceAdjust = GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(1. 0f, 1.0f, 1.0f); | 499 fDistanceAdjust = GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(1. 0f, 1.0f, 1.0f); |
509 } | 500 } |
510 | 501 |
511 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 502 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
512 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = | 503 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = |
513 args.fGP.cast<GrDistanceFieldLCDTextGeoProc>(); | 504 args.fGP.cast<GrDistanceFieldLCDTextGeoProc>(); |
514 GrGLGPBuilder* pb = args.fPB; | 505 GrGLGPBuilder* pb = args.fPB; |
515 | 506 |
516 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 507 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
643 // this gives us a smooth step across approximately one fragment | 634 // this gives us a smooth step across approximately one fragment |
644 fsBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*length (grad);"); | 635 fsBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*length (grad);"); |
645 } | 636 } |
646 | 637 |
647 fsBuilder->codeAppend( | 638 fsBuilder->codeAppend( |
648 "vec4 val = vec4(smoothstep(vec3(-afwidth), vec3(afwidth), distance), 1.0);"); | 639 "vec4 val = vec4(smoothstep(vec3(-afwidth), vec3(afwidth), distance), 1.0);"); |
649 | 640 |
650 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); | 641 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); |
651 } | 642 } |
652 | 643 |
653 virtual void setData(const GrGLProgramDataManager& pdman, | 644 virtual void setData(const GrGLProgramDataManager& pdman, |
bsalomon
2015/09/10 18:55:32
one line? -virtual?
joshualitt
2015/09/10 20:08:06
Acknowledged.
| |
654 const GrPrimitiveProcessor& processor, | 645 const GrPrimitiveProcessor& processor) override { |
655 const GrBatchTracker& bt) override { | |
656 SkASSERT(fDistanceAdjustUni.isValid()); | 646 SkASSERT(fDistanceAdjustUni.isValid()); |
657 | 647 |
658 const GrDistanceFieldLCDTextGeoProc& dflcd = processor.cast<GrDistanceFi eldLCDTextGeoProc>(); | 648 const GrDistanceFieldLCDTextGeoProc& dflcd = processor.cast<GrDistanceFi eldLCDTextGeoProc>(); |
659 GrDistanceFieldLCDTextGeoProc::DistanceAdjust wa = dflcd.getDistanceAdju st(); | 649 GrDistanceFieldLCDTextGeoProc::DistanceAdjust wa = dflcd.getDistanceAdju st(); |
660 if (wa != fDistanceAdjust) { | 650 if (wa != fDistanceAdjust) { |
661 pdman.set3f(fDistanceAdjustUni, | 651 pdman.set3f(fDistanceAdjustUni, |
662 wa.fR, | 652 wa.fR, |
663 wa.fG, | 653 wa.fG, |
664 wa.fB); | 654 wa.fB); |
665 fDistanceAdjust = wa; | 655 fDistanceAdjust = wa; |
666 } | 656 } |
667 | 657 |
668 if (!dflcd.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dflcd. viewMatrix())) { | 658 if (!dflcd.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dflcd. viewMatrix())) { |
669 fViewMatrix = dflcd.viewMatrix(); | 659 fViewMatrix = dflcd.viewMatrix(); |
670 GrGLfloat viewMatrix[3 * 3]; | 660 GrGLfloat viewMatrix[3 * 3]; |
671 GrGLGetMatrix<3>(viewMatrix, fViewMatrix); | 661 GrGLGetMatrix<3>(viewMatrix, fViewMatrix); |
672 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 662 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
673 } | 663 } |
674 | 664 |
675 if (dflcd.color() != fColor) { | 665 if (dflcd.color() != fColor) { |
676 GrGLfloat c[4]; | 666 GrGLfloat c[4]; |
677 GrColorToRGBAFloat(dflcd.color(), c); | 667 GrColorToRGBAFloat(dflcd.color(), c); |
678 pdman.set4fv(fColorUniform, 1, c); | 668 pdman.set4fv(fColorUniform, 1, c); |
679 fColor = dflcd.color(); | 669 fColor = dflcd.color(); |
680 } | 670 } |
681 } | 671 } |
682 | 672 |
683 static inline void GenKey(const GrGeometryProcessor& gp, | 673 static inline void GenKey(const GrGeometryProcessor& gp, |
684 const GrBatchTracker& bt, | |
685 const GrGLSLCaps&, | 674 const GrGLSLCaps&, |
686 GrProcessorKeyBuilder* b) { | 675 GrProcessorKeyBuilder* b) { |
687 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = gp.cast<GrDistanceFie ldLCDTextGeoProc>(); | 676 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = gp.cast<GrDistanceFie ldLCDTextGeoProc>(); |
688 | 677 |
689 uint32_t key = dfTexEffect.getFlags(); | 678 uint32_t key = dfTexEffect.getFlags(); |
690 key |= dfTexEffect.colorIgnored() << 16; | 679 key |= dfTexEffect.colorIgnored() << 16; |
691 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; | 680 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
692 b->add32(key); | 681 b->add32(key); |
693 | 682 |
694 // Currently we hardcode numbers to convert atlas coordinates to normali zed floating point | 683 // Currently we hardcode numbers to convert atlas coordinates to normali zed floating point |
(...skipping 30 matching lines...) Expand all Loading... | |
725 , fUsesLocalCoords(usesLocalCoords) { | 714 , fUsesLocalCoords(usesLocalCoords) { |
726 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan ceFieldEffectFlag)); | 715 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan ceFieldEffectFlag)); |
727 this->initClassID<GrDistanceFieldLCDTextGeoProc>(); | 716 this->initClassID<GrDistanceFieldLCDTextGeoProc>(); |
728 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType, | 717 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType, |
729 kHigh_GrSLPrecision)); | 718 kHigh_GrSLPrecision)); |
730 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 719 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
731 kVec2s_GrVertexAttribTyp e)); | 720 kVec2s_GrVertexAttribTyp e)); |
732 this->addTextureAccess(&fTextureAccess); | 721 this->addTextureAccess(&fTextureAccess); |
733 } | 722 } |
734 | 723 |
735 void GrDistanceFieldLCDTextGeoProc::getGLProcessorKey(const GrBatchTracker& bt, | 724 void GrDistanceFieldLCDTextGeoProc::getGLProcessorKey(const GrGLSLCaps& caps, |
736 const GrGLSLCaps& caps, | |
737 GrProcessorKeyBuilder* b) const { | 725 GrProcessorKeyBuilder* b) const { |
738 GrGLDistanceFieldLCDTextGeoProc::GenKey(*this, bt, caps, b); | 726 GrGLDistanceFieldLCDTextGeoProc::GenKey(*this, caps, b); |
739 } | 727 } |
740 | 728 |
741 GrGLPrimitiveProcessor* | 729 GrGLPrimitiveProcessor* |
bsalomon
2015/09/10 18:55:32
one line?
joshualitt
2015/09/10 20:08:06
Acknowledged.
| |
742 GrDistanceFieldLCDTextGeoProc::createGLInstance(const GrBatchTracker& bt, | 730 GrDistanceFieldLCDTextGeoProc::createGLInstance(const GrGLSLCaps&) const { |
743 const GrGLSLCaps&) const { | 731 return new GrGLDistanceFieldLCDTextGeoProc(); |
744 return new GrGLDistanceFieldLCDTextGeoProc(*this, bt); | |
745 } | 732 } |
746 | 733 |
747 /////////////////////////////////////////////////////////////////////////////// | 734 /////////////////////////////////////////////////////////////////////////////// |
748 | 735 |
749 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldLCDTextGeoProc); | 736 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldLCDTextGeoProc); |
750 | 737 |
751 const GrGeometryProcessor* GrDistanceFieldLCDTextGeoProc::TestCreate(GrProcessor TestData* d) { | 738 const GrGeometryProcessor* GrDistanceFieldLCDTextGeoProc::TestCreate(GrProcessor TestData* d) { |
752 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : | 739 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : |
753 GrProcessorUnitTest::kAlphaTextureIdx; | 740 GrProcessorUnitTest::kAlphaTextureIdx; |
754 static const SkShader::TileMode kTileModes[] = { | 741 static const SkShader::TileMode kTileModes[] = { |
(...skipping 11 matching lines...) Expand all Loading... | |
766 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 753 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; |
767 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 754 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; |
768 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 755 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
769 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), | 756 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), |
770 GrTest::TestMatrix(d->fRandom), | 757 GrTest::TestMatrix(d->fRandom), |
771 d->fTextures[texIdx], params, | 758 d->fTextures[texIdx], params, |
772 wa, | 759 wa, |
773 flags, | 760 flags, |
774 d->fRandom->nextBool()); | 761 d->fRandom->nextBool()); |
775 } | 762 } |
OLD | NEW |