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" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 dfTexEffect.inPosition()->fName, | 66 dfTexEffect.inPosition()->fName, |
67 dfTexEffect.viewMatrix(), | 67 dfTexEffect.viewMatrix(), |
68 &fViewMatrixUniform); | 68 &fViewMatrixUniform); |
69 | 69 |
70 // emit transforms | 70 // emit transforms |
71 this->emitTransforms(vertBuilder, | 71 this->emitTransforms(vertBuilder, |
72 varyingHandler, | 72 varyingHandler, |
73 uniformHandler, | 73 uniformHandler, |
74 gpArgs->fPositionVar, | 74 gpArgs->fPositionVar, |
75 dfTexEffect.inPosition()->fName, | 75 dfTexEffect.inPosition()->fName, |
76 args.fTransformsIn, | 76 args.fFPCoordTransformHandler); |
77 args.fTransformsOut); | |
78 | 77 |
79 // add varyings | 78 // add varyings |
80 GrGLSLVertToFrag recipScale(kFloat_GrSLType); | 79 GrGLSLVertToFrag recipScale(kFloat_GrSLType); |
81 GrGLSLVertToFrag uv(kVec2f_GrSLType); | 80 GrGLSLVertToFrag uv(kVec2f_GrSLType); |
82 bool isUniformScale = (dfTexEffect.getFlags() & kUniformScale_DistanceFi
eldEffectMask) == | 81 bool isUniformScale = (dfTexEffect.getFlags() & kUniformScale_DistanceFi
eldEffectMask) == |
83 kUniformScale_DistanceFieldEffectMask; | 82 kUniformScale_DistanceFieldEffectMask; |
84 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan
ceFieldEffectFlag); | 83 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan
ceFieldEffectFlag); |
85 bool isGammaCorrect = | 84 bool isGammaCorrect = |
86 SkToBool(dfTexEffect.getFlags() & kGammaCorrect_DistanceFieldEffectF
lag); | 85 SkToBool(dfTexEffect.getFlags() & kGammaCorrect_DistanceFieldEffectF
lag); |
87 varyingHandler->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); | 86 varyingHandler->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 if (isGammaCorrect) { | 171 if (isGammaCorrect) { |
173 fragBuilder->codeAppend( | 172 fragBuilder->codeAppend( |
174 "float val = clamp(distance + afwidth / (2.0 * afwidth), 0.0, 1.
0);"); | 173 "float val = clamp(distance + afwidth / (2.0 * afwidth), 0.0, 1.
0);"); |
175 } else { | 174 } else { |
176 fragBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, d
istance);"); | 175 fragBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, d
istance);"); |
177 } | 176 } |
178 | 177 |
179 fragBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); | 178 fragBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); |
180 } | 179 } |
181 | 180 |
182 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess
or& proc) override { | 181 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess
or& proc, |
| 182 FPCoordTransformIter&& transformIter) override { |
183 #ifdef SK_GAMMA_APPLY_TO_A8 | 183 #ifdef SK_GAMMA_APPLY_TO_A8 |
184 const GrDistanceFieldA8TextGeoProc& dfTexEffect = proc.cast<GrDistanceFi
eldA8TextGeoProc>(); | 184 const GrDistanceFieldA8TextGeoProc& dfTexEffect = proc.cast<GrDistanceFi
eldA8TextGeoProc>(); |
185 float distanceAdjust = dfTexEffect.getDistanceAdjust(); | 185 float distanceAdjust = dfTexEffect.getDistanceAdjust(); |
186 if (distanceAdjust != fDistanceAdjust) { | 186 if (distanceAdjust != fDistanceAdjust) { |
187 pdman.set1f(fDistanceAdjustUni, distanceAdjust); | 187 pdman.set1f(fDistanceAdjustUni, distanceAdjust); |
188 fDistanceAdjust = distanceAdjust; | 188 fDistanceAdjust = distanceAdjust; |
189 } | 189 } |
190 #endif | 190 #endif |
191 const GrDistanceFieldA8TextGeoProc& dfa8gp = proc.cast<GrDistanceFieldA8
TextGeoProc>(); | 191 const GrDistanceFieldA8TextGeoProc& dfa8gp = proc.cast<GrDistanceFieldA8
TextGeoProc>(); |
192 | 192 |
193 if (!dfa8gp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfa8g
p.viewMatrix())) { | 193 if (!dfa8gp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfa8g
p.viewMatrix())) { |
194 fViewMatrix = dfa8gp.viewMatrix(); | 194 fViewMatrix = dfa8gp.viewMatrix(); |
195 float viewMatrix[3 * 3]; | 195 float viewMatrix[3 * 3]; |
196 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); | 196 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
197 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 197 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
198 } | 198 } |
| 199 this->setTransformDataHelper(SkMatrix::I(), pdman, &transformIter); |
199 } | 200 } |
200 | 201 |
201 static inline void GenKey(const GrGeometryProcessor& gp, | 202 static inline void GenKey(const GrGeometryProcessor& gp, |
202 const GrGLSLCaps&, | 203 const GrGLSLCaps&, |
203 GrProcessorKeyBuilder* b) { | 204 GrProcessorKeyBuilder* b) { |
204 const GrDistanceFieldA8TextGeoProc& dfTexEffect = gp.cast<GrDistanceFiel
dA8TextGeoProc>(); | 205 const GrDistanceFieldA8TextGeoProc& dfTexEffect = gp.cast<GrDistanceFiel
dA8TextGeoProc>(); |
205 uint32_t key = dfTexEffect.getFlags(); | 206 uint32_t key = dfTexEffect.getFlags(); |
206 key |= dfTexEffect.colorIgnored() << 16; | 207 key |= dfTexEffect.colorIgnored() << 16; |
207 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; | 208 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
208 b->add32(key); | 209 b->add32(key); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 dfTexEffect.inPosition()->fName, | 339 dfTexEffect.inPosition()->fName, |
339 dfTexEffect.viewMatrix(), | 340 dfTexEffect.viewMatrix(), |
340 &fViewMatrixUniform); | 341 &fViewMatrixUniform); |
341 | 342 |
342 // emit transforms | 343 // emit transforms |
343 this->emitTransforms(vertBuilder, | 344 this->emitTransforms(vertBuilder, |
344 varyingHandler, | 345 varyingHandler, |
345 uniformHandler, | 346 uniformHandler, |
346 gpArgs->fPositionVar, | 347 gpArgs->fPositionVar, |
347 dfTexEffect.inPosition()->fName, | 348 dfTexEffect.inPosition()->fName, |
348 args.fTransformsIn, | 349 args.fFPCoordTransformHandler); |
349 args.fTransformsOut); | |
350 | 350 |
351 const char* textureSizeUniName = nullptr; | 351 const char* textureSizeUniName = nullptr; |
352 fTextureSizeUni = uniformHandler->addUniform(kFragment_GrShaderFlag, | 352 fTextureSizeUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
353 kVec2f_GrSLType, kDefault_G
rSLPrecision, | 353 kVec2f_GrSLType, kDefault_G
rSLPrecision, |
354 "TextureSize", &textureSize
UniName); | 354 "TextureSize", &textureSize
UniName); |
355 | 355 |
356 // Use highp to work around aliasing issues | 356 // Use highp to work around aliasing issues |
357 fragBuilder->appendPrecisionModifier(kHigh_GrSLPrecision); | 357 fragBuilder->appendPrecisionModifier(kHigh_GrSLPrecision); |
358 fragBuilder->codeAppendf("vec2 uv = %s;", v.fsIn()); | 358 fragBuilder->codeAppendf("vec2 uv = %s;", v.fsIn()); |
359 | 359 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 if (isGammaCorrect) { | 426 if (isGammaCorrect) { |
427 fragBuilder->codeAppend( | 427 fragBuilder->codeAppend( |
428 "float val = clamp(distance + afwidth / (2.0 * afwidth), 0.0, 1.
0);"); | 428 "float val = clamp(distance + afwidth / (2.0 * afwidth), 0.0, 1.
0);"); |
429 } else { | 429 } else { |
430 fragBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, d
istance);"); | 430 fragBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, d
istance);"); |
431 } | 431 } |
432 | 432 |
433 fragBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); | 433 fragBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); |
434 } | 434 } |
435 | 435 |
436 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess
or& proc) override { | 436 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess
or& proc, |
| 437 FPCoordTransformIter&& transformIter) override { |
437 SkASSERT(fTextureSizeUni.isValid()); | 438 SkASSERT(fTextureSizeUni.isValid()); |
438 | 439 |
439 GrTexture* texture = proc.texture(0); | 440 GrTexture* texture = proc.texture(0); |
440 if (texture->width() != fTextureSize.width() || | 441 if (texture->width() != fTextureSize.width() || |
441 texture->height() != fTextureSize.height()) { | 442 texture->height() != fTextureSize.height()) { |
442 fTextureSize = SkISize::Make(texture->width(), texture->height()); | 443 fTextureSize = SkISize::Make(texture->width(), texture->height()); |
443 pdman.set2f(fTextureSizeUni, | 444 pdman.set2f(fTextureSizeUni, |
444 SkIntToScalar(fTextureSize.width()), | 445 SkIntToScalar(fTextureSize.width()), |
445 SkIntToScalar(fTextureSize.height())); | 446 SkIntToScalar(fTextureSize.height())); |
446 } | 447 } |
447 | 448 |
448 const GrDistanceFieldPathGeoProc& dfpgp = proc.cast<GrDistanceFieldPathG
eoProc>(); | 449 const GrDistanceFieldPathGeoProc& dfpgp = proc.cast<GrDistanceFieldPathG
eoProc>(); |
449 | 450 |
450 if (!dfpgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfpgp.
viewMatrix())) { | 451 if (!dfpgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfpgp.
viewMatrix())) { |
451 fViewMatrix = dfpgp.viewMatrix(); | 452 fViewMatrix = dfpgp.viewMatrix(); |
452 float viewMatrix[3 * 3]; | 453 float viewMatrix[3 * 3]; |
453 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); | 454 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
454 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 455 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
455 } | 456 } |
| 457 this->setTransformDataHelper(SkMatrix::I(), pdman, &transformIter); |
456 } | 458 } |
457 | 459 |
458 static inline void GenKey(const GrGeometryProcessor& gp, | 460 static inline void GenKey(const GrGeometryProcessor& gp, |
459 const GrGLSLCaps&, | 461 const GrGLSLCaps&, |
460 GrProcessorKeyBuilder* b) { | 462 GrProcessorKeyBuilder* b) { |
461 const GrDistanceFieldPathGeoProc& dfTexEffect = gp.cast<GrDistanceFieldP
athGeoProc>(); | 463 const GrDistanceFieldPathGeoProc& dfTexEffect = gp.cast<GrDistanceFieldP
athGeoProc>(); |
462 | 464 |
463 uint32_t key = dfTexEffect.getFlags(); | 465 uint32_t key = dfTexEffect.getFlags(); |
464 key |= dfTexEffect.colorIgnored() << 16; | 466 key |= dfTexEffect.colorIgnored() << 16; |
465 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; | 467 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 dfTexEffect.inPosition()->fName, | 577 dfTexEffect.inPosition()->fName, |
576 dfTexEffect.viewMatrix(), | 578 dfTexEffect.viewMatrix(), |
577 &fViewMatrixUniform); | 579 &fViewMatrixUniform); |
578 | 580 |
579 // emit transforms | 581 // emit transforms |
580 this->emitTransforms(vertBuilder, | 582 this->emitTransforms(vertBuilder, |
581 varyingHandler, | 583 varyingHandler, |
582 uniformHandler, | 584 uniformHandler, |
583 gpArgs->fPositionVar, | 585 gpArgs->fPositionVar, |
584 dfTexEffect.inPosition()->fName, | 586 dfTexEffect.inPosition()->fName, |
585 args.fTransformsIn, | 587 args.fFPCoordTransformHandler); |
586 args.fTransformsOut); | |
587 | 588 |
588 // set up varyings | 589 // set up varyings |
589 bool isUniformScale = (dfTexEffect.getFlags() & kUniformScale_DistanceFi
eldEffectMask) == | 590 bool isUniformScale = (dfTexEffect.getFlags() & kUniformScale_DistanceFi
eldEffectMask) == |
590 kUniformScale_DistanceFieldEffectMask; | 591 kUniformScale_DistanceFieldEffectMask; |
591 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan
ceFieldEffectFlag); | 592 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan
ceFieldEffectFlag); |
592 bool isGammaCorrect = | 593 bool isGammaCorrect = |
593 SkToBool(dfTexEffect.getFlags() & kGammaCorrect_DistanceFieldEffectF
lag); | 594 SkToBool(dfTexEffect.getFlags() & kGammaCorrect_DistanceFieldEffectF
lag); |
594 GrGLSLVertToFrag recipScale(kFloat_GrSLType); | 595 GrGLSLVertToFrag recipScale(kFloat_GrSLType); |
595 GrGLSLVertToFrag uv(kVec2f_GrSLType); | 596 GrGLSLVertToFrag uv(kVec2f_GrSLType); |
596 varyingHandler->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); | 597 varyingHandler->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 fragBuilder->codeAppend( | 726 fragBuilder->codeAppend( |
726 "vec4 val = vec4(smoothstep(vec3(-afwidth), vec3(afwidth), dista
nce), 1.0);"); | 727 "vec4 val = vec4(smoothstep(vec3(-afwidth), vec3(afwidth), dista
nce), 1.0);"); |
727 } | 728 } |
728 | 729 |
729 // set alpha to be max of rgb coverage | 730 // set alpha to be max of rgb coverage |
730 fragBuilder->codeAppend("val.a = max(max(val.r, val.g), val.b);"); | 731 fragBuilder->codeAppend("val.a = max(max(val.r, val.g), val.b);"); |
731 | 732 |
732 fragBuilder->codeAppendf("%s = val;", args.fOutputCoverage); | 733 fragBuilder->codeAppendf("%s = val;", args.fOutputCoverage); |
733 } | 734 } |
734 | 735 |
735 void setData(const GrGLSLProgramDataManager& pdman, | 736 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess
or& processor, |
736 const GrPrimitiveProcessor& processor) override { | 737 FPCoordTransformIter&& transformIter) override { |
737 SkASSERT(fDistanceAdjustUni.isValid()); | 738 SkASSERT(fDistanceAdjustUni.isValid()); |
738 | 739 |
739 const GrDistanceFieldLCDTextGeoProc& dflcd = processor.cast<GrDistanceFi
eldLCDTextGeoProc>(); | 740 const GrDistanceFieldLCDTextGeoProc& dflcd = processor.cast<GrDistanceFi
eldLCDTextGeoProc>(); |
740 GrDistanceFieldLCDTextGeoProc::DistanceAdjust wa = dflcd.getDistanceAdju
st(); | 741 GrDistanceFieldLCDTextGeoProc::DistanceAdjust wa = dflcd.getDistanceAdju
st(); |
741 if (wa != fDistanceAdjust) { | 742 if (wa != fDistanceAdjust) { |
742 pdman.set3f(fDistanceAdjustUni, | 743 pdman.set3f(fDistanceAdjustUni, |
743 wa.fR, | 744 wa.fR, |
744 wa.fG, | 745 wa.fG, |
745 wa.fB); | 746 wa.fB); |
746 fDistanceAdjust = wa; | 747 fDistanceAdjust = wa; |
747 } | 748 } |
748 | 749 |
749 if (!dflcd.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dflcd.
viewMatrix())) { | 750 if (!dflcd.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dflcd.
viewMatrix())) { |
750 fViewMatrix = dflcd.viewMatrix(); | 751 fViewMatrix = dflcd.viewMatrix(); |
751 float viewMatrix[3 * 3]; | 752 float viewMatrix[3 * 3]; |
752 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); | 753 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
753 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 754 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
754 } | 755 } |
| 756 this->setTransformDataHelper(SkMatrix::I(), pdman, &transformIter); |
755 } | 757 } |
756 | 758 |
757 static inline void GenKey(const GrGeometryProcessor& gp, | 759 static inline void GenKey(const GrGeometryProcessor& gp, |
758 const GrGLSLCaps&, | 760 const GrGLSLCaps&, |
759 GrProcessorKeyBuilder* b) { | 761 GrProcessorKeyBuilder* b) { |
760 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = gp.cast<GrDistanceFie
ldLCDTextGeoProc>(); | 762 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = gp.cast<GrDistanceFie
ldLCDTextGeoProc>(); |
761 | 763 |
762 uint32_t key = dfTexEffect.getFlags(); | 764 uint32_t key = dfTexEffect.getFlags(); |
763 key |= dfTexEffect.colorIgnored() << 16; | 765 key |= dfTexEffect.colorIgnored() << 16; |
764 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; | 766 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 flags |= d->fRandom->nextBool() ? kScaleOnly_DistanceFieldEffectFlag : 0
; | 841 flags |= d->fRandom->nextBool() ? kScaleOnly_DistanceFieldEffectFlag : 0
; |
840 } | 842 } |
841 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 843 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
842 return GrDistanceFieldLCDTextGeoProc::Make(GrRandomColor(d->fRandom), | 844 return GrDistanceFieldLCDTextGeoProc::Make(GrRandomColor(d->fRandom), |
843 GrTest::TestMatrix(d->fRandom), | 845 GrTest::TestMatrix(d->fRandom), |
844 d->fTextures[texIdx], params, | 846 d->fTextures[texIdx], params, |
845 wa, | 847 wa, |
846 flags, | 848 flags, |
847 d->fRandom->nextBool()); | 849 d->fRandom->nextBool()); |
848 } | 850 } |
OLD | NEW |