Update EllipticalRRectEffect to support an input FP.
We are updating FPs to receive their input via a child FP where possible, instead of relying on the input color. Additionally, made minor cleanups in CircularRRectEffect for parity with EllipticalRRectEffect, and took advantage of the new API cloneAndRegisterAllChildProcessors to reduce boilerplate. Change-Id: I3b7d22cb2a9da4471bdfda763dac93fe7616d927 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/296129 Commit-Queue: John Stiles <johnstiles@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
parent
8c71f3e7d7
commit
c0d5d9c6f6
@ -61,11 +61,14 @@ public:
|
||||
|
||||
GrClipEdgeType getEdgeType() const { return fEdgeType; }
|
||||
|
||||
int getInputFPIndex() const { return fInputFPIndex; }
|
||||
bool hasInputFP() const {
|
||||
return this->numChildProcessors() > 0;
|
||||
}
|
||||
|
||||
private:
|
||||
CircularRRectEffect(std::unique_ptr<GrFragmentProcessor> inputFP,
|
||||
GrClipEdgeType, uint32_t circularCornerFlags, const SkRRect&);
|
||||
CircularRRectEffect(const CircularRRectEffect& that);
|
||||
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
|
||||
@ -76,7 +79,6 @@ private:
|
||||
SkRRect fRRect;
|
||||
GrClipEdgeType fEdgeType;
|
||||
uint32_t fCircularCornerFlags;
|
||||
int fInputFPIndex;
|
||||
|
||||
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
|
||||
|
||||
@ -103,23 +105,21 @@ CircularRRectEffect::CircularRRectEffect(std::unique_ptr<GrFragmentProcessor> in
|
||||
, fRRect(rrect)
|
||||
, fEdgeType(edgeType)
|
||||
, fCircularCornerFlags(circularCornerFlags) {
|
||||
fInputFPIndex = inputFP
|
||||
? this->registerChildProcessor(std::move(inputFP))
|
||||
: -1;
|
||||
if (inputFP != nullptr) {
|
||||
this->registerChildProcessor(std::move(inputFP));
|
||||
}
|
||||
}
|
||||
|
||||
CircularRRectEffect::CircularRRectEffect(const CircularRRectEffect& that)
|
||||
: INHERITED(kCircularRRectEffect_ClassID, that.optimizationFlags())
|
||||
, fRRect(that.fRRect)
|
||||
, fEdgeType(that.fEdgeType)
|
||||
, fCircularCornerFlags(that.fCircularCornerFlags) {
|
||||
this->cloneAndRegisterAllChildProcessors(that);
|
||||
}
|
||||
|
||||
std::unique_ptr<GrFragmentProcessor> CircularRRectEffect::clone() const {
|
||||
std::unique_ptr<GrFragmentProcessor> inputFPClone;
|
||||
if (fInputFPIndex >= 0) {
|
||||
const GrFragmentProcessor& inputFP = this->childProcessor(fInputFPIndex);
|
||||
inputFPClone = inputFP.clone();
|
||||
if (inputFP.isSampledWithExplicitCoords()) {
|
||||
inputFPClone->setSampledWithExplicitCoords();
|
||||
}
|
||||
}
|
||||
|
||||
return std::unique_ptr<GrFragmentProcessor>(new CircularRRectEffect(
|
||||
std::move(inputFPClone), fEdgeType, fCircularCornerFlags, fRRect));
|
||||
return std::unique_ptr<GrFragmentProcessor>(new CircularRRectEffect(*this));
|
||||
}
|
||||
|
||||
bool CircularRRectEffect::onIsEqual(const GrFragmentProcessor& other) const {
|
||||
@ -301,8 +301,8 @@ void GLCircularRRectEffect::emitCode(EmitArgs& args) {
|
||||
fragBuilder->codeAppend("alpha = 1.0 - alpha;");
|
||||
}
|
||||
|
||||
SkString inputSample = (crre.getInputFPIndex() >= 0)
|
||||
? this->invokeChild(crre.getInputFPIndex(), args.fInputColor, args)
|
||||
SkString inputSample = crre.hasInputFP()
|
||||
? this->invokeChild(/*childIndex=*/0, args.fInputColor, args)
|
||||
: SkString(args.fInputColor);
|
||||
|
||||
fragBuilder->codeAppendf("%s = %s * alpha;", args.fOutputColor, inputSample.c_str());
|
||||
@ -410,7 +410,8 @@ GrGLSLFragmentProcessor* CircularRRectEffect::onCreateGLSLInstance() const {
|
||||
|
||||
class EllipticalRRectEffect : public GrFragmentProcessor {
|
||||
public:
|
||||
static std::unique_ptr<GrFragmentProcessor> Make(GrClipEdgeType, const SkRRect&);
|
||||
static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor>,
|
||||
GrClipEdgeType, const SkRRect&);
|
||||
|
||||
~EllipticalRRectEffect() override {}
|
||||
|
||||
@ -422,8 +423,13 @@ public:
|
||||
|
||||
GrClipEdgeType getEdgeType() const { return fEdgeType; }
|
||||
|
||||
bool hasInputFP() const {
|
||||
return this->numChildProcessors() > 0;
|
||||
}
|
||||
|
||||
private:
|
||||
EllipticalRRectEffect(GrClipEdgeType, const SkRRect&);
|
||||
EllipticalRRectEffect(std::unique_ptr<GrFragmentProcessor>, GrClipEdgeType, const SkRRect&);
|
||||
EllipticalRRectEffect(const EllipticalRRectEffect& that);
|
||||
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
|
||||
@ -439,22 +445,38 @@ private:
|
||||
typedef GrFragmentProcessor INHERITED;
|
||||
};
|
||||
|
||||
std::unique_ptr<GrFragmentProcessor> EllipticalRRectEffect::Make(GrClipEdgeType edgeType,
|
||||
const SkRRect& rrect) {
|
||||
std::unique_ptr<GrFragmentProcessor> EllipticalRRectEffect::Make(
|
||||
std::unique_ptr<GrFragmentProcessor> inputFP,
|
||||
GrClipEdgeType edgeType, const SkRRect& rrect) {
|
||||
if (GrClipEdgeType::kFillAA != edgeType && GrClipEdgeType::kInverseFillAA != edgeType) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::unique_ptr<GrFragmentProcessor>(new EllipticalRRectEffect(edgeType, rrect));
|
||||
return std::unique_ptr<GrFragmentProcessor>(new EllipticalRRectEffect(
|
||||
std::move(inputFP), edgeType, rrect));
|
||||
}
|
||||
|
||||
EllipticalRRectEffect::EllipticalRRectEffect(GrClipEdgeType edgeType, const SkRRect& rrect)
|
||||
: INHERITED(kEllipticalRRectEffect_ClassID, kCompatibleWithCoverageAsAlpha_OptimizationFlag)
|
||||
EllipticalRRectEffect::EllipticalRRectEffect(std::unique_ptr<GrFragmentProcessor> inputFP,
|
||||
GrClipEdgeType edgeType, const SkRRect& rrect)
|
||||
: INHERITED(
|
||||
kEllipticalRRectEffect_ClassID,
|
||||
(inputFP ? ProcessorOptimizationFlags(inputFP.get()) : kAll_OptimizationFlags) &
|
||||
kCompatibleWithCoverageAsAlpha_OptimizationFlag)
|
||||
, fRRect(rrect)
|
||||
, fEdgeType(edgeType) {
|
||||
if (inputFP != nullptr) {
|
||||
this->registerChildProcessor(std::move(inputFP));
|
||||
}
|
||||
}
|
||||
|
||||
EllipticalRRectEffect::EllipticalRRectEffect(const EllipticalRRectEffect& that)
|
||||
: INHERITED(kEllipticalRRectEffect_ClassID, that.optimizationFlags())
|
||||
, fRRect(that.fRRect)
|
||||
, fEdgeType(that.fEdgeType) {
|
||||
this->cloneAndRegisterAllChildProcessors(that);
|
||||
}
|
||||
|
||||
std::unique_ptr<GrFragmentProcessor> EllipticalRRectEffect::clone() const {
|
||||
return std::unique_ptr<GrFragmentProcessor>(new EllipticalRRectEffect(fEdgeType, fRRect));
|
||||
return std::unique_ptr<GrFragmentProcessor>(new EllipticalRRectEffect(*this));
|
||||
}
|
||||
|
||||
bool EllipticalRRectEffect::onIsEqual(const GrFragmentProcessor& other) const {
|
||||
@ -545,8 +567,8 @@ void GLEllipticalRRectEffect::emitCode(EmitArgs& args) {
|
||||
// The code below is a simplified version of the above that performs maxs on the vector
|
||||
// components before computing distances and alpha values so that only one distance computation
|
||||
// need be computed to determine the min alpha.
|
||||
fragBuilder->codeAppendf("float2 dxy0 = %s.xy - sk_FragCoord.xy;", rectName);
|
||||
fragBuilder->codeAppendf("float2 dxy1 = sk_FragCoord.xy - %s.zw;", rectName);
|
||||
fragBuilder->codeAppendf("float2 dxy0 = %s.LT - sk_FragCoord.xy;", rectName);
|
||||
fragBuilder->codeAppendf("float2 dxy1 = sk_FragCoord.xy - %s.RB;", rectName);
|
||||
|
||||
// If we're on a device where float != fp32 then we'll do the distance computation in a space
|
||||
// that is normalized by the largest radius. The scale uniform will be scale, 1/scale. The
|
||||
@ -614,7 +636,11 @@ void GLEllipticalRRectEffect::emitCode(EmitArgs& args) {
|
||||
fragBuilder->codeAppend("half alpha = clamp(0.5 + approx_dist, 0.0, 1.0);");
|
||||
}
|
||||
|
||||
fragBuilder->codeAppendf("%s = %s * alpha;", args.fOutputColor, args.fInputColor);
|
||||
SkString inputSample = erre.hasInputFP()
|
||||
? this->invokeChild(/*childIndex=*/0, args.fInputColor, args)
|
||||
: SkString(args.fInputColor);
|
||||
|
||||
fragBuilder->codeAppendf("%s = %s * alpha;", args.fOutputColor, inputSample.c_str());
|
||||
}
|
||||
|
||||
void GLEllipticalRRectEffect::GenKey(const GrProcessor& effect, const GrShaderCaps&,
|
||||
@ -718,7 +744,7 @@ std::unique_ptr<GrFragmentProcessor> GrRRectEffect::Make(GrClipEdgeType edgeType
|
||||
return CircularRRectEffect::Make(/*inputFP=*/nullptr, edgeType,
|
||||
CircularRRectEffect::kAll_CornerFlags, rrect);
|
||||
} else {
|
||||
return EllipticalRRectEffect::Make(edgeType, rrect);
|
||||
return EllipticalRRectEffect::Make(/*inputFP=*/nullptr, edgeType, rrect);
|
||||
}
|
||||
}
|
||||
|
||||
@ -787,7 +813,7 @@ std::unique_ptr<GrFragmentProcessor> GrRRectEffect::Make(GrClipEdgeType edgeType
|
||||
return nullptr;
|
||||
}
|
||||
if (rrect.isNinePatch()) {
|
||||
return EllipticalRRectEffect::Make(edgeType, rrect);
|
||||
return EllipticalRRectEffect::Make(/*inputFP=*/nullptr, edgeType, rrect);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user