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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, | 70 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, |
71 args.fTransformsIn, args.fTransformsOut); | 71 args.fTransformsIn, args.fTransformsOut); |
72 | 72 |
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 | |
81 SkASSERT(dfTexEffect.numTextures() == 1); | |
82 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); | |
83 SkASSERT(atlas); | |
84 SkScalar recipWidth = 1.0f / atlas->width(); | |
85 SkScalar recipHeight = 1.0f / atlas->height(); | |
86 | |
87 GrGLVertToFrag uv(kVec2f_GrSLType); | 80 GrGLVertToFrag uv(kVec2f_GrSLType); |
88 args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); | 81 args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); |
89 vsBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), | 82 // this is only used with text, so our texture bounds always match the g
lyph atlas |
90 SK_FLT_DECIMAL_DIG, recipWidth, | 83 vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_A8_RECIP_WIDTH ", " |
91 SK_FLT_DECIMAL_DIG, recipHeight, | 84 GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", uv.vsOut(), |
92 dfTexEffect.inTextureCoords()->fName); | 85 dfTexEffect.inTextureCoords()->fName); |
93 | 86 |
94 // Use highp to work around aliasing issues | 87 // Use highp to work around aliasing issues |
95 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, | 88 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, |
96 pb->ctxInfo().stand
ard())); | 89 pb->ctxInfo().stand
ard())); |
97 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); | 90 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); |
98 | 91 |
99 fsBuilder->codeAppend("\tfloat texColor = "); | 92 fsBuilder->codeAppend("\tfloat texColor = "); |
100 fsBuilder->appendTextureLookup(args.fSamplers[0], | 93 fsBuilder->appendTextureLookup(args.fSamplers[0], |
101 "uv", | 94 "uv", |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 static inline void GenKey(const GrGeometryProcessor& gp, | 169 static inline void GenKey(const GrGeometryProcessor& gp, |
177 const GrBatchTracker& bt, | 170 const GrBatchTracker& bt, |
178 const GrGLSLCaps&, | 171 const GrGLSLCaps&, |
179 GrProcessorKeyBuilder* b) { | 172 GrProcessorKeyBuilder* b) { |
180 const GrDistanceFieldA8TextGeoProc& dfTexEffect = gp.cast<GrDistanceFiel
dA8TextGeoProc>(); | 173 const GrDistanceFieldA8TextGeoProc& dfTexEffect = gp.cast<GrDistanceFiel
dA8TextGeoProc>(); |
181 uint32_t key = dfTexEffect.getFlags(); | 174 uint32_t key = dfTexEffect.getFlags(); |
182 key |= dfTexEffect.hasVertexColor() << 16; | 175 key |= dfTexEffect.hasVertexColor() << 16; |
183 key |= dfTexEffect.colorIgnored() << 17; | 176 key |= dfTexEffect.colorIgnored() << 17; |
184 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; | 177 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
185 b->add32(key); | 178 b->add32(key); |
186 | |
187 // Currently we hardcode numbers to convert atlas coordinates to normali
zed floating point | |
188 SkASSERT(gp.numTextures() == 1); | |
189 GrTexture* atlas = gp.textureAccess(0).getTexture(); | |
190 SkASSERT(atlas); | |
191 b->add32(atlas->width()); | |
192 b->add32(atlas->height()); | |
193 } | 179 } |
194 | 180 |
195 private: | 181 private: |
196 SkMatrix fViewMatrix; | 182 SkMatrix fViewMatrix; |
197 GrColor fColor; | 183 GrColor fColor; |
198 UniformHandle fColorUniform; | 184 UniformHandle fColorUniform; |
199 UniformHandle fViewMatrixUniform; | 185 UniformHandle fViewMatrixUniform; |
200 #ifdef SK_GAMMA_APPLY_TO_A8 | 186 #ifdef SK_GAMMA_APPLY_TO_A8 |
201 float fDistanceAdjust; | 187 float fDistanceAdjust; |
202 UniformHandle fDistanceAdjustUni; | 188 UniformHandle fDistanceAdjustUni; |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, | 518 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, |
533 args.fTransformsIn, args.fTransformsOut); | 519 args.fTransformsIn, args.fTransformsOut); |
534 | 520 |
535 // set up varyings | 521 // set up varyings |
536 bool isUniformScale = SkToBool(dfTexEffect.getFlags() & kUniformScale_Di
stanceFieldEffectMask); | 522 bool isUniformScale = SkToBool(dfTexEffect.getFlags() & kUniformScale_Di
stanceFieldEffectMask); |
537 GrGLVertToFrag recipScale(kFloat_GrSLType); | 523 GrGLVertToFrag recipScale(kFloat_GrSLType); |
538 GrGLVertToFrag st(kVec2f_GrSLType); | 524 GrGLVertToFrag st(kVec2f_GrSLType); |
539 args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); | 525 args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); |
540 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor
ds()->fName); | 526 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor
ds()->fName); |
541 | 527 |
542 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float | |
543 SkASSERT(dfTexEffect.numTextures() == 1); | |
544 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); | |
545 SkASSERT(atlas); | |
546 SkScalar recipWidth = 1.0f / atlas->width(); | |
547 SkScalar recipHeight = 1.0f / atlas->height(); | |
548 | |
549 GrGLVertToFrag uv(kVec2f_GrSLType); | 528 GrGLVertToFrag uv(kVec2f_GrSLType); |
550 args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); | 529 args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); |
551 vsBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), | 530 // this is only used with text, so our texture bounds always match the g
lyph atlas |
552 SK_FLT_DECIMAL_DIG, recipWidth, | 531 vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_A8_RECIP_WIDTH ", " |
553 SK_FLT_DECIMAL_DIG, recipHeight, | 532 GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", uv.vsOut(), |
554 dfTexEffect.inTextureCoords()->fName); | 533 dfTexEffect.inTextureCoords()->fName); |
555 | 534 |
556 // add frag shader code | 535 // add frag shader code |
557 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 536 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
558 | 537 |
559 SkAssertResult(fsBuilder->enableFeature( | 538 SkAssertResult(fsBuilder->enableFeature( |
560 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); | 539 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
561 | 540 |
562 // create LCD offset adjusted by inverse of transform | 541 // create LCD offset adjusted by inverse of transform |
563 // Use highp to work around aliasing issues | 542 // Use highp to work around aliasing issues |
564 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, | 543 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, |
565 pb->ctxInfo().stand
ard())); | 544 pb->ctxInfo().stand
ard())); |
566 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); | 545 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); |
567 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, | 546 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, |
568 pb->ctxInfo().stand
ard())); | 547 pb->ctxInfo().stand
ard())); |
569 | |
570 SkScalar lcdDelta = 1.0f / (3.0f * atlas->width()); | |
571 if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) { | 548 if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) { |
572 fsBuilder->codeAppendf("float delta = -%.*f;\n", SK_FLT_DECIMAL_DIG,
lcdDelta); | 549 fsBuilder->codeAppend("float delta = -" GR_FONT_ATLAS_LCD_DELTA ";\n
"); |
573 } else { | 550 } else { |
574 fsBuilder->codeAppendf("float delta = %.*f;\n", SK_FLT_DECIMAL_DIG,
lcdDelta); | 551 fsBuilder->codeAppend("float delta = " GR_FONT_ATLAS_LCD_DELTA ";\n"
); |
575 } | 552 } |
576 if (isUniformScale) { | 553 if (isUniformScale) { |
577 fsBuilder->codeAppendf("float dy = abs(dFdy(%s.y));", st.fsIn()); | 554 fsBuilder->codeAppendf("float dy = abs(dFdy(%s.y));", st.fsIn()); |
578 fsBuilder->codeAppend("vec2 offset = vec2(dy*delta, 0.0);"); | 555 fsBuilder->codeAppend("vec2 offset = vec2(dy*delta, 0.0);"); |
579 } else { | 556 } else { |
580 fsBuilder->codeAppendf("vec2 st = %s;\n", st.fsIn()); | 557 fsBuilder->codeAppendf("vec2 st = %s;\n", st.fsIn()); |
581 | 558 |
582 fsBuilder->codeAppend("vec2 Jdx = dFdx(st);"); | 559 fsBuilder->codeAppend("vec2 Jdx = dFdx(st);"); |
583 fsBuilder->codeAppend("vec2 Jdy = dFdy(st);"); | 560 fsBuilder->codeAppend("vec2 Jdy = dFdy(st);"); |
584 fsBuilder->codeAppend("vec2 offset = delta*Jdx;"); | 561 fsBuilder->codeAppend("vec2 offset = delta*Jdx;"); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 static inline void GenKey(const GrGeometryProcessor& gp, | 661 static inline void GenKey(const GrGeometryProcessor& gp, |
685 const GrBatchTracker& bt, | 662 const GrBatchTracker& bt, |
686 const GrGLSLCaps&, | 663 const GrGLSLCaps&, |
687 GrProcessorKeyBuilder* b) { | 664 GrProcessorKeyBuilder* b) { |
688 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = gp.cast<GrDistanceFie
ldLCDTextGeoProc>(); | 665 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = gp.cast<GrDistanceFie
ldLCDTextGeoProc>(); |
689 | 666 |
690 uint32_t key = dfTexEffect.getFlags(); | 667 uint32_t key = dfTexEffect.getFlags(); |
691 key |= dfTexEffect.colorIgnored() << 16; | 668 key |= dfTexEffect.colorIgnored() << 16; |
692 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; | 669 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
693 b->add32(key); | 670 b->add32(key); |
694 | |
695 // Currently we hardcode numbers to convert atlas coordinates to normali
zed floating point | |
696 SkASSERT(gp.numTextures() == 1); | |
697 GrTexture* atlas = gp.textureAccess(0).getTexture(); | |
698 SkASSERT(atlas); | |
699 b->add32(atlas->width()); | |
700 b->add32(atlas->height()); | |
701 } | 671 } |
702 | 672 |
703 private: | 673 private: |
704 SkMatrix fViewMatrix; | 674 SkMatrix fViewMatrix; |
705 GrColor fColor; | 675 GrColor fColor; |
706 UniformHandle fViewMatrixUniform; | 676 UniformHandle fViewMatrixUniform; |
707 UniformHandle fColorUniform; | 677 UniformHandle fColorUniform; |
708 GrDistanceFieldLCDTextGeoProc::DistanceAdjust fDistanceAdjust; | 678 GrDistanceFieldLCDTextGeoProc::DistanceAdjust fDistanceAdjust; |
709 UniformHandle fDistanceAdjustUni; | 679 UniformHandle fDistanceAdjustUni; |
710 | 680 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 737 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; |
768 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 738 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; |
769 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 739 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
770 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), | 740 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), |
771 GrTest::TestMatrix(d->fRandom), | 741 GrTest::TestMatrix(d->fRandom), |
772 d->fTextures[texIdx], params, | 742 d->fTextures[texIdx], params, |
773 wa, | 743 wa, |
774 flags, | 744 flags, |
775 d->fRandom->nextBool()); | 745 d->fRandom->nextBool()); |
776 } | 746 } |
OLD | NEW |