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

Side by Side Diff: src/gpu/GrGeometryProcessor.h

Issue 820783005: More changes to bring together path / geo procs (Closed) Base URL: https://skia.googlesource.com/skia.git@lc1
Patch Set: some asserts for safety Created 5 years, 11 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/gpu/GrInOrderDrawBuffer.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 2013 Google Inc. 2 * Copyright 2013 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 GrGeometryProcessor_DEFINED 8 #ifndef GrGeometryProcessor_DEFINED
9 #define GrGeometryProcessor_DEFINED 9 #define GrGeometryProcessor_DEFINED
10 10
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 /* 114 /*
115 * We always call canMakeEqual before makeEqual so there is no need to do an y kind of equality 115 * We always call canMakeEqual before makeEqual so there is no need to do an y kind of equality
116 * testing here 116 * testing here
117 * TODO make this pure virtual when primProcs can actually use it 117 * TODO make this pure virtual when primProcs can actually use it
118 */ 118 */
119 virtual void makeEqual(GrBatchTracker*, const GrBatchTracker&) const {} 119 virtual void makeEqual(GrBatchTracker*, const GrBatchTracker&) const {}
120 120
121 virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0; 121 virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0;
122 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const = 0; 122 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const = 0;
123 123
124 // Only the GrGeometryProcessor subclass actually has a geo shader or vertex attributes, but
125 // we put these calls on the base class to prevent having to cast
126 virtual bool willUseGeoShader() const = 0;
127
128 /*
129 * This is a safeguard to prevent GrPrimitiveProcessor's from going beyond p latform specific
130 * attribute limits. This number can almost certainly be raised if required.
131 */
132 static const int kMaxVertexAttribs = 6;
133
134 struct GrAttribute {
bsalomon 2015/01/13 14:31:44 Should just be "Attribute" if it is nested inside
135 GrAttribute(const char* name, GrVertexAttribType type)
136 : fName(name)
137 , fType(type)
138 , fOffset(SkAlign4(GrVertexAttribTypeSize(type))) {}
139 const char* fName;
140 GrVertexAttribType fType;
141 size_t fOffset;
142 };
143
144 typedef SkTArray<GrAttribute, true> VertexAttribArray;
145
146 const VertexAttribArray& getAttribs() const { return fAttribs; }
147
148 // Returns the vertex stride of the GP. A common use case is to request geo metry from a
149 // drawtarget based off of the stride, and to populate this memory using an implicit array of
150 // structs. In this case, it is best to assert the vertexstride == sizeof(V ertexStruct).
151 size_t getVertexStride() const { return fVertexStride; }
152
124 /** 153 /**
125 * Gets a transformKey from an array of coord transforms 154 * Gets a transformKey from an array of coord transforms
126 */ 155 */
127 uint32_t getTransformKey(const SkTArray<const GrCoordTransform*, true>&) con st; 156 uint32_t getTransformKey(const SkTArray<const GrCoordTransform*, true>&) con st;
128 157
129 /** 158 /**
130 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate d with this geometry 159 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate d with this geometry
131 * processor's GL backend implementation. 160 * processor's GL backend implementation.
132 */ 161 */
133 virtual void getGLProcessorKey(const GrBatchTracker& bt, 162 virtual void getGLProcessorKey(const GrBatchTracker& bt,
134 const GrGLCaps& caps, 163 const GrGLCaps& caps,
135 GrProcessorKeyBuilder* b) const = 0; 164 GrProcessorKeyBuilder* b) const = 0;
136 165
137 166
138 /** Returns a new instance of the appropriate *GL* implementation class 167 /** Returns a new instance of the appropriate *GL* implementation class
139 for the given GrProcessor; caller is responsible for deleting 168 for the given GrProcessor; caller is responsible for deleting
140 the object. */ 169 the object. */
141 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, 170 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt,
142 const GrGLCaps& caps) const = 0; 171 const GrGLCaps& caps) const = 0;
143 172
144 protected: 173 protected:
145 GrPrimitiveProcessor(const SkMatrix& viewMatrix, const SkMatrix& localMatrix ) 174 GrPrimitiveProcessor(const SkMatrix& viewMatrix, const SkMatrix& localMatrix )
146 : fViewMatrix(viewMatrix) 175 : fVertexStride(0)
176 , fViewMatrix(viewMatrix)
147 , fLocalMatrix(localMatrix) {} 177 , fLocalMatrix(localMatrix) {}
148 178
149 /* 179 /*
150 * CanCombineOutput will return true if two draws are 'batchable' from a col or perspective. 180 * CanCombineOutput will return true if two draws are 'batchable' from a col or perspective.
151 * TODO remove this when GPs can upgrade to attribute color 181 * TODO remove this when GPs can upgrade to attribute color
152 */ 182 */
153 static bool CanCombineOutput(GrGPInput left, GrColor lColor, GrGPInput right , GrColor rColor) { 183 static bool CanCombineOutput(GrGPInput left, GrColor lColor, GrGPInput right , GrColor rColor) {
154 if (left != right) { 184 if (left != right) {
155 return false; 185 return false;
156 } 186 }
(...skipping 12 matching lines...) Expand all
169 if (leftUsesLocalCoords != rightUsesLocalCoords) { 199 if (leftUsesLocalCoords != rightUsesLocalCoords) {
170 return false; 200 return false;
171 } 201 }
172 202
173 if (leftUsesLocalCoords && !left.localMatrix().cheapEqualTo(right.localM atrix())) { 203 if (leftUsesLocalCoords && !left.localMatrix().cheapEqualTo(right.localM atrix())) {
174 return false; 204 return false;
175 } 205 }
176 return true; 206 return true;
177 } 207 }
178 208
209 SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs;
bsalomon 2015/01/13 14:31:45 If it's really capped why not just Attribute fAtt
210 size_t fVertexStride;
211
179 private: 212 private:
180 virtual bool hasExplicitLocalCoords() const = 0; 213 virtual bool hasExplicitLocalCoords() const = 0;
181 214
182 SkMatrix fViewMatrix; 215 SkMatrix fViewMatrix;
183 SkMatrix fLocalMatrix; 216 SkMatrix fLocalMatrix;
184 217
185 typedef GrProcessor INHERITED; 218 typedef GrProcessor INHERITED;
186 }; 219 };
187 220
188 /** 221 /**
189 * A GrGeometryProcessor is a flexible method for rendering a primitive. The Gr GeometryProcessor 222 * A GrGeometryProcessor is a flexible method for rendering a primitive. The Gr GeometryProcessor
190 * has complete control over vertex attributes and uniforms(aside from the rende r target) but it 223 * has complete control over vertex attributes and uniforms(aside from the rende r target) but it
191 * must obey the same contract as any GrPrimitiveProcessor, specifically it must emit a color and 224 * must obey the same contract as any GrPrimitiveProcessor, specifically it must emit a color and
192 * coverage into the fragment shader. Where this color and coverage come from i s completely the 225 * coverage into the fragment shader. Where this color and coverage come from i s completely the
193 * responsibility of the GrGeometryProcessor. 226 * responsibility of the GrGeometryProcessor.
194 */ 227 */
195 class GrGeometryProcessor : public GrPrimitiveProcessor { 228 class GrGeometryProcessor : public GrPrimitiveProcessor {
196 public: 229 public:
197 // TODO the Hint can be handled in a much more clean way when we have deferr ed geometry or 230 // TODO the Hint can be handled in a much more clean way when we have deferr ed geometry or
198 // atleast bundles 231 // atleast bundles
199 GrGeometryProcessor(GrColor color, 232 GrGeometryProcessor(GrColor color,
200 const SkMatrix& viewMatrix = SkMatrix::I(), 233 const SkMatrix& viewMatrix = SkMatrix::I(),
201 const SkMatrix& localMatrix = SkMatrix::I(), 234 const SkMatrix& localMatrix = SkMatrix::I(),
202 bool opaqueVertexColors = false) 235 bool opaqueVertexColors = false)
203 : INHERITED(viewMatrix, localMatrix) 236 : INHERITED(viewMatrix, localMatrix)
204 , fVertexStride(0)
205 , fColor(color) 237 , fColor(color)
206 , fOpaqueVertexColors(opaqueVertexColors) 238 , fOpaqueVertexColors(opaqueVertexColors)
207 , fWillUseGeoShader(false) 239 , fWillUseGeoShader(false)
208 , fHasVertexColor(false) 240 , fHasVertexColor(false)
209 , fHasLocalCoords(false) {} 241 , fHasLocalCoords(false) {}
210 242
211 /*
212 * This is a safeguard to prevent GPs from going beyond platform specific at tribute limits.
213 * This number can almost certainly be raised if required.
214 */
215 static const int kMaxVertexAttribs = 6;
216
217 struct GrAttribute {
218 GrAttribute(const char* name, GrVertexAttribType type)
219 : fName(name)
220 , fType(type)
221 , fOffset(SkAlign4(GrVertexAttribTypeSize(type))) {}
222 const char* fName;
223 GrVertexAttribType fType;
224 size_t fOffset;
225 };
226
227 typedef SkTArray<GrAttribute, true> VertexAttribArray;
228
229 const VertexAttribArray& getAttribs() const { return fAttribs; }
230
231 // Returns the vertex stride of the GP. A common use case is to request geo metry from a
232 // drawtarget based off of the stride, and to populate this memory using an implicit array of
233 // structs. In this case, it is best to assert the vertexstride == sizeof(V ertexStruct).
234 size_t getVertexStride() const { return fVertexStride; }
235
236 bool willUseGeoShader() const { return fWillUseGeoShader; } 243 bool willUseGeoShader() const { return fWillUseGeoShader; }
237 244
238 /* 245 /*
239 * In an ideal world, two GrGeometryProcessors with the same class id and te xture accesses 246 * In an ideal world, two GrGeometryProcessors with the same class id and te xture accesses
240 * would ALWAYS be able to batch together. If two GrGeometryProcesosrs are the same then we 247 * would ALWAYS be able to batch together. If two GrGeometryProcesosrs are the same then we
241 * will only keep one of them. The remaining GrGeometryProcessor then updat es its 248 * will only keep one of them. The remaining GrGeometryProcessor then updat es its
242 * GrBatchTracker to incorporate the draw information from the GrGeometryPro cessor we discard. 249 * GrBatchTracker to incorporate the draw information from the GrGeometryPro cessor we discard.
243 * Any bundles associated with the discarded GrGeometryProcessor will be att ached to the 250 * Any bundles associated with the discarded GrGeometryProcessor will be att ached to the
244 * remaining GrGeometryProcessor. 251 * remaining GrGeometryProcessor.
245 */ 252 */
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 private: 342 private:
336 virtual bool onCanMakeEqual(const GrBatchTracker& mine, 343 virtual bool onCanMakeEqual(const GrBatchTracker& mine,
337 const GrGeometryProcessor& that, 344 const GrGeometryProcessor& that,
338 const GrBatchTracker& theirs) const = 0; 345 const GrBatchTracker& theirs) const = 0;
339 346
340 // TODO delete this when we have more advanced equality testing via bundles and the BT 347 // TODO delete this when we have more advanced equality testing via bundles and the BT
341 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; 348 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0;
342 349
343 bool hasExplicitLocalCoords() const SK_OVERRIDE { return fHasLocalCoords; } 350 bool hasExplicitLocalCoords() const SK_OVERRIDE { return fHasLocalCoords; }
344 351
345 SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs;
346 size_t fVertexStride;
347 GrColor fColor; 352 GrColor fColor;
348 bool fOpaqueVertexColors; 353 bool fOpaqueVertexColors;
349 bool fWillUseGeoShader; 354 bool fWillUseGeoShader;
350 bool fHasVertexColor; 355 bool fHasVertexColor;
351 bool fHasLocalCoords; 356 bool fHasLocalCoords;
352 357
353 typedef GrPrimitiveProcessor INHERITED; 358 typedef GrPrimitiveProcessor INHERITED;
354 }; 359 };
355 360
356 /* 361 /*
(...skipping 14 matching lines...) Expand all
371 const GrPrimitiveProcessor& that, 376 const GrPrimitiveProcessor& that,
372 const GrBatchTracker& theirs) const SK_OVERRIDE; 377 const GrBatchTracker& theirs) const SK_OVERRIDE;
373 378
374 const char* name() const SK_OVERRIDE { return "PathProcessor"; } 379 const char* name() const SK_OVERRIDE { return "PathProcessor"; }
375 380
376 GrColor color() const { return fColor; } 381 GrColor color() const { return fColor; }
377 382
378 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; 383 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE;
379 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID E; 384 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID E;
380 385
386 bool willUseGeoShader() const SK_OVERRIDE { return false; }
387
381 virtual void getGLProcessorKey(const GrBatchTracker& bt, 388 virtual void getGLProcessorKey(const GrBatchTracker& bt,
382 const GrGLCaps& caps, 389 const GrGLCaps& caps,
383 GrProcessorKeyBuilder* b) const SK_OVERRIDE; 390 GrProcessorKeyBuilder* b) const SK_OVERRIDE;
384 391
385 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, 392 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt,
386 const GrGLCaps& caps) const SK_OVERRIDE; 393 const GrGLCaps& caps) const SK_OVERRIDE;
387 394
388 protected: 395 protected:
389 GrPathProcessor(GrColor color, const SkMatrix& viewMatrix, const SkMatrix& l ocalMatrix); 396 GrPathProcessor(GrColor color, const SkMatrix& viewMatrix, const SkMatrix& l ocalMatrix);
390 397
391 private: 398 private:
392 bool hasExplicitLocalCoords() const SK_OVERRIDE { return false; } 399 bool hasExplicitLocalCoords() const SK_OVERRIDE { return false; }
393 400
394 GrColor fColor; 401 GrColor fColor;
395 402
396 typedef GrPrimitiveProcessor INHERITED; 403 typedef GrPrimitiveProcessor INHERITED;
397 }; 404 };
398 405
399 #endif 406 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrInOrderDrawBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698