Remove the last use of fragmentProcessor field access in .fp files
This is a complex feature that was propping up this one use-case. After this CL, it can be removed. Change-Id: Ia391565daddeba46adfb325980d10ad653e269c8 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375019 Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
948baff2b5
commit
c826a1caec
@ -23,6 +23,7 @@ layout(ctype=SkPMColor4f, tracked) in uniform half4 rightBorderColor; // t > 1.0
|
||||
layout(key) in bool makePremul;
|
||||
// Trust the creator that this matches the color spec of the gradient
|
||||
in bool colorsAreOpaque;
|
||||
layout(key) in bool layoutPreservesOpacity;
|
||||
|
||||
half4 main() {
|
||||
half4 t = sample(gradLayout);
|
||||
@ -31,7 +32,7 @@ half4 main() {
|
||||
// If t.x is below 0, use the left border color without invoking the child processor. If any t.x
|
||||
// is above 1, use the right border color. Otherwise, t is in the [0, 1] range assumed by the
|
||||
// colorizer FP, so delegate to the child processor.
|
||||
if (!gradLayout.preservesOpaqueInput && t.y < 0) {
|
||||
if (!layoutPreservesOpacity && t.y < 0) {
|
||||
// layout has rejected this fragment (rely on sksl to remove this branch if the layout FP
|
||||
// preserves opacity is false)
|
||||
outColor = half4(0);
|
||||
@ -56,6 +57,21 @@ half4 main() {
|
||||
// into account the opacity of the border colors).
|
||||
@optimizationFlags {
|
||||
kCompatibleWithCoverageAsAlpha_OptimizationFlag |
|
||||
(colorsAreOpaque && gradLayout->preservesOpaqueInput() ? kPreservesOpaqueInput_OptimizationFlag
|
||||
: kNone_OptimizationFlags)
|
||||
(colorsAreOpaque && layoutPreservesOpacity ? kPreservesOpaqueInput_OptimizationFlag
|
||||
: kNone_OptimizationFlags)
|
||||
}
|
||||
|
||||
@make{
|
||||
static std::unique_ptr<GrFragmentProcessor> Make(
|
||||
std::unique_ptr<GrFragmentProcessor> colorizer,
|
||||
std::unique_ptr<GrFragmentProcessor> gradLayout,
|
||||
SkPMColor4f leftBorderColor,
|
||||
SkPMColor4f rightBorderColor,
|
||||
bool makePremul,
|
||||
bool colorsAreOpaque) {
|
||||
bool layoutPreservesOpacity = gradLayout->preservesOpaqueInput();
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrClampedGradientEffect(
|
||||
std::move(colorizer), std::move(gradLayout), leftBorderColor, rightBorderColor,
|
||||
makePremul, colorsAreOpaque, layoutPreservesOpacity));
|
||||
}
|
||||
}
|
||||
|
@ -14,11 +14,12 @@ layout(key) in bool mirror;
|
||||
layout(key) in bool makePremul;
|
||||
// Trust the creator that this matches the color spec of the gradient
|
||||
in bool colorsAreOpaque;
|
||||
layout(key) in bool layoutPreservesOpacity;
|
||||
|
||||
half4 main() {
|
||||
half4 t = sample(gradLayout);
|
||||
|
||||
if (!gradLayout.preservesOpaqueInput && t.y < 0) {
|
||||
if (!layoutPreservesOpacity && t.y < 0) {
|
||||
// layout has rejected this fragment (rely on sksl to remove this branch if the layout FP
|
||||
// preserves opacity is false)
|
||||
return half4(0);
|
||||
@ -54,6 +55,20 @@ half4 main() {
|
||||
// but otherwise respect the provided color opacity state.
|
||||
@optimizationFlags {
|
||||
kCompatibleWithCoverageAsAlpha_OptimizationFlag |
|
||||
(colorsAreOpaque && gradLayout->preservesOpaqueInput() ? kPreservesOpaqueInput_OptimizationFlag
|
||||
: kNone_OptimizationFlags)
|
||||
(colorsAreOpaque && layoutPreservesOpacity ? kPreservesOpaqueInput_OptimizationFlag
|
||||
: kNone_OptimizationFlags)
|
||||
}
|
||||
|
||||
@make{
|
||||
static std::unique_ptr<GrFragmentProcessor> Make(
|
||||
std::unique_ptr<GrFragmentProcessor> colorizer,
|
||||
std::unique_ptr<GrFragmentProcessor> gradLayout,
|
||||
bool mirror,
|
||||
bool makePremul,
|
||||
bool colorsAreOpaque) {
|
||||
bool layoutPreservesOpacity = gradLayout->preservesOpaqueInput();
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrTiledGradientEffect(
|
||||
std::move(colorizer), std::move(gradLayout), mirror, makePremul, colorsAreOpaque,
|
||||
layoutPreservesOpacity));
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,8 @@ public:
|
||||
(void)makePremul;
|
||||
auto colorsAreOpaque = _outer.colorsAreOpaque;
|
||||
(void)colorsAreOpaque;
|
||||
auto layoutPreservesOpacity = _outer.layoutPreservesOpacity;
|
||||
(void)layoutPreservesOpacity;
|
||||
leftBorderColorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
|
||||
kHalf4_GrSLType, "leftBorderColor");
|
||||
rightBorderColorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
|
||||
@ -47,8 +49,7 @@ if (!%s && t.y < 0.0) {
|
||||
} else if (t.x > 1.0) {
|
||||
outColor = %s;
|
||||
} else {)SkSL",
|
||||
_sample0.c_str(),
|
||||
(_outer.childProcessor(1)->preservesOpaqueInput() ? "true" : "false"),
|
||||
_sample0.c_str(), (_outer.layoutPreservesOpacity ? "true" : "false"),
|
||||
args.fUniformHandler->getUniformCStr(leftBorderColorVar),
|
||||
args.fUniformHandler->getUniformCStr(rightBorderColorVar));
|
||||
SkString _coords1("float2(half2(t.x, 0.0))");
|
||||
@ -93,6 +94,7 @@ std::unique_ptr<GrGLSLFragmentProcessor> GrClampedGradientEffect::onMakeProgramI
|
||||
void GrClampedGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
|
||||
GrProcessorKeyBuilder* b) const {
|
||||
b->add32((uint32_t)makePremul);
|
||||
b->add32((uint32_t)layoutPreservesOpacity);
|
||||
}
|
||||
bool GrClampedGradientEffect::onIsEqual(const GrFragmentProcessor& other) const {
|
||||
const GrClampedGradientEffect& that = other.cast<GrClampedGradientEffect>();
|
||||
@ -101,6 +103,7 @@ bool GrClampedGradientEffect::onIsEqual(const GrFragmentProcessor& other) const
|
||||
if (rightBorderColor != that.rightBorderColor) return false;
|
||||
if (makePremul != that.makePremul) return false;
|
||||
if (colorsAreOpaque != that.colorsAreOpaque) return false;
|
||||
if (layoutPreservesOpacity != that.layoutPreservesOpacity) return false;
|
||||
return true;
|
||||
}
|
||||
GrClampedGradientEffect::GrClampedGradientEffect(const GrClampedGradientEffect& src)
|
||||
@ -108,7 +111,8 @@ GrClampedGradientEffect::GrClampedGradientEffect(const GrClampedGradientEffect&
|
||||
, leftBorderColor(src.leftBorderColor)
|
||||
, rightBorderColor(src.rightBorderColor)
|
||||
, makePremul(src.makePremul)
|
||||
, colorsAreOpaque(src.colorsAreOpaque) {
|
||||
, colorsAreOpaque(src.colorsAreOpaque)
|
||||
, layoutPreservesOpacity(src.layoutPreservesOpacity) {
|
||||
this->cloneAndRegisterAllChildProcessors(src);
|
||||
}
|
||||
std::unique_ptr<GrFragmentProcessor> GrClampedGradientEffect::clone() const {
|
||||
@ -118,9 +122,10 @@ std::unique_ptr<GrFragmentProcessor> GrClampedGradientEffect::clone() const {
|
||||
SkString GrClampedGradientEffect::onDumpInfo() const {
|
||||
return SkStringPrintf(
|
||||
"(leftBorderColor=half4(%f, %f, %f, %f), rightBorderColor=half4(%f, %f, %f, %f), "
|
||||
"makePremul=%s, colorsAreOpaque=%s)",
|
||||
"makePremul=%s, colorsAreOpaque=%s, layoutPreservesOpacity=%s)",
|
||||
leftBorderColor.fR, leftBorderColor.fG, leftBorderColor.fB, leftBorderColor.fA,
|
||||
rightBorderColor.fR, rightBorderColor.fG, rightBorderColor.fB, rightBorderColor.fA,
|
||||
(makePremul ? "true" : "false"), (colorsAreOpaque ? "true" : "false"));
|
||||
(makePremul ? "true" : "false"), (colorsAreOpaque ? "true" : "false"),
|
||||
(layoutPreservesOpacity ? "true" : "false"));
|
||||
}
|
||||
#endif
|
||||
|
@ -25,9 +25,10 @@ public:
|
||||
SkPMColor4f rightBorderColor,
|
||||
bool makePremul,
|
||||
bool colorsAreOpaque) {
|
||||
bool layoutPreservesOpacity = gradLayout->preservesOpaqueInput();
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrClampedGradientEffect(
|
||||
std::move(colorizer), std::move(gradLayout), leftBorderColor, rightBorderColor,
|
||||
makePremul, colorsAreOpaque));
|
||||
makePremul, colorsAreOpaque, layoutPreservesOpacity));
|
||||
}
|
||||
GrClampedGradientEffect(const GrClampedGradientEffect& src);
|
||||
std::unique_ptr<GrFragmentProcessor> clone() const override;
|
||||
@ -36,6 +37,7 @@ public:
|
||||
SkPMColor4f rightBorderColor;
|
||||
bool makePremul;
|
||||
bool colorsAreOpaque;
|
||||
bool layoutPreservesOpacity;
|
||||
|
||||
private:
|
||||
GrClampedGradientEffect(std::unique_ptr<GrFragmentProcessor> colorizer,
|
||||
@ -43,16 +45,18 @@ private:
|
||||
SkPMColor4f leftBorderColor,
|
||||
SkPMColor4f rightBorderColor,
|
||||
bool makePremul,
|
||||
bool colorsAreOpaque)
|
||||
bool colorsAreOpaque,
|
||||
bool layoutPreservesOpacity)
|
||||
: INHERITED(kGrClampedGradientEffect_ClassID,
|
||||
(OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag |
|
||||
(colorsAreOpaque && gradLayout->preservesOpaqueInput()
|
||||
(colorsAreOpaque && layoutPreservesOpacity
|
||||
? kPreservesOpaqueInput_OptimizationFlag
|
||||
: kNone_OptimizationFlags))
|
||||
, leftBorderColor(leftBorderColor)
|
||||
, rightBorderColor(rightBorderColor)
|
||||
, makePremul(makePremul)
|
||||
, colorsAreOpaque(colorsAreOpaque) {
|
||||
, colorsAreOpaque(colorsAreOpaque)
|
||||
, layoutPreservesOpacity(layoutPreservesOpacity) {
|
||||
this->registerChild(std::move(colorizer), SkSL::SampleUsage::Explicit());
|
||||
this->registerChild(std::move(gradLayout), SkSL::SampleUsage::PassThrough());
|
||||
}
|
||||
|
@ -30,6 +30,8 @@ public:
|
||||
(void)makePremul;
|
||||
auto colorsAreOpaque = _outer.colorsAreOpaque;
|
||||
(void)colorsAreOpaque;
|
||||
auto layoutPreservesOpacity = _outer.layoutPreservesOpacity;
|
||||
(void)layoutPreservesOpacity;
|
||||
SkString _sample0 = this->invokeChild(1, args);
|
||||
fragBuilder->codeAppendf(
|
||||
R"SkSL(half4 t = %s;
|
||||
@ -47,8 +49,7 @@ if (!%s && t.y < 0.0) {
|
||||
t.x = fract(t.x);
|
||||
}
|
||||
@if (!%s) {)SkSL",
|
||||
_sample0.c_str(),
|
||||
(_outer.childProcessor(1)->preservesOpaqueInput() ? "true" : "false"),
|
||||
_sample0.c_str(), (_outer.layoutPreservesOpacity ? "true" : "false"),
|
||||
(_outer.mirror ? "true" : "false"), (_outer.makePremul ? "true" : "false"));
|
||||
SkString _coords1("float2(half2(t.x, 0.0))");
|
||||
SkString _sample1 = this->invokeChild(0, args, _coords1.c_str());
|
||||
@ -80,6 +81,7 @@ void GrTiledGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
|
||||
GrProcessorKeyBuilder* b) const {
|
||||
b->add32((uint32_t)mirror);
|
||||
b->add32((uint32_t)makePremul);
|
||||
b->add32((uint32_t)layoutPreservesOpacity);
|
||||
}
|
||||
bool GrTiledGradientEffect::onIsEqual(const GrFragmentProcessor& other) const {
|
||||
const GrTiledGradientEffect& that = other.cast<GrTiledGradientEffect>();
|
||||
@ -87,13 +89,15 @@ bool GrTiledGradientEffect::onIsEqual(const GrFragmentProcessor& other) const {
|
||||
if (mirror != that.mirror) return false;
|
||||
if (makePremul != that.makePremul) return false;
|
||||
if (colorsAreOpaque != that.colorsAreOpaque) return false;
|
||||
if (layoutPreservesOpacity != that.layoutPreservesOpacity) return false;
|
||||
return true;
|
||||
}
|
||||
GrTiledGradientEffect::GrTiledGradientEffect(const GrTiledGradientEffect& src)
|
||||
: INHERITED(kGrTiledGradientEffect_ClassID, src.optimizationFlags())
|
||||
, mirror(src.mirror)
|
||||
, makePremul(src.makePremul)
|
||||
, colorsAreOpaque(src.colorsAreOpaque) {
|
||||
, colorsAreOpaque(src.colorsAreOpaque)
|
||||
, layoutPreservesOpacity(src.layoutPreservesOpacity) {
|
||||
this->cloneAndRegisterAllChildProcessors(src);
|
||||
}
|
||||
std::unique_ptr<GrFragmentProcessor> GrTiledGradientEffect::clone() const {
|
||||
@ -101,8 +105,9 @@ std::unique_ptr<GrFragmentProcessor> GrTiledGradientEffect::clone() const {
|
||||
}
|
||||
#if GR_TEST_UTILS
|
||||
SkString GrTiledGradientEffect::onDumpInfo() const {
|
||||
return SkStringPrintf("(mirror=%s, makePremul=%s, colorsAreOpaque=%s)",
|
||||
(mirror ? "true" : "false"), (makePremul ? "true" : "false"),
|
||||
(colorsAreOpaque ? "true" : "false"));
|
||||
return SkStringPrintf(
|
||||
"(mirror=%s, makePremul=%s, colorsAreOpaque=%s, layoutPreservesOpacity=%s)",
|
||||
(mirror ? "true" : "false"), (makePremul ? "true" : "false"),
|
||||
(colorsAreOpaque ? "true" : "false"), (layoutPreservesOpacity ? "true" : "false"));
|
||||
}
|
||||
#endif
|
||||
|
@ -24,8 +24,10 @@ public:
|
||||
bool mirror,
|
||||
bool makePremul,
|
||||
bool colorsAreOpaque) {
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrTiledGradientEffect(
|
||||
std::move(colorizer), std::move(gradLayout), mirror, makePremul, colorsAreOpaque));
|
||||
bool layoutPreservesOpacity = gradLayout->preservesOpaqueInput();
|
||||
return std::unique_ptr<GrFragmentProcessor>(
|
||||
new GrTiledGradientEffect(std::move(colorizer), std::move(gradLayout), mirror,
|
||||
makePremul, colorsAreOpaque, layoutPreservesOpacity));
|
||||
}
|
||||
GrTiledGradientEffect(const GrTiledGradientEffect& src);
|
||||
std::unique_ptr<GrFragmentProcessor> clone() const override;
|
||||
@ -33,21 +35,24 @@ public:
|
||||
bool mirror;
|
||||
bool makePremul;
|
||||
bool colorsAreOpaque;
|
||||
bool layoutPreservesOpacity;
|
||||
|
||||
private:
|
||||
GrTiledGradientEffect(std::unique_ptr<GrFragmentProcessor> colorizer,
|
||||
std::unique_ptr<GrFragmentProcessor> gradLayout,
|
||||
bool mirror,
|
||||
bool makePremul,
|
||||
bool colorsAreOpaque)
|
||||
bool colorsAreOpaque,
|
||||
bool layoutPreservesOpacity)
|
||||
: INHERITED(kGrTiledGradientEffect_ClassID,
|
||||
(OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag |
|
||||
(colorsAreOpaque && gradLayout->preservesOpaqueInput()
|
||||
(colorsAreOpaque && layoutPreservesOpacity
|
||||
? kPreservesOpaqueInput_OptimizationFlag
|
||||
: kNone_OptimizationFlags))
|
||||
, mirror(mirror)
|
||||
, makePremul(makePremul)
|
||||
, colorsAreOpaque(colorsAreOpaque) {
|
||||
, colorsAreOpaque(colorsAreOpaque)
|
||||
, layoutPreservesOpacity(layoutPreservesOpacity) {
|
||||
this->registerChild(std::move(colorizer), SkSL::SampleUsage::Explicit());
|
||||
this->registerChild(std::move(gradLayout), SkSL::SampleUsage::PassThrough());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user