| 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 "GrFontAtlasSizes.h" | 9 #include "GrFontAtlasSizes.h" |
| 10 #include "GrInvariantOutput.h" | 10 #include "GrInvariantOutput.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // add varyings | 73 // add varyings |
| 74 GrGLVertToFrag recipScale(kFloat_GrSLType); | 74 GrGLVertToFrag recipScale(kFloat_GrSLType); |
| 75 GrGLVertToFrag st(kVec2f_GrSLType); | 75 GrGLVertToFrag st(kVec2f_GrSLType); |
| 76 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan
ceFieldEffectFlag); | 76 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan
ceFieldEffectFlag); |
| 77 args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); | 77 args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); |
| 78 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor
ds()->fName); | 78 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor
ds()->fName); |
| 79 | 79 |
| 80 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float | 80 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float |
| 81 SkASSERT(dfTexEffect.numTextures() == 1); | 81 SkASSERT(dfTexEffect.numTextures() == 1); |
| 82 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); | 82 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); |
| 83 SkASSERT(atlas); | 83 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height()))
; |
| 84 SkScalar recipWidth = 1.0f / atlas->width(); | 84 SkScalar recipWidth = 1.0f / atlas->width(); |
| 85 SkScalar recipHeight = 1.0f / atlas->height(); | 85 SkScalar recipHeight = 1.0f / atlas->height(); |
| 86 | 86 |
| 87 GrGLVertToFrag uv(kVec2f_GrSLType); | 87 GrGLVertToFrag uv(kVec2f_GrSLType); |
| 88 args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); | 88 args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); |
| 89 vsBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), | 89 vsBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), |
| 90 SK_FLT_DECIMAL_DIG, recipWidth, | 90 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipWidth, |
| 91 SK_FLT_DECIMAL_DIG, recipHeight, | 91 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipHeight, |
| 92 dfTexEffect.inTextureCoords()->fName); | 92 dfTexEffect.inTextureCoords()->fName); |
| 93 | 93 |
| 94 // Use highp to work around aliasing issues | 94 // Use highp to work around aliasing issues |
| 95 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, | 95 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, |
| 96 pb->ctxInfo().stand
ard())); | 96 pb->ctxInfo().stand
ard())); |
| 97 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); | 97 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); |
| 98 | 98 |
| 99 fsBuilder->codeAppend("\tfloat texColor = "); | 99 fsBuilder->codeAppend("\tfloat texColor = "); |
| 100 fsBuilder->appendTextureLookup(args.fSamplers[0], | 100 fsBuilder->appendTextureLookup(args.fSamplers[0], |
| 101 "uv", | 101 "uv", |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 // set up varyings | 535 // set up varyings |
| 536 bool isUniformScale = SkToBool(dfTexEffect.getFlags() & kUniformScale_Di
stanceFieldEffectMask); | 536 bool isUniformScale = SkToBool(dfTexEffect.getFlags() & kUniformScale_Di
stanceFieldEffectMask); |
| 537 GrGLVertToFrag recipScale(kFloat_GrSLType); | 537 GrGLVertToFrag recipScale(kFloat_GrSLType); |
| 538 GrGLVertToFrag st(kVec2f_GrSLType); | 538 GrGLVertToFrag st(kVec2f_GrSLType); |
| 539 args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); | 539 args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); |
| 540 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor
ds()->fName); | 540 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor
ds()->fName); |
| 541 | 541 |
| 542 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float | 542 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float |
| 543 SkASSERT(dfTexEffect.numTextures() == 1); | 543 SkASSERT(dfTexEffect.numTextures() == 1); |
| 544 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); | 544 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); |
| 545 SkASSERT(atlas); | 545 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height()))
; |
| 546 SkScalar recipWidth = 1.0f / atlas->width(); | 546 SkScalar recipWidth = 1.0f / atlas->width(); |
| 547 SkScalar recipHeight = 1.0f / atlas->height(); | 547 SkScalar recipHeight = 1.0f / atlas->height(); |
| 548 | 548 |
| 549 GrGLVertToFrag uv(kVec2f_GrSLType); | 549 GrGLVertToFrag uv(kVec2f_GrSLType); |
| 550 args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); | 550 args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); |
| 551 vsBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), | 551 vsBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), |
| 552 SK_FLT_DECIMAL_DIG, recipWidth, | 552 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipWidth, |
| 553 SK_FLT_DECIMAL_DIG, recipHeight, | 553 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipHeight, |
| 554 dfTexEffect.inTextureCoords()->fName); | 554 dfTexEffect.inTextureCoords()->fName); |
| 555 | 555 |
| 556 // add frag shader code | 556 // add frag shader code |
| 557 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 557 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 558 | 558 |
| 559 SkAssertResult(fsBuilder->enableFeature( | 559 SkAssertResult(fsBuilder->enableFeature( |
| 560 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); | 560 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
| 561 | 561 |
| 562 // create LCD offset adjusted by inverse of transform | 562 // create LCD offset adjusted by inverse of transform |
| 563 // Use highp to work around aliasing issues | 563 // Use highp to work around aliasing issues |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 767 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; |
| 768 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 768 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; |
| 769 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 769 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
| 770 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), | 770 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), |
| 771 GrTest::TestMatrix(d->fRandom), | 771 GrTest::TestMatrix(d->fRandom), |
| 772 d->fTextures[texIdx], params, | 772 d->fTextures[texIdx], params, |
| 773 wa, | 773 wa, |
| 774 flags, | 774 flags, |
| 775 d->fRandom->nextBool()); | 775 d->fRandom->nextBool()); |
| 776 } | 776 } |
| OLD | NEW |