Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: src/effects/SkLightingImageFilter.cpp

Issue 1287023009: Added tree structure to GrGLFragmentProcessor, i.e. GL instances (Closed) Base URL: https://skia.googlesource.com/skia@cs3_isequal_nonrecursive
Patch Set: moved onSetData from public to protected, onCreateGLInstance from public to private in subclasses Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/effects/SkDisplacementMapEffect.cpp ('k') | src/effects/SkLightingShader.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 texture, 526 texture,
527 light, 527 light,
528 surfaceScale, 528 surfaceScale,
529 matrix, 529 matrix,
530 kd, 530 kd,
531 boundaryMode)); 531 boundaryMode));
532 } 532 }
533 533
534 const char* name() const override { return "DiffuseLighting"; } 534 const char* name() const override { return "DiffuseLighting"; }
535 535
536 GrGLFragmentProcessor* createGLInstance() const override;
537
538 SkScalar kd() const { return fKD; } 536 SkScalar kd() const { return fKD; }
539 537
540 private: 538 private:
539 GrGLFragmentProcessor* onCreateGLInstance() const override;
540
541 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride; 541 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride;
542 542
543 bool onIsEqual(const GrFragmentProcessor&) const override; 543 bool onIsEqual(const GrFragmentProcessor&) const override;
544 544
545 GrDiffuseLightingEffect(GrProcessorDataManager*, 545 GrDiffuseLightingEffect(GrProcessorDataManager*,
546 GrTexture* texture, 546 GrTexture* texture,
547 const SkLight* light, 547 const SkLight* light,
548 SkScalar surfaceScale, 548 SkScalar surfaceScale,
549 const SkMatrix& matrix, 549 const SkMatrix& matrix,
550 SkScalar kd, 550 SkScalar kd,
(...skipping 19 matching lines...) Expand all
570 light, 570 light,
571 surfaceScale, 571 surfaceScale,
572 matrix, 572 matrix,
573 ks, 573 ks,
574 shininess, 574 shininess,
575 boundaryMode)); 575 boundaryMode));
576 } 576 }
577 577
578 const char* name() const override { return "SpecularLighting"; } 578 const char* name() const override { return "SpecularLighting"; }
579 579
580 GrGLFragmentProcessor* createGLInstance() const override; 580 GrGLFragmentProcessor* onCreateGLInstance() const override;
581 581
582 SkScalar ks() const { return fKS; } 582 SkScalar ks() const { return fKS; }
583 SkScalar shininess() const { return fShininess; } 583 SkScalar shininess() const { return fShininess; }
584 584
585 private: 585 private:
586 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride; 586 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride;
587 587
588 bool onIsEqual(const GrFragmentProcessor&) const override; 588 bool onIsEqual(const GrFragmentProcessor&) const override;
589 589
590 GrSpecularLightingEffect(GrProcessorDataManager*, 590 GrSpecularLightingEffect(GrProcessorDataManager*,
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
1510 1510
1511 class GrGLLightingEffect : public GrGLFragmentProcessor { 1511 class GrGLLightingEffect : public GrGLFragmentProcessor {
1512 public: 1512 public:
1513 GrGLLightingEffect(const GrProcessor&); 1513 GrGLLightingEffect(const GrProcessor&);
1514 virtual ~GrGLLightingEffect(); 1514 virtual ~GrGLLightingEffect();
1515 1515
1516 void emitCode(EmitArgs&) override; 1516 void emitCode(EmitArgs&) override;
1517 1517
1518 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder* b); 1518 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder* b);
1519 1519
1520 protected:
1520 /** 1521 /**
1521 * Subclasses of GrGLLightingEffect must call INHERITED::setData(); 1522 * Subclasses of GrGLLightingEffect must call INHERITED::onSetData();
1522 */ 1523 */
1523 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 1524 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override;
1524 1525
1525 protected:
1526 virtual void emitLightFunc(GrGLFPBuilder*, SkString* funcName) = 0; 1526 virtual void emitLightFunc(GrGLFPBuilder*, SkString* funcName) = 0;
1527 1527
1528 private: 1528 private:
1529 typedef GrGLFragmentProcessor INHERITED; 1529 typedef GrGLFragmentProcessor INHERITED;
1530 1530
1531 UniformHandle fImageIncrementUni; 1531 UniformHandle fImageIncrementUni;
1532 UniformHandle fSurfaceScaleUni; 1532 UniformHandle fSurfaceScaleUni;
1533 GrGLLight* fLight; 1533 GrGLLight* fLight;
1534 BoundaryMode fBoundaryMode; 1534 BoundaryMode fBoundaryMode;
1535 }; 1535 };
1536 1536
1537 /////////////////////////////////////////////////////////////////////////////// 1537 ///////////////////////////////////////////////////////////////////////////////
1538 1538
1539 class GrGLDiffuseLightingEffect : public GrGLLightingEffect { 1539 class GrGLDiffuseLightingEffect : public GrGLLightingEffect {
1540 public: 1540 public:
1541 GrGLDiffuseLightingEffect(const GrProcessor&); 1541 GrGLDiffuseLightingEffect(const GrProcessor&);
1542 void emitLightFunc(GrGLFPBuilder*, SkString* funcName) override; 1542 void emitLightFunc(GrGLFPBuilder*, SkString* funcName) override;
1543 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 1543
1544 protected:
1545 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override;
1544 1546
1545 private: 1547 private:
1546 typedef GrGLLightingEffect INHERITED; 1548 typedef GrGLLightingEffect INHERITED;
1547 1549
1548 UniformHandle fKDUni; 1550 UniformHandle fKDUni;
1549 }; 1551 };
1550 1552
1551 /////////////////////////////////////////////////////////////////////////////// 1553 ///////////////////////////////////////////////////////////////////////////////
1552 1554
1553 class GrGLSpecularLightingEffect : public GrGLLightingEffect { 1555 class GrGLSpecularLightingEffect : public GrGLLightingEffect {
1554 public: 1556 public:
1555 GrGLSpecularLightingEffect(const GrProcessor&); 1557 GrGLSpecularLightingEffect(const GrProcessor&);
1556 void emitLightFunc(GrGLFPBuilder*, SkString* funcName) override; 1558 void emitLightFunc(GrGLFPBuilder*, SkString* funcName) override;
1557 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 1559
1560 protected:
1561 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override;
1558 1562
1559 private: 1563 private:
1560 typedef GrGLLightingEffect INHERITED; 1564 typedef GrGLLightingEffect INHERITED;
1561 1565
1562 UniformHandle fKSUni; 1566 UniformHandle fKSUni;
1563 UniformHandle fShininessUni; 1567 UniformHandle fShininessUni;
1564 }; 1568 };
1565 1569
1566 /////////////////////////////////////////////////////////////////////////////// 1570 ///////////////////////////////////////////////////////////////////////////////
1567 1571
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>(); 1614 const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>();
1611 return INHERITED::onIsEqual(sBase) && 1615 return INHERITED::onIsEqual(sBase) &&
1612 this->kd() == s.kd(); 1616 this->kd() == s.kd();
1613 } 1617 }
1614 1618
1615 void GrDiffuseLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, 1619 void GrDiffuseLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
1616 GrProcessorKeyBuilder* b) const { 1620 GrProcessorKeyBuilder* b) const {
1617 GrGLDiffuseLightingEffect::GenKey(*this, caps, b); 1621 GrGLDiffuseLightingEffect::GenKey(*this, caps, b);
1618 } 1622 }
1619 1623
1620 GrGLFragmentProcessor* GrDiffuseLightingEffect::createGLInstance() const { 1624 GrGLFragmentProcessor* GrDiffuseLightingEffect::onCreateGLInstance() const {
1621 return SkNEW_ARGS(GrGLDiffuseLightingEffect, (*this)); 1625 return SkNEW_ARGS(GrGLDiffuseLightingEffect, (*this));
1622 } 1626 }
1623 1627
1624 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect); 1628 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect);
1625 1629
1626 GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(GrProcessorTestData* d) { 1630 GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(GrProcessorTestData* d) {
1627 SkScalar surfaceScale = d->fRandom->nextSScalar1(); 1631 SkScalar surfaceScale = d->fRandom->nextSScalar1();
1628 SkScalar kd = d->fRandom->nextUScalar1(); 1632 SkScalar kd = d->fRandom->nextUScalar1();
1629 SkAutoTUnref<SkLight> light(create_random_light(d->fRandom)); 1633 SkAutoTUnref<SkLight> light(create_random_light(d->fRandom));
1630 SkMatrix matrix; 1634 SkMatrix matrix;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1736 GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor); 1740 GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor);
1737 fsBuilder->codeAppend(modulate.c_str()); 1741 fsBuilder->codeAppend(modulate.c_str());
1738 } 1742 }
1739 1743
1740 void GrGLLightingEffect::GenKey(const GrProcessor& proc, 1744 void GrGLLightingEffect::GenKey(const GrProcessor& proc,
1741 const GrGLSLCaps& caps, GrProcessorKeyBuilder* b ) { 1745 const GrGLSLCaps& caps, GrProcessorKeyBuilder* b ) {
1742 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>(); 1746 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>();
1743 b->add32(lighting.boundaryMode() << 2 | lighting.light()->type()); 1747 b->add32(lighting.boundaryMode() << 2 | lighting.light()->type());
1744 } 1748 }
1745 1749
1746 void GrGLLightingEffect::setData(const GrGLProgramDataManager& pdman, 1750 void GrGLLightingEffect::onSetData(const GrGLProgramDataManager& pdman,
1747 const GrProcessor& proc) { 1751 const GrProcessor& proc) {
1748 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>(); 1752 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>();
1749 GrTexture* texture = lighting.texture(0); 1753 GrTexture* texture = lighting.texture(0);
1750 float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f; 1754 float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f;
1751 pdman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->he ight()); 1755 pdman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->he ight());
1752 pdman.set1f(fSurfaceScaleUni, lighting.surfaceScale()); 1756 pdman.set1f(fSurfaceScaleUni, lighting.surfaceScale());
1753 SkAutoTUnref<SkLight> transformedLight(lighting.light()->transform(lighting. filterMatrix())); 1757 SkAutoTUnref<SkLight> transformedLight(lighting.light()->transform(lighting. filterMatrix()));
1754 fLight->setData(pdman, transformedLight); 1758 fLight->setData(pdman, transformedLight);
1755 } 1759 }
1756 1760
(...skipping 20 matching lines...) Expand all
1777 lightBody.appendf("\tfloat colorScale = %s * dot(normal, surfaceToLight);\n" , kd); 1781 lightBody.appendf("\tfloat colorScale = %s * dot(normal, surfaceToLight);\n" , kd);
1778 lightBody.appendf("\treturn vec4(lightColor * clamp(colorScale, 0.0, 1.0), 1 .0);\n"); 1782 lightBody.appendf("\treturn vec4(lightColor * clamp(colorScale, 0.0, 1.0), 1 .0);\n");
1779 builder->getFragmentShaderBuilder()->emitFunction(kVec4f_GrSLType, 1783 builder->getFragmentShaderBuilder()->emitFunction(kVec4f_GrSLType,
1780 "light", 1784 "light",
1781 SK_ARRAY_COUNT(gLightArgs) , 1785 SK_ARRAY_COUNT(gLightArgs) ,
1782 gLightArgs, 1786 gLightArgs,
1783 lightBody.c_str(), 1787 lightBody.c_str(),
1784 funcName); 1788 funcName);
1785 } 1789 }
1786 1790
1787 void GrGLDiffuseLightingEffect::setData(const GrGLProgramDataManager& pdman, 1791 void GrGLDiffuseLightingEffect::onSetData(const GrGLProgramDataManager& pdman,
1788 const GrProcessor& proc) { 1792 const GrProcessor& proc) {
1789 INHERITED::setData(pdman, proc); 1793 INHERITED::onSetData(pdman, proc);
1790 const GrDiffuseLightingEffect& diffuse = proc.cast<GrDiffuseLightingEffect>( ); 1794 const GrDiffuseLightingEffect& diffuse = proc.cast<GrDiffuseLightingEffect>( );
1791 pdman.set1f(fKDUni, diffuse.kd()); 1795 pdman.set1f(fKDUni, diffuse.kd());
1792 } 1796 }
1793 1797
1794 /////////////////////////////////////////////////////////////////////////////// 1798 ///////////////////////////////////////////////////////////////////////////////
1795 1799
1796 GrSpecularLightingEffect::GrSpecularLightingEffect(GrProcessorDataManager* procD ataManager, 1800 GrSpecularLightingEffect::GrSpecularLightingEffect(GrProcessorDataManager* procD ataManager,
1797 GrTexture* texture, 1801 GrTexture* texture,
1798 const SkLight* light, 1802 const SkLight* light,
1799 SkScalar surfaceScale, 1803 SkScalar surfaceScale,
(...skipping 12 matching lines...) Expand all
1812 return INHERITED::onIsEqual(sBase) && 1816 return INHERITED::onIsEqual(sBase) &&
1813 this->ks() == s.ks() && 1817 this->ks() == s.ks() &&
1814 this->shininess() == s.shininess(); 1818 this->shininess() == s.shininess();
1815 } 1819 }
1816 1820
1817 void GrSpecularLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, 1821 void GrSpecularLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
1818 GrProcessorKeyBuilder* b) const { 1822 GrProcessorKeyBuilder* b) const {
1819 GrGLSpecularLightingEffect::GenKey(*this, caps, b); 1823 GrGLSpecularLightingEffect::GenKey(*this, caps, b);
1820 } 1824 }
1821 1825
1822 GrGLFragmentProcessor* GrSpecularLightingEffect::createGLInstance() const { 1826 GrGLFragmentProcessor* GrSpecularLightingEffect::onCreateGLInstance() const {
1823 return SkNEW_ARGS(GrGLSpecularLightingEffect, (*this)); 1827 return SkNEW_ARGS(GrGLSpecularLightingEffect, (*this));
1824 } 1828 }
1825 1829
1826 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect); 1830 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect);
1827 1831
1828 GrFragmentProcessor* GrSpecularLightingEffect::TestCreate(GrProcessorTestData* d ) { 1832 GrFragmentProcessor* GrSpecularLightingEffect::TestCreate(GrProcessorTestData* d ) {
1829 SkScalar surfaceScale = d->fRandom->nextSScalar1(); 1833 SkScalar surfaceScale = d->fRandom->nextSScalar1();
1830 SkScalar ks = d->fRandom->nextUScalar1(); 1834 SkScalar ks = d->fRandom->nextUScalar1();
1831 SkScalar shininess = d->fRandom->nextUScalar1(); 1835 SkScalar shininess = d->fRandom->nextUScalar1();
1832 SkAutoTUnref<SkLight> light(create_random_light(d->fRandom)); 1836 SkAutoTUnref<SkLight> light(create_random_light(d->fRandom));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1869 lightBody.appendf("\tvec3 color = lightColor * clamp(colorScale, 0.0, 1.0);\ n"); 1873 lightBody.appendf("\tvec3 color = lightColor * clamp(colorScale, 0.0, 1.0);\ n");
1870 lightBody.appendf("\treturn vec4(color, max(max(color.r, color.g), color.b)) ;\n"); 1874 lightBody.appendf("\treturn vec4(color, max(max(color.r, color.g), color.b)) ;\n");
1871 builder->getFragmentShaderBuilder()->emitFunction(kVec4f_GrSLType, 1875 builder->getFragmentShaderBuilder()->emitFunction(kVec4f_GrSLType,
1872 "light", 1876 "light",
1873 SK_ARRAY_COUNT(gLightArgs) , 1877 SK_ARRAY_COUNT(gLightArgs) ,
1874 gLightArgs, 1878 gLightArgs,
1875 lightBody.c_str(), 1879 lightBody.c_str(),
1876 funcName); 1880 funcName);
1877 } 1881 }
1878 1882
1879 void GrGLSpecularLightingEffect::setData(const GrGLProgramDataManager& pdman, 1883 void GrGLSpecularLightingEffect::onSetData(const GrGLProgramDataManager& pdman,
1880 const GrProcessor& effect) { 1884 const GrProcessor& effect) {
1881 INHERITED::setData(pdman, effect); 1885 INHERITED::onSetData(pdman, effect);
1882 const GrSpecularLightingEffect& spec = effect.cast<GrSpecularLightingEffect> (); 1886 const GrSpecularLightingEffect& spec = effect.cast<GrSpecularLightingEffect> ();
1883 pdman.set1f(fKSUni, spec.ks()); 1887 pdman.set1f(fKSUni, spec.ks());
1884 pdman.set1f(fShininessUni, spec.shininess()); 1888 pdman.set1f(fShininessUni, spec.shininess());
1885 } 1889 }
1886 1890
1887 /////////////////////////////////////////////////////////////////////////////// 1891 ///////////////////////////////////////////////////////////////////////////////
1888 void GrGLLight::emitLightColorUniform(GrGLFPBuilder* builder) { 1892 void GrGLLight::emitLightColorUniform(GrGLFPBuilder* builder) {
1889 fColorUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, 1893 fColorUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
1890 kVec3f_GrSLType, kDefault_GrSLPrecision, 1894 kVec3f_GrSLType, kDefault_GrSLPrecision,
1891 "LightColor"); 1895 "LightColor");
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
2013 2017
2014 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); 2018 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight);
2015 } 2019 }
2016 2020
2017 #endif 2021 #endif
2018 2022
2019 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) 2023 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter)
2020 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) 2024 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter)
2021 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) 2025 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter)
2022 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 2026 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « src/effects/SkDisplacementMapEffect.cpp ('k') | src/effects/SkLightingShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698