| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 pb->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(pb->glslCaps(), kHi
gh_GrSLPrecision)); | 93 fsBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(pb->glslCaps(), |
| 94 kHigh_GrSLPrecisi
on)); |
| 94 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); | 95 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); |
| 95 | 96 |
| 96 fsBuilder->codeAppend("\tfloat texColor = "); | 97 fsBuilder->codeAppend("\tfloat texColor = "); |
| 97 fsBuilder->appendTextureLookup(args.fSamplers[0], | 98 fsBuilder->appendTextureLookup(args.fSamplers[0], |
| 98 "uv", | 99 "uv", |
| 99 kVec2f_GrSLType); | 100 kVec2f_GrSLType); |
| 100 fsBuilder->codeAppend(".r;\n"); | 101 fsBuilder->codeAppend(".r;\n"); |
| 101 fsBuilder->codeAppend("\tfloat distance = " | 102 fsBuilder->codeAppend("\tfloat distance = " |
| 102 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFie
ldThreshold ");"); | 103 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFie
ldThreshold ");"); |
| 103 #ifdef SK_GAMMA_APPLY_TO_A8 | 104 #ifdef SK_GAMMA_APPLY_TO_A8 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 // emit transforms | 313 // emit transforms |
| 313 this->emitTransforms(pb, gpArgs->fPositionVar, dfTexEffect.inPosition()-
>fName, | 314 this->emitTransforms(pb, gpArgs->fPositionVar, dfTexEffect.inPosition()-
>fName, |
| 314 args.fTransformsIn, args.fTransformsOut); | 315 args.fTransformsIn, args.fTransformsOut); |
| 315 | 316 |
| 316 const char* textureSizeUniName = nullptr; | 317 const char* textureSizeUniName = nullptr; |
| 317 fTextureSizeUni = pb->addUniform(GrGLProgramBuilder::kFragment_Visibilit
y, | 318 fTextureSizeUni = pb->addUniform(GrGLProgramBuilder::kFragment_Visibilit
y, |
| 318 kVec2f_GrSLType, kDefault_GrSLPrecision
, | 319 kVec2f_GrSLType, kDefault_GrSLPrecision
, |
| 319 "TextureSize", &textureSizeUniName); | 320 "TextureSize", &textureSizeUniName); |
| 320 | 321 |
| 321 // Use highp to work around aliasing issues | 322 // Use highp to work around aliasing issues |
| 322 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(pb->glslCaps(), kHi
gh_GrSLPrecision)); | 323 fsBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(pb->glslCaps(), |
| 324 kHigh_GrSLPrecisi
on)); |
| 323 fsBuilder->codeAppendf("vec2 uv = %s;", v.fsIn()); | 325 fsBuilder->codeAppendf("vec2 uv = %s;", v.fsIn()); |
| 324 | 326 |
| 325 fsBuilder->codeAppend("float texColor = "); | 327 fsBuilder->codeAppend("float texColor = "); |
| 326 fsBuilder->appendTextureLookup(args.fSamplers[0], | 328 fsBuilder->appendTextureLookup(args.fSamplers[0], |
| 327 "uv", | 329 "uv", |
| 328 kVec2f_GrSLType); | 330 kVec2f_GrSLType); |
| 329 fsBuilder->codeAppend(".r;"); | 331 fsBuilder->codeAppend(".r;"); |
| 330 fsBuilder->codeAppend("float distance = " | 332 fsBuilder->codeAppend("float distance = " |
| 331 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFieldThreshold
");"); | 333 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFieldThreshold
");"); |
| 332 | 334 |
| 333 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(pb->glslCaps(), kHi
gh_GrSLPrecision)); | 335 fsBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(pb->glslCaps(), |
| 336 kHigh_GrSLPrecisi
on)); |
| 334 fsBuilder->codeAppendf("vec2 st = uv*%s;", textureSizeUniName); | 337 fsBuilder->codeAppendf("vec2 st = uv*%s;", textureSizeUniName); |
| 335 fsBuilder->codeAppend("float afwidth;"); | 338 fsBuilder->codeAppend("float afwidth;"); |
| 336 if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) { | 339 if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) { |
| 337 // For uniform scale, we adjust for the effect of the transformation
on the distance | 340 // For uniform scale, we adjust for the effect of the transformation
on the distance |
| 338 // by using the length of the gradient of the texture coordinates. W
e use st coordinates | 341 // by using the length of the gradient of the texture coordinates. W
e use st coordinates |
| 339 // to ensure we're mapping 1:1 from texel space to pixel space. | 342 // to ensure we're mapping 1:1 from texel space to pixel space. |
| 340 | 343 |
| 341 // this gives us a smooth step across approximately one fragment | 344 // this gives us a smooth step across approximately one fragment |
| 342 fsBuilder->codeAppend("afwidth = abs(" SK_DistanceFieldAAFactor "*dF
dy(st.y));"); | 345 fsBuilder->codeAppend("afwidth = abs(" SK_DistanceFieldAAFactor "*dF
dy(st.y));"); |
| 343 } else { | 346 } else { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 dfTexEffect.inTextureCoords()->fName); | 540 dfTexEffect.inTextureCoords()->fName); |
| 538 | 541 |
| 539 // add frag shader code | 542 // add frag shader code |
| 540 GrGLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); | 543 GrGLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); |
| 541 | 544 |
| 542 SkAssertResult(fsBuilder->enableFeature( | 545 SkAssertResult(fsBuilder->enableFeature( |
| 543 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); | 546 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
| 544 | 547 |
| 545 // create LCD offset adjusted by inverse of transform | 548 // create LCD offset adjusted by inverse of transform |
| 546 // Use highp to work around aliasing issues | 549 // Use highp to work around aliasing issues |
| 547 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(pb->glslCaps(), kHi
gh_GrSLPrecision)); | 550 fsBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(pb->glslCaps(), |
| 551 kHigh_GrSLPrecisi
on)); |
| 548 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); | 552 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); |
| 549 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(pb->glslCaps(), kHi
gh_GrSLPrecision)); | 553 fsBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(pb->glslCaps(), |
| 554 kHigh_GrSLPrecisi
on)); |
| 550 | 555 |
| 551 SkScalar lcdDelta = 1.0f / (3.0f * atlas->width()); | 556 SkScalar lcdDelta = 1.0f / (3.0f * atlas->width()); |
| 552 if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) { | 557 if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) { |
| 553 fsBuilder->codeAppendf("float delta = -%.*f;\n", SK_FLT_DECIMAL_DIG,
lcdDelta); | 558 fsBuilder->codeAppendf("float delta = -%.*f;\n", SK_FLT_DECIMAL_DIG,
lcdDelta); |
| 554 } else { | 559 } else { |
| 555 fsBuilder->codeAppendf("float delta = %.*f;\n", SK_FLT_DECIMAL_DIG,
lcdDelta); | 560 fsBuilder->codeAppendf("float delta = %.*f;\n", SK_FLT_DECIMAL_DIG,
lcdDelta); |
| 556 } | 561 } |
| 557 if (isUniformScale) { | 562 if (isUniformScale) { |
| 558 fsBuilder->codeAppendf("float dy = abs(dFdy(%s.y));", st.fsIn()); | 563 fsBuilder->codeAppendf("float dy = abs(dFdy(%s.y));", st.fsIn()); |
| 559 fsBuilder->codeAppend("vec2 offset = vec2(dy*delta, 0.0);"); | 564 fsBuilder->codeAppend("vec2 offset = vec2(dy*delta, 0.0);"); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 750 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; |
| 746 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 751 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; |
| 747 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 752 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
| 748 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), | 753 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), |
| 749 GrTest::TestMatrix(d->fRandom), | 754 GrTest::TestMatrix(d->fRandom), |
| 750 d->fTextures[texIdx], params, | 755 d->fTextures[texIdx], params, |
| 751 wa, | 756 wa, |
| 752 flags, | 757 flags, |
| 753 d->fRandom->nextBool()); | 758 d->fRandom->nextBool()); |
| 754 } | 759 } |
| OLD | NEW |