[graphite] Reenable linear gradient shading
Bug: skia:12701
Change-Id: I51bfad4ff61f2ab32753e532eb5b6ee46d765303
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/481737
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/experimental/graphite/src/ContextUtils.cpp b/experimental/graphite/src/ContextUtils.cpp
index 673f251..ccbb048 100644
--- a/experimental/graphite/src/ContextUtils.cpp
+++ b/experimental/graphite/src/ContextUtils.cpp
@@ -42,7 +42,7 @@
static const char* kGradientSkSL =
// TODO: This should use local coords
- "float2 pos = coord.xy;\n"
+ "float2 pos = sk_FragCoord.xy;\n"
"float2 delta = point1 - point0;\n"
"float2 pt = pos - point0;\n"
"float t = dot(pt, delta) / dot(delta, delta);\n"
@@ -56,7 +56,7 @@
"result = mix(result, colors[3],\n"
" clamp((t-offsets[2])/(offsets[3]-offsets[2]),\n"
" 0, 1));\n"
- "outColor = result;\n";
+ "outColor = half4(result);\n";
static const char* kSolidColorSkSL = " outColor = half4(color);\n";
@@ -220,8 +220,6 @@
if (gradInfo.fColorCount > kMaxStops) {
type = SkShader::GradientType::kNone_GradientType;
}
- // TODO(robertphillips): Remove once gradient MSL compiles
- type = SkShader::GradientType::kNone_GradientType;
switch (type) {
case SkShader::kLinear_GradientType: {
@@ -298,15 +296,14 @@
SkSpan<const Uniform> GetUniforms(ShaderCombo::ShaderType shaderType) {
switch (shaderType) {
+ case ShaderCombo::ShaderType::kNone:
+ return {nullptr, 0};
case ShaderCombo::ShaderType::kLinearGradient:
+ return SkMakeSpan(kGradientUniforms, kNumGradientUniforms);
case ShaderCombo::ShaderType::kRadialGradient:
case ShaderCombo::ShaderType::kSweepGradient:
case ShaderCombo::ShaderType::kConicalGradient:
- // TODO(robertphillips): return gradient uniforms when MSL is ready
- // return SkMakeSpan(kGradientUniforms, kNumGradientUniforms);
- return SkMakeSpan(kSolidUniforms, kNumSolidUniforms);
- case ShaderCombo::ShaderType::kNone:
- return {nullptr, 0};
+ case ShaderCombo::ShaderType::kSolidColor:
default:
return SkMakeSpan(kSolidUniforms, kNumSolidUniforms);
}
@@ -314,15 +311,13 @@
const char* GetShaderSkSL(ShaderCombo::ShaderType shaderType) {
switch (shaderType) {
+ case ShaderCombo::ShaderType::kNone:
+ return kNoneSkSL;
case ShaderCombo::ShaderType::kLinearGradient:
+ return kGradientSkSL;
case ShaderCombo::ShaderType::kRadialGradient:
case ShaderCombo::ShaderType::kSweepGradient:
case ShaderCombo::ShaderType::kConicalGradient:
- // TODO(robertphillips): return gradient MSL when ready
- (void) kGradientSkSL;
- return kSolidColorSkSL;
- case ShaderCombo::ShaderType::kNone:
- return kNoneSkSL;
case ShaderCombo::ShaderType::kSolidColor:
default:
return kSolidColorSkSL;
diff --git a/tests/graphite/UniformTest.cpp b/tests/graphite/UniformTest.cpp
index b6a0085..d566a20 100644
--- a/tests/graphite/UniformTest.cpp
+++ b/tests/graphite/UniformTest.cpp
@@ -63,12 +63,11 @@
// Intentionally does not include ShaderType::kNone, which represents no fragment shading stage
// and is thus not relevant to uniform extraction/caching.
- // TODO(robertphillips): Renable gradient shader types when MSL compiles correctly
- for (auto s : { ShaderCombo::ShaderType::kSolidColor}) {
- // ShaderCombo::ShaderType::kLinearGradient,
- // ShaderCombo::ShaderType::kRadialGradient,
- // ShaderCombo::ShaderType::kSweepGradient,
- // ShaderCombo::ShaderType::kConicalGradient }) {
+ for (auto s : { ShaderCombo::ShaderType::kSolidColor,
+ ShaderCombo::ShaderType::kLinearGradient,
+ ShaderCombo::ShaderType::kRadialGradient,
+ ShaderCombo::ShaderType::kSweepGradient,
+ ShaderCombo::ShaderType::kConicalGradient }) {
for (auto tm: { SkTileMode::kClamp,
SkTileMode::kRepeat,
SkTileMode::kMirror,