OLD | NEW |
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 GrPrimitiveProcessor_DEFINED | 8 #ifndef GrPrimitiveProcessor_DEFINED |
9 #define GrPrimitiveProcessor_DEFINED | 9 #define GrPrimitiveProcessor_DEFINED |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 * | 35 * |
36 * In a deferred geometry world, the GrPrimitiveProcessor can always 'batch' To
do this, each | 36 * In a deferred geometry world, the GrPrimitiveProcessor can always 'batch' To
do this, each |
37 * primitive type is associated with one GrPrimitiveProcessor, who has complete
control of how | 37 * primitive type is associated with one GrPrimitiveProcessor, who has complete
control of how |
38 * it draws. Each primitive draw will bundle all required data to perform the d
raw, and these | 38 * it draws. Each primitive draw will bundle all required data to perform the d
raw, and these |
39 * bundles of data will be owned by an instance of the associated GrPrimitivePro
cessor. Bundles | 39 * bundles of data will be owned by an instance of the associated GrPrimitivePro
cessor. Bundles |
40 * can be updated alongside the GrBatchTracker struct itself, ultimately allowin
g the | 40 * can be updated alongside the GrBatchTracker struct itself, ultimately allowin
g the |
41 * GrPrimitiveProcessor complete control of how it gets data into the fragment s
hader as long as | 41 * GrPrimitiveProcessor complete control of how it gets data into the fragment s
hader as long as |
42 * it emits the appropriate color, or none at all, as directed. | 42 * it emits the appropriate color, or none at all, as directed. |
43 */ | 43 */ |
44 | 44 |
45 /* | |
46 * A struct for tracking batching decisions. While this lives on GrOptState, it
is managed | |
47 * entirely by the derived classes of the GP. | |
48 * // TODO this was an early attempt at handling out of order batching. It shou
ld be | |
49 * used carefully as it is being replaced by GrBatch | |
50 */ | |
51 class GrBatchTracker { | |
52 public: | |
53 template <typename T> const T& cast() const { | |
54 SkASSERT(sizeof(T) <= kMaxSize); | |
55 return *reinterpret_cast<const T*>(fData.get()); | |
56 } | |
57 | |
58 template <typename T> T* cast() { | |
59 SkASSERT(sizeof(T) <= kMaxSize); | |
60 return reinterpret_cast<T*>(fData.get()); | |
61 } | |
62 | |
63 static const size_t kMaxSize = 32; | |
64 | |
65 private: | |
66 SkAlignedSStorage<kMaxSize> fData; | |
67 }; | |
68 | |
69 class GrGLSLCaps; | 45 class GrGLSLCaps; |
70 class GrGLPrimitiveProcessor; | 46 class GrGLPrimitiveProcessor; |
71 | 47 |
72 struct GrInitInvariantOutput; | 48 struct GrInitInvariantOutput; |
73 | 49 |
74 /* | 50 /* |
75 * This class allows the GrPipeline to communicate information about the pipelin
e to a | 51 * This class allows the GrPipeline to communicate information about the pipelin
e to a |
76 * GrBatch which should be forwarded to the GrPrimitiveProcessor(s) created by t
he batch. | 52 * GrBatch which should be forwarded to the GrPrimitiveProcessor(s) created by t
he batch. |
77 * These are not properly part of the pipeline because they assume the specific
inputs | 53 * These are not properly part of the pipeline because they assume the specific
inputs |
78 * that the batch provided when it created the pipeline. Identical pipelines may
be | 54 * that the batch provided when it created the pipeline. Identical pipelines may
be |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 kWillColorBlendWithDst_Flag = 0x20, | 124 kWillColorBlendWithDst_Flag = 0x20, |
149 }; | 125 }; |
150 | 126 |
151 uint32_t fFlags; | 127 uint32_t fFlags; |
152 GrColor fOverrideColor; | 128 GrColor fOverrideColor; |
153 | 129 |
154 friend class GrPipeline; // To initialize this | 130 friend class GrPipeline; // To initialize this |
155 }; | 131 }; |
156 | 132 |
157 /* | 133 /* |
158 * This enum is shared by GrPrimitiveProcessors and GrGLPrimitiveProcessors to c
oordinate shaders | |
159 * with vertex attributes / uniforms. | |
160 */ | |
161 enum GrGPInput { | |
162 kAllOnes_GrGPInput, | |
163 kAttribute_GrGPInput, | |
164 kUniform_GrGPInput, | |
165 kIgnored_GrGPInput, | |
166 }; | |
167 | |
168 /* | |
169 * GrPrimitiveProcessor defines an interface which all subclasses must implement
. All | 134 * GrPrimitiveProcessor defines an interface which all subclasses must implement
. All |
170 * GrPrimitiveProcessors must proivide seed color and coverage for the Ganesh co
lor / coverage | 135 * GrPrimitiveProcessors must proivide seed color and coverage for the Ganesh co
lor / coverage |
171 * pipelines, and they must provide some notion of equality | 136 * pipelines, and they must provide some notion of equality |
172 */ | 137 */ |
173 class GrPrimitiveProcessor : public GrProcessor { | 138 class GrPrimitiveProcessor : public GrProcessor { |
174 public: | 139 public: |
175 virtual void initBatchTracker(GrBatchTracker*, const GrPipelineOptimizations
&) const = 0; | |
176 | |
177 virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0; | |
178 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const =
0; | |
179 | |
180 // Only the GrGeometryProcessor subclass actually has a geo shader or vertex
attributes, but | 140 // Only the GrGeometryProcessor subclass actually has a geo shader or vertex
attributes, but |
181 // we put these calls on the base class to prevent having to cast | 141 // we put these calls on the base class to prevent having to cast |
182 virtual bool willUseGeoShader() const = 0; | 142 virtual bool willUseGeoShader() const = 0; |
183 | 143 |
184 /* | 144 /* |
185 * This is a safeguard to prevent GrPrimitiveProcessor's from going beyond p
latform specific | 145 * This is a safeguard to prevent GrPrimitiveProcessor's from going beyond p
latform specific |
186 * attribute limits. This number can almost certainly be raised if required. | 146 * attribute limits. This number can almost certainly be raised if required. |
187 */ | 147 */ |
188 static const int kMaxVertexAttribs = 6; | 148 static const int kMaxVertexAttribs = 6; |
189 | 149 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 */ | 183 */ |
224 uint32_t getTransformKey(const SkTArray<const GrCoordTransform*, true>& coor
ds, | 184 uint32_t getTransformKey(const SkTArray<const GrCoordTransform*, true>& coor
ds, |
225 int numCoords) const; | 185 int numCoords) const; |
226 | 186 |
227 /** | 187 /** |
228 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate
d with this geometry | 188 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate
d with this geometry |
229 * processor's GL backend implementation. | 189 * processor's GL backend implementation. |
230 * | 190 * |
231 * TODO: A better name for this function would be "compute" instead of "get
". | 191 * TODO: A better name for this function would be "compute" instead of "get
". |
232 */ | 192 */ |
233 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 193 virtual void getGLProcessorKey(const GrGLSLCaps& caps, |
234 const GrGLSLCaps& caps, | |
235 GrProcessorKeyBuilder* b) const = 0; | 194 GrProcessorKeyBuilder* b) const = 0; |
236 | 195 |
237 | 196 |
238 /** Returns a new instance of the appropriate *GL* implementation class | 197 /** Returns a new instance of the appropriate *GL* implementation class |
239 for the given GrProcessor; caller is responsible for deleting | 198 for the given GrProcessor; caller is responsible for deleting |
240 the object. */ | 199 the object. */ |
241 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, | 200 virtual GrGLPrimitiveProcessor* createGLInstance(const GrGLSLCaps& caps) con
st = 0; |
242 const GrGLSLCaps& caps) con
st = 0; | |
243 | 201 |
244 bool isPathRendering() const { return fIsPathRendering; } | 202 bool isPathRendering() const { return fIsPathRendering; } |
245 | 203 |
246 /** | 204 /** |
247 * No Local Coord Transformation is needed in the shader, instead transforme
d local coords will | 205 * No Local Coord Transformation is needed in the shader, instead transforme
d local coords will |
248 * be provided via vertex attribute. | 206 * be provided via vertex attribute. |
249 */ | 207 */ |
250 virtual bool hasTransformedLocalCoords() const = 0; | 208 virtual bool hasTransformedLocalCoords() const = 0; |
251 | 209 |
252 protected: | 210 protected: |
253 GrPrimitiveProcessor(bool isPathRendering) | 211 GrPrimitiveProcessor(bool isPathRendering) |
254 : fNumAttribs(0) | 212 : fNumAttribs(0) |
255 , fVertexStride(0) | 213 , fVertexStride(0) |
256 , fIsPathRendering(isPathRendering) {} | 214 , fIsPathRendering(isPathRendering) {} |
257 | 215 |
258 Attribute fAttribs[kMaxVertexAttribs]; | 216 Attribute fAttribs[kMaxVertexAttribs]; |
259 int fNumAttribs; | 217 int fNumAttribs; |
260 size_t fVertexStride; | 218 size_t fVertexStride; |
261 | 219 |
262 private: | 220 private: |
263 void notifyRefCntIsZero() const final {}; | 221 void notifyRefCntIsZero() const final {}; |
264 virtual bool hasExplicitLocalCoords() const = 0; | 222 virtual bool hasExplicitLocalCoords() const = 0; |
265 | 223 |
266 bool fIsPathRendering; | 224 bool fIsPathRendering; |
267 | 225 |
268 typedef GrProcessor INHERITED; | 226 typedef GrProcessor INHERITED; |
269 }; | 227 }; |
270 | 228 |
271 #endif | 229 #endif |
OLD | NEW |