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

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

Issue 1251173002: Added GrGLFragmentProcessor::EmitArgs struct for use with emitCode() (Closed) Base URL: https://skia.googlesource.com/skia@composeshader_gpu
Patch Set: Created 5 years, 5 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/SkLumaColorFilter.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 1496 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 return result; 1507 return result;
1508 } 1508 }
1509 1509
1510 } 1510 }
1511 1511
1512 class GrGLLightingEffect : public GrGLFragmentProcessor { 1512 class GrGLLightingEffect : public GrGLFragmentProcessor {
1513 public: 1513 public:
1514 GrGLLightingEffect(const GrProcessor&); 1514 GrGLLightingEffect(const GrProcessor&);
1515 virtual ~GrGLLightingEffect(); 1515 virtual ~GrGLLightingEffect();
1516 1516
1517 void emitCode(GrGLFPBuilder*, 1517 void emitCode(EmitArgs&) override;
1518 const GrFragmentProcessor&,
1519 const char* outputColor,
1520 const char* inputColor,
1521 const TransformedCoordsArray&,
1522 const TextureSamplerArray&) override;
1523 1518
1524 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder* b); 1519 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder* b);
1525 1520
1526 /** 1521 /**
1527 * Subclasses of GrGLLightingEffect must call INHERITED::setData(); 1522 * Subclasses of GrGLLightingEffect must call INHERITED::setData();
1528 */ 1523 */
1529 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 1524 void setData(const GrGLProgramDataManager&, const GrProcessor&) override;
1530 1525
1531 protected: 1526 protected:
1532 virtual void emitLightFunc(GrGLFPBuilder*, SkString* funcName) = 0; 1527 virtual void emitLightFunc(GrGLFPBuilder*, SkString* funcName) = 0;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 GrGLLightingEffect::GrGLLightingEffect(const GrProcessor& fp) { 1644 GrGLLightingEffect::GrGLLightingEffect(const GrProcessor& fp) {
1650 const GrLightingEffect& m = fp.cast<GrLightingEffect>(); 1645 const GrLightingEffect& m = fp.cast<GrLightingEffect>();
1651 fLight = m.light()->createGLLight(); 1646 fLight = m.light()->createGLLight();
1652 fBoundaryMode = m.boundaryMode(); 1647 fBoundaryMode = m.boundaryMode();
1653 } 1648 }
1654 1649
1655 GrGLLightingEffect::~GrGLLightingEffect() { 1650 GrGLLightingEffect::~GrGLLightingEffect() {
1656 delete fLight; 1651 delete fLight;
1657 } 1652 }
1658 1653
1659 void GrGLLightingEffect::emitCode(GrGLFPBuilder* builder, 1654 void GrGLLightingEffect::emitCode(EmitArgs& args) {
1660 const GrFragmentProcessor&, 1655 fImageIncrementUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment _Visibility,
1661 const char* outputColor,
1662 const char* inputColor,
1663 const TransformedCoordsArray& coords,
1664 const TextureSamplerArray& samplers) {
1665 fImageIncrementUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib ility,
1666 kVec2f_GrSLType, kDefault_GrSLPrec ision, 1656 kVec2f_GrSLType, kDefault_GrSLPrec ision,
1667 "ImageIncrement"); 1657 "ImageIncrement");
1668 fSurfaceScaleUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibil ity, 1658 fSurfaceScaleUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_V isibility,
1669 kFloat_GrSLType, kDefault_GrSLPrecisi on, 1659 kFloat_GrSLType, kDefault_GrSLPrecisi on,
1670 "SurfaceScale"); 1660 "SurfaceScale");
1671 fLight->emitLightColorUniform(builder); 1661 fLight->emitLightColorUniform(args.fBuilder);
1672 SkString lightFunc; 1662 SkString lightFunc;
1673 this->emitLightFunc(builder, &lightFunc); 1663 this->emitLightFunc(args.fBuilder, &lightFunc);
1674 static const GrGLShaderVar gSobelArgs[] = { 1664 static const GrGLShaderVar gSobelArgs[] = {
1675 GrGLShaderVar("a", kFloat_GrSLType), 1665 GrGLShaderVar("a", kFloat_GrSLType),
1676 GrGLShaderVar("b", kFloat_GrSLType), 1666 GrGLShaderVar("b", kFloat_GrSLType),
1677 GrGLShaderVar("c", kFloat_GrSLType), 1667 GrGLShaderVar("c", kFloat_GrSLType),
1678 GrGLShaderVar("d", kFloat_GrSLType), 1668 GrGLShaderVar("d", kFloat_GrSLType),
1679 GrGLShaderVar("e", kFloat_GrSLType), 1669 GrGLShaderVar("e", kFloat_GrSLType),
1680 GrGLShaderVar("f", kFloat_GrSLType), 1670 GrGLShaderVar("f", kFloat_GrSLType),
1681 GrGLShaderVar("scale", kFloat_GrSLType), 1671 GrGLShaderVar("scale", kFloat_GrSLType),
1682 }; 1672 };
1683 SkString sobelFuncName; 1673 SkString sobelFuncName;
1684 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 1674 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
1685 SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 0); 1675 SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
1686 1676
1687 fsBuilder->emitFunction(kFloat_GrSLType, 1677 fsBuilder->emitFunction(kFloat_GrSLType,
1688 "sobel", 1678 "sobel",
1689 SK_ARRAY_COUNT(gSobelArgs), 1679 SK_ARRAY_COUNT(gSobelArgs),
1690 gSobelArgs, 1680 gSobelArgs,
1691 "\treturn (-a + b - 2.0 * c + 2.0 * d -e + f) * scal e;\n", 1681 "\treturn (-a + b - 2.0 * c + 2.0 * d -e + f) * scal e;\n",
1692 &sobelFuncName); 1682 &sobelFuncName);
1693 static const GrGLShaderVar gPointToNormalArgs[] = { 1683 static const GrGLShaderVar gPointToNormalArgs[] = {
1694 GrGLShaderVar("x", kFloat_GrSLType), 1684 GrGLShaderVar("x", kFloat_GrSLType),
1695 GrGLShaderVar("y", kFloat_GrSLType), 1685 GrGLShaderVar("y", kFloat_GrSLType),
(...skipping 18 matching lines...) Expand all
1714 fsBuilder->emitFunction(kVec3f_GrSLType, 1704 fsBuilder->emitFunction(kVec3f_GrSLType,
1715 "normal", 1705 "normal",
1716 SK_ARRAY_COUNT(gInteriorNormalArgs), 1706 SK_ARRAY_COUNT(gInteriorNormalArgs),
1717 gInteriorNormalArgs, 1707 gInteriorNormalArgs,
1718 normalBody.c_str(), 1708 normalBody.c_str(),
1719 &normalName); 1709 &normalName);
1720 1710
1721 fsBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str()); 1711 fsBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str());
1722 fsBuilder->codeAppend("\t\tfloat m[9];\n"); 1712 fsBuilder->codeAppend("\t\tfloat m[9];\n");
1723 1713
1724 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); 1714 const char* imgInc = args.fBuilder->getUniformCStr(fImageIncrementUni);
1725 const char* surfScale = builder->getUniformCStr(fSurfaceScaleUni); 1715 const char* surfScale = args.fBuilder->getUniformCStr(fSurfaceScaleUni);
1726 1716
1727 int index = 0; 1717 int index = 0;
1728 for (int dy = 1; dy >= -1; dy--) { 1718 for (int dy = 1; dy >= -1; dy--) {
1729 for (int dx = -1; dx <= 1; dx++) { 1719 for (int dx = -1; dx <= 1; dx++) {
1730 SkString texCoords; 1720 SkString texCoords;
1731 texCoords.appendf("coord + vec2(%d, %d) * %s", dx, dy, imgInc); 1721 texCoords.appendf("coord + vec2(%d, %d) * %s", dx, dy, imgInc);
1732 fsBuilder->codeAppendf("\t\tm[%d] = ", index++); 1722 fsBuilder->codeAppendf("\t\tm[%d] = ", index++);
1733 fsBuilder->appendTextureLookup(samplers[0], texCoords.c_str()); 1723 fsBuilder->appendTextureLookup(args.fSamplers[0], texCoords.c_str()) ;
1734 fsBuilder->codeAppend(".a;\n"); 1724 fsBuilder->codeAppend(".a;\n");
1735 } 1725 }
1736 } 1726 }
1737 fsBuilder->codeAppend("\t\tvec3 surfaceToLight = "); 1727 fsBuilder->codeAppend("\t\tvec3 surfaceToLight = ");
1738 SkString arg; 1728 SkString arg;
1739 arg.appendf("%s * m[4]", surfScale); 1729 arg.appendf("%s * m[4]", surfScale);
1740 fLight->emitSurfaceToLight(builder, arg.c_str()); 1730 fLight->emitSurfaceToLight(args.fBuilder, arg.c_str());
1741 fsBuilder->codeAppend(";\n"); 1731 fsBuilder->codeAppend(";\n");
1742 fsBuilder->codeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ", 1732 fsBuilder->codeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ",
1743 outputColor, lightFunc.c_str(), normalName.c_str(), s urfScale); 1733 args.fOutputColor, lightFunc.c_str(), normalName.c_st r(), surfScale);
1744 fLight->emitLightColor(builder, "surfaceToLight"); 1734 fLight->emitLightColor(args.fBuilder, "surfaceToLight");
1745 fsBuilder->codeAppend(");\n"); 1735 fsBuilder->codeAppend(");\n");
1746 SkString modulate; 1736 SkString modulate;
1747 GrGLSLMulVarBy4f(&modulate, outputColor, inputColor); 1737 GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor);
1748 fsBuilder->codeAppend(modulate.c_str()); 1738 fsBuilder->codeAppend(modulate.c_str());
1749 } 1739 }
1750 1740
1751 void GrGLLightingEffect::GenKey(const GrProcessor& proc, 1741 void GrGLLightingEffect::GenKey(const GrProcessor& proc,
1752 const GrGLSLCaps& caps, GrProcessorKeyBuilder* b ) { 1742 const GrGLSLCaps& caps, GrProcessorKeyBuilder* b ) {
1753 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>(); 1743 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>();
1754 b->add32(lighting.boundaryMode() << 2 | lighting.light()->type()); 1744 b->add32(lighting.boundaryMode() << 2 | lighting.light()->type());
1755 } 1745 }
1756 1746
1757 void GrGLLightingEffect::setData(const GrGLProgramDataManager& pdman, 1747 void GrGLLightingEffect::setData(const GrGLProgramDataManager& pdman,
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
2024 2014
2025 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); 2015 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight);
2026 } 2016 }
2027 2017
2028 #endif 2018 #endif
2029 2019
2030 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) 2020 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter)
2031 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) 2021 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter)
2032 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) 2022 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter)
2033 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 2023 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « src/effects/SkDisplacementMapEffect.cpp ('k') | src/effects/SkLumaColorFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698