| 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" | 
| 11 #include "SkDistanceFieldGen.h" | 11 #include "SkDistanceFieldGen.h" | 
| 12 #include "gl/GrGLProcessor.h" | 12 #include "gl/GrGLProcessor.h" | 
| 13 #include "gl/GrGLSL.h" | 13 #include "gl/GrGLSL.h" | 
| 14 #include "gl/GrGLTexture.h" | 14 #include "gl/GrGLTexture.h" | 
| 15 #include "gl/GrGLGeometryProcessor.h" | 15 #include "gl/GrGLGeometryProcessor.h" | 
| 16 #include "gl/builders/GrGLProgramBuilder.h" | 16 #include "gl/builders/GrGLProgramBuilder.h" | 
| 17 | 17 | 
| 18 // Assuming a radius of the diagonal of the fragment, hence a factor of sqrt(2)/
     2 | 18 // Assuming a radius of the diagonal of the fragment, hence a factor of sqrt(2)/
     2 | 
| 19 #define SK_DistanceFieldAAFactor     "0.7071" | 19 #define SK_DistanceFieldAAFactor     "0.7071" | 
| 20 | 20 | 
| 21 struct DistanceFieldBatchTracker { | 21 struct DistanceFieldBatchTracker { | 
| 22     GrGPInput fInputColorType; | 22     GrGPInput fInputColorType; | 
| 23     GrColor fColor; | 23     GrColor fColor; | 
|  | 24     bool fUsesLocalCoords; | 
| 24 }; | 25 }; | 
| 25 | 26 | 
| 26 class GrGLDistanceFieldTextureEffect : public GrGLGeometryProcessor { | 27 class GrGLDistanceFieldTextureEffect : public GrGLGeometryProcessor { | 
| 27 public: | 28 public: | 
| 28     GrGLDistanceFieldTextureEffect(const GrGeometryProcessor&, | 29     GrGLDistanceFieldTextureEffect(const GrGeometryProcessor&, | 
| 29                                    const GrBatchTracker&) | 30                                    const GrBatchTracker&) | 
| 30         : fColor(GrColor_ILLEGAL) | 31         : fColor(GrColor_ILLEGAL) | 
| 31         , fTextureSize(SkISize::Make(-1,-1)) | 32         , fTextureSize(SkISize::Make(-1,-1)) | 
| 32 #ifdef SK_GAMMA_APPLY_TO_A8 | 33 #ifdef SK_GAMMA_APPLY_TO_A8 | 
| 33         , fLuminance(-1.0f) | 34         , fLuminance(-1.0f) | 
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 235 | 236 | 
| 236 GrGLGeometryProcessor* | 237 GrGLGeometryProcessor* | 
| 237 GrDistanceFieldTextureEffect::createGLInstance(const GrBatchTracker& bt) const { | 238 GrDistanceFieldTextureEffect::createGLInstance(const GrBatchTracker& bt) const { | 
| 238     return SkNEW_ARGS(GrGLDistanceFieldTextureEffect, (*this, bt)); | 239     return SkNEW_ARGS(GrGLDistanceFieldTextureEffect, (*this, bt)); | 
| 239 } | 240 } | 
| 240 | 241 | 
| 241 void GrDistanceFieldTextureEffect::initBatchTracker(GrBatchTracker* bt, const In
     itBT& init) const { | 242 void GrDistanceFieldTextureEffect::initBatchTracker(GrBatchTracker* bt, const In
     itBT& init) const { | 
| 242     DistanceFieldBatchTracker* local = bt->cast<DistanceFieldBatchTracker>(); | 243     DistanceFieldBatchTracker* local = bt->cast<DistanceFieldBatchTracker>(); | 
| 243     local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
     it, | 244     local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
     it, | 
| 244                                                SkToBool(fInColor)); | 245                                                SkToBool(fInColor)); | 
|  | 246     local->fUsesLocalCoords = init.fUsesLocalCoords; | 
| 245 } | 247 } | 
| 246 | 248 | 
| 247 bool GrDistanceFieldTextureEffect::onCanMakeEqual(const GrBatchTracker& m, | 249 bool GrDistanceFieldTextureEffect::onCanMakeEqual(const GrBatchTracker& m, | 
|  | 250                                                   const GrGeometryProcessor& tha
     t, | 
| 248                                                   const GrBatchTracker& t) const
      { | 251                                                   const GrBatchTracker& t) const
      { | 
| 249     const DistanceFieldBatchTracker& mine = m.cast<DistanceFieldBatchTracker>(); | 252     const DistanceFieldBatchTracker& mine = m.cast<DistanceFieldBatchTracker>(); | 
| 250     const DistanceFieldBatchTracker& theirs = t.cast<DistanceFieldBatchTracker>(
     ); | 253     const DistanceFieldBatchTracker& theirs = t.cast<DistanceFieldBatchTracker>(
     ); | 
| 251     return CanCombineOutput(mine.fInputColorType, mine.fColor, | 254     return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, | 
|  | 255                                    that, theirs.fUsesLocalCoords) && | 
|  | 256            CanCombineOutput(mine.fInputColorType, mine.fColor, | 
| 252                             theirs.fInputColorType, theirs.fColor); | 257                             theirs.fInputColorType, theirs.fColor); | 
| 253 } | 258 } | 
| 254 | 259 | 
| 255 /////////////////////////////////////////////////////////////////////////////// | 260 /////////////////////////////////////////////////////////////////////////////// | 
| 256 | 261 | 
| 257 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldTextureEffect); | 262 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldTextureEffect); | 
| 258 | 263 | 
| 259 GrGeometryProcessor* GrDistanceFieldTextureEffect::TestCreate(SkRandom* random, | 264 GrGeometryProcessor* GrDistanceFieldTextureEffect::TestCreate(SkRandom* random, | 
| 260                                                               GrContext*, | 265                                                               GrContext*, | 
| 261                                                               const GrDrawTarget
     Caps&, | 266                                                               const GrDrawTarget
     Caps&, | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
| 290                                                 random->nextBool() ? | 295                                                 random->nextBool() ? | 
| 291                                                     kSimilarity_DistanceFieldEff
     ectFlag : 0, | 296                                                     kSimilarity_DistanceFieldEff
     ectFlag : 0, | 
| 292                                                 random->nextBool()); | 297                                                 random->nextBool()); | 
| 293 } | 298 } | 
| 294 | 299 | 
| 295 /////////////////////////////////////////////////////////////////////////////// | 300 /////////////////////////////////////////////////////////////////////////////// | 
| 296 | 301 | 
| 297 struct DistanceFieldNoGammaBatchTracker { | 302 struct DistanceFieldNoGammaBatchTracker { | 
| 298     GrGPInput fInputColorType; | 303     GrGPInput fInputColorType; | 
| 299     GrColor fColor; | 304     GrColor fColor; | 
|  | 305     bool fUsesLocalCoords; | 
| 300 }; | 306 }; | 
| 301 | 307 | 
| 302 class GrGLDistanceFieldNoGammaTextureEffect : public GrGLGeometryProcessor { | 308 class GrGLDistanceFieldNoGammaTextureEffect : public GrGLGeometryProcessor { | 
| 303 public: | 309 public: | 
| 304     GrGLDistanceFieldNoGammaTextureEffect(const GrGeometryProcessor&, | 310     GrGLDistanceFieldNoGammaTextureEffect(const GrGeometryProcessor&, | 
| 305                                           const GrBatchTracker&) | 311                                           const GrBatchTracker&) | 
| 306         : fColor(GrColor_ILLEGAL), fTextureSize(SkISize::Make(-1, -1)) {} | 312         : fColor(GrColor_ILLEGAL), fTextureSize(SkISize::Make(-1, -1)) {} | 
| 307 | 313 | 
| 308     virtual void emitCode(const EmitArgs& args) SK_OVERRIDE { | 314     virtual void emitCode(const EmitArgs& args) SK_OVERRIDE { | 
| 309         const GrDistanceFieldNoGammaTextureEffect& dfTexEffect = | 315         const GrDistanceFieldNoGammaTextureEffect& dfTexEffect = | 
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 472 GrGLGeometryProcessor* | 478 GrGLGeometryProcessor* | 
| 473 GrDistanceFieldNoGammaTextureEffect::createGLInstance(const GrBatchTracker& bt) 
     const { | 479 GrDistanceFieldNoGammaTextureEffect::createGLInstance(const GrBatchTracker& bt) 
     const { | 
| 474     return SkNEW_ARGS(GrGLDistanceFieldNoGammaTextureEffect, (*this, bt)); | 480     return SkNEW_ARGS(GrGLDistanceFieldNoGammaTextureEffect, (*this, bt)); | 
| 475 } | 481 } | 
| 476 | 482 | 
| 477 void GrDistanceFieldNoGammaTextureEffect::initBatchTracker(GrBatchTracker* bt, | 483 void GrDistanceFieldNoGammaTextureEffect::initBatchTracker(GrBatchTracker* bt, | 
| 478                                                            const InitBT& init) c
     onst { | 484                                                            const InitBT& init) c
     onst { | 
| 479     DistanceFieldNoGammaBatchTracker* local = bt->cast<DistanceFieldNoGammaBatch
     Tracker>(); | 485     DistanceFieldNoGammaBatchTracker* local = bt->cast<DistanceFieldNoGammaBatch
     Tracker>(); | 
| 480     local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
     it, | 486     local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
     it, | 
| 481                                                SkToBool(fInColor)); | 487                                                SkToBool(fInColor)); | 
|  | 488     local->fUsesLocalCoords = init.fUsesLocalCoords; | 
| 482 } | 489 } | 
| 483 | 490 | 
| 484 bool GrDistanceFieldNoGammaTextureEffect::onCanMakeEqual(const GrBatchTracker& m
     , | 491 bool GrDistanceFieldNoGammaTextureEffect::onCanMakeEqual(const GrBatchTracker& m
     , | 
|  | 492                                                          const GrGeometryProcess
     or& that, | 
| 485                                                          const GrBatchTracker& t
     ) const { | 493                                                          const GrBatchTracker& t
     ) const { | 
| 486     const DistanceFieldNoGammaBatchTracker& mine = m.cast<DistanceFieldNoGammaBa
     tchTracker>(); | 494     const DistanceFieldNoGammaBatchTracker& mine = m.cast<DistanceFieldNoGammaBa
     tchTracker>(); | 
| 487     const DistanceFieldNoGammaBatchTracker& theirs = t.cast<DistanceFieldNoGamma
     BatchTracker>(); | 495     const DistanceFieldNoGammaBatchTracker& theirs = t.cast<DistanceFieldNoGamma
     BatchTracker>(); | 
| 488     return CanCombineOutput(mine.fInputColorType, mine.fColor, | 496     return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, | 
|  | 497                                    that, theirs.fUsesLocalCoords) && | 
|  | 498            CanCombineOutput(mine.fInputColorType, mine.fColor, | 
| 489                             theirs.fInputColorType, theirs.fColor); | 499                             theirs.fInputColorType, theirs.fColor); | 
| 490 } | 500 } | 
| 491 | 501 | 
| 492 /////////////////////////////////////////////////////////////////////////////// | 502 /////////////////////////////////////////////////////////////////////////////// | 
| 493 | 503 | 
| 494 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldNoGammaTextureEffect); | 504 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldNoGammaTextureEffect); | 
| 495 | 505 | 
| 496 GrGeometryProcessor* GrDistanceFieldNoGammaTextureEffect::TestCreate(SkRandom* r
     andom, | 506 GrGeometryProcessor* GrDistanceFieldNoGammaTextureEffect::TestCreate(SkRandom* r
     andom, | 
| 497                                                                      GrContext*, | 507                                                                      GrContext*, | 
| 498                                                                      const GrDra
     wTargetCaps&, | 508                                                                      const GrDra
     wTargetCaps&, | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 514     return GrDistanceFieldNoGammaTextureEffect::Create(GrRandomColor(random), te
     xtures[texIdx], | 524     return GrDistanceFieldNoGammaTextureEffect::Create(GrRandomColor(random), te
     xtures[texIdx], | 
| 515                                                        params, | 525                                                        params, | 
| 516         random->nextBool() ? kSimilarity_DistanceFieldEffectFlag : 0, random->ne
     xtBool()); | 526         random->nextBool() ? kSimilarity_DistanceFieldEffectFlag : 0, random->ne
     xtBool()); | 
| 517 } | 527 } | 
| 518 | 528 | 
| 519 /////////////////////////////////////////////////////////////////////////////// | 529 /////////////////////////////////////////////////////////////////////////////// | 
| 520 | 530 | 
| 521 struct DistanceFieldLCDBatchTracker { | 531 struct DistanceFieldLCDBatchTracker { | 
| 522     GrGPInput fInputColorType; | 532     GrGPInput fInputColorType; | 
| 523     GrColor fColor; | 533     GrColor fColor; | 
|  | 534     bool fUsesLocalCoords; | 
| 524 }; | 535 }; | 
| 525 | 536 | 
| 526 class GrGLDistanceFieldLCDTextureEffect : public GrGLGeometryProcessor { | 537 class GrGLDistanceFieldLCDTextureEffect : public GrGLGeometryProcessor { | 
| 527 public: | 538 public: | 
| 528     GrGLDistanceFieldLCDTextureEffect(const GrGeometryProcessor&, | 539     GrGLDistanceFieldLCDTextureEffect(const GrGeometryProcessor&, | 
| 529                                       const GrBatchTracker&) | 540                                       const GrBatchTracker&) | 
| 530     : fColor(GrColor_ILLEGAL) | 541     : fColor(GrColor_ILLEGAL) | 
| 531     , fTextureSize(SkISize::Make(-1,-1)) | 542     , fTextureSize(SkISize::Make(-1,-1)) | 
| 532     , fTextColor(GrColor_ILLEGAL) {} | 543     , fTextColor(GrColor_ILLEGAL) {} | 
| 533 | 544 | 
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 769 | 780 | 
| 770 GrGLGeometryProcessor* | 781 GrGLGeometryProcessor* | 
| 771 GrDistanceFieldLCDTextureEffect::createGLInstance(const GrBatchTracker& bt) cons
     t { | 782 GrDistanceFieldLCDTextureEffect::createGLInstance(const GrBatchTracker& bt) cons
     t { | 
| 772     return SkNEW_ARGS(GrGLDistanceFieldLCDTextureEffect, (*this, bt)); | 783     return SkNEW_ARGS(GrGLDistanceFieldLCDTextureEffect, (*this, bt)); | 
| 773 } | 784 } | 
| 774 | 785 | 
| 775 void GrDistanceFieldLCDTextureEffect::initBatchTracker(GrBatchTracker* bt, | 786 void GrDistanceFieldLCDTextureEffect::initBatchTracker(GrBatchTracker* bt, | 
| 776                                                        const InitBT& init) const
      { | 787                                                        const InitBT& init) const
      { | 
| 777     DistanceFieldLCDBatchTracker* local = bt->cast<DistanceFieldLCDBatchTracker>
     (); | 788     DistanceFieldLCDBatchTracker* local = bt->cast<DistanceFieldLCDBatchTracker>
     (); | 
| 778     local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
     it, false); | 789     local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
     it, false); | 
|  | 790     local->fUsesLocalCoords = init.fUsesLocalCoords; | 
| 779 } | 791 } | 
| 780 | 792 | 
| 781 bool GrDistanceFieldLCDTextureEffect::onCanMakeEqual(const GrBatchTracker& m, | 793 bool GrDistanceFieldLCDTextureEffect::onCanMakeEqual(const GrBatchTracker& m, | 
|  | 794                                                      const GrGeometryProcessor& 
     that, | 
| 782                                                      const GrBatchTracker& t) co
     nst { | 795                                                      const GrBatchTracker& t) co
     nst { | 
| 783     const DistanceFieldLCDBatchTracker& mine = m.cast<DistanceFieldLCDBatchTrack
     er>(); | 796     const DistanceFieldLCDBatchTracker& mine = m.cast<DistanceFieldLCDBatchTrack
     er>(); | 
| 784     const DistanceFieldLCDBatchTracker& theirs = t.cast<DistanceFieldLCDBatchTra
     cker>(); | 797     const DistanceFieldLCDBatchTracker& theirs = t.cast<DistanceFieldLCDBatchTra
     cker>(); | 
| 785     return CanCombineOutput(mine.fInputColorType, mine.fColor, | 798     return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, | 
|  | 799                                    that, theirs.fUsesLocalCoords) && | 
|  | 800            CanCombineOutput(mine.fInputColorType, mine.fColor, | 
| 786                             theirs.fInputColorType, theirs.fColor); | 801                             theirs.fInputColorType, theirs.fColor); | 
| 787 } | 802 } | 
| 788 | 803 | 
| 789 /////////////////////////////////////////////////////////////////////////////// | 804 /////////////////////////////////////////////////////////////////////////////// | 
| 790 | 805 | 
| 791 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldLCDTextureEffect); | 806 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldLCDTextureEffect); | 
| 792 | 807 | 
| 793 GrGeometryProcessor* GrDistanceFieldLCDTextureEffect::TestCreate(SkRandom* rando
     m, | 808 GrGeometryProcessor* GrDistanceFieldLCDTextureEffect::TestCreate(SkRandom* rando
     m, | 
| 794                                                                  GrContext*, | 809                                                                  GrContext*, | 
| 795                                                                  const GrDrawTar
     getCaps&, | 810                                                                  const GrDrawTar
     getCaps&, | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 816                                         random->nextULessThan(256), | 831                                         random->nextULessThan(256), | 
| 817                                         random->nextULessThan(256)); | 832                                         random->nextULessThan(256)); | 
| 818     uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 833     uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 
| 819     flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 834     flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 
| 820     flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 835     flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 
| 821     return GrDistanceFieldLCDTextureEffect::Create(GrRandomColor(random), textur
     es[texIdx], params, | 836     return GrDistanceFieldLCDTextureEffect::Create(GrRandomColor(random), textur
     es[texIdx], params, | 
| 822                                                    textures[texIdx2], params2, | 837                                                    textures[texIdx2], params2, | 
| 823                                                    textColor, | 838                                                    textColor, | 
| 824                                                    flags); | 839                                                    flags); | 
| 825 } | 840 } | 
| OLD | NEW | 
|---|