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

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

Issue 2339203002: Stop flattening GrCoordTransforms in parent GrFragmentProcessors. (Closed)
Patch Set: Fix issue of taking ref to a temporary 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
« no previous file with comments | « src/gpu/glsl/GrGLSLFragmentProcessor.h ('k') | src/gpu/glsl/GrGLSLGeometryProcessor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
96 TransformedCoordVars coordVars = args.fTransformedCoords.childTransforms(chi ldIndex);
102 EmitArgs childArgs(fragBuilder, 97 EmitArgs childArgs(fragBuilder,
103 args.fUniformHandler, 98 args.fUniformHandler,
104 args.fGLSLCaps, 99 args.fGLSLCaps,
105 childProc, 100 childProc,
106 outputColor, 101 outputColor,
107 inputColor, 102 inputColor,
108 childCoords, 103 coordVars,
109 childTexSamplers, 104 childTexSamplers,
110 childBufferSamplers, 105 childBufferSamplers,
111 args.fGpImplementsDistanceVector); 106 args.fGpImplementsDistanceVector);
112 this->childProcessor(childIndex)->emitCode(childArgs); 107 this->childProcessor(childIndex)->emitCode(childArgs);
113 fragBuilder->codeAppend("}\n"); 108 fragBuilder->codeAppend("}\n");
114 109
115 fragBuilder->onAfterChildProcEmitCode(); 110 fragBuilder->onAfterChildProcEmitCode();
116 } 111 }
112
113 //////////////////////////////////////////////////////////////////////////////
114
115 using TransformedCoordVars = GrGLSLFragmentProcessor::TransformedCoordVars;
116 TransformedCoordVars TransformedCoordVars::childTransforms(int childIdx) const {
117 const GrFragmentProcessor* child = &fFP->childProcessor(childIdx);
118 GrFragmentProcessor::Iter iter(fFP);
119 int numToSkip = 0;
120 while (true) {
121 const GrFragmentProcessor* fp = iter.next();
122 if (fp == child) {
123 return TransformedCoordVars(child, fTransformedVars + numToSkip);
124 }
125 numToSkip += fp->numCoordTransforms();
126 }
127 }
OLDNEW
« no previous file with comments | « src/gpu/glsl/GrGLSLFragmentProcessor.h ('k') | src/gpu/glsl/GrGLSLGeometryProcessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698