| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrGLFragmentProcessor.h" | 8 #include "GrGLFragmentProcessor.h" |
| 9 #include "GrFragmentProcessor.h" | 9 #include "GrFragmentProcessor.h" |
| 10 #include "builders/GrGLFragmentShaderBuilder.h" | 10 #include "builders/GrGLFragmentShaderBuilder.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 fb->onBeforeChildProcEmitCode(); // call first so mangleString is updated | 25 fb->onBeforeChildProcEmitCode(); // call first so mangleString is updated |
| 26 | 26 |
| 27 const GrFragmentProcessor& childProc = args.fFp.childProcessor(childIndex); | 27 const GrFragmentProcessor& childProc = args.fFp.childProcessor(childIndex); |
| 28 | 28 |
| 29 // Mangle the name of the outputColor | 29 // Mangle the name of the outputColor |
| 30 outputColor->set(args.fOutputColor); | 30 outputColor->set(args.fOutputColor); |
| 31 outputColor->append(fb->getMangleStringThisLevel()); | 31 outputColor->append(fb->getMangleStringThisLevel()); |
| 32 | 32 |
| 33 /* | 33 /* |
| 34 * We now want to find the subset of coords and samplers that belong to the
child and its | 34 * We now want to find the subset of coords and samplers that belong to the
child and its |
| 35 * descendants and put that into childCoords and childSamplers. To do so, we
must do a | 35 * descendants and put that into childCoords and childSamplers. To do so, we
'll do a forwards |
| 36 * backwards linear search on coords and samplers. | 36 * linear search. |
| 37 * | 37 * |
| 38 * Explanation: | 38 * Explanation: |
| 39 * Each GrFragmentProcessor has a copy of all the transforms and textures of
itself and | 39 * Each GrFragmentProcessor has a copy of all the transforms and textures of
itself and |
| 40 * all procs in its subtree. For example, suppose we have frag proc A, who h
as two children B | 40 * all procs in its subtree. For example, suppose we have frag proc A, who h
as two children B |
| 41 * and D. B has a child C, and D has two children E and F. Each frag proc's
transforms array | 41 * and D. B has a child C, and D has two children E and F. Each frag proc's
transforms array |
| 42 * contains its own transforms, followed by the transforms of all its descen
dants (i.e. preorder | 42 * contains its own transforms, followed by the transforms of all its descen
dants (i.e. preorder |
| 43 * traversal). Suppose procs A, B, C, D, E, F have 1, 2, 1, 1, 3, 2 transfor
ms respectively. | 43 * traversal). Suppose procs A, B, C, D, E, F have 1, 2, 1, 1, 3, 2 transfor
ms respectively. |
| 44 * | 44 * |
| 45 * (A) | 45 * (A) |
| 46 * [a1,b1,b2,c1,d1,e1,e2,e3,f1,f2] | 46 * [a1,b1,b2,c1,d1,e1,e2,e3,f1,f2] |
| 47 * / \ | 47 * / \ |
| 48 * / \ | 48 * / \ |
| 49 * (B) (D) | 49 * (B) (D) |
| 50 * [b1,b2,c1] [d1,e1,e2,e3,f1,f2] | 50 * [b1,b2,c1] [d1,e1,e2,e3,f1,f2] |
| 51 * / / \ | 51 * / / \ |
| 52 * / / \ | 52 * / / \ |
| 53 * (C) (E) (F) | 53 * (C) (E) (F) |
| 54 * [c1] [e1,e2,e3] [f1,f2] | 54 * [c1] [e1,e2,e3] [f1,f2] |
| 55 * | 55 * |
| 56 * So if we're inside proc A's emitCode, and A is about to call emitCode on
proc B, we want the | 56 * So if we're inside proc A's emitCode, and A is about to call emitCode on
proc D, we want the |
| 57 * EmitArgs that's passed onto B to only contain its and its descendants' co
ords. The | 57 * EmitArgs that's passed onto D to only contain its and its descendants' co
ords. The |
| 58 * EmitArgs given to A would contain the transforms [a1,b1,b2,c1,d1,e1,e2,e3
,f1,f2], and we want | 58 * EmitArgs given to A would contain the transforms [a1,b1,b2,c1,d1,e1,e2,e3
,f1,f2], and we want |
| 59 * to extract the subset [b1,b2,c1] to pass on to B. We can do this with a b
ackwards linear | 59 * to extract the subset [d1,e1,e2,e3,f1,f2] to pass on to D. We can do this
with a linear |
| 60 * search since we know that D's subtree has 6 transforms and B's subtree ha
s 3 transforms (by | 60 * search since we know that A has 1 transform (using A.numTransformsExclChi
ldren()), and B's |
| 61 * calling D.numTextures() and B.numTextures()), so we know the start of B's
transforms is 9 | 61 * subtree has 3 transforms (using B.numTransforms()), so we know the start
of D's transforms is |
| 62 * from the end of A's transforms. We cannot do this with a forwards linear
search since we | 62 * 4 after the start of A's transforms. |
| 63 * don't know how many transforms belong to A (A.numTextures() will return 1
0, not 1), so | |
| 64 * we wouldn't know how many transforms to initially skip in A's array if us
ing a forward linear | |
| 65 * search. | |
| 66 * Textures work the same way as transforms. | 63 * Textures work the same way as transforms. |
| 67 */ | 64 */ |
| 68 int firstCoordAt = args.fFp.numTransforms(); | 65 int firstCoordAt = args.fFp.numTransformsExclChildren(); |
| 69 int firstSamplerAt = args.fFp.numTextures(); | 66 int firstSamplerAt = args.fFp.numTexturesExclChildren(); |
| 70 for (int i = args.fFp.numChildProcessors() - 1; i >= childIndex; --i) { | 67 for (int i = 0; i < childIndex; ++i) { |
| 71 firstCoordAt -= args.fFp.childProcessor(i).numTransforms(); | 68 firstCoordAt += args.fFp.childProcessor(i).numTransforms(); |
| 72 firstSamplerAt -= args.fFp.childProcessor(i).numTextures(); | 69 firstSamplerAt += args.fFp.childProcessor(i).numTextures(); |
| 73 } | 70 } |
| 74 TransformedCoordsArray childCoords; | 71 TransformedCoordsArray childCoords; |
| 75 TextureSamplerArray childSamplers; | 72 TextureSamplerArray childSamplers; |
| 76 if (childProc.numTransforms() > 0) { | 73 if (childProc.numTransforms() > 0) { |
| 77 childCoords.push_back_n(childProc.numTransforms(), &args.fCoords[firstCo
ordAt]); | 74 childCoords.push_back_n(childProc.numTransforms(), &args.fCoords[firstCo
ordAt]); |
| 78 } | 75 } |
| 79 if (childProc.numTextures() > 0) { | 76 if (childProc.numTextures() > 0) { |
| 80 childSamplers.push_back_n(childProc.numTextures(), &args.fSamplers[first
SamplerAt]); | 77 childSamplers.push_back_n(childProc.numTextures(), &args.fSamplers[first
SamplerAt]); |
| 81 } | 78 } |
| 82 | 79 |
| 83 // emit the code for the child in its own scope | 80 // emit the code for the child in its own scope |
| 84 fb->codeAppendf("vec4 %s;\n", outputColor->c_str()); | 81 fb->codeAppendf("vec4 %s;\n", outputColor->c_str()); |
| 85 fb->codeAppend("{\n"); | 82 fb->codeAppend("{\n"); |
| 86 fb->codeAppendf("// Child Index %d (mangle: %s): %s\n", childIndex, | 83 fb->codeAppendf("// Child Index %d (mangle: %s): %s\n", childIndex, |
| 87 fb->getMangleString().c_str(), childProc.name()); | 84 fb->getMangleString().c_str(), childProc.name()); |
| 88 EmitArgs childArgs(args.fBuilder, | 85 EmitArgs childArgs(args.fBuilder, |
| 89 childProc, | 86 childProc, |
| 90 outputColor->c_str(), | 87 outputColor->c_str(), |
| 91 inputColor, | 88 inputColor, |
| 92 childCoords, | 89 childCoords, |
| 93 childSamplers); | 90 childSamplers); |
| 94 this->childProcessor(childIndex)->emitCode(childArgs); | 91 this->childProcessor(childIndex)->emitCode(childArgs); |
| 95 fb->codeAppend("}\n"); | 92 fb->codeAppend("}\n"); |
| 96 | 93 |
| 97 fb->onAfterChildProcEmitCode(); | 94 fb->onAfterChildProcEmitCode(); |
| 98 } | 95 } |
| OLD | NEW |