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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 #endif | 61 #endif |
62 | 62 |
63 // Setup pass through color | 63 // Setup pass through color |
64 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor
, | 64 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor
, |
65 dfTexEffect.inColor(), &fColorUniform); | 65 dfTexEffect.inColor(), &fColorUniform); |
66 | 66 |
67 // Setup position | 67 // Setup position |
68 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix()); | 68 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix()); |
69 | 69 |
70 // emit transforms | 70 // emit transforms |
71 const SkMatrix& localMatrix = dfTexEffect.localMatrix(); | |
72 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, | 71 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, |
73 localMatrix, args.fTransformsIn, args.fTransformsOu
t); | 72 args.fTransformsIn, args.fTransformsOut); |
74 | 73 |
75 // add varyings | 74 // add varyings |
76 GrGLVertToFrag recipScale(kFloat_GrSLType); | 75 GrGLVertToFrag recipScale(kFloat_GrSLType); |
77 GrGLVertToFrag st(kVec2f_GrSLType); | 76 GrGLVertToFrag st(kVec2f_GrSLType); |
78 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan
ceFieldEffectFlag); | 77 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan
ceFieldEffectFlag); |
79 args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); | 78 args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); |
80 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor
ds()->fName); | 79 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor
ds()->fName); |
81 | 80 |
82 GrGLVertToFrag uv(kVec2f_GrSLType); | 81 GrGLVertToFrag uv(kVec2f_GrSLType); |
83 args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); | 82 args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 164 } |
166 | 165 |
167 static inline void GenKey(const GrGeometryProcessor& gp, | 166 static inline void GenKey(const GrGeometryProcessor& gp, |
168 const GrBatchTracker& bt, | 167 const GrBatchTracker& bt, |
169 const GrGLSLCaps&, | 168 const GrGLSLCaps&, |
170 GrProcessorKeyBuilder* b) { | 169 GrProcessorKeyBuilder* b) { |
171 const GrDistanceFieldA8TextGeoProc& dfTexEffect = gp.cast<GrDistanceFiel
dA8TextGeoProc>(); | 170 const GrDistanceFieldA8TextGeoProc& dfTexEffect = gp.cast<GrDistanceFiel
dA8TextGeoProc>(); |
172 const DistanceFieldBatchTracker& local = bt.cast<DistanceFieldBatchTrack
er>(); | 171 const DistanceFieldBatchTracker& local = bt.cast<DistanceFieldBatchTrack
er>(); |
173 uint32_t key = dfTexEffect.getFlags(); | 172 uint32_t key = dfTexEffect.getFlags(); |
174 key |= local.fInputColorType << 16; | 173 key |= local.fInputColorType << 16; |
175 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1
<< 24: 0x0; | |
176 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; | 174 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
177 b->add32(key); | 175 b->add32(key); |
178 } | 176 } |
179 | 177 |
180 private: | 178 private: |
181 GrColor fColor; | 179 GrColor fColor; |
182 UniformHandle fColorUniform; | 180 UniformHandle fColorUniform; |
183 #ifdef SK_GAMMA_APPLY_TO_A8 | 181 #ifdef SK_GAMMA_APPLY_TO_A8 |
184 float fDistanceAdjust; | 182 float fDistanceAdjust; |
185 UniformHandle fDistanceAdjustUni; | 183 UniformHandle fDistanceAdjustUni; |
186 #endif | 184 #endif |
187 | 185 |
188 typedef GrGLGeometryProcessor INHERITED; | 186 typedef GrGLGeometryProcessor INHERITED; |
189 }; | 187 }; |
190 | 188 |
191 /////////////////////////////////////////////////////////////////////////////// | 189 /////////////////////////////////////////////////////////////////////////////// |
192 | 190 |
193 GrDistanceFieldA8TextGeoProc::GrDistanceFieldA8TextGeoProc(GrColor color, | 191 GrDistanceFieldA8TextGeoProc::GrDistanceFieldA8TextGeoProc(GrColor color, |
194 const SkMatrix& viewM
atrix, | 192 const SkMatrix& viewM
atrix, |
195 GrTexture* texture, | 193 GrTexture* texture, |
196 const GrTextureParams
& params, | 194 const GrTextureParams
& params, |
197 #ifdef SK_GAMMA_APPLY_TO_A8 | 195 #ifdef SK_GAMMA_APPLY_TO_A8 |
198 float distanceAdjust, | 196 float distanceAdjust, |
199 #endif | 197 #endif |
200 uint32_t flags) | 198 uint32_t flags) |
201 : INHERITED(SkMatrix::I()) | 199 : fColor(color) |
202 , fColor(color) | |
203 , fViewMatrix(viewMatrix) | 200 , fViewMatrix(viewMatrix) |
204 , fTextureAccess(texture, params) | 201 , fTextureAccess(texture, params) |
205 #ifdef SK_GAMMA_APPLY_TO_A8 | 202 #ifdef SK_GAMMA_APPLY_TO_A8 |
206 , fDistanceAdjust(distanceAdjust) | 203 , fDistanceAdjust(distanceAdjust) |
207 #endif | 204 #endif |
208 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) | 205 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) |
209 , fInColor(NULL) { | 206 , fInColor(NULL) { |
210 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); | 207 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); |
211 this->initClassID<GrDistanceFieldA8TextGeoProc>(); | 208 this->initClassID<GrDistanceFieldA8TextGeoProc>(); |
212 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); | 209 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor
, | 302 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor
, |
306 dfTexEffect.inColor(), &fColorUniform); | 303 dfTexEffect.inColor(), &fColorUniform); |
307 | 304 |
308 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoord
s()->fName); | 305 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoord
s()->fName); |
309 | 306 |
310 // Setup position | 307 // Setup position |
311 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix()); | 308 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix()); |
312 | 309 |
313 // emit transforms | 310 // emit transforms |
314 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, | 311 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, |
315 dfTexEffect.localMatrix(), args.fTransformsIn, args
.fTransformsOut); | 312 args.fTransformsIn, args.fTransformsOut); |
316 | 313 |
317 const char* textureSizeUniName = NULL; | 314 const char* textureSizeUniName = NULL; |
318 fTextureSizeUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Vis
ibility, | 315 fTextureSizeUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Vis
ibility, |
319 kVec2f_GrSLType, kDefault_GrSLPrec
ision, | 316 kVec2f_GrSLType, kDefault_GrSLPrec
ision, |
320 "TextureSize", &textureSizeUniName
); | 317 "TextureSize", &textureSizeUniName
); |
321 | 318 |
322 // Use highp to work around aliasing issues | 319 // Use highp to work around aliasing issues |
323 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, | 320 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, |
324 pb->ctxInfo().stand
ard())); | 321 pb->ctxInfo().stand
ard())); |
325 fsBuilder->codeAppendf("vec2 uv = %s;", v.fsIn()); | 322 fsBuilder->codeAppendf("vec2 uv = %s;", v.fsIn()); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 395 |
399 static inline void GenKey(const GrGeometryProcessor& gp, | 396 static inline void GenKey(const GrGeometryProcessor& gp, |
400 const GrBatchTracker& bt, | 397 const GrBatchTracker& bt, |
401 const GrGLSLCaps&, | 398 const GrGLSLCaps&, |
402 GrProcessorKeyBuilder* b) { | 399 GrProcessorKeyBuilder* b) { |
403 const GrDistanceFieldPathGeoProc& dfTexEffect = gp.cast<GrDistanceFieldP
athGeoProc>(); | 400 const GrDistanceFieldPathGeoProc& dfTexEffect = gp.cast<GrDistanceFieldP
athGeoProc>(); |
404 | 401 |
405 const DistanceFieldPathBatchTracker& local = bt.cast<DistanceFieldPathBa
tchTracker>(); | 402 const DistanceFieldPathBatchTracker& local = bt.cast<DistanceFieldPathBa
tchTracker>(); |
406 uint32_t key = dfTexEffect.getFlags(); | 403 uint32_t key = dfTexEffect.getFlags(); |
407 key |= local.fInputColorType << 16; | 404 key |= local.fInputColorType << 16; |
408 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1
<< 24: 0x0; | |
409 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; | 405 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
410 b->add32(key); | 406 b->add32(key); |
411 } | 407 } |
412 | 408 |
413 private: | 409 private: |
414 UniformHandle fColorUniform; | 410 UniformHandle fColorUniform; |
415 UniformHandle fTextureSizeUni; | 411 UniformHandle fTextureSizeUni; |
416 GrColor fColor; | 412 GrColor fColor; |
417 SkISize fTextureSize; | 413 SkISize fTextureSize; |
418 | 414 |
419 typedef GrGLGeometryProcessor INHERITED; | 415 typedef GrGLGeometryProcessor INHERITED; |
420 }; | 416 }; |
421 | 417 |
422 /////////////////////////////////////////////////////////////////////////////// | 418 /////////////////////////////////////////////////////////////////////////////// |
423 | 419 |
424 GrDistanceFieldPathGeoProc::GrDistanceFieldPathGeoProc( | 420 GrDistanceFieldPathGeoProc::GrDistanceFieldPathGeoProc( |
425 GrColor color, | 421 GrColor color, |
426 const SkMatrix& viewMatrix, | 422 const SkMatrix& viewMatrix, |
427 GrTexture* texture, | 423 GrTexture* texture, |
428 const GrTextureParams& params, | 424 const GrTextureParams& params, |
429 uint32_t flags) | 425 uint32_t flags) |
430 : INHERITED(SkMatrix::I()) | 426 : fColor(color) |
431 , fColor(color) | |
432 , fViewMatrix(viewMatrix) | 427 , fViewMatrix(viewMatrix) |
433 , fTextureAccess(texture, params) | 428 , fTextureAccess(texture, params) |
434 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) | 429 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) |
435 , fInColor(NULL) { | 430 , fInColor(NULL) { |
436 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); | 431 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); |
437 this->initClassID<GrDistanceFieldPathGeoProc>(); | 432 this->initClassID<GrDistanceFieldPathGeoProc>(); |
438 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); | 433 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); |
439 if (flags & kColorAttr_DistanceFieldEffectFlag) { | 434 if (flags & kColorAttr_DistanceFieldEffectFlag) { |
440 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); | 435 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); |
441 } | 436 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 vsBuilder->emitAttributes(dfTexEffect); | 514 vsBuilder->emitAttributes(dfTexEffect); |
520 | 515 |
521 // setup pass through color | 516 // setup pass through color |
522 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor
, NULL, | 517 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor
, NULL, |
523 &fColorUniform); | 518 &fColorUniform); |
524 | 519 |
525 // Setup position | 520 // Setup position |
526 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix()); | 521 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix()); |
527 | 522 |
528 // emit transforms | 523 // emit transforms |
529 const SkMatrix& localMatrix = dfTexEffect.localMatrix(); | |
530 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, | 524 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, |
531 localMatrix, args.fTransformsIn, args.fTransformsOu
t); | 525 args.fTransformsIn, args.fTransformsOut); |
532 | 526 |
533 // set up varyings | 527 // set up varyings |
534 bool isUniformScale = SkToBool(dfTexEffect.getFlags() & kUniformScale_Di
stanceFieldEffectMask); | 528 bool isUniformScale = SkToBool(dfTexEffect.getFlags() & kUniformScale_Di
stanceFieldEffectMask); |
535 GrGLVertToFrag recipScale(kFloat_GrSLType); | 529 GrGLVertToFrag recipScale(kFloat_GrSLType); |
536 GrGLVertToFrag st(kVec2f_GrSLType); | 530 GrGLVertToFrag st(kVec2f_GrSLType); |
537 args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); | 531 args.fPB->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); |
538 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor
ds()->fName); | 532 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor
ds()->fName); |
539 | 533 |
540 GrGLVertToFrag uv(kVec2f_GrSLType); | 534 GrGLVertToFrag uv(kVec2f_GrSLType); |
541 args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); | 535 args.fPB->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 | 663 |
670 static inline void GenKey(const GrGeometryProcessor& gp, | 664 static inline void GenKey(const GrGeometryProcessor& gp, |
671 const GrBatchTracker& bt, | 665 const GrBatchTracker& bt, |
672 const GrGLSLCaps&, | 666 const GrGLSLCaps&, |
673 GrProcessorKeyBuilder* b) { | 667 GrProcessorKeyBuilder* b) { |
674 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = gp.cast<GrDistanceFie
ldLCDTextGeoProc>(); | 668 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = gp.cast<GrDistanceFie
ldLCDTextGeoProc>(); |
675 | 669 |
676 const DistanceFieldLCDBatchTracker& local = bt.cast<DistanceFieldLCDBatc
hTracker>(); | 670 const DistanceFieldLCDBatchTracker& local = bt.cast<DistanceFieldLCDBatc
hTracker>(); |
677 uint32_t key = dfTexEffect.getFlags(); | 671 uint32_t key = dfTexEffect.getFlags(); |
678 key |= local.fInputColorType << 16; | 672 key |= local.fInputColorType << 16; |
679 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1
<< 24: 0x0; | |
680 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; | 673 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
681 b->add32(key); | 674 b->add32(key); |
682 } | 675 } |
683 | 676 |
684 private: | 677 private: |
685 GrColor fColor; | 678 GrColor fColor; |
686 UniformHandle fColorUniform; | 679 UniformHandle fColorUniform; |
687 GrDistanceFieldLCDTextGeoProc::DistanceAdjust fDistanceAdjust; | 680 GrDistanceFieldLCDTextGeoProc::DistanceAdjust fDistanceAdjust; |
688 UniformHandle fDistanceAdjustUni; | 681 UniformHandle fDistanceAdjustUni; |
689 | 682 |
690 typedef GrGLGeometryProcessor INHERITED; | 683 typedef GrGLGeometryProcessor INHERITED; |
691 }; | 684 }; |
692 | 685 |
693 /////////////////////////////////////////////////////////////////////////////// | 686 /////////////////////////////////////////////////////////////////////////////// |
694 | 687 |
695 GrDistanceFieldLCDTextGeoProc::GrDistanceFieldLCDTextGeoProc( | 688 GrDistanceFieldLCDTextGeoProc::GrDistanceFieldLCDTextGeoProc( |
696 GrColor color, const SkMatrix&
viewMatrix, | 689 GrColor color, const SkMatrix&
viewMatrix, |
697 GrTexture* texture, const GrTe
xtureParams& params, | 690 GrTexture* texture, const GrTe
xtureParams& params, |
698 DistanceAdjust distanceAdjust, | 691 DistanceAdjust distanceAdjust, |
699 uint32_t flags) | 692 uint32_t flags) |
700 : INHERITED(SkMatrix::I()) | 693 : fColor(color) |
701 , fColor(color) | |
702 , fViewMatrix(viewMatrix) | 694 , fViewMatrix(viewMatrix) |
703 , fTextureAccess(texture, params) | 695 , fTextureAccess(texture, params) |
704 , fDistanceAdjust(distanceAdjust) | 696 , fDistanceAdjust(distanceAdjust) |
705 , fFlags(flags & kLCD_DistanceFieldEffectMask){ | 697 , fFlags(flags & kLCD_DistanceFieldEffectMask){ |
706 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan
ceFieldEffectFlag)); | 698 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan
ceFieldEffectFlag)); |
707 this->initClassID<GrDistanceFieldLCDTextGeoProc>(); | 699 this->initClassID<GrDistanceFieldLCDTextGeoProc>(); |
708 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); | 700 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); |
709 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 701 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
710 kVec2s_GrVertexAttribT
ype)); | 702 kVec2s_GrVertexAttribT
ype)); |
711 this->addTextureAccess(&fTextureAccess); | 703 this->addTextureAccess(&fTextureAccess); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 DistanceAdjust wa = { 0.0f, 0.1f, -0.1f }; | 746 DistanceAdjust wa = { 0.0f, 0.1f, -0.1f }; |
755 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 747 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; |
756 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 748 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; |
757 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 749 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
758 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(random), | 750 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(random), |
759 GrTest::TestMatrix(random), | 751 GrTest::TestMatrix(random), |
760 textures[texIdx], params, | 752 textures[texIdx], params, |
761 wa, | 753 wa, |
762 flags); | 754 flags); |
763 } | 755 } |
OLD | NEW |