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

Side by Side Diff: include/gpu/GrFragmentProcessor.h

Issue 2365943003: Stop aggregating texture/buffer access objects in GrFragmentProcessor parents. (Closed)
Patch Set: Readd base class, rebase Created 4 years, 2 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 | « no previous file | src/effects/gradients/SkGradientShader.cpp » ('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 2014 Google Inc. 2 * Copyright 2014 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 #ifndef GrFragmentProcessor_DEFINED 8 #ifndef GrFragmentProcessor_DEFINED
9 #define GrFragmentProcessor_DEFINED 9 #define GrFragmentProcessor_DEFINED
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 * second, etc. The output of the returned processor is the output of the la st processor of the 60 * second, etc. The output of the returned processor is the output of the la st processor of the
61 * series. 61 * series.
62 * 62 *
63 * The array elements with be moved. 63 * The array elements with be moved.
64 */ 64 */
65 static sk_sp<GrFragmentProcessor> RunInSeries(sk_sp<GrFragmentProcessor>*, i nt cnt); 65 static sk_sp<GrFragmentProcessor> RunInSeries(sk_sp<GrFragmentProcessor>*, i nt cnt);
66 66
67 GrFragmentProcessor() 67 GrFragmentProcessor()
68 : INHERITED() 68 : INHERITED()
69 , fUsesDistanceVectorField(false) 69 , fUsesDistanceVectorField(false)
70 , fUsesLocalCoords(false) 70 , fUsesLocalCoords(false) {}
71 , fNumTexturesExclChildren(0)
72 , fNumBuffersExclChildren(0) {}
73 71
74 ~GrFragmentProcessor() override; 72 ~GrFragmentProcessor() override;
75 73
76 GrGLSLFragmentProcessor* createGLSLInstance() const; 74 GrGLSLFragmentProcessor* createGLSLInstance() const;
77 75
78 void getGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c onst { 76 void getGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c onst {
79 this->onGetGLSLProcessorKey(caps, b); 77 this->onGetGLSLProcessorKey(caps, b);
80 for (int i = 0; i < fChildProcessors.count(); ++i) { 78 for (int i = 0; i < fChildProcessors.count(); ++i) {
81 fChildProcessors[i]->getGLSLProcessorKey(caps, b); 79 fChildProcessors[i]->getGLSLProcessorKey(caps, b);
82 } 80 }
83 } 81 }
84 82
85 int numTexturesExclChildren() const { return fNumTexturesExclChildren; }
86
87 int numBuffersExclChildren() const { return fNumBuffersExclChildren; }
88
89 int numCoordTransforms() const { return fCoordTransforms.count(); } 83 int numCoordTransforms() const { return fCoordTransforms.count(); }
90 84
91 /** Returns the coordinate transformation at index. index must be valid acco rding to 85 /** Returns the coordinate transformation at index. index must be valid acco rding to
92 numTransforms(). */ 86 numTransforms(). */
93 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran sforms[index]; } 87 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran sforms[index]; }
94 88
95 const SkTArray<const GrCoordTransform*, true>& coordTransforms() const { 89 const SkTArray<const GrCoordTransform*, true>& coordTransforms() const {
96 return fCoordTransforms; 90 return fCoordTransforms;
97 } 91 }
98 92
99 void gatherCoordTransforms(SkTArray<const GrCoordTransform*, true>* outTrans forms) const {
100 if (!fCoordTransforms.empty()) {
101 outTransforms->push_back_n(fCoordTransforms.count(), fCoordTransform s.begin());
102 }
103 }
104
105 int numChildProcessors() const { return fChildProcessors.count(); } 93 int numChildProcessors() const { return fChildProcessors.count(); }
106 94
107 const GrFragmentProcessor& childProcessor(int index) const { return *fChildP rocessors[index]; } 95 const GrFragmentProcessor& childProcessor(int index) const { return *fChildP rocessors[index]; }
108 96
109 /** Do any of the coordtransforms for this processor require local coords? * / 97 /** Do any of the coordtransforms for this processor require local coords? * /
110 bool usesLocalCoords() const { return fUsesLocalCoords; } 98 bool usesLocalCoords() const { return fUsesLocalCoords; }
111 99
112 /** Does this FP need a vector to the nearest edge? */ 100 /** Does this FP need a vector to the nearest edge? */
113 bool usesDistanceVectorField() const { return fUsesDistanceVectorField; } 101 bool usesDistanceVectorField() const { return fUsesDistanceVectorField; }
114 102
(...skipping 14 matching lines...) Expand all
129 * inout to indicate known values of its output. A component of the color me mber only has 117 * inout to indicate known values of its output. A component of the color me mber only has
130 * meaning if the corresponding bit in validFlags is set. 118 * meaning if the corresponding bit in validFlags is set.
131 */ 119 */
132 void computeInvariantOutput(GrInvariantOutput* inout) const { 120 void computeInvariantOutput(GrInvariantOutput* inout) const {
133 this->onComputeInvariantOutput(inout); 121 this->onComputeInvariantOutput(inout);
134 } 122 }
135 123
136 /** 124 /**
137 * Pre-order traversal of a FP hierarchy, or of the forest of FPs in a GrPip eline. In the latter 125 * Pre-order traversal of a FP hierarchy, or of the forest of FPs in a GrPip eline. In the latter
138 * case the tree rooted at each FP in the GrPipeline is visited successively . 126 * case the tree rooted at each FP in the GrPipeline is visited successively .
139 * */ 127 */
140 class Iter : public SkNoncopyable { 128 class Iter : public SkNoncopyable {
141 public: 129 public:
142 explicit Iter(const GrFragmentProcessor* fp) { fFPStack.push_back(fp); } 130 explicit Iter(const GrFragmentProcessor* fp) { fFPStack.push_back(fp); }
143 explicit Iter(const GrPipeline& pipeline); 131 explicit Iter(const GrPipeline& pipeline);
144 const GrFragmentProcessor* next(); 132 const GrFragmentProcessor* next();
145 133
146 private: 134 private:
147 SkSTArray<4, const GrFragmentProcessor*, true> fFPStack; 135 SkSTArray<4, const GrFragmentProcessor*, true> fFPStack;
148 }; 136 };
149 137
150 /** 138 /**
151 * Iterates over all the GrCoordTransforms in a GrPipeline's GrFragmentProce ssors. FPs are 139 * Iterates over all the Ts owned by a GrFragmentProcessor and its children or over all the Ts
152 * visited in the same order as Iter and each of an FP's coord transforms ar e visited linearly. 140 * owned by the forest of GrFragmentProcessors in a GrPipeline. FPs are visi ted in the same
141 * order as Iter and each of an FP's Ts are visited in order.
153 */ 142 */
154 class CoordTransformIter : public SkNoncopyable { 143 template <typename T, typename BASE,
144 int (BASE::*COUNT)() const,
145 const T& (BASE::*GET)(int) const>
146 class FPItemIter : public SkNoncopyable {
155 public: 147 public:
156 explicit CoordTransformIter(const GrPipeline& pipeline) 148 explicit FPItemIter(const GrFragmentProcessor* fp)
149 : fCurrFP(nullptr)
150 , fCTIdx(0)
151 , fFPIter(fp) {
152 fCurrFP = fFPIter.next();
153 }
154 explicit FPItemIter(const GrPipeline& pipeline)
157 : fCurrFP(nullptr) 155 : fCurrFP(nullptr)
158 , fCTIdx(0) 156 , fCTIdx(0)
159 , fFPIter(pipeline) { 157 , fFPIter(pipeline) {
160 fCurrFP = fFPIter.next(); 158 fCurrFP = fFPIter.next();
161 } 159 }
162 const GrCoordTransform* next(); 160
161 const T* next() {
162 if (!fCurrFP) {
163 return nullptr;
164 }
165 while (fCTIdx == (fCurrFP->*COUNT)()) {
166 fCTIdx = 0;
167 fCurrFP = fFPIter.next();
168 if (!fCurrFP) {
169 return nullptr;
170 }
171 }
172 return &(fCurrFP->*GET)(fCTIdx++);
173 }
163 174
164 private: 175 private:
165 const GrFragmentProcessor* fCurrFP; 176 const GrFragmentProcessor* fCurrFP;
166 int fCTIdx; 177 int fCTIdx;
167 GrFragmentProcessor::Iter fFPIter; 178 GrFragmentProcessor::Iter fFPIter;
168 }; 179 };
169 180
181 using CoordTransformIter = FPItemIter<GrCoordTransform,
182 GrFragmentProcessor,
183 &GrFragmentProcessor::numCoordTransfor ms,
184 &GrFragmentProcessor::coordTransform>;
185
186 using TextureAccessIter = FPItemIter<GrTextureAccess,
187 GrProcessor,
188 &GrProcessor::numTextures,
189 &GrProcessor::textureAccess>;
190
170 protected: 191 protected:
171 void addTextureAccess(const GrTextureAccess* textureAccess) override; 192 void addTextureAccess(const GrTextureAccess* textureAccess) override;
172 void addBufferAccess(const GrBufferAccess*) override; 193 void addBufferAccess(const GrBufferAccess*) override;
173 194
174 /** 195 /**
175 * Fragment Processor subclasses call this from their constructor to registe r coordinate 196 * Fragment Processor subclasses call this from their constructor to registe r coordinate
176 * transformations. Coord transforms provide a mechanism for a processor to receive coordinates 197 * transformations. Coord transforms provide a mechanism for a processor to receive coordinates
177 * in their FS code. The matrix expresses a transformation from local space. For a given 198 * in their FS code. The matrix expresses a transformation from local space. For a given
178 * fragment the matrix will be applied to the local coordinate that maps to the fragment. 199 * fragment the matrix will be applied to the local coordinate that maps to the fragment.
179 * 200 *
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 */ 255 */
235 virtual bool onIsEqual(const GrFragmentProcessor&) const = 0; 256 virtual bool onIsEqual(const GrFragmentProcessor&) const = 0;
236 257
237 bool hasSameTransforms(const GrFragmentProcessor&) const; 258 bool hasSameTransforms(const GrFragmentProcessor&) const;
238 259
239 bool fUsesLocalCoords; 260 bool fUsesLocalCoords;
240 261
241 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; 262 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms;
242 263
243 /** 264 /**
244 * A processor stores the texture accesses of this proc, followed by all the accesses of this
245 * proc's children. In other words, each proc stores all the accesses of its subtree as if
246 * they were collected using preorder traversal.
247 *
248 * Example:
249 * Suppose we have frag proc A, who has two children B and D. B has a child C, and D has
250 * two children E and F. Suppose procs A, B, C, D, E, F have 1, 2, 1, 1, 3, 2 accesses
251 * respectively. The following shows what the array of each proc's texture a ccesses would
252 * contain:
253 *
254 * (A)
255 * [a1,b1,b2,c1,d1,e1,e2,e3,f1,f2]
256 * / \
257 * / \
258 * (B) (D)
259 * [b1,b2,c1] [d1,e1,e2,e3,f1,f2]
260 * / / \
261 * / / \
262 * (C) (E) (F)
263 * [c1] [e1,e2,e3] [f1,f2]
264 *
265 * The same goes for buffer accesses.
266 */
267 int fNumTexturesExclChildren;
268 int fNumBuffersExclChildren;
269
270 /**
271 * This is not SkSTArray<1, sk_sp<GrFragmentProcessor>> because this class h olds strong 265 * This is not SkSTArray<1, sk_sp<GrFragmentProcessor>> because this class h olds strong
272 * references until notifyRefCntIsZero and then it holds pending executions. 266 * references until notifyRefCntIsZero and then it holds pending executions.
273 */ 267 */
274 SkSTArray<1, GrFragmentProcessor*, true> fChildProcessors; 268 SkSTArray<1, GrFragmentProcessor*, true> fChildProcessors;
275 269
276 typedef GrProcessor INHERITED; 270 typedef GrProcessor INHERITED;
277 }; 271 };
278 272
279 #endif 273 #endif
OLDNEW
« no previous file with comments | « no previous file | src/effects/gradients/SkGradientShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698