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:
parent
3cf3d92b56
commit
9aba625ec3
@ -38,8 +38,7 @@ public:
|
||||
|
||||
SampleCoordEffect(std::unique_ptr<GrFragmentProcessor> child)
|
||||
: INHERITED(CLASS_ID, kNone_OptimizationFlags) {
|
||||
child->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(child));
|
||||
this->registerExplicitlySampledChild(std::move(child));
|
||||
}
|
||||
|
||||
const char* name() const override { return "SampleCoordEffect"; }
|
||||
|
@ -21,11 +21,11 @@ public:
|
||||
|
||||
SampleMatrixConstantEffect(std::unique_ptr<GrFragmentProcessor> child)
|
||||
: INHERITED(CLASS_ID, kNone_OptimizationFlags) {
|
||||
child->setSampleMatrix(SkSL::SampleMatrix(SkSL::SampleMatrix::Kind::kConstantOrUniform,
|
||||
child.get(), "float3x3(float3(0.5, 0.0, 0.0), "
|
||||
"float3(0.0, 0.5, 0.0), "
|
||||
"float3(0.0, 0.0, 1.0))"));
|
||||
this->registerChildProcessor(std::move(child));
|
||||
this->registerChild(std::move(child),
|
||||
SkSL::SampleMatrix::MakeConstUniform(
|
||||
"float3x3(float3(0.5, 0.0, 0.0), "
|
||||
"float3(0.0, 0.5, 0.0), "
|
||||
"float3(0.0, 0.0, 1.0))"));
|
||||
}
|
||||
|
||||
const char* name() const override { return "SampleMatrixConstantEffect"; }
|
||||
|
@ -25,8 +25,7 @@ public:
|
||||
: INHERITED(CLASS_ID, kNone_OptimizationFlags)
|
||||
, fXOffset(xOffset)
|
||||
, fYOffset(yOffset) {
|
||||
child->setSampleMatrix(SkSL::SampleMatrix(SkSL::SampleMatrix::Kind::kVariable));
|
||||
this->registerChildProcessor(std::move(child));
|
||||
this->registerChild(std::move(child), SkSL::SampleMatrix::MakeVariable());
|
||||
}
|
||||
|
||||
const char* name() const override { return "SampleMatrixVariableEffect"; }
|
||||
|
@ -307,15 +307,12 @@ ColorTableEffect::ColorTableEffect(GrSurfaceProxyView view)
|
||||
// Not bothering with table-specific optimizations.
|
||||
: INHERITED(kColorTableEffect_ClassID, kNone_OptimizationFlags) {
|
||||
auto te = GrTextureEffect::Make(std::move(view), kUnknown_SkAlphaType);
|
||||
te->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(te));
|
||||
this->registerExplicitlySampledChild(std::move(te));
|
||||
}
|
||||
|
||||
ColorTableEffect::ColorTableEffect(const ColorTableEffect& that)
|
||||
: INHERITED(kColorTableEffect_ClassID, that.optimizationFlags()) {
|
||||
auto child = that.childProcessor(0).clone();
|
||||
child->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(child));
|
||||
this->cloneAndRegisterAllChildProcessors(that);
|
||||
}
|
||||
|
||||
GrGLSLFragmentProcessor* ColorTableEffect::onCreateGLSLInstance() const {
|
||||
|
@ -508,9 +508,8 @@ GrDisplacementMapEffect::GrDisplacementMapEffect(SkColorChannel xChannelSelector
|
||||
, fXChannelSelector(xChannelSelector)
|
||||
, fYChannelSelector(yChannelSelector)
|
||||
, fScale(scale) {
|
||||
this->registerChildProcessor(std::move(displacement));
|
||||
color->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(color));
|
||||
this->registerChild(std::move(displacement));
|
||||
this->registerExplicitlySampledChild(std::move(color));
|
||||
this->addCoordTransform(&fCoordTransform);
|
||||
}
|
||||
|
||||
|
@ -1632,8 +1632,7 @@ GrLightingEffect::GrLightingEffect(ClassID classID,
|
||||
child = GrTextureEffect::Make(std::move(view), kPremul_SkAlphaType, SkMatrix::I(), kSampler,
|
||||
caps);
|
||||
}
|
||||
child->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(child));
|
||||
this->registerExplicitlySampledChild(std::move(child));
|
||||
this->addCoordTransform(&fCoordTransform);
|
||||
}
|
||||
|
||||
@ -1643,9 +1642,7 @@ GrLightingEffect::GrLightingEffect(const GrLightingEffect& that)
|
||||
, fSurfaceScale(that.fSurfaceScale)
|
||||
, fFilterMatrix(that.fFilterMatrix)
|
||||
, fBoundaryMode(that.fBoundaryMode) {
|
||||
auto child = that.childProcessor(0).clone();
|
||||
child->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(child));
|
||||
this->cloneAndRegisterAllChildProcessors(that);
|
||||
this->addCoordTransform(&fCoordTransform);
|
||||
}
|
||||
|
||||
|
@ -346,8 +346,7 @@ GrMorphologyEffect::GrMorphologyEffect(GrSurfaceProxyView view,
|
||||
, fUseRange(SkToBool(range)) {
|
||||
this->addCoordTransform(&fCoordTransform);
|
||||
auto te = GrTextureEffect::Make(std::move(view), srcAlphaType);
|
||||
te->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(te));
|
||||
this->registerExplicitlySampledChild(std::move(te));
|
||||
if (fUseRange) {
|
||||
fRange[0] = range[0];
|
||||
fRange[1] = range[1];
|
||||
@ -361,9 +360,7 @@ GrMorphologyEffect::GrMorphologyEffect(const GrMorphologyEffect& that)
|
||||
, fType(that.fType)
|
||||
, fUseRange(that.fUseRange) {
|
||||
this->addCoordTransform(&fCoordTransform);
|
||||
auto child = that.childProcessor(0).clone();
|
||||
child->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(child));
|
||||
this->cloneAndRegisterAllChildProcessors(that);
|
||||
if (that.fUseRange) {
|
||||
fRange[0] = that.fRange[0];
|
||||
fRange[1] = that.fRange[1];
|
||||
|
@ -97,7 +97,7 @@ GrColorSpaceXformEffect::GrColorSpaceXformEffect(std::unique_ptr<GrFragmentProce
|
||||
: INHERITED(kGrColorSpaceXformEffect_ClassID, OptFlags(child.get()))
|
||||
, fColorXform(std::move(colorXform)) {
|
||||
if (child) {
|
||||
this->registerChildProcessor(std::move(child));
|
||||
this->registerChild(std::move(child));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,8 +98,8 @@ void GrFragmentProcessor::setSampleMatrix(SkSL::SampleMatrix newMatrix) {
|
||||
}
|
||||
} else {
|
||||
SkASSERT(newMatrix.fKind == SkSL::SampleMatrix::Kind::kVariable);
|
||||
fMatrix = SkSL::SampleMatrix(SkSL::SampleMatrix::Kind::kMixed, fMatrix.fOwner,
|
||||
fMatrix.fExpression);
|
||||
fMatrix.fKind = SkSL::SampleMatrix::Kind::kMixed;
|
||||
fMatrix.fBase = nullptr;
|
||||
}
|
||||
} else {
|
||||
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
|
||||
bool GrFragmentProcessor::isInstantiated() const {
|
||||
for (int i = 0; i < fTextureSamplerCnt; ++i) {
|
||||
@ -128,7 +135,26 @@ bool GrFragmentProcessor::isInstantiated() const {
|
||||
}
|
||||
#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) {
|
||||
fFlags |= kHasCoordTransforms_Flag;
|
||||
}
|
||||
@ -143,10 +169,8 @@ int GrFragmentProcessor::registerChildProcessor(std::unique_ptr<GrFragmentProces
|
||||
|
||||
int GrFragmentProcessor::cloneAndRegisterChildProcessor(const GrFragmentProcessor& fp) {
|
||||
std::unique_ptr<GrFragmentProcessor> clone = fp.clone();
|
||||
if (fp.isSampledWithExplicitCoords()) {
|
||||
clone->setSampledWithExplicitCoords();
|
||||
}
|
||||
return this->registerChildProcessor(std::move(clone));
|
||||
return this->registerChild(std::move(clone), fp.sampleMatrix(),
|
||||
fp.isSampledWithExplicitCoords());
|
||||
}
|
||||
|
||||
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)
|
||||
: INHERITED(kSwizzleFragmentProcessor_ClassID, ProcessorOptimizationFlags(fp.get()))
|
||||
, fSwizzle(swizzle) {
|
||||
this->registerChildProcessor(std::move(fp));
|
||||
this->registerChild(std::move(fp));
|
||||
}
|
||||
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
|
||||
@ -279,7 +303,7 @@ std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::MakeInputPremulAndMulB
|
||||
private:
|
||||
PremulFragmentProcessor(std::unique_ptr<GrFragmentProcessor> processor)
|
||||
: INHERITED(kPremulFragmentProcessor_ClassID, OptFlags(processor.get())) {
|
||||
this->registerChildProcessor(std::move(processor));
|
||||
this->registerChild(std::move(processor));
|
||||
}
|
||||
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
|
||||
@ -379,7 +403,7 @@ std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::RunInSeries(
|
||||
: INHERITED(kSeriesFragmentProcessor_ClassID, OptFlags(children, cnt)) {
|
||||
SkASSERT(cnt > 1);
|
||||
for (int i = 0; i < cnt; ++i) {
|
||||
this->registerChildProcessor(std::move(children[i]));
|
||||
this->registerChild(std::move(children[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,19 +148,10 @@ public:
|
||||
return SkToBool(fFlags & kSampledWithExplicitCoords);
|
||||
}
|
||||
|
||||
void setSampledWithExplicitCoords() {
|
||||
fFlags |= kSampledWithExplicitCoords;
|
||||
for (auto& child : fChildProcessors) {
|
||||
child->setSampledWithExplicitCoords();
|
||||
}
|
||||
}
|
||||
|
||||
SkSL::SampleMatrix sampleMatrix() const {
|
||||
return fMatrix;
|
||||
}
|
||||
|
||||
void setSampleMatrix(SkSL::SampleMatrix matrix);
|
||||
|
||||
/**
|
||||
* A GrDrawOp may premultiply its antialiasing coverage into its GrGeometryProcessor's color
|
||||
* output under the following scenario:
|
||||
@ -332,6 +323,13 @@ public:
|
||||
// Sentinel type for range-for using FPItemIter.
|
||||
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:
|
||||
enum OptimizationFlags : uint32_t {
|
||||
kNone_OptimizationFlags,
|
||||
@ -424,8 +422,24 @@ protected:
|
||||
* 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
|
||||
* 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
|
||||
@ -484,6 +498,10 @@ private:
|
||||
|
||||
bool hasSameTransforms(const GrFragmentProcessor&) const;
|
||||
|
||||
void setSampledWithExplicitCoords();
|
||||
|
||||
void setSampleMatrix(SkSL::SampleMatrix matrix);
|
||||
|
||||
enum PrivateFlags {
|
||||
kFirstPrivateFlag = kAll_OptimizationFlags + 1,
|
||||
kHasCoordTransforms_Flag = kFirstPrivateFlag,
|
||||
|
@ -387,7 +387,7 @@ static inline bool skpaint_to_grpaint_impl(GrRecordingContext* context,
|
||||
if (ditherFP) {
|
||||
// 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.
|
||||
ditherFP->setSampledWithExplicitCoords();
|
||||
ditherFP->temporary_SetExplicitlySampled();
|
||||
grPaint->addColorFragmentProcessor(std::move(ditherFP));
|
||||
}
|
||||
}
|
||||
|
@ -30,11 +30,10 @@ GrCCClipProcessor::GrCCClipProcessor(std::unique_ptr<GrFragmentProcessor> inputF
|
||||
, fMustCheckBounds(MustCheckBounds::kYes == mustCheckBounds) {
|
||||
auto view = make_view(caps, clipPath->atlasLazyProxy(), fIsCoverageCount);
|
||||
auto texEffect = GrTextureEffect::Make(std::move(view), kUnknown_SkAlphaType);
|
||||
texEffect->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(texEffect));
|
||||
this->registerExplicitlySampledChild(std::move(texEffect));
|
||||
|
||||
if (inputFP != nullptr) {
|
||||
this->registerChildProcessor(std::move(inputFP));
|
||||
this->registerChild(std::move(inputFP));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -176,9 +176,8 @@ GrBicubicEffect::GrBicubicEffect(std::unique_ptr<GrFragmentProcessor> fp,
|
||||
, fCoordTransform(matrix)
|
||||
, fDirection(direction)
|
||||
, fClamp(clamp) {
|
||||
fp->setSampledWithExplicitCoords();
|
||||
this->addCoordTransform(&fCoordTransform);
|
||||
this->registerChildProcessor(std::move(fp));
|
||||
this->registerExplicitlySampledChild(std::move(fp));
|
||||
}
|
||||
|
||||
GrBicubicEffect::GrBicubicEffect(const GrBicubicEffect& that)
|
||||
@ -187,9 +186,7 @@ GrBicubicEffect::GrBicubicEffect(const GrBicubicEffect& that)
|
||||
, fDirection(that.fDirection)
|
||||
, fClamp(that.fClamp) {
|
||||
this->addCoordTransform(&fCoordTransform);
|
||||
auto child = that.childProcessor(0).clone();
|
||||
child->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(child));
|
||||
this->cloneAndRegisterAllChildProcessors(that);
|
||||
}
|
||||
|
||||
void GrBicubicEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
|
||||
|
@ -200,7 +200,7 @@ GrConvexPolyEffect::GrConvexPolyEffect(std::unique_ptr<GrFragmentProcessor> inpu
|
||||
}
|
||||
|
||||
if (inputFP != nullptr) {
|
||||
this->registerChildProcessor(std::move(inputFP));
|
||||
this->registerChild(std::move(inputFP));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,8 +171,7 @@ GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor(
|
||||
ProcessorOptimizationFlags(child.get()))
|
||||
, fRadius(radius)
|
||||
, fDirection(direction) {
|
||||
child->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(child));
|
||||
this->registerExplicitlySampledChild(std::move(child));
|
||||
SkASSERT(radius <= kMaxKernelRadius);
|
||||
fill_in_1D_gaussian_kernel(fKernel, gaussianSigma, fRadius);
|
||||
this->addCoordTransform(&fCoordTransform);
|
||||
@ -183,9 +182,7 @@ GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor(
|
||||
: INHERITED(kGrGaussianConvolutionFragmentProcessor_ClassID, that.optimizationFlags())
|
||||
, fRadius(that.fRadius)
|
||||
, fDirection(that.fDirection) {
|
||||
auto child = that.childProcessor(0).clone();
|
||||
child->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(child));
|
||||
this->cloneAndRegisterAllChildProcessors(that);
|
||||
memcpy(fKernel, that.fKernel, radius_to_width(fRadius) * sizeof(float));
|
||||
this->addCoordTransform(&fCoordTransform);
|
||||
}
|
||||
|
@ -294,11 +294,9 @@ GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(std::unique_ptr<GrFragmentP
|
||||
, fGain(SkScalarToFloat(gain))
|
||||
, fBias(SkScalarToFloat(bias) / 255.0f)
|
||||
, fConvolveAlpha(convolveAlpha) {
|
||||
child->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(child));
|
||||
this->registerExplicitlySampledChild(std::move(child));
|
||||
if (kernelFP) {
|
||||
kernelFP->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(kernelFP));
|
||||
this->registerExplicitlySampledChild(std::move(kernelFP));
|
||||
}
|
||||
fKernelOffset = {static_cast<float>(kernelOffset.x()),
|
||||
static_cast<float>(kernelOffset.y())};
|
||||
@ -312,14 +310,7 @@ GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(const GrMatrixConvolutionEf
|
||||
, fBias(that.fBias)
|
||||
, fKernelOffset(that.fKernelOffset)
|
||||
, fConvolveAlpha(that.fConvolveAlpha) {
|
||||
auto child = that.childProcessor(0).clone();
|
||||
child->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(child));
|
||||
if (fKernel.isSampled()) {
|
||||
child = that.childProcessor(1).clone();
|
||||
child->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(child));
|
||||
}
|
||||
this->cloneAndRegisterAllChildProcessors(that);
|
||||
this->addCoordTransform(&fCoordTransform);
|
||||
}
|
||||
|
||||
|
@ -38,9 +38,7 @@ private:
|
||||
: INHERITED(kGrMatrixEffect_ClassID, kNone_OptimizationFlags)
|
||||
, fMatrix(matrix) {
|
||||
SkASSERT(child);
|
||||
child->setSampleMatrix(
|
||||
SkSL::SampleMatrix(SkSL::SampleMatrix::Kind::kConstantOrUniform, this, "matrix"));
|
||||
this->registerChildProcessor(std::move(child));
|
||||
this->registerChild(std::move(child), SkSL::SampleMatrix::MakeConstUniform("matrix"));
|
||||
}
|
||||
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
|
@ -106,7 +106,7 @@ CircularRRectEffect::CircularRRectEffect(std::unique_ptr<GrFragmentProcessor> in
|
||||
, fEdgeType(edgeType)
|
||||
, fCircularCornerFlags(circularCornerFlags) {
|
||||
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)
|
||||
, fEdgeType(edgeType) {
|
||||
if (inputFP != nullptr) {
|
||||
this->registerChildProcessor(std::move(inputFP));
|
||||
this->registerChild(std::move(inputFP));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -198,8 +198,7 @@ const char* GrSkSLFP::name() const {
|
||||
}
|
||||
|
||||
void GrSkSLFP::addChild(std::unique_ptr<GrFragmentProcessor> child) {
|
||||
child->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(child));
|
||||
this->registerExplicitlySampledChild(std::move(child));
|
||||
}
|
||||
|
||||
GrGLSLFragmentProcessor* GrSkSLFP::onCreateGLSLInstance() const {
|
||||
|
@ -62,8 +62,8 @@ private:
|
||||
SkBlendMode mode)
|
||||
: INHERITED(kComposeTwoFragmentProcessor_ClassID, OptFlags(src.get(), dst.get(), mode))
|
||||
, fMode(mode) {
|
||||
SkDEBUGCODE(int shaderAChildIndex = )this->registerChildProcessor(std::move(src));
|
||||
SkDEBUGCODE(int shaderBChildIndex = )this->registerChildProcessor(std::move(dst));
|
||||
SkDEBUGCODE(int shaderAChildIndex = )this->registerChild(std::move(src));
|
||||
SkDEBUGCODE(int shaderBChildIndex = )this->registerChild(std::move(dst));
|
||||
SkASSERT(0 == shaderAChildIndex);
|
||||
SkASSERT(1 == shaderBChildIndex);
|
||||
}
|
||||
@ -413,7 +413,7 @@ private:
|
||||
: INHERITED(kComposeOneFragmentProcessor_ClassID, OptFlags(fp.get(), mode, child))
|
||||
, fMode(mode)
|
||||
, fChild(child) {
|
||||
SkDEBUGCODE(int dstIndex =) this->registerChildProcessor(std::move(fp));
|
||||
SkDEBUGCODE(int dstIndex =) this->registerChild(std::move(fp));
|
||||
SkASSERT(0 == dstIndex);
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ GrYUVtoRGBEffect::GrYUVtoRGBEffect(std::unique_ptr<GrFragmentProcessor> planeFPs
|
||||
ModulateForClampedSamplerOptFlags(alpha_type(yuvaIndices)))
|
||||
, fYUVColorSpace(yuvColorSpace) {
|
||||
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);
|
||||
}
|
||||
@ -251,10 +251,7 @@ bool GrYUVtoRGBEffect::onIsEqual(const GrFragmentProcessor& other) const {
|
||||
GrYUVtoRGBEffect::GrYUVtoRGBEffect(const GrYUVtoRGBEffect& src)
|
||||
: GrFragmentProcessor(kGrYUVtoRGBEffect_ClassID, src.optimizationFlags())
|
||||
, fYUVColorSpace(src.fYUVColorSpace) {
|
||||
int numPlanes = src.numChildProcessors();
|
||||
for (int i = 0; i < numPlanes; ++i) {
|
||||
this->registerChildProcessor(this->childProcessor(i).clone());
|
||||
}
|
||||
this->cloneAndRegisterAllChildProcessors(src);
|
||||
std::copy_n(src.fYUVAIndices, this->numChildProcessors(), fYUVAIndices);
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ private:
|
||||
, edgeType(edgeType)
|
||||
, rect(rect) {
|
||||
if (inputFP) {
|
||||
inputFP_index = this->registerChildProcessor(std::move(inputFP));
|
||||
inputFP_index = this->registerChild(std::move(inputFP));
|
||||
}
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
|
@ -47,10 +47,10 @@ private:
|
||||
, innerThreshold(innerThreshold)
|
||||
, outerThreshold(outerThreshold) {
|
||||
if (inputFP) {
|
||||
inputFP_index = this->registerChildProcessor(std::move(inputFP));
|
||||
inputFP_index = this->registerChild(std::move(inputFP));
|
||||
}
|
||||
SkASSERT(maskFP);
|
||||
maskFP_index = this->registerChildProcessor(std::move(maskFP));
|
||||
maskFP_index = this->registerChild(std::move(maskFP));
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||
|
@ -36,7 +36,7 @@ private:
|
||||
: INHERITED(kGrBlurredEdgeFragmentProcessor_ClassID, kNone_OptimizationFlags)
|
||||
, mode(mode) {
|
||||
if (inputFP) {
|
||||
inputFP_index = this->registerChildProcessor(std::move(inputFP));
|
||||
inputFP_index = this->registerChild(std::move(inputFP));
|
||||
}
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
|
@ -48,11 +48,10 @@ private:
|
||||
, solidRadius(solidRadius)
|
||||
, textureRadius(textureRadius) {
|
||||
if (inputFP) {
|
||||
inputFP_index = this->registerChildProcessor(std::move(inputFP));
|
||||
inputFP_index = this->registerChild(std::move(inputFP));
|
||||
}
|
||||
SkASSERT(blurProfile);
|
||||
blurProfile->setSampledWithExplicitCoords();
|
||||
blurProfile_index = this->registerChildProcessor(std::move(blurProfile));
|
||||
blurProfile_index = this->registerExplicitlySampledChild(std::move(blurProfile));
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||
|
@ -52,7 +52,7 @@ private:
|
||||
, center(center)
|
||||
, radius(radius) {
|
||||
if (inputFP) {
|
||||
inputFP_index = this->registerChildProcessor(std::move(inputFP));
|
||||
inputFP_index = this->registerChild(std::move(inputFP));
|
||||
}
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
|
@ -48,7 +48,7 @@ private:
|
||||
kPreservesOpaqueInput_OptimizationFlag))
|
||||
, clampToPremul(clampToPremul) {
|
||||
if (inputFP) {
|
||||
inputFP_index = this->registerChildProcessor(std::move(inputFP));
|
||||
inputFP_index = this->registerChild(std::move(inputFP));
|
||||
}
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
|
@ -86,7 +86,7 @@ private:
|
||||
, clampRGBOutput(clampRGBOutput)
|
||||
, premulOutput(premulOutput) {
|
||||
if (inputFP) {
|
||||
inputFP_index = this->registerChildProcessor(std::move(inputFP));
|
||||
inputFP_index = this->registerChild(std::move(inputFP));
|
||||
}
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
|
@ -38,10 +38,10 @@ private:
|
||||
float weight)
|
||||
: INHERITED(kGrComposeLerpEffect_ClassID, kNone_OptimizationFlags), weight(weight) {
|
||||
if (child1) {
|
||||
child1_index = this->registerChildProcessor(std::move(child1));
|
||||
child1_index = this->registerChild(std::move(child1));
|
||||
}
|
||||
if (child2) {
|
||||
child2_index = this->registerChildProcessor(std::move(child2));
|
||||
child2_index = this->registerChild(std::move(child2));
|
||||
}
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
|
@ -74,7 +74,7 @@ private:
|
||||
, color(color)
|
||||
, mode(mode) {
|
||||
if (inputFP) {
|
||||
inputFP_index = this->registerChildProcessor(std::move(inputFP));
|
||||
inputFP_index = this->registerChild(std::move(inputFP));
|
||||
}
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
|
@ -33,8 +33,7 @@ private:
|
||||
GrDeviceSpaceEffect(std::unique_ptr<GrFragmentProcessor> fp, SkMatrix matrix)
|
||||
: INHERITED(kGrDeviceSpaceEffect_ClassID, kNone_OptimizationFlags), matrix(matrix) {
|
||||
SkASSERT(fp);
|
||||
fp->setSampledWithExplicitCoords();
|
||||
fp_index = this->registerChildProcessor(std::move(fp));
|
||||
fp_index = this->registerExplicitlySampledChild(std::move(fp));
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||
|
@ -62,7 +62,7 @@ private:
|
||||
, center(center)
|
||||
, radii(radii) {
|
||||
if (inputFP) {
|
||||
inputFP_index = this->registerChildProcessor(std::move(inputFP));
|
||||
inputFP_index = this->registerChild(std::move(inputFP));
|
||||
}
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
|
@ -51,7 +51,7 @@ private:
|
||||
(kConstantOutputForConstantInput_OptimizationFlag |
|
||||
kPreservesOpaqueInput_OptimizationFlag)) {
|
||||
if (inputFP) {
|
||||
inputFP_index = this->registerChildProcessor(std::move(inputFP));
|
||||
inputFP_index = this->registerChild(std::move(inputFP));
|
||||
}
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
|
@ -46,7 +46,7 @@ private:
|
||||
: kAll_OptimizationFlags) &
|
||||
kConstantOutputForConstantInput_OptimizationFlag) {
|
||||
if (inputFP) {
|
||||
inputFP_index = this->registerChildProcessor(std::move(inputFP));
|
||||
inputFP_index = this->registerChild(std::move(inputFP));
|
||||
}
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
|
@ -58,8 +58,7 @@ private:
|
||||
, xInvInset(xInvInset)
|
||||
, yInvInset(yInvInset) {
|
||||
SkASSERT(src);
|
||||
src->setSampledWithExplicitCoords();
|
||||
src_index = this->registerChildProcessor(std::move(src));
|
||||
src_index = this->registerExplicitlySampledChild(std::move(src));
|
||||
this->addCoordTransform(&fCoordTransform0);
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
|
@ -56,9 +56,9 @@ private:
|
||||
: INHERITED(kGrMixerEffect_ClassID, (OptimizationFlags)OptFlags(fp0, fp1))
|
||||
, weight(weight) {
|
||||
SkASSERT(fp0);
|
||||
fp0_index = this->registerChildProcessor(std::move(fp0));
|
||||
fp0_index = this->registerChild(std::move(fp0));
|
||||
if (fp1) {
|
||||
fp1_index = this->registerChildProcessor(std::move(fp1));
|
||||
fp1_index = this->registerChild(std::move(fp1));
|
||||
}
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
|
@ -61,7 +61,7 @@ private:
|
||||
, uniformColor(uniformColor)
|
||||
, literalColor(literalColor) {
|
||||
SkASSERT(fp);
|
||||
fp_index = this->registerChildProcessor(std::move(fp));
|
||||
fp_index = this->registerChild(std::move(fp));
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||
|
@ -53,7 +53,7 @@ private:
|
||||
(kConstantOutputForConstantInput_OptimizationFlag |
|
||||
kPreservesOpaqueInput_OptimizationFlag)) {
|
||||
if (inputFP) {
|
||||
inputFP_index = this->registerChildProcessor(std::move(inputFP));
|
||||
inputFP_index = this->registerChild(std::move(inputFP));
|
||||
}
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
|
@ -139,11 +139,10 @@ private:
|
||||
, rect(rect)
|
||||
, cornerRadius(cornerRadius) {
|
||||
if (inputFP) {
|
||||
inputFP_index = this->registerChildProcessor(std::move(inputFP));
|
||||
inputFP_index = this->registerChild(std::move(inputFP));
|
||||
}
|
||||
SkASSERT(ninePatchFP);
|
||||
ninePatchFP->setSampledWithExplicitCoords();
|
||||
ninePatchFP_index = this->registerChildProcessor(std::move(ninePatchFP));
|
||||
ninePatchFP_index = this->registerExplicitlySampledChild(std::move(ninePatchFP));
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||
|
@ -145,11 +145,10 @@ private:
|
||||
, rect(rect)
|
||||
, isFast(isFast) {
|
||||
if (inputFP) {
|
||||
inputFP_index = this->registerChildProcessor(std::move(inputFP));
|
||||
inputFP_index = this->registerChild(std::move(inputFP));
|
||||
}
|
||||
SkASSERT(integral);
|
||||
integral->setSampledWithExplicitCoords();
|
||||
integral_index = this->registerChildProcessor(std::move(integral));
|
||||
integral_index = this->registerExplicitlySampledChild(std::move(integral));
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||
|
@ -166,7 +166,9 @@ void GrGLSLGeometryProcessor::emitTransformCode(GrGLSLVertexBuilder* vb,
|
||||
localCoords = tr.fLocalCoords.c_str();
|
||||
}
|
||||
vb->codeAppend("{\n");
|
||||
uniformHandler->writeUniformMappings(tr.fFP->sampleMatrix().fOwner, vb);
|
||||
if (tr.fFP->sampleMatrix().fOwner) {
|
||||
uniformHandler->writeUniformMappings(tr.fFP->sampleMatrix().fOwner, vb);
|
||||
}
|
||||
if (tr.fType == kFloat2_GrSLType) {
|
||||
vb->codeAppendf("%s = (%s * %s * %s).xy", tr.fName,
|
||||
tr.fFP->sampleMatrix().fExpression.c_str(), tr.fMatrix.c_str(),
|
||||
|
@ -57,9 +57,9 @@ private:
|
||||
, makePremul(makePremul)
|
||||
, colorsAreOpaque(colorsAreOpaque) {
|
||||
SkASSERT(colorizer);
|
||||
colorizer_index = this->registerChildProcessor(std::move(colorizer));
|
||||
colorizer_index = this->registerChild(std::move(colorizer));
|
||||
SkASSERT(gradLayout);
|
||||
gradLayout_index = this->registerChildProcessor(std::move(gradLayout));
|
||||
gradLayout_index = this->registerChild(std::move(gradLayout));
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||
|
@ -33,8 +33,7 @@ private:
|
||||
GrTextureGradientColorizer(std::unique_ptr<GrFragmentProcessor> textureFP)
|
||||
: INHERITED(kGrTextureGradientColorizer_ClassID, kNone_OptimizationFlags) {
|
||||
SkASSERT(textureFP);
|
||||
textureFP->setSampledWithExplicitCoords();
|
||||
textureFP_index = this->registerChildProcessor(std::move(textureFP));
|
||||
textureFP_index = this->registerExplicitlySampledChild(std::move(textureFP));
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||
|
@ -52,9 +52,9 @@ private:
|
||||
, makePremul(makePremul)
|
||||
, colorsAreOpaque(colorsAreOpaque) {
|
||||
SkASSERT(colorizer);
|
||||
colorizer_index = this->registerChildProcessor(std::move(colorizer));
|
||||
colorizer_index = this->registerChild(std::move(colorizer));
|
||||
SkASSERT(gradLayout);
|
||||
gradLayout_index = this->registerChildProcessor(std::move(gradLayout));
|
||||
gradLayout_index = this->registerChild(std::move(gradLayout));
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||
|
@ -785,10 +785,8 @@ private:
|
||||
, fNumOctaves(numOctaves)
|
||||
, fStitchTiles(stitchTiles)
|
||||
, fPaintingData(std::move(paintingData)) {
|
||||
permutationsFP->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(permutationsFP));
|
||||
noiseFP->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(noiseFP));
|
||||
this->registerExplicitlySampledChild(std::move(permutationsFP));
|
||||
this->registerExplicitlySampledChild(std::move(noiseFP));
|
||||
fCoordTransform = GrCoordTransform(matrix);
|
||||
this->addCoordTransform(&fCoordTransform);
|
||||
}
|
||||
@ -1154,10 +1152,8 @@ private:
|
||||
, fOctaves(octaves)
|
||||
, fZ(z)
|
||||
, fPaintingData(std::move(paintingData)) {
|
||||
permutationsFP->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(permutationsFP));
|
||||
gradientFP->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(gradientFP));
|
||||
this->registerExplicitlySampledChild(std::move(permutationsFP));
|
||||
this->registerExplicitlySampledChild(std::move(gradientFP));
|
||||
fCoordTransform = GrCoordTransform(matrix);
|
||||
this->addCoordTransform(&fCoordTransform);
|
||||
}
|
||||
|
@ -122,13 +122,17 @@ void CPPCodeGenerator::writeIndexExpression(const IndexExpression& i) {
|
||||
return;
|
||||
}
|
||||
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);
|
||||
fFormatArgs.push_back(name + ".c_str()");
|
||||
if (fWrittenTransformedCoords.find(index) == fWrittenTransformedCoords.end()) {
|
||||
if (!fAccessLocalCoordsDirectly) {
|
||||
fAccessLocalCoordsDirectly = true;
|
||||
addExtraEmitCodeLine("SkString " + name +
|
||||
" = fragBuilder->ensureCoords2D(args.fTransformedCoords[" +
|
||||
to_string(index) + "].fVaryingPoint, _outer.sampleMatrix());");
|
||||
fWrittenTransformedCoords.insert(index);
|
||||
}
|
||||
return;
|
||||
} else if (SK_TEXTURESAMPLERS_BUILTIN == builtin) {
|
||||
|
@ -123,7 +123,9 @@ private:
|
||||
std::vector<String> fExtraEmitCodeBlocks;
|
||||
|
||||
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
|
||||
bool fCPPMode = false;
|
||||
bool fInMain = false;
|
||||
|
@ -282,35 +282,45 @@ void HCodeGenerator::writeConstructor() {
|
||||
} else {
|
||||
this->writef(" SkASSERT(%s);", String(param->fName).c_str());
|
||||
}
|
||||
if (fSectionAndParameterHelper.hasCoordOverrides(*param)) {
|
||||
this->writef(" %s->setSampledWithExplicitCoords();",
|
||||
String(param->fName).c_str());
|
||||
}
|
||||
|
||||
bool explicitCoords = fSectionAndParameterHelper.hasCoordOverrides(*param);
|
||||
SampleMatrix matrix = SampleMatrix::Make(fProgram, *param);
|
||||
switch (matrix.fKind) {
|
||||
case SampleMatrix::Kind::kVariable:
|
||||
this->writef(" %s->setSampleMatrix(SkSL::SampleMatrix("
|
||||
"SkSL::SampleMatrix::Kind::kVariable));",
|
||||
String(param->fName).c_str());
|
||||
break;
|
||||
case SampleMatrix::Kind::kConstantOrUniform:
|
||||
this->writef(" %s->setSampleMatrix(SkSL::SampleMatrix("
|
||||
"SkSL::SampleMatrix::Kind::kConstantOrUniform, this, \"%s\"));",
|
||||
String(param->fName).c_str(),
|
||||
matrix.fExpression.c_str());
|
||||
break;
|
||||
case SampleMatrix::Kind::kMixed:
|
||||
this->writef(" %s->setSampleMatrix(SkSL::SampleMatrix("
|
||||
"SkSL::SampleMatrix::Kind::kMixed, this, \"%s\"));",
|
||||
String(param->fName).c_str(),
|
||||
matrix.fExpression.c_str());
|
||||
break;
|
||||
case SampleMatrix::Kind::kNone:
|
||||
break;
|
||||
|
||||
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:
|
||||
matrixArg.appendf(", SkSL::SampleMatrix::MakeVariable()");
|
||||
break;
|
||||
case SampleMatrix::Kind::kConstantOrUniform:
|
||||
matrixArg.appendf(", SkSL::SampleMatrix::MakeConstUniform(\"%s\")",
|
||||
matrix.fExpression.c_str());
|
||||
break;
|
||||
case SampleMatrix::Kind::kMixed:
|
||||
// Mixed is only produced when combining FPs, not from analysis of sksl
|
||||
SkASSERT(false);
|
||||
break;
|
||||
case SampleMatrix::Kind::kNone:
|
||||
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(),
|
||||
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) {
|
||||
this->writef(" }");
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ namespace SkSL {
|
||||
|
||||
SampleMatrix SampleMatrix::merge(const SampleMatrix& other) {
|
||||
if (fKind == Kind::kVariable || other.fKind == Kind::kVariable) {
|
||||
*this = SampleMatrix(Kind::kVariable);
|
||||
*this = SampleMatrix::MakeVariable();
|
||||
return *this;
|
||||
}
|
||||
if (other.fKind == Kind::kConstantOrUniform) {
|
||||
@ -40,7 +40,7 @@ SampleMatrix SampleMatrix::merge(const SampleMatrix& other) {
|
||||
if (fExpression == other.fExpression) {
|
||||
return *this;
|
||||
}
|
||||
*this = SampleMatrix(Kind::kVariable);
|
||||
*this = SampleMatrix::MakeVariable();
|
||||
return *this;
|
||||
}
|
||||
SkASSERT(fKind == Kind::kNone);
|
||||
@ -94,10 +94,9 @@ SampleMatrix SampleMatrixExtractor::getMatrix(const Expression& e) const {
|
||||
fc.fArguments[0]->fKind == Expression::kVariableReference_Kind &&
|
||||
&((VariableReference&) *fc.fArguments[0]).fVariable == &fFP) {
|
||||
if (fc.fArguments.back()->isConstantOrUniform()) {
|
||||
return SampleMatrix(SampleMatrix::Kind::kConstantOrUniform, nullptr,
|
||||
fc.fArguments.back()->description());
|
||||
return SampleMatrix::MakeConstUniform(fc.fArguments.back()->description());
|
||||
} else {
|
||||
return SampleMatrix(SampleMatrix::Kind::kVariable);
|
||||
return SampleMatrix::MakeVariable();
|
||||
}
|
||||
}
|
||||
SampleMatrix result;
|
||||
|
@ -27,7 +27,8 @@ struct SampleMatrix {
|
||||
// No sample(child, matrix) call affects the FP.
|
||||
kNone,
|
||||
// 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,
|
||||
// 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.
|
||||
@ -38,20 +39,18 @@ struct SampleMatrix {
|
||||
kMixed,
|
||||
};
|
||||
|
||||
// Make a SampleMatrix with kNone for its kind. Will not have an expression or have perspective.
|
||||
SampleMatrix()
|
||||
: fOwner(nullptr)
|
||||
, fKind(Kind::kNone) {}
|
||||
: fOwner(nullptr)
|
||||
, fKind(Kind::kNone) {}
|
||||
|
||||
SampleMatrix(Kind kind)
|
||||
: fOwner(nullptr)
|
||||
, fKind(kind) {
|
||||
SkASSERT(kind == Kind::kNone || kind == Kind::kVariable);
|
||||
static SampleMatrix MakeConstUniform(String expression) {
|
||||
return SampleMatrix(Kind::kConstantOrUniform, expression);
|
||||
}
|
||||
|
||||
SampleMatrix(Kind kind, GrFragmentProcessor* owner, String expression)
|
||||
: fOwner(owner)
|
||||
, fKind(kind)
|
||||
, fExpression(expression) {}
|
||||
static SampleMatrix MakeVariable() {
|
||||
return SampleMatrix(Kind::kVariable, "");
|
||||
}
|
||||
|
||||
static SampleMatrix Make(const Program& program, const Variable& fp);
|
||||
|
||||
@ -76,12 +75,20 @@ struct SampleMatrix {
|
||||
}
|
||||
#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;
|
||||
Kind fKind;
|
||||
// The constant or uniform expression representing the matrix (will be the empty string when
|
||||
// kind == kNone or kVariable)
|
||||
String fExpression;
|
||||
const GrFragmentProcessor* fBase = nullptr;
|
||||
|
||||
private:
|
||||
SampleMatrix(Kind kind, String expression)
|
||||
: fOwner(nullptr)
|
||||
, fKind(kind)
|
||||
, fExpression(expression) {}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
@ -148,7 +148,7 @@ public:
|
||||
GrSurfaceProxy::UseAllocator::kYes);
|
||||
auto atlasEffect = GrTextureEffect::Make({fLazyProxy, kOrigin, readSwizzle},
|
||||
kPremul_SkAlphaType);
|
||||
this->registerChildProcessor(std::move(atlasEffect));
|
||||
this->registerChild(std::move(atlasEffect));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -110,13 +110,13 @@ private:
|
||||
TestFP(const SkTArray<GrSurfaceProxyView>& views)
|
||||
: INHERITED(kTestFP_ClassID, kNone_OptimizationFlags) {
|
||||
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)
|
||||
: 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()) {
|
||||
|
@ -126,7 +126,7 @@ private:
|
||||
|
||||
BlockInputFragmentProcessor(std::unique_ptr<GrFragmentProcessor> child)
|
||||
: INHERITED(kBlockInputFragmentProcessor_ClassID, kNone_OptimizationFlags) {
|
||||
this->registerChildProcessor(std::move(child));
|
||||
this->registerChild(std::move(child));
|
||||
}
|
||||
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {}
|
||||
|
@ -545,8 +545,8 @@ DEF_TEST(SkSLFPChildProcessors, r) {
|
||||
}
|
||||
)__SkSL__",
|
||||
/*expectedH=*/{
|
||||
"child1_index = this->registerChildProcessor(std::move(child1));",
|
||||
"child2_index = this->registerChildProcessor(std::move(child2));"
|
||||
"child1_index = this->registerChild(std::move(child1));",
|
||||
"child2_index = this->registerChild(std::move(child2));"
|
||||
},
|
||||
/*expectedCPP=*/{
|
||||
"SkString _sample149;\n",
|
||||
@ -576,8 +576,8 @@ DEF_TEST(SkSLFPChildProcessorsWithInput, r) {
|
||||
}
|
||||
)__SkSL__",
|
||||
/*expectedH=*/{
|
||||
"child1_index = this->registerChildProcessor(std::move(child1));",
|
||||
"child2_index = this->registerChildProcessor(std::move(child2));"
|
||||
"child1_index = this->registerChild(std::move(child1));",
|
||||
"child2_index = this->registerChild(std::move(child2));"
|
||||
},
|
||||
/*expectedCPP=*/{
|
||||
"SkString _input198(\"childIn\");",
|
||||
@ -605,7 +605,7 @@ DEF_TEST(SkSLFPChildProcessorWithInputExpression, r) {
|
||||
}
|
||||
)__SkSL__",
|
||||
/*expectedH=*/{
|
||||
"child_index = this->registerChildProcessor(std::move(child));",
|
||||
"child_index = this->registerChild(std::move(child));",
|
||||
},
|
||||
/*expectedCPP=*/{
|
||||
"SkString _input106 = SkStringPrintf(\"%s * half4(0.5)\", args.fInputColor);",
|
||||
@ -630,8 +630,8 @@ DEF_TEST(SkSLFPNestedChildProcessors, r) {
|
||||
}
|
||||
)__SkSL__",
|
||||
/*expectedH=*/{
|
||||
"child1_index = this->registerChildProcessor(std::move(child1));",
|
||||
"child2_index = this->registerChildProcessor(std::move(child2));"
|
||||
"child1_index = this->registerChild(std::move(child1));",
|
||||
"child2_index = this->registerChild(std::move(child2));"
|
||||
},
|
||||
/*expectedCPP=*/{
|
||||
"SkString _input177 = SkStringPrintf(\"%s * half4(0.5)\", args.fInputColor);",
|
||||
@ -664,7 +664,7 @@ DEF_TEST(SkSLFPChildFPAndGlobal, r) {
|
||||
}
|
||||
)__SkSL__",
|
||||
/*expectedH=*/{
|
||||
"child_index = this->registerChildProcessor(std::move(child));"
|
||||
"child_index = this->registerChild(std::move(child));"
|
||||
},
|
||||
/*expectedCPP=*/{
|
||||
"hasCap = sk_Caps.externalTextureSupport;",
|
||||
@ -702,7 +702,7 @@ DEF_TEST(SkSLFPChildProcessorInlineFieldAccess, r) {
|
||||
}
|
||||
)__SkSL__",
|
||||
/*expectedH=*/{
|
||||
"child_index = this->registerChildProcessor(std::move(child));"
|
||||
"child_index = this->registerChild(std::move(child));"
|
||||
},
|
||||
/*expectedCPP=*/{
|
||||
"fragBuilder->codeAppendf(\n"
|
||||
@ -738,7 +738,7 @@ DEF_TEST(SkSLFPChildProcessorFieldAccess, r) {
|
||||
}
|
||||
)__SkSL__",
|
||||
/*expectedH=*/{
|
||||
"child_index = this->registerChildProcessor(std::move(child));"
|
||||
"child_index = this->registerChild(std::move(child));"
|
||||
},
|
||||
/*expectedCPP=*/{
|
||||
"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);
|
||||
}
|
||||
)__SkSL__",
|
||||
/*expectedH=*/{},
|
||||
/*expectedH=*/{
|
||||
"child_index = this->registerExplicitlySampledChild(std::move(child));"
|
||||
},
|
||||
/*expectedCPP=*/{
|
||||
"SkString _sample150;\n",
|
||||
"_sample150 = this->invokeChild(_outer.child_index, args);\n",
|
||||
|
Loading…
Reference in New Issue
Block a user