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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 SkScalar recipHeight = 1.0f / atlas->height(); | 93 SkScalar recipHeight = 1.0f / atlas->height(); |
94 | 94 |
95 GrGLSLVertToFrag uv(kVec2f_GrSLType); | 95 GrGLSLVertToFrag uv(kVec2f_GrSLType); |
96 pb->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); | 96 pb->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); |
97 vertBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), | 97 vertBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), |
98 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipWidth, | 98 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipWidth, |
99 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipHeight, | 99 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipHeight, |
100 dfTexEffect.inTextureCoords()->fName); | 100 dfTexEffect.inTextureCoords()->fName); |
101 | 101 |
102 // Use highp to work around aliasing issues | 102 // Use highp to work around aliasing issues |
103 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(pb->glslCaps(), | 103 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps, |
104 kHigh_GrSLPreci
sion)); | 104 kHigh_GrSLPreci
sion)); |
105 fragBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); | 105 fragBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); |
106 | 106 |
107 fragBuilder->codeAppend("\tfloat texColor = "); | 107 fragBuilder->codeAppend("\tfloat texColor = "); |
108 fragBuilder->appendTextureLookup(args.fSamplers[0], | 108 fragBuilder->appendTextureLookup(args.fSamplers[0], |
109 "uv", | 109 "uv", |
110 kVec2f_GrSLType); | 110 kVec2f_GrSLType); |
111 fragBuilder->codeAppend(".r;\n"); | 111 fragBuilder->codeAppend(".r;\n"); |
112 fragBuilder->codeAppend("\tfloat distance = " | 112 fragBuilder->codeAppend("\tfloat distance = " |
113 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFie
ldThreshold ");"); | 113 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFie
ldThreshold ");"); |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 dfTexEffect.inPosition()->fName, | 331 dfTexEffect.inPosition()->fName, |
332 args.fTransformsIn, | 332 args.fTransformsIn, |
333 args.fTransformsOut); | 333 args.fTransformsOut); |
334 | 334 |
335 const char* textureSizeUniName = nullptr; | 335 const char* textureSizeUniName = nullptr; |
336 fTextureSizeUni = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibil
ity, | 336 fTextureSizeUni = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibil
ity, |
337 kVec2f_GrSLType, kDefault_GrSLPrecision
, | 337 kVec2f_GrSLType, kDefault_GrSLPrecision
, |
338 "TextureSize", &textureSizeUniName); | 338 "TextureSize", &textureSizeUniName); |
339 | 339 |
340 // Use highp to work around aliasing issues | 340 // Use highp to work around aliasing issues |
341 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(pb->glslCaps(), | 341 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps, |
342 kHigh_GrSLPreci
sion)); | 342 kHigh_GrSLPreci
sion)); |
343 fragBuilder->codeAppendf("vec2 uv = %s;", v.fsIn()); | 343 fragBuilder->codeAppendf("vec2 uv = %s;", v.fsIn()); |
344 | 344 |
345 fragBuilder->codeAppend("float texColor = "); | 345 fragBuilder->codeAppend("float texColor = "); |
346 fragBuilder->appendTextureLookup(args.fSamplers[0], | 346 fragBuilder->appendTextureLookup(args.fSamplers[0], |
347 "uv", | 347 "uv", |
348 kVec2f_GrSLType); | 348 kVec2f_GrSLType); |
349 fragBuilder->codeAppend(".r;"); | 349 fragBuilder->codeAppend(".r;"); |
350 fragBuilder->codeAppend("float distance = " | 350 fragBuilder->codeAppend("float distance = " |
351 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFieldThreshold
");"); | 351 SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFieldThreshold
");"); |
352 | 352 |
353 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(pb->glslCaps(), | 353 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps, |
354 kHigh_GrSLPreci
sion)); | 354 kHigh_GrSLPreci
sion)); |
355 fragBuilder->codeAppendf("vec2 st = uv*%s;", textureSizeUniName); | 355 fragBuilder->codeAppendf("vec2 st = uv*%s;", textureSizeUniName); |
356 fragBuilder->codeAppend("float afwidth;"); | 356 fragBuilder->codeAppend("float afwidth;"); |
357 if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) { | 357 if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) { |
358 // For uniform scale, we adjust for the effect of the transformation
on the distance | 358 // For uniform scale, we adjust for the effect of the transformation
on the distance |
359 // by using the length of the gradient of the texture coordinates. W
e use st coordinates | 359 // by using the length of the gradient of the texture coordinates. W
e use st coordinates |
360 // to ensure we're mapping 1:1 from texel space to pixel space. | 360 // to ensure we're mapping 1:1 from texel space to pixel space. |
361 | 361 |
362 // this gives us a smooth step across approximately one fragment | 362 // this gives us a smooth step across approximately one fragment |
363 fragBuilder->codeAppend("afwidth = abs(" SK_DistanceFieldAAFactor "*
dFdy(st.y));"); | 363 fragBuilder->codeAppend("afwidth = abs(" SK_DistanceFieldAAFactor "*
dFdy(st.y));"); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipHeight, | 567 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipHeight, |
568 dfTexEffect.inTextureCoords()->fName); | 568 dfTexEffect.inTextureCoords()->fName); |
569 | 569 |
570 // add frag shader code | 570 // add frag shader code |
571 | 571 |
572 SkAssertResult(fragBuilder->enableFeature( | 572 SkAssertResult(fragBuilder->enableFeature( |
573 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); | 573 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
574 | 574 |
575 // create LCD offset adjusted by inverse of transform | 575 // create LCD offset adjusted by inverse of transform |
576 // Use highp to work around aliasing issues | 576 // Use highp to work around aliasing issues |
577 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(pb->glslCaps(), | 577 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps, |
578 kHigh_GrSLPreci
sion)); | 578 kHigh_GrSLPreci
sion)); |
579 fragBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); | 579 fragBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); |
580 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(pb->glslCaps(), | 580 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps, |
581 kHigh_GrSLPreci
sion)); | 581 kHigh_GrSLPreci
sion)); |
582 | 582 |
583 SkScalar lcdDelta = 1.0f / (3.0f * atlas->width()); | 583 SkScalar lcdDelta = 1.0f / (3.0f * atlas->width()); |
584 if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) { | 584 if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) { |
585 fragBuilder->codeAppendf("float delta = -%.*f;\n", SK_FLT_DECIMAL_DI
G, lcdDelta); | 585 fragBuilder->codeAppendf("float delta = -%.*f;\n", SK_FLT_DECIMAL_DI
G, lcdDelta); |
586 } else { | 586 } else { |
587 fragBuilder->codeAppendf("float delta = %.*f;\n", SK_FLT_DECIMAL_DIG
, lcdDelta); | 587 fragBuilder->codeAppendf("float delta = %.*f;\n", SK_FLT_DECIMAL_DIG
, lcdDelta); |
588 } | 588 } |
589 if (isUniformScale) { | 589 if (isUniformScale) { |
590 fragBuilder->codeAppendf("float dy = abs(dFdy(%s.y));", st.fsIn()); | 590 fragBuilder->codeAppendf("float dy = abs(dFdy(%s.y));", st.fsIn()); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 777 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; |
778 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 778 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; |
779 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 779 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
780 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), | 780 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), |
781 GrTest::TestMatrix(d->fRandom), | 781 GrTest::TestMatrix(d->fRandom), |
782 d->fTextures[texIdx], params, | 782 d->fTextures[texIdx], params, |
783 wa, | 783 wa, |
784 flags, | 784 flags, |
785 d->fRandom->nextBool()); | 785 d->fRandom->nextBool()); |
786 } | 786 } |
OLD | NEW |