diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2017-10-26 09:30:08 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-10-26 14:58:27 +0000 |
commit | d608c09ac5d862568962d63e62e693d22c58f95c (patch) | |
tree | 7a5dd9bc7a97dea7fa7720c73e7f9bdf1dac51c9 /src/sksl/SkSLCPPCodeGenerator.cpp | |
parent | d4e9ec86cf934107cc441f651ee2429078188d02 (diff) |
Re-land "converted OverdrawColorFilter to SkSL"
This reverts commit 2d3cac58fcc8f2d398a421b0341c36479a6ba324.
Bug: skia:
Change-Id: I6607d419f6b30c3e17b52ec5ce67d489bd1ad1dc
Reviewed-on: https://skia-review.googlesource.com/64080
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl/SkSLCPPCodeGenerator.cpp')
-rw-r--r-- | src/sksl/SkSLCPPCodeGenerator.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/sksl/SkSLCPPCodeGenerator.cpp b/src/sksl/SkSLCPPCodeGenerator.cpp index b5362bf2b7..3f1d15669d 100644 --- a/src/sksl/SkSLCPPCodeGenerator.cpp +++ b/src/sksl/SkSLCPPCodeGenerator.cpp @@ -130,7 +130,8 @@ static bool is_private(const Variable& var) { var.fModifiers.fLayout.fBuiltin == -1; } -void CPPCodeGenerator::writeRuntimeValue(const Type& type, const String& cppCode) { +void CPPCodeGenerator::writeRuntimeValue(const Type& type, const Layout& layout, + const String& cppCode) { if (type.isFloat()) { this->write("%f"); fFormatArgs.push_back(cppCode); @@ -146,10 +147,17 @@ void CPPCodeGenerator::writeRuntimeValue(const Type& type, const String& cppCode fFormatArgs.push_back(cppCode + ".fY"); } else if (type == *fContext.fFloat4_Type || type == *fContext.fHalf4_Type) { this->write(type.name() + "(%f, %f, %f, %f)"); - fFormatArgs.push_back(cppCode + ".left()"); - fFormatArgs.push_back(cppCode + ".top()"); - fFormatArgs.push_back(cppCode + ".right()"); - fFormatArgs.push_back(cppCode + ".bottom()"); + if (layout.fCType == "SkPMColor") { + fFormatArgs.push_back("SkGetPackedR32(" + cppCode + ") / 255.0"); + fFormatArgs.push_back("SkGetPackedG32(" + cppCode + ") / 255.0"); + fFormatArgs.push_back("SkGetPackedB32(" + cppCode + ") / 255.0"); + fFormatArgs.push_back("SkGetPackedA32(" + cppCode + ") / 255.0"); + } else { + fFormatArgs.push_back(cppCode + ".left()"); + fFormatArgs.push_back(cppCode + ".top()"); + fFormatArgs.push_back(cppCode + ".right()"); + fFormatArgs.push_back(cppCode + ".bottom()"); + } } else { printf("unsupported runtime value type '%s'\n", String(type.fName).c_str()); ASSERT(false); @@ -158,7 +166,7 @@ void CPPCodeGenerator::writeRuntimeValue(const Type& type, const String& cppCode void CPPCodeGenerator::writeVarInitializer(const Variable& var, const Expression& value) { if (is_private(var)) { - this->writeRuntimeValue(var.fType, var.fName); + this->writeRuntimeValue(var.fType, var.fModifiers.fLayout, var.fName); } else { this->writeExpression(value, kTopLevel_Precedence); } @@ -234,7 +242,7 @@ void CPPCodeGenerator::writeVariableReference(const VariableReference& ref) { fFormatArgs.push_back(code); } else if (SectionAndParameterHelper::IsParameter(ref.fVariable)) { String name(ref.fVariable.fName); - this->writeRuntimeValue(ref.fVariable.fType, + this->writeRuntimeValue(ref.fVariable.fType, ref.fVariable.fModifiers.fLayout, String::printf("_outer.%s()", name.c_str()).c_str()); } else { this->write(ref.fVariable.fName); @@ -321,7 +329,7 @@ void CPPCodeGenerator::writeSetting(const Setting& s) { static constexpr const char* kPrefix = "sk_Args."; if (!strncmp(s.fName.c_str(), kPrefix, strlen(kPrefix))) { const char* name = s.fName.c_str() + strlen(kPrefix); - this->writeRuntimeValue(s.fType, HCodeGenerator::FieldName(name).c_str()); + this->writeRuntimeValue(s.fType, Layout(), HCodeGenerator::FieldName(name).c_str()); } else { this->write(s.fName.c_str()); } @@ -414,7 +422,8 @@ void CPPCodeGenerator::writePrivateVars() { return; } this->writef("%s %s;\n", - HCodeGenerator::FieldType(fContext, decl.fVar->fType).c_str(), + HCodeGenerator::FieldType(fContext, decl.fVar->fType, + decl.fVar->fModifiers.fLayout).c_str(), String(decl.fVar->fName).c_str()); } } |