diff options
author | wangyix <wangyix@google.com> | 2015-09-08 08:41:51 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-08 08:41:51 -0700 |
commit | 54a6b1a1228489161294e4fa1fc8f93797cff259 (patch) | |
tree | d4663fe8b04109640be41d7b109e99c5eb285e52 /src/gpu/gl | |
parent | 43fe6185c5043247c47daa450b015e26d86728fe (diff) |
emitChild() used to generate a mangled outputColor based on the parent's outputColor; now it just accepts an outputColor string. It's now up to the programmer to declare outputColors if needed before emitting child code.
BUG=skia:4182
Review URL: https://codereview.chromium.org/1321253003
Diffstat (limited to 'src/gpu/gl')
-rw-r--r-- | src/gpu/gl/GrGLFragmentProcessor.cpp | 9 | ||||
-rw-r--r-- | src/gpu/gl/GrGLFragmentProcessor.h | 7 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp | 8 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLFragmentShaderBuilder.h | 18 |
4 files changed, 14 insertions, 28 deletions
diff --git a/src/gpu/gl/GrGLFragmentProcessor.cpp b/src/gpu/gl/GrGLFragmentProcessor.cpp index 078491a5bf..6d91c72fcf 100644 --- a/src/gpu/gl/GrGLFragmentProcessor.cpp +++ b/src/gpu/gl/GrGLFragmentProcessor.cpp @@ -20,16 +20,12 @@ void GrGLFragmentProcessor::setData(const GrGLProgramDataManager& pdman, } void GrGLFragmentProcessor::emitChild(int childIndex, const char* inputColor, - SkString* outputColor, EmitArgs& args) { + const char* outputColor, EmitArgs& args) { GrGLFragmentBuilder* fb = args.fBuilder->getFragmentShaderBuilder(); fb->onBeforeChildProcEmitCode(); // call first so mangleString is updated const GrFragmentProcessor& childProc = args.fFp.childProcessor(childIndex); - // Mangle the name of the outputColor - outputColor->set(args.fOutputColor); - outputColor->append(fb->getMangleStringThisLevel()); - /* * We now want to find the subset of coords and samplers that belong to the child and its * descendants and put that into childCoords and childSamplers. To do so, we'll do a forwards @@ -78,13 +74,12 @@ void GrGLFragmentProcessor::emitChild(int childIndex, const char* inputColor, } // emit the code for the child in its own scope - fb->codeAppendf("vec4 %s;\n", outputColor->c_str()); fb->codeAppend("{\n"); fb->codeAppendf("// Child Index %d (mangle: %s): %s\n", childIndex, fb->getMangleString().c_str(), childProc.name()); EmitArgs childArgs(args.fBuilder, childProc, - outputColor->c_str(), + outputColor, inputColor, childCoords, childSamplers); diff --git a/src/gpu/gl/GrGLFragmentProcessor.h b/src/gpu/gl/GrGLFragmentProcessor.h index b8e2afc1bb..e11d28b26b 100644 --- a/src/gpu/gl/GrGLFragmentProcessor.h +++ b/src/gpu/gl/GrGLFragmentProcessor.h @@ -80,7 +80,12 @@ public: return fChildProcessors[index]; } - void emitChild(int childIndex, const char* inputColor, SkString* outputColor, EmitArgs& args); + /** Will emit the code of a child proc in its own scope. Pass in the parent's EmitArgs and + * emitChild will automatically extract the coords and samplers of that child and pass them + * on to the child's emitCode(). Also, any uniforms or functions emitted by the child will + * have their names mangled to prevent redefinitions. + */ + void emitChild(int childIndex, const char* inputColor, const char* outputColor, EmitArgs& args); protected: /** A GrGLFragmentProcessor instance can be reused with any GrFragmentProcessor that produces diff --git a/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp b/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp index 20bb3a3893..a5b3a99ebe 100644 --- a/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp +++ b/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp @@ -302,13 +302,17 @@ void GrGLFragmentShaderBuilder::addVarying(GrGLVarying* v, GrSLPrecision fsPrec) } void GrGLFragmentBuilder::onBeforeChildProcEmitCode() { - fSubstageIndices.back()++; + SkASSERT(fSubstageIndices.count() >= 1); fSubstageIndices.push_back(0); - fMangleString.append(this->getMangleStringThisLevel()); + // second-to-last value in the fSubstageIndices stack is the index of the child proc + // at that level which is currently emitting code. + fMangleString.appendf("_c%d", fSubstageIndices[fSubstageIndices.count() - 2]); } void GrGLFragmentBuilder::onAfterChildProcEmitCode() { + SkASSERT(fSubstageIndices.count() >= 2); fSubstageIndices.pop_back(); + fSubstageIndices.back()++; int removeAt = fMangleString.findLastOf('_'); fMangleString.remove(removeAt, fMangleString.size() - removeAt); } diff --git a/src/gpu/gl/builders/GrGLFragmentShaderBuilder.h b/src/gpu/gl/builders/GrGLFragmentShaderBuilder.h index 912de0a645..4f17b68ae6 100644 --- a/src/gpu/gl/builders/GrGLFragmentShaderBuilder.h +++ b/src/gpu/gl/builders/GrGLFragmentShaderBuilder.h @@ -57,26 +57,8 @@ public: void onBeforeChildProcEmitCode(); void onAfterChildProcEmitCode(); - int getChildNumberThisLevel() const { - if (fSubstageIndices.count() > 1) { - // second-to-last value in the fSubstageIndices stack is the index of the child proc - // at that level which is currently emitting code. - return fSubstageIndices[fSubstageIndices.count() - 2]; - } - return -1; - } - const SkString& getMangleString() const { return fMangleString; } - SkString getMangleStringThisLevel() const { - SkString ret; - int childNumber = this->getChildNumberThisLevel(); - if (childNumber >= 0) { - ret.printf("_c%d", childNumber); - } - return ret; - } - private: /* * State that tracks which child proc in the proc tree is currently emitting code. This is |