diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2017-11-20 12:12:24 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-11-20 20:34:38 +0000 |
commit | e9d172af84fff5d76e19180a0c2b7b3cc51e90a2 (patch) | |
tree | 115bce6c41c0e7fada2f45de6e7b5e90b464e00a /src/sksl | |
parent | 53d863c18cd3b53d8b4c4dcb8505f2c52f1e5c59 (diff) |
converted ConstColorProcessor to SkSL
Bug: skia:
Change-Id: Ic3b18f82c1ab940637fb26dec1cf376dd859b35d
Reviewed-on: https://skia-review.googlesource.com/73720
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl')
-rw-r--r-- | src/sksl/SkSLCPP.h | 30 | ||||
-rw-r--r-- | src/sksl/SkSLCPPCodeGenerator.cpp | 20 | ||||
-rw-r--r-- | src/sksl/SkSLHCodeGenerator.cpp | 2 | ||||
-rw-r--r-- | src/sksl/SkSLString.cpp | 14 |
4 files changed, 59 insertions, 7 deletions
diff --git a/src/sksl/SkSLCPP.h b/src/sksl/SkSLCPP.h index 970e2c73c9..fc9cafa4ac 100644 --- a/src/sksl/SkSLCPP.h +++ b/src/sksl/SkSLCPP.h @@ -15,6 +15,28 @@ using std::abs; +struct Float4 { + Float4(float x, float y, float z, float w) + : fX(x) + , fY(y) + , fZ(z) + , fW(w) {} + + operator SkRect() const { + return SkRect::MakeLTRB(fX, fY, fZ, fW); + } + + operator GrColor4f() const { + return GrColor4f(fX, fY, fZ, fW); + } + +private: + float fX; + float fY; + float fZ; + float fW; +}; + // macros to make sk_Caps.<cap name> work from C++ code #define sk_Caps (*args.fShaderCaps) @@ -25,10 +47,14 @@ inline SkPoint float2(float xy) { return SkPoint::Make(xy, xy); } inline SkPoint float2(float x, float y) { return SkPoint::Make(x, y); } -inline SkRect float4(float ltrb) { return SkRect::MakeLTRB(ltrb, ltrb, ltrb, ltrb); } +inline Float4 float4(float xyzw) { return Float4(xyzw, xyzw, xyzw, xyzw); } -inline SkRect float4(float l, float t, float r, float b) { return SkRect::MakeLTRB(l, t, r, b); } +inline Float4 float4(float x, float y, float z, float w) { return Float4(x, y, z, w); } #define half2 float2 +#define half3 float3 + +#define half4 float4 + #endif diff --git a/src/sksl/SkSLCPPCodeGenerator.cpp b/src/sksl/SkSLCPPCodeGenerator.cpp index fc2a6e396e..5b0b497fa1 100644 --- a/src/sksl/SkSLCPPCodeGenerator.cpp +++ b/src/sksl/SkSLCPPCodeGenerator.cpp @@ -115,6 +115,9 @@ void CPPCodeGenerator::writeIndexExpression(const IndexExpression& i) { } static String default_value(const Type& type) { + if (type.fName == "bool") { + return "false"; + } switch (type.kind()) { case Type::kScalar_Kind: return "0"; case Type::kVector_Kind: return type.name() + "(0)"; @@ -123,6 +126,13 @@ static String default_value(const Type& type) { } } +static String default_value(const Variable& var) { + if (var.fModifiers.fLayout.fCType == "GrColor4f") { + return "GrColor4f::kIllegalConstructor"; + } + return default_value(var.fType); +} + static bool is_private(const Variable& var) { return !(var.fModifiers.fFlags & Modifiers::kUniform_Flag) && !(var.fModifiers.fFlags & Modifiers::kIn_Flag) && @@ -152,6 +162,11 @@ void CPPCodeGenerator::writeRuntimeValue(const Type& type, const Layout& layout, fFormatArgs.push_back("SkGetPackedG32(" + cppCode + ") / 255.0"); fFormatArgs.push_back("SkGetPackedB32(" + cppCode + ") / 255.0"); fFormatArgs.push_back("SkGetPackedA32(" + cppCode + ") / 255.0"); + } else if (layout.fCType == "GrColor4f") { + fFormatArgs.push_back(cppCode + ".fRGBA[0]"); + fFormatArgs.push_back(cppCode + ".fRGBA[1]"); + fFormatArgs.push_back(cppCode + ".fRGBA[2]"); + fFormatArgs.push_back(cppCode + ".fRGBA[3]"); } else { fFormatArgs.push_back(cppCode + ".left()"); fFormatArgs.push_back(cppCode + ".top()"); @@ -424,10 +439,11 @@ void CPPCodeGenerator::writePrivateVars() { "fragmentProcessor variables must be declared 'in'"); return; } - this->writef("%s %s;\n", + this->writef("%s %s = %s;\n", HCodeGenerator::FieldType(fContext, decl.fVar->fType, decl.fVar->fModifiers.fLayout).c_str(), - String(decl.fVar->fName).c_str()); + String(decl.fVar->fName).c_str(), + default_value(*decl.fVar).c_str()); } } } diff --git a/src/sksl/SkSLHCodeGenerator.cpp b/src/sksl/SkSLHCodeGenerator.cpp index 37eef60f9b..819b85a515 100644 --- a/src/sksl/SkSLHCodeGenerator.cpp +++ b/src/sksl/SkSLHCodeGenerator.cpp @@ -266,12 +266,12 @@ bool HCodeGenerator::generateCode() { this->writef("class %s : public GrFragmentProcessor {\n" "public:\n", fFullName.c_str()); - this->writeSection(CLASS_SECTION); for (const auto& p : fProgram.fElements) { if (ProgramElement::kEnum_Kind == p->fKind && !((Enum&) *p).fBuiltin) { this->writef("%s\n", p->description().c_str()); } } + this->writeSection(CLASS_SECTION); for (const auto& param : fSectionAndParameterHelper.getParameters()) { if (param->fType.kind() == Type::kSampler_Kind || param->fType.kind() == Type::kOther_Kind) { diff --git a/src/sksl/SkSLString.cpp b/src/sksl/SkSLString.cpp index bd6de3532c..c9242d398e 100644 --- a/src/sksl/SkSLString.cpp +++ b/src/sksl/SkSLString.cpp @@ -148,11 +148,21 @@ bool StringFragment::operator!=(StringFragment s) const { } bool StringFragment::operator==(const char* s) const { - return !strncmp(fChars, s, fLength); + for (size_t i = 0; i < fLength; ++i) { + if (fChars[i] != s[i]) { + return false; + } + } + return 0 == s[fLength]; } bool StringFragment::operator!=(const char* s) const { - return strncmp(fChars, s, fLength); + for (size_t i = 0; i < fLength; ++i) { + if (fChars[i] != s[i]) { + return true; + } + } + return 0 != s[fLength]; } bool operator==(const char* s1, StringFragment s2) { |