| 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 "GrDistanceFieldTextureEffect.h" | 8 #include "GrDistanceFieldTextureEffect.h" |
| 9 #include "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.h" |
| 10 #include "GrTexture.h" | 10 #include "GrTexture.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 SkISize fTextureSize; | 179 SkISize fTextureSize; |
| 180 UniformHandle fLuminanceUni; | 180 UniformHandle fLuminanceUni; |
| 181 float fLuminance; | 181 float fLuminance; |
| 182 | 182 |
| 183 typedef GrGLGeometryProcessor INHERITED; | 183 typedef GrGLGeometryProcessor INHERITED; |
| 184 }; | 184 }; |
| 185 | 185 |
| 186 /////////////////////////////////////////////////////////////////////////////// | 186 /////////////////////////////////////////////////////////////////////////////// |
| 187 | 187 |
| 188 GrDistanceFieldTextureEffect::GrDistanceFieldTextureEffect(GrColor color, | 188 GrDistanceFieldTextureEffect::GrDistanceFieldTextureEffect(GrColor color, |
| 189 const SkMatrix& viewM
atrix, |
| 189 GrTexture* texture, | 190 GrTexture* texture, |
| 190 const GrTextureParams
& params, | 191 const GrTextureParams
& params, |
| 191 #ifdef SK_GAMMA_APPLY_TO_A8 | 192 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 192 GrTexture* gamma, | 193 GrTexture* gamma, |
| 193 const GrTextureParams
& gammaParams, | 194 const GrTextureParams
& gammaParams, |
| 194 float luminance, | 195 float luminance, |
| 195 #endif | 196 #endif |
| 196 uint32_t flags, bool
opaqueVertexColors) | 197 uint32_t flags, bool
opaqueVertexColors) |
| 197 : INHERITED(color, opaqueVertexColors) | 198 : INHERITED(color, viewMatrix, SkMatrix::I(), opaqueVertexColors) |
| 198 , fTextureAccess(texture, params) | 199 , fTextureAccess(texture, params) |
| 199 #ifdef SK_GAMMA_APPLY_TO_A8 | 200 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 200 , fGammaTextureAccess(gamma, gammaParams) | 201 , fGammaTextureAccess(gamma, gammaParams) |
| 201 , fLuminance(luminance) | 202 , fLuminance(luminance) |
| 202 #endif | 203 #endif |
| 203 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) | 204 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) |
| 204 , fInColor(NULL) { | 205 , fInColor(NULL) { |
| 205 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); | 206 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); |
| 206 this->initClassID<GrDistanceFieldTextureEffect>(); | 207 this->initClassID<GrDistanceFieldTextureEffect>(); |
| 207 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 208 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 283 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 283 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 284 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 284 }; | 285 }; |
| 285 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : | 286 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : |
| 286 GrTextureParams::kNon
e_FilterMode); | 287 GrTextureParams::kNon
e_FilterMode); |
| 287 #ifdef SK_GAMMA_APPLY_TO_A8 | 288 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 288 GrTextureParams params2(tileModes, random->nextBool() ? GrTextureParams::kBi
lerp_FilterMode : | 289 GrTextureParams params2(tileModes, random->nextBool() ? GrTextureParams::kBi
lerp_FilterMode : |
| 289 GrTextureParams::kNo
ne_FilterMode); | 290 GrTextureParams::kNo
ne_FilterMode); |
| 290 #endif | 291 #endif |
| 291 | 292 |
| 292 return GrDistanceFieldTextureEffect::Create(GrRandomColor(random), textures[
texIdx], params, | 293 return GrDistanceFieldTextureEffect::Create(GrRandomColor(random), |
| 294 GrProcessorUnitTest::TestMatrix(
random), |
| 295 textures[texIdx], params, |
| 293 #ifdef SK_GAMMA_APPLY_TO_A8 | 296 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 294 textures[texIdx2], params2, | 297 textures[texIdx2], params2, |
| 295 random->nextF(), | 298 random->nextF(), |
| 296 #endif | 299 #endif |
| 297 random->nextBool() ? | 300 random->nextBool() ? |
| 298 kSimilarity_DistanceFieldEff
ectFlag : 0, | 301 kSimilarity_DistanceFieldEff
ectFlag : 0, |
| 299 random->nextBool()); | 302 random->nextBool()); |
| 300 } | 303 } |
| 301 | 304 |
| 302 /////////////////////////////////////////////////////////////////////////////// | 305 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 GrColor fColor; | 439 GrColor fColor; |
| 437 SkISize fTextureSize; | 440 SkISize fTextureSize; |
| 438 | 441 |
| 439 typedef GrGLGeometryProcessor INHERITED; | 442 typedef GrGLGeometryProcessor INHERITED; |
| 440 }; | 443 }; |
| 441 | 444 |
| 442 /////////////////////////////////////////////////////////////////////////////// | 445 /////////////////////////////////////////////////////////////////////////////// |
| 443 | 446 |
| 444 GrDistanceFieldNoGammaTextureEffect::GrDistanceFieldNoGammaTextureEffect( | 447 GrDistanceFieldNoGammaTextureEffect::GrDistanceFieldNoGammaTextureEffect( |
| 445 GrColor color, | 448 GrColor color, |
| 449 const SkMatrix& viewMatrix, |
| 446 GrTexture* texture, | 450 GrTexture* texture, |
| 447 const GrTextureParams& params, | 451 const GrTextureParams& params, |
| 448 uint32_t flags, | 452 uint32_t flags, |
| 449 bool opaqueVertexColors) | 453 bool opaqueVertexColors) |
| 450 : INHERITED(color, opaqueVertexColors) | 454 : INHERITED(color, viewMatrix, SkMatrix::I(), opaqueVertexColors) |
| 451 , fTextureAccess(texture, params) | 455 , fTextureAccess(texture, params) |
| 452 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) | 456 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) |
| 453 , fInColor(NULL) { | 457 , fInColor(NULL) { |
| 454 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); | 458 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); |
| 455 this->initClassID<GrDistanceFieldNoGammaTextureEffect>(); | 459 this->initClassID<GrDistanceFieldNoGammaTextureEffect>(); |
| 456 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 460 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
| 457 if (flags & kColorAttr_DistanceFieldEffectFlag) { | 461 if (flags & kColorAttr_DistanceFieldEffectFlag) { |
| 458 fInColor = &this->addVertexAttrib(GrAttribute("inColor", kVec4ub_GrVerte
xAttribType)); | 462 fInColor = &this->addVertexAttrib(GrAttribute("inColor", kVec4ub_GrVerte
xAttribType)); |
| 459 this->setHasVertexColor(); | 463 this->setHasVertexColor(); |
| 460 } | 464 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 SkShader::kRepeat_TileMode, | 522 SkShader::kRepeat_TileMode, |
| 519 SkShader::kMirror_TileMode, | 523 SkShader::kMirror_TileMode, |
| 520 }; | 524 }; |
| 521 SkShader::TileMode tileModes[] = { | 525 SkShader::TileMode tileModes[] = { |
| 522 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 526 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 523 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 527 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 524 }; | 528 }; |
| 525 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode | 529 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode |
| 526 : GrTextureParams::kNon
e_FilterMode); | 530 : GrTextureParams::kNon
e_FilterMode); |
| 527 | 531 |
| 528 return GrDistanceFieldNoGammaTextureEffect::Create(GrRandomColor(random), te
xtures[texIdx], | 532 return GrDistanceFieldNoGammaTextureEffect::Create(GrRandomColor(random), |
| 533 GrProcessorUnitTest::Test
Matrix(random), |
| 534 textures[texIdx], |
| 529 params, | 535 params, |
| 530 random->nextBool() ? kSimilarity_DistanceFieldEffectFlag : 0, random->ne
xtBool()); | 536 random->nextBool() ? kSimilarity_DistanceFieldEffectFlag : 0, random->ne
xtBool()); |
| 531 } | 537 } |
| 532 | 538 |
| 533 /////////////////////////////////////////////////////////////////////////////// | 539 /////////////////////////////////////////////////////////////////////////////// |
| 534 | 540 |
| 535 struct DistanceFieldLCDBatchTracker { | 541 struct DistanceFieldLCDBatchTracker { |
| 536 GrGPInput fInputColorType; | 542 GrGPInput fInputColorType; |
| 537 GrColor fColor; | 543 GrColor fColor; |
| 538 bool fUsesLocalCoords; | 544 bool fUsesLocalCoords; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 SkISize fTextureSize; | 747 SkISize fTextureSize; |
| 742 UniformHandle fTextColorUni; | 748 UniformHandle fTextColorUni; |
| 743 SkColor fTextColor; | 749 SkColor fTextColor; |
| 744 | 750 |
| 745 typedef GrGLGeometryProcessor INHERITED; | 751 typedef GrGLGeometryProcessor INHERITED; |
| 746 }; | 752 }; |
| 747 | 753 |
| 748 /////////////////////////////////////////////////////////////////////////////// | 754 /////////////////////////////////////////////////////////////////////////////// |
| 749 | 755 |
| 750 GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect( | 756 GrDistanceFieldLCDTextureEffect::GrDistanceFieldLCDTextureEffect( |
| 751 GrColor color, | 757 GrColor color, const SkMatrix&
viewMatrix, |
| 752 GrTexture* texture, const GrTe
xtureParams& params, | 758 GrTexture* texture, const GrTe
xtureParams& params, |
| 753 GrTexture* gamma, const GrText
ureParams& gParams, | 759 GrTexture* gamma, const GrText
ureParams& gParams, |
| 754 SkColor textColor, | 760 SkColor textColor, |
| 755 uint32_t flags) | 761 uint32_t flags) |
| 756 : INHERITED(color) | 762 : INHERITED(color, viewMatrix, SkMatrix::I()) |
| 757 , fTextureAccess(texture, params) | 763 , fTextureAccess(texture, params) |
| 758 , fGammaTextureAccess(gamma, gParams) | 764 , fGammaTextureAccess(gamma, gParams) |
| 759 , fTextColor(textColor) | 765 , fTextColor(textColor) |
| 760 , fFlags(flags & kLCD_DistanceFieldEffectMask){ | 766 , fFlags(flags & kLCD_DistanceFieldEffectMask){ |
| 761 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan
ceFieldEffectFlag)); | 767 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan
ceFieldEffectFlag)); |
| 762 this->initClassID<GrDistanceFieldLCDTextureEffect>(); | 768 this->initClassID<GrDistanceFieldLCDTextureEffect>(); |
| 763 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 769 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
| 764 fInTextureCoords = &this->addVertexAttrib(GrAttribute("inTextureCoords", | 770 fInTextureCoords = &this->addVertexAttrib(GrAttribute("inTextureCoords", |
| 765 kVec2f_GrVertexAttribT
ype)); | 771 kVec2f_GrVertexAttribT
ype)); |
| 766 this->addTextureAccess(&fTextureAccess); | 772 this->addTextureAccess(&fTextureAccess); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 GrTextureParams::kNone_FilterMode); | 838 GrTextureParams::kNone_FilterMode); |
| 833 GrTextureParams params2(tileModes, random->nextBool() ? GrTextureParams::kBi
lerp_FilterMode : | 839 GrTextureParams params2(tileModes, random->nextBool() ? GrTextureParams::kBi
lerp_FilterMode : |
| 834 GrTextureParams::kNone_FilterMode); | 840 GrTextureParams::kNone_FilterMode); |
| 835 GrColor textColor = GrColorPackRGBA(random->nextULessThan(256), | 841 GrColor textColor = GrColorPackRGBA(random->nextULessThan(256), |
| 836 random->nextULessThan(256), | 842 random->nextULessThan(256), |
| 837 random->nextULessThan(256), | 843 random->nextULessThan(256), |
| 838 random->nextULessThan(256)); | 844 random->nextULessThan(256)); |
| 839 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 845 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; |
| 840 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 846 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; |
| 841 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 847 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
| 842 return GrDistanceFieldLCDTextureEffect::Create(GrRandomColor(random), textur
es[texIdx], params, | 848 return GrDistanceFieldLCDTextureEffect::Create(GrRandomColor(random), |
| 849 GrProcessorUnitTest::TestMatr
ix(random), |
| 850 textures[texIdx], params, |
| 843 textures[texIdx2], params2, | 851 textures[texIdx2], params2, |
| 844 textColor, | 852 textColor, |
| 845 flags); | 853 flags); |
| 846 } | 854 } |
| OLD | NEW |