| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
| 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 "SkLightingImageFilter.h" | 8 #include "SkLightingImageFilter.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 return SkNEW_ARGS(GrDiffuseLightingEffect, (texture, | 501 return SkNEW_ARGS(GrDiffuseLightingEffect, (texture, |
| 502 light, | 502 light, |
| 503 surfaceScale, | 503 surfaceScale, |
| 504 matrix, | 504 matrix, |
| 505 kd, | 505 kd, |
| 506 boundaryMode)); | 506 boundaryMode)); |
| 507 } | 507 } |
| 508 | 508 |
| 509 const char* name() const override { return "DiffuseLighting"; } | 509 const char* name() const override { return "DiffuseLighting"; } |
| 510 | 510 |
| 511 void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) const overri
de; | 511 void getGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const over
ride; |
| 512 | 512 |
| 513 GrGLFragmentProcessor* createGLInstance() const override; | 513 GrGLFragmentProcessor* createGLInstance() const override; |
| 514 | 514 |
| 515 SkScalar kd() const { return fKD; } | 515 SkScalar kd() const { return fKD; } |
| 516 | 516 |
| 517 private: | 517 private: |
| 518 bool onIsEqual(const GrFragmentProcessor&) const override; | 518 bool onIsEqual(const GrFragmentProcessor&) const override; |
| 519 | 519 |
| 520 GrDiffuseLightingEffect(GrTexture* texture, | 520 GrDiffuseLightingEffect(GrTexture* texture, |
| 521 const SkLight* light, | 521 const SkLight* light, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 542 light, | 542 light, |
| 543 surfaceScale, | 543 surfaceScale, |
| 544 matrix, | 544 matrix, |
| 545 ks, | 545 ks, |
| 546 shininess, | 546 shininess, |
| 547 boundaryMode)); | 547 boundaryMode)); |
| 548 } | 548 } |
| 549 | 549 |
| 550 const char* name() const override { return "SpecularLighting"; } | 550 const char* name() const override { return "SpecularLighting"; } |
| 551 | 551 |
| 552 void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) const overri
de; | 552 void getGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const over
ride; |
| 553 | 553 |
| 554 GrGLFragmentProcessor* createGLInstance() const override; | 554 GrGLFragmentProcessor* createGLInstance() const override; |
| 555 | 555 |
| 556 SkScalar ks() const { return fKS; } | 556 SkScalar ks() const { return fKS; } |
| 557 SkScalar shininess() const { return fShininess; } | 557 SkScalar shininess() const { return fShininess; } |
| 558 | 558 |
| 559 private: | 559 private: |
| 560 bool onIsEqual(const GrFragmentProcessor&) const override; | 560 bool onIsEqual(const GrFragmentProcessor&) const override; |
| 561 | 561 |
| 562 GrSpecularLightingEffect(GrTexture* texture, | 562 GrSpecularLightingEffect(GrTexture* texture, |
| (...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1474 GrGLLightingEffect(const GrProcessor&); | 1474 GrGLLightingEffect(const GrProcessor&); |
| 1475 virtual ~GrGLLightingEffect(); | 1475 virtual ~GrGLLightingEffect(); |
| 1476 | 1476 |
| 1477 void emitCode(GrGLFPBuilder*, | 1477 void emitCode(GrGLFPBuilder*, |
| 1478 const GrFragmentProcessor&, | 1478 const GrFragmentProcessor&, |
| 1479 const char* outputColor, | 1479 const char* outputColor, |
| 1480 const char* inputColor, | 1480 const char* inputColor, |
| 1481 const TransformedCoordsArray&, | 1481 const TransformedCoordsArray&, |
| 1482 const TextureSamplerArray&) override; | 1482 const TextureSamplerArray&) override; |
| 1483 | 1483 |
| 1484 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder* b); | 1484 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder* b); |
| 1485 | 1485 |
| 1486 /** | 1486 /** |
| 1487 * Subclasses of GrGLLightingEffect must call INHERITED::setData(); | 1487 * Subclasses of GrGLLightingEffect must call INHERITED::setData(); |
| 1488 */ | 1488 */ |
| 1489 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; | 1489 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; |
| 1490 | 1490 |
| 1491 protected: | 1491 protected: |
| 1492 virtual void emitLightFunc(GrGLFPBuilder*, SkString* funcName) = 0; | 1492 virtual void emitLightFunc(GrGLFPBuilder*, SkString* funcName) = 0; |
| 1493 | 1493 |
| 1494 private: | 1494 private: |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1569 : INHERITED(texture, light, surfaceScale, matrix, boundaryMode), fKD(kd) { | 1569 : INHERITED(texture, light, surfaceScale, matrix, boundaryMode), fKD(kd) { |
| 1570 this->initClassID<GrDiffuseLightingEffect>(); | 1570 this->initClassID<GrDiffuseLightingEffect>(); |
| 1571 } | 1571 } |
| 1572 | 1572 |
| 1573 bool GrDiffuseLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const
{ | 1573 bool GrDiffuseLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const
{ |
| 1574 const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>(); | 1574 const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>(); |
| 1575 return INHERITED::onIsEqual(sBase) && | 1575 return INHERITED::onIsEqual(sBase) && |
| 1576 this->kd() == s.kd(); | 1576 this->kd() == s.kd(); |
| 1577 } | 1577 } |
| 1578 | 1578 |
| 1579 void GrDiffuseLightingEffect::getGLProcessorKey(const GrGLCaps& caps, | 1579 void GrDiffuseLightingEffect::getGLProcessorKey(const GrGLSLCaps& caps, |
| 1580 GrProcessorKeyBuilder* b) const
{ | 1580 GrProcessorKeyBuilder* b) const
{ |
| 1581 GrGLDiffuseLightingEffect::GenKey(*this, caps, b); | 1581 GrGLDiffuseLightingEffect::GenKey(*this, caps, b); |
| 1582 } | 1582 } |
| 1583 | 1583 |
| 1584 GrGLFragmentProcessor* GrDiffuseLightingEffect::createGLInstance() const { | 1584 GrGLFragmentProcessor* GrDiffuseLightingEffect::createGLInstance() const { |
| 1585 return SkNEW_ARGS(GrGLDiffuseLightingEffect, (*this)); | 1585 return SkNEW_ARGS(GrGLDiffuseLightingEffect, (*this)); |
| 1586 } | 1586 } |
| 1587 | 1587 |
| 1588 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect); | 1588 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect); |
| 1589 | 1589 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 fsBuilder->codeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ", | 1702 fsBuilder->codeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ", |
| 1703 outputColor, lightFunc.c_str(), normalName.c_str(), s
urfScale); | 1703 outputColor, lightFunc.c_str(), normalName.c_str(), s
urfScale); |
| 1704 fLight->emitLightColor(builder, "surfaceToLight"); | 1704 fLight->emitLightColor(builder, "surfaceToLight"); |
| 1705 fsBuilder->codeAppend(");\n"); | 1705 fsBuilder->codeAppend(");\n"); |
| 1706 SkString modulate; | 1706 SkString modulate; |
| 1707 GrGLSLMulVarBy4f(&modulate, outputColor, inputColor); | 1707 GrGLSLMulVarBy4f(&modulate, outputColor, inputColor); |
| 1708 fsBuilder->codeAppend(modulate.c_str()); | 1708 fsBuilder->codeAppend(modulate.c_str()); |
| 1709 } | 1709 } |
| 1710 | 1710 |
| 1711 void GrGLLightingEffect::GenKey(const GrProcessor& proc, | 1711 void GrGLLightingEffect::GenKey(const GrProcessor& proc, |
| 1712 const GrGLCaps& caps, GrProcessorKeyBuilder* b)
{ | 1712 const GrGLSLCaps& caps, GrProcessorKeyBuilder* b
) { |
| 1713 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>(); | 1713 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>(); |
| 1714 b->add32(lighting.boundaryMode() << 2 | lighting.light()->type()); | 1714 b->add32(lighting.boundaryMode() << 2 | lighting.light()->type()); |
| 1715 } | 1715 } |
| 1716 | 1716 |
| 1717 void GrGLLightingEffect::setData(const GrGLProgramDataManager& pdman, | 1717 void GrGLLightingEffect::setData(const GrGLProgramDataManager& pdman, |
| 1718 const GrProcessor& proc) { | 1718 const GrProcessor& proc) { |
| 1719 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>(); | 1719 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>(); |
| 1720 GrTexture* texture = lighting.texture(0); | 1720 GrTexture* texture = lighting.texture(0); |
| 1721 float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f; | 1721 float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f; |
| 1722 pdman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->he
ight()); | 1722 pdman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->he
ight()); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1777 this->initClassID<GrSpecularLightingEffect>(); | 1777 this->initClassID<GrSpecularLightingEffect>(); |
| 1778 } | 1778 } |
| 1779 | 1779 |
| 1780 bool GrSpecularLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const
{ | 1780 bool GrSpecularLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const
{ |
| 1781 const GrSpecularLightingEffect& s = sBase.cast<GrSpecularLightingEffect>(); | 1781 const GrSpecularLightingEffect& s = sBase.cast<GrSpecularLightingEffect>(); |
| 1782 return INHERITED::onIsEqual(sBase) && | 1782 return INHERITED::onIsEqual(sBase) && |
| 1783 this->ks() == s.ks() && | 1783 this->ks() == s.ks() && |
| 1784 this->shininess() == s.shininess(); | 1784 this->shininess() == s.shininess(); |
| 1785 } | 1785 } |
| 1786 | 1786 |
| 1787 void GrSpecularLightingEffect::getGLProcessorKey(const GrGLCaps& caps, | 1787 void GrSpecularLightingEffect::getGLProcessorKey(const GrGLSLCaps& caps, |
| 1788 GrProcessorKeyBuilder* b) const
{ | 1788 GrProcessorKeyBuilder* b) const
{ |
| 1789 GrGLSpecularLightingEffect::GenKey(*this, caps, b); | 1789 GrGLSpecularLightingEffect::GenKey(*this, caps, b); |
| 1790 } | 1790 } |
| 1791 | 1791 |
| 1792 GrGLFragmentProcessor* GrSpecularLightingEffect::createGLInstance() const { | 1792 GrGLFragmentProcessor* GrSpecularLightingEffect::createGLInstance() const { |
| 1793 return SkNEW_ARGS(GrGLSpecularLightingEffect, (*this)); | 1793 return SkNEW_ARGS(GrGLSpecularLightingEffect, (*this)); |
| 1794 } | 1794 } |
| 1795 | 1795 |
| 1796 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect); | 1796 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect); |
| 1797 | 1797 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1986 | 1986 |
| 1987 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 1987 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
| 1988 } | 1988 } |
| 1989 | 1989 |
| 1990 #endif | 1990 #endif |
| 1991 | 1991 |
| 1992 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1992 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
| 1993 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1993 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
| 1994 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1994 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
| 1995 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1995 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |