Index: src/gpu/glsl/GrGLSLFragmentProcessor.cpp |
diff --git a/src/gpu/glsl/GrGLSLFragmentProcessor.cpp b/src/gpu/glsl/GrGLSLFragmentProcessor.cpp |
index 9a58db77bd6cd1430f58bd8f7097b00fbbe36e6a..82a07ca39d819a88292f9ae1710f6a779b0dd1df 100644 |
--- a/src/gpu/glsl/GrGLSLFragmentProcessor.cpp |
+++ b/src/gpu/glsl/GrGLSLFragmentProcessor.cpp |
@@ -43,16 +43,16 @@ void GrGLSLFragmentProcessor::internalEmitChild(int childIndex, const char* inpu |
const GrFragmentProcessor& childProc = args.fFp.childProcessor(childIndex); |
/* |
- * 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 |
- * linear search. |
+ * TODO: Move textures and buffers to the iterator model used by coords. |
+ * We now want to find the subset of samplers that belong to the child and its descendants and |
+ * put that into childSamplers. To do so, we'll do a forwards linear search. |
* |
* Explanation: |
- * Each GrFragmentProcessor has a copy of all the transforms and textures of itself and |
- * all procs in its subtree. For example, suppose we have frag proc A, who has two children B |
- * and D. B has a child C, and D has two children E and F. Each frag proc's transforms array |
- * contains its own transforms, followed by the transforms of all its descendants (i.e. preorder |
- * traversal). Suppose procs A, B, C, D, E, F have 1, 2, 1, 1, 3, 2 transforms respectively. |
+ * Each GrFragmentProcessor has a copy of all the textures of itself and all procs in its |
+ * subtree. For example, suppose we have frag proc A, who has two children B and D. B has a |
+ * child C, and D has two children E and F. Each frag proc's textures array contains its own |
+ * textures, followed by the textures of all its descendants (i.e. preorder traversal). Suppose |
+ * procs A, B, C, D, E, F have 1, 2, 1, 1, 3, 2 textures respectively. |
* |
* (A) |
* [a1,b1,b2,c1,d1,e1,e2,e3,f1,f2] |
@@ -66,28 +66,22 @@ void GrGLSLFragmentProcessor::internalEmitChild(int childIndex, const char* inpu |
* [c1] [e1,e2,e3] [f1,f2] |
* |
* So if we're inside proc A's emitCode, and A is about to call emitCode on proc D, we want the |
- * EmitArgs that's passed onto D to only contain its and its descendants' coords. The |
- * EmitArgs given to A would contain the transforms [a1,b1,b2,c1,d1,e1,e2,e3,f1,f2], and we want |
+ * EmitArgs that's passed onto D to only contain its and its descendants' textures. The |
+ * EmitArgs given to A would contain the textures [a1,b1,b2,c1,d1,e1,e2,e3,f1,f2], and we want |
* to extract the subset [d1,e1,e2,e3,f1,f2] to pass on to D. We can do this with a linear |
- * search since we know that A has 1 transform (using A.numTransformsExclChildren()), and B's |
- * subtree has 3 transforms (using B.numTransforms()), so we know the start of D's transforms is |
- * 4 after the start of A's transforms. |
- * Textures work the same way as transforms. |
+ * search since we know that A has 1 texture (using A.numTexturesExclChildren()), and B's |
+ * subtree has 3 textures (using B.numTextures()), so we know the start of D's textures is |
+ * 4 after the start of A's textures. |
+ * Textures work the same way as textures. |
*/ |
- int firstCoordAt = args.fFp.numTransformsExclChildren(); |
int firstTextureAt = args.fFp.numTexturesExclChildren(); |
int firstBufferAt = args.fFp.numBuffersExclChildren(); |
for (int i = 0; i < childIndex; ++i) { |
- firstCoordAt += args.fFp.childProcessor(i).numTransforms(); |
firstTextureAt += args.fFp.childProcessor(i).numTextures(); |
firstBufferAt += args.fFp.childProcessor(i).numBuffers(); |
} |
- SkTArray<GrShaderVar> childCoords; |
const SamplerHandle* childTexSamplers = nullptr; |
const SamplerHandle* childBufferSamplers = nullptr; |
- if (childProc.numTransforms() > 0) { |
- childCoords.push_back_n(childProc.numTransforms(), &args.fTransformedCoords[firstCoordAt]); |
- } |
if (childProc.numTextures() > 0) { |
childTexSamplers = &args.fTexSamplers[firstTextureAt]; |
} |
@@ -99,13 +93,14 @@ void GrGLSLFragmentProcessor::internalEmitChild(int childIndex, const char* inpu |
fragBuilder->codeAppend("{\n"); |
fragBuilder->codeAppendf("// Child Index %d (mangle: %s): %s\n", childIndex, |
fragBuilder->getMangleString().c_str(), childProc.name()); |
+ TransformedCoordVars coordVars = args.fTransformedCoords.childTransforms(childIndex); |
EmitArgs childArgs(fragBuilder, |
args.fUniformHandler, |
args.fGLSLCaps, |
childProc, |
outputColor, |
inputColor, |
- childCoords, |
+ coordVars, |
childTexSamplers, |
childBufferSamplers, |
args.fGpImplementsDistanceVector); |
@@ -114,3 +109,19 @@ void GrGLSLFragmentProcessor::internalEmitChild(int childIndex, const char* inpu |
fragBuilder->onAfterChildProcEmitCode(); |
} |
+ |
+////////////////////////////////////////////////////////////////////////////// |
+ |
+using TransformedCoordVars = GrGLSLFragmentProcessor::TransformedCoordVars; |
+TransformedCoordVars TransformedCoordVars::childTransforms(int childIdx) const { |
+ const GrFragmentProcessor* child = &fFP->childProcessor(childIdx); |
+ GrFragmentProcessor::Iter iter(fFP); |
+ int numToSkip = 0; |
+ while (true) { |
+ const GrFragmentProcessor* fp = iter.next(); |
+ if (fp == child) { |
+ return TransformedCoordVars(child, fTransformedVars + numToSkip); |
+ } |
+ numToSkip += fp->numCoordTransforms(); |
+ } |
+} |