Update gradient colorizers to take coords instead of colors.
Gradient layout FPs were passing a position to their colorizers via
sk_InColor.x. This worked, but it makes more sense to pass coordinates
to children by sampling the child at explicit coordinates.
Change-Id: I60520f2e54e04bc9c4d8562e6b2256b95e0de5b4
Bug: skia:10548
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/307217
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index 12ff519..7b669ea 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -2101,8 +2101,10 @@
test_app("fuzz") {
sources = [
"fuzz/Fuzz.cpp",
+ "fuzz/Fuzz.h",
"fuzz/FuzzCanvas.cpp",
"fuzz/FuzzCommon.cpp",
+ "fuzz/FuzzCommon.h",
"fuzz/FuzzCreateDDL.cpp",
"fuzz/FuzzDrawFunctions.cpp",
"fuzz/FuzzEncoders.cpp",
@@ -2476,6 +2478,7 @@
"tools/viewer/TouchGesture.cpp",
"tools/viewer/TouchGesture.h",
"tools/viewer/Viewer.cpp",
+ "tools/viewer/Viewer.h",
]
libs = []
diff --git a/src/gpu/gradients/GrClampedGradientEffect.fp b/src/gpu/gradients/GrClampedGradientEffect.fp
index 69d52f5..7704609 100644
--- a/src/gpu/gradients/GrClampedGradientEffect.fp
+++ b/src/gpu/gradients/GrClampedGradientEffect.fp
@@ -38,10 +38,10 @@
} else if (t.x > 1.0) {
sk_OutColor = rightBorderColor;
} else {
- sk_OutColor = sample(colorizer, t);
+ sk_OutColor = sample(colorizer, t.xy);
}
- @if(makePremul) {
+ @if (makePremul) {
sk_OutColor.xyz *= sk_OutColor.w;
}
}
diff --git a/src/gpu/gradients/GrDualIntervalGradientColorizer.fp b/src/gpu/gradients/GrDualIntervalGradientColorizer.fp
index 602b075..9d56314 100644
--- a/src/gpu/gradients/GrDualIntervalGradientColorizer.fp
+++ b/src/gpu/gradients/GrDualIntervalGradientColorizer.fp
@@ -17,8 +17,8 @@
layout(tracked) in uniform half threshold;
-void main() {
- half t = sk_InColor.x;
+void main(float2 coord) {
+ half t = half(coord.x);
float4 scale, bias;
if (t < threshold) {
diff --git a/src/gpu/gradients/GrGradientShader.cpp b/src/gpu/gradients/GrGradientShader.cpp
index 24d12ba..45c2ec4 100644
--- a/src/gpu/gradients/GrGradientShader.cpp
+++ b/src/gpu/gradients/GrGradientShader.cpp
@@ -65,8 +65,8 @@
SkDebugf("Gradient won't draw. Could not create texture.");
return nullptr;
}
- // TODO: When we start sampling colorizers with explicit coords rather than using sk_InColor
- // the GrTextureEffect can simply be the colorizer.
+ // TODO(skbug.com/10548): When we start sampling colorizers with explicit coords rather than
+ // using sk_InColor, the GrTextureEffect can simply be the colorizer.
auto m = SkMatrix::Scale(view.width(), 1.f);
auto te = GrTextureEffect::Make(std::move(view), alphaType, m, GrSamplerState::Filter::kLinear);
return GrTextureGradientColorizer::Make(std::move(te));
diff --git a/src/gpu/gradients/GrSingleIntervalGradientColorizer.fp b/src/gpu/gradients/GrSingleIntervalGradientColorizer.fp
index fcebe2e..17b6f2f 100644
--- a/src/gpu/gradients/GrSingleIntervalGradientColorizer.fp
+++ b/src/gpu/gradients/GrSingleIntervalGradientColorizer.fp
@@ -12,8 +12,8 @@
layout(ctype=SkPMColor4f, tracked) in uniform half4 start;
layout(ctype=SkPMColor4f, tracked) in uniform half4 end;
-void main() {
- half t = sk_InColor.x;
+void main(float2 coord) {
+ half t = half(coord.x);
// Clamping and/or wrapping was already handled by the parent shader so the output color is a
// simple lerp.
diff --git a/src/gpu/gradients/GrTextureGradientColorizer.fp b/src/gpu/gradients/GrTextureGradientColorizer.fp
index b8dba02..2a7c2ca 100644
--- a/src/gpu/gradients/GrTextureGradientColorizer.fp
+++ b/src/gpu/gradients/GrTextureGradientColorizer.fp
@@ -8,7 +8,6 @@
// Should have height = 1px, horizontal axis represents t = 0 to 1
in fragmentProcessor textureFP;
-void main() {
- half2 coord = half2(sk_InColor.x, 0.5);
- sk_OutColor = sample(textureFP, coord);
+void main(float2 coord) {
+ sk_OutColor = sample(textureFP);
}
diff --git a/src/gpu/gradients/GrTiledGradientEffect.fp b/src/gpu/gradients/GrTiledGradientEffect.fp
index aba5b6c..626a4fc 100644
--- a/src/gpu/gradients/GrTiledGradientEffect.fp
+++ b/src/gpu/gradients/GrTiledGradientEffect.fp
@@ -40,7 +40,7 @@
// t.x has been tiled (repeat or mirrored), but pass through remaining 3 components
// unmodified.
- sk_OutColor = sample(colorizer, t);
+ sk_OutColor = sample(colorizer, t.xy);
}
@if (makePremul) {
diff --git a/src/gpu/gradients/GrUnrolledBinaryGradientColorizer.fp b/src/gpu/gradients/GrUnrolledBinaryGradientColorizer.fp
index d5d7053..bf370ee 100644
--- a/src/gpu/gradients/GrUnrolledBinaryGradientColorizer.fp
+++ b/src/gpu/gradients/GrUnrolledBinaryGradientColorizer.fp
@@ -47,8 +47,8 @@
in uniform half4 thresholds1_7;
in uniform half4 thresholds9_13;
-void main() {
- half t = sk_InColor.x;
+void main(float2 coord) {
+ half t = half(coord.x);
float4 scale, bias;
// Explicit binary search for the proper interval that t falls within. The interval count
diff --git a/src/gpu/gradients/generated/GrClampedGradientEffect.cpp b/src/gpu/gradients/generated/GrClampedGradientEffect.cpp
index f7c57dd..2f5b0a3 100644
--- a/src/gpu/gradients/generated/GrClampedGradientEffect.cpp
+++ b/src/gpu/gradients/generated/GrClampedGradientEffect.cpp
@@ -51,8 +51,8 @@
args.fOutputColor, args.fOutputColor,
args.fUniformHandler->getUniformCStr(leftBorderColorVar), args.fOutputColor,
args.fUniformHandler->getUniformCStr(rightBorderColorVar));
- SkString _input1767("t");
- SkString _sample1767 = this->invokeChild(0, _input1767.c_str(), args);
+ SkString _coords1767("float2(t.xy)");
+ SkString _sample1767 = this->invokeChild(0, args, _coords1767.c_str());
fragBuilder->codeAppendf(
R"SkSL(
%s = %s;
diff --git a/src/gpu/gradients/generated/GrClampedGradientEffect.h b/src/gpu/gradients/generated/GrClampedGradientEffect.h
index e9dc2f2..aec0fd5 100644
--- a/src/gpu/gradients/generated/GrClampedGradientEffect.h
+++ b/src/gpu/gradients/generated/GrClampedGradientEffect.h
@@ -54,7 +54,7 @@
, makePremul(makePremul)
, colorsAreOpaque(colorsAreOpaque) {
SkASSERT(colorizer);
- this->registerChild(std::move(colorizer), SkSL::SampleUsage::PassThrough());
+ this->registerChild(std::move(colorizer), SkSL::SampleUsage::Explicit());
SkASSERT(gradLayout);
this->registerChild(std::move(gradLayout), SkSL::SampleUsage::PassThrough());
}
diff --git a/src/gpu/gradients/generated/GrDualIntervalGradientColorizer.cpp b/src/gpu/gradients/generated/GrDualIntervalGradientColorizer.cpp
index a8ce8f0..c4d8dd6 100644
--- a/src/gpu/gradients/generated/GrDualIntervalGradientColorizer.cpp
+++ b/src/gpu/gradients/generated/GrDualIntervalGradientColorizer.cpp
@@ -46,7 +46,7 @@
thresholdVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kHalf_GrSLType, "threshold");
fragBuilder->codeAppendf(
- R"SkSL(half t = %s.x;
+ R"SkSL(half t = half(%s.x);
float4 scale, bias;
if (t < %s) {
scale = %s;
@@ -57,7 +57,7 @@
}
%s = half4(float(t) * scale + bias);
)SkSL",
- args.fInputColor, args.fUniformHandler->getUniformCStr(thresholdVar),
+ args.fSampleCoord, args.fUniformHandler->getUniformCStr(thresholdVar),
args.fUniformHandler->getUniformCStr(scale01Var),
args.fUniformHandler->getUniformCStr(bias01Var),
args.fUniformHandler->getUniformCStr(scale23Var),
@@ -132,6 +132,7 @@
, bias23(src.bias23)
, threshold(src.threshold) {
this->cloneAndRegisterAllChildProcessors(src);
+ this->setUsesSampleCoordsDirectly();
}
std::unique_ptr<GrFragmentProcessor> GrDualIntervalGradientColorizer::clone() const {
return std::unique_ptr<GrFragmentProcessor>(new GrDualIntervalGradientColorizer(*this));
diff --git a/src/gpu/gradients/generated/GrDualIntervalGradientColorizer.h b/src/gpu/gradients/generated/GrDualIntervalGradientColorizer.h
index a869661..3d3be41 100644
--- a/src/gpu/gradients/generated/GrDualIntervalGradientColorizer.h
+++ b/src/gpu/gradients/generated/GrDualIntervalGradientColorizer.h
@@ -43,7 +43,9 @@
, bias01(bias01)
, scale23(scale23)
, bias23(bias23)
- , threshold(threshold) {}
+ , threshold(threshold) {
+ this->setUsesSampleCoordsDirectly();
+ }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
diff --git a/src/gpu/gradients/generated/GrSingleIntervalGradientColorizer.cpp b/src/gpu/gradients/generated/GrSingleIntervalGradientColorizer.cpp
index c0e1411..8ee0cbd 100644
--- a/src/gpu/gradients/generated/GrSingleIntervalGradientColorizer.cpp
+++ b/src/gpu/gradients/generated/GrSingleIntervalGradientColorizer.cpp
@@ -34,10 +34,11 @@
endVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, kHalf4_GrSLType,
"end");
fragBuilder->codeAppendf(
- R"SkSL(half t = %s.x;
+ R"SkSL(half t = half(%s.x);
%s = mix(%s, %s, t);
)SkSL",
- args.fInputColor, args.fOutputColor, args.fUniformHandler->getUniformCStr(startVar),
+ args.fSampleCoord, args.fOutputColor,
+ args.fUniformHandler->getUniformCStr(startVar),
args.fUniformHandler->getUniformCStr(endVar));
}
@@ -82,6 +83,7 @@
, start(src.start)
, end(src.end) {
this->cloneAndRegisterAllChildProcessors(src);
+ this->setUsesSampleCoordsDirectly();
}
std::unique_ptr<GrFragmentProcessor> GrSingleIntervalGradientColorizer::clone() const {
return std::unique_ptr<GrFragmentProcessor>(new GrSingleIntervalGradientColorizer(*this));
diff --git a/src/gpu/gradients/generated/GrSingleIntervalGradientColorizer.h b/src/gpu/gradients/generated/GrSingleIntervalGradientColorizer.h
index 0f01b7e..15220f5 100644
--- a/src/gpu/gradients/generated/GrSingleIntervalGradientColorizer.h
+++ b/src/gpu/gradients/generated/GrSingleIntervalGradientColorizer.h
@@ -32,7 +32,9 @@
GrSingleIntervalGradientColorizer(SkPMColor4f start, SkPMColor4f end)
: INHERITED(kGrSingleIntervalGradientColorizer_ClassID, kNone_OptimizationFlags)
, start(start)
- , end(end) {}
+ , end(end) {
+ this->setUsesSampleCoordsDirectly();
+ }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
diff --git a/src/gpu/gradients/generated/GrTextureGradientColorizer.cpp b/src/gpu/gradients/generated/GrTextureGradientColorizer.cpp
index ed39249..131e981 100644
--- a/src/gpu/gradients/generated/GrTextureGradientColorizer.cpp
+++ b/src/gpu/gradients/generated/GrTextureGradientColorizer.cpp
@@ -24,15 +24,11 @@
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrTextureGradientColorizer& _outer = args.fFp.cast<GrTextureGradientColorizer>();
(void)_outer;
+ SkString _sample295 = this->invokeChild(0, args);
fragBuilder->codeAppendf(
- R"SkSL(half2 coord = half2(%s.x, 0.5);)SkSL", args.fInputColor);
- SkString _coords327("float2(coord)");
- SkString _sample327 = this->invokeChild(0, args, _coords327.c_str());
- fragBuilder->codeAppendf(
- R"SkSL(
-%s = %s;
+ R"SkSL(%s = %s;
)SkSL",
- args.fOutputColor, _sample327.c_str());
+ args.fOutputColor, _sample295.c_str());
}
private:
diff --git a/src/gpu/gradients/generated/GrTextureGradientColorizer.h b/src/gpu/gradients/generated/GrTextureGradientColorizer.h
index 6216513..53369f6 100644
--- a/src/gpu/gradients/generated/GrTextureGradientColorizer.h
+++ b/src/gpu/gradients/generated/GrTextureGradientColorizer.h
@@ -31,7 +31,7 @@
GrTextureGradientColorizer(std::unique_ptr<GrFragmentProcessor> textureFP)
: INHERITED(kGrTextureGradientColorizer_ClassID, kNone_OptimizationFlags) {
SkASSERT(textureFP);
- this->registerChild(std::move(textureFP), SkSL::SampleUsage::Explicit());
+ this->registerChild(std::move(textureFP), SkSL::SampleUsage::PassThrough());
}
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
diff --git a/src/gpu/gradients/generated/GrTiledGradientEffect.cpp b/src/gpu/gradients/generated/GrTiledGradientEffect.cpp
index ac3da0e5..9ad5ca7 100644
--- a/src/gpu/gradients/generated/GrTiledGradientEffect.cpp
+++ b/src/gpu/gradients/generated/GrTiledGradientEffect.cpp
@@ -49,8 +49,8 @@
_sample453.c_str(),
(_outer.childProcessor(1)->preservesOpaqueInput() ? "true" : "false"),
args.fOutputColor, (_outer.mirror ? "true" : "false"));
- SkString _input1464("t");
- SkString _sample1464 = this->invokeChild(0, _input1464.c_str(), args);
+ SkString _coords1464("float2(t.xy)");
+ SkString _sample1464 = this->invokeChild(0, args, _coords1464.c_str());
fragBuilder->codeAppendf(
R"SkSL(
%s = %s;
diff --git a/src/gpu/gradients/generated/GrTiledGradientEffect.h b/src/gpu/gradients/generated/GrTiledGradientEffect.h
index 3042743..9831c97 100644
--- a/src/gpu/gradients/generated/GrTiledGradientEffect.h
+++ b/src/gpu/gradients/generated/GrTiledGradientEffect.h
@@ -49,7 +49,7 @@
, makePremul(makePremul)
, colorsAreOpaque(colorsAreOpaque) {
SkASSERT(colorizer);
- this->registerChild(std::move(colorizer), SkSL::SampleUsage::PassThrough());
+ this->registerChild(std::move(colorizer), SkSL::SampleUsage::Explicit());
SkASSERT(gradLayout);
this->registerChild(std::move(gradLayout), SkSL::SampleUsage::PassThrough());
}
diff --git a/src/gpu/gradients/generated/GrUnrolledBinaryGradientColorizer.cpp b/src/gpu/gradients/generated/GrUnrolledBinaryGradientColorizer.cpp
index 193a955..38eb82e 100644
--- a/src/gpu/gradients/generated/GrUnrolledBinaryGradientColorizer.cpp
+++ b/src/gpu/gradients/generated/GrUnrolledBinaryGradientColorizer.cpp
@@ -128,7 +128,7 @@
thresholds9_13Var = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kHalf4_GrSLType, "thresholds9_13");
fragBuilder->codeAppendf(
- R"SkSL(half t = %s.x;
+ R"SkSL(half t = half(%s.x);
float4 scale, bias;
if (%d <= 4 || t < %s.w) {
if (%d <= 2 || t < %s.y) {
@@ -169,7 +169,7 @@
}
%s = half4(float(t) * scale + bias);
)SkSL",
- args.fInputColor, _outer.intervalCount,
+ args.fSampleCoord, _outer.intervalCount,
args.fUniformHandler->getUniformCStr(thresholds1_7Var), _outer.intervalCount,
args.fUniformHandler->getUniformCStr(thresholds1_7Var), _outer.intervalCount,
args.fUniformHandler->getUniformCStr(thresholds1_7Var),
@@ -339,6 +339,7 @@
, thresholds1_7(src.thresholds1_7)
, thresholds9_13(src.thresholds9_13) {
this->cloneAndRegisterAllChildProcessors(src);
+ this->setUsesSampleCoordsDirectly();
}
std::unique_ptr<GrFragmentProcessor> GrUnrolledBinaryGradientColorizer::clone() const {
return std::unique_ptr<GrFragmentProcessor>(new GrUnrolledBinaryGradientColorizer(*this));
diff --git a/src/gpu/gradients/generated/GrUnrolledBinaryGradientColorizer.h b/src/gpu/gradients/generated/GrUnrolledBinaryGradientColorizer.h
index 5d9e6f3..1a3d20c 100644
--- a/src/gpu/gradients/generated/GrUnrolledBinaryGradientColorizer.h
+++ b/src/gpu/gradients/generated/GrUnrolledBinaryGradientColorizer.h
@@ -85,7 +85,9 @@
, bias12_13(bias12_13)
, bias14_15(bias14_15)
, thresholds1_7(thresholds1_7)
- , thresholds9_13(thresholds9_13) {}
+ , thresholds9_13(thresholds9_13) {
+ this->setUsesSampleCoordsDirectly();
+ }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;