Move setSampleMatrix and setSampledWithExplicitCoords into child registration

Bug: skia:10396
Change-Id: I0c117ab4d95737b76dec5bce16103b9058218fb8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/297065
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
Michael Ludwig 2020-06-22 14:46:36 -04:00 committed by Skia Commit-Bot
parent 3cf3d92b56
commit 9aba625ec3
54 changed files with 219 additions and 195 deletions

View File

@ -38,8 +38,7 @@ public:
SampleCoordEffect(std::unique_ptr<GrFragmentProcessor> child) SampleCoordEffect(std::unique_ptr<GrFragmentProcessor> child)
: INHERITED(CLASS_ID, kNone_OptimizationFlags) { : INHERITED(CLASS_ID, kNone_OptimizationFlags) {
child->setSampledWithExplicitCoords(); this->registerExplicitlySampledChild(std::move(child));
this->registerChildProcessor(std::move(child));
} }
const char* name() const override { return "SampleCoordEffect"; } const char* name() const override { return "SampleCoordEffect"; }

View File

@ -21,11 +21,11 @@ public:
SampleMatrixConstantEffect(std::unique_ptr<GrFragmentProcessor> child) SampleMatrixConstantEffect(std::unique_ptr<GrFragmentProcessor> child)
: INHERITED(CLASS_ID, kNone_OptimizationFlags) { : INHERITED(CLASS_ID, kNone_OptimizationFlags) {
child->setSampleMatrix(SkSL::SampleMatrix(SkSL::SampleMatrix::Kind::kConstantOrUniform, this->registerChild(std::move(child),
child.get(), "float3x3(float3(0.5, 0.0, 0.0), " SkSL::SampleMatrix::MakeConstUniform(
"float3x3(float3(0.5, 0.0, 0.0), "
"float3(0.0, 0.5, 0.0), " "float3(0.0, 0.5, 0.0), "
"float3(0.0, 0.0, 1.0))")); "float3(0.0, 0.0, 1.0))"));
this->registerChildProcessor(std::move(child));
} }
const char* name() const override { return "SampleMatrixConstantEffect"; } const char* name() const override { return "SampleMatrixConstantEffect"; }

View File

@ -25,8 +25,7 @@ public:
: INHERITED(CLASS_ID, kNone_OptimizationFlags) : INHERITED(CLASS_ID, kNone_OptimizationFlags)
, fXOffset(xOffset) , fXOffset(xOffset)
, fYOffset(yOffset) { , fYOffset(yOffset) {
child->setSampleMatrix(SkSL::SampleMatrix(SkSL::SampleMatrix::Kind::kVariable)); this->registerChild(std::move(child), SkSL::SampleMatrix::MakeVariable());
this->registerChildProcessor(std::move(child));
} }
const char* name() const override { return "SampleMatrixVariableEffect"; } const char* name() const override { return "SampleMatrixVariableEffect"; }

View File

@ -307,15 +307,12 @@ ColorTableEffect::ColorTableEffect(GrSurfaceProxyView view)
// Not bothering with table-specific optimizations. // Not bothering with table-specific optimizations.
: INHERITED(kColorTableEffect_ClassID, kNone_OptimizationFlags) { : INHERITED(kColorTableEffect_ClassID, kNone_OptimizationFlags) {
auto te = GrTextureEffect::Make(std::move(view), kUnknown_SkAlphaType); auto te = GrTextureEffect::Make(std::move(view), kUnknown_SkAlphaType);
te->setSampledWithExplicitCoords(); this->registerExplicitlySampledChild(std::move(te));
this->registerChildProcessor(std::move(te));
} }
ColorTableEffect::ColorTableEffect(const ColorTableEffect& that) ColorTableEffect::ColorTableEffect(const ColorTableEffect& that)
: INHERITED(kColorTableEffect_ClassID, that.optimizationFlags()) { : INHERITED(kColorTableEffect_ClassID, that.optimizationFlags()) {
auto child = that.childProcessor(0).clone(); this->cloneAndRegisterAllChildProcessors(that);
child->setSampledWithExplicitCoords();
this->registerChildProcessor(std::move(child));
} }
GrGLSLFragmentProcessor* ColorTableEffect::onCreateGLSLInstance() const { GrGLSLFragmentProcessor* ColorTableEffect::onCreateGLSLInstance() const {

View File

@ -508,9 +508,8 @@ GrDisplacementMapEffect::GrDisplacementMapEffect(SkColorChannel xChannelSelector
, fXChannelSelector(xChannelSelector) , fXChannelSelector(xChannelSelector)
, fYChannelSelector(yChannelSelector) , fYChannelSelector(yChannelSelector)
, fScale(scale) { , fScale(scale) {
this->registerChildProcessor(std::move(displacement)); this->registerChild(std::move(displacement));
color->setSampledWithExplicitCoords(); this->registerExplicitlySampledChild(std::move(color));
this->registerChildProcessor(std::move(color));
this->addCoordTransform(&fCoordTransform); this->addCoordTransform(&fCoordTransform);
} }

View File

@ -1632,8 +1632,7 @@ GrLightingEffect::GrLightingEffect(ClassID classID,
child = GrTextureEffect::Make(std::move(view), kPremul_SkAlphaType, SkMatrix::I(), kSampler, child = GrTextureEffect::Make(std::move(view), kPremul_SkAlphaType, SkMatrix::I(), kSampler,
caps); caps);
} }
child->setSampledWithExplicitCoords(); this->registerExplicitlySampledChild(std::move(child));
this->registerChildProcessor(std::move(child));
this->addCoordTransform(&fCoordTransform); this->addCoordTransform(&fCoordTransform);
} }
@ -1643,9 +1642,7 @@ GrLightingEffect::GrLightingEffect(const GrLightingEffect& that)
, fSurfaceScale(that.fSurfaceScale) , fSurfaceScale(that.fSurfaceScale)
, fFilterMatrix(that.fFilterMatrix) , fFilterMatrix(that.fFilterMatrix)
, fBoundaryMode(that.fBoundaryMode) { , fBoundaryMode(that.fBoundaryMode) {
auto child = that.childProcessor(0).clone(); this->cloneAndRegisterAllChildProcessors(that);
child->setSampledWithExplicitCoords();
this->registerChildProcessor(std::move(child));
this->addCoordTransform(&fCoordTransform); this->addCoordTransform(&fCoordTransform);
} }

View File

@ -346,8 +346,7 @@ GrMorphologyEffect::GrMorphologyEffect(GrSurfaceProxyView view,
, fUseRange(SkToBool(range)) { , fUseRange(SkToBool(range)) {
this->addCoordTransform(&fCoordTransform); this->addCoordTransform(&fCoordTransform);
auto te = GrTextureEffect::Make(std::move(view), srcAlphaType); auto te = GrTextureEffect::Make(std::move(view), srcAlphaType);
te->setSampledWithExplicitCoords(); this->registerExplicitlySampledChild(std::move(te));
this->registerChildProcessor(std::move(te));
if (fUseRange) { if (fUseRange) {
fRange[0] = range[0]; fRange[0] = range[0];
fRange[1] = range[1]; fRange[1] = range[1];
@ -361,9 +360,7 @@ GrMorphologyEffect::GrMorphologyEffect(const GrMorphologyEffect& that)
, fType(that.fType) , fType(that.fType)
, fUseRange(that.fUseRange) { , fUseRange(that.fUseRange) {
this->addCoordTransform(&fCoordTransform); this->addCoordTransform(&fCoordTransform);
auto child = that.childProcessor(0).clone(); this->cloneAndRegisterAllChildProcessors(that);
child->setSampledWithExplicitCoords();
this->registerChildProcessor(std::move(child));
if (that.fUseRange) { if (that.fUseRange) {
fRange[0] = that.fRange[0]; fRange[0] = that.fRange[0];
fRange[1] = that.fRange[1]; fRange[1] = that.fRange[1];

View File

@ -97,7 +97,7 @@ GrColorSpaceXformEffect::GrColorSpaceXformEffect(std::unique_ptr<GrFragmentProce
: INHERITED(kGrColorSpaceXformEffect_ClassID, OptFlags(child.get())) : INHERITED(kGrColorSpaceXformEffect_ClassID, OptFlags(child.get()))
, fColorXform(std::move(colorXform)) { , fColorXform(std::move(colorXform)) {
if (child) { if (child) {
this->registerChildProcessor(std::move(child)); this->registerChild(std::move(child));
} }
} }

View File

@ -98,8 +98,8 @@ void GrFragmentProcessor::setSampleMatrix(SkSL::SampleMatrix newMatrix) {
} }
} else { } else {
SkASSERT(newMatrix.fKind == SkSL::SampleMatrix::Kind::kVariable); SkASSERT(newMatrix.fKind == SkSL::SampleMatrix::Kind::kVariable);
fMatrix = SkSL::SampleMatrix(SkSL::SampleMatrix::Kind::kMixed, fMatrix.fOwner, fMatrix.fKind = SkSL::SampleMatrix::Kind::kMixed;
fMatrix.fExpression); fMatrix.fBase = nullptr;
} }
} else { } else {
SkASSERT(fMatrix.fKind == SkSL::SampleMatrix::Kind::kNone); SkASSERT(fMatrix.fKind == SkSL::SampleMatrix::Kind::kNone);
@ -110,6 +110,13 @@ void GrFragmentProcessor::setSampleMatrix(SkSL::SampleMatrix newMatrix) {
} }
} }
void GrFragmentProcessor::setSampledWithExplicitCoords() {
fFlags |= kSampledWithExplicitCoords;
for (auto& child : fChildProcessors) {
child->setSampledWithExplicitCoords();
}
}
#ifdef SK_DEBUG #ifdef SK_DEBUG
bool GrFragmentProcessor::isInstantiated() const { bool GrFragmentProcessor::isInstantiated() const {
for (int i = 0; i < fTextureSamplerCnt; ++i) { for (int i = 0; i < fTextureSamplerCnt; ++i) {
@ -128,7 +135,26 @@ bool GrFragmentProcessor::isInstantiated() const {
} }
#endif #endif
int GrFragmentProcessor::registerChildProcessor(std::unique_ptr<GrFragmentProcessor> child) { int GrFragmentProcessor::registerChild(std::unique_ptr<GrFragmentProcessor> child,
SkSL::SampleMatrix sampleMatrix,
bool explicitlySampled) {
// Configure child's sampling state first
if (explicitlySampled) {
child->setSampledWithExplicitCoords();
}
if (sampleMatrix.fKind != SkSL::SampleMatrix::Kind::kNone) {
// FIXME(michaelludwig) - Temporary hack. Owner tracking will be moved off of SampleMatrix
// and into FP. Currently, coord transform compilation fails on sample_matrix GMs if the
// child isn't the owner. But the matrix effect (and expected behavior) require the owner
// to be 'this' FP.
if (this->classID() == kGrMatrixEffect_ClassID) {
sampleMatrix.fOwner = this;
} else {
sampleMatrix.fOwner = child.get();
}
child->setSampleMatrix(sampleMatrix);
}
if (child->fFlags & kHasCoordTransforms_Flag) { if (child->fFlags & kHasCoordTransforms_Flag) {
fFlags |= kHasCoordTransforms_Flag; fFlags |= kHasCoordTransforms_Flag;
} }
@ -143,10 +169,8 @@ int GrFragmentProcessor::registerChildProcessor(std::unique_ptr<GrFragmentProces
int GrFragmentProcessor::cloneAndRegisterChildProcessor(const GrFragmentProcessor& fp) { int GrFragmentProcessor::cloneAndRegisterChildProcessor(const GrFragmentProcessor& fp) {
std::unique_ptr<GrFragmentProcessor> clone = fp.clone(); std::unique_ptr<GrFragmentProcessor> clone = fp.clone();
if (fp.isSampledWithExplicitCoords()) { return this->registerChild(std::move(clone), fp.sampleMatrix(),
clone->setSampledWithExplicitCoords(); fp.isSampledWithExplicitCoords());
}
return this->registerChildProcessor(std::move(clone));
} }
void GrFragmentProcessor::cloneAndRegisterAllChildProcessors(const GrFragmentProcessor& src) { void GrFragmentProcessor::cloneAndRegisterAllChildProcessors(const GrFragmentProcessor& src) {
@ -213,7 +237,7 @@ std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::SwizzleOutput(
SwizzleFragmentProcessor(std::unique_ptr<GrFragmentProcessor> fp, const GrSwizzle& swizzle) SwizzleFragmentProcessor(std::unique_ptr<GrFragmentProcessor> fp, const GrSwizzle& swizzle)
: INHERITED(kSwizzleFragmentProcessor_ClassID, ProcessorOptimizationFlags(fp.get())) : INHERITED(kSwizzleFragmentProcessor_ClassID, ProcessorOptimizationFlags(fp.get()))
, fSwizzle(swizzle) { , fSwizzle(swizzle) {
this->registerChildProcessor(std::move(fp)); this->registerChild(std::move(fp));
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
@ -279,7 +303,7 @@ std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::MakeInputPremulAndMulB
private: private:
PremulFragmentProcessor(std::unique_ptr<GrFragmentProcessor> processor) PremulFragmentProcessor(std::unique_ptr<GrFragmentProcessor> processor)
: INHERITED(kPremulFragmentProcessor_ClassID, OptFlags(processor.get())) { : INHERITED(kPremulFragmentProcessor_ClassID, OptFlags(processor.get())) {
this->registerChildProcessor(std::move(processor)); this->registerChild(std::move(processor));
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
@ -379,7 +403,7 @@ std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::RunInSeries(
: INHERITED(kSeriesFragmentProcessor_ClassID, OptFlags(children, cnt)) { : INHERITED(kSeriesFragmentProcessor_ClassID, OptFlags(children, cnt)) {
SkASSERT(cnt > 1); SkASSERT(cnt > 1);
for (int i = 0; i < cnt; ++i) { for (int i = 0; i < cnt; ++i) {
this->registerChildProcessor(std::move(children[i])); this->registerChild(std::move(children[i]));
} }
} }

View File

@ -148,19 +148,10 @@ public:
return SkToBool(fFlags & kSampledWithExplicitCoords); return SkToBool(fFlags & kSampledWithExplicitCoords);
} }
void setSampledWithExplicitCoords() {
fFlags |= kSampledWithExplicitCoords;
for (auto& child : fChildProcessors) {
child->setSampledWithExplicitCoords();
}
}
SkSL::SampleMatrix sampleMatrix() const { SkSL::SampleMatrix sampleMatrix() const {
return fMatrix; return fMatrix;
} }
void setSampleMatrix(SkSL::SampleMatrix matrix);
/** /**
* A GrDrawOp may premultiply its antialiasing coverage into its GrGeometryProcessor's color * A GrDrawOp may premultiply its antialiasing coverage into its GrGeometryProcessor's color
* output under the following scenario: * output under the following scenario:
@ -332,6 +323,13 @@ public:
// Sentinel type for range-for using FPItemIter. // Sentinel type for range-for using FPItemIter.
class FPItemEndIter {}; class FPItemEndIter {};
// FIXME This should be private, but SkGr needs to mark the dither effect as sampled explicitly
// even though it's not added to another FP. Once varying generation doesn't add a redundant
// varying for it, this can be fully private.
void temporary_SetExplicitlySampled() {
this->setSampledWithExplicitCoords();
}
protected: protected:
enum OptimizationFlags : uint32_t { enum OptimizationFlags : uint32_t {
kNone_OptimizationFlags, kNone_OptimizationFlags,
@ -424,8 +422,24 @@ protected:
* colors will be combined somehow to produce its output color. Registering these child * colors will be combined somehow to produce its output color. Registering these child
* processors will allow the ProgramBuilder to automatically handle their transformed coords and * processors will allow the ProgramBuilder to automatically handle their transformed coords and
* texture accesses and mangle their uniform and output color names. * texture accesses and mangle their uniform and output color names.
*
* Depending on the 2nd and 3rd parameters, this corresponds to the following SkSL sample calls:
* - sample(child): Keep default arguments
* - sample(child, matrix): Provide approprate SampleMatrix matching SkSL
* - sample(child, float2): SampleMatrix() and 'true', or use 'registerExplicitlySampledChild'
* - sample(child, matrix)+sample(child, float2): Appropriate SampleMatrix and 'true'
*/ */
int registerChildProcessor(std::unique_ptr<GrFragmentProcessor> child); int registerChild(std::unique_ptr<GrFragmentProcessor> child,
SkSL::SampleMatrix sampleMatrix = SkSL::SampleMatrix(),
bool explicitlySampled = false);
/**
* A helper for use when the child is only invoked with sample(float2), and not sample()
* or sample(matrix).
*/
int registerExplicitlySampledChild(std::unique_ptr<GrFragmentProcessor> child) {
return this->registerChild(std::move(child), SkSL::SampleMatrix(), true);
}
/** /**
* This method takes an existing fragment processor, clones it, registers it as a child of this * This method takes an existing fragment processor, clones it, registers it as a child of this
@ -484,6 +498,10 @@ private:
bool hasSameTransforms(const GrFragmentProcessor&) const; bool hasSameTransforms(const GrFragmentProcessor&) const;
void setSampledWithExplicitCoords();
void setSampleMatrix(SkSL::SampleMatrix matrix);
enum PrivateFlags { enum PrivateFlags {
kFirstPrivateFlag = kAll_OptimizationFlags + 1, kFirstPrivateFlag = kAll_OptimizationFlags + 1,
kHasCoordTransforms_Flag = kFirstPrivateFlag, kHasCoordTransforms_Flag = kFirstPrivateFlag,

View File

@ -387,7 +387,7 @@ static inline bool skpaint_to_grpaint_impl(GrRecordingContext* context,
if (ditherFP) { if (ditherFP) {
// The dither shader doesn't actually use input coordinates, but if we don't set // The dither shader doesn't actually use input coordinates, but if we don't set
// this flag, the generated shader includes an extra local coord varying. // this flag, the generated shader includes an extra local coord varying.
ditherFP->setSampledWithExplicitCoords(); ditherFP->temporary_SetExplicitlySampled();
grPaint->addColorFragmentProcessor(std::move(ditherFP)); grPaint->addColorFragmentProcessor(std::move(ditherFP));
} }
} }

View File

@ -30,11 +30,10 @@ GrCCClipProcessor::GrCCClipProcessor(std::unique_ptr<GrFragmentProcessor> inputF
, fMustCheckBounds(MustCheckBounds::kYes == mustCheckBounds) { , fMustCheckBounds(MustCheckBounds::kYes == mustCheckBounds) {
auto view = make_view(caps, clipPath->atlasLazyProxy(), fIsCoverageCount); auto view = make_view(caps, clipPath->atlasLazyProxy(), fIsCoverageCount);
auto texEffect = GrTextureEffect::Make(std::move(view), kUnknown_SkAlphaType); auto texEffect = GrTextureEffect::Make(std::move(view), kUnknown_SkAlphaType);
texEffect->setSampledWithExplicitCoords(); this->registerExplicitlySampledChild(std::move(texEffect));
this->registerChildProcessor(std::move(texEffect));
if (inputFP != nullptr) { if (inputFP != nullptr) {
this->registerChildProcessor(std::move(inputFP)); this->registerChild(std::move(inputFP));
} }
} }

View File

@ -176,9 +176,8 @@ GrBicubicEffect::GrBicubicEffect(std::unique_ptr<GrFragmentProcessor> fp,
, fCoordTransform(matrix) , fCoordTransform(matrix)
, fDirection(direction) , fDirection(direction)
, fClamp(clamp) { , fClamp(clamp) {
fp->setSampledWithExplicitCoords();
this->addCoordTransform(&fCoordTransform); this->addCoordTransform(&fCoordTransform);
this->registerChildProcessor(std::move(fp)); this->registerExplicitlySampledChild(std::move(fp));
} }
GrBicubicEffect::GrBicubicEffect(const GrBicubicEffect& that) GrBicubicEffect::GrBicubicEffect(const GrBicubicEffect& that)
@ -187,9 +186,7 @@ GrBicubicEffect::GrBicubicEffect(const GrBicubicEffect& that)
, fDirection(that.fDirection) , fDirection(that.fDirection)
, fClamp(that.fClamp) { , fClamp(that.fClamp) {
this->addCoordTransform(&fCoordTransform); this->addCoordTransform(&fCoordTransform);
auto child = that.childProcessor(0).clone(); this->cloneAndRegisterAllChildProcessors(that);
child->setSampledWithExplicitCoords();
this->registerChildProcessor(std::move(child));
} }
void GrBicubicEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, void GrBicubicEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,

View File

@ -200,7 +200,7 @@ GrConvexPolyEffect::GrConvexPolyEffect(std::unique_ptr<GrFragmentProcessor> inpu
} }
if (inputFP != nullptr) { if (inputFP != nullptr) {
this->registerChildProcessor(std::move(inputFP)); this->registerChild(std::move(inputFP));
} }
} }

View File

@ -171,8 +171,7 @@ GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor(
ProcessorOptimizationFlags(child.get())) ProcessorOptimizationFlags(child.get()))
, fRadius(radius) , fRadius(radius)
, fDirection(direction) { , fDirection(direction) {
child->setSampledWithExplicitCoords(); this->registerExplicitlySampledChild(std::move(child));
this->registerChildProcessor(std::move(child));
SkASSERT(radius <= kMaxKernelRadius); SkASSERT(radius <= kMaxKernelRadius);
fill_in_1D_gaussian_kernel(fKernel, gaussianSigma, fRadius); fill_in_1D_gaussian_kernel(fKernel, gaussianSigma, fRadius);
this->addCoordTransform(&fCoordTransform); this->addCoordTransform(&fCoordTransform);
@ -183,9 +182,7 @@ GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor(
: INHERITED(kGrGaussianConvolutionFragmentProcessor_ClassID, that.optimizationFlags()) : INHERITED(kGrGaussianConvolutionFragmentProcessor_ClassID, that.optimizationFlags())
, fRadius(that.fRadius) , fRadius(that.fRadius)
, fDirection(that.fDirection) { , fDirection(that.fDirection) {
auto child = that.childProcessor(0).clone(); this->cloneAndRegisterAllChildProcessors(that);
child->setSampledWithExplicitCoords();
this->registerChildProcessor(std::move(child));
memcpy(fKernel, that.fKernel, radius_to_width(fRadius) * sizeof(float)); memcpy(fKernel, that.fKernel, radius_to_width(fRadius) * sizeof(float));
this->addCoordTransform(&fCoordTransform); this->addCoordTransform(&fCoordTransform);
} }

View File

@ -294,11 +294,9 @@ GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(std::unique_ptr<GrFragmentP
, fGain(SkScalarToFloat(gain)) , fGain(SkScalarToFloat(gain))
, fBias(SkScalarToFloat(bias) / 255.0f) , fBias(SkScalarToFloat(bias) / 255.0f)
, fConvolveAlpha(convolveAlpha) { , fConvolveAlpha(convolveAlpha) {
child->setSampledWithExplicitCoords(); this->registerExplicitlySampledChild(std::move(child));
this->registerChildProcessor(std::move(child));
if (kernelFP) { if (kernelFP) {
kernelFP->setSampledWithExplicitCoords(); this->registerExplicitlySampledChild(std::move(kernelFP));
this->registerChildProcessor(std::move(kernelFP));
} }
fKernelOffset = {static_cast<float>(kernelOffset.x()), fKernelOffset = {static_cast<float>(kernelOffset.x()),
static_cast<float>(kernelOffset.y())}; static_cast<float>(kernelOffset.y())};
@ -312,14 +310,7 @@ GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(const GrMatrixConvolutionEf
, fBias(that.fBias) , fBias(that.fBias)
, fKernelOffset(that.fKernelOffset) , fKernelOffset(that.fKernelOffset)
, fConvolveAlpha(that.fConvolveAlpha) { , fConvolveAlpha(that.fConvolveAlpha) {
auto child = that.childProcessor(0).clone(); this->cloneAndRegisterAllChildProcessors(that);
child->setSampledWithExplicitCoords();
this->registerChildProcessor(std::move(child));
if (fKernel.isSampled()) {
child = that.childProcessor(1).clone();
child->setSampledWithExplicitCoords();
this->registerChildProcessor(std::move(child));
}
this->addCoordTransform(&fCoordTransform); this->addCoordTransform(&fCoordTransform);
} }

View File

@ -38,9 +38,7 @@ private:
: INHERITED(kGrMatrixEffect_ClassID, kNone_OptimizationFlags) : INHERITED(kGrMatrixEffect_ClassID, kNone_OptimizationFlags)
, fMatrix(matrix) { , fMatrix(matrix) {
SkASSERT(child); SkASSERT(child);
child->setSampleMatrix( this->registerChild(std::move(child), SkSL::SampleMatrix::MakeConstUniform("matrix"));
SkSL::SampleMatrix(SkSL::SampleMatrix::Kind::kConstantOrUniform, this, "matrix"));
this->registerChildProcessor(std::move(child));
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;

View File

@ -106,7 +106,7 @@ CircularRRectEffect::CircularRRectEffect(std::unique_ptr<GrFragmentProcessor> in
, fEdgeType(edgeType) , fEdgeType(edgeType)
, fCircularCornerFlags(circularCornerFlags) { , fCircularCornerFlags(circularCornerFlags) {
if (inputFP != nullptr) { if (inputFP != nullptr) {
this->registerChildProcessor(std::move(inputFP)); this->registerChild(std::move(inputFP));
} }
} }
@ -465,7 +465,7 @@ EllipticalRRectEffect::EllipticalRRectEffect(std::unique_ptr<GrFragmentProcessor
, fRRect(rrect) , fRRect(rrect)
, fEdgeType(edgeType) { , fEdgeType(edgeType) {
if (inputFP != nullptr) { if (inputFP != nullptr) {
this->registerChildProcessor(std::move(inputFP)); this->registerChild(std::move(inputFP));
} }
} }

View File

@ -198,8 +198,7 @@ const char* GrSkSLFP::name() const {
} }
void GrSkSLFP::addChild(std::unique_ptr<GrFragmentProcessor> child) { void GrSkSLFP::addChild(std::unique_ptr<GrFragmentProcessor> child) {
child->setSampledWithExplicitCoords(); this->registerExplicitlySampledChild(std::move(child));
this->registerChildProcessor(std::move(child));
} }
GrGLSLFragmentProcessor* GrSkSLFP::onCreateGLSLInstance() const { GrGLSLFragmentProcessor* GrSkSLFP::onCreateGLSLInstance() const {

View File

@ -62,8 +62,8 @@ private:
SkBlendMode mode) SkBlendMode mode)
: INHERITED(kComposeTwoFragmentProcessor_ClassID, OptFlags(src.get(), dst.get(), mode)) : INHERITED(kComposeTwoFragmentProcessor_ClassID, OptFlags(src.get(), dst.get(), mode))
, fMode(mode) { , fMode(mode) {
SkDEBUGCODE(int shaderAChildIndex = )this->registerChildProcessor(std::move(src)); SkDEBUGCODE(int shaderAChildIndex = )this->registerChild(std::move(src));
SkDEBUGCODE(int shaderBChildIndex = )this->registerChildProcessor(std::move(dst)); SkDEBUGCODE(int shaderBChildIndex = )this->registerChild(std::move(dst));
SkASSERT(0 == shaderAChildIndex); SkASSERT(0 == shaderAChildIndex);
SkASSERT(1 == shaderBChildIndex); SkASSERT(1 == shaderBChildIndex);
} }
@ -413,7 +413,7 @@ private:
: INHERITED(kComposeOneFragmentProcessor_ClassID, OptFlags(fp.get(), mode, child)) : INHERITED(kComposeOneFragmentProcessor_ClassID, OptFlags(fp.get(), mode, child))
, fMode(mode) , fMode(mode)
, fChild(child) { , fChild(child) {
SkDEBUGCODE(int dstIndex =) this->registerChildProcessor(std::move(fp)); SkDEBUGCODE(int dstIndex =) this->registerChild(std::move(fp));
SkASSERT(0 == dstIndex); SkASSERT(0 == dstIndex);
} }

View File

@ -112,7 +112,7 @@ GrYUVtoRGBEffect::GrYUVtoRGBEffect(std::unique_ptr<GrFragmentProcessor> planeFPs
ModulateForClampedSamplerOptFlags(alpha_type(yuvaIndices))) ModulateForClampedSamplerOptFlags(alpha_type(yuvaIndices)))
, fYUVColorSpace(yuvColorSpace) { , fYUVColorSpace(yuvColorSpace) {
for (int i = 0; i < numPlanes; ++i) { for (int i = 0; i < numPlanes; ++i) {
this->registerChildProcessor(std::move(planeFPs[i])); this->registerChild(std::move(planeFPs[i]));
} }
std::copy_n(yuvaIndices, 4, fYUVAIndices); std::copy_n(yuvaIndices, 4, fYUVAIndices);
} }
@ -251,10 +251,7 @@ bool GrYUVtoRGBEffect::onIsEqual(const GrFragmentProcessor& other) const {
GrYUVtoRGBEffect::GrYUVtoRGBEffect(const GrYUVtoRGBEffect& src) GrYUVtoRGBEffect::GrYUVtoRGBEffect(const GrYUVtoRGBEffect& src)
: GrFragmentProcessor(kGrYUVtoRGBEffect_ClassID, src.optimizationFlags()) : GrFragmentProcessor(kGrYUVtoRGBEffect_ClassID, src.optimizationFlags())
, fYUVColorSpace(src.fYUVColorSpace) { , fYUVColorSpace(src.fYUVColorSpace) {
int numPlanes = src.numChildProcessors(); this->cloneAndRegisterAllChildProcessors(src);
for (int i = 0; i < numPlanes; ++i) {
this->registerChildProcessor(this->childProcessor(i).clone());
}
std::copy_n(src.fYUVAIndices, this->numChildProcessors(), fYUVAIndices); std::copy_n(src.fYUVAIndices, this->numChildProcessors(), fYUVAIndices);
} }

View File

@ -43,7 +43,7 @@ private:
, edgeType(edgeType) , edgeType(edgeType)
, rect(rect) { , rect(rect) {
if (inputFP) { if (inputFP) {
inputFP_index = this->registerChildProcessor(std::move(inputFP)); inputFP_index = this->registerChild(std::move(inputFP));
} }
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;

View File

@ -47,10 +47,10 @@ private:
, innerThreshold(innerThreshold) , innerThreshold(innerThreshold)
, outerThreshold(outerThreshold) { , outerThreshold(outerThreshold) {
if (inputFP) { if (inputFP) {
inputFP_index = this->registerChildProcessor(std::move(inputFP)); inputFP_index = this->registerChild(std::move(inputFP));
} }
SkASSERT(maskFP); SkASSERT(maskFP);
maskFP_index = this->registerChildProcessor(std::move(maskFP)); maskFP_index = this->registerChild(std::move(maskFP));
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;

View File

@ -36,7 +36,7 @@ private:
: INHERITED(kGrBlurredEdgeFragmentProcessor_ClassID, kNone_OptimizationFlags) : INHERITED(kGrBlurredEdgeFragmentProcessor_ClassID, kNone_OptimizationFlags)
, mode(mode) { , mode(mode) {
if (inputFP) { if (inputFP) {
inputFP_index = this->registerChildProcessor(std::move(inputFP)); inputFP_index = this->registerChild(std::move(inputFP));
} }
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;

View File

@ -48,11 +48,10 @@ private:
, solidRadius(solidRadius) , solidRadius(solidRadius)
, textureRadius(textureRadius) { , textureRadius(textureRadius) {
if (inputFP) { if (inputFP) {
inputFP_index = this->registerChildProcessor(std::move(inputFP)); inputFP_index = this->registerChild(std::move(inputFP));
} }
SkASSERT(blurProfile); SkASSERT(blurProfile);
blurProfile->setSampledWithExplicitCoords(); blurProfile_index = this->registerExplicitlySampledChild(std::move(blurProfile));
blurProfile_index = this->registerChildProcessor(std::move(blurProfile));
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;

View File

@ -52,7 +52,7 @@ private:
, center(center) , center(center)
, radius(radius) { , radius(radius) {
if (inputFP) { if (inputFP) {
inputFP_index = this->registerChildProcessor(std::move(inputFP)); inputFP_index = this->registerChild(std::move(inputFP));
} }
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;

View File

@ -48,7 +48,7 @@ private:
kPreservesOpaqueInput_OptimizationFlag)) kPreservesOpaqueInput_OptimizationFlag))
, clampToPremul(clampToPremul) { , clampToPremul(clampToPremul) {
if (inputFP) { if (inputFP) {
inputFP_index = this->registerChildProcessor(std::move(inputFP)); inputFP_index = this->registerChild(std::move(inputFP));
} }
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;

View File

@ -86,7 +86,7 @@ private:
, clampRGBOutput(clampRGBOutput) , clampRGBOutput(clampRGBOutput)
, premulOutput(premulOutput) { , premulOutput(premulOutput) {
if (inputFP) { if (inputFP) {
inputFP_index = this->registerChildProcessor(std::move(inputFP)); inputFP_index = this->registerChild(std::move(inputFP));
} }
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;

View File

@ -38,10 +38,10 @@ private:
float weight) float weight)
: INHERITED(kGrComposeLerpEffect_ClassID, kNone_OptimizationFlags), weight(weight) { : INHERITED(kGrComposeLerpEffect_ClassID, kNone_OptimizationFlags), weight(weight) {
if (child1) { if (child1) {
child1_index = this->registerChildProcessor(std::move(child1)); child1_index = this->registerChild(std::move(child1));
} }
if (child2) { if (child2) {
child2_index = this->registerChildProcessor(std::move(child2)); child2_index = this->registerChild(std::move(child2));
} }
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;

View File

@ -74,7 +74,7 @@ private:
, color(color) , color(color)
, mode(mode) { , mode(mode) {
if (inputFP) { if (inputFP) {
inputFP_index = this->registerChildProcessor(std::move(inputFP)); inputFP_index = this->registerChild(std::move(inputFP));
} }
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;

View File

@ -33,8 +33,7 @@ private:
GrDeviceSpaceEffect(std::unique_ptr<GrFragmentProcessor> fp, SkMatrix matrix) GrDeviceSpaceEffect(std::unique_ptr<GrFragmentProcessor> fp, SkMatrix matrix)
: INHERITED(kGrDeviceSpaceEffect_ClassID, kNone_OptimizationFlags), matrix(matrix) { : INHERITED(kGrDeviceSpaceEffect_ClassID, kNone_OptimizationFlags), matrix(matrix) {
SkASSERT(fp); SkASSERT(fp);
fp->setSampledWithExplicitCoords(); fp_index = this->registerExplicitlySampledChild(std::move(fp));
fp_index = this->registerChildProcessor(std::move(fp));
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;

View File

@ -62,7 +62,7 @@ private:
, center(center) , center(center)
, radii(radii) { , radii(radii) {
if (inputFP) { if (inputFP) {
inputFP_index = this->registerChildProcessor(std::move(inputFP)); inputFP_index = this->registerChild(std::move(inputFP));
} }
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;

View File

@ -51,7 +51,7 @@ private:
(kConstantOutputForConstantInput_OptimizationFlag | (kConstantOutputForConstantInput_OptimizationFlag |
kPreservesOpaqueInput_OptimizationFlag)) { kPreservesOpaqueInput_OptimizationFlag)) {
if (inputFP) { if (inputFP) {
inputFP_index = this->registerChildProcessor(std::move(inputFP)); inputFP_index = this->registerChild(std::move(inputFP));
} }
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;

View File

@ -46,7 +46,7 @@ private:
: kAll_OptimizationFlags) & : kAll_OptimizationFlags) &
kConstantOutputForConstantInput_OptimizationFlag) { kConstantOutputForConstantInput_OptimizationFlag) {
if (inputFP) { if (inputFP) {
inputFP_index = this->registerChildProcessor(std::move(inputFP)); inputFP_index = this->registerChild(std::move(inputFP));
} }
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;

View File

@ -58,8 +58,7 @@ private:
, xInvInset(xInvInset) , xInvInset(xInvInset)
, yInvInset(yInvInset) { , yInvInset(yInvInset) {
SkASSERT(src); SkASSERT(src);
src->setSampledWithExplicitCoords(); src_index = this->registerExplicitlySampledChild(std::move(src));
src_index = this->registerChildProcessor(std::move(src));
this->addCoordTransform(&fCoordTransform0); this->addCoordTransform(&fCoordTransform0);
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;

View File

@ -56,9 +56,9 @@ private:
: INHERITED(kGrMixerEffect_ClassID, (OptimizationFlags)OptFlags(fp0, fp1)) : INHERITED(kGrMixerEffect_ClassID, (OptimizationFlags)OptFlags(fp0, fp1))
, weight(weight) { , weight(weight) {
SkASSERT(fp0); SkASSERT(fp0);
fp0_index = this->registerChildProcessor(std::move(fp0)); fp0_index = this->registerChild(std::move(fp0));
if (fp1) { if (fp1) {
fp1_index = this->registerChildProcessor(std::move(fp1)); fp1_index = this->registerChild(std::move(fp1));
} }
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;

View File

@ -61,7 +61,7 @@ private:
, uniformColor(uniformColor) , uniformColor(uniformColor)
, literalColor(literalColor) { , literalColor(literalColor) {
SkASSERT(fp); SkASSERT(fp);
fp_index = this->registerChildProcessor(std::move(fp)); fp_index = this->registerChild(std::move(fp));
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;

View File

@ -53,7 +53,7 @@ private:
(kConstantOutputForConstantInput_OptimizationFlag | (kConstantOutputForConstantInput_OptimizationFlag |
kPreservesOpaqueInput_OptimizationFlag)) { kPreservesOpaqueInput_OptimizationFlag)) {
if (inputFP) { if (inputFP) {
inputFP_index = this->registerChildProcessor(std::move(inputFP)); inputFP_index = this->registerChild(std::move(inputFP));
} }
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;

View File

@ -139,11 +139,10 @@ private:
, rect(rect) , rect(rect)
, cornerRadius(cornerRadius) { , cornerRadius(cornerRadius) {
if (inputFP) { if (inputFP) {
inputFP_index = this->registerChildProcessor(std::move(inputFP)); inputFP_index = this->registerChild(std::move(inputFP));
} }
SkASSERT(ninePatchFP); SkASSERT(ninePatchFP);
ninePatchFP->setSampledWithExplicitCoords(); ninePatchFP_index = this->registerExplicitlySampledChild(std::move(ninePatchFP));
ninePatchFP_index = this->registerChildProcessor(std::move(ninePatchFP));
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;

View File

@ -145,11 +145,10 @@ private:
, rect(rect) , rect(rect)
, isFast(isFast) { , isFast(isFast) {
if (inputFP) { if (inputFP) {
inputFP_index = this->registerChildProcessor(std::move(inputFP)); inputFP_index = this->registerChild(std::move(inputFP));
} }
SkASSERT(integral); SkASSERT(integral);
integral->setSampledWithExplicitCoords(); integral_index = this->registerExplicitlySampledChild(std::move(integral));
integral_index = this->registerChildProcessor(std::move(integral));
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;

View File

@ -166,7 +166,9 @@ void GrGLSLGeometryProcessor::emitTransformCode(GrGLSLVertexBuilder* vb,
localCoords = tr.fLocalCoords.c_str(); localCoords = tr.fLocalCoords.c_str();
} }
vb->codeAppend("{\n"); vb->codeAppend("{\n");
if (tr.fFP->sampleMatrix().fOwner) {
uniformHandler->writeUniformMappings(tr.fFP->sampleMatrix().fOwner, vb); uniformHandler->writeUniformMappings(tr.fFP->sampleMatrix().fOwner, vb);
}
if (tr.fType == kFloat2_GrSLType) { if (tr.fType == kFloat2_GrSLType) {
vb->codeAppendf("%s = (%s * %s * %s).xy", tr.fName, vb->codeAppendf("%s = (%s * %s * %s).xy", tr.fName,
tr.fFP->sampleMatrix().fExpression.c_str(), tr.fMatrix.c_str(), tr.fFP->sampleMatrix().fExpression.c_str(), tr.fMatrix.c_str(),

View File

@ -57,9 +57,9 @@ private:
, makePremul(makePremul) , makePremul(makePremul)
, colorsAreOpaque(colorsAreOpaque) { , colorsAreOpaque(colorsAreOpaque) {
SkASSERT(colorizer); SkASSERT(colorizer);
colorizer_index = this->registerChildProcessor(std::move(colorizer)); colorizer_index = this->registerChild(std::move(colorizer));
SkASSERT(gradLayout); SkASSERT(gradLayout);
gradLayout_index = this->registerChildProcessor(std::move(gradLayout)); gradLayout_index = this->registerChild(std::move(gradLayout));
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;

View File

@ -33,8 +33,7 @@ private:
GrTextureGradientColorizer(std::unique_ptr<GrFragmentProcessor> textureFP) GrTextureGradientColorizer(std::unique_ptr<GrFragmentProcessor> textureFP)
: INHERITED(kGrTextureGradientColorizer_ClassID, kNone_OptimizationFlags) { : INHERITED(kGrTextureGradientColorizer_ClassID, kNone_OptimizationFlags) {
SkASSERT(textureFP); SkASSERT(textureFP);
textureFP->setSampledWithExplicitCoords(); textureFP_index = this->registerExplicitlySampledChild(std::move(textureFP));
textureFP_index = this->registerChildProcessor(std::move(textureFP));
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;

View File

@ -52,9 +52,9 @@ private:
, makePremul(makePremul) , makePremul(makePremul)
, colorsAreOpaque(colorsAreOpaque) { , colorsAreOpaque(colorsAreOpaque) {
SkASSERT(colorizer); SkASSERT(colorizer);
colorizer_index = this->registerChildProcessor(std::move(colorizer)); colorizer_index = this->registerChild(std::move(colorizer));
SkASSERT(gradLayout); SkASSERT(gradLayout);
gradLayout_index = this->registerChildProcessor(std::move(gradLayout)); gradLayout_index = this->registerChild(std::move(gradLayout));
} }
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;

View File

@ -785,10 +785,8 @@ private:
, fNumOctaves(numOctaves) , fNumOctaves(numOctaves)
, fStitchTiles(stitchTiles) , fStitchTiles(stitchTiles)
, fPaintingData(std::move(paintingData)) { , fPaintingData(std::move(paintingData)) {
permutationsFP->setSampledWithExplicitCoords(); this->registerExplicitlySampledChild(std::move(permutationsFP));
this->registerChildProcessor(std::move(permutationsFP)); this->registerExplicitlySampledChild(std::move(noiseFP));
noiseFP->setSampledWithExplicitCoords();
this->registerChildProcessor(std::move(noiseFP));
fCoordTransform = GrCoordTransform(matrix); fCoordTransform = GrCoordTransform(matrix);
this->addCoordTransform(&fCoordTransform); this->addCoordTransform(&fCoordTransform);
} }
@ -1154,10 +1152,8 @@ private:
, fOctaves(octaves) , fOctaves(octaves)
, fZ(z) , fZ(z)
, fPaintingData(std::move(paintingData)) { , fPaintingData(std::move(paintingData)) {
permutationsFP->setSampledWithExplicitCoords(); this->registerExplicitlySampledChild(std::move(permutationsFP));
this->registerChildProcessor(std::move(permutationsFP)); this->registerExplicitlySampledChild(std::move(gradientFP));
gradientFP->setSampledWithExplicitCoords();
this->registerChildProcessor(std::move(gradientFP));
fCoordTransform = GrCoordTransform(matrix); fCoordTransform = GrCoordTransform(matrix);
this->addCoordTransform(&fCoordTransform); this->addCoordTransform(&fCoordTransform);
} }

View File

@ -122,13 +122,17 @@ void CPPCodeGenerator::writeIndexExpression(const IndexExpression& i) {
return; return;
} }
int64_t index = ((IntLiteral&) *i.fIndex).fValue; int64_t index = ((IntLiteral&) *i.fIndex).fValue;
if (index != 0) {
fErrors.error(i.fIndex->fOffset, "Only sk_TransformedCoords2D[0] is allowed");
return;
}
String name = "sk_TransformedCoords2D_" + to_string(index); String name = "sk_TransformedCoords2D_" + to_string(index);
fFormatArgs.push_back(name + ".c_str()"); fFormatArgs.push_back(name + ".c_str()");
if (fWrittenTransformedCoords.find(index) == fWrittenTransformedCoords.end()) { if (!fAccessLocalCoordsDirectly) {
fAccessLocalCoordsDirectly = true;
addExtraEmitCodeLine("SkString " + name + addExtraEmitCodeLine("SkString " + name +
" = fragBuilder->ensureCoords2D(args.fTransformedCoords[" + " = fragBuilder->ensureCoords2D(args.fTransformedCoords[" +
to_string(index) + "].fVaryingPoint, _outer.sampleMatrix());"); to_string(index) + "].fVaryingPoint, _outer.sampleMatrix());");
fWrittenTransformedCoords.insert(index);
} }
return; return;
} else if (SK_TEXTURESAMPLERS_BUILTIN == builtin) { } else if (SK_TEXTURESAMPLERS_BUILTIN == builtin) {

View File

@ -123,7 +123,9 @@ private:
std::vector<String> fExtraEmitCodeBlocks; std::vector<String> fExtraEmitCodeBlocks;
std::vector<String> fFormatArgs; std::vector<String> fFormatArgs;
std::set<int> fWrittenTransformedCoords; // true if the sksl referenced sk_TransformedCoords[0]
bool fAccessLocalCoordsDirectly = false;
// if true, we are writing a C++ expression instead of a GLSL expression // if true, we are writing a C++ expression instead of a GLSL expression
bool fCPPMode = false; bool fCPPMode = false;
bool fInMain = false; bool fInMain = false;

View File

@ -282,35 +282,45 @@ void HCodeGenerator::writeConstructor() {
} else { } else {
this->writef(" SkASSERT(%s);", String(param->fName).c_str()); this->writef(" SkASSERT(%s);", String(param->fName).c_str());
} }
if (fSectionAndParameterHelper.hasCoordOverrides(*param)) {
this->writef(" %s->setSampledWithExplicitCoords();", bool explicitCoords = fSectionAndParameterHelper.hasCoordOverrides(*param);
String(param->fName).c_str());
}
SampleMatrix matrix = SampleMatrix::Make(fProgram, *param); SampleMatrix matrix = SampleMatrix::Make(fProgram, *param);
switch (matrix.fKind) {
String registerFunc;
String matrixArg;
String explicitArg;
if (explicitCoords && matrix.fKind == SampleMatrix::Kind::kNone) {
registerFunc = "registerExplicitlySampledChild";
} else {
registerFunc = "registerChild";
if (explicitCoords) {
explicitArg = ", true";
}
switch(matrix.fKind) {
case SampleMatrix::Kind::kVariable: case SampleMatrix::Kind::kVariable:
this->writef(" %s->setSampleMatrix(SkSL::SampleMatrix(" matrixArg.appendf(", SkSL::SampleMatrix::MakeVariable()");
"SkSL::SampleMatrix::Kind::kVariable));",
String(param->fName).c_str());
break; break;
case SampleMatrix::Kind::kConstantOrUniform: case SampleMatrix::Kind::kConstantOrUniform:
this->writef(" %s->setSampleMatrix(SkSL::SampleMatrix(" matrixArg.appendf(", SkSL::SampleMatrix::MakeConstUniform(\"%s\")",
"SkSL::SampleMatrix::Kind::kConstantOrUniform, this, \"%s\"));",
String(param->fName).c_str(),
matrix.fExpression.c_str()); matrix.fExpression.c_str());
break; break;
case SampleMatrix::Kind::kMixed: case SampleMatrix::Kind::kMixed:
this->writef(" %s->setSampleMatrix(SkSL::SampleMatrix(" // Mixed is only produced when combining FPs, not from analysis of sksl
"SkSL::SampleMatrix::Kind::kMixed, this, \"%s\"));", SkASSERT(false);
String(param->fName).c_str(),
matrix.fExpression.c_str());
break; break;
case SampleMatrix::Kind::kNone: case SampleMatrix::Kind::kNone:
break; break;
} }
this->writef(" %s_index = this->registerChildProcessor(std::move(%s));", }
this->writef(" %s_index = this->%s(std::move(%s)%s%s);",
FieldName(String(param->fName).c_str()).c_str(), FieldName(String(param->fName).c_str()).c_str(),
String(param->fName).c_str()); registerFunc.c_str(),
String(param->fName).c_str(),
matrixArg.c_str(),
explicitArg.c_str());
if (param->fType.kind() == Type::kNullable_Kind) { if (param->fType.kind() == Type::kNullable_Kind) {
this->writef(" }"); this->writef(" }");
} }

View File

@ -32,7 +32,7 @@ namespace SkSL {
SampleMatrix SampleMatrix::merge(const SampleMatrix& other) { SampleMatrix SampleMatrix::merge(const SampleMatrix& other) {
if (fKind == Kind::kVariable || other.fKind == Kind::kVariable) { if (fKind == Kind::kVariable || other.fKind == Kind::kVariable) {
*this = SampleMatrix(Kind::kVariable); *this = SampleMatrix::MakeVariable();
return *this; return *this;
} }
if (other.fKind == Kind::kConstantOrUniform) { if (other.fKind == Kind::kConstantOrUniform) {
@ -40,7 +40,7 @@ SampleMatrix SampleMatrix::merge(const SampleMatrix& other) {
if (fExpression == other.fExpression) { if (fExpression == other.fExpression) {
return *this; return *this;
} }
*this = SampleMatrix(Kind::kVariable); *this = SampleMatrix::MakeVariable();
return *this; return *this;
} }
SkASSERT(fKind == Kind::kNone); SkASSERT(fKind == Kind::kNone);
@ -94,10 +94,9 @@ SampleMatrix SampleMatrixExtractor::getMatrix(const Expression& e) const {
fc.fArguments[0]->fKind == Expression::kVariableReference_Kind && fc.fArguments[0]->fKind == Expression::kVariableReference_Kind &&
&((VariableReference&) *fc.fArguments[0]).fVariable == &fFP) { &((VariableReference&) *fc.fArguments[0]).fVariable == &fFP) {
if (fc.fArguments.back()->isConstantOrUniform()) { if (fc.fArguments.back()->isConstantOrUniform()) {
return SampleMatrix(SampleMatrix::Kind::kConstantOrUniform, nullptr, return SampleMatrix::MakeConstUniform(fc.fArguments.back()->description());
fc.fArguments.back()->description());
} else { } else {
return SampleMatrix(SampleMatrix::Kind::kVariable); return SampleMatrix::MakeVariable();
} }
} }
SampleMatrix result; SampleMatrix result;

View File

@ -27,7 +27,8 @@ struct SampleMatrix {
// No sample(child, matrix) call affects the FP. // No sample(child, matrix) call affects the FP.
kNone, kNone,
// The FP is sampled with a matrix whose value is fixed and based only on constants or // The FP is sampled with a matrix whose value is fixed and based only on constants or
// uniforms, and thus the transform can be hoisted to the vertex shader. // uniforms, and thus the transform can be hoisted to the vertex shader (assuming that
// its parent can also be hoisted, i.e. not sampled explicitly).
kConstantOrUniform, kConstantOrUniform,
// The FP is sampled with a non-constant/uniform value, or sampled multiple times, and // The FP is sampled with a non-constant/uniform value, or sampled multiple times, and
// thus the transform cannot be hoisted to the vertex shader. // thus the transform cannot be hoisted to the vertex shader.
@ -38,20 +39,18 @@ struct SampleMatrix {
kMixed, kMixed,
}; };
// Make a SampleMatrix with kNone for its kind. Will not have an expression or have perspective.
SampleMatrix() SampleMatrix()
: fOwner(nullptr) : fOwner(nullptr)
, fKind(Kind::kNone) {} , fKind(Kind::kNone) {}
SampleMatrix(Kind kind) static SampleMatrix MakeConstUniform(String expression) {
: fOwner(nullptr) return SampleMatrix(Kind::kConstantOrUniform, expression);
, fKind(kind) {
SkASSERT(kind == Kind::kNone || kind == Kind::kVariable);
} }
SampleMatrix(Kind kind, GrFragmentProcessor* owner, String expression) static SampleMatrix MakeVariable() {
: fOwner(owner) return SampleMatrix(Kind::kVariable, "");
, fKind(kind) }
, fExpression(expression) {}
static SampleMatrix Make(const Program& program, const Variable& fp); static SampleMatrix Make(const Program& program, const Variable& fp);
@ -76,12 +75,20 @@ struct SampleMatrix {
} }
#endif #endif
// TODO(michaelludwig): fOwner and fBase are going away; owner is filled in automatically when
// a matrix-sampled FP is registered as a child.
GrFragmentProcessor* fOwner; GrFragmentProcessor* fOwner;
Kind fKind; Kind fKind;
// The constant or uniform expression representing the matrix (will be the empty string when // The constant or uniform expression representing the matrix (will be the empty string when
// kind == kNone or kVariable) // kind == kNone or kVariable)
String fExpression; String fExpression;
const GrFragmentProcessor* fBase = nullptr; const GrFragmentProcessor* fBase = nullptr;
private:
SampleMatrix(Kind kind, String expression)
: fOwner(nullptr)
, fKind(kind)
, fExpression(expression) {}
}; };
} // namespace } // namespace

View File

@ -148,7 +148,7 @@ public:
GrSurfaceProxy::UseAllocator::kYes); GrSurfaceProxy::UseAllocator::kYes);
auto atlasEffect = GrTextureEffect::Make({fLazyProxy, kOrigin, readSwizzle}, auto atlasEffect = GrTextureEffect::Make({fLazyProxy, kOrigin, readSwizzle},
kPremul_SkAlphaType); kPremul_SkAlphaType);
this->registerChildProcessor(std::move(atlasEffect)); this->registerChild(std::move(atlasEffect));
} }
private: private:

View File

@ -110,13 +110,13 @@ private:
TestFP(const SkTArray<GrSurfaceProxyView>& views) TestFP(const SkTArray<GrSurfaceProxyView>& views)
: INHERITED(kTestFP_ClassID, kNone_OptimizationFlags) { : INHERITED(kTestFP_ClassID, kNone_OptimizationFlags) {
for (const auto& view : views) { for (const auto& view : views) {
this->registerChildProcessor(GrTextureEffect::Make(view, kUnknown_SkAlphaType)); this->registerChild(GrTextureEffect::Make(view, kUnknown_SkAlphaType));
} }
} }
TestFP(std::unique_ptr<GrFragmentProcessor> child) TestFP(std::unique_ptr<GrFragmentProcessor> child)
: INHERITED(kTestFP_ClassID, kNone_OptimizationFlags) { : INHERITED(kTestFP_ClassID, kNone_OptimizationFlags) {
this->registerChildProcessor(std::move(child)); this->registerChild(std::move(child));
} }
explicit TestFP(const TestFP& that) : INHERITED(kTestFP_ClassID, that.optimizationFlags()) { explicit TestFP(const TestFP& that) : INHERITED(kTestFP_ClassID, that.optimizationFlags()) {

View File

@ -126,7 +126,7 @@ private:
BlockInputFragmentProcessor(std::unique_ptr<GrFragmentProcessor> child) BlockInputFragmentProcessor(std::unique_ptr<GrFragmentProcessor> child)
: INHERITED(kBlockInputFragmentProcessor_ClassID, kNone_OptimizationFlags) { : INHERITED(kBlockInputFragmentProcessor_ClassID, kNone_OptimizationFlags) {
this->registerChildProcessor(std::move(child)); this->registerChild(std::move(child));
} }
void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {} void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {}

View File

@ -545,8 +545,8 @@ DEF_TEST(SkSLFPChildProcessors, r) {
} }
)__SkSL__", )__SkSL__",
/*expectedH=*/{ /*expectedH=*/{
"child1_index = this->registerChildProcessor(std::move(child1));", "child1_index = this->registerChild(std::move(child1));",
"child2_index = this->registerChildProcessor(std::move(child2));" "child2_index = this->registerChild(std::move(child2));"
}, },
/*expectedCPP=*/{ /*expectedCPP=*/{
"SkString _sample149;\n", "SkString _sample149;\n",
@ -576,8 +576,8 @@ DEF_TEST(SkSLFPChildProcessorsWithInput, r) {
} }
)__SkSL__", )__SkSL__",
/*expectedH=*/{ /*expectedH=*/{
"child1_index = this->registerChildProcessor(std::move(child1));", "child1_index = this->registerChild(std::move(child1));",
"child2_index = this->registerChildProcessor(std::move(child2));" "child2_index = this->registerChild(std::move(child2));"
}, },
/*expectedCPP=*/{ /*expectedCPP=*/{
"SkString _input198(\"childIn\");", "SkString _input198(\"childIn\");",
@ -605,7 +605,7 @@ DEF_TEST(SkSLFPChildProcessorWithInputExpression, r) {
} }
)__SkSL__", )__SkSL__",
/*expectedH=*/{ /*expectedH=*/{
"child_index = this->registerChildProcessor(std::move(child));", "child_index = this->registerChild(std::move(child));",
}, },
/*expectedCPP=*/{ /*expectedCPP=*/{
"SkString _input106 = SkStringPrintf(\"%s * half4(0.5)\", args.fInputColor);", "SkString _input106 = SkStringPrintf(\"%s * half4(0.5)\", args.fInputColor);",
@ -630,8 +630,8 @@ DEF_TEST(SkSLFPNestedChildProcessors, r) {
} }
)__SkSL__", )__SkSL__",
/*expectedH=*/{ /*expectedH=*/{
"child1_index = this->registerChildProcessor(std::move(child1));", "child1_index = this->registerChild(std::move(child1));",
"child2_index = this->registerChildProcessor(std::move(child2));" "child2_index = this->registerChild(std::move(child2));"
}, },
/*expectedCPP=*/{ /*expectedCPP=*/{
"SkString _input177 = SkStringPrintf(\"%s * half4(0.5)\", args.fInputColor);", "SkString _input177 = SkStringPrintf(\"%s * half4(0.5)\", args.fInputColor);",
@ -664,7 +664,7 @@ DEF_TEST(SkSLFPChildFPAndGlobal, r) {
} }
)__SkSL__", )__SkSL__",
/*expectedH=*/{ /*expectedH=*/{
"child_index = this->registerChildProcessor(std::move(child));" "child_index = this->registerChild(std::move(child));"
}, },
/*expectedCPP=*/{ /*expectedCPP=*/{
"hasCap = sk_Caps.externalTextureSupport;", "hasCap = sk_Caps.externalTextureSupport;",
@ -702,7 +702,7 @@ DEF_TEST(SkSLFPChildProcessorInlineFieldAccess, r) {
} }
)__SkSL__", )__SkSL__",
/*expectedH=*/{ /*expectedH=*/{
"child_index = this->registerChildProcessor(std::move(child));" "child_index = this->registerChild(std::move(child));"
}, },
/*expectedCPP=*/{ /*expectedCPP=*/{
"fragBuilder->codeAppendf(\n" "fragBuilder->codeAppendf(\n"
@ -738,7 +738,7 @@ DEF_TEST(SkSLFPChildProcessorFieldAccess, r) {
} }
)__SkSL__", )__SkSL__",
/*expectedH=*/{ /*expectedH=*/{
"child_index = this->registerChildProcessor(std::move(child));" "child_index = this->registerChild(std::move(child));"
}, },
/*expectedCPP=*/{ /*expectedCPP=*/{
"opaque = _outer.childProcessor(_outer.child_index).preservesOpaqueInput();", "opaque = _outer.childProcessor(_outer.child_index).preservesOpaqueInput();",
@ -814,7 +814,9 @@ DEF_TEST(SkSLFPSampleCoords, r) {
sk_OutColor = sample(child) + sample(child, sk_TransformedCoords2D[0] / 2); sk_OutColor = sample(child) + sample(child, sk_TransformedCoords2D[0] / 2);
} }
)__SkSL__", )__SkSL__",
/*expectedH=*/{}, /*expectedH=*/{
"child_index = this->registerExplicitlySampledChild(std::move(child));"
},
/*expectedCPP=*/{ /*expectedCPP=*/{
"SkString _sample150;\n", "SkString _sample150;\n",
"_sample150 = this->invokeChild(_outer.child_index, args);\n", "_sample150 = this->invokeChild(_outer.child_index, args);\n",