| 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 15 matching lines...) Expand all Loading... |
| 26 , fColor(GrColor_ILLEGAL) | 26 , fColor(GrColor_ILLEGAL) |
| 27 #ifdef SK_GAMMA_APPLY_TO_A8 | 27 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 28 , fDistanceAdjust(-1.0f) | 28 , fDistanceAdjust(-1.0f) |
| 29 #endif | 29 #endif |
| 30 {} | 30 {} |
| 31 | 31 |
| 32 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 32 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
| 33 const GrDistanceFieldA8TextGeoProc& dfTexEffect = | 33 const GrDistanceFieldA8TextGeoProc& dfTexEffect = |
| 34 args.fGP.cast<GrDistanceFieldA8TextGeoProc>(); | 34 args.fGP.cast<GrDistanceFieldA8TextGeoProc>(); |
| 35 GrGLGPBuilder* pb = args.fPB; | 35 GrGLGPBuilder* pb = args.fPB; |
| 36 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 36 GrGLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); |
| 37 SkAssertResult(fsBuilder->enableFeature( | 37 SkAssertResult(fsBuilder->enableFeature( |
| 38 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); | 38 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
| 39 | 39 |
| 40 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 40 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); |
| 41 | 41 |
| 42 // emit attributes | 42 // emit attributes |
| 43 vsBuilder->emitAttributes(dfTexEffect); | 43 vsBuilder->emitAttributes(dfTexEffect); |
| 44 | 44 |
| 45 #ifdef SK_GAMMA_APPLY_TO_A8 | 45 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 46 // adjust based on gamma | 46 // adjust based on gamma |
| 47 const char* distanceAdjustUniName = nullptr; | 47 const char* distanceAdjustUniName = nullptr; |
| 48 // width, height, 1/(3*width) | 48 // width, height, 1/(3*width) |
| 49 fDistanceAdjustUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_
Visibility, | 49 fDistanceAdjustUni = pb->addUniform(GrGLProgramBuilder::kFragment_Visibi
lity, |
| 50 kFloat_GrSLType, kDefault_GrSLPrecision, | 50 kFloat_GrSLType, kDefault_GrSLPrecision, |
| 51 "DistanceAdjust", &distanceAdjustUniName); | 51 "DistanceAdjust", &distanceAdjustUniName); |
| 52 #endif | 52 #endif |
| 53 | 53 |
| 54 // Setup pass through color | 54 // Setup pass through color |
| 55 if (!dfTexEffect.colorIgnored()) { | 55 if (!dfTexEffect.colorIgnored()) { |
| 56 if (dfTexEffect.hasVertexColor()) { | 56 if (dfTexEffect.hasVertexColor()) { |
| 57 pb->addPassThroughAttribute(dfTexEffect.inColor(), args.fOutputC
olor); | 57 pb->addPassThroughAttribute(dfTexEffect.inColor(), args.fOutputC
olor); |
| 58 } else { | 58 } else { |
| 59 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); | 59 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 // Setup position | 63 // Setup position |
| 64 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix(), | 64 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix(), |
| 65 &fViewMatrixUniform); | 65 &fViewMatrixUniform); |
| 66 | 66 |
| 67 // emit transforms | 67 // emit transforms |
| 68 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, | 68 this->emitTransforms(pb, gpArgs->fPositionVar, dfTexEffect.inPosition()-
>fName, |
| 69 args.fTransformsIn, args.fTransformsOut); | 69 args.fTransformsIn, args.fTransformsOut); |
| 70 | 70 |
| 71 // add varyings | 71 // add varyings |
| 72 GrGLVertToFrag recipScale(kFloat_GrSLType); | 72 GrGLVertToFrag recipScale(kFloat_GrSLType); |
| 73 GrGLVertToFrag st(kVec2f_GrSLType); | 73 GrGLVertToFrag st(kVec2f_GrSLType); |
| 74 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan
ceFieldEffectFlag); | 74 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan
ceFieldEffectFlag); |
| 75 args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); | 75 pb->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); |
| 76 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor
ds()->fName); | 76 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor
ds()->fName); |
| 77 | 77 |
| 78 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float | 78 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float |
| 79 SkASSERT(dfTexEffect.numTextures() == 1); | 79 SkASSERT(dfTexEffect.numTextures() == 1); |
| 80 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); | 80 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); |
| 81 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height()))
; | 81 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height()))
; |
| 82 SkScalar recipWidth = 1.0f / atlas->width(); | 82 SkScalar recipWidth = 1.0f / atlas->width(); |
| 83 SkScalar recipHeight = 1.0f / atlas->height(); | 83 SkScalar recipHeight = 1.0f / atlas->height(); |
| 84 | 84 |
| 85 GrGLVertToFrag uv(kVec2f_GrSLType); | 85 GrGLVertToFrag uv(kVec2f_GrSLType); |
| 86 args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); | 86 pb->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); |
| 87 vsBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), | 87 vsBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), |
| 88 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipWidth, | 88 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipWidth, |
| 89 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipHeight, | 89 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipHeight, |
| 90 dfTexEffect.inTextureCoords()->fName); | 90 dfTexEffect.inTextureCoords()->fName); |
| 91 | 91 |
| 92 // Use highp to work around aliasing issues | 92 // Use highp to work around aliasing issues |
| 93 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, | 93 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(pb->glslCaps(), kHi
gh_GrSLPrecision)); |
| 94 pb->ctxInfo().stand
ard())); | |
| 95 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); | 94 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); |
| 96 | 95 |
| 97 fsBuilder->codeAppend("\tfloat texColor = "); | 96 fsBuilder->codeAppend("\tfloat texColor = "); |
| 98 fsBuilder->appendTextureLookup(args.fSamplers[0], | 97 fsBuilder->appendTextureLookup(args.fSamplers[0], |
| 99 "uv", | 98 "uv", |
| 100 kVec2f_GrSLType); | 99 kVec2f_GrSLType); |
| 101 fsBuilder->codeAppend(".r;\n"); | 100 fsBuilder->codeAppend(".r;\n"); |
| 102 fsBuilder->codeAppend("\tfloat distance = " | 101 fsBuilder->codeAppend("\tfloat distance = " |
| 103 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFie
ldThreshold ");"); | 102 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFie
ldThreshold ");"); |
| 104 #ifdef SK_GAMMA_APPLY_TO_A8 | 103 #ifdef SK_GAMMA_APPLY_TO_A8 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 public: | 276 public: |
| 278 GrGLDistanceFieldPathGeoProc() | 277 GrGLDistanceFieldPathGeoProc() |
| 279 : fViewMatrix(SkMatrix::InvalidMatrix()) | 278 : fViewMatrix(SkMatrix::InvalidMatrix()) |
| 280 , fColor(GrColor_ILLEGAL) | 279 , fColor(GrColor_ILLEGAL) |
| 281 , fTextureSize(SkISize::Make(-1, -1)) {} | 280 , fTextureSize(SkISize::Make(-1, -1)) {} |
| 282 | 281 |
| 283 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 282 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
| 284 const GrDistanceFieldPathGeoProc& dfTexEffect = args.fGP.cast<GrDistance
FieldPathGeoProc>(); | 283 const GrDistanceFieldPathGeoProc& dfTexEffect = args.fGP.cast<GrDistance
FieldPathGeoProc>(); |
| 285 | 284 |
| 286 GrGLGPBuilder* pb = args.fPB; | 285 GrGLGPBuilder* pb = args.fPB; |
| 287 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 286 GrGLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); |
| 288 SkAssertResult(fsBuilder->enableFeature( | 287 SkAssertResult(fsBuilder->enableFeature( |
| 289 GrGLFragmentShaderBuilder::kStandardDerivat
ives_GLSLFeature)); | 288 GrGLFragmentShaderBuilder::kStandardDerivat
ives_GLSLFeature)); |
| 290 | 289 |
| 291 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 290 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); |
| 292 | 291 |
| 293 // emit attributes | 292 // emit attributes |
| 294 vsBuilder->emitAttributes(dfTexEffect); | 293 vsBuilder->emitAttributes(dfTexEffect); |
| 295 | 294 |
| 296 GrGLVertToFrag v(kVec2f_GrSLType); | 295 GrGLVertToFrag v(kVec2f_GrSLType); |
| 297 args.fPB->addVarying("TextureCoords", &v, kHigh_GrSLPrecision); | 296 pb->addVarying("TextureCoords", &v, kHigh_GrSLPrecision); |
| 298 | 297 |
| 299 // setup pass through color | 298 // setup pass through color |
| 300 if (!dfTexEffect.colorIgnored()) { | 299 if (!dfTexEffect.colorIgnored()) { |
| 301 if (dfTexEffect.hasVertexColor()) { | 300 if (dfTexEffect.hasVertexColor()) { |
| 302 pb->addPassThroughAttribute(dfTexEffect.inColor(), args.fOutputC
olor); | 301 pb->addPassThroughAttribute(dfTexEffect.inColor(), args.fOutputC
olor); |
| 303 } else { | 302 } else { |
| 304 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); | 303 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); |
| 305 } | 304 } |
| 306 } | 305 } |
| 307 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoord
s()->fName); | 306 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoord
s()->fName); |
| 308 | 307 |
| 309 // Setup position | 308 // Setup position |
| 310 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix(), | 309 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix(), |
| 311 &fViewMatrixUniform); | 310 &fViewMatrixUniform); |
| 312 | 311 |
| 313 // emit transforms | 312 // emit transforms |
| 314 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, | 313 this->emitTransforms(pb, gpArgs->fPositionVar, dfTexEffect.inPosition()-
>fName, |
| 315 args.fTransformsIn, args.fTransformsOut); | 314 args.fTransformsIn, args.fTransformsOut); |
| 316 | 315 |
| 317 const char* textureSizeUniName = nullptr; | 316 const char* textureSizeUniName = nullptr; |
| 318 fTextureSizeUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Vis
ibility, | 317 fTextureSizeUni = pb->addUniform(GrGLProgramBuilder::kFragment_Visibilit
y, |
| 319 kVec2f_GrSLType, kDefault_GrSLPrec
ision, | 318 kVec2f_GrSLType, kDefault_GrSLPrecision
, |
| 320 "TextureSize", &textureSizeUniName
); | 319 "TextureSize", &textureSizeUniName); |
| 321 | 320 |
| 322 // Use highp to work around aliasing issues | 321 // Use highp to work around aliasing issues |
| 323 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, | 322 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(pb->glslCaps(), kHi
gh_GrSLPrecision)); |
| 324 pb->ctxInfo().stand
ard())); | |
| 325 fsBuilder->codeAppendf("vec2 uv = %s;", v.fsIn()); | 323 fsBuilder->codeAppendf("vec2 uv = %s;", v.fsIn()); |
| 326 | 324 |
| 327 fsBuilder->codeAppend("float texColor = "); | 325 fsBuilder->codeAppend("float texColor = "); |
| 328 fsBuilder->appendTextureLookup(args.fSamplers[0], | 326 fsBuilder->appendTextureLookup(args.fSamplers[0], |
| 329 "uv", | 327 "uv", |
| 330 kVec2f_GrSLType); | 328 kVec2f_GrSLType); |
| 331 fsBuilder->codeAppend(".r;"); | 329 fsBuilder->codeAppend(".r;"); |
| 332 fsBuilder->codeAppend("float distance = " | 330 fsBuilder->codeAppend("float distance = " |
| 333 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFieldThreshold
");"); | 331 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFieldThreshold
");"); |
| 334 | 332 |
| 335 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, | 333 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(pb->glslCaps(), kHi
gh_GrSLPrecision)); |
| 336 pb->ctxInfo().stand
ard())); | |
| 337 fsBuilder->codeAppendf("vec2 st = uv*%s;", textureSizeUniName); | 334 fsBuilder->codeAppendf("vec2 st = uv*%s;", textureSizeUniName); |
| 338 fsBuilder->codeAppend("float afwidth;"); | 335 fsBuilder->codeAppend("float afwidth;"); |
| 339 if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) { | 336 if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) { |
| 340 // For uniform scale, we adjust for the effect of the transformation
on the distance | 337 // For uniform scale, we adjust for the effect of the transformation
on the distance |
| 341 // by using the length of the gradient of the texture coordinates. W
e use st coordinates | 338 // by using the length of the gradient of the texture coordinates. W
e use st coordinates |
| 342 // to ensure we're mapping 1:1 from texel space to pixel space. | 339 // to ensure we're mapping 1:1 from texel space to pixel space. |
| 343 | 340 |
| 344 // this gives us a smooth step across approximately one fragment | 341 // this gives us a smooth step across approximately one fragment |
| 345 fsBuilder->codeAppend("afwidth = abs(" SK_DistanceFieldAAFactor "*dF
dy(st.y));"); | 342 fsBuilder->codeAppend("afwidth = abs(" SK_DistanceFieldAAFactor "*dF
dy(st.y));"); |
| 346 } else { | 343 } else { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 GrGLDistanceFieldLCDTextGeoProc() | 490 GrGLDistanceFieldLCDTextGeoProc() |
| 494 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL) { | 491 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL) { |
| 495 fDistanceAdjust = GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(1.
0f, 1.0f, 1.0f); | 492 fDistanceAdjust = GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(1.
0f, 1.0f, 1.0f); |
| 496 } | 493 } |
| 497 | 494 |
| 498 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 495 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
| 499 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = | 496 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = |
| 500 args.fGP.cast<GrDistanceFieldLCDTextGeoProc>(); | 497 args.fGP.cast<GrDistanceFieldLCDTextGeoProc>(); |
| 501 GrGLGPBuilder* pb = args.fPB; | 498 GrGLGPBuilder* pb = args.fPB; |
| 502 | 499 |
| 503 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 500 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); |
| 504 | 501 |
| 505 // emit attributes | 502 // emit attributes |
| 506 vsBuilder->emitAttributes(dfTexEffect); | 503 vsBuilder->emitAttributes(dfTexEffect); |
| 507 | 504 |
| 508 // setup pass through color | 505 // setup pass through color |
| 509 if (!dfTexEffect.colorIgnored()) { | 506 if (!dfTexEffect.colorIgnored()) { |
| 510 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); | 507 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); |
| 511 } | 508 } |
| 512 | 509 |
| 513 // Setup position | 510 // Setup position |
| 514 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix(), | 511 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix(), |
| 515 &fViewMatrixUniform); | 512 &fViewMatrixUniform); |
| 516 | 513 |
| 517 // emit transforms | 514 // emit transforms |
| 518 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, | 515 this->emitTransforms(pb, gpArgs->fPositionVar, dfTexEffect.inPosition()-
>fName, |
| 519 args.fTransformsIn, args.fTransformsOut); | 516 args.fTransformsIn, args.fTransformsOut); |
| 520 | 517 |
| 521 // set up varyings | 518 // set up varyings |
| 522 bool isUniformScale = SkToBool(dfTexEffect.getFlags() & kUniformScale_Di
stanceFieldEffectMask); | 519 bool isUniformScale = SkToBool(dfTexEffect.getFlags() & kUniformScale_Di
stanceFieldEffectMask); |
| 523 GrGLVertToFrag recipScale(kFloat_GrSLType); | 520 GrGLVertToFrag recipScale(kFloat_GrSLType); |
| 524 GrGLVertToFrag st(kVec2f_GrSLType); | 521 GrGLVertToFrag st(kVec2f_GrSLType); |
| 525 args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); | 522 pb->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); |
| 526 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor
ds()->fName); | 523 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor
ds()->fName); |
| 527 | 524 |
| 528 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float | 525 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float |
| 529 SkASSERT(dfTexEffect.numTextures() == 1); | 526 SkASSERT(dfTexEffect.numTextures() == 1); |
| 530 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); | 527 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); |
| 531 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height()))
; | 528 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height()))
; |
| 532 SkScalar recipWidth = 1.0f / atlas->width(); | 529 SkScalar recipWidth = 1.0f / atlas->width(); |
| 533 SkScalar recipHeight = 1.0f / atlas->height(); | 530 SkScalar recipHeight = 1.0f / atlas->height(); |
| 534 | 531 |
| 535 GrGLVertToFrag uv(kVec2f_GrSLType); | 532 GrGLVertToFrag uv(kVec2f_GrSLType); |
| 536 args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); | 533 pb->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); |
| 537 vsBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), | 534 vsBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), |
| 538 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipWidth, | 535 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipWidth, |
| 539 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipHeight, | 536 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipHeight, |
| 540 dfTexEffect.inTextureCoords()->fName); | 537 dfTexEffect.inTextureCoords()->fName); |
| 541 | 538 |
| 542 // add frag shader code | 539 // add frag shader code |
| 543 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 540 GrGLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); |
| 544 | 541 |
| 545 SkAssertResult(fsBuilder->enableFeature( | 542 SkAssertResult(fsBuilder->enableFeature( |
| 546 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); | 543 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
| 547 | 544 |
| 548 // create LCD offset adjusted by inverse of transform | 545 // create LCD offset adjusted by inverse of transform |
| 549 // Use highp to work around aliasing issues | 546 // Use highp to work around aliasing issues |
| 550 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, | 547 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(pb->glslCaps(), kHi
gh_GrSLPrecision)); |
| 551 pb->ctxInfo().stand
ard())); | |
| 552 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); | 548 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); |
| 553 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, | 549 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(pb->glslCaps(), kHi
gh_GrSLPrecision)); |
| 554 pb->ctxInfo().stand
ard())); | |
| 555 | 550 |
| 556 SkScalar lcdDelta = 1.0f / (3.0f * atlas->width()); | 551 SkScalar lcdDelta = 1.0f / (3.0f * atlas->width()); |
| 557 if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) { | 552 if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) { |
| 558 fsBuilder->codeAppendf("float delta = -%.*f;\n", SK_FLT_DECIMAL_DIG,
lcdDelta); | 553 fsBuilder->codeAppendf("float delta = -%.*f;\n", SK_FLT_DECIMAL_DIG,
lcdDelta); |
| 559 } else { | 554 } else { |
| 560 fsBuilder->codeAppendf("float delta = %.*f;\n", SK_FLT_DECIMAL_DIG,
lcdDelta); | 555 fsBuilder->codeAppendf("float delta = %.*f;\n", SK_FLT_DECIMAL_DIG,
lcdDelta); |
| 561 } | 556 } |
| 562 if (isUniformScale) { | 557 if (isUniformScale) { |
| 563 fsBuilder->codeAppendf("float dy = abs(dFdy(%s.y));", st.fsIn()); | 558 fsBuilder->codeAppendf("float dy = abs(dFdy(%s.y));", st.fsIn()); |
| 564 fsBuilder->codeAppend("vec2 offset = vec2(dy*delta, 0.0);"); | 559 fsBuilder->codeAppend("vec2 offset = vec2(dy*delta, 0.0);"); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 587 fsBuilder->codeAppend("\ttexColor = "); | 582 fsBuilder->codeAppend("\ttexColor = "); |
| 588 fsBuilder->appendTextureLookup(args.fSamplers[0], "uv_adjusted", kVec2f_
GrSLType); | 583 fsBuilder->appendTextureLookup(args.fSamplers[0], "uv_adjusted", kVec2f_
GrSLType); |
| 589 fsBuilder->codeAppend(";\n"); | 584 fsBuilder->codeAppend(";\n"); |
| 590 fsBuilder->codeAppend("\tdistance.z = texColor.r;\n"); | 585 fsBuilder->codeAppend("\tdistance.z = texColor.r;\n"); |
| 591 | 586 |
| 592 fsBuilder->codeAppend("\tdistance = " | 587 fsBuilder->codeAppend("\tdistance = " |
| 593 "vec3(" SK_DistanceFieldMultiplier ")*(distance - vec3(" SK_DistanceF
ieldThreshold"));"); | 588 "vec3(" SK_DistanceFieldMultiplier ")*(distance - vec3(" SK_DistanceF
ieldThreshold"));"); |
| 594 | 589 |
| 595 // adjust width based on gamma | 590 // adjust width based on gamma |
| 596 const char* distanceAdjustUniName = nullptr; | 591 const char* distanceAdjustUniName = nullptr; |
| 597 fDistanceAdjustUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_
Visibility, | 592 fDistanceAdjustUni = pb->addUniform(GrGLProgramBuilder::kFragment_Visibi
lity, |
| 598 kVec3f_GrSLType, kDefault_GrSLPrecision, | 593 kVec3f_GrSLType, kDefault_GrSLPrecision, |
| 599 "DistanceAdjust", &distanceAdjustUniName); | 594 "DistanceAdjust", &distanceAdjustUniName); |
| 600 fsBuilder->codeAppendf("distance -= %s;", distanceAdjustUniName); | 595 fsBuilder->codeAppendf("distance -= %s;", distanceAdjustUniName); |
| 601 | 596 |
| 602 // To be strictly correct, we should compute the anti-aliasing factor se
parately | 597 // To be strictly correct, we should compute the anti-aliasing factor se
parately |
| 603 // for each color component. However, this is only important when using
perspective | 598 // for each color component. However, this is only important when using
perspective |
| 604 // transformations, and even then using a single factor seems like a rea
sonable | 599 // transformations, and even then using a single factor seems like a rea
sonable |
| 605 // trade-off between quality and speed. | 600 // trade-off between quality and speed. |
| 606 fsBuilder->codeAppend("float afwidth;"); | 601 fsBuilder->codeAppend("float afwidth;"); |
| 607 if (isUniformScale) { | 602 if (isUniformScale) { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 745 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; |
| 751 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 746 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; |
| 752 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 747 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
| 753 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), | 748 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), |
| 754 GrTest::TestMatrix(d->fRandom), | 749 GrTest::TestMatrix(d->fRandom), |
| 755 d->fTextures[texIdx], params, | 750 d->fTextures[texIdx], params, |
| 756 wa, | 751 wa, |
| 757 flags, | 752 flags, |
| 758 d->fRandom->nextBool()); | 753 d->fRandom->nextBool()); |
| 759 } | 754 } |
| OLD | NEW |