Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: src/gpu/glsl/GrGLSLFragmentProcessor.cpp

Issue 2339203002: Stop flattening GrCoordTransforms in parent GrFragmentProcessors. (Closed)
Patch Set: cleanup Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "GrGLSLFragmentProcessor.h" 8 #include "GrGLSLFragmentProcessor.h"
9 #include "GrFragmentProcessor.h" 9 #include "GrFragmentProcessor.h"
10 #include "GrProcessor.h" 10 #include "GrProcessor.h"
(...skipping 25 matching lines...) Expand all
36 36
37 void GrGLSLFragmentProcessor::internalEmitChild(int childIndex, const char* inpu tColor, 37 void GrGLSLFragmentProcessor::internalEmitChild(int childIndex, const char* inpu tColor,
38 const char* outputColor, EmitArg s& args) { 38 const char* outputColor, EmitArg s& args) {
39 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; 39 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
40 40
41 fragBuilder->onBeforeChildProcEmitCode(); // call first so mangleString is updated 41 fragBuilder->onBeforeChildProcEmitCode(); // call first so mangleString is updated
42 42
43 const GrFragmentProcessor& childProc = args.fFp.childProcessor(childIndex); 43 const GrFragmentProcessor& childProc = args.fFp.childProcessor(childIndex);
44 44
45 /* 45 /*
46 * We now want to find the subset of coords and samplers that belong to the child and its 46 * TODO: Move textures and buffers to the iterator model used by coords.
47 * descendants and put that into childCoords and childSamplers. To do so, we 'll do a forwards 47 * We now want to find the subset of samplers that belong to the child and i ts descendants and
48 * linear search. 48 * put that into childSamplers. To do so, we'll do a forwards linear search.
49 * 49 *
50 * Explanation: 50 * Explanation:
51 * Each GrFragmentProcessor has a copy of all the transforms and textures of itself and 51 * Each GrFragmentProcessor has a copy of all the textures of itself and all procs in its
52 * all procs in its subtree. For example, suppose we have frag proc A, who h as two children B 52 * subtree. For example, suppose we have frag proc A, who has two children B and D. B has a
53 * and D. B has a child C, and D has two children E and F. Each frag proc's transforms array 53 * child C, and D has two children E and F. Each frag proc's textures array contains its own
54 * contains its own transforms, followed by the transforms of all its descen dants (i.e. preorder 54 * textures, followed by the textures of all its descendants (i.e. preorder traversal). Suppose
55 * traversal). Suppose procs A, B, C, D, E, F have 1, 2, 1, 1, 3, 2 transfor ms respectively. 55 * procs A, B, C, D, E, F have 1, 2, 1, 1, 3, 2 textures respectively.
56 * 56 *
57 * (A) 57 * (A)
58 * [a1,b1,b2,c1,d1,e1,e2,e3,f1,f2] 58 * [a1,b1,b2,c1,d1,e1,e2,e3,f1,f2]
59 * / \ 59 * / \
60 * / \ 60 * / \
61 * (B) (D) 61 * (B) (D)
62 * [b1,b2,c1] [d1,e1,e2,e3,f1,f2] 62 * [b1,b2,c1] [d1,e1,e2,e3,f1,f2]
63 * / / \ 63 * / / \
64 * / / \ 64 * / / \
65 * (C) (E) (F) 65 * (C) (E) (F)
66 * [c1] [e1,e2,e3] [f1,f2] 66 * [c1] [e1,e2,e3] [f1,f2]
67 * 67 *
68 * So if we're inside proc A's emitCode, and A is about to call emitCode on proc D, we want the 68 * So if we're inside proc A's emitCode, and A is about to call emitCode on proc D, we want the
69 * EmitArgs that's passed onto D to only contain its and its descendants' co ords. The 69 * EmitArgs that's passed onto D to only contain its and its descendants' te xtures. The
70 * EmitArgs given to A would contain the transforms [a1,b1,b2,c1,d1,e1,e2,e3 ,f1,f2], and we want 70 * EmitArgs given to A would contain the textures [a1,b1,b2,c1,d1,e1,e2,e3,f 1,f2], and we want
71 * to extract the subset [d1,e1,e2,e3,f1,f2] to pass on to D. We can do this with a linear 71 * to extract the subset [d1,e1,e2,e3,f1,f2] to pass on to D. We can do this with a linear
72 * search since we know that A has 1 transform (using A.numTransformsExclChi ldren()), and B's 72 * search since we know that A has 1 texture (using A.numTexturesExclChildre n()), and B's
73 * subtree has 3 transforms (using B.numTransforms()), so we know the start of D's transforms is 73 * subtree has 3 textures (using B.numTextures()), so we know the start of D 's textures is
74 * 4 after the start of A's transforms. 74 * 4 after the start of A's textures.
75 * Textures work the same way as transforms. 75 * Textures work the same way as textures.
76 */ 76 */
77 int firstCoordAt = args.fFp.numTransformsExclChildren();
78 int firstTextureAt = args.fFp.numTexturesExclChildren(); 77 int firstTextureAt = args.fFp.numTexturesExclChildren();
79 int firstBufferAt = args.fFp.numBuffersExclChildren(); 78 int firstBufferAt = args.fFp.numBuffersExclChildren();
80 for (int i = 0; i < childIndex; ++i) { 79 for (int i = 0; i < childIndex; ++i) {
81 firstCoordAt += args.fFp.childProcessor(i).numTransforms();
82 firstTextureAt += args.fFp.childProcessor(i).numTextures(); 80 firstTextureAt += args.fFp.childProcessor(i).numTextures();
83 firstBufferAt += args.fFp.childProcessor(i).numBuffers(); 81 firstBufferAt += args.fFp.childProcessor(i).numBuffers();
84 } 82 }
85 SkTArray<GrShaderVar> childCoords;
86 const SamplerHandle* childTexSamplers = nullptr; 83 const SamplerHandle* childTexSamplers = nullptr;
87 const SamplerHandle* childBufferSamplers = nullptr; 84 const SamplerHandle* childBufferSamplers = nullptr;
88 if (childProc.numTransforms() > 0) {
89 childCoords.push_back_n(childProc.numTransforms(), &args.fTransformedCoo rds[firstCoordAt]);
90 }
91 if (childProc.numTextures() > 0) { 85 if (childProc.numTextures() > 0) {
92 childTexSamplers = &args.fTexSamplers[firstTextureAt]; 86 childTexSamplers = &args.fTexSamplers[firstTextureAt];
93 } 87 }
94 if (childProc.numBuffers() > 0) { 88 if (childProc.numBuffers() > 0) {
95 childBufferSamplers = &args.fBufferSamplers[firstBufferAt]; 89 childBufferSamplers = &args.fBufferSamplers[firstBufferAt];
96 } 90 }
97 91
98 // emit the code for the child in its own scope 92 // emit the code for the child in its own scope
99 fragBuilder->codeAppend("{\n"); 93 fragBuilder->codeAppend("{\n");
100 fragBuilder->codeAppendf("// Child Index %d (mangle: %s): %s\n", childIndex, 94 fragBuilder->codeAppendf("// Child Index %d (mangle: %s): %s\n", childIndex,
101 fragBuilder->getMangleString().c_str(), childProc.n ame()); 95 fragBuilder->getMangleString().c_str(), childProc.n ame());
102 EmitArgs childArgs(fragBuilder, 96 EmitArgs childArgs(fragBuilder,
103 args.fUniformHandler, 97 args.fUniformHandler,
104 args.fGLSLCaps, 98 args.fGLSLCaps,
105 childProc, 99 childProc,
106 outputColor, 100 outputColor,
107 inputColor, 101 inputColor,
108 childCoords, 102 args.fTransformedCoords.childTransforms(childIndex),
109 childTexSamplers, 103 childTexSamplers,
110 childBufferSamplers, 104 childBufferSamplers,
111 args.fGpImplementsDistanceVector); 105 args.fGpImplementsDistanceVector);
112 this->childProcessor(childIndex)->emitCode(childArgs); 106 this->childProcessor(childIndex)->emitCode(childArgs);
113 fragBuilder->codeAppend("}\n"); 107 fragBuilder->codeAppend("}\n");
114 108
115 fragBuilder->onAfterChildProcEmitCode(); 109 fragBuilder->onAfterChildProcEmitCode();
116 } 110 }
111
112 //////////////////////////////////////////////////////////////////////////////
113
114 using TransformedCoordVars = GrGLSLFragmentProcessor::TransformedCoordVars;
115 TransformedCoordVars TransformedCoordVars::childTransforms(int childIdx) const {
116 const GrFragmentProcessor* child = &fFP->childProcessor(childIdx);
117 GrFragmentProcessor::Iter iter(fFP);
118 int numToSkip = 0;
119 while (true) {
120 const GrFragmentProcessor* fp = iter.next();
121 if (fp == child) {
122 return TransformedCoordVars(child, fTransformedVars + numToSkip);
123 }
124 numToSkip += fp->numCoordTransforms();
125 }
126 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698