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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 const GrBatchTracker& bt) override { | 145 const GrBatchTracker& bt) override { |
146 #ifdef SK_GAMMA_APPLY_TO_A8 | 146 #ifdef SK_GAMMA_APPLY_TO_A8 |
147 const GrDistanceFieldA8TextGeoProc& dfTexEffect = proc.cast<GrDistanceFi
eldA8TextGeoProc>(); | 147 const GrDistanceFieldA8TextGeoProc& dfTexEffect = proc.cast<GrDistanceFi
eldA8TextGeoProc>(); |
148 float distanceAdjust = dfTexEffect.getDistanceAdjust(); | 148 float distanceAdjust = dfTexEffect.getDistanceAdjust(); |
149 if (distanceAdjust != fDistanceAdjust) { | 149 if (distanceAdjust != fDistanceAdjust) { |
150 pdman.set1f(fDistanceAdjustUni, distanceAdjust); | 150 pdman.set1f(fDistanceAdjustUni, distanceAdjust); |
151 fDistanceAdjust = distanceAdjust; | 151 fDistanceAdjust = distanceAdjust; |
152 } | 152 } |
153 #endif | 153 #endif |
154 | 154 |
155 this->setUniformViewMatrix(pdman, proc.viewMatrix()); | 155 const GrDistanceFieldA8TextGeoProc& dfa8gp = proc.cast<GrDistanceFieldA8
TextGeoProc>(); |
| 156 this->setUniformViewMatrix(pdman, dfa8gp.viewMatrix()); |
156 | 157 |
157 const DistanceFieldBatchTracker& local = bt.cast<DistanceFieldBatchTrack
er>(); | 158 const DistanceFieldBatchTracker& local = bt.cast<DistanceFieldBatchTrack
er>(); |
158 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { | 159 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
159 GrGLfloat c[4]; | 160 GrGLfloat c[4]; |
160 GrColorToRGBAFloat(local.fColor, c); | 161 GrColorToRGBAFloat(local.fColor, c); |
161 pdman.set4fv(fColorUniform, 1, c); | 162 pdman.set4fv(fColorUniform, 1, c); |
162 fColor = local.fColor; | 163 fColor = local.fColor; |
163 } | 164 } |
164 } | 165 } |
165 | 166 |
166 static inline void GenKey(const GrGeometryProcessor& gp, | 167 static inline void GenKey(const GrGeometryProcessor& gp, |
167 const GrBatchTracker& bt, | 168 const GrBatchTracker& bt, |
168 const GrGLSLCaps&, | 169 const GrGLSLCaps&, |
169 GrProcessorKeyBuilder* b) { | 170 GrProcessorKeyBuilder* b) { |
170 const GrDistanceFieldA8TextGeoProc& dfTexEffect = gp.cast<GrDistanceFiel
dA8TextGeoProc>(); | 171 const GrDistanceFieldA8TextGeoProc& dfTexEffect = gp.cast<GrDistanceFiel
dA8TextGeoProc>(); |
171 const DistanceFieldBatchTracker& local = bt.cast<DistanceFieldBatchTrack
er>(); | 172 const DistanceFieldBatchTracker& local = bt.cast<DistanceFieldBatchTrack
er>(); |
172 uint32_t key = dfTexEffect.getFlags(); | 173 uint32_t key = dfTexEffect.getFlags(); |
173 key |= local.fInputColorType << 16; | 174 key |= local.fInputColorType << 16; |
174 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1
<< 24: 0x0; | 175 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1
<< 24: 0x0; |
175 key |= ComputePosKey(gp.viewMatrix()) << 25; | 176 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
176 b->add32(key); | 177 b->add32(key); |
177 } | 178 } |
178 | 179 |
179 private: | 180 private: |
180 GrColor fColor; | 181 GrColor fColor; |
181 UniformHandle fColorUniform; | 182 UniformHandle fColorUniform; |
182 #ifdef SK_GAMMA_APPLY_TO_A8 | 183 #ifdef SK_GAMMA_APPLY_TO_A8 |
183 float fDistanceAdjust; | 184 float fDistanceAdjust; |
184 UniformHandle fDistanceAdjustUni; | 185 UniformHandle fDistanceAdjustUni; |
185 #endif | 186 #endif |
186 | 187 |
187 typedef GrGLGeometryProcessor INHERITED; | 188 typedef GrGLGeometryProcessor INHERITED; |
188 }; | 189 }; |
189 | 190 |
190 /////////////////////////////////////////////////////////////////////////////// | 191 /////////////////////////////////////////////////////////////////////////////// |
191 | 192 |
192 GrDistanceFieldA8TextGeoProc::GrDistanceFieldA8TextGeoProc(GrColor color, | 193 GrDistanceFieldA8TextGeoProc::GrDistanceFieldA8TextGeoProc(GrColor color, |
193 const SkMatrix& viewM
atrix, | 194 const SkMatrix& viewM
atrix, |
194 GrTexture* texture, | 195 GrTexture* texture, |
195 const GrTextureParams
& params, | 196 const GrTextureParams
& params, |
196 #ifdef SK_GAMMA_APPLY_TO_A8 | 197 #ifdef SK_GAMMA_APPLY_TO_A8 |
197 float distanceAdjust, | 198 float distanceAdjust, |
198 #endif | 199 #endif |
199 uint32_t flags) | 200 uint32_t flags) |
200 : INHERITED(viewMatrix, SkMatrix::I()) | 201 : INHERITED(SkMatrix::I()) |
201 , fColor(color) | 202 , fColor(color) |
| 203 , fViewMatrix(viewMatrix) |
202 , fTextureAccess(texture, params) | 204 , fTextureAccess(texture, params) |
203 #ifdef SK_GAMMA_APPLY_TO_A8 | 205 #ifdef SK_GAMMA_APPLY_TO_A8 |
204 , fDistanceAdjust(distanceAdjust) | 206 , fDistanceAdjust(distanceAdjust) |
205 #endif | 207 #endif |
206 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) | 208 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) |
207 , fInColor(NULL) { | 209 , fInColor(NULL) { |
208 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); | 210 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); |
209 this->initClassID<GrDistanceFieldA8TextGeoProc>(); | 211 this->initClassID<GrDistanceFieldA8TextGeoProc>(); |
210 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); | 212 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); |
211 if (flags & kColorAttr_DistanceFieldEffectFlag) { | 213 if (flags & kColorAttr_DistanceFieldEffectFlag) { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 | 377 |
376 GrTexture* texture = proc.texture(0); | 378 GrTexture* texture = proc.texture(0); |
377 if (texture->width() != fTextureSize.width() || | 379 if (texture->width() != fTextureSize.width() || |
378 texture->height() != fTextureSize.height()) { | 380 texture->height() != fTextureSize.height()) { |
379 fTextureSize = SkISize::Make(texture->width(), texture->height()); | 381 fTextureSize = SkISize::Make(texture->width(), texture->height()); |
380 pdman.set2f(fTextureSizeUni, | 382 pdman.set2f(fTextureSizeUni, |
381 SkIntToScalar(fTextureSize.width()), | 383 SkIntToScalar(fTextureSize.width()), |
382 SkIntToScalar(fTextureSize.height())); | 384 SkIntToScalar(fTextureSize.height())); |
383 } | 385 } |
384 | 386 |
385 this->setUniformViewMatrix(pdman, proc.viewMatrix()); | 387 const GrDistanceFieldPathGeoProc& dfpgp = proc.cast<GrDistanceFieldPathG
eoProc>(); |
| 388 this->setUniformViewMatrix(pdman, dfpgp.viewMatrix()); |
386 | 389 |
387 const DistanceFieldPathBatchTracker& local = bt.cast<DistanceFieldPathBa
tchTracker>(); | 390 const DistanceFieldPathBatchTracker& local = bt.cast<DistanceFieldPathBa
tchTracker>(); |
388 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { | 391 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
389 GrGLfloat c[4]; | 392 GrGLfloat c[4]; |
390 GrColorToRGBAFloat(local.fColor, c); | 393 GrColorToRGBAFloat(local.fColor, c); |
391 pdman.set4fv(fColorUniform, 1, c); | 394 pdman.set4fv(fColorUniform, 1, c); |
392 fColor = local.fColor; | 395 fColor = local.fColor; |
393 } | 396 } |
394 } | 397 } |
395 | 398 |
396 static inline void GenKey(const GrGeometryProcessor& gp, | 399 static inline void GenKey(const GrGeometryProcessor& gp, |
397 const GrBatchTracker& bt, | 400 const GrBatchTracker& bt, |
398 const GrGLSLCaps&, | 401 const GrGLSLCaps&, |
399 GrProcessorKeyBuilder* b) { | 402 GrProcessorKeyBuilder* b) { |
400 const GrDistanceFieldPathGeoProc& dfTexEffect = gp.cast<GrDistanceFieldP
athGeoProc>(); | 403 const GrDistanceFieldPathGeoProc& dfTexEffect = gp.cast<GrDistanceFieldP
athGeoProc>(); |
401 | 404 |
402 const DistanceFieldPathBatchTracker& local = bt.cast<DistanceFieldPathBa
tchTracker>(); | 405 const DistanceFieldPathBatchTracker& local = bt.cast<DistanceFieldPathBa
tchTracker>(); |
403 uint32_t key = dfTexEffect.getFlags(); | 406 uint32_t key = dfTexEffect.getFlags(); |
404 key |= local.fInputColorType << 16; | 407 key |= local.fInputColorType << 16; |
405 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1
<< 24: 0x0; | 408 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1
<< 24: 0x0; |
406 key |= ComputePosKey(gp.viewMatrix()) << 25; | 409 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
407 b->add32(key); | 410 b->add32(key); |
408 } | 411 } |
409 | 412 |
410 private: | 413 private: |
411 UniformHandle fColorUniform; | 414 UniformHandle fColorUniform; |
412 UniformHandle fTextureSizeUni; | 415 UniformHandle fTextureSizeUni; |
413 GrColor fColor; | 416 GrColor fColor; |
414 SkISize fTextureSize; | 417 SkISize fTextureSize; |
415 | 418 |
416 typedef GrGLGeometryProcessor INHERITED; | 419 typedef GrGLGeometryProcessor INHERITED; |
417 }; | 420 }; |
418 | 421 |
419 /////////////////////////////////////////////////////////////////////////////// | 422 /////////////////////////////////////////////////////////////////////////////// |
420 | 423 |
421 GrDistanceFieldPathGeoProc::GrDistanceFieldPathGeoProc( | 424 GrDistanceFieldPathGeoProc::GrDistanceFieldPathGeoProc( |
422 GrColor color, | 425 GrColor color, |
423 const SkMatrix& viewMatrix, | 426 const SkMatrix& viewMatrix, |
424 GrTexture* texture, | 427 GrTexture* texture, |
425 const GrTextureParams& params, | 428 const GrTextureParams& params, |
426 uint32_t flags) | 429 uint32_t flags) |
427 : INHERITED(viewMatrix, SkMatrix::I()) | 430 : INHERITED(SkMatrix::I()) |
428 , fColor(color) | 431 , fColor(color) |
| 432 , fViewMatrix(viewMatrix) |
429 , fTextureAccess(texture, params) | 433 , fTextureAccess(texture, params) |
430 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) | 434 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) |
431 , fInColor(NULL) { | 435 , fInColor(NULL) { |
432 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); | 436 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); |
433 this->initClassID<GrDistanceFieldPathGeoProc>(); | 437 this->initClassID<GrDistanceFieldPathGeoProc>(); |
434 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); | 438 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); |
435 if (flags & kColorAttr_DistanceFieldEffectFlag) { | 439 if (flags & kColorAttr_DistanceFieldEffectFlag) { |
436 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); | 440 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); |
437 } | 441 } |
438 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 442 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 processor.cast<GrDistanceFieldLCDTextGeoProc>(); | 649 processor.cast<GrDistanceFieldLCDTextGeoProc>(); |
646 GrDistanceFieldLCDTextGeoProc::DistanceAdjust wa = dfTexEffect.getDistan
ceAdjust(); | 650 GrDistanceFieldLCDTextGeoProc::DistanceAdjust wa = dfTexEffect.getDistan
ceAdjust(); |
647 if (wa != fDistanceAdjust) { | 651 if (wa != fDistanceAdjust) { |
648 pdman.set3f(fDistanceAdjustUni, | 652 pdman.set3f(fDistanceAdjustUni, |
649 wa.fR, | 653 wa.fR, |
650 wa.fG, | 654 wa.fG, |
651 wa.fB); | 655 wa.fB); |
652 fDistanceAdjust = wa; | 656 fDistanceAdjust = wa; |
653 } | 657 } |
654 | 658 |
655 this->setUniformViewMatrix(pdman, processor.viewMatrix()); | 659 this->setUniformViewMatrix(pdman, dfTexEffect.viewMatrix()); |
656 | 660 |
657 const DistanceFieldLCDBatchTracker& local = bt.cast<DistanceFieldLCDBatc
hTracker>(); | 661 const DistanceFieldLCDBatchTracker& local = bt.cast<DistanceFieldLCDBatc
hTracker>(); |
658 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { | 662 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
659 GrGLfloat c[4]; | 663 GrGLfloat c[4]; |
660 GrColorToRGBAFloat(local.fColor, c); | 664 GrColorToRGBAFloat(local.fColor, c); |
661 pdman.set4fv(fColorUniform, 1, c); | 665 pdman.set4fv(fColorUniform, 1, c); |
662 fColor = local.fColor; | 666 fColor = local.fColor; |
663 } | 667 } |
664 } | 668 } |
665 | 669 |
666 static inline void GenKey(const GrGeometryProcessor& gp, | 670 static inline void GenKey(const GrGeometryProcessor& gp, |
667 const GrBatchTracker& bt, | 671 const GrBatchTracker& bt, |
668 const GrGLSLCaps&, | 672 const GrGLSLCaps&, |
669 GrProcessorKeyBuilder* b) { | 673 GrProcessorKeyBuilder* b) { |
670 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = gp.cast<GrDistanceFie
ldLCDTextGeoProc>(); | 674 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = gp.cast<GrDistanceFie
ldLCDTextGeoProc>(); |
671 | 675 |
672 const DistanceFieldLCDBatchTracker& local = bt.cast<DistanceFieldLCDBatc
hTracker>(); | 676 const DistanceFieldLCDBatchTracker& local = bt.cast<DistanceFieldLCDBatc
hTracker>(); |
673 uint32_t key = dfTexEffect.getFlags(); | 677 uint32_t key = dfTexEffect.getFlags(); |
674 key |= local.fInputColorType << 16; | 678 key |= local.fInputColorType << 16; |
675 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1
<< 24: 0x0; | 679 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1
<< 24: 0x0; |
676 key |= ComputePosKey(gp.viewMatrix()) << 25; | 680 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
677 b->add32(key); | 681 b->add32(key); |
678 } | 682 } |
679 | 683 |
680 private: | 684 private: |
681 GrColor fColor; | 685 GrColor fColor; |
682 UniformHandle fColorUniform; | 686 UniformHandle fColorUniform; |
683 GrDistanceFieldLCDTextGeoProc::DistanceAdjust fDistanceAdjust; | 687 GrDistanceFieldLCDTextGeoProc::DistanceAdjust fDistanceAdjust; |
684 UniformHandle fDistanceAdjustUni; | 688 UniformHandle fDistanceAdjustUni; |
685 | 689 |
686 typedef GrGLGeometryProcessor INHERITED; | 690 typedef GrGLGeometryProcessor INHERITED; |
687 }; | 691 }; |
688 | 692 |
689 /////////////////////////////////////////////////////////////////////////////// | 693 /////////////////////////////////////////////////////////////////////////////// |
690 | 694 |
691 GrDistanceFieldLCDTextGeoProc::GrDistanceFieldLCDTextGeoProc( | 695 GrDistanceFieldLCDTextGeoProc::GrDistanceFieldLCDTextGeoProc( |
692 GrColor color, const SkMatrix&
viewMatrix, | 696 GrColor color, const SkMatrix&
viewMatrix, |
693 GrTexture* texture, const GrTe
xtureParams& params, | 697 GrTexture* texture, const GrTe
xtureParams& params, |
694 DistanceAdjust distanceAdjust, | 698 DistanceAdjust distanceAdjust, |
695 uint32_t flags) | 699 uint32_t flags) |
696 : INHERITED(viewMatrix, SkMatrix::I()) | 700 : INHERITED(SkMatrix::I()) |
697 , fColor(color) | 701 , fColor(color) |
| 702 , fViewMatrix(viewMatrix) |
698 , fTextureAccess(texture, params) | 703 , fTextureAccess(texture, params) |
699 , fDistanceAdjust(distanceAdjust) | 704 , fDistanceAdjust(distanceAdjust) |
700 , fFlags(flags & kLCD_DistanceFieldEffectMask){ | 705 , fFlags(flags & kLCD_DistanceFieldEffectMask){ |
701 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan
ceFieldEffectFlag)); | 706 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan
ceFieldEffectFlag)); |
702 this->initClassID<GrDistanceFieldLCDTextGeoProc>(); | 707 this->initClassID<GrDistanceFieldLCDTextGeoProc>(); |
703 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); | 708 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); |
704 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 709 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
705 kVec2s_GrVertexAttribT
ype)); | 710 kVec2s_GrVertexAttribT
ype)); |
706 this->addTextureAccess(&fTextureAccess); | 711 this->addTextureAccess(&fTextureAccess); |
707 } | 712 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 DistanceAdjust wa = { 0.0f, 0.1f, -0.1f }; | 754 DistanceAdjust wa = { 0.0f, 0.1f, -0.1f }; |
750 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 755 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; |
751 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 756 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; |
752 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 757 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
753 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(random), | 758 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(random), |
754 GrTest::TestMatrix(random), | 759 GrTest::TestMatrix(random), |
755 textures[texIdx], params, | 760 textures[texIdx], params, |
756 wa, | 761 wa, |
757 flags); | 762 flags); |
758 } | 763 } |
OLD | NEW |