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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 this->emitTransforms(vertBuilder, | 71 this->emitTransforms(vertBuilder, |
72 varyingHandler, | 72 varyingHandler, |
73 uniformHandler, | 73 uniformHandler, |
74 gpArgs->fPositionVar, | 74 gpArgs->fPositionVar, |
75 dfTexEffect.inPosition()->fName, | 75 dfTexEffect.inPosition()->fName, |
76 args.fTransformsIn, | 76 args.fTransformsIn, |
77 args.fTransformsOut); | 77 args.fTransformsOut); |
78 | 78 |
79 // add varyings | 79 // add varyings |
80 GrGLSLVertToFrag recipScale(kFloat_GrSLType); | 80 GrGLSLVertToFrag recipScale(kFloat_GrSLType); |
81 GrGLSLVertToFrag uv(kVec2f_GrSLType); | 81 GrGLSLVertToFrag st(kVec2f_GrSLType); |
82 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan
ceFieldEffectFlag); | 82 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan
ceFieldEffectFlag); |
83 varyingHandler->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); | 83 varyingHandler->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision)
; |
84 vertBuilder->codeAppendf("%s = %s;", uv.vsOut(), dfTexEffect.inTextureCo
ords()->fName); | 84 vertBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCo
ords()->fName); |
85 | 85 |
86 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float | 86 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float |
87 SkASSERT(dfTexEffect.numTextures() == 1); | 87 SkASSERT(dfTexEffect.numTextures() == 1); |
88 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); | 88 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); |
89 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height()))
; | 89 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height()))
; |
| 90 SkScalar recipWidth = 1.0f / atlas->width(); |
| 91 SkScalar recipHeight = 1.0f / atlas->height(); |
90 | 92 |
91 GrGLSLVertToFrag st(kVec2f_GrSLType); | 93 GrGLSLVertToFrag uv(kVec2f_GrSLType); |
92 varyingHandler->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision)
; | 94 varyingHandler->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); |
93 vertBuilder->codeAppendf("%s = vec2(%d, %d) * %s;", st.vsOut(), | 95 vertBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), |
94 atlas->width(), atlas->height(), | 96 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipWidth, |
| 97 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipHeight, |
95 dfTexEffect.inTextureCoords()->fName); | 98 dfTexEffect.inTextureCoords()->fName); |
96 | 99 |
97 // Use highp to work around aliasing issues | 100 // Use highp to work around aliasing issues |
98 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps, | 101 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps, |
99 kHigh_GrSLPreci
sion)); | 102 kHigh_GrSLPreci
sion)); |
100 fragBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); | 103 fragBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); |
101 | 104 |
102 fragBuilder->codeAppend("\tfloat texColor = "); | 105 fragBuilder->codeAppend("\tfloat texColor = "); |
103 fragBuilder->appendTextureLookup(args.fSamplers[0], | 106 fragBuilder->appendTextureLookup(args.fSamplers[0], |
104 "uv", | 107 "uv", |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 #endif | 217 #endif |
215 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) | 218 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) |
216 , fInColor(nullptr) | 219 , fInColor(nullptr) |
217 , fUsesLocalCoords(usesLocalCoords) { | 220 , fUsesLocalCoords(usesLocalCoords) { |
218 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); | 221 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); |
219 this->initClassID<GrDistanceFieldA8TextGeoProc>(); | 222 this->initClassID<GrDistanceFieldA8TextGeoProc>(); |
220 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType, | 223 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType, |
221 kHigh_GrSLPrecision)); | 224 kHigh_GrSLPrecision)); |
222 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttri
bType)); | 225 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttri
bType)); |
223 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 226 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
224 kVec2us_GrVertexAttrib
Type)); | 227 kVec2s_GrVertexAttribT
ype)); |
225 this->addTextureAccess(&fTextureAccess); | 228 this->addTextureAccess(&fTextureAccess); |
226 } | 229 } |
227 | 230 |
228 void GrDistanceFieldA8TextGeoProc::getGLSLProcessorKey(const GrGLSLCaps& caps, | 231 void GrDistanceFieldA8TextGeoProc::getGLSLProcessorKey(const GrGLSLCaps& caps, |
229 GrProcessorKeyBuilder* b)
const { | 232 GrProcessorKeyBuilder* b)
const { |
230 GrGLDistanceFieldA8TextGeoProc::GenKey(*this, caps, b); | 233 GrGLDistanceFieldA8TextGeoProc::GenKey(*this, caps, b); |
231 } | 234 } |
232 | 235 |
233 GrGLSLPrimitiveProcessor* GrDistanceFieldA8TextGeoProc::createGLSLInstance(const
GrGLSLCaps&) const { | 236 GrGLSLPrimitiveProcessor* GrDistanceFieldA8TextGeoProc::createGLSLInstance(const
GrGLSLCaps&) const { |
234 return new GrGLDistanceFieldA8TextGeoProc(); | 237 return new GrGLDistanceFieldA8TextGeoProc(); |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 varyingHandler, | 515 varyingHandler, |
513 uniformHandler, | 516 uniformHandler, |
514 gpArgs->fPositionVar, | 517 gpArgs->fPositionVar, |
515 dfTexEffect.inPosition()->fName, | 518 dfTexEffect.inPosition()->fName, |
516 args.fTransformsIn, | 519 args.fTransformsIn, |
517 args.fTransformsOut); | 520 args.fTransformsOut); |
518 | 521 |
519 // set up varyings | 522 // set up varyings |
520 bool isUniformScale = SkToBool(dfTexEffect.getFlags() & kUniformScale_Di
stanceFieldEffectMask); | 523 bool isUniformScale = SkToBool(dfTexEffect.getFlags() & kUniformScale_Di
stanceFieldEffectMask); |
521 GrGLSLVertToFrag recipScale(kFloat_GrSLType); | 524 GrGLSLVertToFrag recipScale(kFloat_GrSLType); |
522 GrGLSLVertToFrag uv(kVec2f_GrSLType); | 525 GrGLSLVertToFrag st(kVec2f_GrSLType); |
523 varyingHandler->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); | 526 varyingHandler->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision)
; |
524 vertBuilder->codeAppendf("%s = %s;", uv.vsOut(), dfTexEffect.inTextureCo
ords()->fName); | 527 vertBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCo
ords()->fName); |
525 | 528 |
526 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float | 529 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float |
527 SkASSERT(dfTexEffect.numTextures() == 1); | 530 SkASSERT(dfTexEffect.numTextures() == 1); |
528 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); | 531 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); |
529 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height()))
; | 532 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height()))
; |
| 533 SkScalar recipWidth = 1.0f / atlas->width(); |
| 534 SkScalar recipHeight = 1.0f / atlas->height(); |
530 | 535 |
531 GrGLSLVertToFrag st(kVec2f_GrSLType); | 536 GrGLSLVertToFrag uv(kVec2f_GrSLType); |
532 varyingHandler->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision)
; | 537 varyingHandler->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); |
533 vertBuilder->codeAppendf("%s = vec2(%d, %d) * %s;", st.vsOut(), | 538 vertBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), |
534 atlas->width(), atlas->height(), | 539 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipWidth, |
| 540 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipHeight, |
535 dfTexEffect.inTextureCoords()->fName); | 541 dfTexEffect.inTextureCoords()->fName); |
536 | 542 |
537 // add frag shader code | 543 // add frag shader code |
538 | 544 |
539 SkAssertResult(fragBuilder->enableFeature( | 545 SkAssertResult(fragBuilder->enableFeature( |
540 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); | 546 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
541 | 547 |
542 // create LCD offset adjusted by inverse of transform | 548 // create LCD offset adjusted by inverse of transform |
543 // Use highp to work around aliasing issues | 549 // Use highp to work around aliasing issues |
544 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps, | 550 fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps, |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 , fTextureAccess(texture, params) | 701 , fTextureAccess(texture, params) |
696 , fDistanceAdjust(distanceAdjust) | 702 , fDistanceAdjust(distanceAdjust) |
697 , fFlags(flags & kLCD_DistanceFieldEffectMask) | 703 , fFlags(flags & kLCD_DistanceFieldEffectMask) |
698 , fUsesLocalCoords(usesLocalCoords) { | 704 , fUsesLocalCoords(usesLocalCoords) { |
699 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan
ceFieldEffectFlag)); | 705 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan
ceFieldEffectFlag)); |
700 this->initClassID<GrDistanceFieldLCDTextGeoProc>(); | 706 this->initClassID<GrDistanceFieldLCDTextGeoProc>(); |
701 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType, | 707 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType, |
702 kHigh_GrSLPrecision)); | 708 kHigh_GrSLPrecision)); |
703 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttri
bType)); | 709 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttri
bType)); |
704 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 710 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
705 kVec2us_GrVertexAttribTy
pe)); | 711 kVec2s_GrVertexAttribTyp
e)); |
706 this->addTextureAccess(&fTextureAccess); | 712 this->addTextureAccess(&fTextureAccess); |
707 } | 713 } |
708 | 714 |
709 void GrDistanceFieldLCDTextGeoProc::getGLSLProcessorKey(const GrGLSLCaps& caps, | 715 void GrDistanceFieldLCDTextGeoProc::getGLSLProcessorKey(const GrGLSLCaps& caps, |
710 GrProcessorKeyBuilder* b
) const { | 716 GrProcessorKeyBuilder* b
) const { |
711 GrGLDistanceFieldLCDTextGeoProc::GenKey(*this, caps, b); | 717 GrGLDistanceFieldLCDTextGeoProc::GenKey(*this, caps, b); |
712 } | 718 } |
713 | 719 |
714 GrGLSLPrimitiveProcessor* GrDistanceFieldLCDTextGeoProc::createGLSLInstance(cons
t GrGLSLCaps&) const { | 720 GrGLSLPrimitiveProcessor* GrDistanceFieldLCDTextGeoProc::createGLSLInstance(cons
t GrGLSLCaps&) const { |
715 return new GrGLDistanceFieldLCDTextGeoProc(); | 721 return new GrGLDistanceFieldLCDTextGeoProc(); |
(...skipping 21 matching lines...) Expand all Loading... |
737 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 743 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; |
738 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 744 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; |
739 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 745 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
740 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), | 746 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), |
741 GrTest::TestMatrix(d->fRandom), | 747 GrTest::TestMatrix(d->fRandom), |
742 d->fTextures[texIdx], params, | 748 d->fTextures[texIdx], params, |
743 wa, | 749 wa, |
744 flags, | 750 flags, |
745 d->fRandom->nextBool()); | 751 d->fRandom->nextBool()); |
746 } | 752 } |
OLD | NEW |