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 GrGeometryProcessor_DEFINED | 8 #ifndef GrGeometryProcessor_DEFINED |
9 #define GrGeometryProcessor_DEFINED | 9 #define GrGeometryProcessor_DEFINED |
10 | 10 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 85 |
86 /* | 86 /* |
87 * GrPrimitiveProcessor defines an interface which all subclasses must implement
. All | 87 * GrPrimitiveProcessor defines an interface which all subclasses must implement
. All |
88 * GrPrimitiveProcessors must proivide seed color and coverage for the Ganesh co
lor / coverage | 88 * GrPrimitiveProcessors must proivide seed color and coverage for the Ganesh co
lor / coverage |
89 * pipelines, and they must provide some notion of equality | 89 * pipelines, and they must provide some notion of equality |
90 */ | 90 */ |
91 class GrPrimitiveProcessor : public GrProcessor { | 91 class GrPrimitiveProcessor : public GrProcessor { |
92 public: | 92 public: |
93 // TODO let the PrimProc itself set this in its setData call, this should re
ally live on the | 93 // TODO let the PrimProc itself set this in its setData call, this should re
ally live on the |
94 // bundle of primitive data | 94 // bundle of primitive data |
| 95 const SkMatrix& viewMatrix() const { return fViewMatrix; } |
95 const SkMatrix& localMatrix() const { return fLocalMatrix; } | 96 const SkMatrix& localMatrix() const { return fLocalMatrix; } |
96 | 97 |
97 /* | 98 /* |
98 * This struct allows the optstate to communicate requirements to the GrPrim
itiveProcessor. | 99 * This struct allows the optstate to communicate requirements to the GrPrim
itiveProcessor. |
99 */ | 100 */ |
100 struct InitBT { | 101 struct InitBT { |
101 bool fColorIgnored; | 102 bool fColorIgnored; |
102 bool fCoverageIgnored; | 103 bool fCoverageIgnored; |
103 GrColor fOverrideColor; | 104 GrColor fOverrideColor; |
104 bool fUsesLocalCoords; | 105 bool fUsesLocalCoords; |
(...skipping 23 matching lines...) Expand all Loading... |
128 const GrGLCaps& caps, | 129 const GrGLCaps& caps, |
129 GrProcessorKeyBuilder* b) const = 0; | 130 GrProcessorKeyBuilder* b) const = 0; |
130 | 131 |
131 | 132 |
132 /** Returns a new instance of the appropriate *GL* implementation class | 133 /** Returns a new instance of the appropriate *GL* implementation class |
133 for the given GrProcessor; caller is responsible for deleting | 134 for the given GrProcessor; caller is responsible for deleting |
134 the object. */ | 135 the object. */ |
135 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co
nst = 0; | 136 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co
nst = 0; |
136 | 137 |
137 protected: | 138 protected: |
138 GrPrimitiveProcessor(const SkMatrix& localMatrix) : fLocalMatrix(localMatrix
) {} | 139 GrPrimitiveProcessor(const SkMatrix& viewMatrix, const SkMatrix& localMatrix
) |
| 140 : fViewMatrix(viewMatrix) |
| 141 , fLocalMatrix(localMatrix) {} |
139 | 142 |
140 /* | 143 /* |
141 * CanCombineOutput will return true if two draws are 'batchable' from a col
or perspective. | 144 * CanCombineOutput will return true if two draws are 'batchable' from a col
or perspective. |
142 * TODO remove this when GPs can upgrade to attribute color | 145 * TODO remove this when GPs can upgrade to attribute color |
143 */ | 146 */ |
144 static bool CanCombineOutput(GrGPInput left, GrColor lColor, GrGPInput right
, GrColor rColor) { | 147 static bool CanCombineOutput(GrGPInput left, GrColor lColor, GrGPInput right
, GrColor rColor) { |
145 if (left != right) { | 148 if (left != right) { |
146 return false; | 149 return false; |
147 } | 150 } |
148 | 151 |
(...skipping 12 matching lines...) Expand all Loading... |
161 return false; | 164 return false; |
162 } | 165 } |
163 | 166 |
164 if (leftUsesLocalCoords && !left.localMatrix().cheapEqualTo(right.localM
atrix())) { | 167 if (leftUsesLocalCoords && !left.localMatrix().cheapEqualTo(right.localM
atrix())) { |
165 return false; | 168 return false; |
166 } | 169 } |
167 return true; | 170 return true; |
168 } | 171 } |
169 | 172 |
170 private: | 173 private: |
| 174 SkMatrix fViewMatrix; |
171 SkMatrix fLocalMatrix; | 175 SkMatrix fLocalMatrix; |
172 | 176 |
173 typedef GrProcessor INHERITED; | 177 typedef GrProcessor INHERITED; |
174 }; | 178 }; |
175 | 179 |
176 /** | 180 /** |
177 * A GrGeometryProcessor is a flexible method for rendering a primitive. The Gr
GeometryProcessor | 181 * A GrGeometryProcessor is a flexible method for rendering a primitive. The Gr
GeometryProcessor |
178 * has complete control over vertex attributes and uniforms(aside from the rende
r target) but it | 182 * has complete control over vertex attributes and uniforms(aside from the rende
r target) but it |
179 * must obey the same contract as any GrPrimitiveProcessor, specifically it must
emit a color and | 183 * must obey the same contract as any GrPrimitiveProcessor, specifically it must
emit a color and |
180 * coverage into the fragment shader. Where this color and coverage come from i
s completely the | 184 * coverage into the fragment shader. Where this color and coverage come from i
s completely the |
181 * responsibility of the GrGeometryProcessor. | 185 * responsibility of the GrGeometryProcessor. |
182 */ | 186 */ |
183 class GrGeometryProcessor : public GrPrimitiveProcessor { | 187 class GrGeometryProcessor : public GrPrimitiveProcessor { |
184 public: | 188 public: |
185 // TODO the Hint can be handled in a much more clean way when we have deferr
ed geometry or | 189 // TODO the Hint can be handled in a much more clean way when we have deferr
ed geometry or |
186 // atleast bundles | 190 // atleast bundles |
187 GrGeometryProcessor(GrColor color, | 191 GrGeometryProcessor(GrColor color, |
188 bool opaqueVertexColors = false, | 192 const SkMatrix& viewMatrix = SkMatrix::I(), |
189 const SkMatrix& localMatrix = SkMatrix::I()) | 193 const SkMatrix& localMatrix = SkMatrix::I(), |
190 : INHERITED(localMatrix) | 194 bool opaqueVertexColors = false) |
| 195 : INHERITED(viewMatrix, localMatrix) |
191 , fVertexStride(0) | 196 , fVertexStride(0) |
192 , fColor(color) | 197 , fColor(color) |
193 , fOpaqueVertexColors(opaqueVertexColors) | 198 , fOpaqueVertexColors(opaqueVertexColors) |
194 , fWillUseGeoShader(false) | 199 , fWillUseGeoShader(false) |
195 , fHasVertexColor(false) | 200 , fHasVertexColor(false) |
196 , fHasLocalCoords(false) {} | 201 , fHasLocalCoords(false) {} |
197 | 202 |
198 /* | 203 /* |
199 * This is a safeguard to prevent GPs from going beyond platform specific at
tribute limits. | 204 * This is a safeguard to prevent GPs from going beyond platform specific at
tribute limits. |
200 * This number can almost certainly be raised if required. | 205 * This number can almost certainly be raised if required. |
(...skipping 29 matching lines...) Expand all Loading... |
230 * Any bundles associated with the discarded GrGeometryProcessor will be att
ached to the | 235 * Any bundles associated with the discarded GrGeometryProcessor will be att
ached to the |
231 * remaining GrGeometryProcessor. | 236 * remaining GrGeometryProcessor. |
232 */ | 237 */ |
233 bool canMakeEqual(const GrBatchTracker& mine, | 238 bool canMakeEqual(const GrBatchTracker& mine, |
234 const GrPrimitiveProcessor& that, | 239 const GrPrimitiveProcessor& that, |
235 const GrBatchTracker& theirs) const SK_OVERRIDE { | 240 const GrBatchTracker& theirs) const SK_OVERRIDE { |
236 if (this->classID() != that.classID() || !this->hasSameTextureAccesses(t
hat)) { | 241 if (this->classID() != that.classID() || !this->hasSameTextureAccesses(t
hat)) { |
237 return false; | 242 return false; |
238 } | 243 } |
239 | 244 |
| 245 // TODO let the GPs decide this |
| 246 if (!this->viewMatrix().cheapEqualTo(that.viewMatrix())) { |
| 247 return false; |
| 248 } |
| 249 |
240 // TODO remove the hint | 250 // TODO remove the hint |
241 const GrGeometryProcessor& other = that.cast<GrGeometryProcessor>(); | 251 const GrGeometryProcessor& other = that.cast<GrGeometryProcessor>(); |
242 if (fHasVertexColor && fOpaqueVertexColors != other.fOpaqueVertexColors)
{ | 252 if (fHasVertexColor && fOpaqueVertexColors != other.fOpaqueVertexColors)
{ |
243 return false; | 253 return false; |
244 } | 254 } |
245 | 255 |
246 // TODO this equality test should really be broken up, some of this can
live on the batch | 256 // TODO this equality test should really be broken up, some of this can
live on the batch |
247 // tracker test and some of this should be in bundles | 257 // tracker test and some of this should be in bundles |
248 if (!this->onIsEqual(other)) { | 258 if (!this->onIsEqual(other)) { |
249 return false; | 259 return false; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 | 345 |
336 typedef GrPrimitiveProcessor INHERITED; | 346 typedef GrPrimitiveProcessor INHERITED; |
337 }; | 347 }; |
338 | 348 |
339 /* | 349 /* |
340 * The path equivalent of the GP. For now this just manages color. In the long
term we plan on | 350 * The path equivalent of the GP. For now this just manages color. In the long
term we plan on |
341 * extending this class to handle all nvpr uniform / varying / program work. | 351 * extending this class to handle all nvpr uniform / varying / program work. |
342 */ | 352 */ |
343 class GrPathProcessor : public GrPrimitiveProcessor { | 353 class GrPathProcessor : public GrPrimitiveProcessor { |
344 public: | 354 public: |
345 static GrPathProcessor* Create(GrColor color, const SkMatrix& localMatrix =
SkMatrix::I()) { | 355 static GrPathProcessor* Create(GrColor color, |
346 return SkNEW_ARGS(GrPathProcessor, (color, localMatrix)); | 356 const SkMatrix& viewMatrix = SkMatrix::I(), |
| 357 const SkMatrix& localMatrix = SkMatrix::I())
{ |
| 358 return SkNEW_ARGS(GrPathProcessor, (color, viewMatrix, localMatrix)); |
347 } | 359 } |
348 | 360 |
349 void initBatchTracker(GrBatchTracker*, const InitBT&) const SK_OVERRIDE; | 361 void initBatchTracker(GrBatchTracker*, const InitBT&) const SK_OVERRIDE; |
350 | 362 |
351 bool canMakeEqual(const GrBatchTracker& mine, | 363 bool canMakeEqual(const GrBatchTracker& mine, |
352 const GrPrimitiveProcessor& that, | 364 const GrPrimitiveProcessor& that, |
353 const GrBatchTracker& theirs) const SK_OVERRIDE; | 365 const GrBatchTracker& theirs) const SK_OVERRIDE; |
354 | 366 |
355 const char* name() const SK_OVERRIDE { return "PathProcessor"; } | 367 const char* name() const SK_OVERRIDE { return "PathProcessor"; } |
356 | 368 |
357 GrColor color() const { return fColor; } | 369 GrColor color() const { return fColor; } |
358 | 370 |
359 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; | 371 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; |
360 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID
E; | 372 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID
E; |
361 | 373 |
362 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 374 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
363 const GrGLCaps& caps, | 375 const GrGLCaps& caps, |
364 GrProcessorKeyBuilder* b) const SK_OVERRIDE; | 376 GrProcessorKeyBuilder* b) const SK_OVERRIDE; |
365 | 377 |
366 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co
nst SK_OVERRIDE; | 378 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co
nst SK_OVERRIDE; |
367 | 379 |
368 private: | 380 private: |
369 GrPathProcessor(GrColor color, const SkMatrix& localMatrix); | 381 GrPathProcessor(GrColor color, const SkMatrix& viewMatrix, const SkMatrix& l
ocalMatrix); |
370 GrColor fColor; | 382 GrColor fColor; |
371 | 383 |
372 typedef GrPrimitiveProcessor INHERITED; | 384 typedef GrPrimitiveProcessor INHERITED; |
373 }; | 385 }; |
374 #endif | 386 #endif |
OLD | NEW |