| 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 "GrDistanceFieldTextureEffect.h" | 8 #include "GrDistanceFieldTextureEffect.h" |
| 9 #include "GrFontAtlasSizes.h" | 9 #include "GrFontAtlasSizes.h" |
| 10 #include "GrInvariantOutput.h" | 10 #include "GrInvariantOutput.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 class GrGLDistanceFieldTextureEffect : public GrGLGeometryProcessor { | 28 class GrGLDistanceFieldTextureEffect : public GrGLGeometryProcessor { |
| 29 public: | 29 public: |
| 30 GrGLDistanceFieldTextureEffect(const GrGeometryProcessor&, | 30 GrGLDistanceFieldTextureEffect(const GrGeometryProcessor&, |
| 31 const GrBatchTracker&) | 31 const GrBatchTracker&) |
| 32 : fColor(GrColor_ILLEGAL) | 32 : fColor(GrColor_ILLEGAL) |
| 33 #ifdef SK_GAMMA_APPLY_TO_A8 | 33 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 34 , fLuminance(-1.0f) | 34 , fLuminance(-1.0f) |
| 35 #endif | 35 #endif |
| 36 {} | 36 {} |
| 37 | 37 |
| 38 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{ | 38 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
| 39 const GrDistanceFieldTextureEffect& dfTexEffect = | 39 const GrDistanceFieldTextureEffect& dfTexEffect = |
| 40 args.fGP.cast<GrDistanceFieldTextureEffect>(); | 40 args.fGP.cast<GrDistanceFieldTextureEffect>(); |
| 41 const DistanceFieldBatchTracker& local = args.fBT.cast<DistanceFieldBatc
hTracker>(); | 41 const DistanceFieldBatchTracker& local = args.fBT.cast<DistanceFieldBatc
hTracker>(); |
| 42 GrGLGPBuilder* pb = args.fPB; | 42 GrGLGPBuilder* pb = args.fPB; |
| 43 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 43 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 44 SkAssertResult(fsBuilder->enableFeature( | 44 SkAssertResult(fsBuilder->enableFeature( |
| 45 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); | 45 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
| 46 | 46 |
| 47 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 47 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 48 | 48 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType)
; | 132 fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType)
; |
| 133 fsBuilder->codeAppend(";\n"); | 133 fsBuilder->codeAppend(";\n"); |
| 134 fsBuilder->codeAppend("\tval = gammaColor.r;\n"); | 134 fsBuilder->codeAppend("\tval = gammaColor.r;\n"); |
| 135 #endif | 135 #endif |
| 136 | 136 |
| 137 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); | 137 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); |
| 138 } | 138 } |
| 139 | 139 |
| 140 virtual void setData(const GrGLProgramDataManager& pdman, | 140 virtual void setData(const GrGLProgramDataManager& pdman, |
| 141 const GrPrimitiveProcessor& proc, | 141 const GrPrimitiveProcessor& proc, |
| 142 const GrBatchTracker& bt) SK_OVERRIDE { | 142 const GrBatchTracker& bt) override { |
| 143 #ifdef SK_GAMMA_APPLY_TO_A8 | 143 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 144 const GrDistanceFieldTextureEffect& dfTexEffect = | 144 const GrDistanceFieldTextureEffect& dfTexEffect = |
| 145 proc.cast<GrDistanceFieldTextureEffect>(); | 145 proc.cast<GrDistanceFieldTextureEffect>(); |
| 146 float luminance = dfTexEffect.getLuminance(); | 146 float luminance = dfTexEffect.getLuminance(); |
| 147 if (luminance != fLuminance) { | 147 if (luminance != fLuminance) { |
| 148 pdman.set1f(fLuminanceUni, luminance); | 148 pdman.set1f(fLuminanceUni, luminance); |
| 149 fLuminance = luminance; | 149 fLuminance = luminance; |
| 150 } | 150 } |
| 151 #endif | 151 #endif |
| 152 | 152 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 GrColor fColor; | 312 GrColor fColor; |
| 313 bool fUsesLocalCoords; | 313 bool fUsesLocalCoords; |
| 314 }; | 314 }; |
| 315 | 315 |
| 316 class GrGLDistanceFieldNoGammaTextureEffect : public GrGLGeometryProcessor { | 316 class GrGLDistanceFieldNoGammaTextureEffect : public GrGLGeometryProcessor { |
| 317 public: | 317 public: |
| 318 GrGLDistanceFieldNoGammaTextureEffect(const GrGeometryProcessor&, | 318 GrGLDistanceFieldNoGammaTextureEffect(const GrGeometryProcessor&, |
| 319 const GrBatchTracker&) | 319 const GrBatchTracker&) |
| 320 : fColor(GrColor_ILLEGAL), fTextureSize(SkISize::Make(-1, -1)) {} | 320 : fColor(GrColor_ILLEGAL), fTextureSize(SkISize::Make(-1, -1)) {} |
| 321 | 321 |
| 322 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{ | 322 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
| 323 const GrDistanceFieldNoGammaTextureEffect& dfTexEffect = | 323 const GrDistanceFieldNoGammaTextureEffect& dfTexEffect = |
| 324 args.fGP.cast<GrDistanceFieldNoGammaTextureEffect>(); | 324 args.fGP.cast<GrDistanceFieldNoGammaTextureEffect>(); |
| 325 | 325 |
| 326 const DistanceFieldNoGammaBatchTracker& local = | 326 const DistanceFieldNoGammaBatchTracker& local = |
| 327 args.fBT.cast<DistanceFieldNoGammaBatchTracker>(); | 327 args.fBT.cast<DistanceFieldNoGammaBatchTracker>(); |
| 328 GrGLGPBuilder* pb = args.fPB; | 328 GrGLGPBuilder* pb = args.fPB; |
| 329 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 329 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 330 SkAssertResult(fsBuilder->enableFeature( | 330 SkAssertResult(fsBuilder->enableFeature( |
| 331 GrGLFragmentShaderBuilder::kStandardDerivat
ives_GLSLFeature)); | 331 GrGLFragmentShaderBuilder::kStandardDerivat
ives_GLSLFeature)); |
| 332 | 332 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 // this gives us a smooth step across approximately one fragment | 402 // this gives us a smooth step across approximately one fragment |
| 403 fsBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*length
(grad);"); | 403 fsBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*length
(grad);"); |
| 404 } | 404 } |
| 405 fsBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, distanc
e);"); | 405 fsBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, distanc
e);"); |
| 406 | 406 |
| 407 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); | 407 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); |
| 408 } | 408 } |
| 409 | 409 |
| 410 virtual void setData(const GrGLProgramDataManager& pdman, | 410 virtual void setData(const GrGLProgramDataManager& pdman, |
| 411 const GrPrimitiveProcessor& proc, | 411 const GrPrimitiveProcessor& proc, |
| 412 const GrBatchTracker& bt) SK_OVERRIDE { | 412 const GrBatchTracker& bt) override { |
| 413 SkASSERT(fTextureSizeUni.isValid()); | 413 SkASSERT(fTextureSizeUni.isValid()); |
| 414 | 414 |
| 415 GrTexture* texture = proc.texture(0); | 415 GrTexture* texture = proc.texture(0); |
| 416 if (texture->width() != fTextureSize.width() || | 416 if (texture->width() != fTextureSize.width() || |
| 417 texture->height() != fTextureSize.height()) { | 417 texture->height() != fTextureSize.height()) { |
| 418 fTextureSize = SkISize::Make(texture->width(), texture->height()); | 418 fTextureSize = SkISize::Make(texture->width(), texture->height()); |
| 419 pdman.set2f(fTextureSizeUni, | 419 pdman.set2f(fTextureSizeUni, |
| 420 SkIntToScalar(fTextureSize.width()), | 420 SkIntToScalar(fTextureSize.width()), |
| 421 SkIntToScalar(fTextureSize.height())); | 421 SkIntToScalar(fTextureSize.height())); |
| 422 } | 422 } |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 bool fUsesLocalCoords; | 559 bool fUsesLocalCoords; |
| 560 }; | 560 }; |
| 561 | 561 |
| 562 class GrGLDistanceFieldLCDTextureEffect : public GrGLGeometryProcessor { | 562 class GrGLDistanceFieldLCDTextureEffect : public GrGLGeometryProcessor { |
| 563 public: | 563 public: |
| 564 GrGLDistanceFieldLCDTextureEffect(const GrGeometryProcessor&, | 564 GrGLDistanceFieldLCDTextureEffect(const GrGeometryProcessor&, |
| 565 const GrBatchTracker&) | 565 const GrBatchTracker&) |
| 566 : fColor(GrColor_ILLEGAL) | 566 : fColor(GrColor_ILLEGAL) |
| 567 , fTextColor(GrColor_ILLEGAL) {} | 567 , fTextColor(GrColor_ILLEGAL) {} |
| 568 | 568 |
| 569 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{ | 569 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
| 570 const GrDistanceFieldLCDTextureEffect& dfTexEffect = | 570 const GrDistanceFieldLCDTextureEffect& dfTexEffect = |
| 571 args.fGP.cast<GrDistanceFieldLCDTextureEffect>(); | 571 args.fGP.cast<GrDistanceFieldLCDTextureEffect>(); |
| 572 const DistanceFieldLCDBatchTracker& local = args.fBT.cast<DistanceFieldL
CDBatchTracker>(); | 572 const DistanceFieldLCDBatchTracker& local = args.fBT.cast<DistanceFieldL
CDBatchTracker>(); |
| 573 GrGLGPBuilder* pb = args.fPB; | 573 GrGLGPBuilder* pb = args.fPB; |
| 574 | 574 |
| 575 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 575 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 576 | 576 |
| 577 // emit attributes | 577 // emit attributes |
| 578 vsBuilder->emitAttributes(dfTexEffect); | 578 vsBuilder->emitAttributes(dfTexEffect); |
| 579 | 579 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 fsBuilder->codeAppend("\tgammaColor = "); | 706 fsBuilder->codeAppend("\tgammaColor = "); |
| 707 fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType)
; | 707 fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType)
; |
| 708 fsBuilder->codeAppend(".r;\n"); | 708 fsBuilder->codeAppend(".r;\n"); |
| 709 fsBuilder->codeAppend("\tval.z = gammaColor;\n"); | 709 fsBuilder->codeAppend("\tval.z = gammaColor;\n"); |
| 710 | 710 |
| 711 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); | 711 fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); |
| 712 } | 712 } |
| 713 | 713 |
| 714 virtual void setData(const GrGLProgramDataManager& pdman, | 714 virtual void setData(const GrGLProgramDataManager& pdman, |
| 715 const GrPrimitiveProcessor& processor, | 715 const GrPrimitiveProcessor& processor, |
| 716 const GrBatchTracker& bt) SK_OVERRIDE { | 716 const GrBatchTracker& bt) override { |
| 717 SkASSERT(fTextColorUni.isValid()); | 717 SkASSERT(fTextColorUni.isValid()); |
| 718 | 718 |
| 719 const GrDistanceFieldLCDTextureEffect& dfTexEffect = | 719 const GrDistanceFieldLCDTextureEffect& dfTexEffect = |
| 720 processor.cast<GrDistanceFieldLCDTextureEffect>(); | 720 processor.cast<GrDistanceFieldLCDTextureEffect>(); |
| 721 GrColor textColor = dfTexEffect.getTextColor(); | 721 GrColor textColor = dfTexEffect.getTextColor(); |
| 722 if (textColor != fTextColor) { | 722 if (textColor != fTextColor) { |
| 723 static const float ONE_OVER_255 = 1.f / 255.f; | 723 static const float ONE_OVER_255 = 1.f / 255.f; |
| 724 pdman.set3f(fTextColorUni, | 724 pdman.set3f(fTextColorUni, |
| 725 GrColorUnpackR(textColor) * ONE_OVER_255, | 725 GrColorUnpackR(textColor) * ONE_OVER_255, |
| 726 GrColorUnpackG(textColor) * ONE_OVER_255, | 726 GrColorUnpackG(textColor) * ONE_OVER_255, |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 858 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; |
| 859 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 859 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; |
| 860 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 860 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
| 861 return GrDistanceFieldLCDTextureEffect::Create(GrRandomColor(random), | 861 return GrDistanceFieldLCDTextureEffect::Create(GrRandomColor(random), |
| 862 GrProcessorUnitTest::TestMatr
ix(random), | 862 GrProcessorUnitTest::TestMatr
ix(random), |
| 863 textures[texIdx], params, | 863 textures[texIdx], params, |
| 864 textures[texIdx2], params2, | 864 textures[texIdx2], params2, |
| 865 textColor, | 865 textColor, |
| 866 flags); | 866 flags); |
| 867 } | 867 } |
| OLD | NEW |