@@ -22,13 +22,11 @@ class GrGLSLSkSLFP : public GrGLSLFragmentProcessor {
2222 GrGLSLSkSLFP (SkSL::PipelineStageArgs&& args) : fArgs (std::move(args)) {}
2323
2424 SkSL::String expandFormatArgs (const SkSL::String& raw,
25- const EmitArgs& args,
26- const std::vector<SkSL::Compiler::FormatArg> formatArgs,
27- const char * coordsName,
28- const std::vector<SkString>& childNames) {
25+ EmitArgs& args,
26+ std::vector<SkSL::Compiler::FormatArg>::const_iterator& fmtArg,
27+ const char * coordsName) {
2928 SkSL::String result;
3029 int substringStartIndex = 0 ;
31- int formatArgIndex = 0 ;
3230 for (size_t i = 0 ; i < raw.length (); ++i) {
3331 char c = raw[i];
3432 if (c == ' %' ) {
@@ -38,7 +36,7 @@ class GrGLSLSkSLFP : public GrGLSLFragmentProcessor {
3836 c = raw[i];
3937 switch (c) {
4038 case ' s' : {
41- const SkSL::Compiler::FormatArg& arg = formatArgs[formatArgIndex++] ;
39+ const SkSL::Compiler::FormatArg& arg = *fmtArg++ ;
4240 switch (arg.fKind ) {
4341 case SkSL::Compiler::FormatArg::Kind::kInput :
4442 result += args.fInputColor ;
@@ -58,9 +56,12 @@ class GrGLSLSkSLFP : public GrGLSLFragmentProcessor {
5856 result += args.fUniformHandler ->getUniformCStr (
5957 fUniformHandles [arg.fIndex ]);
6058 break ;
61- case SkSL::Compiler::FormatArg::Kind::kChildProcessor :
62- result += childNames[arg.fIndex ].c_str ();
59+ case SkSL::Compiler::FormatArg::Kind::kChildProcessor : {
60+ SkSL::String coords = this ->expandFormatArgs (arg.fCoords , args,
61+ fmtArg, coordsName);
62+ result += this ->invokeChild (arg.fIndex , args, coords).c_str ();
6363 break ;
64+ }
6465 case SkSL::Compiler::FormatArg::Kind::kFunctionName :
6566 SkASSERT ((int ) fFunctionNames .size () > arg.fIndex );
6667 result += fFunctionNames [arg.fIndex ].c_str ();
@@ -94,22 +95,28 @@ class GrGLSLSkSLFP : public GrGLSLFragmentProcessor {
9495 SkASSERT (args.fTransformedCoords .count () == 1 );
9596 SkString coords = fragBuilder->ensureCoords2D (args.fTransformedCoords [0 ].fVaryingPoint );
9697 std::vector<SkString> childNames;
98+ // We need to ensure that we call invokeChild on each child FP at least once.
99+ // Any child FP that isn't sampled won't trigger a call otherwise, leading to asserts later.
97100 for (int i = 0 ; i < this ->numChildProcessors (); ++i) {
98- childNames. push_back ( this ->invokeChild (i, args));
101+ ( void ) this ->invokeChild (i, args, SkSL::String ( " _coords " ));
99102 }
100103 for (const auto & f : fArgs .fFunctions ) {
101104 fFunctionNames .emplace_back ();
102- SkSL::String body = this ->expandFormatArgs (f.fBody .c_str (), args, f.fFormatArgs ,
103- coords.c_str (), childNames);
105+ auto fmtArgIter = f.fFormatArgs .cbegin ();
106+ SkSL::String body =
107+ this ->expandFormatArgs (f.fBody .c_str (), args, fmtArgIter, coords.c_str ());
108+ SkASSERT (fmtArgIter == f.fFormatArgs .cend ());
104109 fragBuilder->emitFunction (f.fReturnType ,
105110 f.fName .c_str (),
106111 f.fParameters .size (),
107112 f.fParameters .data (),
108113 body.c_str (),
109114 &fFunctionNames .back ());
110115 }
111- fragBuilder->codeAppend (this ->expandFormatArgs (fArgs .fCode .c_str (), args, fArgs .fFormatArgs ,
112- coords.c_str (), childNames).c_str ());
116+ auto fmtArgIter = fArgs .fFormatArgs .cbegin ();
117+ fragBuilder->codeAppend (this ->expandFormatArgs (fArgs .fCode .c_str (), args, fmtArgIter,
118+ coords.c_str ()).c_str ());
119+ SkASSERT (fmtArgIter == fArgs .fFormatArgs .cend ());
113120 }
114121
115122 void onSetData (const GrGLSLProgramDataManager& pdman,
@@ -198,6 +205,7 @@ const char* GrSkSLFP::name() const {
198205}
199206
200207void GrSkSLFP::addChild (std::unique_ptr<GrFragmentProcessor> child) {
208+ child->setSampledWithExplicitCoords (true );
201209 this ->registerChildProcessor (std::move (child));
202210}
203211
@@ -244,7 +252,7 @@ bool GrSkSLFP::onIsEqual(const GrFragmentProcessor& other) const {
244252std::unique_ptr<GrFragmentProcessor> GrSkSLFP::clone () const {
245253 std::unique_ptr<GrSkSLFP> result (new GrSkSLFP (*this ));
246254 for (int i = 0 ; i < this ->numChildProcessors (); ++i) {
247- result->registerChildProcessor (this ->childProcessor (i).clone ());
255+ result->addChild (this ->childProcessor (i).clone ());
248256 }
249257 return std::unique_ptr<GrFragmentProcessor>(result.release ());
250258}
0 commit comments