| 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" | 
| 11 #include "SkDevice.h" | 11 #include "SkDevice.h" | 
| 12 #include "SkPoint3.h" | 12 #include "SkPoint3.h" | 
| 13 #include "SkReadBuffer.h" | 13 #include "SkReadBuffer.h" | 
| 14 #include "SkTypes.h" | 14 #include "SkTypes.h" | 
| 15 #include "SkWriteBuffer.h" | 15 #include "SkWriteBuffer.h" | 
| 16 | 16 | 
| 17 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU | 
| 18 #include "GrContext.h" | 18 #include "GrContext.h" | 
| 19 #include "GrDrawContext.h" | 19 #include "GrDrawContext.h" | 
| 20 #include "GrFragmentProcessor.h" | 20 #include "GrFragmentProcessor.h" | 
| 21 #include "GrInvariantOutput.h" | 21 #include "GrInvariantOutput.h" | 
| 22 #include "GrPaint.h" | 22 #include "GrPaint.h" | 
| 23 #include "effects/GrSingleTextureEffect.h" | 23 #include "effects/GrSingleTextureEffect.h" | 
| 24 #include "glsl/GrGLSLFragmentProcessor.h" | 24 #include "glsl/GrGLSLFragmentProcessor.h" | 
| 25 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 25 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 
| 26 #include "glsl/GrGLSLProgramBuilder.h" |  | 
| 27 #include "glsl/GrGLSLProgramDataManager.h" | 26 #include "glsl/GrGLSLProgramDataManager.h" | 
|  | 27 #include "glsl/GrGLSLUniformHandler.h" | 
| 28 | 28 | 
| 29 class GrGLDiffuseLightingEffect; | 29 class GrGLDiffuseLightingEffect; | 
| 30 class GrGLSpecularLightingEffect; | 30 class GrGLSpecularLightingEffect; | 
| 31 | 31 | 
| 32 // For brevity | 32 // For brevity | 
| 33 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; | 33 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; | 
| 34 #endif | 34 #endif | 
| 35 | 35 | 
| 36 namespace { | 36 namespace { | 
| 37 | 37 | 
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 592 /////////////////////////////////////////////////////////////////////////////// | 592 /////////////////////////////////////////////////////////////////////////////// | 
| 593 | 593 | 
| 594 class GrGLLight { | 594 class GrGLLight { | 
| 595 public: | 595 public: | 
| 596     virtual ~GrGLLight() {} | 596     virtual ~GrGLLight() {} | 
| 597 | 597 | 
| 598     /** | 598     /** | 
| 599      * This is called by GrGLLightingEffect::emitCode() before either of the two
       virtual functions | 599      * This is called by GrGLLightingEffect::emitCode() before either of the two
       virtual functions | 
| 600      * below. It adds a vec3f uniform visible in the FS that represents the cons
      tant light color. | 600      * below. It adds a vec3f uniform visible in the FS that represents the cons
      tant light color. | 
| 601      */ | 601      */ | 
| 602     void emitLightColorUniform(GrGLSLFPBuilder*); | 602     void emitLightColorUniform(GrGLSLUniformHandler*); | 
| 603 | 603 | 
| 604     /** | 604     /** | 
| 605      * These two functions are called from GrGLLightingEffect's emitCode() funct
      ion. | 605      * These two functions are called from GrGLLightingEffect's emitCode() funct
      ion. | 
| 606      * emitSurfaceToLight places an expression in param out that is the vector f
      rom the surface to | 606      * emitSurfaceToLight places an expression in param out that is the vector f
      rom the surface to | 
| 607      * the light. The expression will be used in the FS. emitLightColor writes a
      n expression into | 607      * the light. The expression will be used in the FS. emitLightColor writes a
      n expression into | 
| 608      * the FS that is the color of the light. Either function may add functions 
      and/or uniforms to | 608      * the FS that is the color of the light. Either function may add functions 
      and/or uniforms to | 
| 609      * the FS. The default of emitLightColor appends the name of the constant li
      ght color uniform | 609      * the FS. The default of emitLightColor appends the name of the constant li
      ght color uniform | 
| 610      * and so this function only needs to be overridden if the light color varie
      s spatially. | 610      * and so this function only needs to be overridden if the light color varie
      s spatially. | 
| 611      */ | 611      */ | 
| 612     virtual void emitSurfaceToLight(GrGLSLFPBuilder*, GrGLSLFragmentBuilder*, co
      nst char* z) = 0; | 612     virtual void emitSurfaceToLight(GrGLSLUniformHandler*, | 
| 613     virtual void emitLightColor(GrGLSLFPBuilder*, | 613                                     GrGLSLFragmentBuilder*, | 
|  | 614                                     const char* z) = 0; | 
|  | 615     virtual void emitLightColor(GrGLSLUniformHandler*, | 
| 614                                 GrGLSLFragmentBuilder*, | 616                                 GrGLSLFragmentBuilder*, | 
| 615                                 const char *surfaceToLight); | 617                                 const char *surfaceToLight); | 
| 616 | 618 | 
| 617     // This is called from GrGLLightingEffect's setData(). Subclasses of GrGLLig
      ht must call | 619     // This is called from GrGLLightingEffect's setData(). Subclasses of GrGLLig
      ht must call | 
| 618     // INHERITED::setData(). | 620     // INHERITED::setData(). | 
| 619     virtual void setData(const GrGLSLProgramDataManager&, const SkImageFilterLig
      ht* light) const; | 621     virtual void setData(const GrGLSLProgramDataManager&, const SkImageFilterLig
      ht* light) const; | 
| 620 | 622 | 
| 621 protected: | 623 protected: | 
| 622     /** | 624     /** | 
| 623      * Gets the constant light color uniform. Subclasses can use this in their e
      mitLightColor | 625      * Gets the constant light color uniform. Subclasses can use this in their e
      mitLightColor | 
| 624      * function. | 626      * function. | 
| 625      */ | 627      */ | 
| 626     UniformHandle lightColorUni() const { return fColorUni; } | 628     UniformHandle lightColorUni() const { return fColorUni; } | 
| 627 | 629 | 
| 628 private: | 630 private: | 
| 629     UniformHandle fColorUni; | 631     UniformHandle fColorUni; | 
| 630 | 632 | 
| 631     typedef SkRefCnt INHERITED; | 633     typedef SkRefCnt INHERITED; | 
| 632 }; | 634 }; | 
| 633 | 635 | 
| 634 /////////////////////////////////////////////////////////////////////////////// | 636 /////////////////////////////////////////////////////////////////////////////// | 
| 635 | 637 | 
| 636 class GrGLDistantLight : public GrGLLight { | 638 class GrGLDistantLight : public GrGLLight { | 
| 637 public: | 639 public: | 
| 638     virtual ~GrGLDistantLight() {} | 640     virtual ~GrGLDistantLight() {} | 
| 639     void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* ligh
      t) const override; | 641     void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* ligh
      t) const override; | 
| 640     void emitSurfaceToLight(GrGLSLFPBuilder*, GrGLSLFragmentBuilder*, const char
      * z) override; | 642     void emitSurfaceToLight(GrGLSLUniformHandler*, GrGLSLFragmentBuilder*, const
       char* z) override; | 
| 641 | 643 | 
| 642 private: | 644 private: | 
| 643     typedef GrGLLight INHERITED; | 645     typedef GrGLLight INHERITED; | 
| 644     UniformHandle fDirectionUni; | 646     UniformHandle fDirectionUni; | 
| 645 }; | 647 }; | 
| 646 | 648 | 
| 647 /////////////////////////////////////////////////////////////////////////////// | 649 /////////////////////////////////////////////////////////////////////////////// | 
| 648 | 650 | 
| 649 class GrGLPointLight : public GrGLLight { | 651 class GrGLPointLight : public GrGLLight { | 
| 650 public: | 652 public: | 
| 651     virtual ~GrGLPointLight() {} | 653     virtual ~GrGLPointLight() {} | 
| 652     void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* ligh
      t) const override; | 654     void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* ligh
      t) const override; | 
| 653     void emitSurfaceToLight(GrGLSLFPBuilder*, GrGLSLFragmentBuilder*, const char
      * z) override; | 655     void emitSurfaceToLight(GrGLSLUniformHandler*, GrGLSLFragmentBuilder*, const
       char* z) override; | 
| 654 | 656 | 
| 655 private: | 657 private: | 
| 656     typedef GrGLLight INHERITED; | 658     typedef GrGLLight INHERITED; | 
| 657     UniformHandle fLocationUni; | 659     UniformHandle fLocationUni; | 
| 658 }; | 660 }; | 
| 659 | 661 | 
| 660 /////////////////////////////////////////////////////////////////////////////// | 662 /////////////////////////////////////////////////////////////////////////////// | 
| 661 | 663 | 
| 662 class GrGLSpotLight : public GrGLLight { | 664 class GrGLSpotLight : public GrGLLight { | 
| 663 public: | 665 public: | 
| 664     virtual ~GrGLSpotLight() {} | 666     virtual ~GrGLSpotLight() {} | 
| 665     void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* ligh
      t) const override; | 667     void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* ligh
      t) const override; | 
| 666     void emitSurfaceToLight(GrGLSLFPBuilder*, GrGLSLFragmentBuilder*, const char
      * z) override; | 668     void emitSurfaceToLight(GrGLSLUniformHandler*, GrGLSLFragmentBuilder*, const
       char* z) override; | 
| 667     void emitLightColor(GrGLSLFPBuilder*, | 669     void emitLightColor(GrGLSLUniformHandler*, | 
| 668                         GrGLSLFragmentBuilder*, | 670                         GrGLSLFragmentBuilder*, | 
| 669                         const char *surfaceToLight) override; | 671                         const char *surfaceToLight) override; | 
| 670 | 672 | 
| 671 private: | 673 private: | 
| 672     typedef GrGLLight INHERITED; | 674     typedef GrGLLight INHERITED; | 
| 673 | 675 | 
| 674     SkString        fLightColorFunc; | 676     SkString        fLightColorFunc; | 
| 675     UniformHandle   fLocationUni; | 677     UniformHandle   fLocationUni; | 
| 676     UniformHandle   fExponentUni; | 678     UniformHandle   fExponentUni; | 
| 677     UniformHandle   fCosOuterConeAngleUni; | 679     UniformHandle   fCosOuterConeAngleUni; | 
| (...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1521     void emitCode(EmitArgs&) override; | 1523     void emitCode(EmitArgs&) override; | 
| 1522 | 1524 | 
| 1523     static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
      KeyBuilder* b); | 1525     static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
      KeyBuilder* b); | 
| 1524 | 1526 | 
| 1525 protected: | 1527 protected: | 
| 1526     /** | 1528     /** | 
| 1527      * Subclasses of GrGLLightingEffect must call INHERITED::onSetData(); | 1529      * Subclasses of GrGLLightingEffect must call INHERITED::onSetData(); | 
| 1528      */ | 1530      */ | 
| 1529     void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
      ; | 1531     void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
      ; | 
| 1530 | 1532 | 
| 1531     virtual void emitLightFunc(GrGLSLFPBuilder*, GrGLSLFragmentBuilder*, SkStrin
      g* funcName) = 0; | 1533     virtual void emitLightFunc(GrGLSLUniformHandler*, | 
|  | 1534                                GrGLSLFragmentBuilder*, | 
|  | 1535                                SkString* funcName) = 0; | 
| 1532 | 1536 | 
| 1533 private: | 1537 private: | 
| 1534     typedef GrGLSLFragmentProcessor INHERITED; | 1538     typedef GrGLSLFragmentProcessor INHERITED; | 
| 1535 | 1539 | 
| 1536     UniformHandle       fImageIncrementUni; | 1540     UniformHandle       fImageIncrementUni; | 
| 1537     UniformHandle       fSurfaceScaleUni; | 1541     UniformHandle       fSurfaceScaleUni; | 
| 1538     GrGLLight*          fLight; | 1542     GrGLLight*          fLight; | 
| 1539     BoundaryMode        fBoundaryMode; | 1543     BoundaryMode        fBoundaryMode; | 
| 1540 }; | 1544 }; | 
| 1541 | 1545 | 
| 1542 /////////////////////////////////////////////////////////////////////////////// | 1546 /////////////////////////////////////////////////////////////////////////////// | 
| 1543 | 1547 | 
| 1544 class GrGLDiffuseLightingEffect  : public GrGLLightingEffect { | 1548 class GrGLDiffuseLightingEffect  : public GrGLLightingEffect { | 
| 1545 public: | 1549 public: | 
| 1546     GrGLDiffuseLightingEffect(const GrProcessor&); | 1550     GrGLDiffuseLightingEffect(const GrProcessor&); | 
| 1547     void emitLightFunc(GrGLSLFPBuilder*, GrGLSLFragmentBuilder*, SkString* funcN
      ame) override; | 1551     void emitLightFunc(GrGLSLUniformHandler*, GrGLSLFragmentBuilder*, SkString* 
      funcName) override; | 
| 1548 | 1552 | 
| 1549 protected: | 1553 protected: | 
| 1550     void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
      ; | 1554     void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
      ; | 
| 1551 | 1555 | 
| 1552 private: | 1556 private: | 
| 1553     typedef GrGLLightingEffect INHERITED; | 1557     typedef GrGLLightingEffect INHERITED; | 
| 1554 | 1558 | 
| 1555     UniformHandle   fKDUni; | 1559     UniformHandle   fKDUni; | 
| 1556 }; | 1560 }; | 
| 1557 | 1561 | 
| 1558 /////////////////////////////////////////////////////////////////////////////// | 1562 /////////////////////////////////////////////////////////////////////////////// | 
| 1559 | 1563 | 
| 1560 class GrGLSpecularLightingEffect  : public GrGLLightingEffect { | 1564 class GrGLSpecularLightingEffect  : public GrGLLightingEffect { | 
| 1561 public: | 1565 public: | 
| 1562     GrGLSpecularLightingEffect(const GrProcessor&); | 1566     GrGLSpecularLightingEffect(const GrProcessor&); | 
| 1563     void emitLightFunc(GrGLSLFPBuilder*, GrGLSLFragmentBuilder*, SkString* funcN
      ame) override; | 1567     void emitLightFunc(GrGLSLUniformHandler*, GrGLSLFragmentBuilder*, SkString* 
      funcName) override; | 
| 1564 | 1568 | 
| 1565 protected: | 1569 protected: | 
| 1566     void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
      ; | 1570     void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
      ; | 
| 1567 | 1571 | 
| 1568 private: | 1572 private: | 
| 1569     typedef GrGLLightingEffect INHERITED; | 1573     typedef GrGLLightingEffect INHERITED; | 
| 1570 | 1574 | 
| 1571     UniformHandle   fKSUni; | 1575     UniformHandle   fKSUni; | 
| 1572     UniformHandle   fShininessUni; | 1576     UniformHandle   fShininessUni; | 
| 1573 }; | 1577 }; | 
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1650     const GrLightingEffect& m = fp.cast<GrLightingEffect>(); | 1654     const GrLightingEffect& m = fp.cast<GrLightingEffect>(); | 
| 1651     fLight = m.light()->createGLLight(); | 1655     fLight = m.light()->createGLLight(); | 
| 1652     fBoundaryMode = m.boundaryMode(); | 1656     fBoundaryMode = m.boundaryMode(); | 
| 1653 } | 1657 } | 
| 1654 | 1658 | 
| 1655 GrGLLightingEffect::~GrGLLightingEffect() { | 1659 GrGLLightingEffect::~GrGLLightingEffect() { | 
| 1656     delete fLight; | 1660     delete fLight; | 
| 1657 } | 1661 } | 
| 1658 | 1662 | 
| 1659 void GrGLLightingEffect::emitCode(EmitArgs& args) { | 1663 void GrGLLightingEffect::emitCode(EmitArgs& args) { | 
| 1660     fImageIncrementUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragme
      nt_Visibility, | 1664     GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; | 
| 1661                                               kVec2f_GrSLType, kDefault_GrSLPrec
      ision, | 1665     fImageIncrementUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragm
      ent_Visibility, | 
| 1662                                              "ImageIncrement"); | 1666                                                     kVec2f_GrSLType, kDefault_Gr
      SLPrecision, | 
| 1663     fSurfaceScaleUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment
      _Visibility, | 1667                                                     "ImageIncrement"); | 
| 1664                                            kFloat_GrSLType, kDefault_GrSLPrecisi
      on, | 1668     fSurfaceScaleUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragmen
      t_Visibility, | 
| 1665                                            "SurfaceScale"); | 1669                                                   kFloat_GrSLType, kDefault_GrSL
      Precision, | 
| 1666     fLight->emitLightColorUniform(args.fBuilder); | 1670                                                   "SurfaceScale"); | 
|  | 1671     fLight->emitLightColorUniform(uniformHandler); | 
| 1667     GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 1672     GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 
| 1668     SkString lightFunc; | 1673     SkString lightFunc; | 
| 1669     this->emitLightFunc(args.fBuilder, fragBuilder, &lightFunc); | 1674     this->emitLightFunc(uniformHandler, fragBuilder, &lightFunc); | 
| 1670     static const GrGLSLShaderVar gSobelArgs[] =  { | 1675     static const GrGLSLShaderVar gSobelArgs[] =  { | 
| 1671         GrGLSLShaderVar("a", kFloat_GrSLType), | 1676         GrGLSLShaderVar("a", kFloat_GrSLType), | 
| 1672         GrGLSLShaderVar("b", kFloat_GrSLType), | 1677         GrGLSLShaderVar("b", kFloat_GrSLType), | 
| 1673         GrGLSLShaderVar("c", kFloat_GrSLType), | 1678         GrGLSLShaderVar("c", kFloat_GrSLType), | 
| 1674         GrGLSLShaderVar("d", kFloat_GrSLType), | 1679         GrGLSLShaderVar("d", kFloat_GrSLType), | 
| 1675         GrGLSLShaderVar("e", kFloat_GrSLType), | 1680         GrGLSLShaderVar("e", kFloat_GrSLType), | 
| 1676         GrGLSLShaderVar("f", kFloat_GrSLType), | 1681         GrGLSLShaderVar("f", kFloat_GrSLType), | 
| 1677         GrGLSLShaderVar("scale", kFloat_GrSLType), | 1682         GrGLSLShaderVar("scale", kFloat_GrSLType), | 
| 1678     }; | 1683     }; | 
| 1679     SkString sobelFuncName; | 1684     SkString sobelFuncName; | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 1709     fragBuilder->emitFunction(kVec3f_GrSLType, | 1714     fragBuilder->emitFunction(kVec3f_GrSLType, | 
| 1710                               "normal", | 1715                               "normal", | 
| 1711                               SK_ARRAY_COUNT(gInteriorNormalArgs), | 1716                               SK_ARRAY_COUNT(gInteriorNormalArgs), | 
| 1712                               gInteriorNormalArgs, | 1717                               gInteriorNormalArgs, | 
| 1713                               normalBody.c_str(), | 1718                               normalBody.c_str(), | 
| 1714                               &normalName); | 1719                               &normalName); | 
| 1715 | 1720 | 
| 1716     fragBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str()); | 1721     fragBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str()); | 
| 1717     fragBuilder->codeAppend("\t\tfloat m[9];\n"); | 1722     fragBuilder->codeAppend("\t\tfloat m[9];\n"); | 
| 1718 | 1723 | 
| 1719     const char* imgInc = args.fBuilder->getUniformCStr(fImageIncrementUni); | 1724     const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni); | 
| 1720     const char* surfScale = args.fBuilder->getUniformCStr(fSurfaceScaleUni); | 1725     const char* surfScale = uniformHandler->getUniformCStr(fSurfaceScaleUni); | 
| 1721 | 1726 | 
| 1722     int index = 0; | 1727     int index = 0; | 
| 1723     for (int dy = 1; dy >= -1; dy--) { | 1728     for (int dy = 1; dy >= -1; dy--) { | 
| 1724         for (int dx = -1; dx <= 1; dx++) { | 1729         for (int dx = -1; dx <= 1; dx++) { | 
| 1725             SkString texCoords; | 1730             SkString texCoords; | 
| 1726             texCoords.appendf("coord + vec2(%d, %d) * %s", dx, dy, imgInc); | 1731             texCoords.appendf("coord + vec2(%d, %d) * %s", dx, dy, imgInc); | 
| 1727             fragBuilder->codeAppendf("\t\tm[%d] = ", index++); | 1732             fragBuilder->codeAppendf("\t\tm[%d] = ", index++); | 
| 1728             fragBuilder->appendTextureLookup(args.fSamplers[0], texCoords.c_str(
      )); | 1733             fragBuilder->appendTextureLookup(args.fSamplers[0], texCoords.c_str(
      )); | 
| 1729             fragBuilder->codeAppend(".a;\n"); | 1734             fragBuilder->codeAppend(".a;\n"); | 
| 1730         } | 1735         } | 
| 1731     } | 1736     } | 
| 1732     fragBuilder->codeAppend("\t\tvec3 surfaceToLight = "); | 1737     fragBuilder->codeAppend("\t\tvec3 surfaceToLight = "); | 
| 1733     SkString arg; | 1738     SkString arg; | 
| 1734     arg.appendf("%s * m[4]", surfScale); | 1739     arg.appendf("%s * m[4]", surfScale); | 
| 1735     fLight->emitSurfaceToLight(args.fBuilder, fragBuilder, arg.c_str()); | 1740     fLight->emitSurfaceToLight(uniformHandler, fragBuilder, arg.c_str()); | 
| 1736     fragBuilder->codeAppend(";\n"); | 1741     fragBuilder->codeAppend(";\n"); | 
| 1737     fragBuilder->codeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ", | 1742     fragBuilder->codeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ", | 
| 1738                              args.fOutputColor, lightFunc.c_str(), normalName.c_
      str(), surfScale); | 1743                              args.fOutputColor, lightFunc.c_str(), normalName.c_
      str(), surfScale); | 
| 1739     fLight->emitLightColor(args.fBuilder, fragBuilder, "surfaceToLight"); | 1744     fLight->emitLightColor(uniformHandler, fragBuilder, "surfaceToLight"); | 
| 1740     fragBuilder->codeAppend(");\n"); | 1745     fragBuilder->codeAppend(");\n"); | 
| 1741     SkString modulate; | 1746     SkString modulate; | 
| 1742     GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor); | 1747     GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor); | 
| 1743     fragBuilder->codeAppend(modulate.c_str()); | 1748     fragBuilder->codeAppend(modulate.c_str()); | 
| 1744 } | 1749 } | 
| 1745 | 1750 | 
| 1746 void GrGLLightingEffect::GenKey(const GrProcessor& proc, | 1751 void GrGLLightingEffect::GenKey(const GrProcessor& proc, | 
| 1747                                 const GrGLSLCaps& caps, GrProcessorKeyBuilder* b
      ) { | 1752                                 const GrGLSLCaps& caps, GrProcessorKeyBuilder* b
      ) { | 
| 1748     const GrLightingEffect& lighting = proc.cast<GrLightingEffect>(); | 1753     const GrLightingEffect& lighting = proc.cast<GrLightingEffect>(); | 
| 1749     b->add32(lighting.boundaryMode() << 2 | lighting.light()->type()); | 1754     b->add32(lighting.boundaryMode() << 2 | lighting.light()->type()); | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 1762 } | 1767 } | 
| 1763 | 1768 | 
| 1764 /////////////////////////////////////////////////////////////////////////////// | 1769 /////////////////////////////////////////////////////////////////////////////// | 
| 1765 | 1770 | 
| 1766 /////////////////////////////////////////////////////////////////////////////// | 1771 /////////////////////////////////////////////////////////////////////////////// | 
| 1767 | 1772 | 
| 1768 GrGLDiffuseLightingEffect::GrGLDiffuseLightingEffect(const GrProcessor& proc) | 1773 GrGLDiffuseLightingEffect::GrGLDiffuseLightingEffect(const GrProcessor& proc) | 
| 1769     : INHERITED(proc) { | 1774     : INHERITED(proc) { | 
| 1770 } | 1775 } | 
| 1771 | 1776 | 
| 1772 void GrGLDiffuseLightingEffect::emitLightFunc(GrGLSLFPBuilder* builder, | 1777 void GrGLDiffuseLightingEffect::emitLightFunc(GrGLSLUniformHandler* uniformHandl
      er, | 
| 1773                                               GrGLSLFragmentBuilder* fragBuilder
      , | 1778                                               GrGLSLFragmentBuilder* fragBuilder
      , | 
| 1774                                               SkString* funcName) { | 1779                                               SkString* funcName) { | 
| 1775     const char* kd; | 1780     const char* kd; | 
| 1776     fKDUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility, | 1781     fKDUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibili
      ty, | 
| 1777                                  kFloat_GrSLType, kDefault_GrSLPrecision, | 1782                                  kFloat_GrSLType, kDefault_GrSLPrecision, | 
| 1778                                  "KD", &kd); | 1783                                  "KD", &kd); | 
| 1779 | 1784 | 
| 1780     static const GrGLSLShaderVar gLightArgs[] = { | 1785     static const GrGLSLShaderVar gLightArgs[] = { | 
| 1781         GrGLSLShaderVar("normal", kVec3f_GrSLType), | 1786         GrGLSLShaderVar("normal", kVec3f_GrSLType), | 
| 1782         GrGLSLShaderVar("surfaceToLight", kVec3f_GrSLType), | 1787         GrGLSLShaderVar("surfaceToLight", kVec3f_GrSLType), | 
| 1783         GrGLSLShaderVar("lightColor", kVec3f_GrSLType) | 1788         GrGLSLShaderVar("lightColor", kVec3f_GrSLType) | 
| 1784     }; | 1789     }; | 
| 1785     SkString lightBody; | 1790     SkString lightBody; | 
| 1786     lightBody.appendf("\tfloat colorScale = %s * dot(normal, surfaceToLight);\n"
      , kd); | 1791     lightBody.appendf("\tfloat colorScale = %s * dot(normal, surfaceToLight);\n"
      , kd); | 
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1846     return GrSpecularLightingEffect::Create(d->fTextures[GrProcessorUnitTest::kA
      lphaTextureIdx], | 1851     return GrSpecularLightingEffect::Create(d->fTextures[GrProcessorUnitTest::kA
      lphaTextureIdx], | 
| 1847                                             light, surfaceScale, matrix, ks, shi
      niness, mode); | 1852                                             light, surfaceScale, matrix, ks, shi
      niness, mode); | 
| 1848 } | 1853 } | 
| 1849 | 1854 | 
| 1850 /////////////////////////////////////////////////////////////////////////////// | 1855 /////////////////////////////////////////////////////////////////////////////// | 
| 1851 | 1856 | 
| 1852 GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrProcessor& proc) | 1857 GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrProcessor& proc) | 
| 1853     : INHERITED(proc) { | 1858     : INHERITED(proc) { | 
| 1854 } | 1859 } | 
| 1855 | 1860 | 
| 1856 void GrGLSpecularLightingEffect::emitLightFunc(GrGLSLFPBuilder* builder, | 1861 void GrGLSpecularLightingEffect::emitLightFunc(GrGLSLUniformHandler* uniformHand
      ler, | 
| 1857                                                GrGLSLFragmentBuilder* fragBuilde
      r, | 1862                                                GrGLSLFragmentBuilder* fragBuilde
      r, | 
| 1858                                                SkString* funcName) { | 1863                                                SkString* funcName) { | 
| 1859     const char* ks; | 1864     const char* ks; | 
| 1860     const char* shininess; | 1865     const char* shininess; | 
| 1861 | 1866 | 
| 1862     fKSUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility, | 1867     fKSUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibili
      ty, | 
| 1863                                  kFloat_GrSLType, kDefault_GrSLPrecision, "KS", 
      &ks); | 1868                                         kFloat_GrSLType, kDefault_GrSLPrecision,
       "KS", &ks); | 
| 1864     fShininessUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibili
      ty, | 1869     fShininessUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_V
      isibility, | 
| 1865                                         kFloat_GrSLType, | 1870                                                kFloat_GrSLType, | 
| 1866                                         kDefault_GrSLPrecision, | 1871                                                kDefault_GrSLPrecision, | 
| 1867                                         "Shininess", | 1872                                                "Shininess", | 
| 1868                                         &shininess); | 1873                                                &shininess); | 
| 1869 | 1874 | 
| 1870     static const GrGLSLShaderVar gLightArgs[] = { | 1875     static const GrGLSLShaderVar gLightArgs[] = { | 
| 1871         GrGLSLShaderVar("normal", kVec3f_GrSLType), | 1876         GrGLSLShaderVar("normal", kVec3f_GrSLType), | 
| 1872         GrGLSLShaderVar("surfaceToLight", kVec3f_GrSLType), | 1877         GrGLSLShaderVar("surfaceToLight", kVec3f_GrSLType), | 
| 1873         GrGLSLShaderVar("lightColor", kVec3f_GrSLType) | 1878         GrGLSLShaderVar("lightColor", kVec3f_GrSLType) | 
| 1874     }; | 1879     }; | 
| 1875     SkString lightBody; | 1880     SkString lightBody; | 
| 1876     lightBody.appendf("\tvec3 halfDir = vec3(normalize(surfaceToLight + vec3(0, 
      0, 1)));\n"); | 1881     lightBody.appendf("\tvec3 halfDir = vec3(normalize(surfaceToLight + vec3(0, 
      0, 1)));\n"); | 
| 1877     lightBody.appendf("\tfloat colorScale = %s * pow(dot(normal, halfDir), %s);\
      n", ks, shininess); | 1882     lightBody.appendf("\tfloat colorScale = %s * pow(dot(normal, halfDir), %s);\
      n", ks, shininess); | 
| 1878     lightBody.appendf("\tvec3 color = lightColor * clamp(colorScale, 0.0, 1.0);\
      n"); | 1883     lightBody.appendf("\tvec3 color = lightColor * clamp(colorScale, 0.0, 1.0);\
      n"); | 
| 1879     lightBody.appendf("\treturn vec4(color, max(max(color.r, color.g), color.b))
      ;\n"); | 1884     lightBody.appendf("\treturn vec4(color, max(max(color.r, color.g), color.b))
      ;\n"); | 
| 1880     fragBuilder->emitFunction(kVec4f_GrSLType, | 1885     fragBuilder->emitFunction(kVec4f_GrSLType, | 
| 1881                               "light", | 1886                               "light", | 
| 1882                               SK_ARRAY_COUNT(gLightArgs), | 1887                               SK_ARRAY_COUNT(gLightArgs), | 
| 1883                               gLightArgs, | 1888                               gLightArgs, | 
| 1884                               lightBody.c_str(), | 1889                               lightBody.c_str(), | 
| 1885                               funcName); | 1890                               funcName); | 
| 1886 } | 1891 } | 
| 1887 | 1892 | 
| 1888 void GrGLSpecularLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman
      , | 1893 void GrGLSpecularLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman
      , | 
| 1889                                            const GrProcessor& effect) { | 1894                                            const GrProcessor& effect) { | 
| 1890     INHERITED::onSetData(pdman, effect); | 1895     INHERITED::onSetData(pdman, effect); | 
| 1891     const GrSpecularLightingEffect& spec = effect.cast<GrSpecularLightingEffect>
      (); | 1896     const GrSpecularLightingEffect& spec = effect.cast<GrSpecularLightingEffect>
      (); | 
| 1892     pdman.set1f(fKSUni, spec.ks()); | 1897     pdman.set1f(fKSUni, spec.ks()); | 
| 1893     pdman.set1f(fShininessUni, spec.shininess()); | 1898     pdman.set1f(fShininessUni, spec.shininess()); | 
| 1894 } | 1899 } | 
| 1895 | 1900 | 
| 1896 /////////////////////////////////////////////////////////////////////////////// | 1901 /////////////////////////////////////////////////////////////////////////////// | 
| 1897 void GrGLLight::emitLightColorUniform(GrGLSLFPBuilder* builder) { | 1902 void GrGLLight::emitLightColorUniform(GrGLSLUniformHandler* uniformHandler) { | 
| 1898     fColorUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility, | 1903     fColorUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visib
      ility, | 
| 1899                                     kVec3f_GrSLType, kDefault_GrSLPrecision, | 1904                                            kVec3f_GrSLType, kDefault_GrSLPrecisi
      on, | 
| 1900                                     "LightColor"); | 1905                                            "LightColor"); | 
| 1901 } | 1906 } | 
| 1902 | 1907 | 
| 1903 void GrGLLight::emitLightColor(GrGLSLFPBuilder* builder, | 1908 void GrGLLight::emitLightColor(GrGLSLUniformHandler* uniformHandler, | 
| 1904                                GrGLSLFragmentBuilder* fragBuilder, | 1909                                GrGLSLFragmentBuilder* fragBuilder, | 
| 1905                                const char *surfaceToLight) { | 1910                                const char *surfaceToLight) { | 
| 1906     fragBuilder->codeAppend(builder->getUniformCStr(this->lightColorUni())); | 1911     fragBuilder->codeAppend(uniformHandler->getUniformCStr(this->lightColorUni()
      )); | 
| 1907 } | 1912 } | 
| 1908 | 1913 | 
| 1909 void GrGLLight::setData(const GrGLSLProgramDataManager& pdman, | 1914 void GrGLLight::setData(const GrGLSLProgramDataManager& pdman, | 
| 1910                         const SkImageFilterLight* light) const { | 1915                         const SkImageFilterLight* light) const { | 
| 1911     setUniformPoint3(pdman, fColorUni, | 1916     setUniformPoint3(pdman, fColorUni, | 
| 1912                      light->color().makeScale(SkScalarInvert(SkIntToScalar(255))
      )); | 1917                      light->color().makeScale(SkScalarInvert(SkIntToScalar(255))
      )); | 
| 1913 } | 1918 } | 
| 1914 | 1919 | 
| 1915 /////////////////////////////////////////////////////////////////////////////// | 1920 /////////////////////////////////////////////////////////////////////////////// | 
| 1916 | 1921 | 
| 1917 void GrGLDistantLight::setData(const GrGLSLProgramDataManager& pdman, | 1922 void GrGLDistantLight::setData(const GrGLSLProgramDataManager& pdman, | 
| 1918                                const SkImageFilterLight* light) const { | 1923                                const SkImageFilterLight* light) const { | 
| 1919     INHERITED::setData(pdman, light); | 1924     INHERITED::setData(pdman, light); | 
| 1920     SkASSERT(light->type() == SkImageFilterLight::kDistant_LightType); | 1925     SkASSERT(light->type() == SkImageFilterLight::kDistant_LightType); | 
| 1921     const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(ligh
      t); | 1926     const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(ligh
      t); | 
| 1922     setUniformNormal3(pdman, fDirectionUni, distantLight->direction()); | 1927     setUniformNormal3(pdman, fDirectionUni, distantLight->direction()); | 
| 1923 } | 1928 } | 
| 1924 | 1929 | 
| 1925 void GrGLDistantLight::emitSurfaceToLight(GrGLSLFPBuilder* builder, | 1930 void GrGLDistantLight::emitSurfaceToLight(GrGLSLUniformHandler* uniformHandler, | 
| 1926                                           GrGLSLFragmentBuilder* fragBuilder, | 1931                                           GrGLSLFragmentBuilder* fragBuilder, | 
| 1927                                           const char* z) { | 1932                                           const char* z) { | 
| 1928     const char* dir; | 1933     const char* dir; | 
| 1929     fDirectionUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibili
      ty, | 1934     fDirectionUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_V
      isibility, | 
| 1930                                         kVec3f_GrSLType, kDefault_GrSLPrecision, | 1935                                                kVec3f_GrSLType, kDefault_GrSLPre
      cision, | 
| 1931                                         "LightDirection", &dir); | 1936                                                "LightDirection", &dir); | 
| 1932     fragBuilder->codeAppend(dir); | 1937     fragBuilder->codeAppend(dir); | 
| 1933 } | 1938 } | 
| 1934 | 1939 | 
| 1935 /////////////////////////////////////////////////////////////////////////////// | 1940 /////////////////////////////////////////////////////////////////////////////// | 
| 1936 | 1941 | 
| 1937 void GrGLPointLight::setData(const GrGLSLProgramDataManager& pdman, | 1942 void GrGLPointLight::setData(const GrGLSLProgramDataManager& pdman, | 
| 1938                              const SkImageFilterLight* light) const { | 1943                              const SkImageFilterLight* light) const { | 
| 1939     INHERITED::setData(pdman, light); | 1944     INHERITED::setData(pdman, light); | 
| 1940     SkASSERT(light->type() == SkImageFilterLight::kPoint_LightType); | 1945     SkASSERT(light->type() == SkImageFilterLight::kPoint_LightType); | 
| 1941     const SkPointLight* pointLight = static_cast<const SkPointLight*>(light); | 1946     const SkPointLight* pointLight = static_cast<const SkPointLight*>(light); | 
| 1942     setUniformPoint3(pdman, fLocationUni, pointLight->location()); | 1947     setUniformPoint3(pdman, fLocationUni, pointLight->location()); | 
| 1943 } | 1948 } | 
| 1944 | 1949 | 
| 1945 void GrGLPointLight::emitSurfaceToLight(GrGLSLFPBuilder* builder, | 1950 void GrGLPointLight::emitSurfaceToLight(GrGLSLUniformHandler* uniformHandler, | 
| 1946                                         GrGLSLFragmentBuilder* fragBuilder, | 1951                                         GrGLSLFragmentBuilder* fragBuilder, | 
| 1947                                         const char* z) { | 1952                                         const char* z) { | 
| 1948     const char* loc; | 1953     const char* loc; | 
| 1949     fLocationUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibilit
      y, | 1954     fLocationUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Vi
      sibility, | 
| 1950                                        kVec3f_GrSLType, kDefault_GrSLPrecision, | 1955                                               kVec3f_GrSLType, kDefault_GrSLPrec
      ision, | 
| 1951                                        "LightLocation", &loc); | 1956                                               "LightLocation", &loc); | 
| 1952     fragBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))", | 1957     fragBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))", | 
| 1953                              loc, fragBuilder->fragmentPosition(), z); | 1958                              loc, fragBuilder->fragmentPosition(), z); | 
| 1954 } | 1959 } | 
| 1955 | 1960 | 
| 1956 /////////////////////////////////////////////////////////////////////////////// | 1961 /////////////////////////////////////////////////////////////////////////////// | 
| 1957 | 1962 | 
| 1958 void GrGLSpotLight::setData(const GrGLSLProgramDataManager& pdman, | 1963 void GrGLSpotLight::setData(const GrGLSLProgramDataManager& pdman, | 
| 1959                             const SkImageFilterLight* light) const { | 1964                             const SkImageFilterLight* light) const { | 
| 1960     INHERITED::setData(pdman, light); | 1965     INHERITED::setData(pdman, light); | 
| 1961     SkASSERT(light->type() == SkImageFilterLight::kSpot_LightType); | 1966     SkASSERT(light->type() == SkImageFilterLight::kSpot_LightType); | 
| 1962     const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light); | 1967     const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light); | 
| 1963     setUniformPoint3(pdman, fLocationUni, spotLight->location()); | 1968     setUniformPoint3(pdman, fLocationUni, spotLight->location()); | 
| 1964     pdman.set1f(fExponentUni, spotLight->specularExponent()); | 1969     pdman.set1f(fExponentUni, spotLight->specularExponent()); | 
| 1965     pdman.set1f(fCosInnerConeAngleUni, spotLight->cosInnerConeAngle()); | 1970     pdman.set1f(fCosInnerConeAngleUni, spotLight->cosInnerConeAngle()); | 
| 1966     pdman.set1f(fCosOuterConeAngleUni, spotLight->cosOuterConeAngle()); | 1971     pdman.set1f(fCosOuterConeAngleUni, spotLight->cosOuterConeAngle()); | 
| 1967     pdman.set1f(fConeScaleUni, spotLight->coneScale()); | 1972     pdman.set1f(fConeScaleUni, spotLight->coneScale()); | 
| 1968     setUniformNormal3(pdman, fSUni, spotLight->s()); | 1973     setUniformNormal3(pdman, fSUni, spotLight->s()); | 
| 1969 } | 1974 } | 
| 1970 | 1975 | 
| 1971 void GrGLSpotLight::emitSurfaceToLight(GrGLSLFPBuilder* builder, | 1976 void GrGLSpotLight::emitSurfaceToLight(GrGLSLUniformHandler* uniformHandler, | 
| 1972                                        GrGLSLFragmentBuilder* fragBuilder, | 1977                                        GrGLSLFragmentBuilder* fragBuilder, | 
| 1973                                        const char* z) { | 1978                                        const char* z) { | 
| 1974     const char* location; | 1979     const char* location; | 
| 1975     fLocationUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibilit
      y, | 1980     fLocationUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Vi
      sibility, | 
| 1976                                        kVec3f_GrSLType, kDefault_GrSLPrecision, | 1981                                               kVec3f_GrSLType, kDefault_GrSLPrec
      ision, | 
| 1977                                        "LightLocation", &location); | 1982                                               "LightLocation", &location); | 
| 1978 | 1983 | 
| 1979     fragBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))", | 1984     fragBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))", | 
| 1980                              location, fragBuilder->fragmentPosition(), z); | 1985                              location, fragBuilder->fragmentPosition(), z); | 
| 1981 } | 1986 } | 
| 1982 | 1987 | 
| 1983 void GrGLSpotLight::emitLightColor(GrGLSLFPBuilder* builder, | 1988 void GrGLSpotLight::emitLightColor(GrGLSLUniformHandler* uniformHandler, | 
| 1984                                    GrGLSLFragmentBuilder* fragBuilder, | 1989                                    GrGLSLFragmentBuilder* fragBuilder, | 
| 1985                                    const char *surfaceToLight) { | 1990                                    const char *surfaceToLight) { | 
| 1986 | 1991 | 
| 1987     const char* color = builder->getUniformCStr(this->lightColorUni()); // creat
      ed by parent class. | 1992     const char* color = uniformHandler->getUniformCStr(this->lightColorUni()); /
      / created by parent class. | 
| 1988 | 1993 | 
| 1989     const char* exponent; | 1994     const char* exponent; | 
| 1990     const char* cosInner; | 1995     const char* cosInner; | 
| 1991     const char* cosOuter; | 1996     const char* cosOuter; | 
| 1992     const char* coneScale; | 1997     const char* coneScale; | 
| 1993     const char* s; | 1998     const char* s; | 
| 1994     fExponentUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibilit
      y, | 1999     fExponentUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Vi
      sibility, | 
| 1995                                        kFloat_GrSLType, kDefault_GrSLPrecision, | 2000                                               kFloat_GrSLType, kDefault_GrSLPrec
      ision, | 
| 1996                                        "Exponent", &exponent); | 2001                                               "Exponent", &exponent); | 
| 1997     fCosInnerConeAngleUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_
      Visibility, | 2002     fCosInnerConeAngleUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFr
      agment_Visibility, | 
| 1998                                                 kFloat_GrSLType, kDefault_GrSLPr
      ecision, | 2003                                                        kFloat_GrSLType, kDefault
      _GrSLPrecision, | 
| 1999                                                 "CosInnerConeAngle", &cosInner); | 2004                                                        "CosInnerConeAngle", &cos
      Inner); | 
| 2000     fCosOuterConeAngleUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_
      Visibility, | 2005     fCosOuterConeAngleUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFr
      agment_Visibility, | 
| 2001                                                 kFloat_GrSLType, kDefault_GrSLPr
      ecision, | 2006                                                        kFloat_GrSLType, kDefault
      _GrSLPrecision, | 
| 2002                                                 "CosOuterConeAngle", &cosOuter); | 2007                                                        "CosOuterConeAngle", &cos
      Outer); | 
| 2003     fConeScaleUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibili
      ty, | 2008     fConeScaleUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_V
      isibility, | 
| 2004                                         kFloat_GrSLType, kDefault_GrSLPrecision, | 2009                                                kFloat_GrSLType, kDefault_GrSLPre
      cision, | 
| 2005                                         "ConeScale", &coneScale); | 2010                                                "ConeScale", &coneScale); | 
| 2006     fSUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility, | 2011     fSUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibilit
      y, | 
| 2007                                 kVec3f_GrSLType, kDefault_GrSLPrecision, "S", &s
      ); | 2012                                        kVec3f_GrSLType, kDefault_GrSLPrecision, 
      "S", &s); | 
| 2008 | 2013 | 
| 2009     static const GrGLSLShaderVar gLightColorArgs[] = { | 2014     static const GrGLSLShaderVar gLightColorArgs[] = { | 
| 2010         GrGLSLShaderVar("surfaceToLight", kVec3f_GrSLType) | 2015         GrGLSLShaderVar("surfaceToLight", kVec3f_GrSLType) | 
| 2011     }; | 2016     }; | 
| 2012     SkString lightColorBody; | 2017     SkString lightColorBody; | 
| 2013     lightColorBody.appendf("\tfloat cosAngle = -dot(surfaceToLight, %s);\n", s); | 2018     lightColorBody.appendf("\tfloat cosAngle = -dot(surfaceToLight, %s);\n", s); | 
| 2014     lightColorBody.appendf("\tif (cosAngle < %s) {\n", cosOuter); | 2019     lightColorBody.appendf("\tif (cosAngle < %s) {\n", cosOuter); | 
| 2015     lightColorBody.appendf("\t\treturn vec3(0);\n"); | 2020     lightColorBody.appendf("\t\treturn vec3(0);\n"); | 
| 2016     lightColorBody.appendf("\t}\n"); | 2021     lightColorBody.appendf("\t}\n"); | 
| 2017     lightColorBody.appendf("\tfloat scale = pow(cosAngle, %s);\n", exponent); | 2022     lightColorBody.appendf("\tfloat scale = pow(cosAngle, %s);\n", exponent); | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 2029 | 2034 | 
| 2030     fragBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 2035     fragBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 
| 2031 } | 2036 } | 
| 2032 | 2037 | 
| 2033 #endif | 2038 #endif | 
| 2034 | 2039 | 
| 2035 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 2040 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 
| 2036     SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 2041     SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 
| 2037     SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 2042     SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 
| 2038 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 2043 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 
| OLD | NEW | 
|---|